示例#1
0
        /// <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);
            }
        }
示例#2
0
        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);
     }
 }
示例#5
0
        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();
            }
        }
示例#6
0
        /// <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);
            }
        }
示例#7
0
 /// <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;
 }
示例#8
0
        /// <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();
        }
示例#9
0
        /// <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);
        }
示例#10
0
        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);
        }
示例#11
0
 public void Fire(T t)
 {
     AssertThat.IsNotNull(_action, "Action is null, add listener first");
     _action(t);
 }
示例#12
0
 public void Fire(T1 t1, T2 t2, T3 t3)
 {
     AssertThat.IsNotNull(_action, "Action is null, add listener first");
     _action(t1, t2, t3);
 }
示例#13
0
 /// <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);
 }
示例#14
0
 /// <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);
 }
示例#15
0
 /// <summary>
 /// 移除组件
 /// </summary>
 /// <param name="component"></param>
 public void Remove(IComponent component)
 {
     AssertThat.IsNotNull(component, "Component is null");
     component.Dispose();
     components.Remove(component);
 }