// 初期化 protected override void Awake() { base.Awake(); _param = Resources.Load <SoundParameter>("ScriptableObjects/SoundParameter"); if (_param == null || _param._soundList == null) { return; } var audioSourceTarget = transform; for (var i = 0; i < _param._soundList.Length; ++i) { var param = _param._soundList[i]; var clip = Resources.Load <AudioClip>(param.resourcePath); var obj = new GameObject("Sound_" + param.soundId); var audioSource = obj.AddComponent <AudioSource>(); audioSource.clip = clip; obj.transform.SetParent(audioSourceTarget); _sounds.Add(param.soundId, audioSource); } }
public void Search() { List <GameObject> gameObjects = new List <GameObject>(); foreach (GameObject obj in FindObjectsOfType(typeof(GameObject))) { // シーン上に存在するオブジェクトならば処理. if (obj.activeInHierarchy && obj.tag.Contains("Sound")) { gameObjects.Add(obj); } } soundParameters = new SoundParameter[gameObjects.Count]; for (int i = 0; i < gameObjects.Count; ++i) { Component[] components = gameObjects[i].GetComponentsInChildren <Component>(); AudioSource source = null; foreach (Component component in components) { if (component.GetType().Name == "AudioSource") { source = component as AudioSource; } } if (!source) { continue; } soundParameters[i] = new SoundParameter { Audio = gameObjects[i], Clip = source.clip, Loop = source.loop, Volume = source.volume }; } //変更情報を保存 Undo.RegisterCreatedObjectUndo(this, "SearchedSave"); }