【问题标题】:Unity - Repaint/Redraw Scene after gameObject instantiationUnity - 游戏对象实例化后重绘/重绘场景
【发布时间】:2015-08-01 12:37:33
【问题描述】:

团结:5.1.1f

语言:c#

当我在 Assets/Editor/ 文件中实例化一个游戏对象时,它不会出现在场景中,直到我选择另一个场景的游戏对象。

我尝试过调用一些方法,例如:

SceneView.RepaintAll();
HandleUtility.Repaint();

但其中没有一个看起来有效。这就是我生成对象的方式:

public class PrefabEditor: Editor {
    void OnSceneGUI() {
        GameObject prefabInstance = Instantiate(prefab) as GameObject;

        // assign him an icon label
        Texture2D tex = EditorGUIUtility.IconContent("sv_label_0").image as Texture2D;
        Type editorGUIUtilityType = typeof(EditorGUIUtility);
        BindingFlags bindingFlags = BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic;
        object[] args = new object[] {
            prefabInstance, tex
        };
        editorGUIUtilityType.InvokeMember("SetIconForObject", bindingFlags, null, null, args);

        EditorUtility.SetDirty(prefabInstance);
    }
}

【问题讨论】:

    标签: c# unity3d instantiation redraw


    【解决方案1】:

    我相信您使用的是 Editor 类,而不是像这样实例化您的游戏对象

    GameObject prefabInstance = Instantiate(prefab) as GameObject;
    

    像这样实例化你的游戏对象

    GameObject prefabInstance = (GameObject) PrefabUtility.InstantiatePrefab(prefab);
    

    并尝试使用

    SceneView.lastActiveSceneView.Repaint();
    

    我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-18
      • 1970-01-01
      • 2016-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多