| | 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 | | switch (tutorialType) |
| | 247 | | { |
| | 248 | | case TutorialType.Initial: |
| 23 | 249 | | if (userAlreadyDidTheTutorial) |
| | 250 | | { |
| 2 | 251 | | yield return ExecuteSteps(TutorialPath.FromUserThatAlreadyDidTheTutorial, stepIndex); |
| 2 | 252 | | } |
| 21 | 253 | | else if (playerIsInGenesisPlaza || tutorialReset) |
| | 254 | | { |
| 19 | 255 | | if (tutorialReset) |
| | 256 | | { |
| 2 | 257 | | yield return ExecuteSteps(TutorialPath.FromResetTutorial, stepIndex); |
| 2 | 258 | | } |
| | 259 | | else |
| | 260 | | { |
| 17 | 261 | | yield return ExecuteSteps(TutorialPath.FromGenesisPlaza, stepIndex); |
| | 262 | | } |
| 17 | 263 | | } |
| 2 | 264 | | else if (openedFromDeepLink) |
| | 265 | | { |
| 2 | 266 | | yield return ExecuteSteps(TutorialPath.FromDeepLink, stepIndex); |
| 2 | 267 | | } |
| | 268 | | else |
| | 269 | | { |
| 0 | 270 | | SetTutorialDisabled(); |
| 0 | 271 | | yield break; |
| | 272 | | } |
| | 273 | |
|
| | 274 | | break; |
| | 275 | | case TutorialType.BuilderInWorld: |
| 2 | 276 | | yield return ExecuteSteps(TutorialPath.FromBuilderInWorld, stepIndex); |
| | 277 | | break; |
| | 278 | | } |
| 25 | 279 | | } |
| | 280 | |
|
| | 281 | | /// <summary> |
| | 282 | | /// Shows the teacher that will be guiding along the tutorial. |
| | 283 | | /// </summary> |
| | 284 | | /// <param name="active">True for show the teacher.</param> |
| | 285 | | public void ShowTeacher3DModel(bool active) |
| | 286 | | { |
| 160 | 287 | | if (configuration.teacherCamera != null) |
| 160 | 288 | | configuration.teacherCamera.enabled = active; |
| | 289 | |
|
| 160 | 290 | | if (configuration.teacherRawImage != null) |
| 115 | 291 | | configuration.teacherRawImage.gameObject.SetActive(active); |
| 160 | 292 | | } |
| | 293 | |
|
| | 294 | | /// <summary> |
| | 295 | | /// Move the tutorial teacher to a specific position. |
| | 296 | | /// </summary> |
| | 297 | | /// <param name="position">Target position.</param> |
| | 298 | | /// <param name="animated">True for apply a smooth movement.</param> |
| | 299 | | public void SetTeacherPosition(Vector2 position, bool animated = true) |
| | 300 | | { |
| 22 | 301 | | if (teacherMovementCoroutine != null) |
| 0 | 302 | | CoroutineStarter.Stop(teacherMovementCoroutine); |
| | 303 | |
|
| 22 | 304 | | if (configuration.teacherRawImage != null) |
| | 305 | | { |
| 2 | 306 | | if (animated) |
| 0 | 307 | | teacherMovementCoroutine = CoroutineStarter.Start(MoveTeacher(configuration.teacherRawImage.rectTran |
| | 308 | | else |
| 2 | 309 | | configuration.teacherRawImage.rectTransform.position = position; |
| | 310 | | } |
| 22 | 311 | | } |
| | 312 | |
|
| | 313 | | /// <summary> |
| | 314 | | /// Plays a specific animation on the tutorial teacher. |
| | 315 | | /// </summary> |
| | 316 | | /// <param name="animation">Animation to apply.</param> |
| | 317 | | public void PlayTeacherAnimation(TutorialTeacher.TeacherAnimation animation) |
| | 318 | | { |
| 44 | 319 | | if (configuration.teacher == null) |
| 17 | 320 | | return; |
| | 321 | |
|
| 27 | 322 | | configuration.teacher.PlayAnimation(animation); |
| 27 | 323 | | } |
| | 324 | |
|
| | 325 | | /// <summary> |
| | 326 | | /// Set sort order for canvas containing teacher RawImage |
| | 327 | | /// </summary> |
| | 328 | | /// <param name="sortOrder"></param> |
| | 329 | | public void SetTeacherCanvasSortingOrder(int sortOrder) |
| | 330 | | { |
| 14 | 331 | | if (configuration.teacherCanvas == null) |
| 0 | 332 | | return; |
| | 333 | |
|
| 14 | 334 | | configuration.teacherCanvas.sortingOrder = sortOrder; |
| 14 | 335 | | } |
| | 336 | |
|
| | 337 | | /// <summary> |
| | 338 | | /// Finishes the current running step, skips all the next ones and completes the tutorial. |
| | 339 | | /// </summary> |
| | 340 | | public void SkipTutorial(bool ignoreStatsSending = false) |
| | 341 | | { |
| 5 | 342 | | if (!ignoreStatsSending && !configuration.debugRunTutorial && configuration.sendStats) |
| | 343 | | { |
| 0 | 344 | | SendSkipTutorialSegmentStats( |
| | 345 | | configuration.tutorialVersion, |
| | 346 | | runningStep.name.Replace("(Clone)", "").Replace("TutorialStep_", "")); |
| | 347 | | } |
| | 348 | |
|
| 5 | 349 | | int skipIndex = configuration.stepsOnGenesisPlaza.Count + |
| | 350 | | configuration.stepsFromDeepLink.Count + |
| | 351 | | configuration.stepsFromReset.Count + |
| | 352 | | configuration.stepsFromBuilderInWorld.Count + |
| | 353 | | configuration.stepsFromUserThatAlreadyDidTheTutorial.Count; |
| | 354 | |
|
| 5 | 355 | | CoroutineStarter.Start(StartTutorialFromStep(skipIndex)); |
| | 356 | |
|
| 5 | 357 | | hudController?.taskbarHud?.SetVisibility(true); |
| 0 | 358 | | } |
| | 359 | |
|
| | 360 | | /// <summary> |
| | 361 | | /// Jump to a specific step. |
| | 362 | | /// </summary> |
| | 363 | | /// <param name="stepIndex">Step to jump.</param> |
| | 364 | | public void GoToSpecificStep(string stepName) |
| | 365 | | { |
| 0 | 366 | | int stepIndex = 0; |
| 0 | 367 | | switch (tutorialType) |
| | 368 | | { |
| | 369 | | case TutorialType.Initial: |
| 0 | 370 | | if (userAlreadyDidTheTutorial) |
| | 371 | | { |
| 0 | 372 | | stepIndex = configuration.stepsFromUserThatAlreadyDidTheTutorial.FindIndex(x => x.name == stepNa |
| 0 | 373 | | } |
| 0 | 374 | | else if (playerIsInGenesisPlaza || tutorialReset) |
| | 375 | | { |
| 0 | 376 | | if (tutorialReset) |
| | 377 | | { |
| 0 | 378 | | stepIndex = configuration.stepsFromReset.FindIndex(x => x.name == stepName); |
| 0 | 379 | | } |
| | 380 | | else |
| | 381 | | { |
| 0 | 382 | | stepIndex = configuration.stepsOnGenesisPlaza.FindIndex(x => x.name == stepName); |
| | 383 | | } |
| 0 | 384 | | } |
| 0 | 385 | | else if (openedFromDeepLink) |
| | 386 | | { |
| 0 | 387 | | stepIndex = configuration.stepsFromDeepLink.FindIndex(x => x.name == stepName); |
| | 388 | | } |
| 0 | 389 | | break; |
| | 390 | | case TutorialType.BuilderInWorld: |
| 0 | 391 | | stepIndex = configuration.stepsFromBuilderInWorld.FindIndex(x => x.name == stepName); |
| | 392 | | break; |
| | 393 | | } |
| | 394 | |
|
| 0 | 395 | | nextStepsToSkip = 0; |
| | 396 | |
|
| 0 | 397 | | if (stepIndex >= 0) |
| 0 | 398 | | CoroutineStarter.Start(StartTutorialFromStep(stepIndex)); |
| | 399 | | else |
| 0 | 400 | | SkipTutorial(true); |
| 0 | 401 | | } |
| | 402 | |
|
| | 403 | | /// <summary> |
| | 404 | | /// Set the number of steps that will be skipped in the next iteration. |
| | 405 | | /// </summary> |
| | 406 | | /// <param name="skippedSteps">Number of steps to skip.</param> |
| 0 | 407 | | public void SetNextSkippedSteps(int skippedSteps) { nextStepsToSkip = skippedSteps; } |
| | 408 | |
|
| | 409 | | /// <summary> |
| | 410 | | /// Activate/deactivate the eagle eye camera. |
| | 411 | | /// </summary> |
| | 412 | | /// <param name="isActive">True for activate the eagle eye camera.</param> |
| | 413 | | public void SetEagleEyeCameraActive(bool isActive) |
| | 414 | | { |
| 6 | 415 | | configuration.eagleEyeCamera.gameObject.SetActive(isActive); |
| 6 | 416 | | CoroutineStarter.Start(BlockPlayerCameraUntilBlendingIsFinished(isActive)); |
| | 417 | |
|
| 6 | 418 | | if (isActive) |
| | 419 | | { |
| 3 | 420 | | configuration.eagleEyeCamera.transform.position = configuration.eagleCamInitPosition; |
| 3 | 421 | | configuration.eagleEyeCamera.transform.LookAt(configuration.eagleCamInitLookAtPoint); |
| | 422 | |
|
| 3 | 423 | | if (configuration.eagleCamRotationActived) |
| 2 | 424 | | eagleEyeRotationCoroutine = CoroutineStarter.Start(EagleEyeCameraRotation(configuration.eagleCamRota |
| 2 | 425 | | } |
| 3 | 426 | | else if (eagleEyeRotationCoroutine != null) |
| | 427 | | { |
| 2 | 428 | | CoroutineStarter.Stop(eagleEyeRotationCoroutine); |
| | 429 | | } |
| 4 | 430 | | } |
| | 431 | |
|
| | 432 | | internal void OnRenderingStateChanged(bool renderingEnabled, bool prevState) |
| | 433 | | { |
| 2 | 434 | | if (!renderingEnabled) |
| 0 | 435 | | return; |
| | 436 | |
|
| 2 | 437 | | CommonScriptableObjects.rendererState.OnChange -= OnRenderingStateChanged; |
| | 438 | |
|
| 2 | 439 | | playerIsInGenesisPlaza = IsPlayerInsideGenesisPlaza(); |
| | 440 | |
|
| 2 | 441 | | if (configuration.debugRunTutorial) |
| 1 | 442 | | currentStepIndex = configuration.debugStartingStepIndex >= 0 ? configuration.debugStartingStepIndex : 0; |
| | 443 | | else |
| 1 | 444 | | currentStepIndex = 0; |
| | 445 | |
|
| 2 | 446 | | PlayTeacherAnimation(TutorialTeacher.TeacherAnimation.Reset); |
| 2 | 447 | | executeStepsCoroutine = CoroutineStarter.Start(StartTutorialFromStep(currentStepIndex)); |
| 2 | 448 | | } |
| | 449 | |
|
| | 450 | | private IEnumerator ExecuteSteps(TutorialPath tutorialPath, int startingStepIndex) |
| | 451 | | { |
| 25 | 452 | | List<TutorialStep> steps = new List<TutorialStep>(); |
| | 453 | |
|
| | 454 | | switch (tutorialPath) |
| | 455 | | { |
| | 456 | | case TutorialPath.FromGenesisPlaza: |
| 17 | 457 | | steps = configuration.stepsOnGenesisPlaza; |
| 17 | 458 | | break; |
| | 459 | | case TutorialPath.FromDeepLink: |
| 2 | 460 | | steps = configuration.stepsFromDeepLink; |
| 2 | 461 | | break; |
| | 462 | | case TutorialPath.FromResetTutorial: |
| 2 | 463 | | steps = configuration.stepsFromReset; |
| 2 | 464 | | break; |
| | 465 | | case TutorialPath.FromBuilderInWorld: |
| 2 | 466 | | steps = configuration.stepsFromBuilderInWorld; |
| 2 | 467 | | break; |
| | 468 | | case TutorialPath.FromUserThatAlreadyDidTheTutorial: |
| 2 | 469 | | steps = configuration.stepsFromUserThatAlreadyDidTheTutorial; |
| | 470 | | break; |
| | 471 | | } |
| | 472 | |
|
| 25 | 473 | | currentPath = tutorialPath; |
| | 474 | |
|
| 25 | 475 | | elapsedTimeInCurrentStep = 0f; |
| 130 | 476 | | for (int i = startingStepIndex; i < steps.Count; i++) |
| | 477 | | { |
| 40 | 478 | | if (nextStepsToSkip > 0) |
| | 479 | | { |
| 0 | 480 | | nextStepsToSkip--; |
| 0 | 481 | | continue; |
| | 482 | | } |
| | 483 | |
|
| 40 | 484 | | var stepPrefab = steps[i]; |
| | 485 | |
|
| | 486 | | // TODO (Santi): This a TEMPORAL fix. It will be removed when we refactorize the tutorial system in orde |
| 40 | 487 | | if (stepPrefab is TutorialStep_Tooltip_ExploreButton && |
| | 488 | | !DataStore.i.exploreV2.isInitialized.Get()) |
| | 489 | | continue; |
| | 490 | |
|
| 40 | 491 | | if (stepPrefab.letInstantiation) |
| 15 | 492 | | runningStep = GameObject.Instantiate(stepPrefab, tutorialView.transform).GetComponent<TutorialStep>( |
| | 493 | | else |
| 25 | 494 | | runningStep = steps[i]; |
| | 495 | |
|
| 40 | 496 | | runningStep.gameObject.name = runningStep.gameObject.name.Replace("(Clone)", ""); |
| 40 | 497 | | currentStepIndex = i; |
| | 498 | |
|
| 40 | 499 | | elapsedTimeInCurrentStep = Time.realtimeSinceStartup; |
| 40 | 500 | | currentStepNumber = i + 1; |
| | 501 | |
|
| 40 | 502 | | if (!configuration.debugRunTutorial && configuration.sendStats) |
| | 503 | | { |
| 0 | 504 | | SendStepStartedSegmentStats( |
| | 505 | | configuration.tutorialVersion, |
| | 506 | | tutorialPath, |
| | 507 | | i + 1, |
| | 508 | | runningStep.name.Replace("(Clone)", "").Replace("TutorialStep_", "")); |
| | 509 | | } |
| | 510 | |
|
| 40 | 511 | | runningStep.OnStepStart(); |
| 40 | 512 | | yield return runningStep.OnStepExecute(); |
| 40 | 513 | | if (i < steps.Count - 1) |
| 20 | 514 | | PlayTeacherAnimation(TutorialTeacher.TeacherAnimation.StepCompleted); |
| | 515 | | else |
| 20 | 516 | | PlayTeacherAnimation(TutorialTeacher.TeacherAnimation.QuickGoodbye); |
| | 517 | |
|
| 40 | 518 | | yield return runningStep.OnStepPlayHideAnimation(); |
| 40 | 519 | | runningStep.OnStepFinished(); |
| 40 | 520 | | elapsedTimeInCurrentStep = Time.realtimeSinceStartup - elapsedTimeInCurrentStep; |
| | 521 | |
|
| 40 | 522 | | if (!configuration.debugRunTutorial && |
| | 523 | | configuration.sendStats && |
| | 524 | | tutorialPath != TutorialPath.FromUserThatAlreadyDidTheTutorial) |
| | 525 | | { |
| 0 | 526 | | SendStepCompletedSegmentStats( |
| | 527 | | configuration.tutorialVersion, |
| | 528 | | tutorialPath, |
| | 529 | | i + 1, |
| | 530 | | runningStep.name.Replace("(Clone)", "").Replace("TutorialStep_", ""), |
| | 531 | | elapsedTimeInCurrentStep); |
| | 532 | | } |
| | 533 | |
|
| 40 | 534 | | GameObject.Destroy(runningStep.gameObject); |
| | 535 | |
|
| 40 | 536 | | if (i < steps.Count - 1 && configuration.timeBetweenSteps > 0) |
| 0 | 537 | | yield return new WaitForSeconds(configuration.timeBetweenSteps); |
| | 538 | | } |
| | 539 | |
|
| 25 | 540 | | if (!configuration.debugRunTutorial && |
| | 541 | | tutorialPath != TutorialPath.FromBuilderInWorld && |
| | 542 | | tutorialPath != TutorialPath.FromUserThatAlreadyDidTheTutorial) |
| | 543 | | { |
| 21 | 544 | | SetUserTutorialStepAsCompleted(TutorialFinishStep.NewTutorialFinished); |
| | 545 | | } |
| | 546 | |
|
| 25 | 547 | | runningStep = null; |
| | 548 | |
|
| 25 | 549 | | SetTutorialDisabled(); |
| 25 | 550 | | } |
| | 551 | |
|
| 42 | 552 | | private void SetUserTutorialStepAsCompleted(TutorialFinishStep finishStepType) { WebInterface.SaveUserTutorialSt |
| | 553 | |
|
| | 554 | | internal IEnumerator MoveTeacher(Vector2 fromPosition, Vector2 toPosition) |
| | 555 | | { |
| 1 | 556 | | if (configuration.teacherRawImage == null) |
| 0 | 557 | | yield break; |
| | 558 | |
|
| 1 | 559 | | float t = 0f; |
| | 560 | |
|
| 2 | 561 | | while (Vector2.Distance(configuration.teacherRawImage.rectTransform.position, toPosition) > 0) |
| | 562 | | { |
| 2 | 563 | | t += configuration.teacherMovementSpeed * Time.deltaTime; |
| 2 | 564 | | if (t <= 1.0f) |
| 2 | 565 | | configuration.teacherRawImage.rectTransform.position = Vector2.Lerp(fromPosition, toPosition, config |
| | 566 | | else |
| 0 | 567 | | configuration.teacherRawImage.rectTransform.position = toPosition; |
| | 568 | |
|
| 2 | 569 | | yield return null; |
| | 570 | | } |
| 0 | 571 | | } |
| | 572 | |
|
| | 573 | | private void IsSettingsHUDInitialized_OnChange(bool current, bool previous) |
| | 574 | | { |
| 0 | 575 | | if (current && |
| | 576 | | hudController != null && |
| | 577 | | hudController.settingsPanelHud != null) |
| | 578 | | { |
| 0 | 579 | | hudController.settingsPanelHud.OnRestartTutorial -= OnRestartTutorial; |
| 0 | 580 | | hudController.settingsPanelHud.OnRestartTutorial += OnRestartTutorial; |
| | 581 | | } |
| 0 | 582 | | } |
| | 583 | |
|
| | 584 | | internal void OnRestartTutorial() |
| | 585 | | { |
| 0 | 586 | | SetTutorialDisabled(); |
| 0 | 587 | | tutorialReset = true; |
| 0 | 588 | | SetTutorialEnabled(JsonUtility.ToJson(new TutorialInitializationMessage |
| | 589 | | { |
| | 590 | | fromDeepLink = false.ToString(), |
| | 591 | | enableNewTutorialCamera = false.ToString() |
| | 592 | | })); |
| 0 | 593 | | } |
| | 594 | |
|
| | 595 | | internal static bool IsPlayerInsideGenesisPlaza() |
| | 596 | | { |
| 2 | 597 | | if (Environment.i.world == null) |
| 0 | 598 | | return false; |
| | 599 | |
|
| 2 | 600 | | IWorldState worldState = Environment.i.world.state; |
| | 601 | |
|
| 2 | 602 | | if (worldState == null || worldState.currentSceneId == null) |
| 0 | 603 | | return false; |
| | 604 | |
|
| 2 | 605 | | Vector2Int genesisPlazaBaseCoords = new Vector2Int(-9, -9); |
| | 606 | |
|
| 2 | 607 | | IParcelScene currentScene = null; |
| 2 | 608 | | if (worldState.loadedScenes != null) |
| 0 | 609 | | currentScene = worldState.loadedScenes[worldState.currentSceneId]; |
| | 610 | |
|
| 2 | 611 | | if (currentScene != null && currentScene.IsInsideSceneBoundaries(genesisPlazaBaseCoords)) |
| 0 | 612 | | return true; |
| | 613 | |
|
| 2 | 614 | | return false; |
| | 615 | | } |
| | 616 | |
|
| | 617 | | private void SendStepStartedSegmentStats(int version, TutorialPath tutorialPath, int stepNumber, string stepName |
| | 618 | | { |
| 0 | 619 | | WebInterface.AnalyticsPayload.Property[] properties = new WebInterface.AnalyticsPayload.Property[] |
| | 620 | | { |
| | 621 | | new WebInterface.AnalyticsPayload.Property("version", version.ToString()), |
| | 622 | | new WebInterface.AnalyticsPayload.Property("path", tutorialPath.ToString()), |
| | 623 | | new WebInterface.AnalyticsPayload.Property("step number", stepNumber.ToString()), |
| | 624 | | new WebInterface.AnalyticsPayload.Property("step name", stepName) |
| | 625 | | }; |
| 0 | 626 | | WebInterface.ReportAnalyticsEvent("tutorial step started", properties); |
| 0 | 627 | | } |
| | 628 | |
|
| | 629 | | private void SendStepCompletedSegmentStats(int version, TutorialPath tutorialPath, int stepNumber, string stepNa |
| | 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 | | new WebInterface.AnalyticsPayload.Property("elapsed time", elapsedTime.ToString("0.00")) |
| | 638 | | }; |
| 0 | 639 | | WebInterface.ReportAnalyticsEvent("tutorial step completed", properties); |
| 0 | 640 | | } |
| | 641 | |
|
| | 642 | | private void SendSkipTutorialSegmentStats(int version, string stepName) |
| | 643 | | { |
| 0 | 644 | | WebInterface.AnalyticsPayload.Property[] properties = new WebInterface.AnalyticsPayload.Property[] |
| | 645 | | { |
| | 646 | | new WebInterface.AnalyticsPayload.Property("version", version.ToString()), |
| | 647 | | new WebInterface.AnalyticsPayload.Property("path", currentPath.ToString()), |
| | 648 | | new WebInterface.AnalyticsPayload.Property("step number", currentStepNumber.ToString()), |
| | 649 | | new WebInterface.AnalyticsPayload.Property("step name", stepName), |
| | 650 | | new WebInterface.AnalyticsPayload.Property("elapsed time", (Time.realtimeSinceStartup - elapsedTimeInCur |
| | 651 | | }; |
| 0 | 652 | | WebInterface.ReportAnalyticsEvent("tutorial skipped", properties); |
| 0 | 653 | | } |
| | 654 | |
|
| | 655 | | internal IEnumerator EagleEyeCameraRotation(float rotationSpeed) |
| | 656 | | { |
| 4 | 657 | | while (true) |
| | 658 | | { |
| 6 | 659 | | configuration.eagleEyeCamera.transform.Rotate(Vector3.up * Time.deltaTime * rotationSpeed, Space.World); |
| 6 | 660 | | yield return null; |
| | 661 | | } |
| | 662 | | } |
| | 663 | |
|
| | 664 | | private IEnumerator BlockPlayerCameraUntilBlendingIsFinished(bool hideUIs) |
| | 665 | | { |
| 6 | 666 | | if (hideUIs) |
| | 667 | | { |
| 3 | 668 | | hudController?.minimapHud?.SetVisibility(false); |
| 3 | 669 | | hudController?.profileHud?.SetVisibility(false); |
| | 670 | | } |
| | 671 | |
|
| 6 | 672 | | CommonScriptableObjects.cameraBlocked.Set(true); |
| | 673 | |
|
| 6 | 674 | | yield return null; |
| 12 | 675 | | yield return new WaitUntil(() => !CommonScriptableObjects.cameraIsBlending.Get()); |
| | 676 | |
|
| 6 | 677 | | CommonScriptableObjects.cameraBlocked.Set(false); |
| | 678 | |
|
| 6 | 679 | | if (!hideUIs) |
| | 680 | | { |
| 3 | 681 | | hudController?.minimapHud?.SetVisibility(true); |
| 3 | 682 | | hudController?.profileHud?.SetVisibility(true); |
| | 683 | | } |
| 6 | 684 | | } |
| | 685 | | } |
| | 686 | | } |