static void CreateScripts() { if (Selection.gameObjects != null && Selection.gameObjects.Length >= 1) { GameObject go = Selection.gameObjects[0]; UITypeSign sign = go.GetComponent <UITypeSign>(); if (sign == null) { EditorUtility.DisplayDialog("错误", "选中物体并未添加UITypeSign组件!", "确认"); } else { // if (sign.Type == UIType.UIRoot) // { // //开始生成代码 // CreateScriptsToFile(go.transform); // } // else // { // EditorUtility.DisplayDialog("错误", "选中物体并不是UI根节点!", "确认"); // } } } else { EditorUtility.DisplayDialog("错误", "请先选中UI Root,再进行该操作!", "确认"); } }
static void GetUITypeSignDic(Transform root, string path) { if (root == null) { return; } UITypeSign sign = root.GetComponent <UITypeSign>(); // if (sign != null && sign.Type != UIType.UIRoot) // { // m_interactionUIDic.Add(path, sign); // } if (root.childCount > 0) { for (int i = 0; i < root.childCount; i++) { GetUITypeSignDic(root.GetChild(i), string.IsNullOrEmpty(path) ? root.GetChild(i).name : path + "/" + root.GetChild(i).name); } } return; }
static void AddUIType(UIType type) { if (Selection.gameObjects != null && Selection.gameObjects.Length >= 1) { int count = Selection.gameObjects.Length; for (int i = 0; i < count; i++) { GameObject go = Selection.gameObjects[i]; UITypeSign sign = go.AddComponent <UITypeSign>(); switch (type) { // case UIType.UIRoot: // sign.Type = UIType.UIRoot; // break; case UIType.Transform: sign.Type = UIType.Transform; break; case UIType.Text: sign.Type = UIType.Text; break; case UIType.Image: sign.Type = UIType.Image; break; case UIType.RawImage: sign.Type = UIType.RawImage; break; case UIType.Button: sign.Type = UIType.Button; break; case UIType.Toggle: sign.Type = UIType.Toggle; break; case UIType.Slider: sign.Type = UIType.Slider; break; case UIType.Scrollbar: sign.Type = UIType.Scrollbar; break; case UIType.Dropdown: sign.Type = UIType.Dropdown; break; case UIType.InputField: sign.Type = UIType.InputField; break; case UIType.ScrollRect: sign.Type = UIType.ScrollRect; break; default: break; } } } }