Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.15 KB | None | 0 0
  1. #if UNITY_EDITOR
  2.  
  3.     using UnityEditor;
  4.     using UnityEngine;
  5.     using Sirenix.OdinInspector.Editor;
  6.     using Sirenix.OdinInspector;
  7.     using Sirenix.Utilities.Editor;
  8.     using Sirenix.Utilities;
  9.     using System.Collections.Generic;
  10.     using System;
  11.  
  12. public class K_Odin_EnemyLayer : MonoBehaviour
  13. {
  14.     public SettingsData Settings = new SettingsData();
  15.     [TableList(DrawScrollView = true, MaxScrollViewHeight = 380, MinScrollViewHeight = 100)]
  16.     public List<Object_Layer> Prefabs = new List<Object_Layer>();
  17.     public List<Object_Layer> Level_Prefabs = new List<Object_Layer>();
  18.  
  19. } // class ends here
  20.          [Serializable] // makes it visible in Editor Inspector
  21.     public class SettingsData
  22.     {
  23.         public bool SelectAfterSpawn;
  24.         public Vector3 SpawnLocation;
  25.         public int HowMany;
  26.     }
  27.    
  28.         [Serializable]
  29.     public class Object_Layer
  30.     {
  31.         [TableColumnWidth(57, Resizable = false)]
  32.         [PreviewField(Alignment = Sirenix.OdinInspector.ObjectFieldAlignment.Center)]
  33.        
  34.         public Texture Icon; // texture for spawning enemy
  35.  
  36.         [TextArea]
  37.         public string Notes; // notes on enemy such as should be 3 Y location etc
  38.  
  39.        
  40.         [EnumToggleButtons]
  41.         public en_Path _enemyPath; // so far I have them in resources folder such as: Enemies & Level
  42.        
  43.         public enum en_Path
  44.         {
  45.             Enemies, Level
  46.         }
  47.        
  48.  
  49.         [VerticalGroup("E_Name"), LabelWidth(12)]
  50.         public string _enemyName;
  51.  
  52.         [TableColumnWidth(60)]
  53.         [Button, VerticalGroup("Buttons")]
  54.         public void Spawn()
  55.         {
  56.             var manager = GameObject.FindObjectOfType<K_Odin_EnemyLayer>();
  57.             if (manager == null) return;
  58.             Vector3 _spawnloc = manager.Settings.SpawnLocation;
  59.             int _howMany = manager.Settings.HowMany;
  60.             bool _selectAfterSpawn = manager.Settings.SelectAfterSpawn;
  61.             // notify unity log what we about to spawn and its details
  62.             Debug.Log("Amount: " + _howMany + " Spawning Loc: " + _spawnloc + "| Enemy: " + _enemyName + " from location: " + _enemyPath + "\n Notes: " + Notes);
  63.             string Path = _enemyPath+"/"+_enemyName;
  64.            
  65.             GameObject parent = GameObject.Find("NewSpawns"); // the daddy of the new spawns now
  66.             if(!parent)
  67.             {
  68.                 parent = new GameObject ("NewSpawns"); // create this object if not in scene
  69.             }
  70.             for (int i = 0; i < _howMany ; i++) // if more than one create multiples of
  71.             {
  72.                 // GameObject newSpawn = Instantiate (Resources.Load (Path) as GameObject);
  73.                 GameObject newSpawn = PrefabUtility.InstantiatePrefab(Resources.Load(Path) as GameObject) as GameObject;
  74.                 if(newSpawn==null)
  75.                 {
  76.                     Debug.LogWarning("!!! Error spawning !!!" + _enemyName);
  77.                     return;
  78.                 }
  79.                 newSpawn.name = _enemyName;
  80.                 newSpawn.transform.position = _spawnloc;
  81.                 newSpawn.transform.SetParent(parent.transform);
  82.                 if (_selectAfterSpawn)
  83.                     Selection.activeGameObject = newSpawn; 
  84.             } // for loop ends
  85.         } // Spawn ends here
  86.        
  87.         [TableColumnWidth(60)]
  88.         [Button, VerticalGroup("Buttons")]
  89.         public void Other()
  90.         {
  91.            
  92.         }
  93.     } // K Odin Enemy Layer ends here
  94.    
  95.  
  96. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement