Exemplo n.º 1
0
        private void CreatePanelScript(UIPanelBase.PanelBaseInfo info)
        {
            if (!info.m_IsCreatePanelScript)
            {
                return;
            }

            string fatherFolderPath = "Assets/Code/Modules/Panel";
            string filePath         = CheckFolder(fatherFolderPath, info);

            info.m_PanelScriptPath = filePath;

            string tempContent = File.ReadAllText(m_PanelScriptPath);

            tempContent = tempContent.Replace("PanelScriptBase", info.m_Name + (info.m_IsAddSuffix ? "Panel" : ""));
            string folderName = info.m_FolderName;

            tempContent = tempContent.Replace("ScriptPath", string.Format("{0}/{1}", folderName.Replace("Assets/Resources/", ""), info.m_Name + (info.m_IsAddSuffix ? "Panel" : "")));
            tempContent = tempContent.Replace("Undefine", !Enum.IsDefined(typeof(TPanelType), ( TPanelType )info.m_Id) ? info.m_Name : (( TPanelType )info.m_Id).ToString());
            if (info.m_Level == UIPanelBase.PanelBaseInfo.PanelLevel.二级面板 && info.m_IsAddCloseButton)
            {
                tempContent = tempContent.Replace("//CloseButton", "UIEventListener.Get( transform.Find( \"Anchor/Offset/CloseButton\" ).gameObject ).onClick = _go => \n\t\t{\n\t\t\tClose();\n\t\t};");
            }
            File.WriteAllText(filePath, tempContent, System.Text.Encoding.UTF8);
        }
Exemplo n.º 2
0
        private void RuleMatrixOnGUI(Rect rect, UIPanelBase.PanelBaseInfo info)
        {
            Handles.color = EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.2f) : new Color(0f, 0f, 0f, 0.2f);

            for (int y = 0; y <= 3; y++)
            {
                float dy = rect.yMin + y * k_SingleLineHeight;
                Handles.DrawLine(new Vector3(rect.xMin, dy), new Vector3(rect.xMax, dy));
            }
            for (int x = 0; x <= 3; x++)
            {
                float dx = rect.xMin + x * k_SingleLineHeight;
                Handles.DrawLine(new Vector3(dx, rect.yMin), new Vector3(dx, rect.yMax));
            }

            var anchors = info.GetAnchors();

            for (int y = -1; y < 2; y++)
            {
                for (int x = -1; x < 2; x++)
                {
                    Vector3Int pos      = new Vector3Int(x, y, 0);
                    Rect       iconRect = new Rect(rect.xMin + (x + 1) * k_SingleLineHeight + 1, rect.yMin + (1 - y) * k_SingleLineHeight + 1, k_SingleLineHeight - 2, k_SingleLineHeight - 2);
                    RuleMatrixIconOnGUI(info, anchors, pos, iconRect);
                }
            }
        }
Exemplo n.º 3
0
        private void CreateUIPanels()
        {
            for (int i = 0; i < m_ReorderableList.count; i++)
            {
                UIPanelBase.PanelBaseInfo info = m_PanelBase.m_PanelBaseInfos[i];

                if (info.m_Name != null && info.m_Name != "")
                {
                    if (IsOnlyLetterOrNumber(info.m_Name))
                    {
                        CreateSinglePanel(info);
                    }
                    else
                    {
                        Debug.LogErrorFormat("面板 “ {0} ” 名称包含非法字符!", info.m_Name);
                        continue;
                    }
                }
                else
                {
                    Debug.LogErrorFormat("面板 “ {0} ” 名称为空!", info.m_Name);
                    continue;
                }
            }
        }
Exemplo n.º 4
0
 private void RuleMatrixIconOnGUI(UIPanelBase.PanelBaseInfo info, Dictionary <Vector3Int, bool> anchors, Vector3Int pos, Rect rect)
 {
     if (anchors.ContainsKey(pos))
     {
         DrawAnchorOnGUI(rect, pos, anchors[pos]);
         TooltipOnGUI(rect, anchors[pos]);
         AnchorUpdate(rect, info, anchors, pos);
     }
 }
Exemplo n.º 5
0
        private GameObject InstantiateAndAssign(UIPanelBase.PanelBaseInfo info, string prefabPath)
        {
            GameObject uiPanelBaseGameObject = AssetDatabase.LoadAssetAtPath <GameObject>(prefabPath);

            uiPanelBaseGameObject      = Instantiate(uiPanelBaseGameObject);
            uiPanelBaseGameObject.name = info.m_Name;
            uiPanelBaseGameObject.GetComponent <UIPanel>().depth = info.m_Depth;
            return(uiPanelBaseGameObject);
        }
Exemplo n.º 6
0
 private void OnAddElement(ReorderableList list)
 {
     UIPanelBase.PanelBaseInfo info = new UIPanelBase.PanelBaseInfo();
     info.m_Name = string.Format("UIPanel{0}", list.count);
     info.m_Id   = 0;
     for (int i = 0; i < 9; i++)
     {
         info.m_IsSelectedList.Add(false);
     }
     m_PanelBase.m_PanelBaseInfos.Add(info);
 }
Exemplo n.º 7
0
        private void AnchorUpdate(Rect rect, UIPanelBase.PanelBaseInfo info, Dictionary <Vector3Int, bool> anchors, Vector3Int position)
        {
            if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && rect.Contains(Event.current.mousePosition))
            {
                if (anchors.ContainsKey(position))
                {
                    anchors[position] = !anchors[position];
                }

                info.UpdateListFromDictionary(anchors);
            }
        }
Exemplo n.º 8
0
        private void CreateManagerScript(UIPanelBase.PanelBaseInfo info)
        {
            if (!info.m_IsCreateManagerScript)
            {
                return;
            }

            string fatherFolderPath = "Assets/Code/Modules/Logic";
            string filePath         = CheckFolder(fatherFolderPath, info, "Manager");

            info.m_ManagerScriptPath = filePath;

            string tempContent = File.ReadAllText(m_ManagerScriptPath);

            tempContent = tempContent.Replace("ManagerScriptBase", info.m_Name + "Manager");
            File.WriteAllText(filePath, tempContent, System.Text.Encoding.UTF8);
        }
Exemplo n.º 9
0
        private string CheckFolder(string fatherFolder, UIPanelBase.PanelBaseInfo info, string nameSuffix = "Panel", string fileSuffix = "cs")
        {
            string folderName = info.m_FolderName;

            folderName = folderName.Replace("Assets/Resources/UI/NewPanel/", "");
            if (nameSuffix == "Manager")
            {
                folderName = folderName.Replace("Panel", "") + nameSuffix;
            }

            if (!AssetDatabase.IsValidFolder(fatherFolder + "/" + folderName))
            {
                AssetDatabase.CreateFolder(fatherFolder, folderName);
            }

            DirectoryInfo dir = new DirectoryInfo(fatherFolder + "/" + folderName + "/");

            FileInfo[] files = dir.GetFiles("*." + fileSuffix);
            string     temp  = info.m_Name;

            if (nameSuffix == "Manager")
            {
                temp = temp.Replace("Panel", "") + nameSuffix;
            }
            else
            {
                temp += info.m_IsAddSuffix ? nameSuffix : "";
            }

            string fileName = string.Format("{0}.{1}", temp, fileSuffix);

            for (int i = 0; i < files.Length; i++)
            {
                if (files[i].Name == fileName)
                {
                    isTheSameName = true;
                    break;
                }
            }

            return(string.Format("{0}/{1}/{2}", fatherFolder, folderName, fileName));
        }
Exemplo n.º 10
0
 public float GetElementHeight(int index)
 {
     UIPanelBase.PanelBaseInfo info = m_PanelBase.m_PanelBaseInfos[index];
     if (!info.m_IsFoldedup)
     {
         float inspectorHeight = k_DefaultElementHeight + 6 * k_SingleLineHeight;
         if (info.m_IsShowIdComment)
         {
             inspectorHeight += k_SingleLineHeight;
         }
         if (info.m_Level == UIPanelBase.PanelBaseInfo.PanelLevel.二级面板)
         {
             inspectorHeight += 2 * k_SingleLineHeight;
         }
         return(Mathf.Max(inspectorHeight, k_DefaultElementHeight));
     }
     else
     {
         return(k_SingleLineHeight + 4f);
     }
 }
Exemplo n.º 11
0
        private void OnDrawElement(Rect rect, int index, bool isActive, bool isFocused)
        {
            UIPanelBase.PanelBaseInfo info = m_PanelBase.m_PanelBaseInfos[index];

            float   yPos       = rect.yMin + 2f;
            float   height     = rect.height - k_PaddingBetweenEelements;
            Vector2 matrixSize = 3 * k_SingleLineHeight * Vector2.one;

            Rect headerRect    = new Rect(rect.xMin, yPos, rect.width, k_SingleLineHeight);
            Rect matrixRect    = new Rect(rect.xMax - matrixSize.x - 5f, yPos + k_SingleLineHeight, matrixSize.x, matrixSize.y);
            Rect inspectorRect = new Rect(rect.xMin, yPos + k_SingleLineHeight, rect.width - matrixRect.width - 15f, height);

            RuleHeaderOnGUI(headerRect, info);
            if (!info.m_IsFoldedup)
            {
                RuleInspectorOnGUI(inspectorRect, info);
                if (info.m_Level == UIPanelBase.PanelBaseInfo.PanelLevel.一级面板)
                {
                    RuleMatrixOnGUI(matrixRect, info);
                }
            }
        }
Exemplo n.º 12
0
        private void OnDuplicateSelected(object _info)
        {
            UIPanelBase.PanelBaseInfo info = _info as UIPanelBase.PanelBaseInfo;

            UIPanelBase.PanelBaseInfo newInfo = new UIPanelBase.PanelBaseInfo();
            newInfo.m_Name                  = info.m_Name;
            newInfo.m_Id                    = info.m_Id;
            newInfo.m_IdComment             = info.m_IdComment;
            newInfo.m_IsShowIdComment       = info.m_IsShowIdComment;
            newInfo.m_FolderName            = info.m_FolderName;
            newInfo.m_Level                 = info.m_Level;
            newInfo.m_IsAddCloseButton      = info.m_IsAddCloseButton;
            newInfo.m_IsAddCloseBackground  = info.m_IsAddCloseBackground;
            newInfo.m_IsAddSuffix           = info.m_IsAddSuffix;
            newInfo.m_IsCreatePanelScript   = info.m_IsCreatePanelScript;
            newInfo.m_IsCreateManagerScript = info.m_IsCreateManagerScript;
            newInfo.m_Side                  = info.m_Side;
            newInfo.m_Depth                 = info.m_Depth;
            newInfo.m_SortId                = info.m_SortId;
            newInfo.m_IsSelectedList        = info.m_IsSelectedList;
            m_PanelBase.m_PanelBaseInfos.Add(newInfo);
        }
Exemplo n.º 13
0
        private void RuleHeaderOnGUI(Rect rect, UIPanelBase.PanelBaseInfo info)
        {
            if (isShowCheckbox)
            {
                Rect toggleRect = new Rect(new Rect(rect.xMax - 2 * k_SingleLineHeight, rect.yMin - 3f, k_SingleLineHeight, k_SingleLineHeight));
                info.m_IsCheckboxSelected = EditorGUI.Toggle(toggleRect, info.m_IsCheckboxSelected);
                string tip = string.Format("“ {0}{1} ” 面板复选框{2}被选择", info.m_Name, info.m_IsAddSuffix ? "Panel" : "", info.m_IsCheckboxSelected ? "已" : "未");
                if (toggleRect.Contains(Event.current.mousePosition))
                {
                    GUI.Label(toggleRect, new GUIContent("", tip));
                }
            }

            Rect labelRect = new Rect(rect.xMin, rect.yMin, rect.width - k_SingleLineHeight, k_SingleLineHeight);

            GUI.Label(labelRect, info.m_Name + (info.m_IsAddSuffix ? "Panel" : ""), EditorStyles.boldLabel);
            if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && labelRect.Contains(Event.current.mousePosition))
            {
                Event.current.Use();
                info.m_IsFoldedup = !info.m_IsFoldedup;
            }


            GUI.Label(new Rect(rect.xMax - k_SingleLineHeight, rect.yMin - 1f, k_SingleLineHeight + 10f, k_SingleLineHeight + 10f), EditorGUIUtility.IconContent("d__Popup"));
            Rect checkRect = new Rect(rect.xMax - k_SingleLineHeight, rect.yMin, k_SingleLineHeight, k_SingleLineHeight);

            if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && checkRect.Contains(Event.current.mousePosition))
            {
                GenericMenu menu = new GenericMenu();
                menu.AddItem(new GUIContent("Delete"), false, OnDeleteSelected);
                menu.AddItem(new GUIContent("Duplicate"), false, OnDuplicateSelected, info);
                if (info.m_IsPrefabCreated)
                {
                    menu.AddItem(new GUIContent("Locate Prefab"), false, OnLocateSelected, info);
                }
                menu.ShowAsContext();
            }
        }
Exemplo n.º 14
0
        private void CreateSinglePanel(UIPanelBase.PanelBaseInfo info)
        {
            GameObject uiPanelBaseGameObject = null;

            switch (info.m_Level)
            {
            case UIPanelBase.PanelBaseInfo.PanelLevel.一级面板:
                uiPanelBaseGameObject = InstantiateAndAssign(info, m_Prefab1Path);
                UIAnchor[] anchors = uiPanelBaseGameObject.GetComponentsInChildren <UIAnchor>();
                for (int i = 0; i < info.m_IsSelectedList.Count; i++)
                {
                    if (!info.m_IsSelectedList[i])
                    {
                        DestroyImmediate(anchors[i].gameObject);
                    }
                }
                if (info.m_Side == 16)
                {
                    anchors[4].gameObject.name = "Anchor";
                }
                break;

            case UIPanelBase.PanelBaseInfo.PanelLevel.二级面板:
                uiPanelBaseGameObject = InstantiateAndAssign(info, m_Prefab2Path);
                UISprite[] sprites = uiPanelBaseGameObject.GetComponentsInChildren <UISprite>();
                if (!info.m_IsAddCloseButton)
                {
                    DestroyImmediate(sprites[0].gameObject);
                }
                if (!info.m_IsAddCloseBackground)
                {
                    DestroyImmediate(sprites[1].gameObject);
                }
                break;
            }

            CreateUIPanelPrefabs(uiPanelBaseGameObject, info);
        }
Exemplo n.º 15
0
        private void CreateUIPanelPrefabs(GameObject go, UIPanelBase.PanelBaseInfo info)
        {
            string fatherFolderPath = "Assets/Resources/UI/NewPanel";
            string filePath         = CheckFolder(fatherFolderPath, info, "Panel", "prefab");

            if (!isTheSameName)
            {
                GameObject createObj = PrefabUtility.SaveAsPrefabAsset(go, filePath);
                info.m_Prefab     = createObj;
                info.m_PrefabPath = filePath;

                CreatePanelScript(info);
                CreateManagerScript(info);
                info.m_IsPrefabCreated = true;
            }
            else
            {
                Debug.LogErrorFormat("面板 “ {0} ” 名称与已创面板同名!", info.m_Name);
            }

            isTheSameName = false;
            DestroyImmediate(go);
        }
Exemplo n.º 16
0
 private void OnLocateSelected(object _info)
 {
     UIPanelBase.PanelBaseInfo info = _info as UIPanelBase.PanelBaseInfo;
     Selection.activeObject = AssetDatabase.LoadAssetAtPath <GameObject>(info.m_PrefabPath);
 }
Exemplo n.º 17
0
        public void RuleInspectorOnGUI(Rect rect, UIPanelBase.PanelBaseInfo info)
        {
            if (info.m_IsPrefabCreated)
            {
                GUIStyle style = new GUIStyle();
                style.normal.background = null;
                style.normal.textColor  = Color.red;
                style.fontSize          = 12;
                GUI.Label(new Rect(rect.xMin - 14f, rect.yMin, 12f, 48f), "预\n制\n体\n创\n建\n成\n功", style);
            }

            Handles.color = EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.6f) : new Color(0f, 0f, 0f, 0.6f);

            float y = rect.yMin;

            GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Panel Name");
            info.m_Name        = EditorGUI.TextField(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth - k_SingleLineHeight, k_SingleLineHeight), info.m_Name);
            info.m_IsAddSuffix = EditorGUI.Toggle(new Rect(rect.xMin + rect.width - k_SingleLineHeight + 1f, y - 2f, k_SingleLineHeight - 4f, k_SingleLineHeight - 4f), info.m_IsAddSuffix);
            GUI.Label(new Rect(rect.xMin + rect.width - k_SingleLineHeight + 1f, y - 2f, k_SingleLineHeight - 4f, k_SingleLineHeight - 4f), new GUIContent("", "是否需要后台自动为文件添加后缀\n注意:并不给文件夹添加后缀!"));
            y += k_SingleLineHeight;

            info.m_Id = EditorGUI.IntField(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), info.m_Id);
            if (!Enum.IsDefined(typeof(TPanelType), ( TPanelType )info.m_Id))
            {
                info.m_IsShowIdComment = EditorGUI.Foldout(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), info.m_IsShowIdComment, "Panel ID");
                if (info.m_IsShowIdComment)
                {
                    y += k_SingleLineHeight;
                    GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), new GUIContent("新ID功能注释", "为上面的新ID作功能注释"));
                    info.m_IdComment = EditorGUI.TextField(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), info.m_IdComment);
                }
            }
            else
            {
                GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Panel ID");
            }
            y += k_SingleLineHeight;

            GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Panel Depth");
            info.m_Depth = EditorGUI.IntField(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), info.m_Depth);
            y           += k_SingleLineHeight;

            GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Panel Folder");
            if (GUI.Button(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), "选择文件夹"))
            {
                string path = EditorUtility.SaveFolderPanel("选择文件夹", m_ProjectPath + "Assets/Resources/UI/NewPanel", "XXXPanel");
                if (path.Length != 0)
                {
                    info.m_FolderName = path.Replace(m_ProjectPath, "");
                }
            }

            y += k_SingleLineHeight;

            EditorGUI.TextField(new Rect(rect.xMin, y, rect.width, k_SingleLineHeight), info.m_FolderName);
            y += k_SingleLineHeight;

            GUI.Label(new Rect(rect.xMin, y, k_LabelWidth, k_SingleLineHeight), "Panel Level");
            info.m_Level = (UIPanelBase.PanelBaseInfo.PanelLevel)EditorGUI.EnumPopup(new Rect(rect.xMin + k_LabelWidth, y, rect.width - k_LabelWidth, k_SingleLineHeight), info.m_Level, "ExposablePopupMenu");
            y           += k_SingleLineHeight;

            if (info.m_Level == UIPanelBase.PanelBaseInfo.PanelLevel.二级面板)
            {
                info.m_IsAddCloseButton = EditorGUI.ToggleLeft(new Rect(rect.xMin + k_SingleLineHeight / 2, y, rect.width - k_SingleLineHeight / 2, k_SingleLineHeight), "是否添加Close Button", info.m_IsAddCloseButton);
                if (new Rect(rect.xMin + k_SingleLineHeight / 2, y, rect.width - k_SingleLineHeight / 2, k_SingleLineHeight).Contains(Event.current.mousePosition))
                {
                    Texture texture = AssetDatabase.LoadAssetAtPath <Texture>("Assets/Editor/UIPanelGenerator/Textures/close_2.png");
                    GUI.DrawTexture(new Rect(rect.xMax + 10f, y - 2 * k_SingleLineHeight, 48f, 96f), texture);
                    Handles.DrawLine(new Vector3(rect.xMax + 10f, y - 2 * k_SingleLineHeight, 0), new Vector3(rect.xMax + 58f, y - 2 * k_SingleLineHeight, 0));
                    Handles.DrawLine(new Vector3(rect.xMax + 58f, y - 2 * k_SingleLineHeight, 0), new Vector3(rect.xMax + 58f, y - 2 * k_SingleLineHeight + 96f, 0));
                    Handles.DrawLine(new Vector3(rect.xMax + 58f, y - 2 * k_SingleLineHeight + 96f, 0), new Vector3(rect.xMax + 10f, y - 2 * k_SingleLineHeight + 96f, 0));
                    Handles.DrawLine(new Vector3(rect.xMax + 10f, y - 2 * k_SingleLineHeight + 96f, 0), new Vector3(rect.xMax + 10f, y - 2 * k_SingleLineHeight, 0));
                }
                y += k_SingleLineHeight;

                info.m_IsAddCloseBackground = EditorGUI.ToggleLeft(new Rect(rect.xMin + k_SingleLineHeight / 2, y, rect.width - k_SingleLineHeight / 2, k_SingleLineHeight), "是否添加Close BackGround", info.m_IsAddCloseBackground);
                y += k_SingleLineHeight;

                Handles.DrawLine(new Vector3(rect.xMin, y - 3 * k_SingleLineHeight, 0), new Vector3(rect.xMin, y, 0));
                Handles.DrawLine(new Vector3(rect.xMin, y, 0), new Vector3(rect.xMax, y, 0));
                Handles.DrawLine(new Vector3(rect.xMax, y, 0), new Vector3(rect.xMax, y - 3 * k_SingleLineHeight, 0));
                Handles.DrawLine(new Vector3(rect.xMin, y - 3 * k_SingleLineHeight, 0), new Vector3(rect.xMax, y - 3 * k_SingleLineHeight, 0));
            }

            info.m_IsCreatePanelScript = EditorGUI.ToggleLeft(new Rect(rect.xMin, y, rect.width, k_SingleLineHeight), "是否创建Panel脚本", info.m_IsCreatePanelScript);
            y += k_SingleLineHeight;

            info.m_IsCreateManagerScript = EditorGUI.ToggleLeft(new Rect(rect.xMin, y, rect.width, k_SingleLineHeight), "是否创建Manager脚本", info.m_IsCreateManagerScript);
            y += k_SingleLineHeight;
        }