| | 1 | | using DCL.Controllers; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using DCL.Interface; |
| | 4 | | using System; |
| | 5 | | using System.Collections; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using UnityEngine; |
| | 8 | | using Object = UnityEngine.Object; |
| | 9 | |
|
| | 10 | | namespace DCL.Tutorial |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// Controller that handles all the flow related to the onboarding tutorial. |
| | 14 | | /// </summary> |
| | 15 | | public class TutorialController : IPlugin |
| | 16 | | { |
| | 17 | | [Serializable] |
| | 18 | | public class TutorialInitializationMessage |
| | 19 | | { |
| | 20 | | public string fromDeepLink; |
| | 21 | | public string enableNewTutorialCamera; |
| | 22 | | } |
| | 23 | |
|
| | 24 | | [Flags] |
| | 25 | | public enum TutorialFinishStep |
| | 26 | | { |
| | 27 | | None = 0, |
| | 28 | | OldTutorialValue = 99, // NOTE: old tutorial set tutorialStep to 99 when finished |
| | 29 | | EmailRequested = 128, // NOTE: old email prompt set tutorialStep to 128 when finished |
| | 30 | | NewTutorialFinished = 256, |
| | 31 | | } |
| | 32 | |
|
| | 33 | | internal enum TutorialPath |
| | 34 | | { |
| | 35 | | FromGenesisPlaza, |
| | 36 | | FromDeepLink, |
| | 37 | | FromResetTutorial, |
| | 38 | | FromUserThatAlreadyDidTheTutorial, |
| | 39 | | } |
| | 40 | |
|
| 0 | 41 | | public static TutorialController i { get; private set; } |
| | 42 | |
|
| 0 | 43 | | public HUDController hudController => HUDController.i; |
| | 44 | |
|
| 0 | 45 | | public int currentStepIndex { get; internal set; } |
| | 46 | | public event Action OnTutorialEnabled; |
| | 47 | | public event Action OnTutorialDisabled; |
| | 48 | |
|
| | 49 | | private const string PLAYER_PREFS_START_MENU_SHOWED = "StartMenuFeatureShowed"; |
| | 50 | |
|
| | 51 | | private readonly DataStore_Common commonDataStore; |
| | 52 | | private readonly DataStore_Settings settingsDataStore; |
| | 53 | | private readonly DataStore_ExploreV2 exploreV2DataStore; |
| | 54 | |
|
| | 55 | | internal readonly TutorialView tutorialView; |
| | 56 | |
|
| | 57 | | internal TutorialSettings configuration; |
| | 58 | |
|
| | 59 | | internal bool openedFromDeepLink; |
| | 60 | | internal bool playerIsInGenesisPlaza; |
| | 61 | | internal TutorialStep runningStep; |
| | 62 | | internal bool tutorialReset; |
| | 63 | | private float elapsedTimeInCurrentStep; |
| | 64 | | internal TutorialPath currentPath; |
| | 65 | | private int currentStepNumber; |
| | 66 | | private int nextStepsToSkip; |
| | 67 | |
|
| | 68 | | private Coroutine executeStepsCoroutine; |
| | 69 | | private Coroutine teacherMovementCoroutine; |
| | 70 | | private Coroutine eagleEyeRotationCoroutine; |
| | 71 | |
|
| 0 | 72 | | internal bool userAlreadyDidTheTutorial { get; set; } |
| | 73 | |
|
| 0 | 74 | | public TutorialController(DataStore_Common commonDataStore, DataStore_Settings settingsDataStore, DataStore_Expl |
| | 75 | | { |
| 0 | 76 | | this.commonDataStore = commonDataStore; |
| 0 | 77 | | this.settingsDataStore = settingsDataStore; |
| 0 | 78 | | this.exploreV2DataStore = exploreV2DataStore; |
| | 79 | |
|
| 0 | 80 | | i = this; |
| | 81 | |
|
| 0 | 82 | | tutorialView = CreateTutorialView(); |
| 0 | 83 | | SetConfiguration(tutorialView.configuration); |
| 0 | 84 | | } |
| | 85 | |
|
| | 86 | | private TutorialView CreateTutorialView() |
| | 87 | | { |
| 0 | 88 | | GameObject tutorialObject = Object.Instantiate(Resources.Load<GameObject>("TutorialView")); |
| 0 | 89 | | tutorialObject.name = "TutorialController"; |
| | 90 | |
|
| 0 | 91 | | TutorialView view = tutorialObject.GetComponent<TutorialView>(); |
| 0 | 92 | | view.ConfigureView(this); |
| | 93 | |
|
| 0 | 94 | | return view; |
| | 95 | | } |
| | 96 | |
|
| | 97 | | public void SetConfiguration(TutorialSettings config) |
| | 98 | | { |
| 0 | 99 | | configuration = config; |
| | 100 | |
|
| 0 | 101 | | ShowTeacher3DModel(false); |
| | 102 | |
|
| 0 | 103 | | if (settingsDataStore.isInitialized.Get()) |
| 0 | 104 | | IsSettingsHUDInitialized_OnChange(true, false); |
| | 105 | | else |
| 0 | 106 | | settingsDataStore.isInitialized.OnChange += IsSettingsHUDInitialized_OnChange; |
| | 107 | |
|
| 0 | 108 | | if (config.debugRunTutorial) |
| 0 | 109 | | SetTutorialEnabled(JsonUtility.ToJson(new TutorialInitializationMessage |
| | 110 | | { |
| | 111 | | fromDeepLink = config.debugOpenedFromDeepLink.ToString(), |
| | 112 | | enableNewTutorialCamera = false.ToString(), |
| | 113 | | })); |
| 0 | 114 | | } |
| | 115 | |
|
| | 116 | | public void Dispose() |
| | 117 | | { |
| 0 | 118 | | SetTutorialDisabled(); |
| | 119 | |
|
| 0 | 120 | | settingsDataStore.isInitialized.OnChange -= IsSettingsHUDInitialized_OnChange; |
| | 121 | |
|
| 0 | 122 | | if (hudController is { settingsPanelHud: { } }) |
| 0 | 123 | | hudController.settingsPanelHud.OnRestartTutorial -= OnRestartTutorial; |
| | 124 | |
|
| 0 | 125 | | NotificationsController.disableWelcomeNotification = false; |
| | 126 | |
|
| 0 | 127 | | if (tutorialView != null) |
| 0 | 128 | | Object.Destroy(tutorialView.gameObject); |
| 0 | 129 | | } |
| | 130 | |
|
| | 131 | | public void SetTutorialEnabled(string json) |
| | 132 | | { |
| 0 | 133 | | TutorialInitializationMessage msg = JsonUtility.FromJson<TutorialInitializationMessage>(json); |
| 0 | 134 | | SetupTutorial(msg.fromDeepLink, msg.enableNewTutorialCamera); |
| 0 | 135 | | } |
| | 136 | |
|
| | 137 | | public void SetTutorialEnabledForUsersThatAlreadyDidTheTutorial(string json) |
| | 138 | | { |
| 0 | 139 | | TutorialInitializationMessage msg = JsonUtility.FromJson<TutorialInitializationMessage>(json); |
| | 140 | |
|
| | 141 | | // TODO (Santi): This a TEMPORAL fix. It will be removed when we refactor the tutorial system in order to ma |
| 0 | 142 | | if (PlayerPrefsBridge.GetInt(PLAYER_PREFS_START_MENU_SHOWED) == 1) |
| 0 | 143 | | return; |
| | 144 | |
|
| 0 | 145 | | SetupTutorial(false.ToString(), msg.enableNewTutorialCamera, true); |
| 0 | 146 | | } |
| | 147 | |
|
| | 148 | | /// <summary> |
| | 149 | | /// Enables the tutorial controller and waits for the RenderingState is enabled to start to execute the correspo |
| | 150 | | /// </summary> |
| | 151 | | internal void SetupTutorial(string fromDeepLink, string enableNewTutorialCamera, bool userAlreadyDidTheTutorial |
| | 152 | | { |
| 0 | 153 | | if (commonDataStore.isWorld.Get() || commonDataStore.isTutorialRunning.Get()) |
| 0 | 154 | | return; |
| | 155 | |
|
| 0 | 156 | | if (Convert.ToBoolean(enableNewTutorialCamera)) |
| | 157 | | { |
| 0 | 158 | | configuration.eagleCamInitPosition = new Vector3(15, 115, -30); |
| 0 | 159 | | configuration.eagleCamInitLookAtPoint = new Vector3(16, 105, 6); |
| 0 | 160 | | configuration.eagleCamRotationActived = false; |
| | 161 | | } |
| | 162 | |
|
| 0 | 163 | | commonDataStore.isTutorialRunning.Set(true); |
| 0 | 164 | | this.userAlreadyDidTheTutorial = userAlreadyDidTheTutorial; |
| 0 | 165 | | CommonScriptableObjects.allUIHidden.Set(false); |
| 0 | 166 | | CommonScriptableObjects.tutorialActive.Set(true); |
| 0 | 167 | | openedFromDeepLink = Convert.ToBoolean(fromDeepLink); |
| | 168 | |
|
| 0 | 169 | | hudController?.settingsPanelHud?.SetTutorialButtonEnabled(false); |
| | 170 | |
|
| 0 | 171 | | NotificationsController.disableWelcomeNotification = true; |
| | 172 | |
|
| 0 | 173 | | WebInterface.SetDelightedSurveyEnabled(false); |
| | 174 | |
|
| 0 | 175 | | if (!CommonScriptableObjects.rendererState.Get()) |
| 0 | 176 | | CommonScriptableObjects.rendererState.OnChange += OnRenderingStateChanged; |
| | 177 | | else |
| 0 | 178 | | OnRenderingStateChanged(true, false); |
| | 179 | |
|
| 0 | 180 | | OnTutorialEnabled?.Invoke(); |
| 0 | 181 | | } |
| | 182 | |
|
| | 183 | | /// <summary> |
| | 184 | | /// Stop and disables the tutorial controller. |
| | 185 | | /// </summary> |
| | 186 | | public void SetTutorialDisabled() |
| | 187 | | { |
| 0 | 188 | | CommonScriptableObjects.featureKeyTriggersBlocked.Set(false); |
| | 189 | |
|
| 0 | 190 | | if (executeStepsCoroutine != null) |
| | 191 | | { |
| 0 | 192 | | CoroutineStarter.Stop(executeStepsCoroutine); |
| 0 | 193 | | executeStepsCoroutine = null; |
| | 194 | | } |
| | 195 | |
|
| 0 | 196 | | if (runningStep != null) |
| | 197 | | { |
| 0 | 198 | | Object.Destroy(runningStep.gameObject); |
| 0 | 199 | | runningStep = null; |
| | 200 | | } |
| | 201 | |
|
| 0 | 202 | | if (teacherMovementCoroutine != null) |
| | 203 | | { |
| 0 | 204 | | CoroutineStarter.Stop(teacherMovementCoroutine); |
| 0 | 205 | | teacherMovementCoroutine = null; |
| | 206 | | } |
| | 207 | |
|
| 0 | 208 | | tutorialReset = false; |
| 0 | 209 | | commonDataStore.isTutorialRunning.Set(false); |
| 0 | 210 | | tutorialView.tutorialMusicHandler.StopTutorialMusic(); |
| 0 | 211 | | ShowTeacher3DModel(false); |
| 0 | 212 | | WebInterface.SetDelightedSurveyEnabled(true); |
| | 213 | |
|
| 0 | 214 | | if (Environment.i is { world: { } }) |
| 0 | 215 | | WebInterface.SendSceneExternalActionEvent(Environment.i.world.state.GetCurrentSceneNumber(), "tutorial", |
| | 216 | |
|
| 0 | 217 | | NotificationsController.disableWelcomeNotification = false; |
| | 218 | |
|
| 0 | 219 | | hudController?.settingsPanelHud?.SetTutorialButtonEnabled(true); |
| | 220 | |
|
| 0 | 221 | | CommonScriptableObjects.tutorialActive.Set(false); |
| | 222 | |
|
| 0 | 223 | | CommonScriptableObjects.rendererState.OnChange -= OnRenderingStateChanged; |
| | 224 | |
|
| 0 | 225 | | OnTutorialDisabled?.Invoke(); |
| 0 | 226 | | } |
| | 227 | |
|
| | 228 | | /// <summary> |
| | 229 | | /// Starts to execute the tutorial from a specific step (It is needed to call SetTutorialEnabled() before). |
| | 230 | | /// </summary> |
| | 231 | | /// <param name="stepIndex">First step to be executed.</param> |
| | 232 | | internal IEnumerator StartTutorialFromStep(int stepIndex) |
| | 233 | | { |
| 0 | 234 | | if (!commonDataStore.isTutorialRunning.Get()) |
| 0 | 235 | | yield break; |
| | 236 | |
|
| 0 | 237 | | if (runningStep != null) |
| | 238 | | { |
| 0 | 239 | | runningStep.OnStepFinished(); |
| 0 | 240 | | Object.Destroy(runningStep.gameObject); |
| 0 | 241 | | runningStep = null; |
| | 242 | | } |
| | 243 | |
|
| 0 | 244 | | yield return new WaitUntil(IsPlayerInScene); |
| | 245 | |
|
| 0 | 246 | | playerIsInGenesisPlaza = IsPlayerInsideGenesisPlaza(); |
| | 247 | |
|
| 0 | 248 | | if (playerIsInGenesisPlaza) |
| 0 | 249 | | tutorialView.tutorialMusicHandler.TryPlayingMusic(); |
| | 250 | |
|
| 0 | 251 | | yield return ExecuteRespectiveTutorialStep(stepIndex); |
| 0 | 252 | | } |
| | 253 | |
|
| | 254 | | private IEnumerator ExecuteRespectiveTutorialStep(int stepIndex) |
| | 255 | | { |
| 0 | 256 | | if (userAlreadyDidTheTutorial) |
| 0 | 257 | | yield return ExecuteSteps(TutorialPath.FromUserThatAlreadyDidTheTutorial, stepIndex); |
| 0 | 258 | | else if (tutorialReset) |
| 0 | 259 | | yield return ExecuteSteps(TutorialPath.FromResetTutorial, stepIndex); |
| 0 | 260 | | else if (playerIsInGenesisPlaza) |
| 0 | 261 | | yield return ExecuteSteps(TutorialPath.FromGenesisPlaza, stepIndex); |
| 0 | 262 | | else if (openedFromDeepLink) |
| 0 | 263 | | yield return ExecuteSteps(TutorialPath.FromDeepLink, stepIndex); |
| | 264 | | else |
| 0 | 265 | | SetTutorialDisabled(); |
| 0 | 266 | | } |
| | 267 | |
|
| | 268 | | /// <summary> |
| | 269 | | /// Shows the teacher that will be guiding along the tutorial. |
| | 270 | | /// </summary> |
| | 271 | | /// <param name="active">True for show the teacher.</param> |
| | 272 | | public void ShowTeacher3DModel(bool active) |
| | 273 | | { |
| 0 | 274 | | if (configuration.teacherCamera != null) |
| 0 | 275 | | configuration.teacherCamera.enabled = active; |
| | 276 | |
|
| 0 | 277 | | if (configuration.teacherRawImage != null) |
| 0 | 278 | | configuration.teacherRawImage.gameObject.SetActive(active); |
| 0 | 279 | | } |
| | 280 | |
|
| | 281 | | /// <summary> |
| | 282 | | /// Move the tutorial teacher to a specific position. |
| | 283 | | /// </summary> |
| | 284 | | /// <param name="destinationPosition">Target position.</param> |
| | 285 | | /// <param name="animated">True for apply a smooth movement.</param> |
| | 286 | | public void SetTeacherPosition(Vector3 destinationPosition, bool animated = true) |
| | 287 | | { |
| 0 | 288 | | if (teacherMovementCoroutine != null) |
| 0 | 289 | | CoroutineStarter.Stop(teacherMovementCoroutine); |
| | 290 | |
|
| 0 | 291 | | if (configuration.teacherRawImage != null) |
| | 292 | | { |
| 0 | 293 | | if (animated) |
| 0 | 294 | | teacherMovementCoroutine = CoroutineStarter.Start(MoveTeacher(destinationPosition)); |
| | 295 | | else |
| 0 | 296 | | configuration.teacherRawImage.rectTransform.position = new Vector3(destinationPosition.x, destinatio |
| | 297 | | } |
| 0 | 298 | | } |
| | 299 | |
|
| | 300 | | /// <summary> |
| | 301 | | /// Plays a specific animation on the tutorial teacher. |
| | 302 | | /// </summary> |
| | 303 | | /// <param name="animation">Animation to apply.</param> |
| | 304 | | public void PlayTeacherAnimation(TutorialTeacher.TeacherAnimation animation) |
| | 305 | | { |
| 0 | 306 | | if (configuration.teacher == null) |
| 0 | 307 | | return; |
| | 308 | |
|
| 0 | 309 | | configuration.teacher.PlayAnimation(animation); |
| 0 | 310 | | } |
| | 311 | |
|
| | 312 | | /// <summary> |
| | 313 | | /// Set sort order for canvas containing teacher RawImage |
| | 314 | | /// </summary> |
| | 315 | | /// <param name="sortOrder"></param> |
| | 316 | | public void SetTeacherCanvasSortingOrder(int sortOrder) |
| | 317 | | { |
| 0 | 318 | | if (configuration.teacherCanvas == null) |
| 0 | 319 | | return; |
| | 320 | |
|
| 0 | 321 | | configuration.teacherCanvas.sortingOrder = sortOrder; |
| 0 | 322 | | } |
| | 323 | |
|
| | 324 | | /// <summary> |
| | 325 | | /// Finishes the current running step, skips all the next ones and completes the tutorial. |
| | 326 | | /// </summary> |
| | 327 | | public void SkipTutorial(bool ignoreStatsSending = false) |
| | 328 | | { |
| 0 | 329 | | if (!ignoreStatsSending && NeedToSendStats()) |
| 0 | 330 | | SendSkipTutorialSegmentStats(configuration.tutorialVersion, runningStep.name); |
| | 331 | |
|
| 0 | 332 | | int skipIndex = configuration.stepsOnGenesisPlaza.Count + |
| | 333 | | configuration.stepsFromDeepLink.Count + |
| | 334 | | configuration.stepsFromReset.Count + |
| | 335 | | configuration.stepsFromUserThatAlreadyDidTheTutorial.Count; |
| | 336 | |
|
| 0 | 337 | | CoroutineStarter.Start(StartTutorialFromStep(skipIndex)); |
| | 338 | |
|
| 0 | 339 | | hudController?.taskbarHud?.SetVisibility(true); |
| 0 | 340 | | } |
| | 341 | |
|
| | 342 | | /// <summary> |
| | 343 | | /// Jump to a specific step. |
| | 344 | | /// </summary> |
| | 345 | | /// <param name="stepName">Step to jump.</param> |
| | 346 | | public void GoToSpecificStep(string stepName) |
| | 347 | | { |
| | 348 | | int stepIndex; |
| | 349 | |
|
| 0 | 350 | | if (userAlreadyDidTheTutorial) |
| 0 | 351 | | stepIndex = configuration.stepsFromUserThatAlreadyDidTheTutorial.FindIndex(x => x.name == stepName); |
| 0 | 352 | | else if (tutorialReset) |
| 0 | 353 | | stepIndex = configuration.stepsFromReset.FindIndex(x => x.name == stepName); |
| 0 | 354 | | else if (playerIsInGenesisPlaza) |
| 0 | 355 | | stepIndex = configuration.stepsOnGenesisPlaza.FindIndex(x => x.name == stepName); |
| 0 | 356 | | else if (openedFromDeepLink) |
| 0 | 357 | | stepIndex = configuration.stepsFromDeepLink.FindIndex(x => x.name == stepName); |
| | 358 | | else |
| 0 | 359 | | stepIndex = 0; |
| | 360 | |
|
| 0 | 361 | | nextStepsToSkip = 0; |
| | 362 | |
|
| 0 | 363 | | if (stepIndex >= 0) |
| 0 | 364 | | CoroutineStarter.Start(StartTutorialFromStep(stepIndex)); |
| | 365 | | else |
| 0 | 366 | | SkipTutorial(true); |
| 0 | 367 | | } |
| | 368 | |
|
| | 369 | | /// <summary> |
| | 370 | | /// Set the number of steps that will be skipped in the next iteration. |
| | 371 | | /// </summary> |
| | 372 | | /// <param name="skippedSteps">Number of steps to skip.</param> |
| | 373 | | public void SetNextSkippedSteps(int skippedSteps) => |
| 0 | 374 | | nextStepsToSkip = skippedSteps; |
| | 375 | |
|
| | 376 | | /// <summary> |
| | 377 | | /// Activate/deactivate the eagle eye camera. |
| | 378 | | /// </summary> |
| | 379 | | /// <param name="isActive">True for activate the eagle eye camera.</param> |
| | 380 | | public void SetEagleEyeCameraActive(bool isActive) |
| | 381 | | { |
| 0 | 382 | | configuration.eagleEyeCamera.gameObject.SetActive(isActive); |
| 0 | 383 | | CoroutineStarter.Start(BlockPlayerCameraUntilBlendingIsFinished(isActive)); |
| | 384 | |
|
| 0 | 385 | | if (isActive) |
| | 386 | | { |
| 0 | 387 | | configuration.eagleEyeCamera.transform.position = configuration.eagleCamInitPosition; |
| 0 | 388 | | configuration.eagleEyeCamera.transform.LookAt(configuration.eagleCamInitLookAtPoint); |
| | 389 | |
|
| 0 | 390 | | if (configuration.eagleCamRotationActived) |
| 0 | 391 | | eagleEyeRotationCoroutine = CoroutineStarter.Start(EagleEyeCameraRotation(configuration.eagleCamRota |
| | 392 | | } |
| 0 | 393 | | else if (eagleEyeRotationCoroutine != null) |
| 0 | 394 | | CoroutineStarter.Stop(eagleEyeRotationCoroutine); |
| 0 | 395 | | } |
| | 396 | |
|
| | 397 | | internal void OnRenderingStateChanged(bool renderingEnabled, bool prevState) |
| | 398 | | { |
| 0 | 399 | | if (!renderingEnabled) |
| 0 | 400 | | return; |
| | 401 | |
|
| 0 | 402 | | CommonScriptableObjects.rendererState.OnChange -= OnRenderingStateChanged; |
| | 403 | |
|
| 0 | 404 | | currentStepIndex = configuration.debugRunTutorial ? configuration.debugStartingStepIndex : 0; |
| | 405 | |
|
| 0 | 406 | | PlayTeacherAnimation(TutorialTeacher.TeacherAnimation.Reset); |
| 0 | 407 | | executeStepsCoroutine = CoroutineStarter.Start(StartTutorialFromStep(currentStepIndex)); |
| 0 | 408 | | } |
| | 409 | |
|
| | 410 | | private IEnumerator ExecuteSteps(TutorialPath tutorialPath, int startingStepIndex) |
| | 411 | | { |
| 0 | 412 | | List<TutorialStep> steps = tutorialPath switch |
| | 413 | | { |
| 0 | 414 | | TutorialPath.FromGenesisPlaza => configuration.stepsOnGenesisPlaza, |
| 0 | 415 | | TutorialPath.FromDeepLink => configuration.stepsFromDeepLink, |
| 0 | 416 | | TutorialPath.FromResetTutorial => configuration.stepsFromReset, |
| 0 | 417 | | TutorialPath.FromUserThatAlreadyDidTheTutorial => configuration.stepsFromUser |
| 0 | 418 | | _ => new List<TutorialStep>(), |
| | 419 | | }; |
| | 420 | |
|
| 0 | 421 | | currentPath = tutorialPath; |
| | 422 | |
|
| 0 | 423 | | elapsedTimeInCurrentStep = 0f; |
| | 424 | |
|
| 0 | 425 | | yield return IterateSteps(tutorialPath, startingStepIndex, steps); |
| | 426 | |
|
| 0 | 427 | | if (!configuration.debugRunTutorial && tutorialPath != TutorialPath.FromUserThatAlreadyDidTheTutorial) |
| 0 | 428 | | SetUserTutorialStepAsCompleted(TutorialFinishStep.NewTutorialFinished); |
| | 429 | |
|
| 0 | 430 | | runningStep = null; |
| | 431 | |
|
| 0 | 432 | | SetTutorialDisabled(); |
| 0 | 433 | | } |
| | 434 | |
|
| | 435 | | private IEnumerator IterateSteps(TutorialPath tutorialPath, int startingStepIndex, List<TutorialStep> steps) |
| | 436 | | { |
| 0 | 437 | | for (int stepId = startingStepIndex; stepId < steps.Count; stepId++) |
| | 438 | | { |
| 0 | 439 | | if (nextStepsToSkip > 0) |
| | 440 | | { |
| 0 | 441 | | nextStepsToSkip--; |
| 0 | 442 | | continue; |
| | 443 | | } |
| | 444 | |
|
| 0 | 445 | | TutorialStep stepPrefab = steps[stepId]; |
| | 446 | |
|
| | 447 | | // TODO (Santi): This a TEMPORAL fix. It will be removed when we refactorize the tutorial system in orde |
| 0 | 448 | | if (stepPrefab is TutorialStep_Tooltip_ExploreButton && !exploreV2DataStore.isInitialized.Get()) |
| | 449 | | continue; |
| | 450 | |
|
| 0 | 451 | | yield return RunStep(tutorialPath, stepPrefab, stepId, steps); |
| | 452 | |
|
| 0 | 453 | | if (stepId < steps.Count - 1 && configuration.timeBetweenSteps > 0) |
| 0 | 454 | | yield return new WaitForSeconds(configuration.timeBetweenSteps); |
| | 455 | | } |
| 0 | 456 | | } |
| | 457 | |
|
| | 458 | | private IEnumerator RunStep(TutorialPath tutorialPath, TutorialStep stepPrefab, int stepId, List<TutorialStep> s |
| | 459 | | { |
| 0 | 460 | | runningStep = stepPrefab.letInstantiation ? Object.Instantiate(stepPrefab, tutorialView.transform).GetCompon |
| | 461 | |
|
| 0 | 462 | | runningStep.gameObject.name = runningStep.gameObject.name.Replace("(Clone)", ""); |
| 0 | 463 | | currentStepIndex = stepId; |
| | 464 | |
|
| 0 | 465 | | elapsedTimeInCurrentStep = Time.realtimeSinceStartup; |
| 0 | 466 | | currentStepNumber = stepId + 1; |
| | 467 | |
|
| 0 | 468 | | if (NeedToSendStats()) |
| 0 | 469 | | SendStepStartedSegmentStats(configuration.tutorialVersion, tutorialPath, stepId + 1, runningStep.name); |
| | 470 | |
|
| 0 | 471 | | runningStep.OnStepStart(); |
| 0 | 472 | | yield return runningStep.OnStepExecute(); |
| | 473 | |
|
| 0 | 474 | | PlayTeacherAnimation(animation: stepId < steps.Count - 1 |
| | 475 | | ? TutorialTeacher.TeacherAnimation.StepCompleted |
| | 476 | | : TutorialTeacher.TeacherAnimation.QuickGoodbye); |
| | 477 | |
|
| 0 | 478 | | yield return runningStep.OnStepPlayHideAnimation(); |
| 0 | 479 | | runningStep.OnStepFinished(); |
| 0 | 480 | | elapsedTimeInCurrentStep = Time.realtimeSinceStartup - elapsedTimeInCurrentStep; |
| | 481 | |
|
| 0 | 482 | | if (NeedToSendStats() && tutorialPath != TutorialPath.FromUserThatAlreadyDidTheTutorial) |
| 0 | 483 | | SendStepCompletedSegmentStats(configuration.tutorialVersion, tutorialPath, stepId + 1, runningStep.name, |
| | 484 | |
|
| 0 | 485 | | Object.Destroy(runningStep.gameObject); |
| 0 | 486 | | } |
| | 487 | |
|
| | 488 | | private bool NeedToSendStats() => |
| 0 | 489 | | !configuration.debugRunTutorial && configuration.sendStats; |
| | 490 | |
|
| | 491 | | private static void SetUserTutorialStepAsCompleted(TutorialFinishStep finishStepType) => |
| 0 | 492 | | WebInterface.SaveUserTutorialStep(UserProfile.GetOwnUserProfile().tutorialStep | (int)finishStepType); |
| | 493 | |
|
| | 494 | | internal IEnumerator MoveTeacher(Vector3 toPosition) |
| | 495 | | { |
| 0 | 496 | | if (configuration.teacherRawImage == null) |
| 0 | 497 | | yield break; |
| | 498 | |
|
| 0 | 499 | | var t = 0f; |
| | 500 | |
|
| 0 | 501 | | Vector3 fromPosition = configuration.teacherRawImage.rectTransform.position; |
| | 502 | |
|
| 0 | 503 | | while (Vector3.Distance(configuration.teacherRawImage.rectTransform.position, toPosition) > 0) |
| | 504 | | { |
| 0 | 505 | | t += configuration.teacherMovementSpeed * Time.deltaTime; |
| | 506 | |
|
| 0 | 507 | | configuration.teacherRawImage.rectTransform.position = t <= 1.0f |
| | 508 | | ? Vector3.Lerp(fromPosition, toPosition, configuration.teacherMovementCurve.Evaluate(t)) |
| | 509 | | : toPosition; |
| | 510 | |
|
| 0 | 511 | | yield return null; |
| | 512 | | } |
| 0 | 513 | | } |
| | 514 | |
|
| | 515 | | private void IsSettingsHUDInitialized_OnChange(bool isInitialized, bool _) |
| | 516 | | { |
| 0 | 517 | | if (isInitialized && hudController is { settingsPanelHud: { } }) |
| | 518 | | { |
| 0 | 519 | | hudController.settingsPanelHud.OnRestartTutorial -= OnRestartTutorial; |
| 0 | 520 | | hudController.settingsPanelHud.OnRestartTutorial += OnRestartTutorial; |
| | 521 | | } |
| 0 | 522 | | } |
| | 523 | |
|
| | 524 | | private void OnRestartTutorial() |
| | 525 | | { |
| 0 | 526 | | SetTutorialDisabled(); |
| 0 | 527 | | tutorialReset = true; |
| | 528 | |
|
| 0 | 529 | | SetTutorialEnabled(JsonUtility.ToJson(new TutorialInitializationMessage |
| | 530 | | { |
| | 531 | | fromDeepLink = false.ToString(), |
| | 532 | | enableNewTutorialCamera = false.ToString(), |
| | 533 | | })); |
| 0 | 534 | | } |
| | 535 | |
|
| | 536 | | private static bool IsPlayerInScene() |
| | 537 | | { |
| 0 | 538 | | IWorldState worldState = Environment.i.world.state; |
| | 539 | |
|
| 0 | 540 | | if (worldState == null || worldState.GetCurrentSceneNumber() == null) |
| 0 | 541 | | return false; |
| | 542 | |
|
| 0 | 543 | | return true; |
| | 544 | | } |
| | 545 | |
|
| | 546 | | private static bool IsPlayerInsideGenesisPlaza() |
| | 547 | | { |
| 0 | 548 | | if (Environment.i.world == null) |
| 0 | 549 | | return false; |
| | 550 | |
|
| 0 | 551 | | IWorldState worldState = Environment.i.world.state; |
| | 552 | |
|
| 0 | 553 | | if (worldState == null || worldState.GetCurrentSceneNumber() == null) |
| 0 | 554 | | return false; |
| | 555 | |
|
| 0 | 556 | | var genesisPlazaBaseCoords = new Vector2Int(-9, -9); |
| | 557 | |
|
| 0 | 558 | | IParcelScene currentScene = worldState.GetScene(worldState.GetCurrentSceneNumber()); |
| | 559 | |
|
| 0 | 560 | | return currentScene != null && currentScene.IsInsideSceneBoundaries(genesisPlazaBaseCoords); |
| | 561 | | } |
| | 562 | |
|
| | 563 | | private static void SendStepStartedSegmentStats(int version, TutorialPath tutorialPath, int stepNumber, string s |
| | 564 | | { |
| 0 | 565 | | WebInterface.AnalyticsPayload.Property[] properties = |
| | 566 | | { |
| | 567 | | new ("version", version.ToString()), |
| | 568 | | new ("path", tutorialPath.ToString()), |
| | 569 | | new ("step number", stepNumber.ToString()), |
| | 570 | | new ("step name", StepNameForStatsMessage(stepName)), |
| | 571 | | }; |
| | 572 | |
|
| 0 | 573 | | WebInterface.ReportAnalyticsEvent("tutorial step started", properties); |
| 0 | 574 | | } |
| | 575 | |
|
| | 576 | | private static void SendStepCompletedSegmentStats(int version, TutorialPath tutorialPath, int stepNumber, string |
| | 577 | | { |
| 0 | 578 | | WebInterface.AnalyticsPayload.Property[] properties = |
| | 579 | | { |
| | 580 | | new ("version", version.ToString()), |
| | 581 | | new ("path", tutorialPath.ToString()), |
| | 582 | | new ("step number", stepNumber.ToString()), |
| | 583 | | new ("step name", StepNameForStatsMessage(stepName)), |
| | 584 | | new ("elapsed time", elapsedTime.ToString("0.00")), |
| | 585 | | }; |
| | 586 | |
|
| 0 | 587 | | WebInterface.ReportAnalyticsEvent("tutorial step completed", properties); |
| 0 | 588 | | } |
| | 589 | |
|
| | 590 | | private void SendSkipTutorialSegmentStats(int version, string stepName) |
| | 591 | | { |
| 0 | 592 | | WebInterface.AnalyticsPayload.Property[] properties = |
| | 593 | | { |
| | 594 | | new ("version", version.ToString()), |
| | 595 | | new ("path", currentPath.ToString()), |
| | 596 | | new ("step number", currentStepNumber.ToString()), |
| | 597 | | new ("step name", StepNameForStatsMessage(stepName)), |
| | 598 | | new ("elapsed time", (Time.realtimeSinceStartup - elapsedTimeInCurrentStep).ToString("0.00")), |
| | 599 | | }; |
| | 600 | |
|
| 0 | 601 | | WebInterface.ReportAnalyticsEvent("tutorial skipped", properties); |
| 0 | 602 | | } |
| | 603 | |
|
| | 604 | | private static string StepNameForStatsMessage(string stepName) => |
| 0 | 605 | | stepName.Replace("(Clone)", "").Replace("TutorialStep_", ""); |
| | 606 | |
|
| | 607 | | internal IEnumerator EagleEyeCameraRotation(float rotationSpeed) |
| | 608 | | { |
| 0 | 609 | | while (true) |
| | 610 | | { |
| 0 | 611 | | configuration.eagleEyeCamera.transform.Rotate(Vector3.up * Time.deltaTime * rotationSpeed, Space.World); |
| 0 | 612 | | yield return null; |
| | 613 | | } |
| | 614 | | } |
| | 615 | |
|
| | 616 | | private IEnumerator BlockPlayerCameraUntilBlendingIsFinished(bool hideUIs) |
| | 617 | | { |
| 0 | 618 | | if (hideUIs) |
| 0 | 619 | | SetHudVisibility(false); |
| | 620 | |
|
| 0 | 621 | | CommonScriptableObjects.cameraBlocked.Set(true); |
| | 622 | |
|
| 0 | 623 | | yield return null; |
| 0 | 624 | | yield return new WaitUntil(() => !CommonScriptableObjects.cameraIsBlending.Get()); |
| | 625 | |
|
| 0 | 626 | | CommonScriptableObjects.cameraBlocked.Set(false); |
| | 627 | |
|
| 0 | 628 | | if (!hideUIs) |
| 0 | 629 | | SetHudVisibility(true); |
| | 630 | |
|
| | 631 | | void SetHudVisibility(bool isVisible) |
| | 632 | | { |
| 0 | 633 | | hudController?.minimapHud?.SetVisibility(isVisible); |
| 0 | 634 | | hudController?.profileHud?.SetVisibility(isVisible); |
| 0 | 635 | | } |
| 0 | 636 | | } |
| | 637 | | } |
| | 638 | | } |