void ModifySmartSpawnAsset(Object[] items, int[] chances, SmartSpawnScriptableObject origAsset) { origAsset.itemPrefab = items; origAsset.spawnChance = chances; AssetDatabase.SaveAssets(); }
public static void CreateSmartSpawnAsset() { SmartSpawnScriptableObject asset = ScriptableObject.CreateInstance <SmartSpawnScriptableObject>(); string path = AssetDatabase.GetAssetPath(Selection.activeObject); if (path == "") { path = "Assets"; } else if (Path.GetExtension(path) != "") { path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), ""); } string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/New " + "SpawnerAsset.Asset"); AssetDatabase.CreateAsset(asset, assetPathAndName); AssetDatabase.SaveAssets(); //EditorUtility.FocusProjectWindow(); Selection.activeObject = asset; }
public override void OnInspectorGUI() { //Updates the object we are editing serializedObject.Update(); //Quick references for when we want to change the size of the array bool enlarge = false; bool decrease = false; //Quick reference to the itemspawnscript SmartSpawnScriptDefaultNetworked s = target as SmartSpawnScriptDefaultNetworked; if (itemPrefab == null || spawnChance == null) { this.OnEnable(); } #if !SS_USEPHOTON && !SS_USEBOLT EditorGUILayout.LabelField("Using Default Networking"); #endif #if SS_USEPHOTON && !SS_USEBOLT EditorGUILayout.LabelField("Using Photon Networking"); #endif #if !SS_USEPHOTON && SS_USEBOLT EditorGUILayout.LabelField("Using Bolt Networking"); #endif //Start the horizontal (2 per line) GUI layour EditorGUILayout.BeginHorizontal(); //Spawn timer (how long between spawns) slider and label EditorGUILayout.LabelField("Next spawn in: " + ((int)(s.spawnCountdown - s.timer)).ToString()); //Button to manually call the spawn function, only if the game is in play mode if (GUILayout.Button("Test Spawn")) { if (Application.isPlaying) { s.Spawn(); } if (!Application.isPlaying) { Debug.Log("You can only call the spawn function when the game is running"); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); //Checkbox to see if the user wants to fill any empty spawn point on each spawn EditorGUILayout.LabelField("Fill empty spawn points first"); EditorGUI.BeginChangeCheck(); bool bOne = EditorGUILayout.Toggle(s.useOpenSpawnPoints); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Fill empty sPs"); s.useOpenSpawnPoints = bOne; } EditorGUILayout.EndHorizontal(); //Checkbox to see if the user wants to fill any empty spawn point on each spawn if (s.useOpenSpawnPoints) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Randomise filled Spawnpoints"); EditorGUI.BeginChangeCheck(); bool bTwenty = EditorGUILayout.Toggle(s.useRandomSpawnPointsWhenFillingEmpty); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Track spawned objects"); s.useRandomSpawnPointsWhenFillingEmpty = bTwenty; } EditorGUILayout.EndHorizontal(); } EditorGUILayout.BeginHorizontal(); //Checkbox to see if the user wants to fill any empty spawn point on each spawn EditorGUILayout.LabelField("Cap maximum spawns"); EditorGUI.BeginChangeCheck(); bool bTwo = EditorGUILayout.Toggle(s.useMaxSpawns); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Use max spawns"); s.useMaxSpawns = bTwo; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); //Checkbox to see if the user wants to fill any empty spawn point on each spawn EditorGUILayout.LabelField("Use Wave Spawning"); EditorGUI.BeginChangeCheck(); bool bWave = EditorGUILayout.Toggle(s.useWaveSpawning); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Use Wave Spawning"); s.useWaveSpawning = bWave; } EditorGUILayout.EndHorizontal(); if (s.useWaveSpawning == true) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Reset waves after time?"); EditorGUI.BeginChangeCheck(); bool bWaveT = EditorGUILayout.Toggle(s.resetWaveValuesAfterTime); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Reset waves after time?"); s.resetWaveValuesAfterTime = bWaveT; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (s.resetWaveValuesAfterTime == true && s.useWaveSpawning == true) { EditorGUI.BeginChangeCheck(); float rOne = EditorGUILayout.Slider("Wave reset time", s.waveResetTime, 0f, (s.waveResetTime + 10f)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Wave resettime"); s.waveResetTime = rOne; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); //Checkbox to see if the user wants to fill any empty spawn point on each spawn EditorGUILayout.LabelField("Track spawned objects"); EditorGUI.BeginChangeCheck(); bool bfour = EditorGUILayout.Toggle(s.trackSpawnedObjects); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Track spawned objects"); s.trackSpawnedObjects = bfour; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (s.useMaxSpawns) { EditorGUI.BeginChangeCheck(); int iOne = EditorGUILayout.IntSlider("Max spawns", s.maxSpawnerSpawns, 0, 150); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Change max spawns"); s.maxSpawnerSpawns = iOne; } } EditorGUILayout.EndHorizontal(); //Start the horizontal (2 per line) GUI layour EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Time between spawns"); EditorGUI.BeginChangeCheck(); float iTwo = EditorGUILayout.Slider(s.spawnCountdown, 0f, 500f); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Change time between spawns"); s.spawnCountdown = iTwo; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); SmartSpawnScriptableObject spOne = (SmartSpawnScriptableObject)EditorGUILayout.ObjectField("Spawner type", s.spawnObject, typeof(SmartSpawnScriptableObject), false); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Change spawner type"); s.spawnObject = spOne; } SmartSpawnScriptableObject targetSpawnObject = s.spawnObject; EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Create new Spawner type")) { CreateSmartSpawnAsset(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Add spawn point")) { CreateSpawnPoint(s); } EditorGUILayout.EndHorizontal(); if (Application.isPlaying) { EditorGUILayout.LabelField("Note: Values changed in playmode are not saved"); } if (targetSpawnObject != null) { //Labels EditorGUILayout.LabelField("Spawn ratio", "Object to spawn"); //Start the horizontal (2 per line) GUI layour EditorGUILayout.BeginHorizontal(); if (targetSpawnObject.spawnChance != null) { //Make a column of the spawn chance ratio sliders EditorGUILayout.BeginVertical(); if (Application.isPlaying) { for (int i = 0; i < s.spawnChances.Count; ++i) { //s.spawnObject.spawnChance[i] = EditorGUILayout.IntSlider(s.spawnObject.spawnChance[i], 0, 100); s.spawnChances[i] = EditorGUILayout.IntSlider(s.spawnChances[i], 0, Mathf.Max(100, s.spawnChances[i])); } } else { for (int i = 0; i < targetSpawnObject.spawnChance.Length; ++i) { //s.spawnObject.spawnChance[i] = EditorGUILayout.IntSlider(s.spawnObject.spawnChance[i], 0, 100); EditorGUI.BeginChangeCheck(); int iThree = EditorGUILayout.IntSlider(s.spawnObject.spawnChance[i], 0, Mathf.Max(100, s.spawnObject.spawnChance[i])); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(obj.targetObject, "Change spawn chance"); s.spawnObject.spawnChance[i] = iThree; } } } EditorGUILayout.EndVertical(); //Make a column of the item prefab pickers EditorGUILayout.BeginVertical(); if (Application.isPlaying) { for (int n = 0; n < s.itemPrefabs.Count; ++n) { //s.spawnObject.spawnChance[i] = EditorGUILayout.IntSlider(s.spawnObject.spawnChance[i], 0, 100); s.itemPrefabs[n] = EditorGUILayout.ObjectField(s.itemPrefabs[n], typeof(GameObject), false); } } else { for (int n = 0; n < targetSpawnObject.spawnChance.Length; ++n) { EditorGUI.BeginChangeCheck(); Object pOne = EditorGUILayout.ObjectField(s.spawnObject.itemPrefab[n], typeof(GameObject), false); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(obj.targetObject, "Change spawn obj"); s.spawnObject.itemPrefab[n] = pOne; } } } EditorGUILayout.EndVertical(); } EditorGUILayout.BeginVertical(); //Plus button if (!Application.isPlaying) { if (GUILayout.Button("Add")) { enlarge = true; } //Minus button if (GUILayout.Button("Remove")) { decrease = true; } } //If we press the plus button, increase the size of the array if (enlarge) { EnlargeArray(); serializedObject.ApplyModifiedProperties(); } EditorGUILayout.EndVertical(); //If we press the minus button, decrease array size if (decrease) { DecreaseArray(); serializedObject.ApplyModifiedProperties(); } EditorGUILayout.EndHorizontal(); } if (GUI.changed) { this.OnEnable(); EditorUtility.SetDirty(target); if (s.spawnObject != null) { EditorUtility.SetDirty(s.spawnObject); } } }
public override void OnInspectorGUI() { //Quick references for when we want to change the size of the array bool enlarge = false; bool decrease = false; EditorGUILayout.LabelField("You can also drag this asset into the 'Spawner Type'"); EditorGUILayout.LabelField("field of a Smart Spawn Script to edit"); serializedObject.Update(); SmartSpawnScriptableObject targetSpawnObject = target as SmartSpawnScriptableObject; if (targetSpawnObject != null) { //Labels if (Application.isPlaying) { EditorGUILayout.LabelField("Note: Values are not saved in playmode"); } EditorGUILayout.LabelField("Spawn ratio", "Object to spawn"); //Start the horizontal (2 per line) GUI layour EditorGUILayout.BeginHorizontal(); if (targetSpawnObject.spawnChance != null) { //Make a column of the spawn chance ratio sliders EditorGUILayout.BeginVertical(); for (int i = 0; i < targetSpawnObject.spawnChance.Length; ++i) { //s.spawnObject.spawnChance[i] = EditorGUILayout.IntSlider(s.spawnObject.spawnChance[i], 0, 100); EditorGUI.BeginChangeCheck(); int iThree = EditorGUILayout.IntSlider(targetSpawnObject.spawnChance[i], 0, 100); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(obj.targetObject, "Change spawn chance"); targetSpawnObject.spawnChance[i] = iThree; } } EditorGUILayout.EndVertical(); //Make a column of the item prefab pickers EditorGUILayout.BeginVertical(); for (int n = 0; n < targetSpawnObject.spawnChance.Length; ++n) { EditorGUI.BeginChangeCheck(); Object pOne = EditorGUILayout.ObjectField(targetSpawnObject.itemPrefab[n], typeof(GameObject), false); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(obj.targetObject, "Change spawn obj"); targetSpawnObject.itemPrefab[n] = pOne; } } EditorGUILayout.EndVertical(); } EditorGUILayout.BeginVertical(); //Plus button if (GUILayout.Button("Add")) { enlarge = true; } //If we press the plus button, increase the size of the array if (enlarge) { EnlargeArray(); serializedObject.ApplyModifiedProperties(); } //Minus button if (GUILayout.Button("Remove")) { decrease = true; } EditorGUILayout.EndVertical(); //If we press the minus button, decrease array size if (decrease) { DecreaseArray(); serializedObject.ApplyModifiedProperties(); } EditorGUILayout.EndHorizontal(); } }