Advertisement
diegographics

Untitled

Apr 19th, 2017
525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.33 KB | None | 0 0
  1. //MD5Hash:6014b3c40b7b1230125095ceba807875;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using System;
  5. using UnityEditor;
  6. using UnityEngine.Events;
  7. using System.Collections.Generic;
  8.  
  9.  
  10. public class MechEditor : UnityEngine.MonoBehaviour
  11. {
  12. [HeaderAttribute("UI Elemente")]
  13. public UnityEngine.UI.Dropdown MechTorso = null;
  14. public UnityEngine.UI.Dropdown MechArms = null;
  15. public UnityEngine.UI.Dropdown MechLegs = null;
  16. public UnityEngine.UI.Dropdown MechHead = null;
  17. [HeaderAttribute("Mech Editor Hilfsobjekte")]
  18. public UnityEngine.GameObject Hanging = null;
  19. public UnityEngine.GameObject Torso = null;
  20. public UnityEngine.GameObject Arms = null;
  21. public UnityEngine.GameObject Legs = null;
  22. public UnityEngine.GameObject Head = null;
  23. [HeaderAttribute("Deffinition der Komponenten")]
  24. public MechPart_Torso[] MechTorso_List = null;
  25. public MechPart_Arm[] MechArm_List = null;
  26. public MechPart_Leg[] MechLeg_List = null;
  27. public MechPart_Head[] MechHead_List = null;
  28. public MechEditor.MechConstruct MechConstruction = new MechEditor.MechConstruct();
  29.  
  30.  
  31. [ContextMenu("Hilfe")]
  32. public void ContextMenu()
  33. {
  34. UnityEditor.Help.BrowseURL("https://valentinwinkelmann.com/");
  35. }
  36. void Start()
  37. {
  38. MenuEvents();
  39. Fill_UI();
  40. }
  41. void Update()
  42. {
  43. }
  44. public void MenuEvents()
  45. {
  46. UnityEngine.UI.Dropdown Dropdown_Dropdown_Torso = null;
  47.  
  48. MechTorso.onValueChanged.AddListener(delegate (int arg0)
  49. {
  50. BuildMech_Part(arg0, MechPart_Type.Torso);
  51. });
  52. MechArms.onValueChanged.AddListener(delegate (int arg0)
  53. {
  54. BuildMech_Part(arg0, MechPart_Type.Arm);
  55. });
  56. MechLegs.onValueChanged.AddListener(delegate (int arg0)
  57. {
  58. UnityEngine.Debug.Log(arg0);
  59. });
  60. }
  61. public void InitializeMech()
  62. {
  63. }
  64. public void BuildMech_Torso(int Index)
  65. {
  66. if ((Torso.transform.GetChildCount() > 0))
  67. {
  68. ///Chech if mech part allready exists and delete when true...
  69. UnityEngine.Object.Destroy(Torso.transform.GetChild(0).gameObject);
  70. UnityEngine.Object.Instantiate(MechTorso_List[Index].Prefab, new UnityEngine.Vector3(0f, 0f, 0f), new UnityEngine.Quaternion(0f, 0f, 0f, 0f), Torso.transform);
  71. }
  72. else
  73. {
  74. UnityEngine.Object.Instantiate(MechTorso_List[Index].Prefab, new UnityEngine.Vector3(0f, 0f, 0f), new UnityEngine.Quaternion(0f, 0f, 0f, 0f), Torso.transform);
  75. }
  76.  
  77. }
  78. public void BuildMech_Arms(int Index)
  79. {
  80. }
  81. public void Fill_UI()
  82. {
  83. System.Collections.Generic.List<string> MechTorso_List1 = new System.Collections.Generic.List<string>();
  84. System.Collections.Generic.List<string> MechArm_List1 = new System.Collections.Generic.List<string>();
  85. System.Collections.Generic.List<string> MechLeg_List1 = new System.Collections.Generic.List<string>();
  86. System.Collections.Generic.List<string> MechHead_List1 = new System.Collections.Generic.List<string>();
  87.  
  88. foreach (var iterator_156 in MechTorso_List)
  89. {
  90. MechTorso_List1.Add(iterator_156.name);
  91. }
  92. MechTorso.AddOptions(MechTorso_List1);
  93. foreach (var iterator_173 in MechArm_List)
  94. {
  95. MechArm_List1.Add(iterator_173.name);
  96. }
  97. MechArms.AddOptions(MechArm_List1);
  98. foreach (var iterator_186 in MechLeg_List)
  99. {
  100. MechLeg_List1.Add(iterator_186.name);
  101. }
  102. MechLegs.AddOptions(MechLeg_List1);
  103. foreach (var iterator_193 in MechHead_List)
  104. {
  105. MechHead_List1.Add(iterator_193.name);
  106. }
  107. MechHead.AddOptions(MechHead_List1);
  108. }
  109. public UnityEngine.GameObject FindMechPart(MechPart_Direction Direction, MechPart_Type Type, int Index)
  110. {
  111. UnityEngine.GameObject _GameObject = null;
  112.  
  113. switch (Type)
  114. {
  115. case MechPart_Type.Torso:
  116. _GameObject = MechTorso_List[Index].Prefab;
  117. break;
  118. case MechPart_Type.Arm:
  119. switch (Direction)
  120. {
  121. case MechPart_Direction.left:
  122. _GameObject = MechArm_List[Index].Prefab_LeftArm;
  123. break;
  124. case MechPart_Direction.right:
  125. _GameObject = MechArm_List[Index].Prefab_RightArm;
  126. break;
  127. default:
  128. break;
  129. }
  130.  
  131. break;
  132. case MechPart_Type.Leg:
  133. switch (Direction)
  134. {
  135. case MechPart_Direction.left:
  136. _GameObject = MechLeg_List[Index].Prefab_LeftLeg;
  137. break;
  138. case MechPart_Direction.right:
  139. _GameObject = MechLeg_List[Index].Prefab_RightLeg;
  140. break;
  141. default:
  142. break;
  143. }
  144.  
  145. break;
  146. case MechPart_Type.Head:
  147. _GameObject = MechHead_List[Index].Prefab;
  148. break;
  149. default:
  150. break;
  151. }
  152.  
  153. return _GameObject;
  154. }
  155. public bool CheckPart(MechPart_Type Type)
  156. {
  157. bool _bool = false;
  158.  
  159. switch (Type)
  160. {
  161. case MechPart_Type.Torso:
  162. _bool = (Torso.transform.GetChildCount() > 0);
  163. break;
  164. case MechPart_Type.Arm:
  165. _bool = (Arms.transform.GetChildCount() > 0);
  166. break;
  167. case MechPart_Type.Leg:
  168. _bool = (Legs.transform.GetChildCount() > 0);
  169. break;
  170. case MechPart_Type.Head:
  171. _bool = (Head.transform.GetChildCount() > 0);
  172. break;
  173. default:
  174. break;
  175. }
  176.  
  177. return _bool;
  178. }
  179. public void DeletePart(MechPart_Type Type)
  180. {
  181. UnityEngine.GameObject _GameObject1 = null;
  182.  
  183. switch (Type)
  184. {
  185. case MechPart_Type.Torso:
  186. _GameObject1 = Torso;
  187. break;
  188. case MechPart_Type.Arm:
  189. _GameObject1 = Arms;
  190. break;
  191. case MechPart_Type.Leg:
  192. _GameObject1 = Legs;
  193. break;
  194. case MechPart_Type.Head:
  195. default:
  196. _GameObject1 = Head;
  197. break;
  198. }
  199.  
  200. if (CheckPart(MechPart_Type.Torso))
  201. {
  202. for (int i_402 = 0; i_402 < _GameObject1.transform.GetChildCount(); i_402++)
  203. {
  204. UnityEngine.Object.Destroy(_GameObject1.transform.GetChild(i_402).gameObject);
  205. }
  206. }
  207. else
  208. {
  209. UnityEngine.Debug.Log("Schmuuuuu");
  210. }
  211.  
  212. }
  213. public void BuildMech_Part(int Index, MechPart_Type Type)
  214. {
  215. DeletePart(Type);
  216. switch (Type)
  217. {
  218. case MechPart_Type.Torso:
  219. UnityEngine.Object.Instantiate(FindMechPart(MechPart_Direction.none, Type, Index), new UnityEngine.Vector3(0f, 0f, 0f), new UnityEngine.Quaternion(0f, 0f, 0f, 0f), Torso.transform);
  220. FindJoint(MechPart_Type.Torso);
  221. break;
  222. case MechPart_Type.Arm:
  223. ///Right Arm Instantiating
  224. var _TempVar_336_1 = Arms.transform;
  225. UnityEngine.Object.Instantiate(FindMechPart(MechPart_Direction.right, Type, Index), GetJoint("Right_Arm"), new UnityEngine.Quaternion(0f, 0f, 0f, 0f), _TempVar_336_1);
  226. ///Left Arm Instantiating
  227. UnityEngine.Object.Instantiate(FindMechPart(MechPart_Direction.left, Type, Index), GetJoint("Left_Arm"), new UnityEngine.Quaternion(0f, 0f, 0f, 0f), _TempVar_336_1);
  228. break;
  229. case MechPart_Type.Leg:
  230. UnityEngine.Object.Instantiate(FindMechPart(MechPart_Direction.right, Type, Index), new UnityEngine.Vector3(0f, 0f, 0f), new UnityEngine.Quaternion(0f, 0f, 0f, 0f), Legs.transform);
  231. UnityEngine.Object.Instantiate(FindMechPart(MechPart_Direction.left, Type, Index), new UnityEngine.Vector3(0f, 0f, 0f), new UnityEngine.Quaternion(0f, 0f, 0f, 0f), Legs.transform);
  232. break;
  233. case MechPart_Type.Head:
  234. UnityEngine.Object.Instantiate(FindMechPart(MechPart_Direction.none, Type, Index), new UnityEngine.Vector3(0f, 0f, 0f), new UnityEngine.Quaternion(0f, 0f, 0f, 0f), Head.transform);
  235. break;
  236. default:
  237. break;
  238. }
  239.  
  240. }
  241. public void FindJoint(MechPart_Type Type)
  242. {
  243. switch (Type)
  244. {
  245. case MechPart_Type.Torso:
  246. for (int i_420 = 0; i_420 < Torso.transform.GetChild(0).GetChildCount(); i_420++)
  247. {
  248. var _TempVar_417_2 = Torso.transform.GetChild(0).GetChild(i_420);
  249. if (MechConstruction.JointDictionary.ContainsKey(_TempVar_417_2.name))
  250. {
  251. MechConstruction.JointDictionary.Remove(_TempVar_417_2.name);
  252. MechConstruction.JointDictionary.Add(_TempVar_417_2.name, _TempVar_417_2.position);
  253. }
  254. else
  255. {
  256. MechConstruction.JointDictionary.Add(_TempVar_417_2.name, _TempVar_417_2.position);
  257. }
  258.  
  259. }
  260. break;
  261. default:
  262. break;
  263. }
  264.  
  265. }
  266. public UnityEngine.Vector3 GetJoint(string JointName)
  267. {
  268. return MechConstruction.JointDictionary[JointName];
  269. }
  270. [SerializableAttribute]
  271. public class MechPart_Torso
  272. {
  273. public string name = "";
  274. public UnityEngine.GameObject Prefab = null;
  275. [TextAreaAttribute]
  276. public string Description = "";
  277.  
  278. public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
  279. {
  280. }
  281. }
  282. [SerializableAttribute]
  283. public class MechPart_Arm
  284. {
  285. public string name = "";
  286. public UnityEngine.GameObject Prefab_RightArm = null;
  287. public UnityEngine.GameObject Prefab_LeftArm = null;
  288. [TextAreaAttribute]
  289. public string Description = "";
  290. }
  291. [SerializableAttribute]
  292. public class MechPart_Leg
  293. {
  294. public string name = "";
  295. public UnityEngine.GameObject Prefab_RightLeg = null;
  296. public UnityEngine.GameObject Prefab_LeftLeg = null;
  297. [TextAreaAttribute]
  298. public string Description = "";
  299. }
  300. [SerializableAttribute]
  301. public class MechPart_Head
  302. {
  303. public string name = "";
  304. public UnityEngine.GameObject Prefab = null;
  305. [TextAreaAttribute]
  306. public string Description = "";
  307. }
  308. public class MechConstruct
  309. {
  310. public UnityEngine.Vector3 Arm_Left_Position;
  311. public UnityEngine.Vector3 Arm_Right_Position;
  312. public UnityEngine.Vector3 Leg_Left_Position;
  313. public UnityEngine.Vector3 Leg_Right_Position;
  314. public System.Collections.Generic.Dictionary<string, UnityEngine.Vector3> JointDictionary = new System.Collections.Generic.Dictionary<string, UnityEngine.Vector3>();
  315. }
  316. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement