Advertisement
diegographics

Untitled

Apr 19th, 2017
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.17 KB | None | 0 0
  1. //MD5Hash:7d8b94187d69beb7c809f2d6224883fe;
  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.             UnityEngine.Debug.Log(arg0);
  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.                 var _TempVar_336_1 = Arms.transform;
  224.                 UnityEngine.Object.Instantiate(FindMechPart(MechPart_Direction.right, Type, Index), new UnityEngine.Vector3(0f, 0f, 0f), new UnityEngine.Quaternion(0f, 0f, 0f, 0f), _TempVar_336_1);
  225.                 UnityEngine.Object.Instantiate(FindMechPart(MechPart_Direction.left, Type, Index), new UnityEngine.Vector3(0f, 0f, 0f), new UnityEngine.Quaternion(0f, 0f, 0f, 0f), _TempVar_336_1);
  226.                 break;
  227.             case MechPart_Type.Leg:
  228.                 UnityEngine.Object.Instantiate(FindMechPart(MechPart_Direction.right, Type, Index), new UnityEngine.Vector3(0f, 0f, 0f), new UnityEngine.Quaternion(0f, 0f, 0f, 0f), Legs.transform);
  229.                 UnityEngine.Object.Instantiate(FindMechPart(MechPart_Direction.left, Type, Index), new UnityEngine.Vector3(0f, 0f, 0f), new UnityEngine.Quaternion(0f, 0f, 0f, 0f), Legs.transform);
  230.                 break;
  231.             case MechPart_Type.Head:
  232.                 UnityEngine.Object.Instantiate(FindMechPart(MechPart_Direction.none, Type, Index), new UnityEngine.Vector3(0f, 0f, 0f), new UnityEngine.Quaternion(0f, 0f, 0f, 0f), Head.transform);
  233.                 break;
  234.             default:
  235.                 break;
  236.         }
  237.        
  238.     }
  239.     public void FindJoint(MechPart_Type Type)
  240.     {
  241.         switch (Type)
  242.         {
  243.             case MechPart_Type.Torso:
  244.                 for (int i_420 = 0; i_420 < Torso.transform.GetChild(0).GetChildCount(); i_420++)
  245.                 {
  246.                     var _TempVar_417_2 = Torso.transform.GetChild(0).GetChild(i_420);
  247.                     if (MechConstruction.JointDictionary.ContainsKey(_TempVar_417_2.name))
  248.                     {
  249.                         MechConstruction.JointDictionary.Remove(_TempVar_417_2.name);
  250.                         MechConstruction.JointDictionary.Add(_TempVar_417_2.name, _TempVar_417_2.position);
  251.                     }
  252.                     else
  253.                     {
  254.                         MechConstruction.JointDictionary.Add(_TempVar_417_2.name, _TempVar_417_2.position);
  255.                     }
  256.  
  257.                 }
  258.                 break;
  259.             default:
  260.                 break;
  261.         }
  262.        
  263.     }
  264.     [SerializableAttribute]
  265.     public class MechPart_Torso
  266.     {
  267.         public string name = "";
  268.         public UnityEngine.GameObject Prefab = null;
  269.         [TextAreaAttribute]
  270.         public string Description = "";
  271.  
  272.         public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
  273.         {
  274.         }
  275.     }
  276.     [SerializableAttribute]
  277.     public class MechPart_Arm
  278.     {
  279.         public string name = "";
  280.         public UnityEngine.GameObject Prefab_RightArm = null;
  281.         public UnityEngine.GameObject Prefab_LeftArm = null;
  282.         [TextAreaAttribute]
  283.         public string Description = "";
  284.     }
  285.     [SerializableAttribute]
  286.     public class MechPart_Leg
  287.     {
  288.         public string name = "";
  289.         public UnityEngine.GameObject Prefab_RightLeg = null;
  290.         public UnityEngine.GameObject Prefab_LeftLeg = null;
  291.         [TextAreaAttribute]
  292.         public string Description = "";
  293.     }
  294.     [SerializableAttribute]
  295.     public class MechPart_Head
  296.     {
  297.         public string name = "";
  298.         public UnityEngine.GameObject Prefab = null;
  299.         [TextAreaAttribute]
  300.         public string Description = "";
  301.     }
  302.     public class MechConstruct
  303.     {
  304.         public UnityEngine.Vector3 Arm_Left_Position;
  305.         public UnityEngine.Vector3 Arm_Right_Position;
  306.         public UnityEngine.Vector3 Leg_Left_Position;
  307.         public UnityEngine.Vector3 Leg_Right_Position;
  308.         public System.Collections.Generic.Dictionary<string, UnityEngine.Vector3> JointDictionary = new System.Collections.Generic.Dictionary<string, UnityEngine.Vector3>();
  309.     }
  310. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement