void Awake() { if (Effect == null) { GameObject obj = GameObject.Find(PrefabRootPath); if (obj != null) { Effect = ObjectPoolController.Instantiate(obj); if (Effect != null) { Effect.transform.SetParent(transform); Effect.transform.localPosition = Position; Effect.transform.localEulerAngles = EulerAngles; Effect.transform.localScale = LocalScale; if (ActiveOnAwake) { Effect.SetActive(true); } else { Effect.SetActive(false); } } } } }
public SoundObject PlayAudioSubItem(SoundsCategory audioCategory, SoundItem audioItem, SoundSubItem subItem, Vector3 worldPosition, Transform parentObj, bool playWithoutAudioObject, SoundObject existingAudioObj, System.Action <SoundObject> onLoad = null) { GameObject audioPrefab = GetPrefabForSoundType(subItem.SubItemType); if (audioPrefab == null) { Debug.LogError("missing prefab for sound : " + audioCategory.Name + "/" + audioItem.Name + " with type : " + subItem.SubItemType); Debug.LogError(subItem.clipref.FullPath); return(null); } //volume float subItemVolume = subItem.Volume; if (subItem.RandomVolume != 0) { subItemVolume += UnityEngine.Random.Range(-subItem.RandomVolume, subItem.RandomVolume); subItemVolume = Mathf.Clamp01(subItemVolume); } float masterVolume = Volume * audioCategory.VolumeTotal * audioItem.Volume; float totalVolume = masterVolume * subItemVolume; if (!PlayWithZeroVolume && (totalVolume <= 0)) { return(null); } SoundSettings audioSettings = SoundSettings; if (audioCategory.SoundSettingsOverride != null) { audioSettings = audioCategory.SoundSettingsOverride; } if (audioItem.SoundSettingsOverride != null) { audioSettings = audioItem.SoundSettingsOverride; } GameObject sndObjInstance; SoundObject sndObj; if (existingAudioObj == null) { sndObjInstance = (GameObject)ObjectPoolController.Instantiate(audioPrefab, worldPosition, Quaternion.identity); if (!audioItem.DestroyOnLoad) { Object.DontDestroyOnLoad(sndObjInstance); } sndObjInstance.transform.parent = parentObj ? parentObj : transform; sndObj = sndObjInstance.gameObject.GetComponent <SoundObject>(); } else { sndObjInstance = existingAudioObj.gameObject; sndObj = existingAudioObj; } sndObjInstance.name = "SoundObject:" + subItem.Name; sndObj.SubItem = subItem; sndObj.ApplySettings(audioSettings); //sndObj.primaryAudioSource.rolloffMode = AudioRolloffMode.Linear; // float startTime = subItem.RandomStartPosition ? UnityEngine.Random.Range( 0, sndObj.clipLength ) : 0; // sndObj.primaryAudioSource.time = startTime + subItem.ClipStartTime; if (audioItem.overrideAudioSourceSettings) { sndObj.MinDistance = audioItem.audioSource_MinDistance; sndObj.MaxDistance = audioItem.audioSource_MaxDistance; } sndObj.Volume = subItemVolume; sndObj.MasterVolume = masterVolume; sndObj.Loop = (audioItem.Loop == SoundLoopMode.LoopSubitem); sndObj.Pan = subItem.Pan2D; sndObj.Pitch = subItem.GetPitch(); float delay = 0; if (subItem.RandomDelay > 0) { delay += UnityEngine.Random.Range(0, subItem.RandomDelay); } sndObj.Play(delay + subItem.Delay + audioItem.Delay, subItem.FadeIn); if (onLoad != null) { onLoad(sndObj); } return(sndObj); }