Unity: 5.1.1f
Language: c#
When i instantiate a gameObject inside a Assets/Editor/ file, it doesn't appear in Scene until i select another scene's gameobject.
I've tried calling some methods like:
SceneView.RepaintAll();
HandleUtility.Repaint();
But non of them look to be working. This is how i spawn the object:
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);
}
}
答案 0 :(得分:1)
我相信你正在使用Editor类,而不是像
那样实例化你的gameObjectGameObject prefabInstance = Instantiate(prefab) as GameObject;
像这样实例化你的gameObject
GameObject prefabInstance = (GameObject) PrefabUtility.InstantiatePrefab(prefab);
并尝试使用
SceneView.lastActiveSceneView.Repaint();
我希望这会有所帮助。