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