private void DoOpenCard() { if (_ballStatus != BallStatusEnum.opening) { _ballStatus = BallStatusEnum.opening; OpenCard(); } }
/// <summary> /// 检查是否已经越界 /// </summary> private void CheckOverBords() { Vector3 v = Camera.main.WorldToScreenPoint(transform.position); if (v.x < (0 - 200)) { ballStatus = BallStatusEnum.destorying; } }
/// <summary> /// /// </summary> /// <param name="speed">0 -> 1</param> /// <param name="birthPosition"></param> /// <param name="scaleFactor">0.5 -> 2.0</param> public void Init(float speed, Vector3 birthPosition, float scaleFactor, BallsManager ballsManager, BallData ballData) { _ballsManager = ballsManager; _ballData = ballData; _speed = speed; transform.position = birthPosition; var scale = GetComponent <Transform>().localScale; scale.x *= scaleFactor; scale.y *= scaleFactor; GetComponent <Transform>().localScale = scale; _ballStatus = BallStatusEnum.flow; string coverAddress = "data/" + ballData.cover; //Debug.Log("coverAddress : " + coverAddress); var sprite = Resources.Load <Sprite>(coverAddress); spriteRenderer.sprite = sprite; // 设置图片 //SpriteAtlas spriteAtlas = Resources.Load<SpriteAtlas>("SpriteAtlas"); //string[] spriteAtlasAry = { "1", "2", "3", "4" }; //spriteRenderer.sprite = spriteAtlas.GetSprite(spriteAtlasAry[Random.Range(0, 4)]); // 随机正反显示 float rotRange = Random.Range(0, 1f); if (rotRange > 0.5f) { isReversal = true; GetComponent <RectTransform>().DORotate(new Vector3(180, 180, 0), Time.deltaTime); } else { isReversal = false; } }
public void OnDrag(PointerEventData eventData) { if (_ballStatus == BallStatusEnum.opening) { return; } var selfScreenPosition = Camera.main.WorldToScreenPoint(transform.position); //var selfScreenPosition = eventData.position; var mousePosition = new Vector3(eventData.position.x, eventData.position.y, selfScreenPosition.z); if (_ballStatus != BallStatusEnum.dragging) { // 获取点击处与物体中心的偏移量 var startDragPosition = mousePosition; _clickScreenOffset = selfScreenPosition - startDragPosition; _lastActivePosition = startDragPosition; } _ballStatus = BallStatusEnum.dragging; //var toScreenPosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, selfScreenPosition.z) + _clickScreenOffset; var toScreenPosition = mousePosition + _clickScreenOffset; //Debug.Log("Distance : " + Vector3.Distance(_lastActivePosition, toScreenPosition)); if (CheckAvailablePostion(toScreenPosition)) { _lastActivePosition = toScreenPosition; var mouseWordPosition = Camera.main.ScreenToWorldPoint(toScreenPosition); transform.position = mouseWordPosition; } else { //超出影响范围 } }
public void DestoryIt() { _smallTweener?.Kill(); _moveTweener?.Kill(); _ballStatus = BallStatusEnum.destorying; }