private void Move() { if (_dirList.Count == 0) { return; } ArrayPosHandler oldPosInArray = _currPosInArray, newPosInArray; if (_dirList.Count > 1) { newPosInArray = _currPosInArray + _dirList.Last(); _dirList.RemoveAt(_dirList.Count - 1); } else { newPosInArray = _currPosInArray + _dirList.First(); } ArrayPosHandler inputValue = newPosInArray - _currPosInArray; if (_inputs.Count > 0) { _inputs.Insert(0, new Vector2(inputValue.x, inputValue.y)); } else { _inputs.Insert(0, new Vector2(inputValue.x, inputValue.y)); _inputs.Insert(0, new Vector2(inputValue.x, inputValue.y)); } if (ArrayPosHandler.IsLeftBorderCrossed(newPosInArray)) { _currPosInArray = new ArrayPosHandler(_currPosInArray.x, _gs.gameArray.GetLength(1) - 1); } else if (ArrayPosHandler.IsRightBorderCrossed(newPosInArray, _gs.gameArray.GetLength(1) - 1)) { _currPosInArray = new ArrayPosHandler(_currPosInArray.x, 0); } else if (ArrayPosHandler.IsTopBorderCrossed(newPosInArray)) { _currPosInArray = new ArrayPosHandler(_gs.gameArray.GetLength(0) - 1, _currPosInArray.y); } else if (ArrayPosHandler.IsBottomBorderCrossed(newPosInArray, _gs.gameArray.GetLength(0) - 1)) { _currPosInArray = new ArrayPosHandler(0, _currPosInArray.y); } else { _currPosInArray = newPosInArray; } transform.position = _gs.GetPosition(_currPosInArray); MoveEvent?.Invoke(); _steps.Insert(0, _currPosInArray); _gs.ChangGameArray(_currPosInArray, 1); if (_ateFood) { EatEvent?.Invoke(); SpawnFood?.Invoke(); _gs.ChangGameArray(oldPosInArray, 2); SpawnTail(oldPosInArray); _ateFood = false; } else if (_ateBonus) { BonusEvent?.Invoke(); SpawnTail(oldPosInArray); _gs.ChangGameArray(oldPosInArray, 2); _ateBonus = false; } else if (_tail.Count > 0) { TailLastToFirst(oldPosInArray); } else { _gs.ChangGameArray(oldPosInArray, 0); } if (_steps.Count > 2) { _steps.RemoveAt(_steps.Count - 1); } if (_inputs.Count > 2) { _inputs.RemoveAt(_inputs.Count - 1); } }
//引发事件的方法 public void OnEatEvent(EatEventArgs e) { EatEvent?.Invoke(this, e); }
// Start is called before the first frame update void Start() { animator = gameObject.GetComponent <Animator>(); drinkEvent = animator.GetBehaviour <DrinkEvent>(); eatEvent = animator.GetBehaviour <EatEvent>(); }