Пример #1
0
        public static bool LoadDatabase(bool silent = false)
        {
            if (XXToolsEditorGlobal._db != null)
            {
                return(true);
            }

            if (!XXToolsEdUtil.RelativeFileExist(DB_FILE))
            {
                Debug.LogError("You must first create a Database. From the menu, select: Window -> XXTools -> Database");
                if (!silent)
                {
                    EditorUtility.DisplayDialog("Warning", "You must first create a Database. From the menu, select: Window -> XXTools -> Database", "Close");
                }
                return(false);
            }
            else
            {
                GameObject go = AssetDatabase.LoadAssetAtPath(DB_FILE, typeof(GameObject)) as GameObject;
                XXToolsEditorGlobal._db = go.GetComponent <Database>();
                if (_db != null)
                {
                    PerformAfterDBLoaded(_db);
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
        private void CreateActor(GameObject model)
        {
            string fn = XXToolsEditorGlobal.DB_ACTOR_PATH + model.name + ".prefab";

            if (XXToolsEdUtil.RelativeFileExist(fn))
            {
                fn = AssetDatabase.GenerateUniqueAssetPath(fn);
            }

            GameObject go = PrefabUtility.CreatePrefab(fn, model);

            XXToolsEditorGlobal.DB.actorsPrefabs.Add(go);
            EditorUtility.SetDirty(XXToolsEditorGlobal.DB);
            AssetDatabase.SaveAssets();


            Actor actor = go.AddComponent <Actor>();

            // 扫描 skinnedMesh
            SkinnedMeshRenderer [] smrs = model.GetComponentsInChildren <SkinnedMeshRenderer>();

            List <Actor.ActorComponent> acList = new List <Actor.ActorComponent>();

            foreach (SkinnedMeshRenderer smr in smrs)
            {
                string[]             strs   = smr.name.Split('_');
                string               endStr = "_" + strs[strs.Length - 1];
                Actor.ActorComponent ac     = new Actor.ActorComponent(strs[strs.Length - 1], endStr, smr);
                acList.Add(ac);
            }

            actor.InitActor(actor.gameObject, acList);
        }
Пример #3
0
 private static void DeleteDatabasePath(string path)
 {
     if (XXToolsEdUtil.RelativePathExist(path))
     {
         Debug.Log("Deleting all assets in: " + path);
         path = path.Substring(0, path.LastIndexOf('/'));                // remove last '/'
         AssetDatabase.DeleteAsset(path);
     }
 }
Пример #4
0
 public static void CheckDatabasePath(string parentPath, string newPath)
 {
     if (!XXToolsEdUtil.RelativePathExist(newPath))
     {
         //Debug.Log("Creating: " + newPath);
         parentPath = parentPath.Substring(0, parentPath.LastIndexOf('/'));  // remove last '/'
         newPath    = newPath.Substring(0, newPath.LastIndexOf('/'));        // remove last '/'
         newPath    = newPath.Substring(newPath.LastIndexOf('/') + 1);
         AssetDatabase.CreateFolder(parentPath, newPath);
     }
 }
Пример #5
0
 public static void LoadOrCreateDatabase()
 {
     if (!XXToolsEdUtil.RelativeFileExist(DB_FILE))
     {
         CreateDatabase();
     }
     else
     {
         GameObject go = AssetDatabase.LoadAssetAtPath(DB_FILE, typeof(GameObject)) as GameObject;
         _db = go.GetComponent <Database>();
         PerformAfterDBLoaded(_db);
     }
 }
Пример #6
0
        public override void OnEnable(DatabaseEditor ed)
        {
            base.OnEnable(ed);

            int cnt = ed.db.actorsPrefabs.Count;

            ed.db.actorsPrefabs = XXToolsEdUtil.CleanupList <GameObject>(ed.db.actorsPrefabs);
            if (cnt != ed.db.actorsPrefabs.Count)
            {
                EditorUtility.SetDirty(ed.db);
                AssetDatabase.SaveAssets();
            }
        }
Пример #7
0
        private void CreateActor(FileInfo fileInfo)
        {
            string path = fileInfo.FullName;

            path = XXToolsEdUtil.ProjectRelativePath(path);
            GameObject go = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject;

            if (go == null)
            {
                return;
            }
            CreateActor(go);
            EditorUtility.UnloadUnusedAssetsImmediate();
        }
Пример #8
0
        private void LoadAC()
        {
            string        pathFolder = ed.db.name2Paths[0].path + "Component/";
            DirectoryInfo dirInfo    = new DirectoryInfo(pathFolder);

            FileInfo[]        fileInfos = dirInfo.GetFiles("*.fbx");
            List <GameObject> gos       = new List <GameObject>();

            foreach (FileInfo fileInfo in fileInfos)
            {
                string     path = XXToolsEdUtil.ProjectRelativePath(fileInfo.FullName);
                GameObject go   = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject;
                string     name = go.name;
                go = PrefabUtility.CreatePrefab(XXToolsEditorGlobal.DB_ACTORCOM_PATH + go.name + ".prefab", go);
                gos.Add(go);
            }
            EditorUtility.UnloadUnusedAssetsImmediate();
            ed.db.actorComponesPrefabs = gos;
        }
Пример #9
0
        private string [] ShowFindNamePath(int i)
        {
            string pattern = ".*";

            switch (i)
            {
            case 0: pattern = "*.fbx"; break;

            case 1: pattern = "*.anim"; break;

            case 2: pattern = "*.controller"; break;
            }

            string path = XXToolsEdUtil.FullProjectPath + ed.db.name2Paths[i].path;

            Debug.Log("path:" + path);
            List <string> findes = XXToolsEdUtil.FindFileNames(path, pattern);

            return(findes.ToArray());
        }
Пример #10
0
        public static List <T> FindPrefabsOfTypeAll <T>(string progressbarTitle, string progressbarInfo)
            where T : Component
        {
            DirectoryInfo dir = new DirectoryInfo(XXToolsEdUtil.FullProjectAssetsPath);

            FileInfo[] files = dir.GetFiles("*.prefab", SearchOption.AllDirectories);
            string     fn    = "";

            float progress = 0f;
            float step     = 1f / (float)files.Length;

            EditorUtility.DisplayProgressBar(progressbarTitle, progressbarInfo, progress);

            List <T> res = new List <T>();

            for (int i = 0; i < files.Length; i++)
            {
                progress += step;
                EditorUtility.DisplayProgressBar(progressbarTitle, progressbarInfo, progress);
                if (files[i] == null)
                {
                    continue;
                }
                fn = XXToolsEdUtil.ProjectRelativePath(files[i].FullName);
                if (!string.IsNullOrEmpty(fn))
                {
                    Object obj = AssetDatabase.LoadAssetAtPath(fn, typeof(T));
                    if (obj != null)
                    {
                        res.Add((T)obj);
                    }
                }
            }
            EditorUtility.ClearProgressBar();

            return(res);
        }
Пример #11
0
        private void LeftPanel()
        {
            EditorGUILayout.BeginVertical(GUILayout.Width(DatabaseEditor.LeftPanelWidth));
            GUILayout.Space(5);
            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.FlexibleSpace();
                if (GUILayout.Button(new GUIContent("Add Actors", XXToolsEdGui.Icon_Plus), EditorStyles.miniButtonLeft))
                {
                    GUI.FocusControl("");
                    //EditorUtility.OpenFilePanel("Select Scene", XXToolsEdUtil.FullProjectAssetsPath, "unity");
                    //TextInputWiz.Show("New Actor", "Enter name for new actor", "", CreateActor);
                    CreateActorWiz.Show();
                }
                GUI.enabled = true;
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            scroll[0] = XXToolsEdGui.BeginScrollView(scroll[0], GUILayout.Width(DatabaseEditor.LeftPanelWidth));
            {
                if (ed.db.Actors.Length > 0)
                {
                    foreach (Actor actor in ed.db.Actors)
                    {
                        if (actor == null)
                        {
                            ed.db.actorsPrefabs = XXToolsEdUtil.CleanupList <GameObject>(ed.db.actorsPrefabs);
                            EditorUtility.SetDirty(ed.db);
                            AssetDatabase.SaveAssets();
                            GUIUtility.ExitGUI();
                            return;
                        }

                        EditorGUILayout.BeginHorizontal(GUILayout.Width(DatabaseEditor.LeftPanelWidth - 20), GUILayout.ExpandWidth(false));
                        {
                            if (XXToolsEdGui.ToggleButton(curr == actor, actor.name, XXToolsEdGui.ButtonLeftStyle, GUILayout.Width(160), GUILayout.ExpandWidth(false)))
                            {
                                GUI.FocusControl("");
                                curr   = actor;
                                currAc = null;
                                //GetCurrentEd();
                            }

                            //if (ed.db.Cameras.Length == 1) GUI.enabled = false; // can't allow deleting the camera if there is only one left since runtime depends on at least one being present
                            if (GUILayout.Button("X", XXToolsEdGui.ButtonRightStyle, GUILayout.Width(20)))
                            {
                                del = actor;
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }
                else
                {
                    GUILayout.Label("No Actors are defined.", XXToolsEdGui.WarningLabelStyle);
                }
            }
            XXToolsEdGui.EndScrollView();

            GUILayout.Space(3);
            EditorGUILayout.EndVertical();

            if (del != null)
            {
                if (curr == del)
                {
                    curr = null;
                }
                ed.db.actorsPrefabs.Remove(del.gameObject);
                EditorUtility.SetDirty(ed.db);
                AssetDatabase.SaveAssets();

                string path = AssetDatabase.GetAssetPath(del.gameObject);
                AssetDatabase.DeleteAsset(path);
                AssetDatabase.Refresh();
                del = null;
            }
        }