using System; using System.Collections; using UnityEngine; using FairyGUI; using UI.ActivityGetYuanXiao; namespace GFGGame { public class YuanXiaoItem { private int _type; private int _score; private GComponent _com; private GObject _catcher; private ActivityGetYuanXiaoView _baseView; private GTweener _tweener; public YuanXiaoItem CreateItem(GComponent com, GObject catcher, ActivityGetYuanXiaoView baseView) { _com = com; _catcher = catcher; _baseView = baseView; return this; } public void Init(int type) { SetVisible(true); _type = type; UI_YuanXiaoItem item = UI_YuanXiaoItem.Proxy(_com); item.m_c1.selectedIndex = _type - 1; UI_YuanXiaoItem.ProxyEnd(); } public void Move(Vector3 start, Vector3 end, float time, Action action = null) { Vector3 startPos = start; Vector3 endPos = end; _com.position = startPos; Timers.inst.Remove(HandleCollider); Timers.inst.AddUpdate(HandleCollider); _tweener = _com.TweenMoveY(endPos.y, time); _tweener.SetEase(EaseType.QuadIn).OnComplete(()=> { Timers.inst.Remove(HandleCollider); action?.Invoke(); }); } private void HandleCollider(object param = null) { if(CheckCollider(_com, _catcher)) { Timers.inst.Remove(HandleCollider); _baseView.GetYuanXiao(this); } } private bool CheckCollider(GObject obj1, GObject obj2) { Vector3 pos1 = obj1.LocalToGlobal(Vector2.zero); Vector3 pos2 = obj2.LocalToGlobal(Vector2.zero); bool collisionX = pos1.x + obj1.width >= pos2.x && pos2.x + obj2.width >= pos1.x; bool collisionY = pos1.y + obj1.height >= pos2.y && pos2.y + obj2.height >= pos1.y; return collisionX && collisionY; } public bool GetVisible() { return _com.visible; } public void SetVisible(bool visible) { _com.visible = visible; if (!visible) { _tweener.Kill(false); } } public int GetYuanXiaoType() { return _type; } public void SetScore(int score) { _score = score; } public int GetScore() { return _score; } public void Destroy() { _tweener.Kill(false); Timers.inst.Remove(HandleCollider); _com.Dispose(); } public void SetPause(bool pause = true) { if (_com.visible) { _tweener.SetPaused(pause); } } } }