예제 #1
0
        public void CmdSplitPlatoon(uint platoonNetId)
        {
            NetworkIdentity identity;

            if (NetworkIdentity.spawned.TryGetValue(platoonNetId, out identity))
            {
                PlatoonBehaviour platoon = identity.gameObject.GetComponent <PlatoonBehaviour>();

                // We do not do something like 'while (Units.Count > 0)'
                // because the RPCs finish executing and hence update the unit count
                // way after the loop has concluded!
                int newPlatoonsCount = platoon.Units.Count - 1;
                while (newPlatoonsCount > 0)
                {
                    UnitDispatcher u         = platoon.Units[newPlatoonsCount];
                    uint           unitNetId = u.GetComponent <NetworkIdentity>().netId;
                    platoon.RpcRemoveUnit(unitNetId);

                    PlatoonBehaviour newPlatoon = PlatoonBehaviour.CreateGhostMode(
                        platoon.Unit, platoon.Owner);
                    GhostPlatoonBehaviour ghostPlatoon = newPlatoon.GhostPlatoon;

                    NetworkServer.Spawn(ghostPlatoon.gameObject);
                    NetworkServer.Spawn(newPlatoon.gameObject);

                    newPlatoon.RpcEstablishReferences(
                        ghostPlatoon.netId,
                        new[] { unitNetId });
                    newPlatoon.RpcActivate(u.Transform.position);

                    newPlatoonsCount--;
                }
            }
        }