Пример #1
0
        public static List <PluginCategory> GetLocalCategories(PTPluginConfigData resConfig)
        {
            List <PluginCategory> localCategories = new List <PluginCategory>();

            string[] files = System.IO.Directory.GetFiles(Application.dataPath, "ptplugin.txt", System.IO.SearchOption.AllDirectories);

            foreach (var config in resConfig.configDatas)
            {
                PluginCategory pluginCategory = new PluginCategory();

                pluginCategory.type = config.type;

                foreach (var fileInfo in files)
                {
                    string content = File.ReadAllText(Path.GetFullPath(fileInfo));

                    PluginInfo pluginInfo = JsonUtility.FromJson <PluginInfo> (content);

                    if (pluginInfo.type == config.type)
                    {
                        pluginCategory.plugins.Add(pluginInfo);
                    }
                }
                localCategories.Add(pluginCategory);
            }

            return(localCategories);
        }
Пример #2
0
        public void OnGUI()
        {
            mScrollPos = GUILayout.BeginScrollView(mScrollPos, true, true, GUILayout.Width(600), GUILayout.Height(480));

            GUILayout.BeginHorizontal("box");
            foreach (var configData in resConfig.configDatas)
            {
                if (configData.active)
                {
                    if (curLocalCategory.type == configData.type)
                    {
                        GUI.backgroundColor = Color.yellow;

                        GUILayout.Button(configData.type, focusCategoryStyle, GUILayout.Width(100));

                        GUI.backgroundColor = Color.white;
                    }
                    else
                    {
                        if (GUILayout.Button(configData.type, GUILayout.Width(100)))
                        {
                            curLocalCategory = PTPluginUtil.GetLocalCategoryByType(localCategories, configData.type);
                        }
                    }
                }
            }

            GUILayout.EndHorizontal();

            DrawCategory(curLocalCategory);

            GUILayout.EndScrollView();
        }
Пример #3
0
        public void OnEnable()
        {
            InitStyles();

            resConfig = PTPluginConfigData.GetPluginConfig();

            remoteCategories = PTPluginUtil.GetRemoteCategories(resConfig);

            localCategories = PTPluginUtil.GetLocalCategories(resConfig);

            curLocalCategory = PTPluginUtil.GetLocalCategoryByType(localCategories, resConfig.configDatas.FirstOrDefault(s => s.active).type);
        }
Пример #4
0
        public void DrawCategory(PluginCategory localCategory)
        {
            if (remoteCategories.Count == 0)
            {
                DrawNoServer(localCategory);
            }
            else
            {
                PluginCategory remoteCategory = remoteCategories.FirstOrDefault(s => s.type == localCategory.type);;

                DrawWithServer(localCategory, remoteCategory);
            }
        }
Пример #5
0
        private void DrawNoServer(PluginCategory category)
        {
            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Plugin", titleStyle, GUILayout.Width(150));
            GUILayout.Label("Local", titleStyle, GUILayout.Width(100));

            GUILayout.EndHorizontal();

            foreach (var plugin in category.plugins)
            {
                GUILayout.BeginHorizontal(EditorStyles.helpBox);

                GUILayout.Label(plugin.name, GUILayout.Width(150));

                GUILayout.Label(plugin.version, GUILayout.Width(100));

                GUILayout.EndHorizontal();
            }

            GUILayout.EndVertical();
        }
Пример #6
0
        public static List <PluginCategory> GetRemoteCategories(PTPluginConfigData resConfig)
        {
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                return(null);
            }

            WWW www = new WWW(resConfig.serverUrl + "/getplugins");

            while (!www.isDone)
            {
            }
            if (www.error != null)
            {
                return(null);
            }

            string json = www.text;

            PTPluginInfos pluginInfos = JsonUtility.FromJson <PTPluginInfos> (json);

            List <PluginCategory> categories = new List <PluginCategory>();

            foreach (var config in resConfig.configDatas)
            {
                if (config.active)
                {
                    PluginCategory category = new PluginCategory();
                    category.url     = resConfig.serverUrl;
                    category.type    = config.type;
                    category.plugins = pluginInfos.plugins.Where(s => s.type == config.type).ToList();
                    categories.Add(category);
                }
            }

            return(categories);
        }
Пример #7
0
        private void DrawWithServer(PluginCategory localCategory, PluginCategory serverCategory)
        {
            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Plugin", titleStyle, GUILayout.Width(150));
            GUILayout.Label("Server", titleStyle, GUILayout.Width(100));
            GUILayout.Label("Local", titleStyle, GUILayout.Width(100));
            GUILayout.Label("Action", titleStyle, GUILayout.Width(100));
            GUILayout.Label("Readme", titleStyle, GUILayout.Width(100));

            GUILayout.EndHorizontal();


            foreach (var serverPlugin in serverCategory.plugins)
            {
                GUILayout.BeginHorizontal(EditorStyles.helpBox);

                GUILayout.Label(serverPlugin.name, defaultStype, GUILayout.Width(150));

                GUILayout.Label(serverPlugin.version, titleStyle, GUILayout.Width(100));

                PluginInfo localPlugin = localCategory.GetPluginInfoByName(serverPlugin.name);

                if (localPlugin != null)
                {
                    if (PTPluginUtil.HasNewVersion(serverPlugin.version, localPlugin.version))
                    {
                        GUILayout.Label(localPlugin.version, newVersionStyle, GUILayout.Width(100));

                        if (GUILayout.Button("Update", GUILayout.Width(90)))
                        {
                            if (EditorUtility.DisplayDialog("UpdatePlugin", "是否移除本地旧版本?", "是", "否"))
                            {
                                if (!string.IsNullOrEmpty(localPlugin.url))
                                {
                                    Directory.Delete(localPlugin.url, true);

                                    AssetDatabase.Refresh();
                                }
                            }
                            PTPluginUpdate.UpdatePlugin(serverCategory.url + "/" + serverPlugin.url, serverPlugin.name + "_v" + serverPlugin.version);
                        }
                    }
                    else
                    {
                        GUILayout.Label(localPlugin.version, installedStyle, GUILayout.Width(100));

                        if (GUILayout.Button("Import", GUILayout.Width(90)))
                        {
                            if (EditorUtility.DisplayDialog("UpdatePlugin", "是否移除本地旧版本?", "是", "否"))
                            {
                                if (!string.IsNullOrEmpty(localPlugin.url))
                                {
                                    Directory.Delete(localPlugin.url, true);

                                    AssetDatabase.Refresh();
                                }
                            }

                            PTPluginUpdate.UpdatePlugin(serverCategory.url + "/" + serverPlugin.url, serverPlugin.name + "_v" + serverPlugin.version);
                        }
                    }
                }
                else
                {
                    GUILayout.Label(" ", newVersionStyle, GUILayout.Width(100));

                    if (GUILayout.Button("Import", GUILayout.Width(90)))
                    {
                        PTPluginUpdate.UpdatePlugin(serverCategory.url + "/" + serverPlugin.url, serverPlugin.name + "_v" + serverPlugin.version);
                    }
                }

                if (GUILayout.Button("Readme", GUILayout.Width(90)))
                {
                    ShowReadMe(serverPlugin, serverPlugin.readme);
                }

                GUILayout.EndHorizontal();
            }

            GUILayout.EndVertical();
        }
Пример #8
0
        private void ProcessCompare()
        {
            mConfigIndex++;

            if (mConfigIndex >= mPluginConfig.configDatas.Count)
            {
                mConfigIndex = 0;
            }

            ConfigData configData = mPluginConfig.configDatas[mConfigIndex];

            if (!configData.enableCheck)
            {
                GoToWait();

                return;
            }

            Debug.Log("***** update res check ******");

            Debug.Log("check plugin :" + configData.type + "  configIndex:" + mConfigIndex + "   count:" + mPluginConfig.configDatas.Count);

            List <PluginCategory> categories     = PTPluginUtil.GetRemoteCategories(mPluginConfig);
            PluginCategory        remoteCategory = PTPluginUtil.GetRemoteCategoryByType(categories, configData.type);

            if (remoteCategory == null)
            {
                GoToWait();

                return;
            }

            List <PluginCategory> localCategories = PTPluginUtil.GetLocalCategories(mPluginConfig);

            PluginCategory localCategory = PTPluginUtil.GetLocalCategoryByType(localCategories, configData.type);


            if (localCategory != null)
            {
                foreach (var remotePlugin in remoteCategory.plugins)
                {
                    PluginInfo localPlugin = localCategory.GetPluginInfoByName(remotePlugin.name);

                    if (localPlugin == null)
                    {
                        if (configData.enableNew)
                        {
                            ShowNewVersionDialog(configData.type);
                            break;
                        }
                    }
                    else
                    {
                        bool remoteHasNewVersion = PTPluginUtil.HasNewVersion(remotePlugin.version, localPlugin.version);

                        if (remoteHasNewVersion)
                        {
                            ShowNewVersionDialog(configData.type);

                            break;
                        }
                    }
                }
            }
            else
            {
                ShowNewVersionDialog(configData.type);
            }

            GoToWait();
        }