void SetTileAt(GridPosition pos) { this.Repaint(); this.Focus(); if (currentSelectedTile != null) { ClearPrevious(); } currentSelectedTile = EditorTools.CurrentInspectedGrid.GetTile(pos); currentPos = pos; tiles = EditorTools.CurrentInspectedGrid.drawcircle(currentPos.x, currentPos.y, currentPos.z, Hrange, Vrange); SetLayerColor(); }
public void AddOverLay(GameTile tile) { GameObject go = new GameObject(); go.AddComponent <SpriteRenderer>(); go.GetComponent <SpriteRenderer>().sortingOrder = tile.Srenderer.sortingOrder + 1; go.transform.localPosition = tile.gameObject.transform.localPosition; go.transform.SetParent(tile.gameObject.transform); tile.overlays.Add(go.GetComponent <SpriteRenderer>()); go.name = "overlay"; #if UNITY_EDITOR UnityEditor.Undo.RegisterCreatedObjectUndo(go, "Create object"); #endif }
void OnSceneGUI(SceneView sceneView) { if (previewPath == null) { return; } positions = new Vector3[previewPath.Count]; for (int i = 0; i < previewPath.Count; i++) { GameTile tile = EditorTools.CurrentInspectedGrid.GetTile(previewPath[i]); Vector3 position; if (tile) { position = EditorTools.CurrentInspectedGrid.GetTile(previewPath[i]).CenterPoint; } else { position = Vector3.zero; } positions[i] = position; } Color tmp = Handles.color; Handles.color = Color.red; Handles.DrawPolyLine(positions); Handles.color = tmp; for (int i = 0; i < objList.list.Count; i++) { GameTile tile = EditorTools.CurrentInspectedGrid.GetTile(objList.list[i]); Vector3 position; if (tile) { position = EditorTools.CurrentInspectedGrid.GetTile(objList.list[i]).CenterPoint; } else { position = Vector3.zero; } Handles.Label(position, i.ToString(), EditorStyles.helpBox); } }
public Vector3 CenterPointOnGrid(GridPosition pos) { GameTile tile = GetTile(pos); if (tile != null) { return(tile.CenterPoint); } else { return(gameObject.transform.position + (pos.x * BlockDirections.NE + pos.y * BlockDirections.SE + pos.z * BlockDirections.UP)); } // if (tile) return tile.transform.position + GameGrid.BlockDirections.UP - verticalOffset; // else return Vector3.zero; }
public void DestroyBlock(GameTile tile) { GridPosition pos = FindTile(tile); if (pos.Equals(new GridPosition(-1, -1, -1))) { return; } layers[pos.z].Rows[pos.y].Tiles[pos.x] = null; #if UNITY_EDITOR UnityEditor.Undo.DestroyObjectImmediate(tile.gameObject); #else DestroyImmediate(tile.gameObject); #endif }
public GridPosition FindTile(GameTile tile) { for (int l = 0; l < layers.Count; l++) { for (int r = 0; r < layers[l].Rows.Count; r++) { for (int c = 0; c < layers[l].Rows[r].Tiles.Count; c++) { if (layers[l].Rows[r].Tiles[c] == tile) { return(new GridPosition(l, r, c)); } } } } return(new GridPosition(-1, -1, -1)); }
public void MoveInstant(GridPosition pos) { GameTile tile = GameGrid.currentGrid.GetTile(pos); if (tile) { body.transform.position = tile.CenterPoint + topOffset; Position = pos.Clone(); TruePosition = Position.Clone(); body.sRenderer.sortingOrder = InputHandlerer.GetSortingOrder(this); body.shadowRenderer.sortingOrder = body.sRenderer.sortingOrder - 1; } else { Debug.LogWarning("No Tile At Spawnpoint : " + pos); } }
public List <GridPosition> GetAllWalkableTileInRange(GridPosition pos, int range, bool includeOccupied) { List <GridPosition> tiles = new List <GridPosition>(); for (int z = pos.z - range; z <= pos.z + range; z++) { if (z < 0) { continue; } if (z > layers.Count - 1) { continue; } for (int y = -range; y <= range; y++) { for (int x = -range; x <= range; x++) { if (x * x + y * y <= range * range) { GridPosition position = new GridPosition(z, y + pos.y, x + pos.x); GameTile tile = GetTile(position); if (tile == null) { continue; } if (HasTileOnTop(position)) { continue; } if (!includeOccupied && Character.isCharacterInTile(position)) { continue; } tiles.Add(position); } } } } return(tiles); }
void OnGUI() { GameTile selectedTile = null; if (Selection.activeGameObject != GridEditor.selectedTile && Selection.activeGameObject != null) { selectedTile = Selection.activeGameObject.GetComponent <GameTile>(); } EditorGUI.BeginDisabledGroup(GridEditor.selectedTile == null && selectedTile == null); if (GUILayout.Button("Pick")) { if (callback != null) { GridPosition pos; if (selectedTile != null) { pos = EditorTools.CurrentInspectedGrid.FindTile(selectedTile); } else { pos = GridEditor.Selected; } if (OnPreChangeCallback != null) { OnPreChangeCallback(); } callback.Invoke(pos); } if (OnChangeCallback != null) { OnChangeCallback.Invoke(); } this.Close(); } EditorGUI.EndDisabledGroup(); }
public TemplateCreatorPopUp(TileTemplateDatabase database, GameTile targetTile) { this.tile = targetTile; this.database = database; }
public override void OnInspectorGUI() { if (skini == null) { skini = EditorGUIUtility.Load("Navigation.guiskin") as GUISkin; } EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("P", EditorStyles.miniButtonRight, GUILayout.Width(20))) { var asm = Assembly.GetAssembly(typeof(EditorWindow)); var T = asm.GetType("UnityEditor.PreferencesWindow"); var M = T.GetMethod("ShowPreferencesWindow", BindingFlags.NonPublic | BindingFlags.Static); M.Invoke(null, null); } EditorGUILayout.EndHorizontal(); DrawDefaultInspector(); // get the chosen game object GameGrid t = target as GameGrid; if (t == null) { return; } if (database == null) { database = (TileTemplateDatabase)AssetDatabase.LoadAssetAtPath("Assets/TileTempalteDatabase.asset", typeof(TileTemplateDatabase)); } if (t.layers.Count == 0) { t.Initialize(); } EditorGUI.BeginChangeCheck(); currentTilestyle = EditorGUILayout.Popup("Templates", currentTilestyle, database.GetNames()); if (EditorGUI.EndChangeCheck()) { if (selectedTile) { selectedTile.SetData(database.tiles[currentTilestyle]); } } if (GUILayout.Button("New Style") && selectedTile != null) { PopupWindow.Show(buttonRect, new TemplateCreatorPopUp(database, selectedTile)); } if (Event.current.type == EventType.Repaint) { buttonRect = GUILayoutUtility.GetLastRect(); } t.GridSortingWeights[0] = EditorGUILayout.IntField("Column", t.GridSortingWeights[0]); t.GridSortingWeights[1] = EditorGUILayout.IntField("Row", t.GridSortingWeights[1]); t.GridSortingWeights[2] = EditorGUILayout.IntField("Layer", t.GridSortingWeights[2]); EditorGUI.BeginChangeCheck(); Navigation(t); if (selectedTile != t.layers[Selected.z].Rows[Selected.y].Tiles[Selected.x]) { selectedTile = t.layers[Selected.z].Rows[Selected.y].Tiles[Selected.x]; if (selectedTile != null) { tileEditor = Editor.CreateEditor(selectedTile); ((GameTileEditor)tileEditor).gridEditorMode = true; } } if (selectedTile != null) { if (tileEditor == null) { tileEditor = Editor.CreateEditor(selectedTile); ((GameTileEditor)tileEditor).gridEditorMode = true; } if (tileEditor != null && selectedTile != null) { tileEditor.OnInspectorGUI(); } } else { EditorGUILayout.BeginHorizontal(EditorStyles.helpBox); EditorGUILayout.LabelField("Sprite", GUILayout.Width(38)); if (GUILayout.Button("+", GUILayout.Width(20))) { t.CreateBlock(Selected.y, Selected.x, Selected.z); if (LastSprite != null) { t.layers[Selected.z].Rows[Selected.y].Tiles[Selected.x].Srenderer.sprite = LastSprite; } else { LastSprite = t.layers[Selected.z].Rows[Selected.y].Tiles[Selected.x].Srenderer.sprite; } if (database.tiles.Count != 0) { t.layers[Selected.z].Rows[Selected.y].Tiles[Selected.x].SetData(database.tiles[currentTilestyle]); } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); if (GUILayout.Button("New Layer")) { t.CreateEmptyLayer(t.layers.Count); Selected.z = t.layers.Count - 1; SceneView.RepaintAll(); } if (EditorGUI.EndChangeCheck()) { EditorPrefs.SetInt("selectedX", Selected.x); EditorPrefs.SetInt("selectedY", Selected.y); EditorPrefs.SetInt("selectedZ", Selected.z); } if (GUILayout.Button("Fill")) { t.FillLayer(Selected.z); UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(t.gameObject.scene); } if (GUILayout.Button("Reset Grid")) { t.ResetGrid(); UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(t.gameObject.scene); } if (GUI.changed && !Application.isPlaying) { EditorUtility.SetDirty(t.gameObject); Debug.Log("SAved"); } WasdListener(t); }
void OnSceneGUI(SceneView sceneView) { if (EditorTools.CurrentInspectedGrid == null) { return; } Mission selectedMission = target as Mission; int i = 0; for (i = 0; i < selectedMission.Teams.Count; i++) { for (int q = 0; q < selectedMission.Teams[i].Members.Count; q++) { Vector3 position = EditorTools.CurrentInspectedGrid.CenterPointOnGrid(selectedMission.Teams[i].Members[q].SpawnPositon); Handles.DrawLine(position, position + Vector3.up); GameGrid.BlockDirections.FaceDirections facedir = selectedMission.Teams[i].Members[q].SpawnDirection; Handles.DrawSolidRectangleWithOutline(CreateArrow(facedir, position), teamColors[i], Color.red); // grab the center of the parent Vector3 center = position + GameGrid.BlockDirections.NW / 2 + GameGrid.BlockDirections.SW / 2; Handles.DrawLine(center + Vector3.zero, center + GameGrid.BlockDirections.SE); Handles.DrawLine(center + Vector3.zero, center + GameGrid.BlockDirections.NE); Handles.DrawLine(center + GameGrid.BlockDirections.SE, center + GameGrid.BlockDirections.SE + GameGrid.BlockDirections.NE); Handles.DrawLine(center + GameGrid.BlockDirections.NE, center + GameGrid.BlockDirections.NE + GameGrid.BlockDirections.SE); center += GameGrid.BlockDirections.Down; /* * Handles.DrawLine(center + Vector3.zero, center + GameGrid.BlockDirections.SE); * Handles.DrawLine(center + Vector3.zero, center + GameGrid.BlockDirections.NE); * * Handles.DrawLine(center + GameGrid.BlockDirections.SE, center + GameGrid.BlockDirections.SE + GameGrid.BlockDirections.NE); * Handles.DrawLine(center + GameGrid.BlockDirections.NE, center + GameGrid.BlockDirections.NE + GameGrid.BlockDirections.SE); * * Handles.DrawLine(center, center + GameGrid.BlockDirections.UP); * Handles.DrawLine(center + GameGrid.BlockDirections.SE, center + GameGrid.BlockDirections.SE + GameGrid.BlockDirections.UP); * * Handles.DrawLine(center + GameGrid.BlockDirections.SE + GameGrid.BlockDirections.NE, center + GameGrid.BlockDirections.SE + GameGrid.BlockDirections.NE + GameGrid.BlockDirections.UP); * */ if (selectedMission.Teams.Count < selectedCharacterIndex[0] || selectedMission.Teams[selectedCharacterIndex[0]].members.Count < selectedCharacterIndex[1]) { selectedCharacterIndex[0] = 0; selectedCharacterIndex[1] = 0; characterSelected = false; } center = selectedMission.Teams[selectedCharacterIndex[0]].Members[selectedCharacterIndex[1]].SpawnPositon.z * GameGrid.BlockDirections.UP + EditorTools.CurrentInspectedGrid.transform.position - GameGrid.BlockDirections.SE + GridEditor.verticalOffset; Handles.DrawLine(center + Vector3.zero, center + GameGrid.BlockDirections.SE * EditorTools.CurrentInspectedGrid.rows); Handles.DrawLine(center + Vector3.zero, center + GameGrid.BlockDirections.NE * EditorTools.CurrentInspectedGrid.columns); if (PreferenceWindow.ShowCrosshair) { Handles.DrawLine(center + GameGrid.BlockDirections.SE * EditorTools.CurrentInspectedGrid.rows / 2, center + GameGrid.BlockDirections.SE * EditorTools.CurrentInspectedGrid.rows / 2 + GameGrid.BlockDirections.NE * EditorTools.CurrentInspectedGrid.columns); Handles.DrawLine(center + GameGrid.BlockDirections.NE * EditorTools.CurrentInspectedGrid.columns / 2, center + GameGrid.BlockDirections.NE * EditorTools.CurrentInspectedGrid.columns / 2 + GameGrid.BlockDirections.SE * EditorTools.CurrentInspectedGrid.rows); } Handles.DrawLine(center + GameGrid.BlockDirections.SE * EditorTools.CurrentInspectedGrid.rows, center + GameGrid.BlockDirections.SE * EditorTools.CurrentInspectedGrid.rows + GameGrid.BlockDirections.NE * EditorTools.CurrentInspectedGrid.columns); Handles.DrawLine(center + GameGrid.BlockDirections.NE * EditorTools.CurrentInspectedGrid.columns, center + GameGrid.BlockDirections.NE * EditorTools.CurrentInspectedGrid.columns + GameGrid.BlockDirections.SE * EditorTools.CurrentInspectedGrid.rows); } } if (characterSelected && selectedMission.Teams.Count != 0) { if (ObjectHilighter.currentEditor == this) { GameTile tile = EditorTools.CurrentInspectedGrid.GetTile(selectedMission.Teams[selectedCharacterIndex[0]].Members[selectedCharacterIndex[1]].SpawnPositon); if (tile) { ObjectHilighter.Clear(); ObjectHilighter.Add(tile.GetComponent <SpriteRenderer>(), this); } else { ObjectHilighter.Clear(); } } Vector3 spawnPos = EditorTools.CurrentInspectedGrid.CenterPointOnGrid(selectedMission.Teams[selectedCharacterIndex[0]].Members[selectedCharacterIndex[1]].SpawnPositon); if (Event.current.type == EventType.MouseDrag) { float closestDist = Mathf.Infinity; int closestDir = 0; Vector3[] positions = new Vector3[] { spawnPos, spawnPos + GameGrid.BlockDirections.NW, spawnPos + GameGrid.BlockDirections.NE, spawnPos + GameGrid.BlockDirections.SE, spawnPos + GameGrid.BlockDirections.SW, spawnPos + GameGrid.BlockDirections.UP, spawnPos + GameGrid.BlockDirections.Down }; for (int c = 0; c < positions.Length; c++) { if (Vector3.Distance(selectedCharacterDragPosition, positions[c]) < closestDist) { closestDir = c; closestDist = Vector3.Distance(selectedCharacterDragPosition, positions[c]); } } if (Event.current.modifiers == EventModifiers.Control) { if (closestDir == 5 || closestDir == 6) { closestDir = 0; } } if (closestDir != 0) { GridPosition future = selectedMission.Teams[selectedCharacterIndex[0]].Members[selectedCharacterIndex[1]].SpawnPositon.Clone() + InputHandlerer.GetMovement(closestDir); if (EditorTools.CurrentInspectedGrid.isInBounds(future)) { Undo.RecordObject(target, "Move"); selectedMission.Teams[selectedCharacterIndex[0]].Members[selectedCharacterIndex[1]].SpawnPositon += InputHandlerer.GetMovement(closestDir); } } } if (Event.current.type == EventType.MouseUp) { selectedCharacterDragPosition = EditorTools.CurrentInspectedGrid.CenterPointOnGrid(selectedMission.Teams[selectedCharacterIndex[0]].Members[selectedCharacterIndex[1]].SpawnPositon); sceneView.Repaint(); } selectedCharacterDragPosition = Handles.PositionHandle(selectedCharacterDragPosition, Quaternion.Euler(-60, 0, 45)); } for (i = 0; i < selectedMission.Teams.Count; i++) { for (int q = 0; q < selectedMission.Teams[i].Members.Count; q++) { Vector3 position = EditorTools.CurrentInspectedGrid.CenterPointOnGrid(selectedMission.Teams[i].Members[q].SpawnPositon); Vector3 buttonPosition = position + Vector3.up; float size = 0.25f; float pickSize = size * 2f; Vector2 screenPos = HandleUtility.WorldToGUIPoint(buttonPosition); Rect areaRect = new Rect(screenPos.x - 120 / 2, screenPos.y, 120, 50); GUILayout.BeginArea(areaRect); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(selectedMission.Teams[i].Members[q]._Name, EditorStyles.miniButtonMid)) { SessionState.SetInt("MissionEditor_LastTeamIndex", i); SessionState.SetInt("CharacterEditor_LastCharacterIndex", q); CharacterEditor newEditor = EditorWindow.CreateInstance <CharacterEditor>(); newEditor.Do(selectedMission.Teams[i].Members[q], selectedMission, selectedMission, false); newEditor.SetParent(this); auxWindow = newEditor; EditorWindow.FocusWindowIfItsOpen <MissionEditor>(); selectedCharacterIndex = new int[] { i, q }; characterSelected = true; selectedCharacterDragPosition = position; ObjectHilighter.Clear(); ObjectHilighter.currentEditor = this; Selection.activeGameObject = null; } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); GUILayout.EndArea(); } } Handles.Label(Vector3.up, "", EditorStyles.boldLabel); }
public override void OnInspectorGUI() { GameTile selectedTile = target as GameTile; if (selectedTile == null) { return; } if (!gridEditorMode) { if (GUILayout.Button("Find In Grid")) { GameGrid parentGrid = selectedTile.gameObject.GetComponentInParent <GameGrid>(); if (parentGrid == null) { return; } GridPosition pos = parentGrid.FindTile(selectedTile); EditorPrefs.SetInt("selectedX", pos.x); EditorPrefs.SetInt("selectedY", pos.y); EditorPrefs.SetInt("selectedZ", pos.z); Selection.activeGameObject = parentGrid.gameObject; } } if (selectedTile != null) { EditorGUI.BeginChangeCheck(); //Tile + overlays EditorGUILayout.BeginHorizontal(EditorStyles.helpBox, GUILayout.Height(150)); //Main texture EditorGUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.Width(60)); GUILayout.FlexibleSpace(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Sprite", GUILayout.Width(38)); bool deleteTile = GUILayout.Button("x", GUILayout.Width(20)); EditorGUILayout.EndHorizontal(); Sprite currentSprite = EditorGUILayout.ObjectField(GUIContent.none, selectedTile.Srenderer.sprite, typeof(Sprite), false, GUILayout.Width(60)) as Sprite; if (EditorGUI.EndChangeCheck()) { LastSprite = currentSprite; foreach (GameTile tg in targets) { Undo.RecordObject(tg.Srenderer, "Change Sprite"); tg.Srenderer.sprite = LastSprite; } } GUILayout.Space(-7); EditorGUI.BeginChangeCheck(); Color defColor = EditorGUILayout.ColorField(GUIContent.none, selectedTile.DefaultColor, false, true, false, new ColorPickerHDRConfig(1, 1, 1, 1), GUILayout.Width(60)); if (EditorGUI.EndChangeCheck()) { foreach (GameTile tg in targets) { Undo.RecordObjects(new Object[] { tg.Srenderer, tg }, "Change Sprite"); tg.Srenderer.color = defColor; tg.DefaultColor = defColor; } } //end Main texture GUILayout.FlexibleSpace(); EditorGUILayout.EndVertical(); bool layerCountMatch = true; for (int i = targets.Length - 1; i > 0; i--) { if (((GameTile)targets[i]).overlays.Count != ((GameTile)targets[i - 1]).overlays.Count) { layerCountMatch = false; } } if (layerCountMatch) { //Overlays EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.BeginHorizontal(EditorStyles.helpBox); EditorGUILayout.LabelField("Overlays"); if (GUILayout.Button("+", GUILayout.Width(20))) { Undo.RecordObjects(targets, "Change Sprite"); foreach (GameTile tg in targets) { tg.AddOverLay(tg); } } EditorGUILayout.EndHorizontal(); overlayScrollPosition = EditorGUILayout.BeginScrollView(overlayScrollPosition); EditorGUILayout.BeginHorizontal(); for (int i = 0; i < selectedTile.overlays.Count; i++) { EditorGUILayout.BeginVertical(GUILayout.Width(60)); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Sprite", GUILayout.Width(38)); bool deleteOverlay = GUILayout.Button("x"); EditorGUILayout.EndHorizontal(); selectedTile.overlays[i].sprite = EditorGUILayout.ObjectField(GUIContent.none, selectedTile.overlays[i].sprite, typeof(Sprite), false, GUILayout.Width(60)) as Sprite; EditorGUILayout.EndVertical(); if (deleteOverlay) { GameObject.DestroyImmediate(selectedTile.overlays[i].gameObject); selectedTile.overlays.RemoveAt(i); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); } else { EditorGUILayout.HelpBox("Overlay Count missmatch." + System.Environment.NewLine + "Multi Object editing supports only Tiles with same amount of overlays", MessageType.Warning, true); } //End tile + overlays EditorGUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); bool isWalkable = EditorGUILayout.Toggle("Walkable", selectedTile.isWalkable); if (EditorGUI.EndChangeCheck()) { foreach (GameTile tg in targets) { Undo.RecordObject(tg, "Change Sprite"); tg.isWalkable = isWalkable; } } if (deleteTile) { Undo.RecordObject(EditorTools.CurrentInspectedGrid, "Delete Tile"); foreach (GameTile tg in targets) { EditorTools.CurrentInspectedGrid.DestroyBlock(tg); } // t.DestroyBlock(Selected.y, Selected.x, Selected.z); } } if (!gridEditorMode && target != null) { DrawDefaultInspector(); } }
public WalType CanBeWalked(GridPosition currrentpos, GridPosition pos, out GridPosition tile, bool skipGap = false) { tile = null; if (!isInBounds(pos)) { return(WalType.CannotWalk); } if (!HasTilesVertical(pos.Clone())) { return(WalType.CannotWalk); } if (!HasTileOnTop(pos)) { if (GetTile(pos.x, pos.y, pos.z) != null && GetTile(pos.x, pos.y, pos.z).isWalkable) { tile = pos; return(WalType.CanWalk); } } else { if (CanBeJumpedTo(1, pos)) { tile = pos; GameTile roof = GetTile(currrentpos.x, currrentpos.y, currrentpos.z + 2); if (roof == null && GetTile(pos.x, pos.y, pos.z).isWalkable) { return(WalType.JumUp); } } } if (pos.z > 0) { tile = GetHighestJumpablePosition(pos); //ERWERTWETRYYRRYEWYREYRE if (GetHighestJumpablePosition(pos).z > currrentpos.z && GetTile(tile) != null) { GameTile roof = GetTile(currrentpos.x, currrentpos.y, currrentpos.z + 2); if (roof == null && GetTile(tile).isWalkable) { return(WalType.JumUp); } } else if (GetTile(tile) != null && GetTile(tile).isWalkable) { return(WalType.JumUp); } } if (skipGap) { GridPosition direction = currrentpos - pos; GridPosition tempPos = currrentpos.Clone(); while (GameGrid.currentGrid.isInBounds(tempPos)) { tempPos += direction; tile = GetHighestJumpablePosition(pos); if (tile != null) { return(WalType.CanWalk); } } } return(WalType.CannotWalk); }
public List <GridPosition> GetVisibleTiles(GridPosition pos, GridPosition forward, int range, bool debug = false, bool playermode = false) { List <GridPosition> _visibleTiles = new List <GridPosition>(); List <GridPosition> BannedTiles = new List <GridPosition>(); GridPosition checkpos = pos.Clone(); forward = new GridPosition(0, 0, 1); int faceRange = range; for (int up = 0; up < range + range + 1; up++) { for (int iforward = 0; iforward < faceRange + range + 1; iforward++) { GridPosition tempPos = checkpos.Clone() + forward.GetReversed() * range + (forward * iforward) + GridPosition.Left(forward) * range + (GridPosition.UP * (range + 1)).GetReversed() + GridPosition.UP * up; if (tempPos.x == pos.x && forward.x != 0 && range != -1) { continue; } if (tempPos.y == pos.y && forward.y != 0 && range != -1) { continue; } for (int right = 0; right < range * 2 + 1; right++) { GridPosition Bpos = tempPos.Clone() + GridPosition.Left(forward).GetReversed() * right; GameTile tile = GetTile(Bpos); if (tile) { if (DoLine(checkpos.x, checkpos.y, checkpos.z, Bpos.x, Bpos.y, Bpos.z)) { _visibleTiles.Add(Bpos); } } if (HasTileOnTop(Bpos)) { if (checkpos.x > Bpos.x && checkpos.y < Bpos.y) { int[,] positions = { { 0, 1, 0 }, { 0, 1, -1 }, { 0, 0, -1 } }; for (int i = 0; i < positions.GetLength(0); i++) { GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]); if (GetTile(newPosition)) { BannedTiles.Add(newPosition); } } } if (checkpos.x > Bpos.x && checkpos.y > Bpos.y) { int[,] positions = { { 0, -1, 0 }, { 0, -1, -1 }, { 0, 0, -1 } }; for (int i = 0; i < positions.GetLength(0); i++) { GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]); if (GetTile(newPosition)) { BannedTiles.Add(newPosition); } } } if (checkpos.x < Bpos.x && checkpos.y < Bpos.y) { int[,] positions = { { 0, 1, 0 }, { 0, 1, 1 }, { 0, 0, 1 } }; for (int i = 0; i < positions.GetLength(0); i++) { GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]); if (GetTile(newPosition)) { BannedTiles.Add(newPosition); } } } if (checkpos.x < Bpos.x && checkpos.y > Bpos.y) { int[,] positions = { { 0, -1, 0 }, { 0, -1, 1 }, { 0, 0, 1 } }; for (int i = 0; i < positions.GetLength(0); i++) { GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]); if (GetTile(newPosition)) { BannedTiles.Add(newPosition); } } } if (InRange(checkpos, Bpos, 3)) { if (checkpos.x == Bpos.x && checkpos.y < Bpos.y) { int[,] positions = { { 0, 1, 0 }, { 0, 1, -1 }, { 0, 1, 1 }, { 0, 0, 1 }, { 0, 0, -1 } }; for (int i = 0; i < positions.GetLength(0); i++) { GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]); if (GetTile(newPosition)) { BannedTiles.Add(newPosition); } } } if (checkpos.x == Bpos.x && checkpos.y > Bpos.y) { int[,] positions = { { 0, -1, 0 }, { 0, -1, 1 }, { 0, -1, -1 }, { 0, 0, -1 }, { 0, 0, 1 } }; for (int i = 0; i < positions.GetLength(0); i++) { GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]); if (GetTile(newPosition)) { BannedTiles.Add(newPosition); } } } if (checkpos.x > Bpos.x && checkpos.y == Bpos.y) { int[,] positions = { { 0, -1, 0 }, { 0, -1, -1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, 1, -1 } }; for (int i = 0; i < positions.GetLength(0); i++) { GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]); if (GetTile(newPosition)) { BannedTiles.Add(newPosition); } } } if (checkpos.x < Bpos.x && checkpos.y == Bpos.y) { int[,] positions = { { 0, 1, 0 }, { 0, 1, 1 }, { 0, 0, 1 }, { 0, -1, 0 }, { 0, -1, 1 } }; for (int i = 0; i < positions.GetLength(0); i++) { GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]); if (GetTile(newPosition)) { BannedTiles.Add(newPosition); } } } } } } } } if (playermode) { List <GridPosition> adjancedPositions = GetAdjancedPositions(pos); foreach (GridPosition gp in adjancedPositions) { if (GetTile(gp) == null) { _visibleTiles.Add(GetHighestTileBellow(gp)); } } } List <GridPosition> diagonals = GetDialognaldPositions(pos); foreach (GridPosition diag in diagonals) { if (HasTileOnTop(diag)) { List <GridPosition> corners = GetDialognaldPositions(diag); foreach (GridPosition corner in corners) { if (GetTile(corner) != null) { } BannedTiles.Add(corner); do { _visibleTiles.Remove(corner); } while (_visibleTiles.Contains(corner)); } } } foreach (GridPosition tile in BannedTiles) { for (int i = 0; i < _visibleTiles.Count; i++) { if (tile.Equals(_visibleTiles[i])) { _visibleTiles.RemoveAt(i); } } } foreach (GridPosition tile in _visibleTiles) { if (tile != null) { GameTile tl = GetTile(tile); if (tl) { VisibleTiles.Add(tl); if (debug) { tl.Srenderer.color *= Color.red; } } } } return(_visibleTiles); }