//========================================================== // // 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()); }); } }