コード例 #1
0
    //spawns an object in spawnable objects from an id
    public GameObject SpawnObjectWithoutSetup(int index, int ID)
    {
        //it's not a child, spawn in a new instance of the synced object
        GameObject        instance     = Instantiate(spawnableObjects[index]);
        MultiSyncedObject syncedObject = instance.GetComponent <MultiSyncedObject>();

        //it shouldn't do dict setup
        syncedObject.doSyncedObjectsDictSetup = false;
        //store index and id
        syncedObject.index = index;
        syncedObject.ID    = ID;
        //this is the last synced object spawned by this method
        lastSOSpawnedWOSetup = instance;

        //if this object has children, make sure they don't do dict setup
        if (instance.GetComponentsInChildren <MultiSyncedObject>().Length > 0)
        {
            foreach (MultiSyncedObject m in instance.GetComponentsInChildren <MultiSyncedObject>())
            {
                m.doSyncedObjectsDictSetup = false;
            }
        }

        syncedObjects.Add(ID, syncedObject.GetComponent <MultiSyncedObject>());

        return(instance);
    }
コード例 #2
0
    //spawns an object in spawnable objects from an id
    public GameObject SpawnObject(int index)
    {
        //spawn in the new synced object instance
        GameObject        instance     = Instantiate(spawnableObjects[index]);
        MultiSyncedObject syncedObject = instance.GetComponent <MultiSyncedObject>();

        //store it's index
        syncedObject.index = index;
        return(instance);
    }
コード例 #3
0
    //spawns a local object
    public GameObject LocalSpawnObject(int index)
    {
        //spawn in the new synced object instance
        GameObject        instance     = Instantiate(spawnableObjects[index]);
        MultiSyncedObject syncedObject = instance.GetComponent <MultiSyncedObject>();

        //store its index and its local status
        syncedObject.localOwned = true;
        syncedObject.index      = index;

        //send a request to all other clients to spawn in this object
        MultiSpawnRequest spawnRequest = new MultiSpawnRequest(index);
        MultiBaseRequest  baseRequest  = new MultiBaseRequest(MultiPossibleRequest.MultiSpawnObject, MessagePackSerializer.Serialize(spawnRequest));

        SendMessageToServer(MessagePackSerializer.Serialize(baseRequest));
        return(instance);
    }
 private void Start()
 {
     syncedObject = GetComponent <MultiSyncedObject>();
     GetComponent <MeshRenderer>().material = new Material(GetComponent <MeshRenderer>().material);
     GetComponent <MeshRenderer>().material.SetColor("_Color", new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)255));
 }