commit 8078e745b7f9e455da887df47da7bc2c101bd00e Author: AZ Date: Tue Sep 22 10:29:55 2026 +0000 上传文件至「/」 diff --git a/BeadDrawer.cs b/BeadDrawer.cs new file mode 100644 index 0000000..91cab4b --- /dev/null +++ b/BeadDrawer.cs @@ -0,0 +1,1113 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class BeadDrawer : MonoBehaviour +{ + private enum ExitSide + { + None = 0, + Left = 1, + Right = 2, + Top = 3, + Bottom = 4 + } + + public static BeadDrawer instance; + + public GameObject beadPrefab; + + public Collider2D drawArea; + + public AudioClip beadSound; + + public AudioSource myAudioSource; + + public float minPitch = 0.5f; + + public float maxPitch = 2f; + + [SerializeField] + private float constantDistance = 0.01f; + + [SerializeField] + private float beadSizeMultiplier = 5.5f; + + [SerializeField] + private float movingPlatformTimeLimit = 5f; + + private Vector3 previousPoint; + + private GameObject parentObject; + + private bool isDrawing; + + private int beadsSpawned; + + public bool cantHitBorder; + + private Camera mainCamera; + + private bool IsGameStarted; + + private bool IsLineDrawn; + + private PhysicsMaterial2D linePhysicsMat; + + private bool hasMoved; + + private bool _drawingBlocked; + + private bool _externalDragStart; + + private float lastVibrateTime; + + private const float vibrateInterval = 0.1f; + + private Vector2 touchDownScreenPos; + + private bool touchDownRecorded; + + private const float minMovePixels = 12f; + + private ExitSide currentExitSide; + + private float exitLockValue; + + private float lastBeadTime = -1f; + + private const float soundPauseDelay = 0.05f; + + private int _arrayCapacity = 3000; + + private Mesh drawMesh; + + private MeshFilter meshFilter; + + private MeshRenderer meshRenderer; + + private Material beadMaterial; + + private Vector3[] _verts; + + private Vector2[] _uvs; + + private int[] _tris; + + private int _quadCount; + + private Vector2 uvBL; + + private Vector2 uvBR; + + private Vector2 uvTR; + + private Vector2 uvTL; + + private float beadHalfSize; + + private Vector3[] _allBeadPosArr; + + private int _beadPosCount; + + private float _constantDistanceSq; + + private float _invConstantDistance; + + private Vector3 _boundsMin; + + private Vector3 _boundsMax; + + [SerializeField] + [Header("Draw Blocking")] + private LayerMask drawBlockingLayers; + + [Header("Tool Level")] + public bool isToolLevel; + + public Rigidbody2D[] toolRigidbodies; + + public bool testMode; + + private const int COLLIDER_CHUNK_SIZE = 60; + + private const int MAX_COLLIDER_POINTS = 120; + + private readonly List _colliderPool = new List(); + + private int _activeChunks; + + public float LinemovedThreshold = 0.1f; + + public int DrawnBeadCount => _beadPosCount; + + public Rigidbody2D LineRigidbody => (parentObject != null) ? parentObject.GetComponent() : null; + + private void Awake() + { + instance = this; + EyeBallTracker.LookTarget = null; + } + + private void Start() + { + parentObject = UnityEngine.Object.Instantiate(GameManager.Instance.lineParentTr); + if (parentObject != null) + { + EdgeCollider2D component = parentObject.GetComponent(); + if (component != null) + { + component.enabled = false; + _colliderPool.Add(component); + } + } + mainCamera = Camera.main; + beadHalfSize = constantDistance * beadSizeMultiplier * 0.5f; + GameObject gameObject = new GameObject("BeadMesh"); + gameObject.transform.SetParent(parentObject.transform, false); + meshFilter = gameObject.AddComponent(); + meshRenderer = gameObject.AddComponent(); + _verts = new Vector3[_arrayCapacity * 4]; + _uvs = new Vector2[_arrayCapacity * 4]; + _tris = new int[_arrayCapacity * 6]; + _allBeadPosArr = new Vector3[_arrayCapacity]; + for (int i = 0; i < _arrayCapacity; i++) + { + _tris[i * 6] = i * 4; + _tris[i * 6 + 1] = i * 4 + 2; + _tris[i * 6 + 2] = i * 4 + 1; + _tris[i * 6 + 3] = i * 4; + _tris[i * 6 + 4] = i * 4 + 3; + _tris[i * 6 + 5] = i * 4 + 2; + } + _constantDistanceSq = constantDistance * constantDistance; + _invConstantDistance = 1f / constantDistance; + drawMesh = new Mesh(); + drawMesh.MarkDynamic(); + meshFilter.mesh = drawMesh; + if (beadPrefab != null) + { + SpriteRenderer component2 = beadPrefab.GetComponent(); + if (component2 != null) + { + meshRenderer.sortingLayerID = component2.sortingLayerID; + meshRenderer.sortingOrder = component2.sortingOrder; + } + } + SetupBeadMaterial(PersistableData.Instance.shopItemSprite[PersistableData.Instance.itemsData.currentShopItemId]); + } + + private void SetupBeadMaterial(Sprite sprite) + { + if (sprite == null) + { + return; + } + if (beadMaterial == null) + { + beadMaterial = new Material(Shader.Find("Sprites/Default")); + } + beadMaterial.mainTexture = sprite.texture; + beadMaterial.color = new Color(0f, 0f, 0f, 1f); + meshRenderer.material = beadMaterial; + Rect textureRect = sprite.textureRect; + Texture2D texture = sprite.texture; + uvBL = new Vector2(textureRect.x / (float)texture.width, textureRect.y / (float)texture.height); + uvTR = new Vector2((textureRect.x + textureRect.width) / (float)texture.width, (textureRect.y + textureRect.height) / (float)texture.height); + uvBR = new Vector2((textureRect.x + textureRect.width) / (float)texture.width, textureRect.y / (float)texture.height); + uvTL = new Vector2(textureRect.x / (float)texture.width, (textureRect.y + textureRect.height) / (float)texture.height); + if (_verts != null) + { + RefillUVArray(); + } + } + + private void RefillUVArray() + { + for (int i = 0; i < _arrayCapacity; i++) + { + _uvs[i * 4] = uvBL; + _uvs[i * 4 + 1] = uvBR; + _uvs[i * 4 + 2] = uvTR; + _uvs[i * 4 + 3] = uvTL; + } + } + + public void UpdatePooledBeadSprite(Sprite newSprite) + { + SetupBeadMaterial(newSprite); + } + + private void OnEnable() + { + GameManager.OnGameStarts += OnGameStarts; + GameManager.OnLineDrawingComplete += IsLineDrawingComplete; + } + + private void OnDisable() + { + GameManager.OnGameStarts -= OnGameStarts; + GameManager.OnLineDrawingComplete -= IsLineDrawingComplete; + } + + private void OnGameStarts() + { + linePhysicsMat = GameManager.Instance.lineDrawPhysics2dMat; + IsGameStarted = true; + } + + private void IsLineDrawingComplete() + { + IsLineDrawn = true; + } + + private void Update() + { + if (!IsGameStarted) + { + return; + } + if (AppConstants.IsDialogueOpened) + { + return; + } + if (AppConstants.IsAnyPanelOpen) + { + return; + } + + if (Input.touchCount > 0) + { + HandleTouchInput(); + } + else + { + HandleMouseInput(); + } + if (!hasMoved) + { + return; + } + if (myAudioSource == null) + { + return; + } + if (!AppConstants.isSound) + { + return; + } + if (isDrawing && Time.time - lastBeadTime < soundPauseDelay) + { + if (!myAudioSource.isPlaying) + { + myAudioSource.UnPause(); + } + } + else if (myAudioSource.isPlaying) + { + myAudioSource.Pause(); + } + } + + private void HandleMouseInput() + { + if (Input.GetMouseButtonDown(0)) + { + touchDownScreenPos = Input.mousePosition; + touchDownRecorded = true; + return; + } + if (Input.GetMouseButton(0)) + { + if (IsLineDrawn) + { + return; + } + bool flag = IsMouseInsideDrawArea(); + bool flag2 = isDrawing; + if (flag) + { + if (!flag2) + { + Vector3 mousePosition = Input.mousePosition; + float num = mousePosition.x - touchDownScreenPos.x; + float num2 = mousePosition.y - touchDownScreenPos.y; + if (Mathf.Sqrt(num * num + num2 * num2) < minMovePixels) + { + return; + } + StartDrawing(); + } + if (currentExitSide != ExitSide.None) + { + currentExitSide = ExitSide.None; + } + ContinueDrawing(); + return; + } + if (!flag2) + { + return; + } + if (cantHitBorder) + { + StopDrawing(); + return; + } + DetectExitSide(Input.mousePosition); + ContinueDrawing(); + return; + } + if (Input.GetMouseButtonUp(0)) + { + bool isLineDrawn = IsLineDrawn; + touchDownRecorded = false; + currentExitSide = ExitSide.None; + if (isLineDrawn) + { + return; + } + if (!isDrawing) + { + return; + } + if (beadsSpawned >= 1) + { + if (GameManager.OnLineDrawingComplete != null) + { + GameManager.OnLineDrawingComplete(); + } + changeAction(); + } + StopDrawing(); + } + } + + private void HandleTouchInput() + { + if (Input.touchCount == 0) + { + return; + } + Touch touch = Input.GetTouch(0); + TouchPhase phase = touch.phase; + if (phase != TouchPhase.Ended && phase != TouchPhase.Canceled) + { + if (phase == TouchPhase.Moved) + { + if (IsLineDrawn) + { + return; + } + Vector2 position = touch.position; + bool flag = IsTouchInsideDrawArea(position); + bool flag2 = isDrawing; + if (flag) + { + if (!flag2) + { + Vector2 vector = touch.position; + float num = vector.x - touchDownScreenPos.x; + float num2 = vector.y - touchDownScreenPos.y; + if (Mathf.Sqrt(num * num + num2 * num2) < minMovePixels) + { + return; + } + StartDrawing(); + } + if (currentExitSide != ExitSide.None) + { + currentExitSide = ExitSide.None; + } + ContinueDrawing(); + return; + } + if (!flag2) + { + return; + } + if (cantHitBorder) + { + StopDrawing(); + return; + } + DetectExitSide(touch.position); + ContinueDrawing(); + return; + } + if (phase != TouchPhase.Began) + { + return; + } + touchDownScreenPos = touch.position; + touchDownRecorded = true; + return; + } + bool isLineDrawn = IsLineDrawn; + touchDownRecorded = false; + currentExitSide = ExitSide.None; + if (isLineDrawn) + { + return; + } + if (!isDrawing) + { + return; + } + if (beadsSpawned >= 1) + { + if (GameManager.OnLineDrawingComplete != null) + { + GameManager.OnLineDrawingComplete(); + } + changeAction(); + } + StopDrawing(); + } + + private bool IsMouseInsideDrawArea() + { + Vector3 mousePosition = Input.mousePosition; + return drawArea.OverlapPoint(mainCamera.ScreenToWorldPoint(new Vector3(mousePosition.x, mousePosition.y, 10f))); + } + + private bool IsTouchInsideDrawArea(Vector2 touchPosition) + { + return drawArea.OverlapPoint(mainCamera.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, 10f))); + } + + private void StartDrawing() + { + previousPoint = GetInputWorldPoint(); + _boundsMin = new Vector3(float.MaxValue, float.MaxValue, -1f); + _boundsMax = new Vector3(-3.4028235E+38f, -3.4028235E+38f, 1f); + _beadPosCount = 0; + _quadCount = 0; + drawMesh.Clear(); + beadsSpawned = 0; + hasMoved = false; + _drawingBlocked = false; + EyeBallTracker.IsDrawBlocked = false; + if (drawBlockingLayers != 0) + { + Vector3 vector = mainCamera.ScreenToWorldPoint(new Vector3(touchDownScreenPos.x, touchDownScreenPos.y, 10f)); + _externalDragStart = Physics2D.OverlapPoint(vector, drawBlockingLayers) != null; + } + else + { + _externalDragStart = false; + } + isDrawing = true; + if (GameManager.OnLineDrawingStarts != null) + { + GameManager.OnLineDrawingStarts(); + } + if (GameManager.OnHintHideCalled != null) + { + GameManager.OnHintHideCalled(LevelScript.Instance.isWheelLevel); + } + if (CharacterAction.EnemyAction != null) + { + CharacterAction.EnemyAction(1); + } + EyeBallTracker.LookTarget = null; + } + + private void changeAction() + { + if (CharacterAction.EnemyAction != null) + { + CharacterAction.EnemyAction(2); + } + if (isToolLevel && toolRigidbodies != null && toolRigidbodies.Length > 0 && toolRigidbodies[0] != null) + { + EyeBallTracker.LookTarget = toolRigidbodies[0].transform; + } + else + { + EyeBallTracker.LookTarget = null; + } + } + + private void ContinueDrawing() + { + Vector3 vector = GetEffectiveDrawPosition(); + if (_externalDragStart) + { + bool flag = drawBlockingLayers != 0 && Physics2D.OverlapPoint(vector, drawBlockingLayers) != null; + previousPoint = vector; + if (flag) + { + return; + } + _externalDragStart = false; + } + if (drawBlockingLayers != 0 && (Physics2D.OverlapPoint(vector, drawBlockingLayers) != null || Physics2D.Linecast(previousPoint, vector, drawBlockingLayers).collider != null)) + { + _drawingBlocked = true; + EyeBallTracker.IsDrawBlocked = true; + EyeBallTracker.DrawBlockedLookPoint = previousPoint; + return; + } + if (_drawingBlocked) + { + float num = vector.x - previousPoint.x; + float num2 = vector.y - previousPoint.y; + if (Mathf.Sqrt(num * num + num2 * num2) > constantDistance * 512f) + { + return; + } + if (Physics2D.Linecast(previousPoint, vector, drawBlockingLayers).collider != null) + { + return; + } + _drawingBlocked = false; + EyeBallTracker.IsDrawBlocked = false; + vector = previousPoint + (vector - previousPoint) * 0.25f; + } + Vector3 vector2 = vector - previousPoint; + float num3 = vector2.x * vector2.x + vector2.y * vector2.y + vector2.z * vector2.z; + if (num3 < _constantDistanceSq) + { + return; + } + int num4 = (int)(Mathf.Sqrt(num3) * _invConstantDistance) + 2; + float num5 = ((num4 >= 2) ? (1f / (float)(num4 - 1)) : 0f); + if (!hasMoved) + { + if (AppConstants.isSound) + { + myAudioSource.clip = SoundManager.instance.Drawing; + myAudioSource.loop = true; + myAudioSource.Play(); + } + hasMoved = true; + } + Vector3 p = previousPoint + vector2 * 0.1f; + Vector3 p2 = vector - vector2 * 0.1f; + for (int i = 0; i < num4; i++) + { + AddBeadToMesh(CubicBezierLerp(previousPoint, p, p2, vector, (float)i * num5)); + beadsSpawned++; + } + ApplyMesh(); + if (Time.time - lastVibrateTime >= vibrateInterval) + { + AppConstants.AndroidVibrate(10L); + lastVibrateTime = Time.time; + } + previousPoint = vector; + } + + private void GrowArrays() + { + int arrayCapacity = _arrayCapacity; + int num = arrayCapacity * 2; + Array.Resize(ref _verts, num * 4); + Array.Resize(ref _uvs, num * 4); + Array.Resize(ref _tris, num * 6); + Array.Resize(ref _allBeadPosArr, num); + for (int i = arrayCapacity; i < num; i++) + { + _tris[i * 6] = i * 4; + _tris[i * 6 + 1] = i * 4 + 2; + _tris[i * 6 + 2] = i * 4 + 1; + _tris[i * 6 + 3] = i * 4; + _tris[i * 6 + 4] = i * 4 + 3; + _tris[i * 6 + 5] = i * 4 + 2; + } + for (int j = arrayCapacity * 4; j < num * 4; j += 4) + { + _uvs[j] = uvBL; + _uvs[j + 1] = uvBR; + _uvs[j + 2] = uvTR; + _uvs[j + 3] = uvTL; + } + _arrayCapacity = num; + } + + private void AddBeadToMesh(Vector3 pos) + { + if (_quadCount >= _arrayCapacity) + { + GrowArrays(); + } + _allBeadPosArr[_beadPosCount++] = pos; + int num = _quadCount * 4; + float x = pos.x; + float y = pos.y; + _verts[num] = new Vector3(x - beadHalfSize, y - beadHalfSize, pos.z); + _verts[num + 1] = new Vector3(x + beadHalfSize, y - beadHalfSize, pos.z); + _verts[num + 2] = new Vector3(x + beadHalfSize, y + beadHalfSize, pos.z); + _verts[num + 3] = new Vector3(x - beadHalfSize, y + beadHalfSize, pos.z); + if (x - beadHalfSize < _boundsMin.x) + { + _boundsMin.x = x - beadHalfSize; + } + if (y - beadHalfSize < _boundsMin.y) + { + _boundsMin.y = y - beadHalfSize; + } + if (x + beadHalfSize > _boundsMax.x) + { + _boundsMax.x = x + beadHalfSize; + } + if (y + beadHalfSize > _boundsMax.y) + { + _boundsMax.y = y + beadHalfSize; + } + _quadCount++; + } + + private void ApplyMesh() + { + if (_quadCount == 0) + { + return; + } + drawMesh.Clear(); + int num = _quadCount * 4; + drawMesh.SetVertices(_verts, 0, num); + drawMesh.SetUVs(0, _uvs, 0, num); + drawMesh.SetTriangles(_tris, 0, _quadCount * 6, 0); + drawMesh.bounds = new Bounds((_boundsMax + _boundsMin) * 0.5f, (_boundsMax - _boundsMin) * 0.5f); + } + + public void SetLineStatic() + { + if (parentObject == null) + { + return; + } + Rigidbody2D component = parentObject.GetComponent(); + if (component != null) + { + component.bodyType = RigidbodyType2D.Static; + } + if (toolRigidbodies == null) + { + return; + } + for (int i = 0; i < toolRigidbodies.Length; i++) + { + Rigidbody2D rigidbody2D = toolRigidbodies[i]; + if (rigidbody2D != null) + { + rigidbody2D.bodyType = RigidbodyType2D.Static; + } + } + } + + private void StopDrawing() + { + isDrawing = false; + hasMoved = false; + _drawingBlocked = false; + _externalDragStart = false; + EyeBallTracker.IsDrawBlocked = false; + if (myAudioSource != null) + { + myAudioSource.loop = false; + myAudioSource.Stop(); + } + if (_beadPosCount == 0) + { + return; + } + Vector2[] array = new Vector2[_beadPosCount]; + Vector2 vector = Vector2.zero; + for (int i = 0; i < _beadPosCount; i++) + { + array[i] = _allBeadPosArr[i]; + vector += array[i]; + } + Vector3 position = parentObject.transform.position; + Vector2 vector2 = array[0] - array[array.Length - 1]; + float num = Mathf.Sqrt(vector2.x * vector2.x + vector2.y * vector2.y); + bool flag = num < 0.6f; + bool flag2 = LevelScript.Instance != null && LevelScript.Instance.isMovingPlatformLevel; + bool flag3 = LevelScript.Instance != null && LevelScript.Instance.isWheelLevel; + float num2 = (flag ? 0.08f : 0.15f); + int num3 = ((flag3 || flag2) ? MAX_COLLIDER_POINTS : 30); + Vector2[] array2 = SimplifyPoints(array, num2); + while (num2 < 2f && num3 < array2.Length) + { + num2 *= 2f; + array2 = SimplifyPoints(array, num2); + } + if (flag) + { + Vector2[] array3 = new Vector2[array2.Length + 1]; + Array.Copy(array2, array3, array2.Length); + array3[array3.Length - 1] = array2[0]; + array2 = array3; + } + Debug.Log(string.Format("Original: {0} | Simplified: {1} | Closed: {2} | Tol: {3:F4} | MovingPlatform: {4}", _beadPosCount, array2.Length, flag, num2, flag2)); + SetupChunkedColliders(array2); + if (testMode) + { + return; + } + Rigidbody2D rigidbody2D = parentObject.GetComponent(); + if (rigidbody2D != null) + { + rigidbody2D.interpolation = RigidbodyInterpolation2D.None; + rigidbody2D.centerOfMass = new Vector2(vector.x / (float)_beadPosCount - position.x, vector.y / (float)_beadPosCount - position.y); + rigidbody2D.collisionDetectionMode = CollisionDetectionMode2D.Continuous; + rigidbody2D.bodyType = RigidbodyType2D.Dynamic; + rigidbody2D.velocity = Vector2.zero; + rigidbody2D.angularVelocity = 0f; + StartCoroutine(RestoreInterpolation(rigidbody2D)); + StartCoroutine(CheckLineStuck(rigidbody2D)); + } + } + + private IEnumerator RestoreInterpolation(Rigidbody2D rb) + { + yield return new WaitForFixedUpdate(); + if (rb != null) + { + rb.interpolation = RigidbodyInterpolation2D.Interpolate; + } + } + + private IEnumerator CheckLineStuck(Rigidbody2D rb) + { + yield return new WaitForSeconds(1f); + bool flag = LevelScript.Instance != null && LevelScript.Instance.isMovingPlatformLevel; + float num = 0f; + bool flag2 = isToolLevel && toolRigidbodies != null && toolRigidbodies.Length > 0; + int num2 = (flag2 ? toolRigidbodies.Length : 0); + float num3 = 0f; + Vector2 vector = rb.position; + Camera cam = Camera.main; + float[] array = new float[num2]; + Vector2[] array2 = new Vector2[num2]; + float[] array3 = new float[num2]; + for (int i = 0; i < num2; i++) + { + Rigidbody2D rigidbody2D = toolRigidbodies[i]; + array2[i] = ((rigidbody2D != null) ? rigidbody2D.position : Vector2.zero); + array3[i] = ((rigidbody2D != null) ? rigidbody2D.rotation : 0f); + } + float num4 = 0f; + while (GameManager.Instance != null && !GameManager.Instance.IsGameEnded && rb != null) + { + num += 0.25f; + if (flag && num >= movingPlatformTimeLimit) + { + goto LineStuckFail; + } + Vector2 position = rb.position; + bool flag3 = false; + if (cam != null) + { + Vector3 vector2 = cam.WorldToViewportPoint(position); + flag3 = vector2.y > 1.5f || vector2.y < -0.5f || vector2.x < -0.5f || vector2.x > 1.5f; + } + if (flag3) + { + num4 += 0.25f; + } + else + { + num4 = 0f; + } + if (cam != null && !flag3 && flag2) + { + for (int j = 0; j < num2; j++) + { + Rigidbody2D rigidbody2D2 = toolRigidbodies[j]; + if (rigidbody2D2 == null) + { + continue; + } + Vector3 vector3 = cam.WorldToViewportPoint(rigidbody2D2.position); + if (vector3.y > 1.5f || vector3.y < -0.5f || vector3.x < -0.5f || vector3.x > 1.5f) + { + array[j] += 0.25f; + } + else + { + array[j] = 0f; + } + if (array[j] >= 0.5f && (num4 >= 0.5f || (position - vector).magnitude < LinemovedThreshold)) + { + goto LineStuckFail; + } + } + } + if (flag3 && !flag2 && num4 >= 0.5f) + { + goto LineStuckFail; + } + if (num4 >= 0.5f && num2 > 0) + { + for (int k = 0; k < num2; k++) + { + Rigidbody2D rigidbody2D3 = toolRigidbodies[k]; + if (rigidbody2D3 == null) + { + continue; + } + Vector2 position2 = rigidbody2D3.position; + float rotation = rigidbody2D3.rotation; + float num5 = Mathf.DeltaAngle(rotation, array3[k]); + if ((position2 - array2[k]).magnitude < LinemovedThreshold && Mathf.Abs(num5) < 0.2f) + { + goto LineStuckFail; + } + } + } + Vector2 vector4 = vector; + vector = position; + float linemovedThreshold = LinemovedThreshold; + bool flag4 = true; + if (flag2 && num2 > 0) + { + for (int l = 0; l < num2; l++) + { + Rigidbody2D rigidbody2D4 = toolRigidbodies[l]; + if (rigidbody2D4 == null) + { + continue; + } + Vector2 vector5 = rigidbody2D4.position; + Vector2 vector6 = array2[l]; + float rotation2 = rigidbody2D4.rotation; + float num6 = Mathf.DeltaAngle(rotation2, array3[l]); + array2[l] = vector5; + array3[l] = rotation2; + if (Mathf.Abs(num6) >= 0.2f || (vector5 - vector6).magnitude >= linemovedThreshold) + { + flag4 = false; + break; + } + } + } + if (flag4 && (position - vector4).magnitude < linemovedThreshold) + { + num3 += 0.25f; + if (!flag && num3 >= 0.5f) + { + goto LineStuckFail; + } + } + else + { + num3 = 0f; + } + yield return new WaitForSeconds(0.25f); + } + yield break; + LineStuckFail: + if (!GameManager.Instance.IsGameEnded && GameManager.EnemyList.Count >= 1) + { + GameManager.Instance.CheckLevelFailed(); + } + yield break; + } + + private Vector3 CubicBezierLerp(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t) + { + float num = 1f - t; + float num2 = num * num; + float num3 = num2 * num; + float num4 = t * t; + float num5 = num4 * t; + return num3 * p0 + 3f * num2 * t * p1 + 3f * num * num4 * p2 + num5 * p3; + } + + private Vector2[] SimplifyPoints(Vector2[] points, float tolerance) + { + if (points.Length < 3) + { + return points; + } + List list = new List(); + RDP(points, 0, points.Length - 1, tolerance * tolerance, list); + list.Add(points[points.Length - 1]); + return list.ToArray(); + } + + private void RDP(Vector2[] pts, int s, int e, float tolSq, List result) + { + if (s + 1 < e) + { + float num = 0f; + int num2 = s; + for (int i = s + 1; i < e; i++) + { + float num3 = PerpendicularDistanceSq(pts[i], pts[s], pts[e]); + if (num3 > num) + { + num2 = i; + num = num3; + } + } + if (num > tolSq) + { + RDP(pts, s, num2, tolSq, result); + RDP(pts, num2, e, tolSq, result); + return; + } + } + result.Add(pts[s]); + } + + private void SetupChunkedColliders(Vector2[] points) + { + int num = points.Length; + int num2 = Mathf.CeilToInt((float)(num - 1) / 60f); + while (_colliderPool.Count < num2) + { + EdgeCollider2D edgeCollider2D = parentObject.AddComponent(); + edgeCollider2D.enabled = false; + _colliderPool.Add(edgeCollider2D); + } + if (num2 < _activeChunks) + { + for (int i = num2; i < _activeChunks; i++) + { + _colliderPool[i].enabled = false; + } + } + _activeChunks = num2; + for (int j = 0; j < num2; j++) + { + int num3 = j * 59; + int num4 = Mathf.Min(num3 + 60, points.Length) - num3; + Vector2[] array = new Vector2[num4]; + Array.Copy(points, num3, array, 0, num4); + EdgeCollider2D edgeCollider2D2 = _colliderPool[j]; + edgeCollider2D2.sharedMaterial = linePhysicsMat; + edgeCollider2D2.points = array; + edgeCollider2D2.enabled = true; + } + } + + private float PerpendicularDistanceSq(Vector2 point, Vector2 lineStart, Vector2 lineEnd) + { + Vector2 vector = lineEnd - lineStart; + float num = vector.x * vector.x + vector.y * vector.y; + float num2 = point.x - lineStart.x; + float num3 = point.y - lineStart.y; + if (num == 0f) + { + return num2 * num2 + num3 * num3; + } + float num4 = Mathf.Clamp01((num2 * vector.x + num3 * vector.y) / num); + Vector2 vector2 = lineStart + vector * num4; + float num5 = point.x - vector2.x; + float num6 = point.y - vector2.y; + return num5 * num5 + num6 * num6; + } + + private Vector3 GetEffectiveDrawPosition() + { + Vector3 result = GetInputWorldPoint(); + if (currentExitSide != ExitSide.None) + { + Bounds bounds = drawArea.bounds; + Vector3 center = bounds.center; + Vector3 extents = bounds.extents; + float num = center.x + extents.x; + float num2 = center.x - extents.x; + float num3 = center.y + extents.y; + float num4 = center.y - extents.y; + if (currentExitSide == ExitSide.Left || currentExitSide == ExitSide.Right) + { + result.x = exitLockValue; + result.y = Mathf.Clamp(result.y, num4, num3); + } + else if (currentExitSide == ExitSide.Top || currentExitSide == ExitSide.Bottom) + { + result.x = Mathf.Clamp(result.x, num2, num); + result.y = exitLockValue; + } + } + return result; + } + + private void DetectExitSide(Vector2 screenPos) + { + Vector3 vector = mainCamera.ScreenToWorldPoint(new Vector3(screenPos.x, screenPos.y, 10f)); + Bounds bounds = drawArea.bounds; + Vector3 center = bounds.center; + Vector3 extents = bounds.extents; + float num = center.x + extents.x; + float num2 = center.x - extents.x; + float num3 = center.y + extents.y; + float num4 = center.y - extents.y; + float x = vector.x; + float y = vector.y; + ExitSide exitSide; + float num5; + if (x <= num && x >= num2 && y < num4) + { + exitSide = ExitSide.Bottom; + num5 = num4; + } + else if (x <= num && x >= num2 && y > num3) + { + exitSide = ExitSide.Top; + num5 = num3; + } + else if (y <= num3 && y >= num4 && x < num2) + { + exitSide = ExitSide.Left; + num5 = num2; + } + else if (y <= num3 && y >= num4 && x > num) + { + exitSide = ExitSide.Right; + num5 = num; + } + else + { + float num6 = num2 - x; + float num7 = x - num; + float num8 = num4 - y; + float num9 = y - num3; + float[] array = new float[4]; + array[0] = ((x < num2) ? num6 : float.MaxValue); + array[1] = ((x > num) ? num7 : float.MaxValue); + array[2] = ((y < num4) ? num8 : float.MaxValue); + array[3] = ((y > num3) ? num9 : float.MaxValue); + float num10 = Mathf.Min(array); + if (y < num4 && Mathf.Approximately(num10, num8)) + { + exitSide = ExitSide.Bottom; + num5 = num4; + } + else if (y > num3 && Mathf.Approximately(num10, num9)) + { + exitSide = ExitSide.Top; + num5 = num3; + } + else if (x < num2 && Mathf.Approximately(num10, num6)) + { + exitSide = ExitSide.Left; + num5 = num2; + } + else + { + exitSide = ExitSide.Right; + num5 = num; + } + } + if (currentExitSide != exitSide) + { + currentExitSide = exitSide; + exitLockValue = num5; + } + } + + private Vector3 GetInputWorldPoint() + { + + Vector2 screenPos = Input.touchCount > 0 ? Input.GetTouch(0).position : new Vector2(Input.mousePosition.x, Input.mousePosition.y); + return mainCamera.ScreenToWorldPoint(new Vector3(screenPos.x, screenPos.y, 10f)); + } +} diff --git a/GameManager.cs b/GameManager.cs new file mode 100644 index 0000000..22f860a --- /dev/null +++ b/GameManager.cs @@ -0,0 +1,792 @@ +using System; +using System.Collections.Generic; +using DG.Tweening; +using Monetization.Runtime.Ads; +using MoreMountains.NiceVibrations; +using UnityEngine; +using UnityEngine.UI; + +public class GameManager : Singleton +{ + public PhysicsMaterial2D lineDrawPhysics2dMat; + + public EnvironmentClass[] environmentSkinsList; + + public static Action OnGameStarts; + + public static Action OnStoreClosed; + + public static Action OnLevelComplete; + + public static Action OnNewEnemyUnlocked; + + public static Action OnGameComplete; + + public static Action OnLevelFailed; + + public static Action OnNoInternetAvailable; + + public static Action OnLineDrawingStarts; + + public static Action OnLineDrawingComplete; + + public static Action OnEnemyHit; + + public static Action OnPointDraw; + + public static Action OnHintShowCalled; + + public static Action OnHintHideCalled; + + public static Action OnCoinGrant; + + public static List EnemyList = new List(); + + public static List FriendList = new List(); + + public static Action OnMusicToggle; + + public static Action OnSoundAudioToggle; + + public static Action OnLevelReload; + + public static Action OnShopItemSelection; + + public static Action OnEnvironmentChange; + + public Image flashScreenPanel; + + public Image bloodFadeOverlay; + + private bool isInit; + + public Button[] gameplayUiBtns; + + public Button skinBtn; + + public GameObject lineParentTr; + + [Header("UI Slide Out Animation")] + public RectTransform[] leftSideUI; + + public RectTransform[] rightSideUI; + + public RectTransform levelNumBar; + + public GameObject happyEmojis; + + public GameObject sadEmojis; + + public Button hintBtn; + + public GameObject hintRewardedIcon; + + public GameObject noOfHintsObj; + + public Text noOfHintsText; + + public CanvasGroup hintGlowCanvasGroup; + + public ParticleSystem hintSparkleParticles; + + [Header("Splash Canvas (shown before interstitial ad)")] + public GameObject splashCanvas; + + [Header("Confetti Win GO (Is_PanelTest == 3)")] + public GameObject confettiOnWin; + + public static bool isGamePlayedOnce = false; + + public static bool anyFriendDied = false; + + private bool isEmojiSpawned; + + public GameObject storePanelObj; + + private bool rewardedHintVideoClicked; + + private Color _hintGlowBaseColor; + + private bool _hintGlowColorCached; + + private bool isLevelFailed; + + private bool isLevelCompleted; + + private bool isShowingPopUp; + + private static int lastFailedLevelNum_PanelTest4 = -1; + + private static int _failAttemptLevel = -1; + + private static int _failAttemptCount = 0; + + public bool IsGameEnded => isLevelFailed || isLevelCompleted; + + public static int FreeHintsUsed + { + get + { + if (PlayerPrefs.GetInt("FirstHintFree", 0) == 1 && PlayerPrefs.GetInt("FreeHintsMigrated", 0) == 0) + { + PlayerPrefs.SetInt("FreeHintsUsed", Mathf.Max(PlayerPrefs.GetInt("FreeHintsUsed", 0), 1)); + PlayerPrefs.SetInt("FreeHintsMigrated", 1); + PlayerPrefs.Save(); + } + return PlayerPrefs.GetInt("FreeHintsUsed", 0); + } + } + + public static bool FreeHintsRemaining => FreeHintsUsed < AdConstants.free_hints_count + BonusFreeHints; + + public static int BonusFreeHints + { + get + { + return PlayerPrefs.GetInt("BonusFreeHints", 0); + } + set + { + PlayerPrefs.SetInt("BonusFreeHints", value); + PlayerPrefs.Save(); + } + } + + private void Start() + { + + if (!AdConstants.AdsRemoved && (AdConstants.Is_PanelTest == 2 || AdConstants.Is_PanelTest == 3 || AdConstants.Is_PanelTest == 4)) + { + AdsManager.HideMRec(); + if (UiManager.Instance != null) + { + UiManager.Instance.BannerPati.SetActive(true); + } + } + InitGame(); + } + + private void InitGame() + { + if (isInit) + { + return; + } + print("Game Started"); + AppConstants.IsDialogueOpened = false; + if (PlayerPrefs.GetInt("CurrentZoneLevel" + AppConstants.currentCharacterIndex) == 0) + { + PlayerPrefs.SetInt("CurrentZoneLevel" + AppConstants.currentCharacterIndex, 1); + } + anyFriendDied = false; + isLevelFailed = false; + isLevelCompleted = false; + if (hintBtn != null && PlayerPrefs.GetInt("HintBtnUnlocked", 0) == 0) + { + hintBtn.gameObject.SetActive(false); + } + RefreshHintCounterDisplay(); + Invoke("StartGame", 0.1f); + if (isGamePlayedOnce) + { + if (PlayerPrefs.GetInt("IsRated") == 0 && !AppConstants.isRetryingLevel && Array.IndexOf(AppConstants.RatePanelLevels, PersistableData.Instance.itemsData.currentLevelNumProgressive) >= 0) + { + UiManager.Instance.ShowRatePopUp(); + } + if (PersistableData.Instance.itemsData.currentLevelNumProgressive % AppConstants.ShowNewSkinAtLevel != 0 && LevelManager.currentLevel == 6 && PlayerPrefs.GetInt("CurrentLevelNum") == 5 && PlayerPrefs.GetInt("ShopIndicationShown") == 0) + { + PlayerPrefs.SetInt("ShopIndicationShown", 1); + Invoke("OpenShopStoreWithTutorialPanel", 0.5f); + } + } + isInit = true; + } + + private void OpenShopStoreWithTutorialPanel() + { + SoundManager soundManager = SoundManager.instance; + if (soundManager != null && soundManager.gameSoundSFX != null) + { + soundManager.PlaySFX_UI(soundManager.gameSoundSFX.TutorialScreenAppear, 1f); + } + storePanelObj.gameObject.SetActive(true); + } + + private void OnEnable() + { + OnLineDrawingStarts += OnHideGameUi; + OnEnemyHit += OnEnemyHitEffect; + OnGameComplete += OnGameCompletion; + OnLineDrawingComplete += CheckFriendOnlyLevel; + } + + private void OnDisable() + { + OnLineDrawingStarts -= OnHideGameUi; + OnGameComplete -= OnGameCompletion; + OnEnemyHit -= OnEnemyHitEffect; + OnLineDrawingComplete -= CheckFriendOnlyLevel; + } + + public void SpawnEmoji(GameObject emojiPrefab) + { + if (!isEmojiSpawned) + { + Instantiate(emojiPrefab); + isEmojiSpawned = true; + } + } + + private void CheckFriendOnlyLevel() + { + if (LevelScript.Instance == null) + { + return; + } + if (!LevelScript.Instance.isFriendLevel) + { + return; + } + if (EnemyList.Count != 0) + { + return; + } + if (FriendList.Count < 1) + { + return; + } + Invoke("TryCompleteFriendOnlyLevel", LevelScript.Instance.friendOnlyCompleteDelay); + } + + private void TryCompleteFriendOnlyLevel() + { + if (!isLevelFailed && !isLevelCompleted && !anyFriendDied) + { + CheckLevelComplete(); + } + } + + private void OnEnemyHitEffect() + { + + } + + private void StartGame() + { + OnGameStarts?.Invoke(); + } + + public void IsObjectDropCompleted() + { + AppConstants.Haptic(HapticTypes.LightImpact); + Invoke("changeAction", 1.5f); + } + + private void changeAction() + { + if (CharacterAction.EnemyAction != null) + { + CharacterAction.EnemyAction(3); + } + } + + public void ShowHint() + { + if (rewardedHintVideoClicked) + { + return; + } + UiManager.Instance.SettingPanelAnim.SetBool("SettingIn", false); + UiManager.Instance.SettingPanelAnim.SetBool("SettingOut", true); + UiManager.Instance.isSettingsOpen = false; + if (FreeHintsRemaining) + { + int num = FreeHintsUsed + 1; + PlayerPrefs.SetInt("FreeHintsUsed", num); + PlayerPrefs.Save(); + LevelAnalytics.Send("Hint_Free_" + num); + HintGranted(); + return; + } + LevelAnalytics.Send("Hint_Watch"); + + HintGranted(); + } + + private void HintGranted() + { + if (isLevelCompleted) + { + return; + } + AppConstants.Haptic(HapticTypes.Selection); + SoundManager soundManager = SoundManager.instance; + if (soundManager != null && soundManager.gameSoundSFX != null) + { + soundManager.PlaySFX_UI(soundManager.gameSoundSFX.hintShownSound, 1f); + } + OnHintShowCalled?.Invoke(); + hintBtn.transform.DOKill(false); + hintBtn.transform.localScale = Vector3.one; + StopHintGlowAnim(); + hintBtn.gameObject.SetActive(false); + if (LevelManager.instance.hintTutorialObj != null) + { + LevelManager.instance.hintTutorialObj.SetActive(false); + } + if (hintRewardedIcon != null) + { + hintRewardedIcon.SetActive(true); + } + PlayerPrefs.SetInt("HintWatched_" + LevelManager.instance.currentLevelNumberToShow, 1); + PlayerPrefs.Save(); + rewardedHintVideoClicked = false; + } + + private void ResetShowHintBtnClickAgain() + { + rewardedHintVideoClicked = false; + } + + public void ShowHintButton(bool playBreath = false) + { + hintBtn.gameObject.SetActive(true); + hintBtn.transform.DOKill(false); + hintBtn.transform.localScale = Vector3.one; + bool freeHintsRemaining = FreeHintsRemaining; + if (hintRewardedIcon != null) + { + hintRewardedIcon.SetActive(!freeHintsRemaining); + } + if (noOfHintsObj != null) + { + noOfHintsObj.SetActive(freeHintsRemaining); + } + if (noOfHintsText != null && freeHintsRemaining) + { + noOfHintsText.text = (BonusFreeHints + AdConstants.free_hints_count - FreeHintsUsed).ToString(); + } + if (!freeHintsRemaining && playBreath) + { + StartHintBreathAnim(); + } + else + { + StopHintGlowAnim(); + } + } + + public void RefreshHintCounterDisplay() + { + if (hintBtn == null) + { + return; + } + bool freeHintsRemaining = FreeHintsRemaining; + if (hintRewardedIcon != null) + { + hintRewardedIcon.SetActive(!freeHintsRemaining); + } + if (noOfHintsObj != null) + { + noOfHintsObj.SetActive(freeHintsRemaining); + } + if (noOfHintsText != null && freeHintsRemaining) + { + noOfHintsText.text = (BonusFreeHints + AdConstants.free_hints_count - FreeHintsUsed).ToString(); + } + } + + private void StartHintBreathAnim() + { + if (hintGlowCanvasGroup == null) + { + return; + } + hintGlowCanvasGroup.DOKill(false); + hintGlowCanvasGroup.alpha = 1f; + int step = 0; + hintGlowCanvasGroup.DOFade(0f, 1f).SetLoops(-1, LoopType.Yoyo).SetEase(Ease.InOutSine) + .OnStepComplete(delegate + { + step++; + if (step % 2 == 0 && hintSparkleParticles != null) + { + hintSparkleParticles.Play(); + } + }); + Image image = hintGlowCanvasGroup.GetComponent(); + if (image != null) + { + if (!_hintGlowColorCached) + { + _hintGlowBaseColor = image.color; + _hintGlowColorCached = true; + } + image.DOKill(false); + image.DOColor(new Color(Mathf.Min(_hintGlowBaseColor.r * 1.15f, 1f), Mathf.Min(_hintGlowBaseColor.g * 1.05f, 1f), Mathf.Min(_hintGlowBaseColor.b * 1.4f, 1f), _hintGlowBaseColor.a), 1f).SetLoops(-1, LoopType.Yoyo) + .SetEase(Ease.InOutSine); + } + } + + private void StopHintGlowAnim() + { + if (hintGlowCanvasGroup == null) + { + return; + } + hintGlowCanvasGroup.DOKill(false); + hintGlowCanvasGroup.alpha = 1f; + Image image = hintGlowCanvasGroup.GetComponent(); + if (image != null) + { + image.DOKill(false); + if (_hintGlowColorCached) + { + image.color = _hintGlowBaseColor; + } + } + if (hintSparkleParticles != null) + { + hintSparkleParticles.Stop(); + } + } + + public void ShowHintThroughCode() + { + OnHintShowCalled?.Invoke(); + hintBtn.transform.DOKill(false); + hintBtn.transform.localScale = Vector3.one; + StopHintGlowAnim(); + hintBtn.gameObject.SetActive(false); + } + + private void OnGameCompletion() + { + skinBtn.interactable = false; + isLevelCompleted = true; + } + + private void OnHideGameUi() + { + for (int i = 0; i < leftSideUI.Length; i++) + { + RectTransform rt = leftSideUI[i]; + if (!(rt == null)) + { + rt.DOAnchorPosX(rt.anchoredPosition.x + -500f, 0.5f).SetEase(Ease.InBack).OnComplete(delegate + { + rt.gameObject.SetActive(false); + }); + } + } + for (int j = 0; j < rightSideUI.Length; j++) + { + RectTransform rt2 = rightSideUI[j]; + if (!(rt2 == null)) + { + rt2.DOAnchorPosX(rt2.anchoredPosition.x + 500f, 0.5f).SetEase(Ease.InBack).OnComplete(delegate + { + rt2.gameObject.SetActive(false); + }); + } + } + if (levelNumBar != null) + { + levelNumBar.DOAnchorPosY(levelNumBar.anchoredPosition.y + 500f, 0.5f).SetEase(Ease.InBack).OnComplete(delegate + { + levelNumBar.gameObject.SetActive(false); + }); + } + } + + public void CheckLevelFailed() + { + if (isLevelFailed || isLevelCompleted) + { + return; + } + if (EnemyList.Count < 1) + { + return; + } + AppConstants.isLevelFailedOnce = true; + isLevelFailed = true; + ShowLevelFailed(); + } + + public void CheckLevelFailedFreind() + { + if (isLevelFailed) + { + return; + } + anyFriendDied = true; + isLevelFailed = true; + isLevelCompleted = true; + CancelInvoke("ShowLevelCompleteScreen"); + CancelInvoke("ShowLevelComplete"); + Invoke("ShowLevelFailed", 0.5f); + } + + private void ShowLevelFailed() + { + OnLevelFailed?.Invoke(); + AppConstants.Haptic(HapticTypes.HeavyImpact); + ShowLevelFailedScreen(); + if (SoundManager.instance != null) + { + SoundManager.instance.StopMusic(); + } + } + + private void ConfettiSound() + { + SoundManager soundManager = SoundManager.instance; + if (soundManager != null && soundManager.gameSoundSFX != null) + { + soundManager.PlaySFX_UI(soundManager.gameSoundSFX.confettiSound, 1f); + } + Invoke("BGMUsic", 2f); + } + + private void BGMUsic() + { + SoundManager soundManager = SoundManager.instance; + if (soundManager != null) + { + soundManager.ChangeMusicWithTransition(soundManager.mainMenuMusicClip); + } + } + + public void CheckLevelComplete() + { + if (isLevelFailed || isLevelCompleted) + { + return; + } + if (anyFriendDied) + { + return; + } + if (EnemyList.Count > 0) + { + return; + } + isLevelCompleted = true; + OnLevelComplete?.Invoke(); + CancelInvoke("CheckLevelFailed"); + CancelInvoke("ShowLevelFailed"); + ShowLevelCompleteScreen(); + } + + private void ShowLevelCompleteScreen() + { + if (isLevelFailed || anyFriendDied) + { + return; + } + isGamePlayedOnce = true; + OnGameComplete?.Invoke(); + CancelInvoke("CheckLevelFailed"); + CancelInvoke("ShowLevelFailed"); + SoundManager soundManager = SoundManager.instance; + if (soundManager != null && soundManager.gameSoundSFX != null) + { + soundManager.PlaySFX_UI(soundManager.gameSoundSFX.winSfx, 1f); + } + ConfettiSound(); + ShowLevelComplete(); + } + + private void ShowLevelComplete() + { + AppConstants.levelsSinceLastInterstitial++; + LevelAnalytics.Send("Level_Comp_PT" + AdConstants.Is_PanelTest); + AppConstants.Haptic(HapticTypes.HeavyImpact); + if (LevelScript.Instance.levelType != LevelType.Pendulum && BeadDrawer.instance != null) + { + BeadDrawer.instance.SetLineStatic(); + } + SoundManager.instance.StopMusic(); + if (AdConstants.Is_PanelTest == 3 || AdConstants.Is_PanelTest == 4) + { + if (confettiOnWin != null) + { + confettiOnWin.SetActive(true); + } + if (LevelManager.instance != null) + { + LevelManager.instance.SetupCompScreenConfettiTest(); + } + return; + } + UiManager.Instance.LevelCompletePanel.gameObject.SetActive(true); + if (!AdConstants.AdsRemoved && (AdConstants.Is_PanelTest == 2 || AdConstants.Is_PanelTest == 3) && AdConstants.ShowMrecOnPanels) + { + + AdsManager.HideBanner(); + if (UiManager.Instance != null) + { + UiManager.Instance.BannerPati.SetActive(false); + } + AdsManager.RepositionMRec(MRecPosition.Bottom); + AdsManager.ShowMRec(); + } + if (AdConstants.Is_PanelTest != 1) + { + LevelManager.instance.SetupCompScreenNoPanelTest(); + } + } + + private void ShowLevelFailedScreen() + { + LevelManager levelManager = LevelManager.instance; + int currentLevelNumberToShow = levelManager.currentLevelNumberToShow; + if (_failAttemptLevel != currentLevelNumberToShow) + { + _failAttemptLevel = currentLevelNumberToShow; + _failAttemptCount = 0; + } + _failAttemptCount++; + LevelAnalytics.Send("Level_Fail_PT" + AdConstants.Is_PanelTest, "Attempt_" + _failAttemptCount); + if (AdConstants.Is_PanelTest == 4) + { + if (lastFailedLevelNum_PanelTest4 == LevelManager.instance.currentLevelNumberToShow) + { + SoundManager soundManager = SoundManager.instance; + if (soundManager != null && soundManager.gameSoundSFX != null) + { + soundManager.PlaySFX_UI(soundManager.gameSoundSFX.looseSfx, 1f); + } + if (bloodFadeOverlay != null) + { + bloodFadeOverlay.gameObject.SetActive(true); + Color color = bloodFadeOverlay.color; + color.a = 0f; + bloodFadeOverlay.color = color; + bloodFadeOverlay.DOKill(false); + bloodFadeOverlay.DOFade(0.8823529f, 1.5f).OnComplete(delegate + { + LevelManager.instance.ReloadLevelSilently(); + }); + } + else + { + LevelManager.instance.ReloadLevelSilently(); + } + return; + } + lastFailedLevelNum_PanelTest4 = LevelManager.instance.currentLevelNumberToShow; + } + if (LevelScript.Instance.levelType != LevelType.Pendulum && BeadDrawer.instance != null) + { + BeadDrawer.instance.SetLineStatic(); + } + UiManager.Instance.LevelFailedPanel.gameObject.SetActive(true); + if (!AdConstants.AdsRemoved && (AdConstants.Is_PanelTest == 2 || AdConstants.Is_PanelTest == 3 || AdConstants.Is_PanelTest == 4) && AdConstants.ShowMrecOnPanels) + { + + AdsManager.HideBanner(); + if (UiManager.Instance != null) + { + UiManager.Instance.BannerPati.SetActive(false); + } + AdsManager.RepositionMRec(MRecPosition.Bottom); + AdsManager.ShowMRec(); + } + if (UiManager.Instance.reloadBtnRect != null) + { + UiManager.Instance.reloadBtnRect.gameObject.SetActive(false); + } + SoundManager soundManager2 = SoundManager.instance; + if (soundManager2 != null && soundManager2.gameSoundSFX != null) + { + soundManager2.PlaySFX_UI(soundManager2.gameSoundSFX.looseSfx, 1f); + } + PlayerPrefs.SetInt("EverFailed", 1); + PlayerPrefs.Save(); + bool flag = LevelScript.Instance != null && LevelScript.Instance.isAutoHintLevel; + UiManager.Instance.ShowFailButtons(flag); + if (!flag) + { + PlayerPrefs.SetInt("HintBtnUnlocked", 1); + PlayerPrefs.Save(); + if (PlayerPrefs.GetInt("HintWatched_" + LevelManager.instance.currentLevelNumberToShow, 0) != 1) + { + ShowHintButton(true); + } + } + if (AdConstants.Is_PanelTest != 1) + { + LevelManager.instance.SetupFailScreenNoPanelTest(); + } + Invoke("BGMUsic", 3f); + } + + public void WatchAdForHintsPanel() + { + LevelAnalytics.Send("HintsPanel_WatchAd"); + + OnHintsPanelRewardGranted(); + } + + private void OnHintsPanelRewardGranted() + { + BonusFreeHints = BonusFreeHints + 3; + LevelAnalytics.Send("HintsPanel_Rewarded"); + ShowHintButton(false); + UiManager.Instance.CloseHintsPanel(); + } + + public void ShowInterstitialTimer(string eventName, Action rewardCallBack = null) + { + if (PlayerPrefs.GetInt("FirstAdShown", 0) == 0) + { + PlayerPrefs.SetInt("FirstAdShown", 1); + PlayerPrefs.Save(); + if (UiManager.Instance != null) + { + UiManager.Instance.ShowRemoveAdsBtn(); + } + } + else if (AdConstants.Int_Level_Gap >= 1 && AppConstants.levelsSinceLastInterstitial < AdConstants.Int_Level_Gap) + { + return; + } + if (splashCanvas != null) + { + splashCanvas.SetActive(true); + } + AdsTimerAndCallBack.Instance.SetInterstitialFirstAdsWatchedStatus(GameType.DrawToCrash); + if (LevelManager.instance != null) + { + AppConstants.lastIntAdShownLevel = LevelManager.instance.currentLevelNumberToShow; + } + LevelAnalytics.IntAdBefore(eventName); + + AppConstants.levelsSinceLastInterstitial = 0; + LevelAnalytics.IntAdAfter(); + if (rewardCallBack != null) + { + rewardCallBack(); + } + } + + public bool ShouldShowAd() + { + if (AdConstants.AdsRemoved) + { + return false; + } + if (PlayerPrefs.GetInt("FirstAdShown", 0) != 0) + { + return AdsTimerAndCallBack.Instance.ShouldShowAd(AdsTimerAndCallBack.Instance.gametype); + } + if (LevelManager.instance != null) + { + return LevelManager.instance.currentLevelNumberToShow >= AdConstants.first_interstitial_level; + } + return false; + } +} diff --git a/LevelManager.cs b/LevelManager.cs new file mode 100644 index 0000000..26f8aae --- /dev/null +++ b/LevelManager.cs @@ -0,0 +1,512 @@ +using Monetization.Runtime.Ads; +using MoreMountains.NiceVibrations; +using PimDeWitte.UnityMainThreadDispatcher; +using UnityEngine; +using UnityEngine.UI; + +public class LevelManager : MonoBehaviour +{ + public static LevelManager instance; + + public string levelPrefix = "Lv"; + + private GameObject currentLevelPrefab; + + public static int currentLevel = 1; + + [SerializeField] + private int maxLevels; + + public int currentLevelNumberToShow = 1; + + public Transform noThanksCoinPosTr; + + public Transform GetDoubleRewardCoinTr; + + private float rewardMultiplierCounter = 20f; + + public Text rewardMultiplierText; + + public int currentLevelCoinsEarned = 50; + + public GameObject hintTutorialObj; + + private static int lastHintsPanelShownLevel = -1; + + [Header("No Panel Test — Button Refs")] + public GameObject noThanksBtn_Comp; + + public GameObject retryBtn_Comp; + + public GameObject skipBtn_Fail; + + public GameObject retryBtn_Fail; + + public Animator meterArrowAnimator; + + private bool rewardedGetDoubleVideoClicked; + + private bool rewardedVideoClicked; + + private bool isBtnClicked; + + private void Awake() + { + instance = this; + } + + public void UpdateRewardMultiplier(int rewardMultiplier) + { + if (rewardMultiplierText) + { + rewardMultiplierText.text = rewardMultiplier.ToString("F0"); + } + rewardMultiplierCounter = rewardMultiplier; + } + + private void Start() + { + currentLevelNumberToShow = PersistableData.Instance.itemsData.currentLevelNumProgressive; + if (FirebaseInitialize.RemoteLevelOrder != null && FirebaseInitialize.RemoteLevelOrder.Count > 0) + { + currentLevel = FirebaseInitialize.RemoteLevelOrder[(currentLevelNumberToShow - 1) % FirebaseInitialize.RemoteLevelOrder.Count]; + } + else + { + currentLevel++; + if (currentLevel > maxLevels) + { + currentLevel = Random.Range(1, maxLevels + 1); + } + } + Resources.UnloadUnusedAssets(); + SpawnLevel(currentLevel); + if (FirebaseInitialize.AutoHintListLoaded && LevelScript.Instance != null) + { + LevelScript.Instance.isAutoHintLevel = FirebaseInitialize.AutoHintLevels.Contains(currentLevel); + } + if (currentLevelNumberToShow > maxLevels && currentLevel != 7 && currentLevel != 10) + { + Random.Range(0, 7); + } + if ((LevelScript.Instance != null && LevelScript.Instance.isAutoHintLevel) || (AppConstants.isRetryingLevel && PlayerPrefs.GetInt("HintWatched_" + currentLevelNumberToShow) == 1)) + { + GameManager.Instance.ShowHintThroughCode(); + } + bool flag = AppConstants.isRetryingAfterFail; + bool flag2 = LevelScript.Instance != null && LevelScript.Instance.isAutoHintLevel; + if (flag2 || !AppConstants.isRetryingAfterFail) + { + if (hintTutorialObj != null) + { + hintTutorialObj.SetActive(false); + } + } + else if (hintTutorialObj != null) + { + hintTutorialObj.SetActive(GameManager.FreeHintsRemaining); + } + AppConstants.isRetryingAfterFail = false; + if (PlayerPrefs.GetInt("EverFailed", 0) == 1) + { + UiManager.Instance.ShowFailButtons(flag2); + } + int num = PlayerPrefs.GetInt("HintWatched_" + currentLevelNumberToShow, 0); + int num2 = PlayerPrefs.GetInt("HintBtnUnlocked", 0); + if (num != 1 && !flag2 && num2 == 1) + { + GameManager.Instance.ShowHintButton(flag && !GameManager.FreeHintsRemaining); + } + LevelManager.instance.currentLevelCoinsEarned = 0; + if (AppConstants.shouldShowRemoveAdsOnStart) + { + AppConstants.shouldShowRemoveAdsOnStart = false; + AppConstants.removeAdsPanelFromLevelFlow = true; + Invoke("ShowRemoveAdsPanelFirstTime", 0.5f); + } + else if (!AdConstants.AdsRemoved && !AppConstants.isRetryingLevel && System.Array.IndexOf(AppConstants.RemoveAdsPanelLevels, currentLevelNumberToShow) >= 0 && AppConstants.lastIntAdShownLevel == currentLevelNumberToShow - 1) + { + Invoke("ShowRemoveAdsPanelFromList", 0.5f); + } + if (flag && !flag2 && num != 1 && !GameManager.FreeHintsRemaining && lastHintsPanelShownLevel != currentLevelNumberToShow && System.Array.IndexOf(AppConstants.HintsPanelLevels, currentLevelNumberToShow) >= 0) + { + lastHintsPanelShownLevel = currentLevelNumberToShow; + Invoke("ShowHintsPanelFromList", 0.5f); + } + } + + private void ShowRemoveAdsPanelFromList() + { + UiManager.Instance.ShowRemoveAdPanelAtLevel(); + } + + private void ShowHintsPanelFromList() + { + UiManager.Instance.OpenHintsPanel(); + } + + private void ShowRemoveAdsPanelFirstTime() + { + UiManager.Instance.ShowRemoveAdPanelFromFlow(); + } + + private void SpawnLevel(int levelNumber) + { + if (levelNumber > maxLevels) + { + Debug.Log("All levels completed!"); + return; + } + string levelName = levelPrefix + currentLevel; + GameObject gameObject = Resources.Load("Levels/" + levelName); + if (gameObject == null) + { + Debug.Log("Level prefab not found: " + levelName); + return; + } + if (currentLevelPrefab != null) + { + Destroy(currentLevelPrefab); + } + LevelAnalytics.Send(new string[1] { "Start" }); + currentLevelPrefab = Instantiate(gameObject); + currentLevelPrefab.name = levelName; + } + + private void LoadNextLevel() + { + if (FirebaseInitialize.RemoteLevelOrder != null && FirebaseInitialize.RemoteLevelOrder.Count > 0) + { + currentLevel = FirebaseInitialize.RemoteLevelOrder[PersistableData.Instance.itemsData.currentLevelNumProgressive % FirebaseInitialize.RemoteLevelOrder.Count]; + } + else + { + currentLevel++; + if (currentLevel > maxLevels) + { + currentLevel = Random.Range(1, maxLevels + 1); + } + } + AppConstants.isRetryingAfterFail = false; + AppConstants.isRetryingLevel = false; + PlayerPrefs.DeleteKey("HintWatched_" + currentLevelNumberToShow); + PersistableData.Instance.IncreaseLevelNumber(currentLevel); + SoundManager.instance.StopSoundFxSource(); + FadeSceneLoader.instance.LoadScene("Gameplay"); + } + + private void ResetClaimDoubleCoinsClickAgain() + { + rewardedGetDoubleVideoClicked = false; + } + + private void DoubleRewardGranted() + { + UnityMainThreadDispatcher.Instance().Enqueue(delegate + { + rewardedGetDoubleVideoClicked = false; + AppConstants.Haptic(HapticTypes.MediumImpact); + SoundManager.instance.PlaySFX_UI(SoundManager.instance.gameSoundSFX.buttonClickSfx, 1f); + if (isBtnClicked) + { + return; + } + isBtnClicked = true; + GameManager.OnCoinGrant((int)rewardMultiplierCounter, GetDoubleRewardCoinTr.position, delegate + { + Invoke("LoadNextLevel", 0.1f); + }); + }); + } + + public void SkipLevelLvlFailed() + { + LevelAnalytics.Send(new string[2] + { + "Level_Fail_PT" + AdConstants.Is_PanelTest, + "Skip_Level" + }); + + SkipLevelGranted(); + } + + public void SkipLevelGameplay() + { + UiManager.Instance.SettingPanelAnim.SetBool("SettingIn", false); + UiManager.Instance.SettingPanelAnim.SetBool("SettingOut", true); + UiManager.Instance.isSettingsOpen = false; + LevelAnalytics.Send(new string[1] { "Skip_Level" }); + + SkipLevelGranted(); + } + + private void SkipLevelGranted() + { + if (isBtnClicked) + { + return; + } + isBtnClicked = true; + AppConstants.Haptic(HapticTypes.MediumImpact); + LoadNextLevel(); + rewardedVideoClicked = false; + } + + private void ResetSkipLevelClickAgain() + { + rewardedVideoClicked = false; + } + + public void NoThanksGetDefaultCoins() + { + AppConstants.Haptic(HapticTypes.MediumImpact); + SoundManager.instance.PlaySFX_UI(SoundManager.instance.gameSoundSFX.buttonClickSfx, 1f); + if (isBtnClicked) + { + return; + } + isBtnClicked = true; + if (AdsManager.HasInterstitialFixed() && !AdConstants.AdsRemoved && GameManager.Instance.ShouldShowAd()) + { + if (AdConstants.EnableRemoveAdsFlow && PlayerPrefs.GetInt("RemoveAdsPanelShown", 0) == 0) + { + AppConstants.shouldShowRemoveAdsOnStart = true; + } + else + { + GameManager.Instance.ShowInterstitialTimer("Comp_Next", LoadNextLevel); + Invoke("LoadNextLevel", 1f); + return; + } + } + LoadNextLevel(); + } + + public void ReloadLevelGameplay() + { + SoundManager.instance.StopSoundFxSource(); + SoundManager.instance.StopMusic(); + GameManager.OnLevelReload?.Invoke(); + AppConstants.isRetryingLevel = true; + LevelAnalytics.Send(new string[1] { "In_Game_Replay_Btn" }); + ReloadLevel(); + } + + public void RetryLevelFailScreen() + { + AppConstants.isRetryingAfterFail = LevelScript.Instance == null || !LevelScript.Instance.isAutoHintLevel; + AppConstants.isRetryingLevel = true; + if (AdConstants.show_interstitial_on_fail && AdsManager.HasInterstitialFixed() && !AdConstants.AdsRemoved && GameManager.Instance.ShouldShowAd()) + { + if (AdConstants.EnableRemoveAdsFlow && PlayerPrefs.GetInt("RemoveAdsPanelShown", 0) == 0) + { + AppConstants.shouldShowRemoveAdsOnStart = true; + } + else + { + GameManager.Instance.ShowInterstitialTimer("Fail_Retry", ReloadLevel); + Invoke("ReloadLevel", 1f); + return; + } + } + ReloadLevel(); + } + + public void RetryLevelCompScreen() + { + AppConstants.isRetryingLevel = true; + AppConstants.isRetryingAfterFail = false; + LevelAnalytics.Send(new string[2] + { + "Level_Comp_PT" + AdConstants.Is_PanelTest, + "Try_Again" + }); + if (AdsManager.HasInterstitialFixed() && !AdConstants.AdsRemoved && GameManager.Instance.ShouldShowAd()) + { + if (AdConstants.EnableRemoveAdsFlow && PlayerPrefs.GetInt("RemoveAdsPanelShown", 0) == 0) + { + AppConstants.shouldShowRemoveAdsOnStart = true; + } + else + { + GameManager.Instance.ShowInterstitialTimer("Comp_Retry", ReloadLevel); + Invoke("ReloadLevel", 1f); + return; + } + } + ReloadLevel(); + } + + private void ReloadLevel() + { + if (!AdConstants.AdsRemoved && (AdConstants.Is_PanelTest == 2 || AdConstants.Is_PanelTest == 3 || AdConstants.Is_PanelTest == 4)) + { + + AdsManager.HideMRec(); + UiManager.Instance.BannerPati.SetActive(true); + } + AppConstants.Haptic(HapticTypes.MediumImpact); + SoundManager.instance.PlaySFX_UI(SoundManager.instance.gameSoundSFX.buttonClickSfx, 1f); + if (isBtnClicked) + { + return; + } + isBtnClicked = true; + SoundManager.instance.StopSoundFxSource(); + FadeSceneLoader.instance.LoadScene("Gameplay"); + } + + public void ReloadLevelSilently() + { + if (isBtnClicked) + { + return; + } + isBtnClicked = true; + AppConstants.isRetryingAfterFail = LevelScript.Instance == null || !LevelScript.Instance.isAutoHintLevel; + AppConstants.isRetryingLevel = true; + if (!AdConstants.AdsRemoved) + { + + AdsManager.HideMRec(); + UiManager.Instance.BannerPati.SetActive(true); + } + FadeSceneLoader.instance.LoadScene("Gameplay"); + } + + public void SetupFailScreenNoPanelTest() + { + if (skipBtn_Fail != null) + { + skipBtn_Fail.SetActive(false); + } + if (retryBtn_Fail != null) + { + retryBtn_Fail.SetActive(false); + } + if (UiManager.Instance.reloadBtnRect != null) + { + UiManager.Instance.reloadBtnRect.gameObject.SetActive(false); + } + Invoke("AutoRetryAfterFail_NoPanel", 1.5f); + } + + private void AutoRetryAfterFail_NoPanel() + { + if (!AdConstants.AdsRemoved) + { + + AdsManager.HideMRec(); + AdsManager.ShowBanner(); + } + bool flag = LevelScript.Instance != null && LevelScript.Instance.isAutoHintLevel; + AppConstants.isRetryingAfterFail = !flag; + AppConstants.isRetryingLevel = true; + LevelAnalytics.Send(new string[2] + { + "Level_Fail_PT" + AdConstants.Is_PanelTest, + "Auto_Retry" + }); + if (AdConstants.show_interstitial_on_fail && AdsManager.HasInterstitialFixed() && !AdConstants.AdsRemoved && GameManager.Instance.ShouldShowAd()) + { + if (AdConstants.EnableRemoveAdsFlow && PlayerPrefs.GetInt("RemoveAdsPanelShown", 0) == 0) + { + AppConstants.shouldShowRemoveAdsOnStart = true; + } + else + { + UiManager.Instance.LevelFailedPanel.gameObject.SetActive(false); + SoundManager.instance.StopSoundFxSource(); + GameManager.Instance.ShowInterstitialTimer("Fail_AutoRetry_NoPanel", null); + } + } + if (!AdConstants.AdsRemoved) + { + + AdsManager.HideMRec(); + AdsManager.ShowBanner(); + } + ReloadLevel(); + } + + public void SetupCompScreenConfettiTest() + { + if (UiManager.Instance.reloadBtnRect != null) + { + UiManager.Instance.reloadBtnRect.gameObject.SetActive(false); + } + Invoke("AutoNextAfterComp_ConfettiTest", 1.5f); + } + + private void AutoNextAfterComp_ConfettiTest() + { + LevelAnalytics.Send(new string[2] + { + "Level_Comp_PT" + AdConstants.Is_PanelTest, + "Confetti_AutoContinue" + }); + if (AdsManager.HasInterstitialFixed() && !AdConstants.AdsRemoved && GameManager.Instance.ShouldShowAd()) + { + if (AdConstants.EnableRemoveAdsFlow && PlayerPrefs.GetInt("RemoveAdsPanelShown", 0) == 0) + { + AppConstants.shouldShowRemoveAdsOnStart = true; + } + else + { + if (GameManager.Instance.confettiOnWin != null) + { + GameManager.Instance.confettiOnWin.SetActive(false); + } + SoundManager.instance.StopSoundFxSource(); + GameManager.Instance.ShowInterstitialTimer("Comp_Confetti_AutoNext", null); + } + } + LoadNextLevel(); + } + + public void SetupCompScreenNoPanelTest() + { + if (noThanksBtn_Comp != null) + { + noThanksBtn_Comp.SetActive(false); + } + if (retryBtn_Comp != null) + { + retryBtn_Comp.SetActive(false); + } + if (UiManager.Instance.reloadBtnRect != null) + { + UiManager.Instance.reloadBtnRect.gameObject.SetActive(false); + } + Invoke("AutoNextAfterComp_NoPanel", 1.5f); + } + + private void AutoNextAfterComp_NoPanel() + { + LevelAnalytics.Send(new string[2] + { + "Level_Comp_PT" + AdConstants.Is_PanelTest, + "NoPanel_AutoContinue" + }); + if (AdsManager.HasInterstitialFixed() && !AdConstants.AdsRemoved && GameManager.Instance.ShouldShowAd()) + { + if (AdConstants.EnableRemoveAdsFlow && PlayerPrefs.GetInt("RemoveAdsPanelShown", 0) == 0) + { + AppConstants.shouldShowRemoveAdsOnStart = true; + } + else + { + UiManager.Instance.LevelCompletePanel.gameObject.SetActive(false); + SoundManager.instance.StopSoundFxSource(); + GameManager.Instance.ShowInterstitialTimer("Comp_AutoNext_NoPanel", null); + } + } + if (!AdConstants.AdsRemoved) + { + + AdsManager.HideMRec(); + AdsManager.ShowBanner(); + } + LoadNextLevel(); + } +} diff --git a/UiManager.cs b/UiManager.cs new file mode 100644 index 0000000..068a876 --- /dev/null +++ b/UiManager.cs @@ -0,0 +1,357 @@ +using DG.Tweening; +using UnityEngine; +using UnityEngine.UI; + +public class UiManager : Singleton +{ + public Transform settingsPanel; + + public Transform getCoinsPanel; + + public Transform shopPanel; + + public Transform newSkinUnlockPanel; + + public Transform removeAdPanel; + + public Transform noInternetAvailable; + + public Transform ratePanel; + + public Transform exitPanel; + + public Transform hintsPanel; + + public Transform LevelCompletePanel; + + public Transform LevelFailedPanel; + + public Text levelNumTextGameplay; + + public Text levelNumTextGameover; + + public Transform levelNumTag; + + public Image currentBallImg; + + public Animator SettingPanelAnim; + + public GameObject RemoveAdsBtn; + + public GameObject BannerPati; + + private float currentBallInitialScale; + + public bool isSettingsOpen; + + [Header("Progressive UI Unlock")] + public GameObject topUISkipLevelBtn; + + public GameObject[] iconsUnlockedAfterAd; + + [Header("Reload Button")] + public RectTransform reloadBtnRect; + + private Vector2 _reloadBtnHidePos; + + private readonly Vector2 _reloadBtnShowPos = new Vector2(20f, -7f); + + private bool isGameCompleted; + + private void Start() + { + Application.targetFrameRate = 60; + + MonetizationServices.Ads.ShowBanner(); + if (RemoveAdsBtn != null) + { + RemoveAdsBtn.SetActive(false); + } + if (topUISkipLevelBtn != null) + { + topUISkipLevelBtn.SetActive(false); + } + for (int i = 0; i < iconsUnlockedAfterAd.Length; i++) + { + if (iconsUnlockedAfterAd[i] != null) + { + iconsUnlockedAfterAd[i].SetActive(false); + } + } + if (PlayerPrefs.GetInt("FirstAdShown", 0) == 1) + { + ShowRemoveAdsBtn(); + } + if (PlayerPrefs.GetInt("RemoveAdsPanelShown", 0) == 1) + { + ShowPostAdIcons(); + } + if (AdConstants.AdsRemoved && RemoveAdsBtn != null) + { + RemoveAdsBtn.SetActive(false); + } + if (PlayerPrefs.GetInt("EverFailed", 0) == 1) + { + if (LevelScript.Instance != null) + { + ShowFailButtons(false); + } + } + if (reloadBtnRect != null) + { + _reloadBtnHidePos = reloadBtnRect.anchoredPosition; + reloadBtnRect.gameObject.SetActive(false); + } + Input.multiTouchEnabled = false; + currentBallInitialScale = currentBallImg.transform.localScale.x; + levelNumTag.localScale = Vector3.one; + levelNumTextGameplay.text = "Level " + PersistableData.Instance.itemsData.currentLevelNumProgressive; + levelNumTag.DOScale(0.5f, 1f); + UpdateBallImgIcon(PersistableData.Instance.shopItemSprite[PersistableData.Instance.itemsData.currentShopItemId]); + } + + public void UpdateBallImgIcon(Sprite ballSprite) + { + currentBallImg.sprite = ballSprite; + currentBallImg.transform.DOKill(); + currentBallImg.transform.localScale = Vector3.one * currentBallInitialScale; + currentBallImg.transform.DOPunchScale(Vector3.one * currentBallInitialScale * 0.5f, 0.5f, 1, 1f).OnComplete(delegate + { + currentBallImg.transform.localScale = Vector3.one * currentBallInitialScale; + }); + } + + private void OnEnable() + { + GameManager.OnGameComplete += OnGameComplete; + GameManager.OnLineDrawingStarts += OnLineDrawingStarts; + } + + private void OnDisable() + { + GameManager.OnGameComplete -= OnGameComplete; + GameManager.OnLineDrawingStarts -= OnLineDrawingStarts; + } + + private void OnGameComplete() + { + isGameCompleted = true; + if (reloadBtnRect != null) + { + reloadBtnRect.gameObject.SetActive(false); + } + } + + private void OnLineDrawingStarts() + { + if (reloadBtnRect == null) + { + return; + } + reloadBtnRect.anchoredPosition = _reloadBtnHidePos; + reloadBtnRect.gameObject.SetActive(true); + reloadBtnRect.DOAnchorPos(_reloadBtnShowPos, 0.7f).SetEase(Ease.OutBack); + } + + public void OpenSettingsPanel() + { + if (isGameCompleted) + { + return; + } + isSettingsOpen = !isSettingsOpen; + SettingPanelAnim.enabled = true; + if (isSettingsOpen) + { + SettingPanelAnim.SetBool("SettingIn", true); + SettingPanelAnim.SetBool("SettingOut", false); + } + else + { + SettingPanelAnim.SetBool("SettingIn", false); + SettingPanelAnim.SetBool("SettingOut", true); + } + LevelAnalytics.Send(new string[] { "SettingPanel" }); + } + + public void ShowRatePopUp() + { + AppConstants.IsAnyPanelOpen = true; + ratePanel.gameObject.SetActive(true); + } + + public void CloseRatePanel() + { + AppConstants.IsAnyPanelOpen = false; + ratePanel.gameObject.SetActive(false); + } + + public void OpenShopPanel() + { + if (isGameCompleted) + { + return; + } + shopPanel.gameObject.SetActive(true); + } + + public void ShowRemoveAdPanelAtLevel() + { + if (PersistableData.Instance != null && PersistableData.Instance.itemsData.isRemoveAdPurchased) + { + return; + } + AppConstants.removeAdsPanelFromLevelFlow = false; + AppConstants.IsAnyPanelOpen = true; + removeAdPanel.gameObject.SetActive(true); + LevelAnalytics.Send(new string[] { "RemoveAds_LevelShow" }); + } + + public void ShowRemoveAdPanel() + { + SettingPanelAnim.SetBool("SettingIn", false); + SettingPanelAnim.SetBool("SettingOut", true); + isSettingsOpen = false; + AppConstants.IsAnyPanelOpen = true; + removeAdPanel.gameObject.SetActive(true); + if (PersistableData.Instance.itemsData.isRemoveAdPurchased) + { + return; + } + LevelAnalytics.Send(new string[] { "RemoveAds_Screen" }); + } + + private void Update() + { + if (Input.GetKeyDown(KeyCode.Escape)) + { + ShowExitPanel(); + } + } + + private void ShowExitPanel() + { + SettingPanelAnim.SetBool("SettingIn", false); + SettingPanelAnim.SetBool("SettingOut", true); + AppConstants.IsAnyPanelOpen = true; + exitPanel.gameObject.SetActive(true); + } + + public void CloseExitPanel() + { + AppConstants.IsAnyPanelOpen = false; + exitPanel.gameObject.SetActive(false); + } + + public void CloseShopPanel() + { + shopPanel.gameObject.GetComponent().ClosePanel(); + } + + public void OpenNotEnoughCoinsPanel() + { + AppConstants.IsAnyPanelOpen = true; + getCoinsPanel.gameObject.SetActive(true); + } + + public void CloseNotEnoughCoinsPanel() + { + AppConstants.IsAnyPanelOpen = false; + getCoinsPanel.gameObject.SetActive(false); + } + + public void ShowNoInternetPanel() + { + AppConstants.IsAnyPanelOpen = true; + noInternetAvailable.gameObject.SetActive(true); + } + + public void CloseNoInternetPanel() + { + AppConstants.IsAnyPanelOpen = false; + noInternetAvailable.gameObject.SetActive(false); + } + + public void ShowNewSkinPopUp() + { + newSkinUnlockPanel.gameObject.SetActive(true); + } + + public void ShowFailButtons(bool isAutoHintLevel) + { + if (topUISkipLevelBtn != null) + { + topUISkipLevelBtn.SetActive(true); + } + } + + public void ShowRemoveAdsBtn() + { + if (!AdConstants.AdsRemoved && RemoveAdsBtn != null) + { + RemoveAdsBtn.SetActive(true); + } + } + + public void ShowPostAdIcons() + { + if (!AdConstants.AdsRemoved && RemoveAdsBtn != null) + { + RemoveAdsBtn.SetActive(true); + } + for (int i = 0; i < iconsUnlockedAfterAd.Length; i++) + { + if (iconsUnlockedAfterAd[i] != null) + { + iconsUnlockedAfterAd[i].SetActive(true); + } + } + } + + public void ShowRemoveAdPanelFromFlow() + { + AppConstants.IsAnyPanelOpen = true; + removeAdPanel.gameObject.SetActive(true); + LevelAnalytics.Send(new string[] { "RemoveAds_FirstTime" }); + } + + public void CloseRemoveAdPanel_NoThanks() + { + if (AppConstants.removeAdsPanelFromLevelFlow) + { + AppConstants.removeAdsPanelFromLevelFlow = false; + PlayerPrefs.SetInt("RemoveAdsPanelShown", 1); + PlayerPrefs.Save(); + LevelAnalytics.Send(new string[] { "RemoveAds_NoThanks" }); + + AppConstants.IsAnyPanelOpen = false; + removeAdPanel.gameObject.SetActive(false); + ShowPostAdIcons(); + } + else + { + AppConstants.IsAnyPanelOpen = false; + removeAdPanel.gameObject.SetActive(false); + } + } + + public void CloseRemoveAdPanel_IAPSuccess() + { + AppConstants.removeAdsPanelFromLevelFlow = false; + PlayerPrefs.SetInt("RemoveAdsPanelShown", 1); + PlayerPrefs.Save(); + ShowPostAdIcons(); + } + + public void OpenHintsPanel() + { + AppConstants.IsAnyPanelOpen = true; + hintsPanel.gameObject.SetActive(true); + } + + public void CloseHintsPanel() + { + AppConstants.IsAnyPanelOpen = false; + hintsPanel.gameObject.SetActive(false); + } +}