using System; using System.Collections; using Sirenix.OdinInspector; using UnityEngine; // ReSharper disable once CheckNamespace namespace BlueWaterProject { [DefaultExecutionOrder(-1)] public class GameManager : Singleton { public ShipPlayer ShipPlayer { get; private set; } // Combat [Title("Combat")] [SerializeField] private GameObject combatPlayerPrefab; public CombatPlayer CurrentCombatPlayer { get; set; } public event Action OnInstantiateCombatPlayer; // Tycoon [Title("Tycoon")] public TycoonPlayer TycoonPlayer { get; private set; } public bool IsBuildMode { get; set; } [field: SerializeField] public bool IsOnFollowCamera { get; set; } // Game Data [Title("Game Data")] [Range(0f, 1f)] [SerializeField] private float slowSpeed = 0.1f; private const string IN_ISLAND_PLAYER_NAME = "InIslandPlayer"; private void Init() { TycoonPlayer = FindAnyObjectByType(); ShipPlayer = FindAnyObjectByType(); } protected override void OnAwake() { Init(); } private void Start() { Cursor.lockState = CursorLockMode.Confined; } public IEnumerator ApplySlowMotion(float targetTimeScale, float duration) { var startScale = Time.timeScale; var time = 0f; while (time < duration) { Time.timeScale = Mathf.Lerp(startScale, targetTimeScale, time / duration); Time.fixedDeltaTime = 0.02f * Time.timeScale; time += Time.unscaledDeltaTime; yield return null; } Time.timeScale = targetTimeScale; } public void SlowSpeedMode() { Time.timeScale = slowSpeed; Time.fixedDeltaTime = 0.02f * Time.timeScale; } public void DefaultSpeedMode() { Time.timeScale = 1f; Time.fixedDeltaTime = 0.02f; } public void SetCurrentInIslandPlayer(IInIslandPlayer inIslandPlayer) { // PlayerInput currentPlayerInput; // // if (CurrentInIslandPlayer != null) // { // currentPlayerInput = CurrentInIslandPlayer.Transform.GetComponent(); // if (currentPlayerInput != null) // { // currentPlayerInput.enabled = false; // } // } // // CurrentInIslandPlayer = inIslandPlayer; // InIslandCamera.Inst.SetTarget(inIslandPlayer.Transform); // // currentPlayerInput = CurrentInIslandPlayer.Transform.GetComponent(); // if (currentPlayerInput != null) // { // currentPlayerInput.enabled = true; // } } public void InstantiateCombatPlayer(Vector3 position, Quaternion rotation = default) { var instantiatePlayer = Instantiate(combatPlayerPrefab, position, rotation); OnInstantiateCombatPlayer?.Invoke(instantiatePlayer.transform); } } }