예제 #1
0
        //[MenuItem("UIEditor/另存为 ")]
        public static void SaveAnotherLayoutMenu()
        {
            if (Selection.activeGameObject == null)
            {
                EditorUtility.DisplayDialog("Warning", "I don't know which prefab you want to save", "Ok");
                return;
            }
            LayoutInfo layout = Selection.activeGameObject.GetComponentInParent <LayoutInfo>();

            if (layout != null)
            {
                GameObject editingView = layout.EditingView;
                if (editingView != null)
                {
                    UIEditorHelper.SaveAnotherLayout(layout.GetComponent <Canvas>(), editingView.transform);
                }
            }
            // 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);
            //     UIEditorHelper.SaveAnotherLayout(layout, child);
            //     break;
            // }
        }
예제 #2
0
        //[MenuItem("UIEditor/保存 " + Configure.ShortCut.SaveUIPrefab, false, 2)]
        public static void SaveLayout(GameObject o, bool isQuiet)
        {
            GameObject saveObj = o == null ? Selection.activeGameObject : (o as GameObject);

            if (saveObj == null)
            {
                EditorUtility.DisplayDialog("Warning", "I don't know which prefab you want to save", "Ok");
                return;
            }
            Canvas layout = saveObj.GetComponentInParent <Canvas>();

            if (layout == null)
            {
                EditorUtility.DisplayDialog("Warning", "select any layout below UITestNode/canvas to save", "Ok");
                return;
            }
            Transform real_layout = GetRealLayout(saveObj);

            if (real_layout != null)
            {
                GameObject child_obj = real_layout.gameObject;
                //判断选择的物体,是否为预设
                PrefabType cur_prefab_type = PrefabUtility.GetPrefabType(child_obj);
                if (PrefabUtility.GetPrefabType(child_obj) == PrefabType.PrefabInstance || cur_prefab_type == PrefabType.DisconnectedPrefabInstance)
                {
                    UnityEngine.Object parentObject = PrefabUtility.GetPrefabParent(child_obj);
                    //替换预设,Note:只能用ConnectToPrefab,不然会重复加多几个同名控件的
                    PrefabUtility.ReplacePrefab(child_obj, parentObject, ReplacePrefabOptions.ConnectToPrefab);
                    //刷新
                    AssetDatabase.Refresh();
                    if (Configure.IsShowDialogWhenSaveLayout && !isQuiet)
                    {
                        EditorUtility.DisplayDialog("Tip", "Save Succeed!", "Ok");
                    }

                    //保存时先记录一下,如果是运行游戏时保存了,结束游戏时就要重新加载界面了,不然会重置回运行游戏前的
                    ReloadLayoutOnExitGame reloadCom = layout.GetComponent <ReloadLayoutOnExitGame>();
                    if (reloadCom)
                    {
                        reloadCom.SetHadSaveOnRunTime(true);
                    }
                    Debug.Log("Save Succeed!");
                    LayoutInfo layoutInfo = layout.GetComponent <LayoutInfo>();
                    if (layoutInfo != null)
                    {
                        layoutInfo.SaveToConfigFile();
                    }
                }
                else
                {
                    UIEditorHelper.SaveAnotherLayout(layout, real_layout);
                }
            }
            else
            {
                Debug.Log("save failed!are you select any widget below canvas?");
            }
        }
예제 #3
0
        public static void SaveLayout(object o = null)
        {
            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 (PrefabUtility.GetPrefabType(child_obj) == PrefabType.PrefabInstance || cur_prefab_type == PrefabType.DisconnectedPrefabInstance)
                {
                    UnityEngine.Object parentObject = PrefabUtility.GetPrefabParent(child_obj);
                    //替换预设
                    PrefabUtility.ReplacePrefab(child_obj, parentObject, ReplacePrefabOptions.Default);
                    //刷新
                    AssetDatabase.Refresh();
                    if (Configure.IsShowDialogWhenSaveLayout)
                    {
                        EditorUtility.DisplayDialog("Tip", "Save Succeed!", "Ok");
                    }
                    Debug.Log("Save Succeed!");
                }
                else
                {
                    UIEditorHelper.SaveAnotherLayout(layout, child);
                }
            }
        }
예제 #4
0
        //[MenuItem("UIEditor/另存为 ")]
        public static void SaveAnotherLayoutMenu()
        {
            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);
                UIEditorHelper.SaveAnotherLayout(layout, child);
            }
        }