Пример #1
0
    private void networkSyncDroneSpawn(GameObject droneInstance)
    {
        if (GlobalSettings.SinglePlayer)
        {
            return;
        }

        if (Network.peerType != NetworkPeerType.Server)
        {
            throw new UnityException("Function may only be used by the server.");
        }

        //Debug.Log("Spawned and network sycned a drone:");

        int id = this.guidGenerator.GenerateID();

        ObjectSync objSync = droneInstance.GetComponent <ObjectSync>();

        //Debug.Log(ownObjectSync.Owner == null);

        objSync.AssignID(ownObjectSync.Owner, id);
        objSync.Type = ObjectSyncType.Drone;

        this.objectTables.AddPlayerObject(objSync.Owner, id, droneInstance);

        ObjectRPC.CreateDrone(this.networkControl.ThisPlayer, id, droneInstance.transform.position, droneInstance.layer);
    }
Пример #2
0
    protected void AddToObjectTables(GameObject obj, NetworkViewID playerID, int objectID)
    {
        ObjectSync objSync = obj.GetComponent <ObjectSync>();

        Player player = this.NetworkControl.Players[playerID];

        objSync.AssignID(player, objectID);

        this.ObjectTables.AddPlayerObject(player, objectID, obj);
    }
Пример #3
0
    /// <summary>
    /// Initializes the server-side objects.
    /// </summary>
    private void createServerSideObjects()
    {
        Player server = new Player(base.NetworkControl.LocalViewID, Network.player);

        base.NetworkControl.Players.Add(server.ID, server);
        base.ObjectTables.AddPlayerTable(server);
        Debug.Log("Created server player: " + server.ID);

        Player serverPlayer = base.NetworkControl.ThisPlayer;

        // Initialize the starting positions of the motherships.
        Vector3 team1MothershipPos = new Vector3(2000, 0, 0);
        Vector3 team2MothershipPos = new Vector3(-2000, 0, 0);

        // Initialize te motherships.
        GameObject team1Mothership = (GameObject)GameObject.Instantiate(
            this.MothershipPrefab, team1MothershipPos, Quaternion.identity
            );
        GameObject team2Mothership = (GameObject)GameObject.Instantiate(
            this.MothershipPrefab, team2MothershipPos, Quaternion.identity
            );

        // Assign teams to the motherships.
        TeamHelper.PropagateLayer(team1Mothership, (int)Layers.Team1Mothership);
        TeamHelper.PropagateLayer(team2Mothership, (int)Layers.Team2Mothership);
        team1Mothership.name = "Team1Mothership";
        team2Mothership.name = "Team2Mothership";

        // Generate object IDs for the motherships.
        int team1MothershipID = base.GUIDGenerator.GenerateID();
        int team2MothershipID = base.GUIDGenerator.GenerateID();

        // Assign some values.
        ObjectSync team1MSObjSync = team1Mothership.GetComponent <ObjectSync>();

        team1MSObjSync.Type = ObjectSyncType.Mothership;
        team1MSObjSync.AssignID(serverPlayer, team1MothershipID);
        HealthControl team1MSHealthControl = team1Mothership.GetComponent <HealthControl>();

        team1MSHealthControl.DrawHealthInfo = false;

        ObjectSync team2MSObjSync = team2Mothership.GetComponent <ObjectSync>();

        team2MSObjSync.Type = ObjectSyncType.Mothership;
        team2MSObjSync.AssignID(serverPlayer, team2MothershipID);
        HealthControl team2MSHealthControl = team2Mothership.GetComponent <HealthControl>();

        team2MSHealthControl.DrawHealthInfo = false;

        base.ObjectTables.AddPlayerObject(serverPlayer, team1MothershipID, team1Mothership);
        base.ObjectTables.AddPlayerObject(serverPlayer, team2MothershipID, team2Mothership);
    }
    public void CreateAsteroid(Vector3 position, Vector3 localScale, string name, Player owner, int id)
    {
        GameObject asteroid = (GameObject)GameObject.Instantiate(templateAsteroid, position, Random.rotation);

        asteroid.SetActive(true);
        asteroid.transform.localScale = localScale;
        asteroid.transform.name       = name;
        asteroid.transform.parent     = this.transform;

        if (!GlobalSettings.SinglePlayer)
        {
            if (Network.peerType == NetworkPeerType.Server)
            {
                ObjectSync objSync = asteroid.GetComponent <ObjectSync>();
                objSync.Type = ObjectSyncType.Asteroid;
                objSync.AssignID(owner, id);
            }

            base.ObjectTables.AddPlayerObject(owner, id, asteroid);
        }

        asteroidCount++;
    }