Beispiel #1
0
        public void Init()
        {
            if (!QFileOperation.IsExists(QConfigure.GetInfoPath()))
            {
                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());
                    var          obj = QConfigure.selectTransform.Find(vj.findPath);
                    if (obj == null)
                    {
                        continue;
                    }
                    var v = this[obj];
                    if (v == null)
                    {
                        continue;
                    }
                    v.state.isOpen      = vj.isOpen;
                    v.state.isVariable  = vj.isVariable;
                    v.state.isAttribute = vj.isAttribute;
                    v.state.isEvent     = vj.isEvent;
                    v.state.index       = vj.index;
                }
            }
        }
Beispiel #2
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);
                }
            }
        }
Beispiel #3
0
        public void CreateFile()
        {
            if (QConfigure.selectTransform == null)
            {
                EditorUtility.DisplayDialog(QConfigure.msgTitle, QConfigure.noSelect, QConfigure.ok);
                return;
            }
            if (EditorApplication.isCompiling)
            {
                EditorUtility.DisplayDialog(QConfigure.msgTitle, QConfigure.editorCompiling, QConfigure.ok);
                return;
            }
            if (QFileOperation.IsExists(QConfigure.FilePath(QConfigure.UIBuildFileName)))
            {
                EditorUtility.DisplayDialog(QConfigure.msgTitle, QConfigure.haveBeenCreated, QConfigure.ok);
                return;
            }

            QFileOperation.WriteText(QConfigure.FilePath(QConfigure.UIFileName), GetUICode());
            QFileOperation.WriteText(QConfigure.FilePath(QConfigure.UIBuildFileName), GetBuildUICode());

            if (QConfigure.isCreateModel)
            {
                QFileOperation.WriteText(QConfigure.FilePath(QConfigure.ModelFileName), GetModelCode());
            }

            if (QConfigure.isCreateController)
            {
                QFileOperation.WriteText(QConfigure.FilePath(QConfigure.ControllerFileName), GetControllerCode());
                QFileOperation.WriteText(QConfigure.FilePath(QConfigure.ControllerBuildFileName), GetControllerBuildCode());
            }

            if (QConfigure.version == 1)
            {
                GetBindingInfo();
            }
            else
            {
                GetBindingInfoToJson();
            }
            QConfigure.Compiling();
            AssetDatabase.Refresh();
        }
Beispiel #4
0
        public void Update()
        {
            if (QConfigure.selectTransform == null)
            {
                return;
            }
            if (EditorApplication.isCompiling)
            {
                EditorUtility.DisplayDialog(QConfigure.msgTitle, QConfigure.editorCompiling, QConfigure.ok);
                return;
            }
            var fileName = QConfigure.FilePath(QConfigure.UIBuildFileName);

            if (!QFileOperation.IsExists(fileName))
            {
                EditorUtility.DisplayDialog(QConfigure.msgTitle, QConfigure.notCreate, QConfigure.ok);
                return;
            }
            QFileOperation.WriteText(QConfigure.FilePath(QConfigure.UIBuildFileName), GetBuildUICode(), FileMode.Create);

            if (QConfigure.isCreateController)
            {
                QFileOperation.WriteText(QConfigure.FilePath(QConfigure.ControllerBuildFileName), GetControllerBuildCode(), FileMode.Create);
            }

            if (QConfigure.version == 1)
            {
                GetBindingInfo();
            }
            else
            {
                GetBindingInfoToJson();
            }
            QConfigure.Compiling();
            AssetDatabase.Refresh();
        }
Beispiel #5
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();
            }
        }