public void StartFollowing(Transform transToFollow, string soundType, string variationName, float volume, float trigRadius, bool willFollowSource, bool positionAtClosestColliderPoint, bool useTopCollider, bool useChildColliders, MasterAudio.AmbientSoundExitMode exitMode, float exitFadeTime, MasterAudio.AmbientSoundReEnterMode reEnterMode, float reEnterFadeTime) { RuntimeFollowingTransform = transToFollow; _goToFollow = transToFollow.gameObject; #if PHY3D_ENABLED Trigger.radius = trigRadius; #endif _soundType = soundType; _variationName = variationName; _playVolume = volume; _willFollowSource = willFollowSource; _exitMode = exitMode; _exitFadeTime = exitFadeTime; _reEnterMode = reEnterMode; _reEnterFadeTime = reEnterFadeTime; #if PHY3D_ENABLED _lastPositionByCollider.Clear(); #endif #if PHY2D_ENABLED _lastPositionByCollider2D.Clear(); #endif if (useTopCollider) { #if PHY3D_ENABLED Collider col3D = transToFollow.GetComponent <Collider>(); #else Component col3D = null; #endif if (col3D != null) { #if PHY3D_ENABLED _actorColliders.Add(col3D); _lastPositionByCollider.Add(col3D, transToFollow.position); #endif } else { #if PHY2D_ENABLED Collider2D col2D = transToFollow.GetComponent <Collider2D>(); if (col2D != null) { _actorColliders2D.Add(col2D); _lastPositionByCollider2D.Add(col2D, transToFollow.position); } #endif } } if (useChildColliders && transToFollow != null) { for (var i = 0; i < transToFollow.childCount; i++) { #if PHY3D_ENABLED || PHY2D_ENABLED var child = transToFollow.GetChild(i); #endif #if PHY3D_ENABLED Collider col3D = child.GetComponent <Collider>(); if (col3D != null) { _actorColliders.Add(col3D); _lastPositionByCollider.Add(col3D, transToFollow.position); continue; } #endif #if PHY2D_ENABLED Collider2D col2D = child.GetComponent <Collider2D>(); if (col2D != null) { _actorColliders2D.Add(col2D); _lastPositionByCollider2D.Add(col2D, transToFollow.position); } #endif } } _lastListenerPos = MasterAudio.ListenerTrans.position; #if UNITY_5_6_OR_NEWER var col3DCount = 0; var col2DCount = 0; #if PHY3D_ENABLED col3DCount = _actorColliders.Count; #endif #if PHY2D_ENABLED col2DCount = _actorColliders2D.Count; #endif if (col3DCount == 0 && col2DCount == 0 && positionAtClosestColliderPoint) { Debug.Log("Can't follow collider of '" + transToFollow.name + "' because it doesn't have any colliders."); } else { _positionAtClosestColliderPoint = positionAtClosestColliderPoint; if (_positionAtClosestColliderPoint) { RecalcClosestColliderPosition(true); MasterAudio.QueueTransformFollowerForColliderPositionRecalc(this); } } #endif }
public static Transform InitAudioSourceFollower(Transform transToFollow, string followerName, string soundGroupName, string variationName, float volume, bool willFollowSource, bool willPositionOnClosestColliderPoint, bool useTopCollider, bool useChildColliders, MasterAudio.AmbientSoundExitMode exitMode, float exitFadeTime, MasterAudio.AmbientSoundReEnterMode reEnterMode, float reEnterFadeTime) { #if !PHY3D_ENABLED return(null); // there is no Ambient Sound script functionality without Physics. #else if (ListenerFollower == null || FollowerHolder == null) { return(null); } var grp = MasterAudio.GrabGroup(soundGroupName); if (grp == null) { return(null); } if (grp.groupVariations.Count == 0) { return(null); } SoundGroupVariation variation = null; if (!string.IsNullOrEmpty(variationName)) { variation = grp.groupVariations.Find(delegate(SoundGroupVariation v) { return(v.name == variationName); }); if (variation == null) { Debug.LogError("Could not find Variation '" + variationName + "' in Sound Group '" + soundGroupName); return(null); } } else { variation = grp.groupVariations[0]; } var triggerRadius = variation.VarAudio.maxDistance; var follower = new GameObject(followerName); var existingDupe = FollowerHolder.GetChildTransform(followerName); if (existingDupe != null) { GameObject.Destroy(existingDupe.gameObject); } follower.transform.parent = FollowerHolder; follower.gameObject.layer = FollowerHolder.gameObject.layer; var followerScript = follower.gameObject.AddComponent <TransformFollower>(); followerScript.StartFollowing(transToFollow, soundGroupName, variationName, volume, triggerRadius, willFollowSource, willPositionOnClosestColliderPoint, useTopCollider, useChildColliders, exitMode, exitFadeTime, reEnterMode, reEnterFadeTime); _transformFollowers.Add(followerScript); return(follower.transform); #endif }
public static Transform InitAudioSourceFollower(Transform transToFollow, string followerName, string soundGroupName, string variationName, bool willFollowSource, bool willPositionOnClosestColliderPoint, bool useTopCollider, bool useChildColliders, MasterAudio.AmbientSoundExitMode exitMode, float exitFadeTime) { if (ListenerFollower == null || FollowerHolder == null) { return(null); } var grp = MasterAudio.GrabGroup(soundGroupName); if (grp == null) { return(null); } if (grp.groupVariations.Count == 0) { return(null); } var triggerRadius = grp.groupVariations[0].VarAudio.maxDistance; var follower = new GameObject(followerName); var existingDupe = FollowerHolder.GetChildTransform(followerName); if (existingDupe != null) { GameObject.Destroy(existingDupe.gameObject); } follower.transform.parent = FollowerHolder; follower.gameObject.layer = FollowerHolder.gameObject.layer; var followerScript = follower.gameObject.AddComponent <TransformFollower>(); followerScript.StartFollowing(transToFollow, soundGroupName, variationName, triggerRadius, willFollowSource, willPositionOnClosestColliderPoint, useTopCollider, useChildColliders, exitMode, exitFadeTime); _transformFollowers.Add(followerScript); return(follower.transform); }