using Thousandto.Code.Center; using System.Collections.Generic; using UnityEngine; namespace Thousandto.Code.Logic { public class ItemDropEffectSystem { #region//私有变量 private static Dictionary _dropEntityTable = new Dictionary(); private static List _posList = new List(); #endregion #region//构造函数 static ItemDropEffectSystem() { //47 24 25 26 27 28 29 //46 23 8 9 10 11 30 //45 22 7 0 1 12 31 //44 21 6 2 13 32 //43 20 5 4 3 14 33 //42 19 18 17 16 15 34 //41 40 39 38 37 36 35 _posList.Add(new Vector2(0, 1)); //0 _posList.Add(new Vector2(1, 1)); //1 _posList.Add(new Vector2(1, 0)); //2 _posList.Add(new Vector2(1, -1)); //3 _posList.Add(new Vector2(0, -1)); //4 _posList.Add(new Vector2(-1, -1)); //5 _posList.Add(new Vector2(-1, 0)); //6 _posList.Add(new Vector2(-1, 1)); //7 _posList.Add(new Vector2(-1, 2)); //8 _posList.Add(new Vector2(0, 2)); //9 _posList.Add(new Vector2(1, 2)); //10 _posList.Add(new Vector2(2, 2)); //11 _posList.Add(new Vector2(2, 1)); //12 _posList.Add(new Vector2(2, 0)); //13 _posList.Add(new Vector2(2, -1)); //14 _posList.Add(new Vector2(2, -2)); //15 _posList.Add(new Vector2(1, -2)); //16 _posList.Add(new Vector2(0, -2)); //17 _posList.Add(new Vector2(-1, -2)); //18 _posList.Add(new Vector2(-2, -2)); //19 _posList.Add(new Vector2(-2, -1)); //20 _posList.Add(new Vector2(-2, 0)); //21 _posList.Add(new Vector2(-2, 1)); //22 _posList.Add(new Vector2(-2, 2)); //23 _posList.Add(new Vector2(-2, 3)); //24 _posList.Add(new Vector2(-1, 3)); //25 _posList.Add(new Vector2(0, 3)); //26 _posList.Add(new Vector2(1, 3)); //27 _posList.Add(new Vector2(2, 3)); //28 _posList.Add(new Vector2(3, 3)); //29 _posList.Add(new Vector2(3, 2)); //30 _posList.Add(new Vector2(3, 1)); //31 _posList.Add(new Vector2(3, 0)); //32 _posList.Add(new Vector2(3, -1)); //33 _posList.Add(new Vector2(3, -2)); //34 _posList.Add(new Vector2(3, -3)); //35 _posList.Add(new Vector2(2, -3)); //36 _posList.Add(new Vector2(1, -3)); //37 _posList.Add(new Vector2(0, -3)); //38 _posList.Add(new Vector2(-1, -3)); //39 _posList.Add(new Vector2(-2, -3)); //40 _posList.Add(new Vector2(-3, -3)); //41 _posList.Add(new Vector2(-3, -2)); //42 _posList.Add(new Vector2(-3, -1)); //43 _posList.Add(new Vector2(-3, 0)); //44 _posList.Add(new Vector2(-3, 1)); //45 _posList.Add(new Vector2(-3, 2)); //46 _posList.Add(new Vector2(-3, 3)); //47 } #endregion #region//公有函数 public static Vector2 CalculateDropPos(Character c) { if (c == null || GameCenter.GameSceneSystem.ActivedScene == null) return Vector2.zero; for (int i = 0; i < _posList.Count; ++i) { var pos = CalculateUnBolockDropPos(c); if (!GameCenter.GameSceneSystem.ActivedScene.navigator.IsBlocked(pos)) { return pos; } } return c.Position2d; } public static void Remove(ulong id) { _dropEntityTable.Remove(id); } public static int GetCurIndex(ulong id) { int index = 0; if(_dropEntityTable.TryGetValue(id, out index)) { return index; } return 0; } #endregion #region//私有函数 private static Vector2 CalculateUnBolockDropPos(Character c) { int index = 0; if (_dropEntityTable.TryGetValue(c.ID, out index)) { ++index; if (index >= _posList.Count) { index = 0; } _dropEntityTable[c.ID] = index; } else { index = 0; _dropEntityTable.Add(c.ID, index); } Vector2 pos = c.Position2d; pos.x += _posList[index].x * 2f; pos.y += _posList[index].y * 2f; return pos; } #endregion } }