public void Notfiy(Vector3 pos, Direction dir, SpawngridConfig conf) { foreach (IObersver observer in observers) { observer.StatusUpdate(pos, dir, conf, observers); } }
public void StatusUpdate(Vector3 pos, Direction dir, SpawngridConfig conf, List <IObersver> observers) { if (!CustomController.InRange(pos, GetPos(), conf, dir)) { UpdatePos(dir, conf); UpdateNeigbor(this, observers, conf.gap); this.SignNeighbor(observers, conf.gap); this.IsOccupy = false; } #region foldcomment //todo refactro code //var neighborPos = new Vector3(this.X,this.Y,this.Z); //if (neighborDic[s] == null) //{ // if (s == front) // { // neighborPos += Vector3.forward*gap; // } // else if (s == back) // { // neighborPos += Vector3.back * gap; // } // else if (s == right) // { // neighborPos += Vector3.right * gap; // } // else if (s == left) // { // neighborPos += Vector3.left * gap; // } // else if (s == up) // { // neighborPos += Vector3.up * gap; // } // else if (down == s) // { // neighborPos += Vector3.down * gap; // } // neighborDic[s] = new SpawnGrid(neighborPos); // if (gm.TempSGHoder == null) // { // gm.TempSGHoder = new List<IObersver>(); // gm.TempSGHoder.Add(neighborDic[s]); // } // else { gm.TempSGHoder.Add(neighborDic[s]); } //} #endregion //force update all info }
public static bool InRange(Vector3 v1, Vector3 v2, SpawngridConfig conf, Direction dir) { switch (dir) { #region foldold //as the less method include the equal as true, use some trick here. //case "Front": // return !Less(fVal,Mathf.Abs(v1.z-v2.z)); //case "Back": // return !Less(fVal,Mathf.Abs(v1.z - v2.z) ); //case "Left": // return !Less(fVal,Mathf.Abs(v1.x - v2.x)); //case "Right": // return !Less(fVal,Mathf.Abs(v1.x - v2.x)); //case "Up": // return !Less(fVal,Mathf.Abs(v1.y - v2.y)); //case "Down": // return !Less(fVal,Mathf.Abs(v1.y - v2.y)); #endregion case Direction.Front: return(Less(Mathf.Abs(v1.z - v2.z), conf.length)); case Direction.Back: return(Less(Mathf.Abs(v1.z - v2.z), conf.length)); case Direction.Left: return(Less(Mathf.Abs(v1.x - v2.x), conf.width)); case Direction.Right: return(Less(Mathf.Abs(v1.x - v2.x), conf.width)); case Direction.Up: return(Less(Mathf.Abs(v1.y - v2.y), conf.height)); case Direction.Down: return(Less(Mathf.Abs(v1.y - v2.y), conf.height)); default: throw new System.ArgumentException("No this direction"); } //if (Mathf.Abs(f1-f2)<fVal) { // return true; //} // return false; }
private void UpdatePos(Direction dir, SpawngridConfig conf) { //z front/back, x left/right, y up/down var newPos = GetPos(); #region foldold //todo refactor //if (dir == front) //{ // newPos += Vector3.forward * conf.length * 2; // newPos.z += conf.gap; //} //else if (dir == back) //{ // newPos += Vector3.back * conf.length * 2; // newPos.z -= conf.gap; //} //else if (s == right) //{ // newPos.x += conf.gap; // newPos += Vector3.right * conf.width * 2; //} //else if (s == left) //{ // newPos += Vector3.left * conf.width * 2; // newPos.x -= conf.gap; //} //else if (s == up) //{ // newPos.y += conf.gap; // newPos += Vector3.up * conf.height * 2; //} //else if (down == s) //{ // newPos += Vector3.down * conf.height * 2; // newPos.y -= conf.gap; //} #endregion switch (dir) { case Direction.Front: newPos += Vector3.forward * conf.length * 2; newPos.z += conf.gap; break; case Direction.Back: newPos += Vector3.back * conf.length * 2; newPos.z -= conf.gap; break; case Direction.Left: newPos.x += conf.gap; newPos += Vector3.right * conf.width * 2; break; case Direction.Right: newPos += Vector3.left * conf.width * 2; newPos.x -= conf.gap; break; case Direction.Up: newPos.y += conf.gap; newPos += Vector3.up * conf.height * 2; break; case Direction.Down: newPos += Vector3.down * conf.height * 2; newPos.y -= conf.gap; break; } this.X = newPos.x; this.Y = newPos.y; this.Z = newPos.z; }