本文整理汇总了C#中GameObject.GetPhotonViewsInChildren方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.GetPhotonViewsInChildren方法的具体用法?C# GameObject.GetPhotonViewsInChildren怎么用?C# GameObject.GetPhotonViewsInChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameObject
的用法示例。
在下文中一共展示了GameObject.GetPhotonViewsInChildren方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetInstantiatedObjectsId
/// <summary>
/// This returns -1 if the GO could not be found in list of instantiatedObjects.
/// </summary>
public int GetInstantiatedObjectsId(GameObject go)
{
int id = -1;
if (go == null)
{
Debug.LogError("GetInstantiatedObjectsId() for GO == null.");
return id;
}
PhotonView[] pvs = go.GetPhotonViewsInChildren();
if (pvs != null && pvs.Length > 0 && pvs[0] != null)
{
return pvs[0].instantiationId;
}
if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
UnityEngine.Debug.Log("GetInstantiatedObjectsId failed for GO: " + go);
return id;
}
示例2: DoInstantiate
internal GameObject DoInstantiate(Hashtable evData, PhotonPlayer photonPlayer, GameObject resourceGameObject)
{
// some values always present:
string prefabName = (string)evData[(byte)0];
int serverTime = (int)evData[(byte)6];
int instantiationId = (int)evData[(byte)7];
Vector3 position;
if (evData.ContainsKey((byte)1))
{
position = (Vector3)evData[(byte)1];
}
else
{
position = Vector3.zero;
}
Quaternion rotation = Quaternion.identity;
if (evData.ContainsKey((byte)2))
{
rotation = (Quaternion)evData[(byte)2];
}
int group = 0;
if (evData.ContainsKey((byte)3))
{
group = (int)evData[(byte)3];
}
short objLevelPrefix = 0;
if (evData.ContainsKey((byte)8))
{
objLevelPrefix = (short)evData[(byte)8];
}
int[] viewsIDs;
if (evData.ContainsKey((byte)4))
{
viewsIDs = (int[])evData[(byte)4];
}
else
{
viewsIDs = new int[1] { instantiationId };
}
object[] incomingInstantiationData;
if (evData.ContainsKey((byte)5))
{
incomingInstantiationData = (object[])evData[(byte)5];
}
else
{
incomingInstantiationData = null;
}
// SetReceiving filtering
if (group != 0 && !this.allowedReceivingGroups.Contains(group))
{
return null; // Ignore group
}
// load prefab, if it wasn't loaded before (calling methods might do this)
if (resourceGameObject == null)
{
if (!NetworkingPeer.UsePrefabCache || !NetworkingPeer.PrefabCache.TryGetValue(prefabName, out resourceGameObject))
{
resourceGameObject = (GameObject)Resources.Load(prefabName, typeof(GameObject));
if (NetworkingPeer.UsePrefabCache)
{
NetworkingPeer.PrefabCache.Add(prefabName, resourceGameObject);
}
}
if (resourceGameObject == null)
{
Debug.LogError("PhotonNetwork error: Could not Instantiate the prefab [" + prefabName + "]. Please verify you have this gameobject in a Resources folder.");
return null;
}
}
// now modify the loaded "blueprint" object before it becomes a part of the scene (by instantiating it)
PhotonView[] resourcePVs = resourceGameObject.GetPhotonViewsInChildren();
if (resourcePVs.Length != viewsIDs.Length)
{
throw new Exception("Error in Instantiation! The resource's PhotonView count is not the same as in incoming data.");
}
for (int i = 0; i < viewsIDs.Length; i++)
{
// NOTE instantiating the loaded resource will keep the viewID but would not copy instantiation data, so it's set below
// so we only set the viewID and instantiationId now. the instantiationData can be fetched
resourcePVs[i].viewID = viewsIDs[i];
resourcePVs[i].prefix = objLevelPrefix;
resourcePVs[i].instantiationId = instantiationId;
}
this.StoreInstantiationData(instantiationId, incomingInstantiationData);
// load the resource and set it's values before instantiating it:
GameObject go = (GameObject)GameObject.Instantiate(resourceGameObject, position, rotation);
//.........这里部分代码省略.........
示例3: RemoveInstantiatedGO
/// <summary>Removes GameObject and the PhotonViews on it from local lists and optionally updates remotes. GameObject gets destroyed at end.</summary>
/// <remarks>
/// This method might fail and quit early due to several tests.
/// </remarks>
/// <param name="go">GameObject to cleanup.</param>
/// <param name="localOnly">For localOnly, tests of control are skipped and the server is not updated.</param>
protected internal void RemoveInstantiatedGO(GameObject go, bool localOnly)
{
if (go == null)
{
Debug.LogError("Failed to 'network-remove' GameObject because it's null.");
return;
}
// Don't remove the GO if it doesn't have any PhotonView
PhotonView[] views = go.GetComponentsInChildren<PhotonView>(true);
if (views == null || views.Length <= 0)
{
Debug.LogError("Failed to 'network-remove' GameObject because has no PhotonView components: " + go);
return;
}
PhotonView viewZero = views[0];
int creatorId = viewZero.CreatorActorNr; // creatorId of obj is needed to delete EvInstantiate (only if it's from that user)
int instantiationId = viewZero.instantiationId; // actual, live InstantiationIds start with 1 and go up
// Don't remove GOs that are owned by others (unless this is the master and the remote player left)
if (!localOnly)
{
if (!viewZero.isMine)
{
Debug.LogError("Failed to 'network-remove' GameObject. Client is neither owner nor masterClient taking over for owner who left: " + viewZero);
return;
}
// Don't remove the Instantiation from the server, if it doesn't have a proper ID
if (instantiationId < 1)
{
Debug.LogError("Failed to 'network-remove' GameObject because it is missing a valid InstantiationId on view: " + viewZero + ". Not Destroying GameObject or PhotonViews!");
return;
}
}
// cleanup instantiation (event and local list)
if (!localOnly)
{
this.ServerCleanInstantiateAndDestroy(instantiationId, creatorId, viewZero.isRuntimeInstantiated); // server cleaning
}
// cleanup PhotonViews and their RPCs events (if not localOnly)
for (int j = views.Length - 1; j >= 0; j--)
{
PhotonView view = views[j];
if (view == null)
{
continue;
}
// we only destroy/clean PhotonViews that were created by PhotonNetwork.Instantiate (and those have an instantiationId!)
if (view.instantiationId >= 1)
{
this.LocalCleanPhotonView(view);
}
if (!localOnly)
{
this.OpCleanRpcBuffer(view);
}
}
if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
{
Debug.Log("Network destroy Instantiated GO: " + go.name);
}
if (this.ObjectPool != null)
{
PhotonView[] photonViews = go.GetPhotonViewsInChildren();
for (int i = 0; i < photonViews.Length; i++)
{
photonViews[i].viewID = 0; // marks the PV as not being in use currently.
}
this.ObjectPool.Destroy(go);
}
else
{
GameObject.Destroy(go);
}
}
示例4: GetInstantiatedObjectsId
/// <summary>
/// This returns -1 if the GO could not be found in list of instantiatedObjects.
/// </summary>
public int GetInstantiatedObjectsId(GameObject go)
{
int id = -1;
if (go == null)
{
this.DebugReturn(DebugLevel.ERROR, "GetInstantiatedObjectsId() for GO == null.");
return id;
}
PhotonView[] pvs = go.GetPhotonViewsInChildren();
if (pvs != null && pvs.Length > 0 && pvs[0] != null)
{
return pvs[0].instantiationId;
}
if (DebugOut == DebugLevel.ALL)
{
this.DebugReturn(DebugLevel.ALL, "GetInstantiatedObjectsId failed for GO: " + go);
}
return id;
}
示例5: DoInstantiate
internal GameObject DoInstantiate(Hashtable evData, PhotonPlayer photonPlayer, GameObject resourceGameObject)
{
// some values always present:
string prefabName = (string)evData[(byte)0];
int serverTime = (int)evData[(byte)6];
int instantiationId = (int)evData[(byte)7];
Vector3 position;
if (evData.ContainsKey((byte)1))
{
position = (Vector3)evData[(byte)1];
}
else
{
position = Vector3.zero;
}
Quaternion rotation = Quaternion.identity;
if (evData.ContainsKey((byte)2))
{
rotation = (Quaternion)evData[(byte)2];
}
int group = 0;
if (evData.ContainsKey((byte)3))
{
group = (int)evData[(byte)3];
}
short objLevelPrefix = 0;
if (evData.ContainsKey((byte)8))
{
objLevelPrefix = (short)evData[(byte)8];
}
int[] viewsIDs;
if (evData.ContainsKey((byte)4))
{
viewsIDs = (int[])evData[(byte)4];
}
else
{
viewsIDs = new int[1] { instantiationId };
}
object[] incomingInstantiationData;
if (evData.ContainsKey((byte)5))
{
incomingInstantiationData = (object[])evData[(byte)5];
}
else
{
incomingInstantiationData = null;
}
// SetReceiving filtering
if (group != 0 && !this.allowedReceivingGroups.Contains(group))
{
return null; // Ignore group
}
// load prefab, if it wasn't loaded before (calling methods might do this)
if (resourceGameObject == null)
{
if (!NetworkingPeer.UsePrefabCache || !NetworkingPeer.PrefabCache.TryGetValue(prefabName, out resourceGameObject))
{
resourceGameObject = (GameObject)Resources.Load(prefabName, typeof(GameObject));
if (NetworkingPeer.UsePrefabCache)
{
NetworkingPeer.PrefabCache.Add(prefabName, resourceGameObject);
}
}
if (resourceGameObject == null)
{
Debug.LogError("PhotonNetwork error: Could not Instantiate the prefab [" + prefabName + "]. Please verify you have this gameobject in a Resources folder.");
return null;
}
}
// now modify the loaded "blueprint" object before it becomes a part of the scene (by instantiating it)
PhotonView[] resourcePVs = resourceGameObject.GetPhotonViewsInChildren();
if (resourcePVs.Length != viewsIDs.Length)
{
throw new Exception("Error in Instantiation! The resource's PhotonView count is not the same as in incoming data.");
}
for (int i = 0; i < viewsIDs.Length; i++)
{
// NOTE instantiating the loaded resource will keep the viewID but would not copy instantiation data, so it's set below
// so we only set the viewID and instantiationId now. the instantiationData can be fetched
resourcePVs[i].viewID = viewsIDs[i];
resourcePVs[i].prefix = objLevelPrefix;
resourcePVs[i].instantiationId = instantiationId;
}
this.StoreInstantiationData(instantiationId, incomingInstantiationData);
// load the resource and set it's values before instantiating it:
// Debug.Log("PreInstantiate");
//.........这里部分代码省略.........
示例6: DoInstantiate
internal GameObject DoInstantiate(Hashtable evData, PhotonPlayer photonPlayer, GameObject resourceGameObject)
{
// some values always present:
string prefabName = (string)evData[(byte)0];
int serverTime = (int)evData[(byte)6];
int instantiationId = (int)evData[(byte)7];
Vector3 position;
if (evData.ContainsKey((byte)1))
{
position = (Vector3)evData[(byte)1];
}
else
{
position = Vector3.zero;
}
Quaternion rotation = Quaternion.identity;
if (evData.ContainsKey((byte)2))
{
rotation = (Quaternion)evData[(byte)2];
}
int group = 0;
if (evData.ContainsKey((byte)3))
{
group = (int)evData[(byte)3];
}
short objLevelPrefix = 0;
if (evData.ContainsKey((byte)8))
{
objLevelPrefix = (short)evData[(byte)8];
}
int[] viewsIDs;
if (evData.ContainsKey((byte)4))
{
viewsIDs = (int[])evData[(byte)4];
}
else
{
viewsIDs = new int[1] { instantiationId };
}
object[] incomingInstantiationData;
if (evData.ContainsKey((byte)5))
{
incomingInstantiationData = (object[])evData[(byte)5];
}
else
{
incomingInstantiationData = null;
}
// SetReceiving filtering
if (group != 0 && !this.allowedReceivingGroups.Contains(group))
{
return null; // Ignore group
}
// load prefab, if it wasn't loaded before (calling methods might do this)
if (resourceGameObject == null)
{
if (!NetworkingPeer.UsePrefabCache || !NetworkingPeer.PrefabCache.TryGetValue(prefabName, out resourceGameObject))
{
resourceGameObject = (GameObject)Resources.Load(prefabName, typeof(GameObject));
if (NetworkingPeer.UsePrefabCache)
{
NetworkingPeer.PrefabCache.Add(prefabName, resourceGameObject);
}
}
if (resourceGameObject == null)
{
Debug.LogError("PhotonNetwork error: Could not Instantiate the prefab [" + prefabName + "]. Please verify you have this gameobject in a Resources folder.");
return null;
}
}
// now modify the loaded "blueprint" object before it becomes a part of the scene (by instantiating it)
PhotonView[] resourcePVs = resourceGameObject.GetPhotonViewsInChildren();
if (resourcePVs.Length != viewsIDs.Length)
{
throw new Exception("Error in Instantiation! The resource's PhotonView count is not the same as in incoming data.");
}
for (int i = 0; i < viewsIDs.Length; i++)
{
// NOTE instantiating the loaded resource will keep the viewID but would not copy instantiation data, so it's set below
// so we only set the viewID and instantiationId now. the instantiationData can be fetched
resourcePVs[i].viewID = viewsIDs[i];
resourcePVs[i].prefix = objLevelPrefix;
resourcePVs[i].instantiationId = instantiationId;
}
this.StoreInstantiationData(instantiationId, incomingInstantiationData);
// load the resource and set it's values before instantiating it:
GameObject go = (GameObject)GameObject.Instantiate(resourceGameObject, position, rotation);
//.........这里部分代码省略.........