| | 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 | | if (!CommonScriptableObjects.rendererState.Get()) |
| 0 | 174 | | CommonScriptableObjects.rendererState.OnChange += OnRenderingStateChanged; |
| | 175 | | else |
| 0 | 176 | | OnRenderingStateChanged(true, false); |
| | 177 | |
|
| 0 | 178 | | OnTutorialEnabled?.Invoke(); |
| 0 | 179 | | } |
| | 180 | |
|
| | 181 | | /// <summary> |
| | 182 | | /// Stop and disables the tutorial controller. |
| | 183 | | /// </summary> |
| | 184 | | public void SetTutorialDisabled() |
| | 185 | | { |
| 0 | 186 | | CommonScriptableObjects.featureKeyTriggersBlocked.Set(false); |
| | 187 | |
|
| 0 | 188 | | if (executeStepsCoroutine != null) |
| | 189 | | { |
| 0 | 190 | | CoroutineStarter.Stop(executeStepsCoroutine); |
| 0 | 191 | | executeStepsCoroutine = null; |
| | 192 | | } |
| | 193 | |
|
| 0 | 194 | | if (runningStep != null) |
| | 195 | | { |
| 0 | 196 | | Object.Destroy(runningStep.gameObject); |
| 0 | 197 | | runningStep = null; |
| | 198 | | } |
| | 199 | |
|
| 0 | 200 | | if (teacherMovementCoroutine != null) |
| | 201 | | { |
| 0 | 202 | | CoroutineStarter.Stop(teacherMovementCoroutine); |
| 0 | 203 | | teacherMovementCoroutine = null; |
| | 204 | | } |
| | 205 | |
|
| 0 | 206 | | tutorialReset = false; |
| 0 | 207 | | commonDataStore.isTutorialRunning.Set(false); |
| 0 | 208 | | tutorialView.tutorialMusicHandler.StopTutorialMusic(); |
| 0 | 209 | | ShowTeacher3DModel(false); |
| | 210 | |
|
| 0 | 211 | | if (Environment.i is { world: { } }) |
| 0 | 212 | | WebInterface.SendSceneExternalActionEvent(Environment.i.world.state.GetCurrentSceneNumber(), "tutorial", |
| | 213 | |
|
| 0 | 214 | | NotificationsController.disableWelcomeNotification = false; |
| | 215 | |
|
| 0 | 216 | | hudController?.settingsPanelHud?.SetTutorialButtonEnabled(true); |
| | 217 | |
|
| 0 | 218 | | CommonScriptableObjects.tutorialActive.Set(false); |
| | 219 | |
|
| 0 | 220 | | CommonScriptableObjects.rendererState.OnChange -= OnRenderingStateChanged; |
| | 221 | |
|
| 0 | 222 | | OnTutorialDisabled?.Invoke(); |
| 0 | 223 | | } |
| | 224 | |
|
| | 225 | | /// <summary> |
| | 226 | | /// Starts to execute the tutorial from a specific step (It is needed to call SetTutorialEnabled() before). |
| | 227 | | /// </summary> |
| | 228 | | /// <param name="stepIndex">First step to be executed.</param> |
| | 229 | | internal IEnumerator StartTutorialFromStep(int stepIndex) |
| | 230 | | { |
| 0 | 231 | | if (!commonDataStore.isTutorialRunning.Get()) |
| 0 | 232 | | yield break; |
| | 233 | |
|
| 0 | 234 | | if (runningStep != null) |
| | 235 | | { |
| 0 | 236 | | runningStep.OnStepFinished(); |
| 0 | 237 | | Object.Destroy(runningStep.gameObject); |
| 0 | 238 | | runningStep = null; |
| | 239 | | } |
| | 240 | |
|
| 0 | 241 | | yield return new WaitUntil(IsPlayerInScene); |
| | 242 | |
|
| 0 | 243 | | playerIsInGenesisPlaza = IsPlayerInsideGenesisPlaza(); |
| | 244 | |
|
| 0 | 245 | | if (playerIsInGenesisPlaza) |
| 0 | 246 | | tutorialView.tutorialMusicHandler.TryPlayingMusic(); |
| | 247 | |
|
| 0 | 248 | | yield return ExecuteRespectiveTutorialStep(stepIndex); |
| 0 | 249 | | } |
| | 250 | |
|
| | 251 | | private IEnumerator ExecuteRespectiveTutorialStep(int stepIndex) |
| | 252 | | { |
| 0 | 253 | | if (userAlreadyDidTheTutorial) |
| 0 | 254 | | yield return ExecuteSteps(TutorialPath.FromUserThatAlreadyDidTheTutorial, stepIndex); |
| 0 | 255 | | else if (tutorialReset) |
| 0 | 256 | | yield return ExecuteSteps(TutorialPath.FromResetTutorial, stepIndex); |
| 0 | 257 | | else if (playerIsInGenesisPlaza) |
| 0 | 258 | | yield return ExecuteSteps(TutorialPath.FromGenesisPlaza, stepIndex); |
| 0 | 259 | | else if (openedFromDeepLink) |
| 0 | 260 | | yield return ExecuteSteps(TutorialPath.FromDeepLink, stepIndex); |
| | 261 | | else |
| 0 | 262 | | SetTutorialDisabled(); |
| 0 | 263 | | } |
| | 264 | |
|
| | 265 | | /// <summary> |
| | 266 | | /// Shows the teacher that will be guiding along the tutorial. |
| | 267 | | /// </summary> |
| | 268 | | /// <param name="active">True for show the teacher.</param> |
| | 269 | | public void ShowTeacher3DModel(bool active) |
| | 270 | | { |
| 0 | 271 | | if (configuration.teacherCamera != null) |
| 0 | 272 | | configuration.teacherCamera.enabled = active; |
| | 273 | |
|
| 0 | 274 | | if (configuration.teacherRawImage != null) |
| 0 | 275 | | configuration.teacherRawImage.gameObject.SetActive(active); |
| 0 | 276 | | } |
| | 277 | |
|
| | 278 | | /// <summary> |
| | 279 | | /// Move the tutorial teacher to a specific position. |
| | 280 | | /// </summary> |
| | 281 | | /// <param name="destinationPosition">Target position.</param> |
| | 282 | | /// <param name="animated">True for apply a smooth movement.</param> |
| | 283 | | public void SetTeacherPosition(Vector3 destinationPosition, bool animated = true) |
| | 284 | | { |
| 0 | 285 | | if (teacherMovementCoroutine != null) |
| 0 | 286 | | CoroutineStarter.Stop(teacherMovementCoroutine); |
| | 287 | |
|
| 0 | 288 | | if (configuration.teacherRawImage != null) |
| | 289 | | { |
| 0 | 290 | | if (animated) |
| 0 | 291 | | teacherMovementCoroutine = CoroutineStarter.Start(MoveTeacher(destinationPosition)); |
| | 292 | | else |
| 0 | 293 | | configuration.teacherRawImage.rectTransform.position = new Vector3(destinationPosition.x, destinatio |
| | 294 | | } |
| 0 | 295 | | } |
| | 296 | |
|
| | 297 | | /// <summary> |
| | 298 | | /// Plays a specific animation on the tutorial teacher. |
| | 299 | | /// </summary> |
| | 300 | | /// <param name="animation">Animation to apply.</param> |
| | 301 | | public void PlayTeacherAnimation(TutorialTeacher.TeacherAnimation animation) |
| | 302 | | { |
| 0 | 303 | | if (configuration.teacher == null) |
| 0 | 304 | | return; |
| | 305 | |
|
| 0 | 306 | | configuration.teacher.PlayAnimation(animation); |
| 0 | 307 | | } |
| | 308 | |
|
| | 309 | | /// <summary> |
| | 310 | | /// Set sort order for canvas containing teacher RawImage |
| | 311 | | /// </summary> |
| | 312 | | /// <param name="sortOrder"></param> |
| | 313 | | public void SetTeacherCanvasSortingOrder(int sortOrder) |
| | 314 | | { |
| 0 | 315 | | if (configuration.teacherCanvas == null) |
| 0 | 316 | | return; |
| | 317 | |
|
| 0 | 318 | | configuration.teacherCanvas.sortingOrder = sortOrder; |
| 0 | 319 | | } |
| | 320 | |
|
| | 321 | | /// <summary> |
| | 322 | | /// Finishes the current running step, skips all the next ones and completes the tutorial. |
| | 323 | | /// </summary> |
| | 324 | | public void SkipTutorial(bool ignoreStatsSending = false) |
| | 325 | | { |
| 0 | 326 | | if (!ignoreStatsSending && NeedToSendStats()) |
| 0 | 327 | | SendSkipTutorialSegmentStats(configuration.tutorialVersion, runningStep.name); |
| | 328 | |
|
| 0 | 329 | | int skipIndex = configuration.stepsOnGenesisPlaza.Count + |
| | 330 | | configuration.stepsFromDeepLink.Count + |
| | 331 | | configuration.stepsFromReset.Count + |
| | 332 | | configuration.stepsFromUserThatAlreadyDidTheTutorial.Count; |
| | 333 | |
|
| 0 | 334 | | CoroutineStarter.Start(StartTutorialFromStep(skipIndex)); |
| | 335 | |
|
| 0 | 336 | | hudController?.taskbarHud?.SetVisibility(true); |
| 0 | 337 | | } |
| | 338 | |
|
| | 339 | | /// <summary> |
| | 340 | | /// Jump to a specific step. |
| | 341 | | /// </summary> |
| | 342 | | /// <param name="stepName">Step to jump.</param> |
| | 343 | | public void GoToSpecificStep(string stepName) |
| | 344 | | { |
| | 345 | | int stepIndex; |
| | 346 | |
|
| 0 | 347 | | if (userAlreadyDidTheTutorial) |
| 0 | 348 | | stepIndex = configuration.stepsFromUserThatAlreadyDidTheTutorial.FindIndex(x => x.name == stepName); |
| 0 | 349 | | else if (tutorialReset) |
| 0 | 350 | | stepIndex = configuration.stepsFromReset.FindIndex(x => x.name == stepName); |
| 0 | 351 | | else if (playerIsInGenesisPlaza) |
| 0 | 352 | | stepIndex = configuration.stepsOnGenesisPlaza.FindIndex(x => x.name == stepName); |
| 0 | 353 | | else if (openedFromDeepLink) |
| 0 | 354 | | stepIndex = configuration.stepsFromDeepLink.FindIndex(x => x.name == stepName); |
| | 355 | | else |
| 0 | 356 | | stepIndex = 0; |
| | 357 | |
|
| 0 | 358 | | nextStepsToSkip = 0; |
| | 359 | |
|
| 0 | 360 | | if (stepIndex >= 0) |
| 0 | 361 | | CoroutineStarter.Start(StartTutorialFromStep(stepIndex)); |
| | 362 | | else |
| 0 | 363 | | SkipTutorial(true); |
| 0 | 364 | | } |
| | 365 | |
|
| | 366 | | /// <summary> |
| | 367 | | /// Set the number of steps that will be skipped in the next iteration. |
| | 368 | | /// </summary> |
| | 369 | | /// <param name="skippedSteps">Number of steps to skip.</param> |
| | 370 | | public void SetNextSkippedSteps(int skippedSteps) => |
| 0 | 371 | | nextStepsToSkip = skippedSteps; |
| | 372 | |
|
| | 373 | | /// <summary> |
| | 374 | | /// Activate/deactivate the eagle eye camera. |
| | 375 | | /// </summary> |
| | 376 | | /// <param name="isActive">True for activate the eagle eye camera.</param> |
| | 377 | | public void SetEagleEyeCameraActive(bool isActive) |
| | 378 | | { |
| 0 | 379 | | configuration.eagleEyeCamera.gameObject.SetActive(isActive); |
| 0 | 380 | | CoroutineStarter.Start(BlockPlayerCameraUntilBlendingIsFinished(isActive)); |
| | 381 | |
|
| 0 | 382 | | if (isActive) |
| | 383 | | { |
| 0 | 384 | | configuration.eagleEyeCamera.transform.position = configuration.eagleCamInitPosition; |
| 0 | 385 | | configuration.eagleEyeCamera.transform.LookAt(configuration.eagleCamInitLookAtPoint); |
| | 386 | |
|
| 0 | 387 | | if (configuration.eagleCamRotationActived) |
| 0 | 388 | | eagleEyeRotationCoroutine = CoroutineStarter.Start(EagleEyeCameraRotation(configuration.eagleCamRota |
| | 389 | | } |
| 0 | 390 | | else if (eagleEyeRotationCoroutine != null) |
| 0 | 391 | | CoroutineStarter.Stop(eagleEyeRotationCoroutine); |
| 0 | 392 | | } |
| | 393 | |
|
| | 394 | | internal void OnRenderingStateChanged(bool renderingEnabled, bool prevState) |
| | 395 | | { |
| 0 | 396 | | if (!renderingEnabled) |
| 0 | 397 | | return; |
| | 398 | |
|
| 0 | 399 | | CommonScriptableObjects.rendererState.OnChange -= OnRenderingStateChanged; |
| | 400 | |
|
| 0 | 401 | | currentStepIndex = configuration.debugRunTutorial ? configuration.debugStartingStepIndex : 0; |
| | 402 | |
|
| 0 | 403 | | PlayTeacherAnimation(TutorialTeacher.TeacherAnimation.Reset); |
| 0 | 404 | | executeStepsCoroutine = CoroutineStarter.Start(StartTutorialFromStep(currentStepIndex)); |
| 0 | 405 | | } |
| | 406 | |
|
| | 407 | | private IEnumerator ExecuteSteps(TutorialPath tutorialPath, int startingStepIndex) |
| | 408 | | { |
| 0 | 409 | | List<TutorialStep> steps = tutorialPath switch |
| | 410 | | { |
| 0 | 411 | | TutorialPath.FromGenesisPlaza => configuration.stepsOnGenesisPlaza, |
| 0 | 412 | | TutorialPath.FromDeepLink => configuration.stepsFromDeepLink, |
| 0 | 413 | | TutorialPath.FromResetTutorial => configuration.stepsFromReset, |
| 0 | 414 | | TutorialPath.FromUserThatAlreadyDidTheTutorial => configuration.stepsFromUser |
| 0 | 415 | | _ => new List<TutorialStep>(), |
| | 416 | | }; |
| | 417 | |
|
| 0 | 418 | | currentPath = tutorialPath; |
| | 419 | |
|
| 0 | 420 | | elapsedTimeInCurrentStep = 0f; |
| | 421 | |
|
| 0 | 422 | | yield return IterateSteps(tutorialPath, startingStepIndex, steps); |
| | 423 | |
|
| 0 | 424 | | if (!configuration.debugRunTutorial && tutorialPath != TutorialPath.FromUserThatAlreadyDidTheTutorial) |
| 0 | 425 | | SetUserTutorialStepAsCompleted(TutorialFinishStep.NewTutorialFinished); |
| | 426 | |
|
| 0 | 427 | | runningStep = null; |
| | 428 | |
|
| 0 | 429 | | SetTutorialDisabled(); |
| 0 | 430 | | } |
| | 431 | |
|
| | 432 | | private IEnumerator IterateSteps(TutorialPath tutorialPath, int startingStepIndex, List<TutorialStep> steps) |
| | 433 | | { |
| 0 | 434 | | for (int stepId = startingStepIndex; stepId < steps.Count; stepId++) |
| | 435 | | { |
| 0 | 436 | | if (nextStepsToSkip > 0) |
| | 437 | | { |
| 0 | 438 | | nextStepsToSkip--; |
| 0 | 439 | | continue; |
| | 440 | | } |
| | 441 | |
|
| 0 | 442 | | TutorialStep stepPrefab = steps[stepId]; |
| | 443 | |
|
| | 444 | | // TODO (Santi): This a TEMPORAL fix. It will be removed when we refactorize the tutorial system in orde |
| 0 | 445 | | if (stepPrefab is TutorialStep_Tooltip_ExploreButton && !exploreV2DataStore.isInitialized.Get()) |
| | 446 | | continue; |
| | 447 | |
|
| 0 | 448 | | yield return RunStep(tutorialPath, stepPrefab, stepId, steps); |
| | 449 | |
|
| 0 | 450 | | if (stepId < steps.Count - 1 && configuration.timeBetweenSteps > 0) |
| 0 | 451 | | yield return new WaitForSeconds(configuration.timeBetweenSteps); |
| | 452 | | } |
| 0 | 453 | | } |
| | 454 | |
|
| | 455 | | private IEnumerator RunStep(TutorialPath tutorialPath, TutorialStep stepPrefab, int stepId, List<TutorialStep> s |
| | 456 | | { |
| 0 | 457 | | runningStep = stepPrefab.letInstantiation ? Object.Instantiate(stepPrefab, tutorialView.transform).GetCompon |
| | 458 | |
|
| 0 | 459 | | runningStep.gameObject.name = runningStep.gameObject.name.Replace("(Clone)", ""); |
| 0 | 460 | | currentStepIndex = stepId; |
| | 461 | |
|
| 0 | 462 | | elapsedTimeInCurrentStep = Time.realtimeSinceStartup; |
| 0 | 463 | | currentStepNumber = stepId + 1; |
| | 464 | |
|
| 0 | 465 | | if (NeedToSendStats()) |
| 0 | 466 | | SendStepStartedSegmentStats(configuration.tutorialVersion, tutorialPath, stepId + 1, runningStep.name); |
| | 467 | |
|
| 0 | 468 | | runningStep.OnStepStart(); |
| 0 | 469 | | yield return runningStep.OnStepExecute(); |
| | 470 | |
|
| 0 | 471 | | PlayTeacherAnimation(animation: stepId < steps.Count - 1 |
| | 472 | | ? TutorialTeacher.TeacherAnimation.StepCompleted |
| | 473 | | : TutorialTeacher.TeacherAnimation.QuickGoodbye); |
| | 474 | |
|
| 0 | 475 | | yield return runningStep.OnStepPlayHideAnimation(); |
| 0 | 476 | | runningStep.OnStepFinished(); |
| 0 | 477 | | elapsedTimeInCurrentStep = Time.realtimeSinceStartup - elapsedTimeInCurrentStep; |
| | 478 | |
|
| 0 | 479 | | if (NeedToSendStats() && tutorialPath != TutorialPath.FromUserThatAlreadyDidTheTutorial) |
| 0 | 480 | | SendStepCompletedSegmentStats(configuration.tutorialVersion, tutorialPath, stepId + 1, runningStep.name, |
| | 481 | |
|
| 0 | 482 | | Object.Destroy(runningStep.gameObject); |
| 0 | 483 | | } |
| | 484 | |
|
| | 485 | | private bool NeedToSendStats() => |
| 0 | 486 | | !configuration.debugRunTutorial && configuration.sendStats; |
| | 487 | |
|
| | 488 | | private static void SetUserTutorialStepAsCompleted(TutorialFinishStep finishStepType) => |
| 0 | 489 | | WebInterface.SaveUserTutorialStep(UserProfile.GetOwnUserProfile().tutorialStep | (int)finishStepType); |
| | 490 | |
|
| | 491 | | internal IEnumerator MoveTeacher(Vector3 toPosition) |
| | 492 | | { |
| 0 | 493 | | if (configuration.teacherRawImage == null) |
| 0 | 494 | | yield break; |
| | 495 | |
|
| 0 | 496 | | var t = 0f; |
| | 497 | |
|
| 0 | 498 | | Vector3 fromPosition = configuration.teacherRawImage.rectTransform.position; |
| | 499 | |
|
| 0 | 500 | | while (Vector3.Distance(configuration.teacherRawImage.rectTransform.position, toPosition) > 0) |
| | 501 | | { |
| 0 | 502 | | t += configuration.teacherMovementSpeed * Time.deltaTime; |
| | 503 | |
|
| 0 | 504 | | configuration.teacherRawImage.rectTransform.position = t <= 1.0f |
| | 505 | | ? Vector3.Lerp(fromPosition, toPosition, configuration.teacherMovementCurve.Evaluate(t)) |
| | 506 | | : toPosition; |
| | 507 | |
|
| 0 | 508 | | yield return null; |
| | 509 | | } |
| 0 | 510 | | } |
| | 511 | |
|
| | 512 | | private void IsSettingsHUDInitialized_OnChange(bool isInitialized, bool _) |
| | 513 | | { |
| 0 | 514 | | if (isInitialized && hudController is { settingsPanelHud: { } }) |
| | 515 | | { |
| 0 | 516 | | hudController.settingsPanelHud.OnRestartTutorial -= OnRestartTutorial; |
| 0 | 517 | | hudController.settingsPanelHud.OnRestartTutorial += OnRestartTutorial; |
| | 518 | | } |
| 0 | 519 | | } |
| | 520 | |
|
| | 521 | | private void OnRestartTutorial() |
| | 522 | | { |
| 0 | 523 | | SetTutorialDisabled(); |
| 0 | 524 | | tutorialReset = true; |
| | 525 | |
|
| 0 | 526 | | SetTutorialEnabled(JsonUtility.ToJson(new TutorialInitializationMessage |
| | 527 | | { |
| | 528 | | fromDeepLink = false.ToString(), |
| | 529 | | enableNewTutorialCamera = false.ToString(), |
| | 530 | | })); |
| 0 | 531 | | } |
| | 532 | |
|
| | 533 | | private static bool IsPlayerInScene() |
| | 534 | | { |
| 0 | 535 | | IWorldState worldState = Environment.i.world.state; |
| | 536 | |
|
| 0 | 537 | | if (worldState == null || worldState.GetCurrentSceneNumber() == null) |
| 0 | 538 | | return false; |
| | 539 | |
|
| 0 | 540 | | return true; |
| | 541 | | } |
| | 542 | |
|
| | 543 | | private static bool IsPlayerInsideGenesisPlaza() |
| | 544 | | { |
| 0 | 545 | | if (Environment.i.world == null) |
| 0 | 546 | | return false; |
| | 547 | |
|
| 0 | 548 | | IWorldState worldState = Environment.i.world.state; |
| | 549 | |
|
| 0 | 550 | | if (worldState == null || worldState.GetCurrentSceneNumber() == null) |
| 0 | 551 | | return false; |
| | 552 | |
|
| 0 | 553 | | var genesisPlazaBaseCoords = new Vector2Int(-9, -9); |
| | 554 | |
|
| 0 | 555 | | IParcelScene currentScene = worldState.GetScene(worldState.GetCurrentSceneNumber()); |
| | 556 | |
|
| 0 | 557 | | return currentScene != null && currentScene.IsInsideSceneBoundaries(genesisPlazaBaseCoords); |
| | 558 | | } |
| | 559 | |
|
| | 560 | | private static void SendStepStartedSegmentStats(int version, TutorialPath tutorialPath, int stepNumber, string s |
| | 561 | | { |
| 0 | 562 | | WebInterface.AnalyticsPayload.Property[] properties = |
| | 563 | | { |
| | 564 | | new ("version", version.ToString()), |
| | 565 | | new ("path", tutorialPath.ToString()), |
| | 566 | | new ("step number", stepNumber.ToString()), |
| | 567 | | new ("step name", StepNameForStatsMessage(stepName)), |
| | 568 | | }; |
| | 569 | |
|
| 0 | 570 | | WebInterface.ReportAnalyticsEvent("tutorial step started", properties); |
| 0 | 571 | | } |
| | 572 | |
|
| | 573 | | private static void SendStepCompletedSegmentStats(int version, TutorialPath tutorialPath, int stepNumber, string |
| | 574 | | { |
| 0 | 575 | | WebInterface.AnalyticsPayload.Property[] properties = |
| | 576 | | { |
| | 577 | | new ("version", version.ToString()), |
| | 578 | | new ("path", tutorialPath.ToString()), |
| | 579 | | new ("step number", stepNumber.ToString()), |
| | 580 | | new ("step name", StepNameForStatsMessage(stepName)), |
| | 581 | | new ("elapsed time", elapsedTime.ToString("0.00")), |
| | 582 | | }; |
| | 583 | |
|
| 0 | 584 | | WebInterface.ReportAnalyticsEvent("tutorial step completed", properties); |
| 0 | 585 | | } |
| | 586 | |
|
| | 587 | | private void SendSkipTutorialSegmentStats(int version, string stepName) |
| | 588 | | { |
| 0 | 589 | | WebInterface.AnalyticsPayload.Property[] properties = |
| | 590 | | { |
| | 591 | | new ("version", version.ToString()), |
| | 592 | | new ("path", currentPath.ToString()), |
| | 593 | | new ("step number", currentStepNumber.ToString()), |
| | 594 | | new ("step name", StepNameForStatsMessage(stepName)), |
| | 595 | | new ("elapsed time", (Time.realtimeSinceStartup - elapsedTimeInCurrentStep).ToString("0.00")), |
| | 596 | | }; |
| | 597 | |
|
| 0 | 598 | | WebInterface.ReportAnalyticsEvent("tutorial skipped", properties); |
| 0 | 599 | | } |
| | 600 | |
|
| | 601 | | private static string StepNameForStatsMessage(string stepName) => |
| 0 | 602 | | stepName.Replace("(Clone)", "").Replace("TutorialStep_", ""); |
| | 603 | |
|
| | 604 | | internal IEnumerator EagleEyeCameraRotation(float rotationSpeed) |
| | 605 | | { |
| 0 | 606 | | while (true) |
| | 607 | | { |
| 0 | 608 | | configuration.eagleEyeCamera.transform.Rotate(Vector3.up * Time.deltaTime * rotationSpeed, Space.World); |
| 0 | 609 | | yield return null; |
| | 610 | | } |
| | 611 | | } |
| | 612 | |
|
| | 613 | | private IEnumerator BlockPlayerCameraUntilBlendingIsFinished(bool hideUIs) |
| | 614 | | { |
| 0 | 615 | | if (hideUIs) |
| 0 | 616 | | SetHudVisibility(false); |
| | 617 | |
|
| 0 | 618 | | CommonScriptableObjects.cameraBlocked.Set(true); |
| | 619 | |
|
| 0 | 620 | | yield return null; |
| 0 | 621 | | yield return new WaitUntil(() => !CommonScriptableObjects.cameraIsBlending.Get()); |
| | 622 | |
|
| 0 | 623 | | CommonScriptableObjects.cameraBlocked.Set(false); |
| | 624 | |
|
| 0 | 625 | | if (!hideUIs) |
| 0 | 626 | | SetHudVisibility(true); |
| | 627 | |
|
| | 628 | | void SetHudVisibility(bool isVisible) |
| | 629 | | { |
| 0 | 630 | | hudController?.minimapHud?.SetVisibility(isVisible); |
| 0 | 631 | | hudController?.profileHud?.SetVisibility(isVisible); |
| 0 | 632 | | } |
| 0 | 633 | | } |
| | 634 | | } |
| | 635 | | } |