practice mode integrated to the onboarding tutorial
This commit is contained in:
@@ -3,6 +3,8 @@ using System.Collections;
|
||||
using Mirror;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
using DG.Tweening;
|
||||
|
||||
public class GameTutorialManager : MonoBehaviour
|
||||
{
|
||||
@@ -15,6 +17,17 @@ public class GameTutorialManager : MonoBehaviour
|
||||
|
||||
public AiBotController aiController;
|
||||
|
||||
[Header("UI")]
|
||||
public CanvasGroup intro_shoot;
|
||||
public CanvasGroup intro_goal;
|
||||
public float introFadeDuration = 0.3f;
|
||||
|
||||
Button _introShootButton;
|
||||
Button _introGoalButton;
|
||||
bool _shootIntroDismissed;
|
||||
bool _goalIntroDismissed;
|
||||
bool _introVisible;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
tutorialModeEnabled = false;
|
||||
@@ -25,25 +38,171 @@ public class GameTutorialManager : MonoBehaviour
|
||||
tutorialModeEnabled = true;
|
||||
|
||||
tutorialModeTrigger = false;
|
||||
|
||||
if (!tutorialModeEnabled)
|
||||
{
|
||||
HideIntroImmediate(intro_shoot);
|
||||
HideIntroImmediate(intro_goal);
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
GameManager.OnTeamChanged += OnTeamChanged;
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
GameManager.OnTeamChanged -= OnTeamChanged;
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (tutorialModeEnabled)
|
||||
tutorialModeEnabled = false;
|
||||
|
||||
if (intro_shoot != null)
|
||||
DOTween.Kill(intro_shoot);
|
||||
if (intro_goal != null)
|
||||
DOTween.Kill(intro_goal);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (tutorialModeEnabled)
|
||||
{
|
||||
NetManager.StopNetworkingForSceneChange();
|
||||
|
||||
NetworkManager.singleton.networkAddress = "localhost";
|
||||
NetworkManager.singleton.StartHost();
|
||||
|
||||
WireIntroButtons();
|
||||
HideIntroImmediate(intro_goal);
|
||||
HideIntroImmediate(intro_shoot);
|
||||
|
||||
StartCoroutine(SetupAiWhenReady());
|
||||
StartCoroutine(ShowShootIntroWhenReady());
|
||||
}
|
||||
}
|
||||
|
||||
void WireIntroButtons()
|
||||
{
|
||||
if (intro_shoot != null)
|
||||
_introShootButton = intro_shoot.GetComponentInChildren<Button>(true);
|
||||
if (intro_goal != null)
|
||||
_introGoalButton = intro_goal.GetComponentInChildren<Button>(true);
|
||||
|
||||
if (_introShootButton != null)
|
||||
_introShootButton.onClick.AddListener(OnShootIntroDismissed);
|
||||
if (_introGoalButton != null)
|
||||
_introGoalButton.onClick.AddListener(OnGoalIntroDismissed);
|
||||
}
|
||||
|
||||
IEnumerator ShowShootIntroWhenReady()
|
||||
{
|
||||
while (GameManager.instance == null || !GameManager.instance.gameStarted)
|
||||
yield return null;
|
||||
|
||||
while (NetPlayer.localPlayer == null)
|
||||
yield return null;
|
||||
|
||||
ShowIntro(intro_shoot);
|
||||
}
|
||||
|
||||
void OnTeamChanged(Team team)
|
||||
{
|
||||
if (!tutorialModeEnabled || _introVisible)
|
||||
return;
|
||||
if (team != GetPlayerTeam())
|
||||
return;
|
||||
if (!_shootIntroDismissed || _goalIntroDismissed)
|
||||
return;
|
||||
|
||||
ShowIntro(intro_goal);
|
||||
}
|
||||
|
||||
void OnShootIntroDismissed()
|
||||
{
|
||||
if (_shootIntroDismissed)
|
||||
return;
|
||||
|
||||
_shootIntroDismissed = true;
|
||||
DismissIntro(intro_shoot);
|
||||
}
|
||||
|
||||
void OnGoalIntroDismissed()
|
||||
{
|
||||
if (_goalIntroDismissed)
|
||||
return;
|
||||
|
||||
_goalIntroDismissed = true;
|
||||
DismissIntro(intro_goal);
|
||||
}
|
||||
|
||||
void ShowIntro(CanvasGroup group)
|
||||
{
|
||||
if (group == null)
|
||||
return;
|
||||
|
||||
EnsureTutorialCanvasVisible(group);
|
||||
DOTween.Kill(group);
|
||||
|
||||
group.gameObject.SetActive(true);
|
||||
group.alpha = 1f;
|
||||
group.interactable = true;
|
||||
group.blocksRaycasts = true;
|
||||
|
||||
_introVisible = true;
|
||||
if (GameManager.instance != null)
|
||||
GameManager.instance.SetTurnTimerPaused(true);
|
||||
}
|
||||
|
||||
void DismissIntro(CanvasGroup group)
|
||||
{
|
||||
if (group == null)
|
||||
return;
|
||||
|
||||
group.interactable = false;
|
||||
group.blocksRaycasts = false;
|
||||
|
||||
DOTween.Kill(group);
|
||||
group.DOFade(0f, introFadeDuration)
|
||||
.SetEase(Ease.InOutSine)
|
||||
.OnComplete(() =>
|
||||
{
|
||||
group.gameObject.SetActive(false);
|
||||
_introVisible = false;
|
||||
if (GameManager.instance != null)
|
||||
GameManager.instance.SetTurnTimerPaused(false);
|
||||
});
|
||||
}
|
||||
|
||||
static void HideIntroImmediate(CanvasGroup group)
|
||||
{
|
||||
if (group == null)
|
||||
return;
|
||||
|
||||
DOTween.Kill(group);
|
||||
group.alpha = 0f;
|
||||
group.interactable = false;
|
||||
group.blocksRaycasts = false;
|
||||
group.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
static void EnsureTutorialCanvasVisible(CanvasGroup group)
|
||||
{
|
||||
Transform root = group.transform.root;
|
||||
if (root.localScale == Vector3.zero)
|
||||
root.localScale = Vector3.one;
|
||||
}
|
||||
|
||||
static Team GetPlayerTeam()
|
||||
{
|
||||
if (NetPlayer.localPlayer != null)
|
||||
return NetPlayer.localPlayer.myTeam;
|
||||
return GameManager.MyTeam;
|
||||
}
|
||||
|
||||
/// <summary>Call from the main menu before loading the game scene.</summary>
|
||||
public static void PrepareLaunch(MatchmadePlayer myPlayer, MatchmadePlayer cpuPlayer, Team myTeam = Team.Red)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user