Advertisement
Bagserk

CreateTransforms

May 23rd, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.76 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System;
  8.  
  9. public class CreateTransforms : EditorWindow
  10. {
  11.     //clothes = 0
  12.     //swimsuit = 1
  13.     //gloves = 2
  14.     //shoes = 3
  15.  
  16.     public int objType = 0;
  17.     // Use this for initialization
  18.     [MenuItem("HoneySelect/Create Transforms")]
  19.     static void Init()
  20.     {
  21.         CreateTransforms window = (CreateTransforms)EditorWindow.GetWindow(typeof(CreateTransforms));
  22.         window.Show();
  23.     }
  24.  
  25.     // Update is called once per frame
  26.     void OnGUI()
  27.     {
  28.         GUILayout.Label("Create Transforms", EditorStyles.boldLabel);                        
  29.         if (GUILayout.Button("Clothes"))
  30.         {
  31.             objType = 0;
  32.             aCreateTransforms(objType);
  33.         }
  34.         else if (GUILayout.Button("Swimsuit"))
  35.         {
  36.             objType = 1;
  37.             aCreateTransforms(objType);
  38.         }
  39.         else if (GUILayout.Button("Gloves"))
  40.         {
  41.             objType = 2;
  42.             aCreateTransforms(objType);
  43.         }
  44.         else if (GUILayout.Button("Shoes"))
  45.         {
  46.             objType = 3;
  47.             aCreateTransforms(objType);
  48.         }
  49.         else if (GUILayout.Button("Socks"))
  50.         {
  51.             objType = 4;
  52.             aCreateTransforms(objType);
  53.         }
  54.         else if (GUILayout.Button("Accessory"))
  55.         {
  56.             objType = 5;
  57.             aCreateTransforms(objType);
  58.         }
  59.         else if (GUILayout.Button("Bra"))
  60.         {
  61.             objType = 6;
  62.             aCreateTransforms(objType);
  63.         }
  64.     }
  65.  
  66.     static void aCreateTransforms(int objType)
  67.     {
  68.         switch (objType)
  69.         {
  70.             case 0:                
  71.                 Transform rootTransform = Selection.activeGameObject.transform;
  72.                 String sPath = "cf_N_O_root/N_cos_00/N_top_00/N_bot_d";
  73.                 CreateTree(rootTransform, sPath);
  74.                 sPath = "cf_N_O_root/N_cos_00/N_top_00/N_top_a";
  75.                 CreateTree(rootTransform, sPath);
  76.                 sPath = "cf_N_O_root/N_cos_00/N_top_00/N_bot_n";
  77.                 CreateTree(rootTransform, sPath);
  78.                 sPath = "cf_N_O_root/N_cos_00/N_top_00/N_top_b";
  79.                 CreateTree(rootTransform, sPath);
  80.                 Selection.activeGameObject = GameObject.Find(sPath);
  81.                 break;
  82.             case 2:            
  83.                 rootTransform = Selection.activeGameObject.transform;
  84.                 sPath = "cf_N_O_root/N_under/N_glove";
  85.                 CreateTree(rootTransform, sPath);
  86.                 Selection.activeGameObject = GameObject.Find(sPath);
  87.                 break;
  88.             case 3:            
  89.                 rootTransform = Selection.activeGameObject.transform;
  90.                 sPath = "cf_N_O_root/N_under/N_shoes";
  91.                 CreateTree(rootTransform, sPath);
  92.                 Selection.activeGameObject = GameObject.Find(sPath);
  93.                 break;
  94.             case 4:            
  95.                 rootTransform = Selection.activeGameObject.transform;
  96.                 sPath = "cf_N_O_root/N_under/N_socks";
  97.                 CreateTree(rootTransform, sPath);
  98.                 Selection.activeGameObject = GameObject.Find(sPath);
  99.                 break;
  100.             case 5:
  101.                 rootTransform = Selection.activeGameObject.transform;
  102.                 sPath = "N_move";
  103.                 CreateTree(rootTransform, sPath);
  104.                 Selection.activeGameObject = GameObject.Find(sPath);
  105.                 break;
  106.             case 6:            
  107.                 rootTransform = Selection.activeGameObject.transform;
  108.                 sPath = "cf_N_O_root/N_under/N_bra";
  109.                 CreateTree(rootTransform, sPath);
  110.                 Selection.activeGameObject = GameObject.Find(sPath);
  111.                 break;
  112.             default:
  113.                 Console.WriteLine("This should not happen");
  114.                 break;
  115.  
  116.     }
  117.        
  118.     }
  119.  
  120.     static void CreateTree(Transform parent, string path)
  121.     {
  122.         string[] splitted = path.Split('/');
  123.         foreach (string name in splitted)
  124.         {
  125.             if (string.IsNullOrEmpty(name))
  126.                 continue;
  127.             Transform existingTransform = parent.Find(name);
  128.             if (existingTransform == null)
  129.             {
  130.                 GameObject go = new GameObject(name);
  131.                 go.transform.SetParent(parent);
  132.                 go.transform.localPosition = Vector3.zero;
  133.                 go.transform.localRotation = Quaternion.identity;
  134.                 go.transform.localScale = Vector3.one;
  135.                 parent = go.transform;
  136.             }
  137.             else
  138.                 parent = existingTransform;
  139.         }
  140.     }
  141.  
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement