Esempio n. 1
0
        public static void SaveAnotherLayout(Canvas layout, Transform child)
        {
            if (child.GetComponent <Decorate>() != null)
            {
                return;
            }
            GameObject child_obj = child.gameObject;
            //Debug.Log("child type :" + PrefabUtility.GetPrefabType(child_obj));

            //判断选择的物体,是否为预设
            PrefabType cur_prefab_type = PrefabUtility.GetPrefabType(child_obj);
            //不是预设的话说明还没保存过的,弹出保存框
            string default_path = PathSaver.GetInstance().GetLastPath(PathType.SaveLayout);
            string save_path    = EditorUtility.SaveFilePanel("Save Layout", default_path, "prefab_name", "prefab");

            if (save_path == "")
            {
                return;
            }
            string full_path = save_path;

            PathSaver.GetInstance().SetLastPath(PathType.SaveLayout, save_path);
            save_path = FileUtil.GetProjectRelativePath(save_path);
            if (save_path == "")
            {
                Debug.Log("wrong path to save layout, is this project path? : " + full_path);
                EditorUtility.DisplayDialog("error", "wrong path to save layout, is this project path? : " + full_path, "ok");
                return;
            }

            Object new_prefab = PrefabUtility.CreateEmptyPrefab(save_path);

            PrefabUtility.ReplacePrefab(child_obj, new_prefab, ReplacePrefabOptions.ConnectToPrefab);
            LayoutInfo layoutInfo = layout.GetComponent <LayoutInfo>();

            if (layoutInfo != null)
            {
                layoutInfo.LayoutPath = full_path;
            }
            string just_name = System.IO.Path.GetFileNameWithoutExtension(save_path);

            child_obj.name         = just_name;
            layout.gameObject.name = just_name + "_Canvas";
            //刷新
            AssetDatabase.Refresh();
            if (Configure.IsShowDialogWhenSaveLayout)
            {
                EditorUtility.DisplayDialog("Tip", "Save Succeed!", "Ok");
            }

            //保存时先记录一下,如果是运行游戏时保存了,结束游戏时就要重新加载界面了,不然会重置回运行游戏前的
            ReloadLayoutOnExitGame reloadCom = layout.GetComponent <ReloadLayoutOnExitGame>();

            if (reloadCom)
            {
                reloadCom.SetHadSaveOnRunTime(true);
            }
            Debug.Log("Save Succeed!");
            layoutInfo.SaveToConfigFile();
        }
Esempio n. 2
0
        public static void LoadLayout(object o)
        {
            string default_path = PathSaver.GetInstance().GetLastPath(PathType.SaveLayout);
            string select_path  = EditorUtility.OpenFilePanel("Open Layout", default_path, "prefab");

            PathSaver.GetInstance().SetLastPath(PathType.SaveLayout, select_path);
            //Debug.Log(string.Format("select_path : {0}", select_path));
            if (select_path.Length > 0)
            {
                //Cat!TODO:检查是否已打开同名界面

                GameObject new_layout = CreatNewLayout(false);
                new_layout.transform.localPosition = new Vector3(new_layout.transform.localPosition.x, new_layout.transform.localPosition.y, 0);

                select_path = FileUtil.GetProjectRelativePath(select_path);

                Object     prefab   = AssetDatabase.LoadAssetAtPath(select_path, typeof(Object));
                GameObject new_view = PrefabUtility.InstantiateAttachedAsset(prefab) as GameObject;
                PrefabUtility.ReconnectToLastPrefab(new_view);
                new_view.transform.parent        = new_layout.transform;
                new_view.transform.localPosition = Vector3.zero;
                string just_name = System.IO.Path.GetFileNameWithoutExtension(select_path);
                new_view.name = just_name;
                new_layout.gameObject.name = just_name + "_Canvas";
            }
        }
Esempio n. 3
0
 public static void SelectPicForDecorate(Decorate decorate)
 {
     if (decorate != null)
     {
         string default_path = PathSaver.GetInstance().GetLastPath(PathType.OpenDecorate);
         string spr_path     = EditorUtility.OpenFilePanel("加载外部图片", default_path, "");
         if (spr_path.Length > 0)
         {
             decorate.SprPath = spr_path;
             PathSaver.GetInstance().SetLastPath(PathType.OpenDecorate, spr_path);
         }
     }
 }
Esempio n. 4
0
 public static PathSaver GetInstance()
 {
     if (_instance == null)
     {
         lock (lockHelper)
         {
             if (_instance == null)
             {
                 _instance = new PathSaver();
             }
         }
     }
     return(_instance);
 }
Esempio n. 5
0
        public static void LoadLayoutWithFolder()
        {
            string default_path = PathSaver.GetInstance().GetLastPath(PathType.SaveLayout);
            string select_path  = EditorUtility.OpenFolderPanel("Open Layout", default_path, "");

            PathSaver.GetInstance().SetLastPath(PathType.SaveLayout, select_path);
            if (select_path.Length > 0)
            {
                string[] file_paths = Directory.GetFiles(select_path, "*.prefab");
                foreach (var path in file_paths)
                {
                    LoadLayoutByPath(path);
                }
            }
            UILayoutTool.ResortAllLayout();
        }
Esempio n. 6
0
        public static void SaveAnotherLayout(Canvas layout, Transform child)
        {
            if (child.GetComponent <Decorate>() != null)
            {
                return;
            }
            GameObject child_obj = child.gameObject;
            //Debug.Log("child type :" + PrefabUtility.GetPrefabType(child_obj));

            //判断选择的物体,是否为预设
            PrefabType cur_prefab_type = PrefabUtility.GetPrefabType(child_obj);
            //不是预设的话说明还没保存过的,弹出保存框
            string default_path = PathSaver.GetInstance().GetLastPath(PathType.SaveLayout);
            string save_path    = EditorUtility.SaveFilePanel("Save Layout", default_path, "prefab_name", "prefab");

            if (save_path == "")
            {
                return;
            }
            PathSaver.GetInstance().SetLastPath(PathType.SaveLayout, save_path);
            save_path = FileUtil.GetProjectRelativePath(save_path);

            Object new_prefab = PrefabUtility.CreateEmptyPrefab(save_path);

            PrefabUtility.ReplacePrefab(child_obj, new_prefab, ReplacePrefabOptions.ConnectToPrefab);

            string just_name = System.IO.Path.GetFileNameWithoutExtension(save_path);

            child_obj.name         = just_name;
            layout.gameObject.name = just_name + "_Canvas";
            //刷新
            AssetDatabase.Refresh();
            if (Configure.IsShowDialogWhenSaveLayout)
            {
                EditorUtility.DisplayDialog("Tip", "Save Succeed!", "Ok");
            }
            Debug.Log("Save Succeed!");
        }
Esempio n. 7
0
        //[MenuItem("UIEditor/加载界面 " + Configure.ShortCut.LoadUIPrefab, false, 1)]
        public static void LoadLayout()
        {
            string default_path = PathSaver.GetInstance().GetLastPath(PathType.SaveLayout);
            string select_path  = EditorUtility.OpenFilePanel("Open Layout", default_path, "prefab");

            PathSaver.GetInstance().SetLastPath(PathType.SaveLayout, select_path);
            if (select_path.Length > 0)
            {
                //检查是否已打开同名界面
                GameObject loaded_layout = GetLoadedLayout(select_path);
                if (loaded_layout != null)
                {
                    bool is_reopen = EditorUtility.DisplayDialog("警告", "已打开同名界面,是否重新加载?", "来吧", "不了");
                    if (is_reopen)
                    {
                        //Undo.DestroyObjectImmediate(loaded_layout);
                        ReLoadLayout(loaded_layout, true);
                    }
                    return;
                }
                LoadLayoutByPath(select_path);
            }
        }
Esempio n. 8
0
        public static void SaveLayout(object o)
        {
            if (Selection.activeGameObject == null)
            {
                EditorUtility.DisplayDialog("Warning", "I don't know which prefab you want to save", "Ok");
                return;
            }
            Canvas layout = Selection.activeGameObject.GetComponentInParent <Canvas>();

            for (int i = 0; i < layout.transform.childCount; i++)
            {
                Transform child = layout.transform.GetChild(i);
                if (child.GetComponent <Decorate>() != null)
                {
                    continue;
                }
                GameObject child_obj = child.gameObject;
                //Debug.Log("child type :" + PrefabUtility.GetPrefabType(child_obj));

                //判断选择的物体,是否为预设
                PrefabType cur_prefab_type = PrefabUtility.GetPrefabType(child_obj);
                if (cur_prefab_type == PrefabType.DisconnectedPrefabInstance)
                {
                    PrefabUtility.ReconnectToLastPrefab(child_obj);
                }
                if (PrefabUtility.GetPrefabType(child_obj) == PrefabType.PrefabInstance)
                {
                    UnityEngine.Object parentObject = PrefabUtility.GetPrefabParent(child_obj);
                    //替换预设
                    PrefabUtility.ReplacePrefab(child_obj, parentObject, ReplacePrefabOptions.ConnectToPrefab);
                    //刷新
                    AssetDatabase.Refresh();
                    if (Configure.IsShowDialogWhenSaveLayout)
                    {
                        EditorUtility.DisplayDialog("Tip", "Save Succeed!", "Ok");
                    }
                    Debug.Log("Save Succeed!");
                }
                else
                {
                    //不是预设的话说明还没保存过的,弹出保存框
                    string default_path = PathSaver.GetInstance().GetLastPath(PathType.SaveLayout);
                    string save_path    = EditorUtility.SaveFilePanel("Save Layout", default_path, "prefab_name", "prefab");
                    if (save_path == "")
                    {
                        continue;
                    }
                    PathSaver.GetInstance().SetLastPath(PathType.SaveLayout, save_path);
                    save_path = FileUtil.GetProjectRelativePath(save_path);

                    Object new_prefab = PrefabUtility.CreateEmptyPrefab(save_path);
                    PrefabUtility.ReplacePrefab(child_obj, new_prefab, ReplacePrefabOptions.ConnectToPrefab);

                    string just_name = System.IO.Path.GetFileNameWithoutExtension(save_path);
                    child_obj.name         = just_name;
                    layout.gameObject.name = just_name + "_Canvas";
                    //刷新
                    AssetDatabase.Refresh();
                    if (Configure.IsShowDialogWhenSaveLayout)
                    {
                        EditorUtility.DisplayDialog("Tip", "Save Succeed!", "Ok");
                    }
                    Debug.Log("Save Succeed!");
                }
            }
        }