Beispiel #1
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);
            }
        }
Beispiel #2
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();
            }
        }