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