| | 1 | | using DCL.Controllers; |
| | 2 | | using DCL.Interface; |
| | 3 | | using System; |
| | 4 | | using System.Collections; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using UnityEngine; |
| | 7 | | using DCL.Helpers; |
| | 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 : PluginFeature |
| | 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 | |
|
| 27 | 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_VOICE_CHAT_FEATURE_SHOWED = "VoiceChatFeatureShowed"; |
| | 56 | |
|
| | 57 | | internal TutorialSettings configuration; |
| | 58 | | internal TutorialView tutorialView; |
| | 59 | |
|
| | 60 | | internal bool isRunning = false; |
| | 61 | | internal bool openedFromDeepLink = false; |
| | 62 | | internal bool playerIsInGenesisPlaza = false; |
| | 63 | | internal TutorialStep runningStep = null; |
| | 64 | | internal bool tutorialReset = false; |
| | 65 | | internal float elapsedTimeInCurrentStep = 0f; |
| | 66 | | internal TutorialPath currentPath; |
| | 67 | | internal int currentStepNumber; |
| | 68 | | internal TutorialType tutorialType = TutorialType.Initial; |
| | 69 | |
|
| | 70 | | private Coroutine executeStepsCoroutine; |
| | 71 | | private Coroutine teacherMovementCoroutine; |
| | 72 | | private Coroutine eagleEyeRotationCoroutine; |
| | 73 | |
|
| 0 | 74 | | internal bool userAlreadyDidTheTutorial { get; set; } |
| | 75 | |
|
| | 76 | | public override void Initialize() |
| | 77 | | { |
| 0 | 78 | | base.Initialize(); |
| | 79 | |
|
| 0 | 80 | | tutorialView = CreateTutorialView(); |
| 0 | 81 | | SetConfiguration(tutorialView.configuration); |
| 0 | 82 | | } |
| | 83 | |
|
| | 84 | | internal TutorialView CreateTutorialView() |
| | 85 | | { |
| 44 | 86 | | GameObject tutorialGO = GameObject.Instantiate(Resources.Load<GameObject>("TutorialView")); |
| 44 | 87 | | tutorialGO.name = "TutorialController"; |
| 44 | 88 | | TutorialView tutorialView = tutorialGO.GetComponent<TutorialView>(); |
| 44 | 89 | | tutorialView.ConfigureView(this); |
| | 90 | |
|
| 44 | 91 | | return tutorialView; |
| | 92 | | } |
| | 93 | |
|
| | 94 | | public void SetConfiguration(TutorialSettings configuration) |
| | 95 | | { |
| 44 | 96 | | this.configuration = configuration; |
| | 97 | |
|
| 44 | 98 | | i = this; |
| 44 | 99 | | ShowTeacher3DModel(false); |
| | 100 | |
|
| 44 | 101 | | if (CommonScriptableObjects.isTaskbarHUDInitialized.Get()) |
| 44 | 102 | | IsTaskbarHUDInitialized_OnChange(true, false); |
| | 103 | | else |
| 0 | 104 | | CommonScriptableObjects.isTaskbarHUDInitialized.OnChange += IsTaskbarHUDInitialized_OnChange; |
| | 105 | |
|
| 44 | 106 | | if (configuration.debugRunTutorial) |
| | 107 | | { |
| 0 | 108 | | SetTutorialEnabled(JsonUtility.ToJson(new TutorialInitializationMessage |
| | 109 | | { |
| | 110 | | fromDeepLink = configuration.debugOpenedFromDeepLink.ToString(), |
| | 111 | | enableNewTutorialCamera = false.ToString() |
| | 112 | | })); |
| | 113 | | } |
| 44 | 114 | | } |
| | 115 | |
|
| | 116 | | public override void Dispose() |
| | 117 | | { |
| 44 | 118 | | base.Dispose(); |
| | 119 | |
|
| 44 | 120 | | SetTutorialDisabled(); |
| | 121 | |
|
| 44 | 122 | | CommonScriptableObjects.isTaskbarHUDInitialized.OnChange -= IsTaskbarHUDInitialized_OnChange; |
| | 123 | |
|
| 44 | 124 | | if (hudController != null && |
| | 125 | | hudController.taskbarHud != null) |
| | 126 | | { |
| 0 | 127 | | hudController.taskbarHud.moreMenu.OnRestartTutorial -= MoreMenu_OnRestartTutorial; |
| | 128 | | } |
| | 129 | |
|
| 44 | 130 | | NotificationsController.disableWelcomeNotification = false; |
| | 131 | |
|
| 44 | 132 | | if (tutorialView != null) |
| 44 | 133 | | GameObject.Destroy(tutorialView.gameObject); |
| 44 | 134 | | } |
| | 135 | |
|
| | 136 | | public void SetTutorialEnabled(string json) |
| | 137 | | { |
| 1 | 138 | | TutorialInitializationMessage msg = JsonUtility.FromJson<TutorialInitializationMessage>(json); |
| 1 | 139 | | SetupTutorial(msg.fromDeepLink, msg.enableNewTutorialCamera, TutorialType.Initial); |
| 1 | 140 | | } |
| | 141 | |
|
| | 142 | | public void SetTutorialEnabledForUsersThatAlreadyDidTheTutorial(string json) |
| | 143 | | { |
| 0 | 144 | | TutorialInitializationMessage msg = JsonUtility.FromJson<TutorialInitializationMessage>(json); |
| | 145 | |
|
| | 146 | | // TODO (Santi): This a TEMPORAL fix. It will be removed when we refactorize the tutorial system in order to |
| 0 | 147 | | if (PlayerPrefsUtils.GetInt(PLAYER_PREFS_VOICE_CHAT_FEATURE_SHOWED) == 1) |
| 0 | 148 | | return; |
| | 149 | |
|
| 0 | 150 | | SetupTutorial(false.ToString(), msg.enableNewTutorialCamera, TutorialType.Initial, true); |
| 0 | 151 | | } |
| | 152 | |
|
| 0 | 153 | | public void SetBuilderInWorldTutorialEnabled() { SetupTutorial(false.ToString(), false.ToString(), TutorialType. |
| | 154 | |
|
| | 155 | | /// <summary> |
| | 156 | | /// Enables the tutorial controller and waits for the RenderingState is enabled to start to execute the correspo |
| | 157 | | /// </summary> |
| | 158 | | internal void SetupTutorial(string fromDeepLink, string enableNewTutorialCamera, TutorialType tutorialType, bool |
| | 159 | | { |
| 2 | 160 | | if (isRunning) |
| 0 | 161 | | return; |
| | 162 | |
|
| 2 | 163 | | if (Convert.ToBoolean(enableNewTutorialCamera)) |
| | 164 | | { |
| 1 | 165 | | configuration.eagleCamInitPosition = new Vector3(15, 115, -30); |
| 1 | 166 | | configuration.eagleCamInitLookAtPoint = new Vector3(16, 105, 6); |
| 1 | 167 | | configuration.eagleCamRotationActived = false; |
| | 168 | | } |
| | 169 | |
|
| 2 | 170 | | isRunning = true; |
| 2 | 171 | | DataStore.i.virtualAudioMixer.sceneSFXVolume.Set(0f); |
| 2 | 172 | | this.userAlreadyDidTheTutorial = userAlreadyDidTheTutorial; |
| 2 | 173 | | CommonScriptableObjects.allUIHidden.Set(false); |
| 2 | 174 | | CommonScriptableObjects.tutorialActive.Set(true); |
| 2 | 175 | | openedFromDeepLink = Convert.ToBoolean(fromDeepLink); |
| 2 | 176 | | this.tutorialType = tutorialType; |
| | 177 | |
|
| 2 | 178 | | hudController?.taskbarHud?.ShowTutorialOption(false); |
| 2 | 179 | | hudController?.profileHud?.HideProfileMenu(); |
| | 180 | |
|
| 2 | 181 | | NotificationsController.disableWelcomeNotification = true; |
| | 182 | |
|
| 2 | 183 | | WebInterface.SetDelightedSurveyEnabled(false); |
| | 184 | |
|
| 2 | 185 | | if (!CommonScriptableObjects.rendererState.Get()) |
| 1 | 186 | | CommonScriptableObjects.rendererState.OnChange += OnRenderingStateChanged; |
| | 187 | | else |
| 1 | 188 | | OnRenderingStateChanged(true, false); |
| | 189 | |
|
| 2 | 190 | | OnTutorialEnabled?.Invoke(); |
| 1 | 191 | | } |
| | 192 | |
|
| | 193 | | /// <summary> |
| | 194 | | /// Stop and disables the tutorial controller. |
| | 195 | | /// </summary> |
| | 196 | | public void SetTutorialDisabled() |
| | 197 | | { |
| 76 | 198 | | CommonScriptableObjects.featureKeyTriggersBlocked.Set(false); |
| | 199 | |
|
| 76 | 200 | | if (executeStepsCoroutine != null) |
| | 201 | | { |
| 1 | 202 | | CoroutineStarter.Stop(executeStepsCoroutine); |
| 1 | 203 | | executeStepsCoroutine = null; |
| | 204 | | } |
| | 205 | |
|
| 76 | 206 | | if (runningStep != null) |
| | 207 | | { |
| 1 | 208 | | GameObject.Destroy(runningStep.gameObject); |
| 1 | 209 | | runningStep = null; |
| | 210 | | } |
| | 211 | |
|
| 76 | 212 | | tutorialReset = false; |
| 76 | 213 | | isRunning = false; |
| 76 | 214 | | DataStore.i.virtualAudioMixer.sceneSFXVolume.Set(1f); |
| 76 | 215 | | ShowTeacher3DModel(false); |
| 76 | 216 | | WebInterface.SetDelightedSurveyEnabled(true); |
| | 217 | |
|
| 76 | 218 | | if (Environment.i != null && Environment.i.world != null) |
| | 219 | | { |
| 76 | 220 | | WebInterface.SendSceneExternalActionEvent(Environment.i.world.state.currentSceneId, "tutorial", "end"); |
| | 221 | | } |
| | 222 | |
|
| 76 | 223 | | NotificationsController.disableWelcomeNotification = false; |
| | 224 | |
|
| 76 | 225 | | hudController?.taskbarHud?.ShowTutorialOption(true); |
| | 226 | |
|
| 76 | 227 | | CommonScriptableObjects.tutorialActive.Set(false); |
| | 228 | |
|
| 76 | 229 | | CommonScriptableObjects.rendererState.OnChange -= OnRenderingStateChanged; |
| | 230 | |
|
| 76 | 231 | | OnTutorialDisabled?.Invoke(); |
| 2 | 232 | | } |
| | 233 | |
|
| | 234 | | /// <summary> |
| | 235 | | /// Starts to execute the tutorial from a specific step (It is needed to call SetTutorialEnabled() before). |
| | 236 | | /// </summary> |
| | 237 | | /// <param name="stepIndex">First step to be executed.</param> |
| | 238 | | public IEnumerator StartTutorialFromStep(int stepIndex) |
| | 239 | | { |
| 32 | 240 | | if (!isRunning) |
| 2 | 241 | | yield break; |
| | 242 | |
|
| 30 | 243 | | if (runningStep != null) |
| | 244 | | { |
| 10 | 245 | | runningStep.OnStepFinished(); |
| 10 | 246 | | GameObject.Destroy(runningStep.gameObject); |
| 10 | 247 | | runningStep = null; |
| | 248 | | } |
| | 249 | |
|
| 30 | 250 | | switch (tutorialType) |
| | 251 | | { |
| | 252 | | case TutorialType.Initial: |
| 28 | 253 | | if (userAlreadyDidTheTutorial) |
| | 254 | | { |
| 2 | 255 | | yield return ExecuteSteps(TutorialPath.FromUserThatAlreadyDidTheTutorial, stepIndex); |
| 2 | 256 | | } |
| 26 | 257 | | else if (playerIsInGenesisPlaza || tutorialReset) |
| | 258 | | { |
| 24 | 259 | | if (tutorialReset) |
| | 260 | | { |
| 3 | 261 | | yield return ExecuteSteps(TutorialPath.FromResetTutorial, stepIndex); |
| 2 | 262 | | } |
| | 263 | | else |
| | 264 | | { |
| 21 | 265 | | yield return ExecuteSteps(TutorialPath.FromGenesisPlaza, stepIndex); |
| | 266 | | } |
| 21 | 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 | | } |
| 29 | 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 | | { |
| 141 | 291 | | if (configuration.teacherCamera != null) |
| 141 | 292 | | configuration.teacherCamera.enabled = active; |
| | 293 | |
|
| 141 | 294 | | if (configuration.teacherRawImage != null) |
| 84 | 295 | | configuration.teacherRawImage.gameObject.SetActive(active); |
| 141 | 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 | | { |
| 29 | 305 | | if (teacherMovementCoroutine != null) |
| 0 | 306 | | CoroutineStarter.Stop(teacherMovementCoroutine); |
| | 307 | |
|
| 29 | 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 | | } |
| 29 | 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 | | { |
| 55 | 323 | | if (configuration.teacher == null) |
| 27 | 324 | | return; |
| | 325 | |
|
| 28 | 326 | | configuration.teacher.PlayAnimation(animation); |
| 28 | 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 | | { |
| 13 | 335 | | if (configuration.teacherCanvas == null) |
| 0 | 336 | | return; |
| | 337 | |
|
| 13 | 338 | | configuration.teacherCanvas.sortingOrder = sortOrder; |
| 13 | 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() |
| | 345 | | { |
| 5 | 346 | | if (!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); |
| 5 | 362 | | hudController?.profileHud?.SetBackpackButtonVisibility(true); |
| 0 | 363 | | } |
| | 364 | |
|
| | 365 | | /// <summary> |
| | 366 | | /// Activate/deactivate the eagle eye camera. |
| | 367 | | /// </summary> |
| | 368 | | /// <param name="isActive">True for activate the eagle eye camera.</param> |
| | 369 | | public void SetEagleEyeCameraActive(bool isActive) |
| | 370 | | { |
| 6 | 371 | | configuration.eagleEyeCamera.gameObject.SetActive(isActive); |
| 6 | 372 | | CoroutineStarter.Start(BlockPlayerCameraUntilBlendingIsFinished(isActive)); |
| | 373 | |
|
| 6 | 374 | | if (isActive) |
| | 375 | | { |
| 3 | 376 | | configuration.eagleEyeCamera.transform.position = configuration.eagleCamInitPosition; |
| 3 | 377 | | configuration.eagleEyeCamera.transform.LookAt(configuration.eagleCamInitLookAtPoint); |
| | 378 | |
|
| 3 | 379 | | if (configuration.eagleCamRotationActived) |
| 2 | 380 | | eagleEyeRotationCoroutine = CoroutineStarter.Start(EagleEyeCameraRotation(configuration.eagleCamRota |
| 2 | 381 | | } |
| 3 | 382 | | else if (eagleEyeRotationCoroutine != null) |
| | 383 | | { |
| 2 | 384 | | CoroutineStarter.Stop(eagleEyeRotationCoroutine); |
| | 385 | | } |
| 4 | 386 | | } |
| | 387 | |
|
| | 388 | | internal void OnRenderingStateChanged(bool renderingEnabled, bool prevState) |
| | 389 | | { |
| 3 | 390 | | if (!renderingEnabled) |
| 0 | 391 | | return; |
| | 392 | |
|
| 3 | 393 | | CommonScriptableObjects.rendererState.OnChange -= OnRenderingStateChanged; |
| | 394 | |
|
| 3 | 395 | | playerIsInGenesisPlaza = IsPlayerInsideGenesisPlaza(); |
| | 396 | |
|
| 3 | 397 | | if (configuration.debugRunTutorial) |
| 1 | 398 | | currentStepIndex = configuration.debugStartingStepIndex >= 0 ? configuration.debugStartingStepIndex : 0; |
| | 399 | | else |
| 2 | 400 | | currentStepIndex = 0; |
| | 401 | |
|
| 3 | 402 | | PlayTeacherAnimation(TutorialTeacher.TeacherAnimation.Reset); |
| 3 | 403 | | executeStepsCoroutine = CoroutineStarter.Start(StartTutorialFromStep(currentStepIndex)); |
| 3 | 404 | | } |
| | 405 | |
|
| | 406 | | private IEnumerator ExecuteSteps(TutorialPath tutorialPath, int startingStepIndex) |
| | 407 | | { |
| 30 | 408 | | List<TutorialStep> steps = new List<TutorialStep>(); |
| | 409 | |
|
| | 410 | | switch (tutorialPath) |
| | 411 | | { |
| | 412 | | case TutorialPath.FromGenesisPlaza: |
| 21 | 413 | | steps = configuration.stepsOnGenesisPlaza; |
| 21 | 414 | | break; |
| | 415 | | case TutorialPath.FromDeepLink: |
| 2 | 416 | | steps = configuration.stepsFromDeepLink; |
| 2 | 417 | | break; |
| | 418 | | case TutorialPath.FromResetTutorial: |
| 3 | 419 | | steps = configuration.stepsFromReset; |
| 3 | 420 | | break; |
| | 421 | | case TutorialPath.FromBuilderInWorld: |
| 2 | 422 | | steps = configuration.stepsFromBuilderInWorld; |
| 2 | 423 | | break; |
| | 424 | | case TutorialPath.FromUserThatAlreadyDidTheTutorial: |
| 2 | 425 | | steps = configuration.stepsFromUserThatAlreadyDidTheTutorial; |
| | 426 | | break; |
| | 427 | | } |
| | 428 | |
|
| 30 | 429 | | currentPath = tutorialPath; |
| | 430 | |
|
| 30 | 431 | | elapsedTimeInCurrentStep = 0f; |
| 148 | 432 | | for (int i = startingStepIndex; i < steps.Count; i++) |
| | 433 | | { |
| 44 | 434 | | var stepPrefab = steps[i]; |
| | 435 | |
|
| | 436 | | // TODO (Santi): This a TEMPORAL fix. It will be removed when we refactorize the tutorial system in orde |
| 44 | 437 | | if (stepPrefab is TutorialStep_Tooltip_UsersAround && |
| | 438 | | CommonScriptableObjects.voiceChatDisabled.Get()) |
| | 439 | | continue; |
| | 440 | |
|
| 44 | 441 | | if (stepPrefab.letInstantiation) |
| 19 | 442 | | runningStep = GameObject.Instantiate(stepPrefab, tutorialView.transform).GetComponent<TutorialStep>( |
| | 443 | | else |
| 25 | 444 | | runningStep = steps[i]; |
| | 445 | |
|
| 44 | 446 | | currentStepIndex = i; |
| | 447 | |
|
| 44 | 448 | | elapsedTimeInCurrentStep = Time.realtimeSinceStartup; |
| 44 | 449 | | currentStepNumber = i + 1; |
| | 450 | |
|
| 44 | 451 | | if (!configuration.debugRunTutorial && configuration.sendStats) |
| | 452 | | { |
| 0 | 453 | | SendStepStartedSegmentStats( |
| | 454 | | configuration.tutorialVersion, |
| | 455 | | tutorialPath, |
| | 456 | | i + 1, |
| | 457 | | runningStep.name.Replace("(Clone)", "").Replace("TutorialStep_", "")); |
| | 458 | | } |
| | 459 | |
|
| 44 | 460 | | if (tutorialPath == TutorialPath.FromUserThatAlreadyDidTheTutorial && |
| | 461 | | runningStep is TutorialStep_Tooltip) |
| | 462 | | { |
| 0 | 463 | | ((TutorialStep_Tooltip) runningStep).OverrideSetMaxTimeToHide(true); |
| | 464 | | } |
| | 465 | |
|
| 44 | 466 | | runningStep.OnStepStart(); |
| 44 | 467 | | yield return runningStep.OnStepExecute(); |
| 44 | 468 | | if (i < steps.Count - 1) |
| 20 | 469 | | PlayTeacherAnimation(TutorialTeacher.TeacherAnimation.StepCompleted); |
| | 470 | | else |
| 24 | 471 | | PlayTeacherAnimation(TutorialTeacher.TeacherAnimation.QuickGoodbye); |
| | 472 | |
|
| 44 | 473 | | yield return runningStep.OnStepPlayHideAnimation(); |
| 44 | 474 | | runningStep.OnStepFinished(); |
| 44 | 475 | | elapsedTimeInCurrentStep = Time.realtimeSinceStartup - elapsedTimeInCurrentStep; |
| | 476 | |
|
| 44 | 477 | | if (!configuration.debugRunTutorial && |
| | 478 | | configuration.sendStats && |
| | 479 | | tutorialPath != TutorialPath.FromUserThatAlreadyDidTheTutorial) |
| | 480 | | { |
| 0 | 481 | | SendStepCompletedSegmentStats( |
| | 482 | | configuration.tutorialVersion, |
| | 483 | | tutorialPath, |
| | 484 | | i + 1, |
| | 485 | | runningStep.name.Replace("(Clone)", "").Replace("TutorialStep_", ""), |
| | 486 | | elapsedTimeInCurrentStep); |
| | 487 | | } |
| | 488 | |
|
| 44 | 489 | | GameObject.Destroy(runningStep.gameObject); |
| | 490 | |
|
| 44 | 491 | | if (i < steps.Count - 1 && configuration.timeBetweenSteps > 0) |
| 0 | 492 | | yield return new WaitForSeconds(configuration.timeBetweenSteps); |
| | 493 | | } |
| | 494 | |
|
| 30 | 495 | | if (!configuration.debugRunTutorial && |
| | 496 | | tutorialPath != TutorialPath.FromBuilderInWorld && |
| | 497 | | tutorialPath != TutorialPath.FromUserThatAlreadyDidTheTutorial) |
| | 498 | | { |
| 26 | 499 | | SetUserTutorialStepAsCompleted(TutorialFinishStep.NewTutorialFinished); |
| | 500 | | } |
| | 501 | |
|
| 30 | 502 | | runningStep = null; |
| | 503 | |
|
| 30 | 504 | | SetTutorialDisabled(); |
| 30 | 505 | | } |
| | 506 | |
|
| 52 | 507 | | private void SetUserTutorialStepAsCompleted(TutorialFinishStep finishStepType) { WebInterface.SaveUserTutorialSt |
| | 508 | |
|
| | 509 | | internal IEnumerator MoveTeacher(Vector2 fromPosition, Vector2 toPosition) |
| | 510 | | { |
| 1 | 511 | | if (configuration.teacherRawImage == null) |
| 0 | 512 | | yield break; |
| | 513 | |
|
| 1 | 514 | | float t = 0f; |
| | 515 | |
|
| 2 | 516 | | while (Vector2.Distance(configuration.teacherRawImage.rectTransform.position, toPosition) > 0) |
| | 517 | | { |
| 2 | 518 | | t += configuration.teacherMovementSpeed * Time.deltaTime; |
| 2 | 519 | | if (t <= 1.0f) |
| 2 | 520 | | configuration.teacherRawImage.rectTransform.position = Vector2.Lerp(fromPosition, toPosition, config |
| | 521 | | else |
| 0 | 522 | | configuration.teacherRawImage.rectTransform.position = toPosition; |
| | 523 | |
|
| 2 | 524 | | yield return null; |
| | 525 | | } |
| 0 | 526 | | } |
| | 527 | |
|
| | 528 | | private void IsTaskbarHUDInitialized_OnChange(bool current, bool previous) |
| | 529 | | { |
| 44 | 530 | | if (current && |
| | 531 | | hudController != null && |
| | 532 | | hudController.taskbarHud != null) |
| | 533 | | { |
| 0 | 534 | | hudController.taskbarHud.moreMenu.OnRestartTutorial -= MoreMenu_OnRestartTutorial; |
| 0 | 535 | | hudController.taskbarHud.moreMenu.OnRestartTutorial += MoreMenu_OnRestartTutorial; |
| | 536 | | } |
| 44 | 537 | | } |
| | 538 | |
|
| | 539 | | internal void MoreMenu_OnRestartTutorial() |
| | 540 | | { |
| 1 | 541 | | SetTutorialDisabled(); |
| 1 | 542 | | tutorialReset = true; |
| 1 | 543 | | SetTutorialEnabled(JsonUtility.ToJson(new TutorialInitializationMessage |
| | 544 | | { |
| | 545 | | fromDeepLink = false.ToString(), |
| | 546 | | enableNewTutorialCamera = false.ToString() |
| | 547 | | })); |
| 1 | 548 | | } |
| | 549 | |
|
| | 550 | | internal static bool IsPlayerInsideGenesisPlaza() |
| | 551 | | { |
| 3 | 552 | | if (Environment.i.world == null) |
| 0 | 553 | | return false; |
| | 554 | |
|
| 3 | 555 | | IWorldState worldState = Environment.i.world.state; |
| | 556 | |
|
| 3 | 557 | | if (worldState == null || worldState.currentSceneId == null) |
| 0 | 558 | | return false; |
| | 559 | |
|
| 3 | 560 | | Vector2Int genesisPlazaBaseCoords = new Vector2Int(-9, -9); |
| | 561 | |
|
| 3 | 562 | | IParcelScene currentScene = null; |
| 3 | 563 | | if (worldState.loadedScenes != null) |
| 0 | 564 | | currentScene = worldState.loadedScenes[worldState.currentSceneId]; |
| | 565 | |
|
| 3 | 566 | | if (currentScene != null && currentScene.IsInsideSceneBoundaries(genesisPlazaBaseCoords)) |
| 0 | 567 | | return true; |
| | 568 | |
|
| 3 | 569 | | return false; |
| | 570 | | } |
| | 571 | |
|
| | 572 | | private void SendStepStartedSegmentStats(int version, TutorialPath tutorialPath, int stepNumber, string stepName |
| | 573 | | { |
| 0 | 574 | | WebInterface.AnalyticsPayload.Property[] properties = new WebInterface.AnalyticsPayload.Property[] |
| | 575 | | { |
| | 576 | | new WebInterface.AnalyticsPayload.Property("version", version.ToString()), |
| | 577 | | new WebInterface.AnalyticsPayload.Property("path", tutorialPath.ToString()), |
| | 578 | | new WebInterface.AnalyticsPayload.Property("step number", stepNumber.ToString()), |
| | 579 | | new WebInterface.AnalyticsPayload.Property("step name", stepName) |
| | 580 | | }; |
| 0 | 581 | | WebInterface.ReportAnalyticsEvent("tutorial step started", properties); |
| 0 | 582 | | } |
| | 583 | |
|
| | 584 | | private void SendStepCompletedSegmentStats(int version, TutorialPath tutorialPath, int stepNumber, string stepNa |
| | 585 | | { |
| 0 | 586 | | WebInterface.AnalyticsPayload.Property[] properties = new WebInterface.AnalyticsPayload.Property[] |
| | 587 | | { |
| | 588 | | new WebInterface.AnalyticsPayload.Property("version", version.ToString()), |
| | 589 | | new WebInterface.AnalyticsPayload.Property("path", tutorialPath.ToString()), |
| | 590 | | new WebInterface.AnalyticsPayload.Property("step number", stepNumber.ToString()), |
| | 591 | | new WebInterface.AnalyticsPayload.Property("step name", stepName), |
| | 592 | | new WebInterface.AnalyticsPayload.Property("elapsed time", elapsedTime.ToString("0.00")) |
| | 593 | | }; |
| 0 | 594 | | WebInterface.ReportAnalyticsEvent("tutorial step completed", properties); |
| 0 | 595 | | } |
| | 596 | |
|
| | 597 | | private void SendSkipTutorialSegmentStats(int version, string stepName) |
| | 598 | | { |
| 0 | 599 | | WebInterface.AnalyticsPayload.Property[] properties = new WebInterface.AnalyticsPayload.Property[] |
| | 600 | | { |
| | 601 | | new WebInterface.AnalyticsPayload.Property("version", version.ToString()), |
| | 602 | | new WebInterface.AnalyticsPayload.Property("path", currentPath.ToString()), |
| | 603 | | new WebInterface.AnalyticsPayload.Property("step number", currentStepNumber.ToString()), |
| | 604 | | new WebInterface.AnalyticsPayload.Property("step name", stepName), |
| | 605 | | new WebInterface.AnalyticsPayload.Property("elapsed time", (Time.realtimeSinceStartup - elapsedTimeInCur |
| | 606 | | }; |
| 0 | 607 | | WebInterface.ReportAnalyticsEvent("tutorial skipped", properties); |
| 0 | 608 | | } |
| | 609 | |
|
| | 610 | | internal IEnumerator EagleEyeCameraRotation(float rotationSpeed) |
| | 611 | | { |
| 4 | 612 | | while (true) |
| | 613 | | { |
| 6 | 614 | | configuration.eagleEyeCamera.transform.Rotate(Vector3.up * Time.deltaTime * rotationSpeed, Space.World); |
| 6 | 615 | | yield return null; |
| | 616 | | } |
| | 617 | | } |
| | 618 | |
|
| | 619 | | private IEnumerator BlockPlayerCameraUntilBlendingIsFinished(bool hideUIs) |
| | 620 | | { |
| 6 | 621 | | if (hideUIs) |
| | 622 | | { |
| 3 | 623 | | hudController?.minimapHud?.SetVisibility(false); |
| 3 | 624 | | hudController?.profileHud?.SetVisibility(false); |
| | 625 | | } |
| | 626 | |
|
| 6 | 627 | | CommonScriptableObjects.cameraBlocked.Set(true); |
| | 628 | |
|
| 6 | 629 | | yield return null; |
| 864 | 630 | | yield return new WaitUntil(() => !CommonScriptableObjects.cameraIsBlending.Get()); |
| | 631 | |
|
| 6 | 632 | | CommonScriptableObjects.cameraBlocked.Set(false); |
| | 633 | |
|
| 6 | 634 | | if (!hideUIs) |
| | 635 | | { |
| 3 | 636 | | hudController?.minimapHud?.SetVisibility(true); |
| 3 | 637 | | hudController?.profileHud?.SetVisibility(true); |
| | 638 | | } |
| 6 | 639 | | } |
| | 640 | | } |
| | 641 | | } |