示例#1
0
        public void SetWakeTimerAndSleep(ISleepable node, float t)
        {
            DynamicBuffer <NodeTimer> buffers;

            if (EntityManager.HasComponent <NodeTimer>(CurrentEntity))
            {
                buffers = EntityManager.GetBuffer <NodeTimer>(CurrentEntity);
            }
            else
            {
                buffers = PostUpdateCommands.AddBuffer <NodeTimer>(CurrentEntity);
            }
            buffers.Add(new NodeTimer()
            {
                Time      = t,
                NodeIndex = Index.NodeIndex
            });
            StateData.SetNodeCycle(Index, NodeCycle.Sleeping);
        }
示例#2
0
        /// <summary>
        /// 将node的运行转移到system,并让node进入睡眠状态.
        /// component 是 System与ActionFlow的关联, 当被添加到entity system系统执行, system将它删除时node会被唤醒
        /// </summary>
        /// <typeparam name="ISleepable">node参数不使用,用于调用节点的类型限制 </typeparam>
        /// <typeparam name="T"></typeparam>
        /// <param name="component"></param>
        //public void TransferToSystemAndSleep<T>(ISleepable node, T component) where T : struct, IComponentData
        //{
        //    ActionWakeSystemV2.AddSleepingNode(TargetEntity, ComponentType.ReadWrite<T>(), CurrentEntity, Index.NodeIndex);

        //    if (EM.HasComponent<NodeSleepingTag>(TargetEntity) == false)
        //    {
        //        PostCommand.AddComponent(TargetEntity, new NodeSleepingTag());
        //    }
        //    PostCommand.AddComponent(TargetEntity, component);
        //    StateData.SetNodeCycle(Index, NodeCycle.Sleeping);
        //}

        public void TransferToSystemAndSleep <T>(ISleepable node, T component) where T : struct, IComponentData
        {
            DynamicBuffer <NodeSleeping> buffers;

            if (EntityManager.HasComponent <NodeSleeping>(TargetEntity))
            {
                buffers = EntityManager.GetBuffer <NodeSleeping>(TargetEntity);
            }
            else
            {
                buffers = PostUpdateCommands.AddBuffer <NodeSleeping>(TargetEntity);
            }
            buffers.Add(new NodeSleeping()
            {
                Entity        = CurrentEntity,
                NodeIndex     = Index.NodeIndex,
                ComponentType = ComponentType.ReadWrite <T>()
            });
            PostUpdateCommands.AddComponent(TargetEntity, component);
            StateData.SetNodeCycle(Index, NodeCycle.Sleeping);
        }