InteractionObj.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //==========================================================
  2. //
  3. // Copyright (c) Guangzhou Shixiang Technology Co.,Ltd.
  4. // All rights reserved.
  5. //
  6. //==========================================================
  7. using UnityEngine;
  8. public class InteractionObj : MonoBehaviour
  9. {
  10. private static string TAG = "[InteractionObj]";
  11. [SerializeField]
  12. private InteractionObjCube _interactionObjCube = null;
  13. [SerializeField]
  14. private TextMesh _textMesh = null;
  15. // 作为key索引,初始化后不要修改
  16. private int _index = 0;
  17. public int Index => _index;
  18. private int _row = -1;
  19. public int Row => _row;
  20. private int _column = -1;
  21. public int Column => _column;
  22. private int _number = 0;
  23. public int Number => _number;
  24. private bool _isMoving = false;
  25. public bool IsMoving => _isMoving;
  26. void Start()
  27. {
  28. }
  29. void Update()
  30. {
  31. }
  32. private void OnDestroy()
  33. {
  34. }
  35. public void Init(int row, int column, int index)
  36. {
  37. _row = row;
  38. _column = column;
  39. _index = index;
  40. name = "InteractionObj" + _index;
  41. transform.localPosition = InteractionObjManager.GetObjectLocalPosition(row, column);
  42. _number = _index;
  43. UpdateText(_number.ToString());
  44. }
  45. private void UpdateText(string text)
  46. {
  47. _textMesh.text = text;
  48. }
  49. public void RotateCube()
  50. {
  51. if (_interactionObjCube != null)
  52. {
  53. _interactionObjCube.Rotate();
  54. }
  55. }
  56. public void ChangeColor()
  57. {
  58. if (_interactionObjCube != null)
  59. {
  60. _interactionObjCube.ChangeColor();
  61. }
  62. }
  63. public void LockColor(bool isLock)
  64. {
  65. if (_interactionObjCube != null)
  66. {
  67. _interactionObjCube.LockColor(isLock);
  68. }
  69. }
  70. public void Add()
  71. {
  72. ++_number;
  73. UpdateText(_number.ToString());
  74. }
  75. public void Sub()
  76. {
  77. --_number;
  78. UpdateText(_number.ToString());
  79. }
  80. public void SwapPosition(int row, int column)
  81. {
  82. _row = row;
  83. _column = column;
  84. _isMoving = true;
  85. Vector3 endPos = InteractionObjManager.GetObjectLocalPosition(row, column);
  86. LeanTween.cancel(gameObject);
  87. LeanTween.moveLocal(gameObject, endPos, 0.3f)
  88. .setEase(LeanTweenType.easeOutQuad)
  89. .setOnComplete(() =>
  90. {
  91. _row = row;
  92. _column = column;
  93. _isMoving = false;
  94. UpdateText(_number.ToString());
  95. });
  96. }
  97. }