Exemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            Decorate widget = target as Decorate;

            if (GUILayout.Button("加载外部图片", GUILayout.Height(30)))
            {
                UIEditorHelper.SelectPicForDecorate(widget);
            }
        }
Exemplo n.º 2
0
        static public void AddCommonItems(GameObject[] targets)
        {
            if (targets == null || targets.Length <= 0)
            {
                AddItem("新建", false, UIEditorHelper.CreatNewLayoutForMenu, null);
                AddItem("打开界面", false, UIEditorHelper.LoadLayout, null);
            }
            if (targets != null && targets.Length > 0)
            {
                AddItem("保存", false, UIEditorHelper.SaveLayoutForMenu, null);
                AddItem("另存为", false, UIEditorHelper.SaveAnotherLayoutContextMenu, null);
                AddItem("重新加载", false, UIEditorHelper.ReLoadLayoutForMenu, null);

                AddSeparator("///");
                AddItem("复制选中控件名", false, UIEditorHelper.CopySelectWidgetName, null);

                //如果选中超过1个节点的话
                if (targets.Length > 1)
                {
                    AddAlignMenu();
                    AddItem("同流合污", false, UILayoutTool.MakeGroup, null);
                }
                AddSeparator("///");
                if (targets.Length == 1)
                {
                    AddUIMenu();
                    AddUIComponentMenu();
                    AddPriorityMenu();

                    if (UIEditorHelper.IsNodeCanDivide(targets[0]))
                    {
                        AddItem("分道扬镖", false, UILayoutTool.UnGroup, null);
                    }
                    Decorate uiBase = targets[0].GetComponent <Decorate>();
                    if (uiBase != null)
                    {
                        if (uiBase.gameObject.hideFlags == HideFlags.NotEditable)
                        {
                            AddItem("解锁", false, UIEditorHelper.UnLockWidget, null);
                        }
                        else
                        {
                            AddItem("锁定", false, UIEditorHelper.LockWidget, null);
                        }
                    }
                }

                AddShowOrHideMenu();

                AddSeparator("///");

                AddItem("添加参考图", false, UIEditorHelper.CreateDecorate, null);
            }
            AddItem("排序所有界面", false, UILayoutTool.ResortAllLayout, null);
            AddItem("清空界面", false, UIEditorHelper.ClearAllCanvas, null);
        }
Exemplo 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);
         }
     }
 }
Exemplo n.º 4
0
 public Decorate GetDecorateChild(string picPath)
 {
     for (int i = 0; i < transform.childCount; i++)
     {
         Transform child = transform.GetChild(i);
         Decorate  decor = child.GetComponent <Decorate>();
         if (decor != null && decor.SprPath == picPath)
         {
             return(decor);
         }
     }
     return(null);
 }
Exemplo n.º 5
0
        public static Decorate CreateEmptyDecorate(Transform parent)
        {
            const string file_path       = Configure.ResAssetsPath + "Decorate.prefab";
            GameObject   decorate_prefab = UnityEditor.AssetDatabase.LoadAssetAtPath(file_path, typeof(UnityEngine.Object)) as GameObject;
            GameObject   decorate        = GameObject.Instantiate(decorate_prefab) as GameObject;

            decorate.transform.SetParent(parent);
            RectTransform rectTrans = decorate.transform as RectTransform;

            rectTrans.SetAsFirstSibling();
            rectTrans.localPosition = Vector3.zero;
            Decorate decor = rectTrans.GetComponent <Decorate>();

            return(decor);
        }
Exemplo n.º 6
0
        public static void CreateDecorate()
        {
            if (Selection.activeTransform != null)
            {
                Canvas canvas = Selection.activeTransform.GetComponentInParent <Canvas>();
                if (canvas != null)
                {
                    Decorate decor = CreateEmptyDecorate(canvas.transform);
                    Selection.activeTransform = decor.transform;

                    if (Configure.OpenSelectPicDialogWhenAddDecorate)
                    {
                        bool isSucceed = UIEditorHelper.SelectPicForDecorate(decor);
                        if (!isSucceed)
                        {
                            GameObject.DestroyImmediate(decor.gameObject);
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        public static void CreateDecorate(object o)
        {
            if (Selection.activeTransform != null)
            {
                Canvas canvas = Selection.activeTransform.GetComponentInParent <Canvas>();
                if (canvas != null)
                {
                    const string file_path       = Configure.ResAssetsPath + "Decorate.prefab";
                    GameObject   decorate_prefab = UnityEditor.AssetDatabase.LoadAssetAtPath(file_path, typeof(UnityEngine.Object)) as GameObject;
                    GameObject   decorate        = GameObject.Instantiate(decorate_prefab) as GameObject;
                    decorate.transform.parent = canvas.transform;
                    RectTransform rectTrans = decorate.transform as RectTransform;
                    rectTrans.SetAsFirstSibling();
                    rectTrans.localPosition   = Vector3.zero;
                    Selection.activeTransform = rectTrans;

                    if (Configure.OpenSelectPicDialogWhenAddDecorate)
                    {
                        Decorate decor = rectTrans.GetComponent <Decorate>();
                        UIEditorHelper.SelectPicForDecorate(decor);
                    }
                }
            }
        }
Exemplo n.º 8
0
        //打开界面时,从项目临时文件夹找到对应界面的参照图配置,然后生成参照图
        public void ApplyConfig(string view_path)
        {
            string layout_path_md5 = UIEditorHelper.GenMD5String(view_path);
            string confighFilePath = ConfigPath + "/" + layout_path_md5 + ".txt";

            if (!File.Exists(confighFilePath))
            {
                return;
            }
            string content       = File.ReadAllText(confighFilePath);
            int    pos_end_index = content.IndexOf(RealPosEndStr);

            if (pos_end_index == -1)
            {
                Debug.Log("cannot find real layout pos config on ApplyConfig : " + view_path);
                return;
            }
            string real_layout_pos_str = content.Substring(RealPosStartStr.Length, pos_end_index - RealPosStartStr.Length);

            string[] pos_cfg = real_layout_pos_str.Split(' ');
            if (pos_cfg.Length == 2)
            {
                RectTransform real_layout = UIEditorHelper.GetRealLayout(gameObject) as RectTransform;//先拿到真实的界面prefab
                if (real_layout == null)
                {
                    Debug.Log("cannot find real layout on ApplyConfig : " + view_path);
                    return;
                }
                real_layout.localPosition = new Vector3(float.Parse(pos_cfg[0]), float.Parse(pos_cfg[1]), real_layout.localPosition.z);
            }
            else
            {
                Debug.Log("cannot find real layout pos xy config on ApplyConfig : " + view_path);
                return;
            }
            content = content.Substring(pos_end_index + RealPosEndStr.Length);
            if (content == "")
            {
                return;//有些界面没参考图也是正常的,直接返回
            }
            string[] decorate_cfgs = content.Split('*');
            for (int i = 0; i < decorate_cfgs.Length; i++)
            {
                string[] cfgs = decorate_cfgs[i].Split('#');
                if (cfgs.Length == 3)
                {
                    Decorate decor = UIEditorHelper.CreateEmptyDecorate(transform);
                    decor.SprPath = cfgs[0];
                    RectTransform rectTrans = decor.GetComponent <RectTransform>();
                    if (rectTrans != null)
                    {
                        //IFormatter formatter = new BinaryFormatter();//使用序列化工具的话就可以保存多点信息,但实现复杂了,暂用简单的吧
                        string[] pos = cfgs[1].Split(' ');
                        if (pos.Length == 2)
                        {
                            rectTrans.localPosition = new Vector2(float.Parse(pos[0]), float.Parse(pos[1]));
                        }

                        string[] size = cfgs[2].Split(' ');
                        if (size.Length == 2)
                        {
                            rectTrans.sizeDelta = new Vector2(float.Parse(size[0]), float.Parse(size[1]));
                        }
                    }
                }
                else
                {
                    Debug.Log("warning : detect a wrong decorate config file!");
                    return;
                }
            }
        }