Exemplo n.º 1
0
        static void generateOrUpdateSelected(Type baseType, bool rootOnly = true)
        {
            pref = UGUIAutoScriptPref.getDefaultPref();
            string dir;

            if (Directory.Exists(pref.lastDir))
            {
                dir = pref.lastDir;
            }
            else
            {
                dir          = EditorUtility.OpenFolderPanel("将脚本文件保存至", "Assets", string.Empty);
                pref.lastDir = dir.Replace(Environment.CurrentDirectory + "\\", string.Empty);//保存上一次的地址
            }
            if (!string.IsNullOrEmpty(dir))
            {
                updatedGameObjectDic.Clear();
                foreach (GameObject gameObject in Selection.gameObjects)
                {
                    if (rootOnly)
                    {
                        Component component = gameObject.GetComponent(baseType);
                        if (component != null)
                        {
                            generateOrUpdateRoot(dir, null, gameObject, component.GetType().BaseType);
                        }
                        else
                        {
                            generateOrUpdateRoot(dir, null, gameObject, baseType);
                        }
                    }
                    else
                    {
                        Component[] components = gameObject.GetComponentsInChildren(baseType, true);
                        if (components.Length > 0)
                        {
                            Component rootComponent = gameObject.GetComponent(baseType);
                            if (rootComponent != null)
                            {
                                generateOrUpdateRoot(dir, null, gameObject, rootComponent.GetType().BaseType);
                            }
                            else
                            {
                                generateOrUpdateRoot(dir, null, gameObject, baseType);
                            }
                            foreach (Component component in components)
                            {
                                generateOrUpdateRoot(dir, gameObject, component.gameObject, component.GetType().BaseType);
                            }
                        }
                        else
                        {
                            generateOrUpdateRoot(dir, null, gameObject, baseType);//没有,重新生成
                        }
                    }
                }
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
            }
        }
Exemplo n.º 2
0
        public static UGUIAutoScriptPref getDefaultPref()
        {
            UGUIAutoScriptPref pref = AssetDatabase.LoadAssetAtPath <UGUIAutoScriptPref>("Assets/Editor/UIScriptGeneratorPrefs.asset");

            if (pref == null)
            {
                pref = CreateInstance <UGUIAutoScriptPref>();
                if (!Directory.Exists("Assets/Editor"))
                {
                    Directory.CreateDirectory("Assets/Editor");
                }
                AssetDatabase.CreateAsset(pref, "Assets/Editor/UIScriptGeneratorPrefs.asset");
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
            }
            return(pref);
        }