Exemple #1
0
    private List <string> GetBtnComponentList(bool pNeedTip = true)
    {
        ;
        List <string> tBtnComponentList = null;

        if (null != _exportInfoDic && _exportInfoDic.Count > 0)
        {
            var             tEnum            = _exportInfoDic.GetEnumerator();
            UIComponentInfo tUIComponentInfo = null;
            while (tEnum.MoveNext())
            {
                tUIComponentInfo = tEnum.Current.Value;
                if (null != tUIComponentInfo && tUIComponentInfo.comType == "Button")
                {
                    if (null == tBtnComponentList)
                    {
                        tBtnComponentList = new List <string>();
                    }
                    tBtnComponentList.Add(tUIComponentInfo.memberName);
                }
            }
        }
        if ((null == tBtnComponentList || tBtnComponentList.Count <= 0) && pNeedTip)
        {
            GameDebuger.Log("界面中没有按钮组件,不设置按钮相关事件监听和回掉。");
        }
        return(tBtnComponentList);
    }
Exemple #2
0
 public UIComponentInfo(UIComponentInfo info)
 {
     this.uid        = info.uid;
     this.comType    = info.comType;
     this.memberName = info.memberName;
     this.path       = info.path;
 }
        private static UIComponentInfo GetUIComponentInfo(UIMark markCom)
        {
            var info      = new UIComponentInfo();
            var fieldName = string.IsNullOrEmpty(markCom.customComponentName)
                ? markCom.name
                : markCom.customComponentName;

            fieldName       = FirstCharLower(fieldName);
            info.name       = fieldName;
            info.childIndex = markCom.transform.GetSiblingIndex();
            var selectableCom = markCom.GetComponent <UnityEngine.UI.Selectable>();

            if (selectableCom != null)
            {
                if (selectableCom is UnityEngine.UI.Button)
                {
                    info.type = "Button";
                }
                else if (selectableCom is UnityEngine.UI.Toggle)
                {
                    info.type = "Toggle";
                }
                else if (selectableCom is UnityEngine.UI.Slider)
                {
                    info.type = "Slider";
                }
                else if (selectableCom is UnityEngine.UI.Scrollbar)
                {
                    info.type = "Scrollbar";
                }
                else if (selectableCom is UnityEngine.UI.Dropdown)
                {
                    info.type = "Dropdown";
                }
                else if (selectableCom is UnityEngine.UI.InputField)
                {
                    info.type = "InputField";
                }
            } //end if
            else
            {
                var graphicCom = markCom.GetComponent <UnityEngine.UI.Graphic>();
                if (graphicCom != null)
                {
                    if (graphicCom is UnityEngine.UI.Image)
                    {
                        info.type = "Image";
                    }
                    else if (graphicCom is UnityEngine.UI.Text)
                    {
                        info.type = "Text";
                    }
                    else if (graphicCom is UnityEngine.UI.RawImage)
                    {
                        info.type = "RawImage";
                    }
                }
            } //end else
            return(info);
        }
Exemple #4
0
 private void OnChangeUIPrefab()
 {
     _codeGeneratePath = "";
     _curComInfo       = null;
     exportDicChanged  = true;
     _deleteUIDList.Clear();
     _exportInfoDic.Clear();
     _validatedInfoDic.Clear();
     ClearRelateInfo();
 }
Exemple #5
0
    void DrawExportListView()
    {
        EditorHelper.DrawHeader("ExportList");
        GUILayout.BeginHorizontal();
        GUILayout.Space(3f);
        GUILayout.BeginVertical();
        exportViewPos = EditorGUILayout.BeginScrollView(exportViewPos);
        bool delete = false;
        int  index  = 0;

        foreach (UIComponentInfo item in _exportInfoDic.Values)
        {
            ++index;
            GUILayout.Space(-1f);
            bool highlight = (_curComInfo != null) && (item.uid == _curComInfo.uid);
            if (_validatedInfoDic.ContainsKey(item.uid) && !_validatedInfoDic[item.uid])
            {
                GUI.backgroundColor = Color.red;
            }
            else
            {
                GUI.backgroundColor = highlight ? Color.white : new Color(0.8f, 0.8f, 0.8f);
            }
            GUILayout.BeginHorizontal("AS TextArea", GUILayout.MinHeight(20f));

            GUI.backgroundColor = Color.white;
            GUILayout.Label(index.ToString(), GUILayout.Width(20f));

            if (GUILayout.Button(item.GetName(), "OL TextField", GUILayout.Height(20f)))
            {
                _curComInfo = item;
                Selection.activeTransform = UIPrefabRoot.Find(_curComInfo.path);
            }

            if (_deleteUIDList.Contains(item.uid))
            {
                GUI.backgroundColor = Color.red;

                if (GUILayout.Button("Delete", GUILayout.Width(60f)))
                {
                    delete = true;
                }
                GUI.backgroundColor = Color.green;
                if (GUILayout.Button("X", GUILayout.Width(22f)))
                {
                    _deleteUIDList.Remove(item.uid);
                    delete = false;
                }
                GUI.backgroundColor = Color.white;
            }
            else
            {
                // If we have not yet selected a sprite for deletion, show a small "X" button
                if (GUILayout.Button("X", GUILayout.Width(22f)))
                {
                    _deleteUIDList.Add(item.uid);
                }
            }
            GUILayout.EndHorizontal();
        }
        EditorGUILayout.EndScrollView();
        GUILayout.EndVertical();
        GUILayout.Space(3f);
        GUILayout.EndHorizontal();

        if (delete)
        {
            foreach (string uid in _deleteUIDList)
            {
                _exportInfoDic.Remove(uid);
                _validatedInfoDic.Remove(uid);
            }
            _deleteUIDList.Clear();
            exportDicChanged = true;
        }

        EditorGUILayout.BeginHorizontal();

        //  C# 代码生成 ###############################
        if (GUILayout.Button("GenerateC#Code", GUILayout.Width(120f), GUILayout.Height(40f)))
        {
            if (relateFileCreateEnable)
            {
                var comList = new List <UIComponentInfo>(_exportInfoDic.Values);

                if (!ProduceCSharpCode(comList))
                {
                    ShowNotification(new GUIContent("Code generate Failure"));
                }
            }
        }

        EditorGUILayout.EndHorizontal();
        GUILayout.Space(10f);
    }
Exemple #6
0
    void DrawSelectionComponentView()
    {
        EditorGUILayout.BeginVertical(GUILayout.MinWidth(150f));
        if (EditorHelper.DrawHeader("Node Components"))
        {
            selectionViewPos = EditorGUILayout.BeginScrollView(selectionViewPos, "TextField");

            //根节点只显示除GameObject、Transform以外的组件
            int validateCode = ValidateSelection(Selection.activeTransform);
            if (validateCode != ERROR_NODE)
            {
                if (validateCode != ROOT_NODE && GUILayout.Button("---GameObject---"))
                {
                    UIComponentInfo newInfo = new UIComponentInfo(Selection.activeGameObject, UIPrefabRoot);
                    if (_exportInfoDic.ContainsKey(newInfo.uid))
                    {
                        _curComInfo = _exportInfoDic[newInfo.uid];
                    }
                    else
                    {
                        _curComInfo = newInfo;
                    }

                    EditorGUIUtility.editingTextField = false;
                }
                GUILayout.Space(3f);

                GUILayout.Label("ComponentList");
                var comList = Selection.activeTransform.GetComponents <Component>();
                foreach (Component com in comList)
                {
                    if (validateCode == ROOT_NODE && com.GetType().Name == "Transform")
                    {
                        continue;
                    }

                    if (GUILayout.Button(com.GetType().Name))
                    {
                        var newInfo = new UIComponentInfo(com, UIPrefabRoot);
                        if (_exportInfoDic.ContainsKey(newInfo.uid))
                        {
                            _curComInfo = _exportInfoDic[newInfo.uid];
                        }
                        else
                        {
                            _curComInfo = newInfo;
                        }

                        EditorGUIUtility.editingTextField = false;
                    }
                    GUILayout.Space(3f);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("This is not a node of UIPrefab", MessageType.Info);
            }
            EditorGUILayout.EndScrollView();
        }

        EditorGUILayout.EndVertical();
    }
Exemple #7
0
    public void LoadUIViewByScript()
    {
        var _path = GetPathNameFromConfig();

        if (string.IsNullOrEmpty(_path) || !File.Exists(_path))
        {
            return;
        }

        var sFileContent = File.ReadAllText(_path);

        if (string.IsNullOrEmpty(sFileContent))
        {
            return;
        }

        var contentMat = Regex.Match(sFileContent, @"protected override void InitElementBinding\s*\(\)[\n\s]*\{[\n\s]*([\n\s\S]+?)[\n\s]*\}");

        if (!contentMat.Success)
        {
            Debug.LogError("匹配出错!");
            return;
        }

        var sContent = contentMat.Groups[1].Value;
        var sLines   = sContent.Split('\n');
        var pat1     = @"(\S+) = root\.FindScript<(\S+)>\(""(\S+)?""\)";
        var pat2     = @"(\S+) = root\.FindTrans\(""(\S+)?""\);";
        var pat3     = @"(\S+) = root\.FindGameObject\(""(\S+)?""\);";

        var pat4       = @"(\S+) = root\.GetComponent<(\S+)>\(\)";
        var pat5       = @"(\S+) = root\.Find\(""(\S+)""\)(\S*);";
        var comPattern = @"\.GetComponent<(\S+)>\(\)";

        Match mat;

        foreach (string sLine in sLines)
        {
            if (string.IsNullOrEmpty(sLine) ||
                sLine.Contains("var root = this.gameObject"))
            {
                continue;
            }

            var name = string.Empty;
            var type = string.Empty;
            var path = string.Empty;

            mat = Regex.Match(sLine, pat1);
            if (mat.Success)
            {
                name = mat.Groups[1].Value;
                type = mat.Groups[2].Value;
                path = mat.Groups[3].Value;
            }
            else if ((mat = Regex.Match(sLine, pat2)).Success)
            {
                name = mat.Groups[1].Value;
                path = mat.Groups[2].Value;
                type = "Transform";
            }

            else if ((mat = Regex.Match(sLine, pat3)).Success)
            {
                name = mat.Groups[1].Value;
                path = mat.Groups[2].Value;
                type = "GameObject";
            }
            else if ((mat = Regex.Match(sLine, pat4)).Success)
            {
                name = mat.Groups[1].Value;
                type = mat.Groups[2].Value;
                path = "";
            }
            else if ((mat = Regex.Match(sLine, pat5)).Success)
            {
                name = mat.Groups[1].Value;
                path = mat.Groups[2].Value;

                type = mat.Groups[3].Value;
                if (string.IsNullOrEmpty(type))
                {
                    type = "Transform";
                }
                else if (type.EndsWith("gameObject"))
                {
                    type = "GameObject";
                }
                else if (type.Contains("GetComponent"))
                {
                    var comMat = Regex.Match(sLine, comPattern);
                    if (comMat == null || !comMat.Success)
                    {
                        Debug.LogError("未匹配的类型");
                    }
                    type = comMat.Groups[1].Value;
                }
                else
                {
                    Debug.LogError("未匹配的类型:" + sLine);
                }
            }
            else
            {
                GameDebuger.LogError(" 匹配出错:" + sLine);
                continue;
            }

            if (path.Contains(" "))
            {
                GameDebuger.LogError(string.Format("路径中有空格!path:{0}", path));
                path = path.Replace(" ", string.Empty);
            }
            if (string.IsNullOrEmpty(name))
            {
                continue;
            }

            var item = new UIComponentInfo(UIPrefabRoot, name, path, type);
            if (!_exportInfoDic.ContainsKey(item.uid))
            {
                _exportInfoDic.Add(item.uid, item);
            }
            var itemTrans = UIPrefabRoot.Find(item.path);
            _validatedInfoDic.Add(item.uid, (itemTrans != null));
        }
    }