コード例 #1
0
ファイル: Tool.cs プロジェクト: Hengle/UnityEditor
        public static string GetTmpPrefabPath(string prefab)
        {
            string folder     = EditorTool.GetFolder(prefab);
            string filename   = EditorTool.GetFileName(prefab, false);
            int    index      = 1;
            string tmp_prefab = folder + filename + "_" + (index++).ToString() + s_prefab_postfix;

            while (File.Exists(tmp_prefab))
            {
                tmp_prefab = folder + filename + "_" + (index++).ToString() + s_prefab_postfix;
            }
            return(tmp_prefab);
        }
コード例 #2
0
ファイル: Tool.cs プロジェクト: Hengle/UnityEditor
        public static bool IsPointInConvexPoly(Vector3 p, Vector3[] poly)
        {
            for (int i = 0; i < poly.Length; ++i)
            {
                float cwv = ClockWiseTest(poly[i], poly[EditorTool.GetValidIndex((i + 1), poly.Length)], poly[EditorTool.GetValidIndex((i + 2), poly.Length)]);

                if (cwv < float.Epsilon || ClockWiseTest(p, poly[i], poly[EditorTool.GetValidIndex((i + 1), poly.Length)]) * cwv < 0)
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #3
0
ファイル: Tool.cs プロジェクト: Hengle/UnityEditor
        public static bool RemoveNoUINode(GameObject go)
        {
            bool remove_sth = false;

            if (go != null)
            {
                GameObject[] children = EditorTool.GetSubChildren(go);
                for (int i = 0; i < children.Length; ++i)
                {
                    if (RemoveNoUINode(children[i]))
                    {
                        remove_sth = true;
                    }
                }
                bool        has_ui            = false;
                bool        has_SubPrefabNode = false;
                Component[] components        = go.GetComponents <Component>();
                for (int i = 0; i < components.Length; ++i)
                {
                    if (components[i] != null)
                    {
                        if (components[i] is UIWidget)
                        {
                            has_ui = true;
                        }
                        else if (components[i] is UIPrefabNode)
                        {
                            has_SubPrefabNode = true;
                        }
                        else if (!(components[i] is Transform) &&
                                 !(components[i] is UIPanel) &&
                                 !(components[i] is Camera) &&
                                 !(components[i] is UIAnchor) &&
                                 !(components[i] is BoxCollider)
                                 )
                        {
                            Object.DestroyImmediate(components[i]);
                            remove_sth = true;
                        }
                    }
                }
                if (!has_ui && !has_SubPrefabNode && go.transform.childCount == 0)
                {
                    Object.DestroyImmediate(go);
                    remove_sth = true;
                }
            }

            return(remove_sth);
        }
コード例 #4
0
ファイル: Tool.cs プロジェクト: Hengle/UnityEditor
 public static void SetWidgetSelfPivot(UIWidget widget, UIWidget.Pivot pivot)
 {
     if (widget != null && widget.pivot != pivot)
     {
         GameObject[] children = EditorTool.GetSubChildren(widget.gameObject);
         Vector3      org_pos  = widget.transform.position;
         widget.pivot = pivot;
         Vector3 inv_pos_delta = (org_pos - widget.transform.position);
         for (int i = 0; i < children.Length; ++i)
         {
             children[i].transform.Translate(inv_pos_delta);
         }
     }
 }
コード例 #5
0
ファイル: Tool.cs プロジェクト: Hengle/UnityEditor
        public static bool SaveLayout(string layout_fullpath, GameObject inst)
        {
            string prefab     = LayoutTool.GetPrefabPath(layout_fullpath);
            string tmp_prefab = LayoutTool.GetTmpPrefabPath(prefab);

            PrefabUtility.CreatePrefab(tmp_prefab, inst);
            AssetDatabase.SaveAssets();
            EditorTool.FileWriteable(layout_fullpath);
            File.Copy(EditorTool.GetSystemFullpath(tmp_prefab), layout_fullpath, true);
            FileUtil.DeleteFileOrDirectory(tmp_prefab);
            AssetDatabase.Refresh();

            return(true);
        }
コード例 #6
0
ファイル: Tool.cs プロジェクト: Hengle/UnityEditor
        public Texture2D GetBackTexture(string filename)
        {
            if (!File.Exists(filename))
            {
                return(null);
            }

            string back_texture_fullname = EditorTool.GetSystemFullpath(back_texture);

            EditorTool.FileWriteable(back_texture_fullname);
            File.Copy(filename, back_texture_fullname, true);
            AssetDatabase.Refresh();

            return(AssetDatabase.LoadAssetAtPath(back_texture, typeof(Texture2D)) as Texture2D);
        }
コード例 #7
0
ファイル: Tool.cs プロジェクト: Hengle/UnityEditor
        public static string GetLayoutFullPath(string prefab)
        {
            string fullpath = prefab.ToLower();

            if (!fullpath.StartsWith(ConfigTool.Instance.prefab_prefix.ToLower()))
            {
                Debug.LogError("Prefab·��\"" + prefab + "\"���淶");
                return("");
            }
            fullpath = fullpath.Substring(ConfigTool.Instance.prefab_prefix.Length);
            fullpath = ConfigTool.Instance.layout_prefix + fullpath;
            fullpath = EditorTool.GetProjectFullpath() + fullpath;
            fullpath = EditorTool.MakesureFolderExit(fullpath) + EditorTool.GetFileName(prefab, false) + s_layout_postfix;

            return(fullpath);
        }
コード例 #8
0
ファイル: Tool.cs プロジェクト: Hengle/UnityEditor
        public static GameObject LoadLayout(string layout_fullpath, bool for_edit)
        {
            string name   = EditorTool.GetFileName(layout_fullpath, false);
            string prefab = LayoutTool.GetPrefabPath(layout_fullpath);

            if (string.IsNullOrEmpty(prefab))
            {
                return(null);
            }

            string tmp_prefab          = LayoutTool.GetTmpPrefabPath(prefab);
            string tmp_prefab_fullname = EditorTool.GetSystemFullpath(tmp_prefab);

            EditorTool.FileWriteable(tmp_prefab_fullname);
            File.Copy(layout_fullpath, tmp_prefab_fullname, true);
            AssetDatabase.Refresh();
            //GameObject tmp_prefab_obj = Resources.LoadAssetAtPath(tmp_prefab, typeof(GameObject)) as GameObject;
#if UNITY_EDITOR
            GameObject tmp_prefab_obj = AssetDatabase.LoadAssetAtPath(tmp_prefab, typeof(GameObject)) as GameObject;
#else
            GameObject tmp_prefab_obj = Resources.Load(Trans2ResourcesPath(tmp_prefab), typeof(GameObject)) as GameObject;
#endif
            if (tmp_prefab_obj == null)
            {
                Debug.LogError("�޷�����Layout�ļ�\"" + layout_fullpath + "\"");
                FileUtil.DeleteFileOrDirectory(tmp_prefab);
                AssetDatabase.Refresh();
                return(null);
            }
            GameObject prefab_obj = Object.Instantiate(tmp_prefab_obj) as GameObject;
            if (for_edit)
            {
                prefab_obj.transform.parent = Root.transform;
            }
            prefab_obj.transform.localPosition = tmp_prefab_obj.transform.position;
            prefab_obj.layer = s_editor_layer;
            prefab_obj.name  = name;
            RemoveInvalidNode(prefab_obj);
            FileUtil.DeleteFileOrDirectory(tmp_prefab);
            AssetDatabase.Refresh();

            return(prefab_obj);
        }
コード例 #9
0
ファイル: Tool.cs プロジェクト: Hengle/UnityEditor
        public static string GetPrefabPath(string layout_fullpath)
        {
            string layout_fullpath_prefix = EditorTool.GetSystemFullpath(ConfigTool.Instance.prefab_prefix).ToLower();

            if (!layout_fullpath_prefix.EndsWith(ConfigTool.Instance.prefab_prefix.ToLower()))
            {
                Debug.LogError("Prefab·��ǰ׺\"" + layout_fullpath_prefix + "\"����");
                return("");
            }
            layout_fullpath_prefix = layout_fullpath_prefix.Substring(0, layout_fullpath_prefix.Length - ConfigTool.Instance.prefab_prefix.Length);
            layout_fullpath_prefix = EditorTool.MakesureFolderExit(layout_fullpath_prefix + ConfigTool.Instance.layout_prefix).ToLower();
            layout_fullpath        = layout_fullpath.ToLower();
            if (!layout_fullpath.StartsWith(layout_fullpath_prefix))
            {
                Debug.LogError("Layout·��\"" + layout_fullpath + "\"����");
                return("");
            }

            return(ConfigTool.Instance.prefab_prefix + layout_fullpath.Substring(layout_fullpath_prefix.Length).Replace(s_layout_postfix, s_prefab_postfix));
        }
コード例 #10
0
ファイル: Tool.cs プロジェクト: Hengle/UnityEditor
 public static void RemoveInvalidNode(GameObject go)
 {
     if (go != null)
     {
         GameObject[] children = EditorTool.GetSubChildren(go);
         for (int i = 0; i < children.Length; ++i)
         {
             UIElement ui_element = children[i].GetComponent <UIElement>();
             if (ui_element != null)
             {
                 if (ui_element.Removed)
                 {
                     Object.DestroyImmediate(ui_element.gameObject);
                 }
                 else
                 {
                     RemoveInvalidNode(ui_element.gameObject);
                 }
             }
         }
     }
 }
コード例 #11
0
ファイル: Tool.cs プロジェクト: Hengle/UnityEditor
        public static List <GameObject> FindGameObjectByName(GameObject go, string name)
        {
            List <GameObject>  list  = new List <GameObject>();
            Stack <GameObject> stack = new Stack <GameObject>();

            stack.Push(go);
            while (stack.Count > 0)
            {
                GameObject   cur_go   = stack.Pop();
                GameObject[] children = EditorTool.GetSubChildren(cur_go);

                for (int i = 0; i < children.Length; ++i)
                {
                    stack.Push(children[i]);
                }
                if (cur_go.name.ToLower() == name.ToLower())
                {
                    list.Add(cur_go);
                }
            }

            return(list);
        }
コード例 #12
0
ファイル: Tool.cs プロジェクト: Hengle/UnityEditor
        private static bool CheckSubPrefabImpl(GameObject go, int nCookie)
        {
            UIPrefabNode node = go.GetComponent <UIPrefabNode>();

            if (node != null)
            {
                nCookie++;
            }

            if (nCookie >= 2)
            {
                return(false);
            }

            GameObject[] children = EditorTool.GetSubChildren(go);
            foreach (GameObject child in children)
            {
                if (!CheckSubPrefabImpl(child, nCookie))
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #13
0
ファイル: Tool.cs プロジェクト: Hengle/UnityEditor
        //�ڵ���layout֮ǰ����һ�£���������prefab���Ƿ����������壨ͬ�����£�����������ʾ
        public static bool ProcessBeforeImport(GameObject go)
        {
            if (go == null)
            {
                return(false);
            }

            HashSet <string>   path_name_dic = new HashSet <string>();
            Stack <GameObject> stack         = new Stack <GameObject>();

            stack.Push(go);
            while (stack.Count > 0)
            {
                GameObject   cur_go   = stack.Pop();
                GameObject[] children = EditorTool.GetSubChildren(cur_go);
                for (int i = 0; i < children.Length; ++i)
                {
                    stack.Push(children[i]);
                }

                if (HasUI(cur_go, false))
                {
                    string sPathName = EditorTool.GetGameObjectFullPathName(cur_go, go);
                    if (path_name_dic.Contains(sPathName))
                    {
                        EditorUtility.DisplayDialog("", "ѡ�е�Prefab���������գɽڵ�\"" + cur_go.name + "\"���ȴ���", "ȷ��");
                        return(false);
                    }
                    else
                    {
                        path_name_dic.Add(sPathName);
                    }
                }
            }
            return(true);
        }
コード例 #14
0
ファイル: Tool.cs プロジェクト: Hengle/UnityEditor
        // �����Ƿ�������UIԪ�أ�Ϊÿһ���ڵ�����UIElement
        public static bool ProcessBeforeExport(GameObject go)
        {
            if (go == null)
            {
                return(false);
            }

            HashSet <string>   name_dic      = new HashSet <string>();
            HashSet <string>   path_name_dic = new HashSet <string>();
            Stack <GameObject> stack         = new Stack <GameObject>();

            //bool bFirst = true;
            stack.Push(go);
            while (stack.Count > 0)
            {
                GameObject   cur_go   = stack.Pop();
                GameObject[] children = EditorTool.GetSubChildren(cur_go);

                for (int i = 0; i < children.Length; ++i)
                {
                    stack.Push(children[i]);
                }

                string sPathName = EditorTool.GetGameObjectFullPathName(cur_go, go);
                if (HasUI(cur_go, false))
                {
                    if (name_dic.Contains(cur_go.name))
                    {
                        if (path_name_dic.Contains(sPathName))
                        {
                            EditorUtility.DisplayDialog("", "�ڵ�����\"" + cur_go.name + "\"��Ψһ���޷�����", "ȷ��");
                            return(false);
                        }
                        else
                        {
                            path_name_dic.Add(sPathName);
                        }
                    }
                    else
                    {
                        name_dic.Add(cur_go.name);
                        path_name_dic.Add(sPathName);
                    }
                }

                UIElement ui_element = cur_go.GetComponent <UIElement>();
                if (ui_element == null)
                {
                    ui_element = cur_go.AddComponent <UIElement>();
                }

                ui_element.Hide = !cur_go.activeSelf;
                //UIWidget ui_widget = ui_element.GetWidget();

                if (cur_go.name == "UIRootTempPanel")
                {
                    sPathName = "UIRootTempPanel";
                }
                //else if (bFirst)
                //{
                //    int nIndex = cur_go.name.IndexOf("(Clone)");
                //    if (nIndex > 0)
                //    {
                //        sPathName = cur_go.name.Substring(0, nIndex);
                //    }
                //}

                ui_element.FullPathName = sPathName;
                //Debug.Log(sPathName);

                //SetWidgetSelfPivot(ui_widget, UIWidget.Pivot.BottomLeft);
                //bFirst = false;
            }

            return(true);
        }
コード例 #15
0
ファイル: Tool.cs プロジェクト: Hengle/UnityEditor
 public static bool IsConvexPolyIntersect(Vector3[] poly1, Vector3[] poly2)
 {
     for (int i = 0; i < poly1.Length; ++i)
     {
         if (IsPointInConvexPoly(poly1[i], poly2))
         {
             return(true);
         }
     }
     for (int i = 0; i < poly2.Length; ++i)
     {
         if (IsPointInConvexPoly(poly2[i], poly1))
         {
             return(true);
         }
     }
     for (int i = 0; i < poly1.Length; ++i)
     {
         // test line (poly1[i], poly1[(i + 1) % poly1.Length])
         for (int j = 0; j < poly2.Length; ++j)
         {
             // test line (poly2[j], poly2[(j + 1) % poly2.Length])
             if (IsLineIntersect(poly1[i], poly1[EditorTool.GetValidIndex((i + 1), poly1.Length)], poly2[j], poly2[EditorTool.GetValidIndex((j + 1), poly2.Length)]))
             {
                 return(true);
             }
         }
     }
     return(false);
 }