using System; using System.Collections.Generic; using System.Linq; using System.ScriptListener; using Cysharp.Threading.Tasks; using FJson; using Framework.Asset; using Framework.Audio; using Framework.GamePool.manager; using Framework.Timer; using Framework.UI; using Framework.Utils.SingletonTemplate; using Game.Component; using Game.Data; using Game.EventDefine; using IcecreamView; using StateSystem; using UniFramework.Event; using UnityEngine; using UnityEngine.Playables; using Views; using Object = UnityEngine.Object; namespace Game { public enum VibratorScale { Small = 1, Normal = 2, Big = 4, SuperBig = 6, Max = 8 } public class RoomManager : MgrBase { private EventGroup _eventGroup; private GameFsm _gameFsm; private RoomGlobalData _roomGlobalData; public PlayableDirector _BossSceneDirector; public bool HasLock { get ; private set; } public GameState CurrentGameState => this._gameFsm.CurrentState; public int PartIndex = 1; public RoomGlobalData RoomGlobalData { get => _roomGlobalData; set => _roomGlobalData = value; } public void JoinGame (params object[] args) { this._gameFsm = new GameFsm (); this._gameFsm.Active (GameState.InitGame , args); GameUpdateMgr.Instance.AddUpdater (DoUpdate); this.BindEvent (); this._gameFsm.OpenState (GameState.StartGame); } internal void _OnExitGame () { UnBindEvent (); this._gameFsm.Kill (); GameUpdateMgr.Instance.RemoveUpdater (DoUpdate); GameStateManager.Instance.OpenState (System.StateSystem.GameGlobalState.GameHome); } private void DoUpdate () { #if UNITY_EDITOR if (Input.GetKeyDown (KeyCode.F1)) { } #endif } protected override void OnCreateMge () { // _eventBindHandler = new EventBindHandler (this); _eventGroup = new EventGroup (); } protected override bool InstanceHook () { return GameStateManager.Instance.CurrentState == System.StateSystem.GameGlobalState.GameRoom; } /// /// 锁定操作 /// public void Lock () { this.HasLock = true; } /// /// 解除锁定操作 /// public void UnLock () { this.HasLock = false; } public void LoadScenePart (int partIndex) { var loadName = $"AutoSource/Part/part{partIndex}.prefab"; var scenePart = AssetManager.Instance.LoadAsset (loadName).GetComponent (); var instantiate = Object.Instantiate (scenePart, MapContent.Instance.transform, true); MapContent.Instance.SetPart (instantiate); if (partIndex == 3) { //额外加载boss场景 var bossScene = AssetManager.Instance.LoadAsset("AutoSource/CGScene/BossScene.prefab"); var gameObject = Object.Instantiate (bossScene , MapContent.Instance.ScenePart.SuccessProp.transform.position , Quaternion.identity); this._BossSceneDirector = gameObject.GetComponent (); } } #region 事件 private void BindEvent () { this._eventGroup.AddListener (ChangeGameFsm); this._eventGroup.AddListener (OverlyCoin); } private void ChangeGameFsm (IEventMessage eventMessage) { GameEventDefine.ChangeGameFsm message = eventMessage as GameEventDefine.ChangeGameFsm; this._gameFsm.OpenState (message.State , message.Args); } private async void OverlyCoin (IEventMessage obj) { if (obj is GameEventDefine.OverlyCoin message) { AudioManager.Instance.PlaySoundEffect (SeAudio.Gaming_GetCoin); MapContent.Instance.OverlyCoin (message.overlyCoin); GlobalEventDefine.RefreshView.SendMessage (); if (MapContent.Instance.ScenePart.IsCondition) { if (!MapContent.Instance.ScenePart.successProp.gameObject.activeSelf) { //给一个奖励buff,全局逃跑 CameraManager.Instance.SetCloseUpTarget (MapContent.Instance.ScenePart.successProp.transform); await UniTask.Delay (1000); GameEventDefine.GlobalRunaway.SendMessage (3f); MapContent.Instance.ScenePart.successProp.gameObject.SetActive (true); } } } } private void UnBindEvent () { this._eventGroup.RemoveAllListener (); } #endregion } }