Exemple #1
0
        public T Add <T>() where T : Component
        {
            ComponentHelper.Assert <T>();

            /*if (!ComponentHelper.AllowMultiple<T>() && Handle.Has<T>()) {
             *  throw new Exception($"Already has a component of type {typeof(T).Name}");
             * }
             * T component = Activator.CreateInstance<T>();
             * component.AppendTo(this);
             * Events.RaiseAddedComponent(component);
             * var registerAs = ComponentHelper.GetRegisterAs<T>();
             * if (registerAs != null) {
             *  registerAs.CallSet(Handle, component);
             * } else {
             *  Handle.Set(component);
             * }
             * return component;*/

            T component = Activator.CreateInstance <T>();

            ComponentHelper.CallSet(Handle, component);
            component.AppendTo(this);
            Events.RaiseAddedComponent(component);
            return(component);
        }
Exemple #2
0
        public bool Has <T>() where T : Component
        {
            ComponentHelper.Assert <T>();
            return(ComponentHelper.CallHas <T>(Handle));

            /*var registerAs = ComponentHelper.GetRegisterAs<T>();
             * if (registerAs != null) {
             *  return registerAs.CallHas(Handle);
             * }
             * return Handle.Has<T>();*/
        }
Exemple #3
0
 public bool Has <T>(out T component) where T : Component
 {
     ComponentHelper.Assert <T>();
     try {
         component = ComponentHelper.CallGet <T>(Handle);
         return(true);
     } catch (Exception) {
         component = default;
         return(false);
     }
 }
Exemple #4
0
 public void Disable <T>() where T : Component
 {
     ComponentHelper.Assert <T>();
     Handle.Disable <T>();
 }
Exemple #5
0
 public bool IsEnabled <T>() where T : Component
 {
     ComponentHelper.Assert <T>();
     return(Handle.IsEnabled <T>());
 }