123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- //==========================================================
- //
- // Copyright (c) Guangzhou Shixiang Technology Co.,Ltd.
- // All rights reserved.
- //
- //==========================================================
- using UnityEngine;
- public class InteractionObj : MonoBehaviour
- {
- private static string TAG = "[InteractionObj]";
- [SerializeField]
- private InteractionObjCube _interactionObjCube = null;
- [SerializeField]
- private TextMesh _textMesh = null;
- // 作为key索引,初始化后不要修改
- private int _index = 0;
- public int Index => _index;
- private int _row = -1;
- public int Row => _row;
- private int _column = -1;
- public int Column => _column;
- private int _number = 0;
- public int Number => _number;
- private bool _isMoving = false;
- public bool IsMoving => _isMoving;
- void Start()
- {
- }
- void Update()
- {
- }
- private void OnDestroy()
- {
- }
- public void Init(int row, int column, int index)
- {
- _row = row;
- _column = column;
- _index = index;
- name = "InteractionObj" + _index;
- transform.localPosition = InteractionObjManager.GetObjectLocalPosition(row, column);
- _number = _index;
- UpdateText(_number.ToString());
- }
- private void UpdateText(string text)
- {
- _textMesh.text = text;
- }
- public void RotateCube()
- {
- if (_interactionObjCube != null)
- {
- _interactionObjCube.Rotate();
- }
- }
- public void ChangeColor()
- {
- if (_interactionObjCube != null)
- {
- _interactionObjCube.ChangeColor();
- }
- }
- public void LockColor(bool isLock)
- {
- if (_interactionObjCube != null)
- {
- _interactionObjCube.LockColor(isLock);
- }
- }
- public void Add()
- {
- ++_number;
- UpdateText(_number.ToString());
- }
- public void Sub()
- {
- --_number;
- UpdateText(_number.ToString());
- }
- public void SwapPosition(int row, int column)
- {
- _row = row;
- _column = column;
- _isMoving = true;
- Vector3 endPos = InteractionObjManager.GetObjectLocalPosition(row, column);
- LeanTween.cancel(gameObject);
- LeanTween.moveLocal(gameObject, endPos, 0.3f)
- .setEase(LeanTweenType.easeOutQuad)
- .setOnComplete(() =>
- {
- _row = row;
- _column = column;
- _isMoving = false;
- UpdateText(_number.ToString());
- });
- }
- }
|