Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if UNITY_EDITOR
- using UnityEditor;
- using UnityEngine;
- using Sirenix.OdinInspector.Editor;
- using Sirenix.OdinInspector;
- using Sirenix.Utilities.Editor;
- using Sirenix.Utilities;
- using System.Collections.Generic;
- using System;
- public class K_Odin_EnemyLayer : MonoBehaviour
- {
- public SettingsData Settings = new SettingsData();
- [TableList(DrawScrollView = true, MaxScrollViewHeight = 380, MinScrollViewHeight = 100)]
- public List<Object_Layer> Prefabs = new List<Object_Layer>();
- public List<Object_Layer> Level_Prefabs = new List<Object_Layer>();
- } // class ends here
- [Serializable] // makes it visible in Editor Inspector
- public class SettingsData
- {
- public bool SelectAfterSpawn;
- public Vector3 SpawnLocation;
- public int HowMany;
- }
- [Serializable]
- public class Object_Layer
- {
- [TableColumnWidth(57, Resizable = false)]
- [PreviewField(Alignment = Sirenix.OdinInspector.ObjectFieldAlignment.Center)]
- public Texture Icon; // texture for spawning enemy
- [TextArea]
- public string Notes; // notes on enemy such as should be 3 Y location etc
- [EnumToggleButtons]
- public en_Path _enemyPath; // so far I have them in resources folder such as: Enemies & Level
- public enum en_Path
- {
- Enemies, Level
- }
- [VerticalGroup("E_Name"), LabelWidth(12)]
- public string _enemyName;
- [TableColumnWidth(60)]
- [Button, VerticalGroup("Buttons")]
- public void Spawn()
- {
- var manager = GameObject.FindObjectOfType<K_Odin_EnemyLayer>();
- if (manager == null) return;
- Vector3 _spawnloc = manager.Settings.SpawnLocation;
- int _howMany = manager.Settings.HowMany;
- bool _selectAfterSpawn = manager.Settings.SelectAfterSpawn;
- // notify unity log what we about to spawn and its details
- Debug.Log("Amount: " + _howMany + " Spawning Loc: " + _spawnloc + "| Enemy: " + _enemyName + " from location: " + _enemyPath + "\n Notes: " + Notes);
- string Path = _enemyPath+"/"+_enemyName;
- GameObject parent = GameObject.Find("NewSpawns"); // the daddy of the new spawns now
- if(!parent)
- {
- parent = new GameObject ("NewSpawns"); // create this object if not in scene
- }
- for (int i = 0; i < _howMany ; i++) // if more than one create multiples of
- {
- // GameObject newSpawn = Instantiate (Resources.Load (Path) as GameObject);
- GameObject newSpawn = PrefabUtility.InstantiatePrefab(Resources.Load(Path) as GameObject) as GameObject;
- if(newSpawn==null)
- {
- Debug.LogWarning("!!! Error spawning !!!" + _enemyName);
- return;
- }
- newSpawn.name = _enemyName;
- newSpawn.transform.position = _spawnloc;
- newSpawn.transform.SetParent(parent.transform);
- if (_selectAfterSpawn)
- Selection.activeGameObject = newSpawn;
- } // for loop ends
- } // Spawn ends here
- [TableColumnWidth(60)]
- [Button, VerticalGroup("Buttons")]
- public void Other()
- {
- }
- } // K Odin Enemy Layer ends here
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement