private AudioSource PlayMusicHook(On.GlobalAudioManager.orig_PlayMusic orig, GlobalAudioManager self, GlobalAudioManager.Sounds _sound, float _fade) { string songName = _sound.ToString(); if (SL.Instance.AudioClips.ContainsKey(songName) && At.GetValue(typeof(GlobalAudioManager), self, "s_musicSources") is DictionaryExt <GlobalAudioManager.Sounds, GlobalAudioManager.MusicSource> dict) { // set our custom clip to the actual GlobalAudioManager dictionary, so it works with the game systems as expected if (!dict.ContainsKey(_sound) && At.Call(self, "GetPrefabPath", new object[] { _sound }) is string prefabPath) { GameObject gameObject = Resources.Load("_Sounds/" + prefabPath) as GameObject; gameObject = Instantiate(gameObject); AudioSource component = gameObject.GetComponent <AudioSource>(); DontDestroyOnLoad(gameObject); dict.Add(_sound, new GlobalAudioManager.MusicSource(component)); } dict[_sound].Source.clip = SL.Instance.AudioClips[_sound.ToString()]; At.SetValue(dict, typeof(GlobalAudioManager), self, "s_musicSources"); At.Call(self, "CleanUpMusic", null); At.SetValue(_sound, typeof(GlobalAudioManager), self, "s_currentMusic"); StartCoroutine(FadeMusic(self, _sound, dict[_sound], _fade)); return(dict[_sound].Source); } else { return(orig(self, _sound, _fade)); } }
public static CharacterAI SetupBasicAI(Character _char) { // add required components for AIs (no setup required) _char.gameObject.AddComponent <NavMeshAgent>(); _char.gameObject.AddComponent <AISquadMember>(); _char.gameObject.AddComponent <EditorCharacterAILoadAI>(); // add our basic AIStatesPrefab to a CharacterAI component. This is the prefab set up by SetupBasicAIPrefab(), below. CharacterAI charAI = _char.gameObject.AddComponent(new CharacterAI { AIStatesPrefab = BasicAIPrefab.GetComponent <AIRoot>() }); // remove unwanted components if (_char.GetComponent <NavMeshObstacle>() is NavMeshObstacle navObstacle) { Destroy(navObstacle); } // initialize the AI States (not entirely necessary, but helpful if we want to do something with the AI immediately after) At.Call(charAI, "GetAIStates", new object[0]); return(charAI); }