Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/TutorialManager.cs
2026-02-21 16:45:37 +08:00

319 lines
6.7 KiB
C#

using System;
using System.Collections.Generic;
using BitStrap;
using UnityEngine;
public class TutorialManager : MonoBehaviour
{
public enum TutorialsId
{
NONE = 0,
PROFILE_01 = 1,
START_01 = 2,
START_02 = 3,
ENTER_FISHERY_01 = 4,
SIMPLE_INPUT_01 = 5,
THROW_NEAR_01 = 6,
REEL_01 = 7,
THROW_FAR_01 = 8,
STRIKE_01 = 9,
FIGHT_01 = 10,
PULL_FISH_01 = 11,
METHODS_01 = 12,
WATCH_FISH_01 = 13,
BOILIE_01 = 14,
DRILL_01 = 15,
BOAT_01 = 16,
BEER_FOOD_01 = 17,
EQUIPMENT_01 = 18,
FISHERY_01 = 19,
SKILLS_01 = 20,
FIGHT_02 = 21,
FIGHT_03 = 22,
FISHING_NET = 23,
FLOAT_PARAMS_01 = 24,
ICE_FISHING_01 = 25,
HOOKS_01 = 26,
FISHING_NET_START = 27,
FLY_FISHING_01 = 28,
FLY_FISHING_02 = 29,
TROLLING_01 = 30,
TROLLING_02 = 31,
VR_NOT_INITIALIZED = 32,
VR_OPTIONS = 33,
VR_START = 34
}
private static TutorialManager instance;
public bool isActive = true;
public bool showAlways;
public GameObject inputBlock;
public Transform buildInfoParent;
public float skipDelay = 2f;
[ReadOnly]
public bool wasJustClosed;
[ReadOnly]
public bool showGameFinish;
[ReadOnly]
public float prevTimeScale = 1f;
[ReadOnly]
public TutorialPanel currentTutorial;
[ReadOnly]
public TutorialPanel throwNearTutorial;
[ReadOnly]
public TutorialPanel throwFlyTutorial;
[Header("Help Params")]
public bool helpBlockFarThrow;
public bool helpBlockNearThrow;
public bool helpDontCatchAnything;
public bool helpCatchAnything;
public List<TutorialPanel> tutorialPanels;
public static TutorialManager Instance
{
get
{
return instance;
}
}
private TutorialManager()
{
}
private void Awake()
{
if (instance == null)
{
instance = this;
UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
Initialize();
}
else
{
UnityEngine.Object.DestroyImmediate(base.gameObject);
}
}
private void Initialize()
{
GatherTutorials();
HideAllTutorial();
inputBlock.SetActive(false);
throwNearTutorial = FindTutorial(TutorialsId.THROW_NEAR_01);
throwFlyTutorial = FindTutorial(TutorialsId.FLY_FISHING_01);
}
private void Update()
{
if (wasJustClosed)
{
wasJustClosed = false;
}
if ((Input.GetKeyUp(KeyCode.Space) || Input.GetKeyUp(KeyCode.KeypadEnter) || Input.GetKeyUp(KeyCode.Mouse0) || Input.GetKeyUp(KeyCode.Mouse1) || Input.GetKeyUp(KeyCode.Escape) || UtilitiesInput.GetButtonDown("TUTORIAL_HIDE") || UtilitiesInput.GetButtonDown("UISubmit") || UtilitiesInput.GetButtonDown("UICancel") || OVRInput.GetUp(OVRInput.Button.PrimaryIndexTrigger, OVRInput.Controller.Touch) || OVRInput.GetUp(OVRInput.Button.SecondaryIndexTrigger, OVRInput.Controller.Touch)) && (bool)GetCurrentTutorial() && GetCurrentTutorial().IsVisible())
{
TutorialPanel tutorialPanel = GetCurrentTutorial();
if (((!Input.GetKeyDown(KeyCode.Mouse0) && !VRManager.IsVROn()) || !tutorialPanel.skipButton.isMouseOver) && (tutorialPanel.canBeSkipped || Input.GetKeyDown(KeyCode.Escape)))
{
tutorialPanel.HideTutorial();
wasJustClosed = true;
}
}
}
public void GatherTutorials()
{
tutorialPanels = new List<TutorialPanel>(GetComponentsInChildren<TutorialPanel>(true));
}
public TutorialPanel FindTutorial(TutorialsId id)
{
foreach (TutorialPanel tutorialPanel in tutorialPanels)
{
if (tutorialPanel.tutorialId == id)
{
return tutorialPanel;
}
}
Debug.LogError("Tutorial not found: " + id);
return null;
}
[Button]
public void ShowTestTutorial()
{
ShowTutorial(TutorialsId.START_01);
}
public void ShowTutorial(TutorialsId tutorialId, float delay = 0f)
{
if (!isActive || (bool)GetCurrentTutorial())
{
return;
}
TutorialPanel tutorial = FindTutorial(tutorialId);
if ((bool)tutorial && tutorialId == TutorialsId.VR_NOT_INITIALIZED)
{
tutorial.wasShown = false;
}
if (!tutorial || (tutorial.wasShown && !Instance.showAlways && tutorial.prevTutorial == TutorialsId.NONE))
{
return;
}
if (tutorial.isMenuTutorial && Time.timeScale == 0f)
{
delay = 0f;
}
if (delay == 0f)
{
tutorial.ShowTutorial();
return;
}
LeanTween.delayedCall(delay, (Action)delegate
{
tutorial.ShowTutorial();
});
}
public void HideTutorial(TutorialsId tutorialId)
{
FindTutorial(tutorialId).HideTutorial();
}
public void HideAllTutorial()
{
foreach (TutorialPanel tutorialPanel in tutorialPanels)
{
tutorialPanel.HideTutorialForce();
}
inputBlock.SetActive(false);
}
public bool WasTutorialShown(TutorialsId tutorialId)
{
TutorialPanel tutorialPanel = FindTutorial(tutorialId);
if ((bool)tutorialPanel)
{
return tutorialPanel.wasShown;
}
return false;
}
public TutorialPanel GetCurrentTutorial()
{
return currentTutorial;
}
public void UpdateHelpParams(TutorialsId tutorialId, bool show)
{
switch (tutorialId)
{
case TutorialsId.THROW_FAR_01:
helpDontCatchAnything = false;
break;
case TutorialsId.STRIKE_01:
helpBlockNearThrow = false;
break;
case TutorialsId.WATCH_FISH_01:
helpCatchAnything = false;
break;
}
}
public void ResetAllTutorials()
{
foreach (TutorialPanel tutorialPanel in tutorialPanels)
{
tutorialPanel.ResetTutorial();
helpDontCatchAnything = false;
helpCatchAnything = false;
}
}
public void ResetHelpParams()
{
helpBlockFarThrow = false;
helpBlockNearThrow = false;
helpDontCatchAnything = false;
helpCatchAnything = false;
}
public void SkipAllTutorials()
{
foreach (TutorialPanel tutorialPanel in tutorialPanels)
{
tutorialPanel.wasShown = true;
}
Instance.Save();
}
public void SetIsActive(bool active)
{
isActive = active;
Save();
}
public void Save()
{
if (!GlobalSettings.Instance)
{
return;
}
string currentProfilePrefix = GlobalSettings.Instance.saveManager.GetCurrentProfilePrefix();
using (ES2Writer eS2Writer = ES2Writer.Create(currentProfilePrefix))
{
eS2Writer.Write(isActive, "tutorialsActive");
for (int i = 0; i < tutorialPanels.Count; i++)
{
eS2Writer.Write(tutorialPanels[i].wasShown, "tutorial_shown_" + i);
}
eS2Writer.Save();
Debug.Log("Save TutorialManager");
}
}
public void Load()
{
if (GlobalSettings.Instance.currentPlatform == GlobalSettings.Platform.ARCADE)
{
ResetAllTutorials();
isActive = true;
return;
}
string currentProfilePrefix = GlobalSettings.Instance.saveManager.GetCurrentProfilePrefix();
using (ES2Reader reader = ES2Reader.Create(currentProfilePrefix))
{
isActive = SaveManager.Read(reader, "tutorialsActive", true);
for (int i = 0; i < tutorialPanels.Count; i++)
{
tutorialPanels[i].wasShown = SaveManager.Read(reader, "tutorial_shown_" + i, false);
}
}
ResetHelpParams();
}
[Button]
public void Reset()
{
ResetAllTutorials();
isActive = true;
Save();
}
}