440 lines
10 KiB
C#
440 lines
10 KiB
C#
using System.Collections.Generic;
|
|
using Rewired;
|
|
using UltimateWater;
|
|
using UnityEngine;
|
|
|
|
public class AquariumController : vp_Interactable
|
|
{
|
|
[SerializeField]
|
|
[Header("AQUARIUM")]
|
|
private AquariumCameraController _aquariumCameraNormal;
|
|
|
|
[SerializeField]
|
|
private AquariumCameraControllerVR _aquariumCameraVR;
|
|
|
|
[SerializeField]
|
|
private SchoolController _schoolController;
|
|
|
|
[SerializeField]
|
|
private AquariumSettings _settings;
|
|
|
|
[SerializeField]
|
|
private AquariumRender _render;
|
|
|
|
[SerializeField]
|
|
private UIAquarium _guiVr;
|
|
|
|
[SerializeField]
|
|
private Water _aquariumWater;
|
|
|
|
private vp_FPController _playerController;
|
|
|
|
private vp_FPCamera _cameraController;
|
|
|
|
private UIAquarium _uiAquarium;
|
|
|
|
private bool _isShown;
|
|
|
|
private FishManager.FishKept _lastInspectedFish;
|
|
|
|
public AquariumSettings Settings
|
|
{
|
|
get
|
|
{
|
|
return _settings;
|
|
}
|
|
}
|
|
|
|
private IAquariumCamera _aquariumCamera
|
|
{
|
|
get
|
|
{
|
|
if (VRManager.IsVROn())
|
|
{
|
|
return _aquariumCameraVR;
|
|
}
|
|
return _aquariumCameraNormal;
|
|
}
|
|
}
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
_guiVr.gameObject.SetActive(VRManager.IsVROn());
|
|
_playerController = TrophyRoomManager.Instance.trophyPlayer.GetComponent<vp_FPController>();
|
|
_cameraController = _playerController.GetComponentInChildren<vp_FPCamera>(true);
|
|
if (VRManager.IsVROn())
|
|
{
|
|
_uiAquarium = _guiVr;
|
|
}
|
|
else
|
|
{
|
|
_uiAquarium = TrophyRoomManager.Instance.trophyRoomGUI.uiAquarium;
|
|
}
|
|
if (VRManager.IsVROn())
|
|
{
|
|
_uiAquarium.ShowInfo(this);
|
|
_render.SetCaustics(base.transform);
|
|
}
|
|
FishingWaterSystem.WaterSystemType waterSystem = ((!VRManager.IsVROn()) ? TrophyRoomManager.Instance.waterType : TrophyRoomManager.Instance.vrWaterType);
|
|
_render.SetWaterSystem(waterSystem);
|
|
LoadData();
|
|
_render.SetAquarium(_settings);
|
|
OnCameraChanged(false);
|
|
UpdateFishCount();
|
|
foreach (FishManager.FishKept item in GlobalSettings.Instance.fishManager.fishKeep)
|
|
{
|
|
AddToAquarium(item);
|
|
}
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
float underwaterBlur = GlobalSettings.Instance.renderSettings.underwaterBlur;
|
|
UnderwaterIME component = _aquariumCameraNormal.Camera.GetComponent<UnderwaterIME>();
|
|
if ((bool)component)
|
|
{
|
|
component._CameraBlurScale = underwaterBlur;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void OnEnable()
|
|
{
|
|
base.OnEnable();
|
|
ReInput.players.GetPlayer(0).AddInputEventDelegate(OnInteractPressed, UpdateLoopType.Update, InputActionEventType.ButtonJustPressed, "THROW_NEAR");
|
|
ReInput.players.GetPlayer(0).AddInputEventDelegate(OnInspectPressed, UpdateLoopType.Update, InputActionEventType.ButtonJustPressed, "BOAT_ENTER");
|
|
}
|
|
|
|
protected override void OnDisable()
|
|
{
|
|
base.OnDisable();
|
|
if (ReInput.isReady)
|
|
{
|
|
ReInput.players.GetPlayer(0).RemoveInputEventDelegate(OnInteractPressed, UpdateLoopType.Update, InputActionEventType.ButtonJustPressed, "THROW_NEAR");
|
|
ReInput.players.GetPlayer(0).RemoveInputEventDelegate(OnInspectPressed, UpdateLoopType.Update, InputActionEventType.ButtonJustPressed, "BOAT_ENTER");
|
|
}
|
|
}
|
|
|
|
private void LoadData()
|
|
{
|
|
foreach (FishManager.AquariumData aquarium in GlobalSettings.Instance.fishManager.aquariums)
|
|
{
|
|
if (aquarium.id == _settings.id)
|
|
{
|
|
_settings.name = aquarium.name;
|
|
_settings.waterType = (AquariumWaterType)aquarium.waterType;
|
|
_settings.enviroPreset = aquarium.enviroPreset;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void AddToAquarium(FishManager.FishKept fish)
|
|
{
|
|
if (fish.aquarium == _settings.id)
|
|
{
|
|
_schoolController.AddFish(fish);
|
|
}
|
|
}
|
|
|
|
private void RemoveFromAquarium(FishManager.FishKept fish)
|
|
{
|
|
if (fish.aquarium == _settings.id)
|
|
{
|
|
_schoolController.RemoveFish(fish);
|
|
}
|
|
}
|
|
|
|
public override void UpdateSeeing(bool isSeeing)
|
|
{
|
|
if (isSeeingMe != isSeeing && !VRManager.IsVROn())
|
|
{
|
|
if (isSeeing)
|
|
{
|
|
_uiAquarium.ShowInfo(this);
|
|
}
|
|
else
|
|
{
|
|
_uiAquarium.HideInfo();
|
|
}
|
|
isSeeingMe = isSeeing;
|
|
}
|
|
}
|
|
|
|
private void OnInteractPressed(InputActionEventData data)
|
|
{
|
|
if (isSeeingMe && !_isShown && !VRManager.IsVROn())
|
|
{
|
|
ShowAquariumGUI();
|
|
}
|
|
}
|
|
|
|
private void OnInspectPressed(InputActionEventData data)
|
|
{
|
|
Debug.LogError(_settings.name + "seing: " + isSeeingMe + " shown:" + _isShown + " fish " + GetFishNumber());
|
|
if (isSeeingMe && !_isShown && !VRManager.IsVROn() && GetFishNumber() > 0)
|
|
{
|
|
_isShown = true;
|
|
EnablePlayerControls(false);
|
|
_uiAquarium.SetAquarium(this);
|
|
EnableCursor(true);
|
|
_uiAquarium.HideInfo();
|
|
_cameraController.gameObject.SetActive(false);
|
|
_aquariumCamera.gameObject.SetActive(true);
|
|
OnCameraChanged(true);
|
|
OnInspectFish(_schoolController.GetFirstFish().FishKept);
|
|
}
|
|
}
|
|
|
|
public void OnWaterChanged(AquariumWaterType value)
|
|
{
|
|
_render.SetWater(value);
|
|
}
|
|
|
|
public void OnEnviroChanged(int value, AquariumWaterType water)
|
|
{
|
|
_render.SetEnviro(value, water);
|
|
if (!VRManager.IsVROn())
|
|
{
|
|
SetWaterProfile(value, water);
|
|
}
|
|
}
|
|
|
|
public void SetWaterProfile(int value, AquariumWaterType water)
|
|
{
|
|
_aquariumWater.ProfilesManager.SetProfiles(new Water.WeightedProfile(_render.GetWaterProfile(value, water), 1f));
|
|
}
|
|
|
|
public void SetWaterProfile()
|
|
{
|
|
_aquariumWater.ProfilesManager.SetProfiles(new Water.WeightedProfile(_render.GetWaterProfile(_settings.enviroPreset, _settings.waterType), 1f));
|
|
}
|
|
|
|
public void OnNameChanged(string value)
|
|
{
|
|
}
|
|
|
|
public void RemoveAllFish()
|
|
{
|
|
_schoolController.RemoveAllFish();
|
|
UpdateFishCount();
|
|
}
|
|
|
|
public void OnSellFish(FishManager.FishKept fish)
|
|
{
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
int value = Mathf.RoundToInt(fish.weight);
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
value = GlobalSettings.Instance.playerSettings.GetFishToMoney(fish.weight, fish.GetFishDefinition().fishPrefab.moneyFactor);
|
|
}
|
|
GlobalSettings.Instance.playerSettings.AddMoney(value);
|
|
}
|
|
RemoveFromAquarium(fish);
|
|
GlobalSettings.Instance.fishManager.fishKeep.Remove(fish);
|
|
GlobalSettings.Instance.fishManager.SaveFishKeep();
|
|
GlobalSettings.Instance.playerSettings.Save();
|
|
UpdateFishCount();
|
|
}
|
|
|
|
public void OnRemoveFromAquarium(FishManager.FishKept fish)
|
|
{
|
|
RemoveFromAquarium(fish);
|
|
UpdateFishCount();
|
|
}
|
|
|
|
public void OnInspectFish(FishManager.FishKept fish)
|
|
{
|
|
if (VRManager.IsVROn())
|
|
{
|
|
TrophyRoomManager.Instance.trophyPlayerVR.Enable(this, false, delegate
|
|
{
|
|
_aquariumCamera.gameObject.SetActive(true);
|
|
OnCameraChanged(true);
|
|
_aquariumCamera.AttachToFish(_schoolController.GetFish(fish));
|
|
}, delegate
|
|
{
|
|
_uiAquarium.InspectFish(fish);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
_uiAquarium.InspectFishFaded(fish, delegate
|
|
{
|
|
_aquariumCamera.AttachToFish(_schoolController.GetFish(fish));
|
|
});
|
|
}
|
|
_lastInspectedFish = fish;
|
|
}
|
|
|
|
public void InspectNeighbourFish(bool next)
|
|
{
|
|
if (_lastInspectedFish == null)
|
|
{
|
|
Debug.LogError("Last inspectred fish is null", this);
|
|
}
|
|
else if (next)
|
|
{
|
|
OnInspectFish(_schoolController.GetNextFish(_lastInspectedFish).FishKept);
|
|
}
|
|
else
|
|
{
|
|
OnInspectFish(_schoolController.GetPreviousFish(_lastInspectedFish).FishKept);
|
|
}
|
|
}
|
|
|
|
public void OnCloseInspectFish()
|
|
{
|
|
if (VRManager.IsVROn())
|
|
{
|
|
_uiAquarium.CloseInspectFish();
|
|
TrophyRoomManager.Instance.trophyPlayerVR.Enable(this, true, delegate
|
|
{
|
|
_aquariumCamera.DetachFromFish();
|
|
_aquariumCamera.gameObject.SetActive(false);
|
|
OnCameraChanged(false);
|
|
}, null);
|
|
}
|
|
else
|
|
{
|
|
_uiAquarium.CloseInspectFishFaded(delegate
|
|
{
|
|
_aquariumCamera.DetachFromFish();
|
|
});
|
|
}
|
|
_lastInspectedFish = null;
|
|
}
|
|
|
|
public void OnPutInTheAquarium(FishManager.FishKept fish)
|
|
{
|
|
fish.aquarium = _settings.id;
|
|
UpdateFishCount();
|
|
AddToAquarium(fish);
|
|
GlobalSettings.Instance.fishManager.SaveFishKeep();
|
|
}
|
|
|
|
public void OnCreateAquarium(AquariumSettings settings)
|
|
{
|
|
_settings.name = settings.name;
|
|
_settings.waterType = settings.waterType;
|
|
_settings.enviroPreset = settings.enviroPreset;
|
|
GlobalSettings.Instance.fishManager.SaveAquarium(_settings);
|
|
_uiAquarium.OnCreateAquarium();
|
|
}
|
|
|
|
public void OnCancelCreateAquarium()
|
|
{
|
|
_render.SetAquarium(_settings);
|
|
HideAquariumGUI();
|
|
}
|
|
|
|
public void OnCloaseManageAquarium()
|
|
{
|
|
HideAquariumGUI();
|
|
}
|
|
|
|
public void OnRemakeAquarium()
|
|
{
|
|
_uiAquarium.OnRemakeAquarium();
|
|
}
|
|
|
|
public void ShowAquariumGUI()
|
|
{
|
|
if (VRManager.IsVROn())
|
|
{
|
|
_uiAquarium.Show(this);
|
|
return;
|
|
}
|
|
_isShown = true;
|
|
EnablePlayerControls(false);
|
|
_uiAquarium.ShowFaded(this, delegate
|
|
{
|
|
EnableCursor(true);
|
|
_uiAquarium.HideInfo();
|
|
_cameraController.gameObject.SetActive(false);
|
|
_aquariumCamera.gameObject.SetActive(true);
|
|
OnCameraChanged(true);
|
|
});
|
|
}
|
|
|
|
private void HideAquariumGUI()
|
|
{
|
|
if (VRManager.IsVROn())
|
|
{
|
|
_uiAquarium.Hide();
|
|
_uiAquarium.ShowInfo(this);
|
|
return;
|
|
}
|
|
EnableCursor(false);
|
|
_uiAquarium.HideFaded(delegate
|
|
{
|
|
_aquariumCamera.gameObject.SetActive(false);
|
|
_cameraController.gameObject.SetActive(true);
|
|
OnCameraChanged(false);
|
|
EnablePlayerControls(true);
|
|
_uiAquarium.ShowInfo(this);
|
|
_isShown = false;
|
|
});
|
|
}
|
|
|
|
private void EnablePlayerControls(bool enable)
|
|
{
|
|
if (!enable)
|
|
{
|
|
_playerController.Stop();
|
|
}
|
|
_playerController.AllowMoveInput = enable;
|
|
_cameraController.enabled = enable;
|
|
}
|
|
|
|
private void EnableCursor(bool enable)
|
|
{
|
|
Cursor.lockState = ((!enable) ? CursorLockMode.Locked : CursorLockMode.None);
|
|
Cursor.visible = enable;
|
|
}
|
|
|
|
private void UpdateFishCount()
|
|
{
|
|
_settings.currentFishCount = 0;
|
|
foreach (FishManager.FishKept item in GlobalSettings.Instance.fishManager.fishKeep)
|
|
{
|
|
if (item.aquarium == _settings.id)
|
|
{
|
|
_settings.currentFishCount++;
|
|
}
|
|
}
|
|
}
|
|
|
|
public string GetDefaultName()
|
|
{
|
|
return Utilities.GetTranslation("GUI/AQUARIUM/AQUARIUM") + " " + _settings.id;
|
|
}
|
|
|
|
public List<string> GetEnviroOptions(AquariumWaterType waterType)
|
|
{
|
|
return _render.GetEnvironments(waterType);
|
|
}
|
|
|
|
public static List<string> GetWaterOptions()
|
|
{
|
|
List<string> list = new List<string>();
|
|
list.Add(Utilities.GetTranslation("GUI/AQUARIUM/FRESHWATER"));
|
|
list.Add(Utilities.GetTranslation("GUI/AQUARIUM/SALTWATER"));
|
|
return list;
|
|
}
|
|
|
|
public int GetFishNumber()
|
|
{
|
|
return _schoolController.GetSchoolSize();
|
|
}
|
|
|
|
private void OnCameraChanged(bool isUnderwater)
|
|
{
|
|
_render.OnCameraChanged(isUnderwater);
|
|
if (isUnderwater)
|
|
{
|
|
SetWaterProfile();
|
|
}
|
|
}
|
|
}
|