/// <summary> /// Inject property /// </summary> /// <param name="args"></param> private void InjectProperty(object obj) { var type = obj.GetType(); var propertys = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); for (int i = 0; i < propertys.Length; i++) { var attributes = propertys[i].GetCustomAttributes(typeof(InjectAttribute), true); if (attributes.Length == 0)//have no inject attribute { continue; } InjectAttribute injectAttribute = null; for (int j = 0; j < attributes.Length; j++) { if (attributes[j] is InjectAttribute) { injectAttribute = attributes[j] as InjectAttribute; break; } } if (injectAttribute == null) { break; //There have property with Attribute but not InjectAttribute } var bindInfo = _bindInfoContainer.GetBindInfo(propertys[i].PropertyType, injectAttribute.AsName); AssertThat.IsNotNull(bindInfo, "Bind to object is null"); propertys[i].SetValue(obj, bindInfo.Obj, null); } }
private object CreateSignal(Type t) { var signal = Activator.CreateInstance(t); AssertThat.IsNotNull(signal, "Create signal faild"); _signals[t.FullName] = signal; return(signal); }
private object CreateSignal(Type key) { var signal = Activator.CreateInstance(key); AssertThat.IsNotNull(signal, "Create signal faild"); signals[key] = signal; return(signal); }
public void Tick(float time) { for (int i = 0; i < _ticks.Count; i++) { var tick = _ticks[i]; AssertThat.IsNotNull(tick, "Tick list has null componentBase"); tick.Tick(time); } }
internal void DisposeAll() { var components = this._components.Values.ToList(); for (int i = 0; i < components.Count; i++) { AssertThat.IsNotNull(components[i], "ComponentBase is null"); components[i].Dispose(); } }
/// <summary> /// Fire the event /// </summary> /// <param name="key"></param> /// <param name="obj"></param> public void Dispatch(string key, params object[] obj) { AssertThat.IsNotNull(container.ContainsKey(key)); var infos = container[key]; foreach (var variable in infos) { variable.Dispatch(obj); } }
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary> public void Dispose() { AssertThat.IsNotNull(components, "Components is null"); for (int i = 0; i < components.Count; i++) { components[i].Dispose(); } components.Clear(); components = null; }
/// <summary> /// Dispose framework /// </summary> internal void Dispose() { var components = _components.GetAllValues(); foreach (var component in components) { AssertThat.IsNotNull(component, "Component is null"); component.OnDestroy(); } _components.Clear(); }
/// <summary> /// Create componentBase /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> private ComponentBase CreateComponent <T>(Type key) { var componentType = Center.Binder.BindInfos[key]; AssertThat.IsNotNull(componentType, "Have not bind this type"); var c = Activator.CreateInstance(componentType) as ComponentBase; AssertThat.IsNotNull(c, "Create component faild"); AssertThat.IsFalse(_components.ContainsKey(key), "Already have this component"); _components[key] = c; c.OnCreated(); return(c); }
internal T Get <T>() where T : class { var key = typeof(T); ComponentBase componentBase = null; if (_components.ContainsKey(key)) { componentBase = _components[key]; } else { componentBase = CreateComponent <T>(key); } AssertThat.IsNotNull(componentBase, "ComponentBase is null"); var t = componentBase as T; AssertThat.IsNotNull(t, "As T is null"); return(t); }
public void Fire(T t) { AssertThat.IsNotNull(_action, "Action is null, add listener first"); _action(t); }
public void Fire(T1 t1, T2 t2, T3 t3) { AssertThat.IsNotNull(_action, "Action is null, add listener first"); _action(t1, t2, t3); }
/// <summary> /// Tick维护 /// </summary> public void Tick(float deltaTime) { AssertThat.IsNotNull(tickComponent, "Make sure tick is not null(should init API first to init framework)"); tickComponent.Tick(deltaTime); }
/// <summary> /// Add component to list /// </summary> /// <param name="component"></param> private void AddComponentToList(IComponent component) { AssertThat.IsNotNull(component); AssertThat.IsFalse(components.Contains(component)); components.Add(component); }
/// <summary> /// 移除组件 /// </summary> /// <param name="component"></param> public void Remove(IComponent component) { AssertThat.IsNotNull(component, "Component is null"); component.Dispose(); components.Remove(component); }