OldBlueWater/BlueWater/Assets/02.Scripts/GameManager.cs

106 lines
3.3 KiB
C#
Raw Normal View History

using System;
using System.Collections;
2023-08-11 16:21:26 +00:00
using Sirenix.OdinInspector;
2023-08-08 07:08:41 +00:00
using UnityEngine;
2023-08-31 06:46:13 +00:00
// ReSharper disable once CheckNamespace
namespace BlueWaterProject
2023-08-08 07:08:41 +00:00
{
2023-09-20 09:06:45 +00:00
[DefaultExecutionOrder(-1)]
2023-08-31 06:46:13 +00:00
public class GameManager : Singleton<GameManager>
{
public ShipPlayer ShipPlayer { get; private set; }
// Combat
[Title("Combat")]
[SerializeField] private GameObject combatPlayerPrefab;
public CombatPlayer CurrentCombatPlayer { get; set; }
public event Action<Transform> OnInstantiateCombatPlayer;
// Tycoon
2023-12-26 05:18:14 +00:00
[Title("Tycoon")]
2024-01-03 02:54:03 +00:00
public TycoonPlayer TycoonPlayer { get; private set; }
2023-12-26 05:18:14 +00:00
public bool IsBuildMode { get; set; }
[field: SerializeField] public bool IsOnFollowCamera { get; set; }
2023-08-11 16:21:26 +00:00
// Game Data
[Title("Game Data")]
2023-08-31 06:46:13 +00:00
[Range(0f, 1f)]
[SerializeField] private float slowSpeed = 0.1f;
2023-10-05 04:11:46 +00:00
private const string IN_ISLAND_PLAYER_NAME = "InIslandPlayer";
2023-08-31 06:46:13 +00:00
private void Init()
{
2024-01-03 02:54:03 +00:00
TycoonPlayer = FindAnyObjectByType<TycoonPlayer>();
ShipPlayer = FindAnyObjectByType<ShipPlayer>();
2023-08-31 06:46:13 +00:00
}
protected override void OnAwake()
{
Init();
}
2023-08-31 06:46:13 +00:00
private void Start()
{
Cursor.lockState = CursorLockMode.Confined;
}
2023-10-06 05:41:16 +00:00
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;
}
2023-08-31 06:46:13 +00:00
public void SlowSpeedMode()
{
Time.timeScale = slowSpeed;
Time.fixedDeltaTime = 0.02f * Time.timeScale;
}
2023-08-31 06:46:13 +00:00
public void DefaultSpeedMode()
{
Time.timeScale = 1f;
Time.fixedDeltaTime = 0.02f;
}
2023-10-06 05:41:16 +00:00
public void SetCurrentInIslandPlayer(IInIslandPlayer inIslandPlayer)
{
// PlayerInput currentPlayerInput;
//
// if (CurrentInIslandPlayer != null)
// {
// currentPlayerInput = CurrentInIslandPlayer.Transform.GetComponent<PlayerInput>();
// if (currentPlayerInput != null)
// {
// currentPlayerInput.enabled = false;
// }
// }
//
// CurrentInIslandPlayer = inIslandPlayer;
// InIslandCamera.Inst.SetTarget(inIslandPlayer.Transform);
//
// currentPlayerInput = CurrentInIslandPlayer.Transform.GetComponent<PlayerInput>();
// if (currentPlayerInput != null)
// {
// currentPlayerInput.enabled = true;
// }
}
public void InstantiateCombatPlayer(Vector3 position, Quaternion rotation = default)
{
var instantiatePlayer = Instantiate(combatPlayerPrefab, position, rotation);
OnInstantiateCombatPlayer?.Invoke(instantiatePlayer.transform);
}
}
2023-08-08 07:08:41 +00:00
}