コード例 #1
0
        private void DrawRight()
        {
            EditorGUILayout.BeginVertical();
            {
                var rect = EditorGUILayout.GetControlRect();
                rect.height = 35;
                GUI.Box(rect, "代码预览", "GroupBox");
                GUILayout.Space(20);

                {
                    pos = EditorGUILayout.BeginScrollView(pos, GUILayout.Width(position.width * 0.5f));
                    {
                        if (GConfigure.selectTransform != null)
                        {
                            var str   = m_Manager.ToString();
                            var array = GGlobalFun.GetStringList(str);
                            EditorGUILayout.BeginVertical();
                            {
                                foreach (var item in array)
                                {
                                    GUILayout.Label(item);
                                }
                            }
                            EditorGUILayout.EndVertical();
                        }
                    }
                    EditorGUILayout.EndScrollView();
                }
            }
            EditorGUILayout.EndVertical();
        }
コード例 #2
0
ファイル: GManagerVariable.cs プロジェクト: tkonexhh/NewWorld
        //挂载脚本
        public void MountScript()
        {
            if (GConfigure.selectTransform == null)
            {
                return;
            }

            if (EditorApplication.isCompiling)
            {
                EditorUtility.DisplayDialog(GConfigure.msgTitle, GConfigure.editorCompiling, GConfigure.ok);
                return;
            }

            var name = GConfigure.MainFileName;
            //一定要添加命名空间
            var scriptType = GGlobalFun.GetAssembly().GetType(GConfigureDefine.namespaceStr + "." + name);

            if (scriptType == null)
            {
                EditorUtility.DisplayDialog(GConfigure.msgTitle, GConfigure.notCreate, GConfigure.ok);
                return;
            }
            var root   = GConfigure.selectTransform.gameObject;
            var target = root.GetComponent(scriptType);

            if (target == null)
            {
                target = root.AddComponent(scriptType);
                return;
            }

            EditorUtility.DisplayDialog(GConfigure.msgTitle, GConfigure.hasMount, GConfigure.ok);
        }
コード例 #3
0
        private string GetName(string value, Transform tr)
        {
            var    str  = GGlobalFun.GetString(value);
            string name = str;
            int    i    = 1;

            while (true)
            {
                if (nameDic.ContainsKey(name))
                {
                    if (nameDic[name] == tr)
                    {
                        break;
                    }
                    name = string.Format("{0}{1}", str, i++);
                }
                else
                {
                    break;
                }
            }
            nameDic[name] = tr;

            return(name);
        }
コード例 #4
0
        public GVariableModel(Transform t)
        {
            target = t;
            path   = GGlobalFun.GetGameObjectPath(t, Selection.activeTransform);
            type   = GetUIType();
            name   = GetName(string.Format("{0}_{1}", type, t.name), t);

            state.SetIndex(type, t);
            Init(state, this);
        }
コード例 #5
0
        public void SetIndex(string name, Transform t)
        {
            comNames = GGlobalFun.GetComponentsName(t);
            int count = comNames.Length;

            oldIndex = -1;
            for (int i = 0; i < count; i++)
            {
                if (name == comNames[i])
                {
                    index = i;
                    break;
                }
            }
        }
コード例 #6
0
        private void OnTypeChanged(QVariableState state, string value)
        {
            state.Model.type = value;
            state.Model.name = GetName(string.Format("{0}{1}", GConfigure.GetShortTypeName(state.Model.type), GConfigure.RemoveFrontTypeName(target.name)), target);
            state.SetName(state.Model.name);
            state.Model.isUI    = false;
            state.isSelectEvent = false;
            if (!IsUIType(state.Model.type))
            {
                state.Model.eventType             =
                    state.Model.variableEvent     =
                        state.Model.actionName    =
                            state.Model.eventName = string.Empty;
                return;
            }
            var uiType = (UIType)Enum.Parse(typeof(UIType), state.Model.type);

            state.Model.variableEvent = string.Empty;
            switch (uiType)
            {
            case UIType.Button:
                state.Model.variableEvent = "onClick";
                break;

            case UIType.InputField:
                state.Model.variableEvent = "onEndEdit";
                break;

            case UIType.ScrollRect:
            case UIType.Dropdown:
            case UIType.Scrollbar:
            case UIType.Slider:
            case UIType.Toggle:
                state.Model.variableEvent = "onValueChanged";
                break;
            }


            if (state.Model.variableEvent != string.Empty)
            {
                state.isSelectEvent    = true;
                state.Model.eventType  = parameters[(int)uiType];
                state.Model.actionName = state.Model.variableEvent.Insert(state.Model.variableEvent.Length, state.attributeName);
                state.Model.eventName  = GGlobalFun.GetFirstUpper(state.Model.actionName);
            }

            //Debug.LogError(state.Model.actionName + "---" + state.Model.variableEvent + "---" + state.attributeName);
        }
コード例 #7
0
ファイル: GManagerVariable.cs プロジェクト: tkonexhh/NewWorld
        public string GetMainCode()
        {
            switch (GConfigure.Version)
            {
            case ScriptVersion.Mono:
                return(string.Format(GConfigure.uiCode_Mono, GGlobalFun.GetString(GConfigure.selectTransform.name), GConfigure.uicodeOnAwake));

            case ScriptVersion.Panel:
                return(string.Format(GConfigure.uiCode_Panel, GGlobalFun.GetString(GConfigure.selectTransform.name), GConfigure.uicodeQarthPanel));

            case ScriptVersion.AnimPanel:
                return(string.Format(GConfigure.uiCode_AnimPanel, GGlobalFun.GetString(GConfigure.selectTransform.name), GConfigure.uicodeQarthAnimPanel));

            default:
                return(string.Format(GConfigure.uiCode_Mono, GGlobalFun.GetString(GConfigure.selectTransform.name), GConfigure.uicodeOnAwake));
            }
        }
コード例 #8
0
 private static string GetMainFileName()
 {
     return(string.Format("{0}", GGlobalFun.GetString(Selection.activeTransform.name)));
 }
コード例 #9
0
 private static string GetFileName(string suffix)
 {
     return(string.Format("{0}/{1}_{0}", suffix, GGlobalFun.GetString(Selection.activeTransform.name)));
 }
コード例 #10
0
        public static string GetSelectObjectRootPath()
        {
            var path = string.Format("{0}/{1}/{2}/", Application.dataPath, referencePath, GGlobalFun.GetString(Selection.activeTransform.name));

            return(path);
        }
コード例 #11
0
        public static string FilePath(string name)
        {
            var filePath = string.Format("{0}/{1}/{2}/{3}.cs", Application.dataPath, referencePath, GGlobalFun.GetString(Selection.activeTransform.name), name);

            if (!FileHelper.IsDirctoryName(filePath, true))
            {
                EditorUtility.DisplayDialog(msgTitle, "文件夹无法创建", "OK");
                Debug.LogException(new Exception("文件夹无法创建"));
            }
            return(filePath);
        }
コード例 #12
0
        public bool Update(Transform t, int depth)
        {
            var rect = EditorGUILayout.BeginHorizontal();

            {
                if (isVariable)
                {
                    EditorGUI.DrawRect(rect, new Color(0, 0.5f, 0, 0.3f));
                }

                if (parentState != null)
                {
                    EditorGUILayout.LabelField("----", GConfigureDefine.toggleMaxWidth);
                    if (GUILayout.Button("-", GConfigureDefine.plusMaxWidth))
                    {
                        parentState.lstSubState.Remove(this);
                        //删去一个sub
                        //parentState.lsts
                        parentState.onSubStateDel(this);
                    }
                }

                isVariable = EditorGUILayout.ToggleLeft("变量", isVariable, GConfigureDefine.toggleMaxWidth);

                if (!isVariable)
                {
                    isAttribute = false;
                    isEvent     = false;
                    lstSubState.Clear();
                    // if (parentState != null)
                    //     parentState.onSubStateChanged();
                }

                {
                    GUI.enabled = isVariable;
                    isAttribute = EditorGUILayout.ToggleLeft("属性器", isAttribute, GConfigureDefine.toggleMaxWidth);

                    GUI.enabled = !isVariable ? false : isSelectEvent;
                    isEvent     = EditorGUILayout.ToggleLeft("事件", isEvent, GConfigureDefine.toggleMaxWidth);

                    GUI.enabled = true;
                    if (parentState == null)
                    {
                        if (isVariable && GUILayout.Button("+", GConfigureDefine.plusMaxWidth))
                        {
                            var subState = new QVariableState();
                            subState.comNames    = comNames;
                            subState.isVariable  = true;
                            subState.parentState = this;
                            lstSubState.Add(subState);
                            onSubStateAdd(subState);
                            //添加一个sub
                        }
                    }
                }

                attributeName = EditorGUILayout.TextField(attributeName, GConfigureDefine.attriNameMaxWidth);

                oldIndex = index;
                comNames = GGlobalFun.GetComponentsName(t);

                index = EditorGUILayout.Popup(index, comNames, GConfigureDefine.popupMaxWidth);

                if (oldIndex != index)
                {
                    onTypeChanged(this, comNames[index]);
                }

                GUILayout.Space(depth * GConfigureDefine.space);

                if (t.childCount > 0)
                {
                    isOpen = EditorGUILayout.Foldout(isOpen, t.name, true);
                }
                else
                {
                    EditorGUILayout.LabelField(t.name);
                }
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            for (int i = 0; i < lstSubState.Count; i++)
            {
                EditorGUILayout.BeginVertical();
                lstSubState[i].Update(t, depth);
                EditorGUILayout.EndVertical();
            }


            return(isOpen);
        }
コード例 #13
0
 public string GetEventMethodName()
 {
     return(state.Model.eventName = GGlobalFun.GetFirstUpper(state.Model.actionName));
 }
コード例 #14
0
ファイル: GManagerVariable.cs プロジェクト: tkonexhh/NewWorld
        public string GetBuildUICode()
        {
            newAttribute.Length                            =
                attributeVariable.Length                   =
                    function.Length                        =
                        register.Length                    =
                            variable.Length                =
                                assetNotNull.Length        =
                                    controllerEvent.Length =
                                        attribute.Length   =
                                            find.Length    = 0;

            foreach (var value in dic.Values)
            {
                if (!value.state.isVariable)
                {
                    continue;
                }
                variable.AppendFormat(GConfigure.variableFormat, value.type, value.state.attributeName);
                assetNotNull.AppendFormat(GConfigure.assetNotNull, value.state.attributeName);

                for (int i = 0; i < value.LstSubModel.Count; i++)
                {
                    if (value.LstSubModel[i].state.isVariable)
                    {
                        variable.AppendFormat(GConfigure.variableFormat, value.LstSubModel[i].type, value.LstSubModel[i].state.attributeName);
                        assetNotNull.AppendFormat(GConfigure.assetNotNull, value.LstSubModel[i].state.attributeName);
                    }
                }

                if (isFind)
                {
                    find.AppendFormat(GConfigure.findFormat, value.name, value.path, value.type);
                }

                // if (value.state.isAttribute)
                // {
                //     attribute.AppendFormat(GConfigure.attributeFormat, value.type, value.state.attributeName);
                //     assetNotNull.AppendFormat(GConfigure.assetNotNull, value.state.attributeName);
                // }

                // for (int i = 0; i < value.LstSubModel.Count; i++)
                // {
                //     if (value.LstSubModel[i].state.isAttribute)
                //     {
                //         attribute.AppendFormat(GConfigure.attributeFormat, value.LstSubModel[i].type, value.LstSubModel[i].state.attributeName);
                //         assetNotNull.AppendFormat(GConfigure.assetNotNull, value.state.attributeName);
                //     }
                // }

                if (value.variableEvent != string.Empty && value.state.isEvent)
                {
                    controllerEvent.AppendFormat(GConfigure.controllerEventFormat,
                                                 value.IsButton() ? string.Empty : string.Format("<{0}>", value.eventType),
                                                 value.GetActionMethodName());

                    register.AppendFormat(GConfigure.registerFormat, value.state.attributeName, value.variableEvent, value.GetEventMethodName());

                    function.AppendFormat(GConfigure.functionFormat, value.eventName,
                                          value.eventType + (!value.eventType.IsLengthZero() ? " value" : string.Empty),
                                          value.state.attributeName,
                                          value.actionName,
                                          value.IsButton() ? string.Empty : "value");
                }

                for (int i = 0; i < value.LstSubModel.Count; i++)
                {
                    if (value.LstSubModel[i].variableEvent != string.Empty && value.LstSubModel[i].state.isEvent)
                    {
                        controllerEvent.AppendFormat(GConfigure.controllerEventFormat,
                                                     value.LstSubModel[i].IsButton() ? string.Empty : string.Format("<{0}>", value.LstSubModel[i].eventType),
                                                     value.LstSubModel[i].GetActionMethodName());

                        register.AppendFormat(GConfigure.registerFormat, value.LstSubModel[i].state.attributeName, value.LstSubModel[i].variableEvent, value.LstSubModel[i].GetEventMethodName());

                        function.AppendFormat(GConfigure.functionFormat, value.LstSubModel[i].eventName,
                                              value.LstSubModel[i].eventType + (!value.LstSubModel[i].eventType.IsLengthZero() ? " value" : string.Empty),
                                              value.LstSubModel[i].state.attributeName,
                                              value.LstSubModel[i].actionName,
                                              value.LstSubModel[i].IsButton() ? string.Empty : "value");
                    }
                }
            }

            var tmp = string.Format(GConfigure.Version == ScriptVersion.Mono ? GConfigure.uiClassCode_Mono : GConfigure.uiClassCode,
                                    variable, attributeVariable, controllerEvent, attribute, assetNotNull, find, newAttribute, register, function);

            return(string.Format(GConfigure.uiCode_BindUI, GGlobalFun.GetString(GConfigure.selectTransform.name), tmp));
        }
コード例 #15
0
ファイル: GManagerVariable.cs プロジェクト: tkonexhh/NewWorld
        private void GetBindingInfo()
        {
            GScriptInfo so;

            if (FileHelper.IsExists(GConfigure.InfoPath))
            {
                so = AssetDatabase.LoadAssetAtPath <GScriptInfo>(GConfigure.InfoPath);
            }
            else
            {
                so = ScriptableObject.CreateInstance <GScriptInfo>();
            }

            if (so == null)
            {
                return;
            }

            List <GScriptInfo.FieldInfo> fieldInfos = new List <GScriptInfo.FieldInfo>();

            foreach (var key in dic.Keys)
            {
                var target = dic[key];
                if (target.state.isVariable)
                {
                    GScriptInfo.FieldInfo info = new GScriptInfo.FieldInfo();
                    info.path = GGlobalFun.GetGameObjectPath(key, GConfigure.selectTransform);
                    info.mainAttrInfo.name    = target.state.attributeName;
                    info.mainAttrInfo.type    = target.type.ToString();
                    info.mainAttrInfo.isAttr  = target.state.isAttribute;
                    info.mainAttrInfo.isEvent = target.state.isEvent;

                    var subStates = target.state.LstSubState;
                    info.subField = new List <GScriptInfo.FieldAttrInfo>();
                    for (int i = 0; i < subStates.Count; i++)
                    {
                        GScriptInfo.FieldAttrInfo subInfo = new GScriptInfo.FieldAttrInfo();
                        subInfo.name    = subStates[i].attributeName;
                        subInfo.type    = subStates[i].Model.type.ToString();
                        subInfo.isAttr  = subStates[i].isAttribute;
                        subInfo.isEvent = subStates[i].isEvent;
                        info.subField.Add(subInfo);
                    }
                    fieldInfos.Add(info);
                }
            }

            var infos = fieldInfos.ToArray();

            so.SetClassInfo(GConfigure.MainFileName, GConfigure.Version, infos);

            if (FileHelper.IsExists(GConfigure.InfoPath))
            {
                AssetDatabase.SaveAssets();
            }
            else
            {
                if (FileHelper.IsDirctoryName(GConfigure.InfoPath, true))
                {
                    AssetDatabase.CreateAsset(so, GConfigure.InfoPath);
                }
            }

            EditorUtility.SetDirty(so);
        }
コード例 #16
0
ファイル: GManagerVariable.cs プロジェクト: tkonexhh/NewWorld
        public void BindingUI()
        {
            if (GConfigure.selectTransform == null)
            {
                return;
            }
            if (EditorApplication.isCompiling)
            {
                EditorUtility.DisplayDialog(GConfigure.msgTitle, GConfigure.editorCompiling, GConfigure.ok);
                return;
            }

            if (GConfigure.selectTransform.GetComponent(GConfigure.MainFileName) == null)
            {
                EditorUtility.DisplayDialog(GConfigure.msgTitle, GConfigure.noMountScript, GConfigure.ok);
                return;
            }

            var assembly = GGlobalFun.GetAssembly();
            var type     = assembly.GetType(GConfigureDefine.namespaceStr + "." + GConfigure.MainFileName);

            if (type == null)
            {
                EditorUtility.DisplayDialog(GConfigure.msgTitle, GConfigure.notCreate, GConfigure.ok);
                return;
            }

            var root   = GConfigure.selectTransform;
            var target = root.GetComponent(type);

            var so = AssetDatabase.LoadAssetAtPath <GScriptInfo>(GConfigure.InfoPath);

            if (so == null)
            {
                return;
            }
            var infos = so.GetFieldInfos(GConfigure.MainFileName);

            if (infos == null)
            {
                EditorUtility.DisplayDialog(GConfigure.msgTitle, GConfigure.plugCreate, GConfigure.ok);
                return;
            }
            foreach (var info in infos)
            {
                if (string.IsNullOrEmpty(info.mainAttrInfo.name))
                {
                    continue;
                }
                BindAttributeByInfo(type, root, target, info, info.mainAttrInfo);

                foreach (var subInfo in info.subField)
                {
                    if (string.IsNullOrEmpty(subInfo.name))
                    {
                        continue;
                    }
                    BindAttributeByInfo(type, root, target, info, subInfo);
                }
            }
        }