本文整理汇总了C#中UnityEngine.Transform.BroadcastMessage方法的典型用法代码示例。如果您正苦于以下问题:C# Transform.BroadcastMessage方法的具体用法?C# Transform.BroadcastMessage怎么用?C# Transform.BroadcastMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Transform
的用法示例。
在下文中一共展示了Transform.BroadcastMessage方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InformParticipants
/// <summary>
/// Broadcasts a message to the participants in a bark. Used to send the OnBarkStart and
/// OnBarkEnd messages to the speaker and listener.
/// </summary>
/// <param name='message'>
/// Message (i.e., OnBarkStart or OnBarkEnd).
/// </param>
/// <param name='speaker'>
/// Speaker.
/// </param>
/// <param name='listener'>
/// Listener.
/// </param>
private static void InformParticipants(string message, Transform speaker, Transform listener)
{
if (speaker != null) {
speaker.BroadcastMessage(message, speaker, SendMessageOptions.DontRequireReceiver);
if ((listener != null) && (listener != speaker)) {
listener.BroadcastMessage(message, speaker, SendMessageOptions.DontRequireReceiver);
}
}
}
示例2: AddChild
/// <summary>
/// Set the parent of some GameObject to this GameObject. The 'OnTransformHierarchyChanged' message will be broadcasted
/// to child and all its children signaling it that the change occurred, unless the new child is already a child of the GameObject.
/// Note that changing the parent of complex hierarchies is expensive regardless of the suppress, if you're calling this
/// method frequently, you probably have a design flaw in your game. Reparenting shouldn't occur that frequently.
/// </summary>
/// <param name="obj"></param>
/// <param name="child"></param>
/// <param name="suppressChangeHierarchyMessage">Don't send the OnTransformHierarchyChanged message.</param>
public static void AddChild(this Transform obj, Transform child, bool suppressChangeHierarchyMessage = false)
{
if (child == null) throw new System.ArgumentNullException("child");
if (child.parent == obj) return;
child.parent = obj;
if (!suppressChangeHierarchyMessage) child.BroadcastMessage(SPConstants.MSG_ONTRANSFORMHIERARCHYCHANGED, SendMessageOptions.DontRequireReceiver);
}
示例3: NetworkDespawn
/// <summary>
/// Basically the same method as Despawn() but this will be called from netowrkPooler on all clients.
/// </summary>
/// <param name="transToDespawn">Transform to despawn</param>
public static void NetworkDespawn(Transform transToDespawn) {
if (Instance.logMessages) {
Debug.Log("NetworkDespawn: Player (" + PhotonNetwork.player.ID + ") is networkDespawning " + transToDespawn.name);
}
if (!_isReady) {
LevelSettings.LogIfNew(NotInitError);
return;
}
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
// ReSharper disable HeuristicUnreachableCode
if (transToDespawn == null) {
LevelSettings.LogIfNew("No Transform passed to Despawn method.");
return;
}
// ReSharper restore HeuristicUnreachableCode
if (Instance == null) {
// Scene changing, do nothing.
return;
}
if (!SpawnUtility.IsActive(transToDespawn.gameObject)) {
return; // already sent to despawn
}
var itemName = GetPrefabName(transToDespawn);
if (!PoolItemsByName.ContainsKey(itemName)) {
if (Instance.autoAddMissingPoolItems) {
CreateMissingPoolItem(transToDespawn, itemName, false);
} else {
LevelSettings.LogIfNew("The Transform '" + itemName +
"' passed to Despawn is not in Pool Boss. Not despawning.");
return;
}
}
transToDespawn.BroadcastMessage(DespawnedMessageName, SendMessageOptions.DontRequireReceiver);
var cloneList = PoolItemsByName[itemName];
SetParent(transToDespawn, Trans);
SpawnUtility.SetActive(transToDespawn.gameObject, false);
Instance._changes++;
if (Instance.logMessages || cloneList.LogMessages) {
Debug.Log("Pool Boss despawned '" + itemName + "' at " + Time.time);
}
cloneList.SpawnedClones.Remove(transToDespawn);
cloneList.DespawnedClones.Add(transToDespawn);
}
示例4: Despawn
/// <summary>
/// Call this method to despawn a prefab using Pool Boss. All the Spawners and Killable use this method.
/// </summary>
/// <param name="transToDespawn">Transform to despawn</param>
public static void Despawn(Transform transToDespawn) {
if (!_isReady) {
LevelSettings.LogIfNew(NotInitError);
return;
}
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (transToDespawn == null) {
LevelSettings.LogIfNew("No Transform passed to Despawn method.");
return;
}
#if PHOTON_NETWORK
if (!CheckIfClientSideOnly(transToDespawn)) {
var targetPV = transToDespawn.GetComponent<PhotonView>();
var owner = targetPV.owner;
var vId = targetPV.viewID;
if (owner != null) {
if (owner.ID == PhotonNetwork.player.ID) {
//then we own it so we can destory it
PhotonNetwork.Destroy(transToDespawn.gameObject);
return;
}
_view.RPC("RemoteDespawn", owner, transToDespawn.name, vId); //some reason we get NullReferenceException here so im going to try sending to all targets and have the rpc function check if owner
} else { //the owner of this object must have left the game or d/c
//lets make the master client the owner then and then ask him to despawn
targetPV.TransferOwnership(PhotonNetwork.masterClient);
_view.RPC("RemoteDespawn", PhotonNetwork.masterClient, transToDespawn.name, vId); //some reason we get NullReferenceException here so im going to try sending to all targets and have the rpc function check if owner
}
}
#endif
// ReSharper disable HeuristicUnreachableCode
if (Instance == null) {
// Scene changing, do nothing.
return;
}
if (!SpawnUtility.IsActive(transToDespawn.gameObject)) {
return; // already sent to despawn
}
var itemName = GetPrefabName(transToDespawn);
if (!PoolItemsByName.ContainsKey(itemName)) {
if (Instance.autoAddMissingPoolItems) {
CreateMissingPoolItem(transToDespawn, itemName, false);
} else {
LevelSettings.LogIfNew("The Transform '" + itemName +
"' passed to Despawn is not in Pool Boss. Not despawning.");
return;
}
}
transToDespawn.BroadcastMessage(DespawnedMessageName, SendMessageOptions.DontRequireReceiver);
var cloneList = PoolItemsByName[itemName];
SetParent(transToDespawn, Trans);
SpawnUtility.SetActive(transToDespawn.gameObject, false);
Instance._changes++;
if (Instance.logMessages || cloneList.LogMessages) {
Debug.Log("Pool Boss despawned '" + itemName + "' at " + Time.time);
}
cloneList.SpawnedClones.Remove(transToDespawn);
cloneList.DespawnedClones.Add(transToDespawn);
// ReSharper restore HeuristicUnreachableCode
}
示例5: Despawn
/// <summary>
/// Despawn the specified GameObject
/// The OnDespawned method will be called on the GameObject.
/// </summary>
public void Despawn(Transform transToDespawn)
{
transToDespawn.BroadcastMessage("OnDespawned", SendMessageOptions.DontRequireReceiver);
transToDespawn.parent = parentTransform;
transToDespawn.gameObject.SetActive(false);
if (showDebugLog)
{
Debug.Log("EZ_PoolManager despawned " + transToDespawn.name);
}
spawnedList.Remove(transToDespawn);
despawnedList.Add(transToDespawn);
}