コード例 #1
0
    /// <summary>
    /// 写入路径
    /// </summary>
    /// <returns></returns>
    public static string GetWritePath()
    {
        switch (Application.platform)
        {
        case RuntimePlatform.OSXEditor:
            return(Application.dataPath.Replace("/Assets", "") + "/Data/");

        case RuntimePlatform.IPhonePlayer:
            return(Application.persistentDataPath + "/");

        case RuntimePlatform.WindowsEditor:
            return(Application.dataPath.ToString().Replace("/Assets", "") + "/Data/");

        case RuntimePlatform.WindowsPlayer:
            var path = Application.dataPath.ToString().Replace("/Assets", "") + "/Data/";
            QFileOperation.CreateDirctory(path);
            return(path);

        case RuntimePlatform.Android:
            return(Application.persistentDataPath + "/");

        default:
            return(Application.persistentDataPath + "/");
        }
    }
コード例 #2
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());
        }
コード例 #3
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;
                }
            }
        }
コード例 #4
0
        public static string FilePath(string name)
        {
            var filePath = string.Format("{0}/{1}/{2}.cs", Application.dataPath, referencePath, name);

            if (!QFileOperation.IsDirctoryName(filePath, true))
            {
                EditorUtility.DisplayDialog(msgTitle, "文件夹无法创建", "OK");
                Debug.LogException(new Exception("文件夹无法创建"));
            }
            return(filePath);
        }
コード例 #5
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);
                }
            }
        }
コード例 #6
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();
        }
コード例 #7
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();
        }
コード例 #8
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();
            }
        }