Пример #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());
        }
Пример #2
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;
                }
            }
        }
Пример #3
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();
            }
        }