public void _Equals() { var pos = new GridPos(5, 6); var other = new GridPos(5, 6); var third = new GridPos(6, 5); Assert.Multiple(() => { Assert.That(pos.Equals(pos)); Assert.That(pos.Equals(other)); Assert.That(!pos.Equals(third)); Assert.That(pos.Equals((object)other)); Assert.That(!pos.Equals(null)); }); }
// Use this for initialization void Start() { if (!IsPreview && gameObject.name.Contains("Wall")) { for (int i = 0; i < PersistentData.m_Instance.BuildingGridPos.Count; ++i) { if (GridPos.Equals((PersistentData.m_Instance.BuildingGridPos[i]).GetVec2()) && !PersistentData.m_Instance.BuildingName[i].Contains("+") /* && !gameObject.name.Contains(PersistentData.m_Instance.BuildingName[i])*/) { PersistentData.m_Instance.BuildingName[i] += "+" + gameObject.name; break; } } } else { if (!IsPreview && !CheckIfExist()) { PersistentData.m_Instance.BuildingGridPos.Add(new SerializableVector2(GridPos.x, GridPos.y)); PersistentData.m_Instance.BuildingName.Add(BuildingName); } } }
public void SetGridPosition(GridPos gridPos) { if (!gridPos.Equals(MechaComponentInfo.GridPos)) { foreach (GridPos gp in MechaComponentInfo.OccupiedGridPositions) { GridPos gp_rot = GridPos.RotateGridPos(gp - MechaComponentInfo.GridPos, (GridPos.Orientation)((gridPos.orientation - MechaComponentInfo.GridPos.orientation + 4) % 4)); GridPos newGP = gp_rot + gridPos; if (newGP.x > ConfigManager.EDIT_AREA_SIZE) { SetGridPosition(new GridPos(gridPos.x - 1, gridPos.z, gridPos.orientation)); return; } if (newGP.x < -ConfigManager.EDIT_AREA_SIZE) { SetGridPosition(new GridPos(gridPos.x + 1, gridPos.z, gridPos.orientation)); return; } if (newGP.z > ConfigManager.EDIT_AREA_SIZE) { SetGridPosition(new GridPos(gridPos.x, gridPos.z - 1, gridPos.orientation)); return; } if (newGP.z < -ConfigManager.EDIT_AREA_SIZE) { SetGridPosition(new GridPos(gridPos.x, gridPos.z + 1, gridPos.orientation)); return; } } MechaComponentInfo.GridPos = gridPos; GridPos.ApplyGridPosToLocalTrans(gridPos, transform, GameManager.GridSize); RefreshOccupiedGridPositions(); ParentMecha?.RefreshMechaMatrix(); } }
void UpdateGridCubes(ref GridPos prevGridPosL, ref GridPos newGridPosL, int gridSize, Dictionary<String, GameObject> LDict, int level) { newGridPosL = GridUtils.WorldToGrid(playerObject.transform.position, gridSize); if (!prevGridPosL.Equals(newGridPosL)) { GridPos deltaPos = prevGridPosL.Delta(newGridPosL); GridPos vPosL; string vPosKeyL; GameObject gObj; Vector3 newVector3; GridPos newGridPos; if (deltaPos.x != 0) { for (var i = -1; i <= 1; i++) { for (var j = -1; j <= 1; j++) { vPosL = new GridPos(prevGridPosL.x - deltaPos.x, prevGridPosL.y + i, prevGridPosL.z + j); vPosKeyL = vPosL.ToKeyString(); if (LDict.ContainsKey(vPosKeyL)) { gObj = LDict[vPosKeyL]; LDict.Remove(vPosKeyL); newGridPos = new GridPos(newGridPosL.x + deltaPos.x, prevGridPosL.y + i, prevGridPosL.z + j); newVector3 = new Vector3(newGridPos.x * gridSize, newGridPos.y * gridSize, newGridPos.z * gridSize); gObj.transform.position = newVector3; LDict.Add(newGridPos.ToKeyString(), gObj); StartCoroutine(TransitionRenderCube(gObj, level, newGridPos)); } else { Debug.Log("KEY NOT FOUND :" + vPosKeyL); } } } } if (deltaPos.z != 0) { for (var i = -1 + deltaPos.x; i <= 1 + deltaPos.x; i++) { for (var j = -1; j <= 1; j++) { vPosL = new GridPos(prevGridPosL.x + i, prevGridPosL.y + j, prevGridPosL.z - deltaPos.z); vPosKeyL = vPosL.ToKeyString(); if (LDict.ContainsKey(vPosKeyL)) { gObj = LDict[vPosKeyL]; LDict.Remove(vPosKeyL); newGridPos = new GridPos(prevGridPosL.x + i, prevGridPosL.y + j, newGridPosL.z + deltaPos.z); newVector3 = new Vector3(newGridPos.x * gridSize, newGridPos.y * gridSize, newGridPos.z * gridSize); gObj.transform.position = newVector3; LDict.Add(newGridPos.ToKeyString(), gObj); StartCoroutine(TransitionRenderCube(gObj, level, newGridPos)); } else { Debug.Log("KEY NOT FOUND :" + vPosKeyL); } } } } if (deltaPos.y != 0) { for (var i = -1 + deltaPos.x; i <= 1 + deltaPos.x; i++) { for (var j = -1 + deltaPos.z; j <= 1 + deltaPos.z; j++) { vPosL = new GridPos(prevGridPosL.x + i, prevGridPosL.y - deltaPos.y, prevGridPosL.z + j); vPosKeyL = vPosL.ToKeyString(); if (LDict.ContainsKey(vPosKeyL)) { gObj = LDict[vPosKeyL]; LDict.Remove(vPosKeyL); newGridPos = new GridPos(prevGridPosL.x + i, newGridPosL.y + deltaPos.y, prevGridPosL.z + j); newVector3 = new Vector3(newGridPos.x * gridSize, newGridPos.y * gridSize, newGridPos.z * gridSize); gObj.transform.position = newVector3; LDict.Add(newGridPos.ToKeyString(), gObj); StartCoroutine(TransitionRenderCube(gObj, level, newGridPos)); } else { Debug.Log("KEY NOT FOUND :" + vPosKeyL); } } } } prevGridPosL = newGridPosL; } }