예제 #1
0
        public Entity CreateProjectile(EntityCommandBuffer ecb)
        {
            Debug.Assert(CanExecuteServerActions, "CanExecuteServerActions");

            if (!CanExecuteServerActions)
            {
                return(Entity.Null);
            }

            var entity = EntityManager.CreateEntity(m_EntityArchetype);

            ServerEntityMgr.ConvertAsNetworkable(ecb, entity, entity);

            Debug.Log("Create a projectile!");

            return(entity);
        }
예제 #2
0
        public void Callback(EventReceiveData.Arguments args)
        {
            if (!args.Reader.Type.IsPattern())
            {
                return;
            }

            var conMsgMgr = args.PeerInstance.GetPatternManager();

            var msg = conMsgMgr.GetPattern(args.Reader);
            var ecb = new EntityCommandBuffer(Allocator.Temp);

            if (msg == MsgTestCreateProj)
            {
                var position = args.Reader.Data.GetVec3();
                var aim      = args.Reader.Data.GetVec3();
                var proj     = CreateProjectile(ecb);

                EntityManager.SetComponentData(proj, new Position {
                    Value = position
                });
                EntityManager.SetComponentData(proj, new StVelocity(aim * 42f));

                Debug.Log($"Creating a new projectile. P: {position}; A: {aim}");

                SendProjectile(proj);
            }
            else if (msg == MsgStartProjectile)
            {
                var serverEntity = args.Reader.GetEntity();
                var owner        = default(Entity);
                var position     = args.Reader.Data.GetVec3();
                var velocity     = args.Reader.Data.GetVec3();

                var clientEntity = EntityManager.CreateEntity(m_EntityArchetype);

                ServerEntityMgr.ConvertAsNetworkable(ecb, clientEntity, serverEntity);

                EntityManager.SetOrAddComponentData(clientEntity, new ProjectileTag());
                EntityManager.SetOrAddComponentData(clientEntity, new ProjectileOwner(owner));
                EntityManager.SetOrAddComponentData(clientEntity, new Position {
                    Value = position
                });
                EntityManager.SetOrAddComponentData(clientEntity, new StVelocity(velocity));

                Debug.Log("We got a new projectile from server!");
            }
            else if (msg == MsgEndProjectile)
            {
                var serverEntity = args.Reader.GetEntity();
                var clientEntity = GetEntity(serverEntity);

                Debug.Log($"Destroying projectile... c: {clientEntity}, s: {serverEntity}");

                var projGO = ClientProjectileRocketExplosion[0];
                projGO.transform.position = clientEntity.GetComponentData <Position>().Value;
                projGO.GetComponentInChildren <ParticleSystem>().Play(true);

                ServerEntityMgr.DestroyEntity(serverEntity);
                ecb.DestroyEntity(clientEntity);
            }

            ecb.Playback(EntityManager);
            ecb.Dispose();
        }