示例#1
0
    private GameObject NetworkInstantiate(string uniqueId, bool isBuffered, Vector3 position, Quaternion rotation, SparkPeer sender, Guid[] guids)
    {
        GameObject[] gameObjects = Resources.FindObjectsOfTypeAll <GameObject> ();

        foreach (GameObject instantiate in gameObjects)
        {
            SparkIdentity identity = instantiate.GetComponent <SparkIdentity> ();

            if (identity != null && identity.uniqueId == uniqueId)
            {
                GameObject obj = GameObject.Instantiate(instantiate, position, rotation);

                int count = 0;
                foreach (SparkBehaviour behaviour in obj.GetComponentsInChildren <SparkBehaviour>())
                {
                    behaviour.netGuid = guids [count++];
                }

                foreach (SparkView view in obj.GetComponentsInChildren <SparkView>())
                {
                    view.sparkPeer = sender;
                    view.SendEvent_OnInstantiate();
                    view.netGuid = guids[count++];
                }

                return(obj);
            }
        }

        throw new Exception("A GameObject with this SparkIdentity ID was not found.");
    }
示例#2
0
    private GameObject TryInstantiate(GameObject prefab, Vector3 position, Quaternion rotation, bool isBuffered = true)
    {
        SparkIdentity identity = prefab.GetComponent <SparkIdentity> ();
        SparkPeer     sender   = sparkMatch.peerList.Find(x => x.id == sparkNetwork.PeerId);

        List <Guid> guids = new List <Guid> ();

        foreach (SparkBehaviour behaviour in prefab.GetComponentsInChildren <SparkBehaviour>())
        {
            guids.Add(Guid.NewGuid());
        }
        foreach (SparkView view in prefab.GetComponentsInChildren <SparkView>())
        {
            guids.Add(Guid.NewGuid());
        }

        GameObject instantiate = NetworkInstantiate(identity.uniqueId, isBuffered, position, rotation, sender, guids.ToArray());

        LocalRPC("NetworkInstantiate", SparkTargets.Others, isBuffered, identity.uniqueId, isBuffered, position, rotation, sender, guids.ToArray());

        return(instantiate);
    }