Beispiel #1
0
        public async Task AddComponent(EngineNS.GamePlay.Actor.GActor actor, EngineNS.GamePlay.Component.GComponent component)
        {
            if (actor != null)
            {
                Type type = component.GetType();
                var  atts = type.GetCustomAttributes(typeof(EngineNS.GamePlay.Component.CustomConstructionParamsAttribute), false);
                EngineNS.GamePlay.Component.GComponent.GComponentInitializer initializer = null;
                if (atts.Length > 0)
                {
                    for (int i = 0; i < atts.Length; i++)
                    {
                        var ccAtt = atts[i] as EngineNS.GamePlay.Component.CustomConstructionParamsAttribute;
                        if (ccAtt != null)
                        {
                            initializer = Activator.CreateInstance(ccAtt.ConstructionParamsType) as EngineNS.GamePlay.Component.GComponent.GComponentInitializer;
                            break;
                        }
                    }
                }
                if (initializer != null)
                {
                    await component.SetInitializer(EngineNS.CEngine.Instance.RenderContext, actor, actor, initializer);
                }

                actor.AddComponent(component);
            }
        }
        public async System.Threading.Tasks.Task SetTimer(string name, bool enable, float interval, EngineNS.GamePlay.Component.GTimerComponent.FOnTimer onTimer)
        {
            var timerComp = GetComponent <EngineNS.GamePlay.Component.GTimerComponent>();

            if (timerComp == null)
            {
                timerComp             = new EngineNS.GamePlay.Component.GTimerComponent();
                timerComp.OnlyForGame = true;
                var initer = new EngineNS.GamePlay.Component.GComponent.GComponentInitializer();
                await timerComp.SetInitializer(CEngine.Instance.RenderContext, this, null, initer);

                this.AddComponent(timerComp);
            }
            timerComp.SetTimer(name, enable, interval, onTimer, false);
        }