public void Execute(int index, Entity linkedEntity, NetworkIdComponent networkId)
        {
            if (linkedEntity != Entity.Null)
            {
                CommandBuffer.DestroyEntity(index, linkedEntity);
            }

            EnqueueEventJobPart.EventData.NetworkId = networkId.Value;
            EnqueueEventJobPart.Execute();
        }
Ejemplo n.º 2
0
        public void Execute(Entity entity, int entityInQueryIndex, ref NetworkIdComponent idComponent,
                            ref NativeArray <DisconnectClient> networkIds)
        {
            for (int i = 0; i < networkIds.Length; i++)
            {
                DisconnectClient dc = networkIds[i];
                if (dc.NetworkConnectionId != idComponent.Value)
                {
                    continue;
                }

                CommandBuffer.AddComponent <NetworkStreamRequestDisconnect>(entityInQueryIndex, entity);
                dc.NetworkConnectionId = -1;
                networkIds[i]          = dc;
                break;
            }
        }
Ejemplo n.º 3
0
        public GameObject CreateDefaultGhostGameObject(Entity ent,
                                                       CreatedGameObjectDelegate onCreatedGameObject = null,
                                                       CreatedGameObjectDelegate onCreatedLinkTarget = null)
        {
            var ghost = EntityManager.GetComponentData <GhostComponent>(ent);

            bool isInterpolatedClient = !EntityManager.HasComponent <GhostPredictionComponent>(ent);
            bool isLocalOwner         = false;

            GameObject view;

            if (IsServer)
            {
                view = this.GetByServer(ghost.GhostType);
            }
            else
            {
                // 客户端频断是否是LocalOwner
                if (HasSingleton <NetworkIdComponent>() && EntityManager.HasComponent <GhostOwnerComponent>(ent))
                {
                    NetworkIdComponent  networkIdComponent = GetSingleton <NetworkIdComponent>();
                    GhostOwnerComponent ownerComponent     =
                        EntityManager.GetComponentData <GhostOwnerComponent>(ent);

                    // [客户端特有]
                    isLocalOwner = ownerComponent.Value == networkIdComponent.Value;
                }

                // 预制体集合取
                view = isInterpolatedClient
                    ? this.GetByInterpolated(ghost.GhostType)
                    : this.GetByPrediction(ghost.GhostType);
            }

            view = Object.Instantiate(view);

            // Entity标识,以便碰撞检测能找到对应的Entity
            var entityFlag = view.AddComponent <EntityHold>();

            entityFlag.Ent   = ent;
            entityFlag.World = World;

            SceneManager.MoveGameObjectToScene(view, World.GetLinkedScene());
            EntityManager.AddComponentData(ent, new GhostGameObjectSystemState());
            this.Add(ent, view);
            onCreatedGameObject?.Invoke(ghost.GhostType, view, this);

            var linkedGameObject = CreateLinkedGameObject(isInterpolatedClient, IsServer, view);

            if (linkedGameObject)
            {
                onCreatedLinkTarget?.Invoke(ghost.GhostType, linkedGameObject, this);
            }

            // 只能由一个此NetworkBehaviour
            NetworkBehaviour networkBehaviours = view.GetComponent <NetworkBehaviour>();

            if (networkBehaviours)
            {
                networkBehaviours.World      = World;
                networkBehaviours.SelfEntity = ent;
                networkBehaviours.IsServer   = IsServer;
                networkBehaviours.IsOwner    = isLocalOwner;
                EntityManager.AddComponentObject(ent, networkBehaviours);
                networkBehaviours.NetworkAwake();
            }

            return(view);
        }