예제 #1
0
        public bool Register(FSBehaviour plugin)
        {
            if (!string.IsNullOrEmpty(plugin.id))
            {
                if (!plugins.ContainsKey(plugin.id))
                {
                    if (plugin.IsUnique && GetAllInstances(plugin.GetType()).Count > 0)
                    {
                        plugin.enabled = false;

                        return(false);
                    }
                    else
                    {
                        plugins.Add(plugin.id, plugin);

                        return(true);
                    }
                }
                else
                {
                    plugin.enabled = false;

                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
        public T GetInstance <T>(string id) where T : FSBehaviour
        {
            foreach (KeyValuePair <string, FSBehaviour> keyValue in plugins)
            {
                FSBehaviour FSBehaviour = keyValue.Value;
                if ((FSBehaviour.GetType() == typeof(T) || FSBehaviour.GetType().IsSubclassOf(typeof(T))) && FSBehaviour.id == id)
                {
                    return(FSBehaviour as T);
                }
            }

            return(null);
        }
예제 #3
0
        public List <FSBehaviour> GetAllInstances(System.Type type)
        {
            List <FSBehaviour> list = new List <FSBehaviour>();

            foreach (KeyValuePair <string, FSBehaviour> keyValue in plugins)
            {
                FSBehaviour FSBehaviour = keyValue.Value;
                if (FSBehaviour.GetType() == type || FSBehaviour.GetType().IsSubclassOf(type))
                {
                    list.Add(FSBehaviour);
                }
            }

            return(list);
        }
예제 #4
0
        public List <T> GetAllInstances <T>() where T : FSBehaviour
        {
            List <T> list = new List <T>();

            foreach (KeyValuePair <string, FSBehaviour> keyValue in plugins)
            {
                FSBehaviour FSBehaviour = keyValue.Value;
                if (FSBehaviour.GetType() == typeof(T) || FSBehaviour.GetType().IsSubclassOf(typeof(T)))
                {
                    list.Add(FSBehaviour as T);
                }
            }

            return(list);
        }
예제 #5
0
        public T GetInstance <T>(int index = 0) where T : FSBehaviour
        {
            int i = 0;

            foreach (KeyValuePair <string, FSBehaviour> keyValue in plugins)
            {
                FSBehaviour FSBehaviour = keyValue.Value;

                if ((FSBehaviour.GetType() == typeof(T) || FSBehaviour.GetType().IsSubclassOf(typeof(T))) && i++ == index)
                {
                    return(FSBehaviour as T);
                }
            }

            return(null);
        }
예제 #6
0
        public FSBehaviour GetInstance(System.Type type, int index = 0)
        {
            int i = 0;

            foreach (KeyValuePair <string, FSBehaviour> keyValue in plugins)
            {
                FSBehaviour FSBehaviour = keyValue.Value;

                if ((FSBehaviour.GetType() == type || FSBehaviour.GetType().IsSubclassOf(type)) && i++ == index)
                {
                    return(FSBehaviour);
                }
            }

            return(null);
        }
예제 #7
0
 public bool Unregister(FSBehaviour plugin)
 {
     if (!string.IsNullOrEmpty(plugin.id))
     {
         if (plugins.ContainsKey(plugin.id))
         {
             plugins.Remove(plugin.id);
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }