示例#1
0
        Actor spawnActor(Player owner, ushort playerId, int prefabId, SlimMath.Vector3 position)
        {
            Actor  actor;
            ushort actorId;
            bool   hasOwner = owner != null;

            if (!actorIdPool.Acquire(out actorId))
            {
                log.Error("Can't spawn actor, failed to acquire a new actor id");
                return(null);
            }

            if (hasOwner && owner.Connection == null)
            {
                log.Error("Owner supplied, but it has no connection object");
                return(null);
            }

            Network.IConnection connection = hasOwner ? owner.Connection : null;

            if (Context.InstantiateActor(connection, prefabId, actorId, playerId, position, out actor))
            {
                if (hasOwner)
                {
                    owner.OwnedActors.Add(actor);
                }

                return(actor);
            }

            return(null);
        }
示例#2
0
        void onSpawn(Events.Spawn ev)
        {
            Actor actor;

            if (Context.InstantiateActor(Player.Connection, ev.DefinitionId, ev.ActorId, ev.PlayerId, ev.Position, out actor))
            {
                ev.Actor = actor;

                if (actor.IsMine)
                {
                    Player.OwnedActors.Add(actor);
                }
            }
        }