Пример #1
0
        public void SetDefaultPlugin(PluginItem item, bool set)
        {
            if (item == null || item.PluginData == null)
            {
                return;
            }

            if (set)
            {
                mDefaultPlugins[item.PluginData.PluginType] = item.Id;
            }
            else
            {
                mDefaultPlugins.Remove(item.PluginData.PluginType);
            }

            if (!mDefaultPluginLoaded)
            {
                SavePluginInfo();
            }
        }
Пример #2
0
        private async System.Threading.Tasks.Task GenericPluginItemAction(Guid pluginGuid, EditorCommon.PluginAssist.IEditorPlugin pluginValue, EditorCommon.PluginAssist.IEditorPluginData pluginData)
        {
            await EngineNS.CEngine.Instance.EventPoster.Post(() =>
            {
                var item        = new PluginItem(pluginGuid, pluginValue, pluginData);
                item.PluginName = pluginValue.PluginName;
                item.Version    = pluginValue.Version;

                //if (!plugin.Value.OnActive())
                //{
                //    item.Active = false;
                //    continue;
                //}
                var pluginType = pluginValue.GetType();
                var atts       = pluginType.GetCustomAttributes(typeof(EditorCommon.PluginAssist.PluginMenuItemAttribute), false);
                if (atts.Length > 0)
                {
                    var piAtt          = (EditorCommon.PluginAssist.PluginMenuItemAttribute)(atts[0]);
                    var menuData       = EditorCommon.Menu.MenuItemDataBase.CreateMenuData(piAtt.MenuType, pluginData.PluginType);
                    menuData.MenuNames = piAtt.MenuString;
                    menuData.Count     = piAtt.Count;
                    if (piAtt.Icons != null)
                    {
                        menuData.Icons = new ImageSource[piAtt.MenuString.Length];
                        for (int i = 0; i < piAtt.Icons.Length; i++)
                        {
                            menuData.Icons[i] = new BitmapImage(new Uri(piAtt.Icons[i], UriKind.Relative));
                        }
                    }
                    if (pluginValue.Icon != null)
                    {
                        if (menuData.Icons.Length == 0)
                        {
                            menuData.Icons = new ImageSource[piAtt.MenuString.Length];
                        }
                        menuData.Icons[menuData.Icons.Length - 1] = pluginValue.Icon;
                    }
                    menuData.OperationControlType = pluginType;
                    if (menuData.OperationControls == null || menuData.OperationControls.Length != menuData.Count)
                    {
                        menuData.OperationControls = new DockControl.IDockAbleControl[menuData.Count];
                    }
                    for (int i = 0; i < menuData.Count; i++)
                    {
                        var ctrl = System.Activator.CreateInstance(menuData.OperationControlType) as DockControl.IDockAbleControl;
                        if (ctrl == null)
                        {
                            EngineNS.Profiler.Log.WriteLine(EngineNS.Profiler.ELogTag.Error, "Plugins", $"Plugin item {pluginValue.PluginName} create menus failed");
                            continue;
                        }
                        if (menuData.Count > 1)
                        {
                            ctrl.Index = i;
                        }
                        menuData.OperationControls[i] = ctrl;
                    }
                    EditorCommon.Menu.GeneralMenuManager.Instance.RegisterMenuItem(menuData);
                }

                // 将同类型的插件放入选择器字典表中
                EditorCommon.PluginAssist.PluginSelector selector;
                if (!PluginDicWithTypeKey.TryGetValue(item.PluginData.PluginType, out selector))
                {
                    selector = new EditorCommon.PluginAssist.PluginSelector(item.PluginData.PluginType);
                    PluginDicWithTypeKey[item.PluginData.PluginType] = selector;
                }
                selector.Plugins[pluginGuid] = item;

                PluginsDicWithIdKey[pluginGuid] = item;
                return(true);
            }, EngineNS.Thread.Async.EAsyncTarget.Main);
        }