示例#1
0
        protected override void PostInitializeComponent()
        {
            Entity            owner = GetOwnerEntity();
            PositionComponent position_component = owner.GetComponent(PositionComponent.ID) as PositionComponent;

            if (position_component == null)
            {
                return;
            }

            EffectManager effect_manager = GetLogicWorld().GetEffectManager();

            if (m_enter_generator_cfgid > 0)
            {
                m_enter_generator = effect_manager.CreateGenerator(m_enter_generator_cfgid, owner);
            }
            if (m_period_generator_cfgid > 0)
            {
                m_period_generator = effect_manager.CreateGenerator(m_period_generator_cfgid, owner);
            }

            m_region = GetLogicWorld().GetRegionCallbackManager().CreateRegion();
            m_region.Construct(this, owner);
            m_region.SetUpdateInterval(m_region_update_interval);
            m_region.SetTargetGatheringParam(m_target_gathering_param);
            m_region.Activate();

            if (m_period_generator != null)
            {
                m_task = LogicTask.Create <ComponentCommonTask>();
                m_task.Construct(this);
                var schedeler = GetLogicWorld().GetTaskScheduler();
                schedeler.Schedule(m_task, GetCurrentTime(), m_period, m_period);
            }
        }
示例#2
0
        protected override void OnDestruct()
        {
            EffectManager effect_manager = GetLogicWorld().GetEffectManager();

            if (m_enter_generator != null)
            {
                effect_manager.DestroyGenerator(m_enter_generator.ID, GetOwnerEntityID());
                m_enter_generator = null;
            }
            if (m_period_generator != null)
            {
                effect_manager.DestroyGenerator(m_period_generator.ID, GetOwnerEntityID());
                m_period_generator = null;
            }
            if (m_region != null)
            {
                m_region.Destruct();
                m_region = null;
            }
            if (m_task != null)
            {
                m_task.Cancel();
                LogicTask.Recycle(m_task);
                m_task = null;
            }
        }
 public void DestroyRegion(EntityGatheringRegion region)
 {
     if (m_regions.Remove(region.ID))
     {
         region.Deactivate();
         RecyclableObject.Recycle(region);
     }
 }
        public EntityGatheringRegion CreateRegion()
        {
            EntityGatheringRegion region = RecyclableObject.Create <EntityGatheringRegion>();

            region.PreConstruct(this);
            m_regions[region.ID] = region;
            return(region);
        }
 public void Deactivate(EntityGatheringRegion region)
 {
     for (int i = 0; i < m_active_region_bundles.Count; ++i)
     {
         if (m_active_region_bundles[i].m_update_interval != region.UpdateInterval)
         {
             m_active_region_bundles[i].RemoveRegion(region);
             break;
         }
     }
 }
        public void Destruct()
        {
            m_id_generator.Destruct();
            m_id_generator = null;

            var enumerator = m_regions.GetEnumerator();

            while (enumerator.MoveNext())
            {
                EntityGatheringRegion region = enumerator.Current.Value;
                region.Deactivate();
                RecyclableObject.Recycle(region);
            }
            m_regions.Clear();
            m_active_region_bundles.Clear();

            m_logic_world = null;
        }
        public void Activate(EntityGatheringRegion region)
        {
            int  update_interval = region.UpdateInterval;
            bool done            = false;

            for (int i = 0; i < m_active_region_bundles.Count; ++i)
            {
                if (m_active_region_bundles[i].m_update_interval == update_interval)
                {
                    m_active_region_bundles[i].AddRegion(region);
                    done = true;
                    break;
                }
            }
            if (!done)
            {
                ActiveRegionBundles bundle = new ActiveRegionBundles(this, update_interval);
                m_active_region_bundles.Add(bundle);
                bundle.AddRegion(region);
            }
        }
        public void RemoveRegion(EntityGatheringRegion region)
        {
            int index = m_active_regions.IndexOf(region.ID);

            if (index < 0)
            {
                return;
            }
            m_active_regions.RemoveAt(index);
            if (index > m_next_update_index)
            {
            }
            else if (index < m_next_update_index)
            {
                --m_next_update_index;
            }
            else
            {
                if (m_next_update_index >= m_active_regions.Count)
                {
                    m_next_update_index = 0;
                }
            }
        }
 public void AddRegion(EntityGatheringRegion region)
 {
     m_active_regions.Add(region.ID);
 }