Ejemplo n.º 1
0
        public void GetBindingInfoToJson()
        {
            if (QConfigure.selectTransform == null)
            {
                return;
            }

            JsonData jd = new JsonData();

            foreach (var item in dic)
            {
                if (!item.Value.state.isVariable)
                {
                    continue;
                }
                VariableJson vj    = new VariableJson();
                var          state = item.Value.state;
                vj.isOpen      = state.isOpen;
                vj.isAttribute = state.isAttribute;
                vj.isEvent     = state.isEvent;
                vj.isVariable  = state.isVariable;
                vj.index       = state.index;
                vj.name        = item.Value.name;
                vj.type        = item.Value.type;
                vj.findPath    = QGlobalFun.GetGameObjectPath(item.Key, QConfigure.selectTransform);
                jd.Add(JsonMapper.ToObject(JsonMapper.ToJson(vj)));
            }
            QFileOperation.WriteText(QConfigure.GetInfoPath(), jd.ToJson());
        }
Ejemplo n.º 2
0
        public void MountScript()
        {
            if (QConfigure.selectTransform == null)
            {
                return;
            }

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

            var name       = QConfigure.UIName;
            var scriptType = QGlobalFun.GetAssembly().GetType(name);

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

            if (target == null)
            {
                target = root.AddComponent(scriptType);
            }
        }
Ejemplo n.º 3
0
        private string GetName(string value, Transform tr)
        {
            var str = QGlobalFun.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);
        }
Ejemplo n.º 4
0
        private void DrawRight()
        {
            EditorGUILayout.BeginVertical();
            {
                var rect = EditorGUILayout.GetControlRect();
                rect.height = 35;
                GUI.Box(rect, "代码预览", "GroupBox");
                GUILayout.Space(20);

                //EditorGUILayout.BeginVertical();
                {
                    pos = EditorGUILayout.BeginScrollView(pos, GUILayout.Width(position.width * 0.5f));
                    {
                        if (QConfigure.selectTransform != null)
                        {
                            var str   = manager.ToString();
                            var array = QGlobalFun.GetStringList(str);
                            EditorGUILayout.BeginVertical();
                            {
                                foreach (var item in array)
                                {
                                    GUILayout.Label(item);
                                }
                            }
                            EditorGUILayout.EndVertical();
                        }
                    }
                    EditorGUILayout.EndScrollView();
                }
                //EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndVertical();
        }
Ejemplo n.º 5
0
 public QVariableModel(Transform t)
 {
     target = t;
     path   = QGlobalFun.GetGameObjectPath(t, Selection.activeTransform);
     type   = GetUIType();
     name   = GetName(string.Format("{0}_{1}", type, t.name), t);
     state.SetIndex(type, t);
     OnTypeChanged(type);
     state.onTypeChanged = OnTypeChanged;
 }
Ejemplo n.º 6
0
        private void GetBindingInfo()
        {
            QScriptInfo so;

            if (QFileOperation.IsExists(QConfigure.InfoPath))
            {
                so = AssetDatabase.LoadAssetAtPath <QScriptInfo>(QConfigure.InfoPath);
            }
            else
            {
                so = ScriptableObject.CreateInstance <QScriptInfo>();
            }

            List <string> k = new List <string>(dic.Count);
            List <string> t = new List <string>(dic.Count);
            List <string> p = new List <string>(dic.Count);

            foreach (var key in dic.Keys)
            {
                var target = dic[key];
                if (target.state.isVariable)
                {
                    k.Add(target.name);
                    t.Add(target.type.ToString());
                    p.Add(QGlobalFun.GetGameObjectPath(key, QConfigure.selectTransform));
                }
            }

            int count = k.Count;
            var infos = new QScriptInfo.FieldInfo[count];

            for (int i = 0; i < count; i++)
            {
                infos[i]      = new QScriptInfo.FieldInfo();
                infos[i].name = k[i];
                infos[i].type = t[i];
                infos[i].path = p[i];
            }

            so.SetClassInfo(QConfigure.UIName, infos);

            if (QFileOperation.IsExists(QConfigure.InfoPath))
            {
                AssetDatabase.SaveAssets();
            }
            else
            {
                if (QFileOperation.IsDirctoryName(QConfigure.InfoPath, true))
                {
                    AssetDatabase.CreateAsset(so, QConfigure.InfoPath);
                }
            }
        }
Ejemplo n.º 7
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));
                }

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

                if (!isVariable)
                {
                    isAttribute = false;
                    isEvent     = false;
                }

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

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

                oldIndex = index;
                comNames = QGlobalFun.GetComponentsName(t);
                index    = EditorGUILayout.Popup(index, comNames, popupMaxWidth);
                if (oldIndex != index)
                {
                    onTypeChanged(comNames[index]);
                }

                GUILayout.Space(depth * space);

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

            EditorGUILayout.Space();

            return(isOpen);
        }
Ejemplo n.º 8
0
        public void SetIndex(string name, Transform t)
        {
            comNames = QGlobalFun.GetComponentsName(t);

            int count = comNames.Length;

            for (int i = 0; i < count; i++)
            {
                if (name == comNames[i])
                {
                    index = i;
                    break;
                }
            }
        }
Ejemplo n.º 9
0
        private void OnTypeChanged(string value)
        {
            type = value;
            name = GetName(string.Format("{0}_{1}", type, target.name), target);
            isUI = false;
            state.isSelectEvent = false;
            if (!IsUIType(type))
            {
                eventType             =
                    variableEvent     =
                        attributeName =
                            eventName = string.Empty;
                return;
            }
            var uiType = (UIType)Enum.Parse(typeof(UIType), type);

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

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

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

            if (variableEvent != string.Empty)
            {
                state.isSelectEvent = true;
                eventType           = parameters[(int)uiType];
                attributeName       = variableEvent.Insert(2, name);
                eventName           = QGlobalFun.GetFirstUpper(attributeName);
            }
        }
Ejemplo n.º 10
0
        public string GetControllerBuildCode()
        {
            assignment.Length  =
                declare.Length =
                    fun.Length = 0;
            string type = string.Empty;

            foreach (var value in dic.Values)
            {
                if (value.variableEvent != string.Empty && value.state.isEvent)
                {
                    type = value.IsButton() ? string.Empty : string.Format("{0} value", value.eventType);
                    //assignment.AppendFormat("\t\tui.{0,-50} = {1};\n", value.attributeName, value.eventName);
                    assignment.AppendFormat(QConfigure.assignmentFormat, value.attributeName, value.eventName);
                    //declare.AppendFormat("\tpartial void {0}({1});\n", value.attributeName, type);
                    declare.AppendFormat(QConfigure.declareFormat, value.attributeName, type);

                    /*fun.AppendFormat("\tprivate void {0}({1})\n\t{{\n\t\t{2}({3});\n\t}}\n",
                     *  value.eventName, type, value.attributeName, value.type == "Button" ? string.Empty : "value");*/
                    fun.AppendFormat(QConfigure.funFormat, value.eventName, type,
                                     value.attributeName, value.IsButton() ? string.Empty : "value");
                }
            }

            string code = string.Empty;

            if (QConfigure.isCreateModel)
            {
                code = QConfigure.controllerBuildCode;
            }
            else
            {
                code = QConfigure.controllerBuildCode2;
            }
            return(string.Format(
                       code,
                       QGlobalFun.GetString(QConfigure.selectTransform.name),
                       assignment,
                       declare,
                       fun));
        }
Ejemplo n.º 11
0
 public string GetUICode()
 {
     return(string.Format(QConfigure.uiCode, QGlobalFun.GetString(QConfigure.selectTransform.name), QConfigure.uicodeOnAwake));
 }
Ejemplo n.º 12
0
 public string GetModelCode()
 {
     return(string.Format(QConfigure.modelCode, QGlobalFun.GetString(QConfigure.selectTransform.name)));
 }
Ejemplo n.º 13
0
 private static string GetFileName(string suffix)
 {
     return(string.Format("{0}/{1}_{0}", suffix, QGlobalFun.GetString(Selection.activeTransform.name)));
 }
Ejemplo n.º 14
0
 public static string GetClassName(string suffix)
 {
     return(string.Format("{1}_{0}", suffix, QGlobalFun.GetString(Selection.activeTransform.name)));
 }
Ejemplo n.º 15
0
        public string GetBuildUICode()
        {
            newAttribute.Length                        =
                attributeVariable.Length               =
                    function.Length                    =
                        register.Length                =
                            variable.Length            =
                                controllerEvent.Length =
                                    attribute.Length   =
                                        find.Length    = 0;

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

                if (isFind)
                {
                    //find.AppendFormat("\t\t{0,-25} = transform.Find(\"{1}\").GetComponent<{2}>();\n", value.name, value.path, value.type);
                    find.AppendFormat(QConfigure.findFormat, value.name, value.path, value.type);
                }

                if (value.state.isAttribute)
                {
                    if (value.isUI)
                    {
                        /*attributeVariable.AppendFormat("\tprivate Q{0} q{1};\n", value.type, value.name);
                         * attribute.AppendFormat("\tpublic Q{0} Q{1}{{get{{return q{1};}}}}\n", value.type, value.name);
                         * newAttribute.AppendFormat("\t\tq{0,-49} = new Q{1}({0});\n", value.name, value.type);*/
                        attributeVariable.AppendFormat(QConfigure.attributeVariableFormat, value.type, value.name);
                        attribute.AppendFormat(QConfigure.attributeFormat, value.type, value.name);
                        newAttribute.AppendFormat(QConfigure.newAttributeFormat, value.name, value.type);
                    }
                    else
                    {
                        //attribute.AppendFormat("\tpublic {0} Q{1}{{get{{return {1};}}}}\n", value.type, value.name);
                        attribute.AppendFormat(QConfigure.attribute2Format, value.type, value.name);
                    }
                }

                if (value.variableEvent != string.Empty && value.state.isEvent)
                {
                    /*register.AppendFormat("\t\t{0}.{1}.AddListener( {2} );\n", value.name, value.variableEvent, value.eventName);
                     * controllerEvent.AppendFormat("\tpublic Action{0,-20} {1};\n", value.type == "Button" ? string.Empty : string.Format("<{0}>", value.eventType), value.attributeName);
                     * function.AppendFormat("\tprivate void {0}({1})\n\t{{\n\t\tif({2}!=null){2}({3});\n\t}}\n", value.eventName,
                     *  value.eventType + (value.eventType != string.Empty ? " value" : ""), value.attributeName,
                     *  value.type == "Button" ? string.Empty : "value");*/
                    register.AppendFormat(QConfigure.registerFormat, value.name, value.variableEvent, value.eventName);
                    controllerEvent.AppendFormat(QConfigure.controllerEventFormat, value.IsButton() ? string.Empty : string.Format("<{0}>", value.eventType), value.attributeName);
                    function.AppendFormat(QConfigure.functionFormat, value.eventName,
                                          value.eventType + (!value.eventType.IsLengthZero() ? " value" : string.Empty), value.attributeName,
                                          value.IsButton() ? string.Empty : "value");
                    //Debug.Log(value.IsButton());
                }
            }

            var tmp = string.Format(QConfigure.uiClassCode,
                                    variable, attributeVariable, controllerEvent, attribute, find, newAttribute, register, function);

            return(string.Format(QConfigure.uiCode2, QGlobalFun.GetString(QConfigure.selectTransform.name), tmp));
        }
Ejemplo n.º 16
0
 public string GetControllerCode()
 {
     return(string.Format(QConfigure.controllerCode, QGlobalFun.GetString(QConfigure.selectTransform.name)));
 }
Ejemplo n.º 17
0
        public void BindingUI()
        {
            if (QConfigure.selectTransform == null)
            {
                return;
            }
            if (EditorApplication.isCompiling)
            {
                EditorUtility.DisplayDialog(QConfigure.msgTitle, QConfigure.editorCompiling, QConfigure.ok);
                return;
            }
            if (QConfigure.selectTransform.GetComponent(QConfigure.UIName) == null)
            {
                EditorUtility.DisplayDialog(QConfigure.msgTitle, QConfigure.noMountScript, QConfigure.ok);
                return;
            }

            var assembly = QGlobalFun.GetAssembly();
            var type     = assembly.GetType(QConfigure.UIName);

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

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

            if (QConfigure.version == 1)
            {
                var so    = AssetDatabase.LoadAssetAtPath <QScriptInfo>(QConfigure.InfoPath);
                var infos = so.GetFieldInfos(QConfigure.UIName);
                if (infos == null)
                {
                    EditorUtility.DisplayDialog(QConfigure.msgTitle, QConfigure.plugCreate, QConfigure.ok);
                    return;
                }
                foreach (var info in infos)
                {
                    if (string.IsNullOrEmpty(info.name))
                    {
                        continue;
                    }
                    type.InvokeMember(info.name,
                                      BindingFlags.SetField |
                                      BindingFlags.Instance |
                                      BindingFlags.NonPublic,
                                      null, target, new object[] { root.Find(info.path).GetComponent(info.type) }, null, null, null);
                }
            }
            if (QConfigure.version == 2)
            {
                if (!QFileOperation.IsExists(QConfigure.GetInfoPath()))
                {
                    EditorUtility.DisplayDialog(QConfigure.msgTitle, QConfigure.plugCreate, QConfigure.ok);
                    return;
                }
                var value = QFileOperation.ReadText(QConfigure.GetInfoPath());
                var jd    = JsonMapper.ToObject(value);
                if (jd.IsArray)
                {
                    for (int i = 0; i < jd.Count; i++)
                    {
                        VariableJson vj = JsonMapper.ToObject <VariableJson>(jd[i].ToJson());
                        if (string.IsNullOrEmpty(vj.name))
                        {
                            continue;
                        }
                        type.InvokeMember(vj.name,
                                          BindingFlags.SetField |
                                          BindingFlags.Instance |
                                          BindingFlags.NonPublic,
                                          null, target, new object[] { root.Find(vj.findPath).GetComponent(vj.type) }, null, null, null);
                    }
                }
            }

            var obj = PrefabUtility.GetPrefabParent(root.gameObject);

            if (obj != null)
            {
                PrefabUtility.ReplacePrefab(root.gameObject, obj, ReplacePrefabOptions.ConnectToPrefab);
                AssetDatabase.Refresh();
            }
        }