public override void OnInspectorGUI() { showHelp = (bool)EditorGUILayout.Toggle("Show Help", showHelp); if (showHelp) { EditorGUILayout.BeginFadeGroup(1); EditorGUILayout.HelpBox(helpText, MessageType.None); if (GUILayout.Button("User Guide")) { OpenUserGuide(); } EditorGUILayout.EndFadeGroup(); } DrawDefaultInspector(); if (GUILayout.Button("Create Spawn Point")) { CreateSpawnPoint(); } if (GUILayout.Button("Refresh Spawn Points")) { _quickSpawner = (MonoBehaviour)target as QuickSpawner; _quickSpawner.RefreshSpawnPoints(); } if (GUI.changed) { EditorUtility.SetDirty(_quickSpawner); serializedObject.ApplyModifiedProperties(); } }
void CreateSpawnPoint() { // Set up required variables _quickSpawner = (MonoBehaviour)target as QuickSpawner; string id = _quickSpawner.spawnerID; // Create the prefab GameObject spawnPoint = new GameObject("spawn point"); // Select the prefab and update the components Selection.activeObject = spawnPoint; spawnPoint.AddComponent <QuickGizmo> (); SetSpawnPointGizmo(spawnPoint.GetComponent <QuickGizmo> ()); spawnPoint.AddComponent <QS_SpawnPoint> (); spawnPoint.GetComponent <QS_SpawnPoint> ().spawnerID = id; // Move the prefab to the Editor's camera position var sceneView = SceneView.lastActiveSceneView; if (sceneView != null) { spawnPoint.transform.position = sceneView.camera.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 10f)); } // Child the prefab to its relevant Spawner and add it to the list of Spawn Points spawnPoint.transform.parent = _quickSpawner.gameObject.transform; _quickSpawner.RefreshSpawnPoints(); }
void onEnable() { _quickSpawner = (MonoBehaviour)target as QuickSpawner; }