Esempio n. 1
0
        void Navigation(GameGrid t)
        {
            //return;


            EditorGUILayout.BeginHorizontal(EditorStyles.helpBox);

            GUILayout.FlexibleSpace();
            EditorGUILayout.BeginVertical(GUILayout.Width(50));


            EditorGUILayout.BeginHorizontal();

            GUILayout.FlexibleSpace();
            if (GUILayout.Button("", skini.customStyles[0], GUILayout.Width(50), GUILayout.Height(50)))
            {
                Move(1, -1, t);
            }
            if (GUILayout.Button("", skini.customStyles[1], GUILayout.Width(50), GUILayout.Height(50)))
            {
                Move(0, 1, t);
            }
            GUILayout.FlexibleSpace();

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();


            if (GUILayout.Button("", skini.customStyles[3], GUILayout.Width(50), GUILayout.Height(50)))
            {
                Move(0, -1, t);
            }
            if (GUILayout.Button("", skini.customStyles[2], GUILayout.Width(50), GUILayout.Height(50)))
            {
                Move(1, 1, t);
            }



            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();
            EditorGUILayout.BeginVertical(GUILayout.Width(50));
            if (GUILayout.Button("^ Layer", EditorStyles.miniButton, GUILayout.Width(50), GUILayout.Height(50)))
            {
                Move(2, 1, t);
            }
            if (GUILayout.Button("v Layer", EditorStyles.miniButton, GUILayout.Width(50), GUILayout.Height(50)))
            {
                Move(2, -1, t);
            }
            EditorGUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
        }
        public static void EditorField(this GridPosition pos, Mission mission, GameGrid grid, GUIContent prefix)
        {
            EditorGUI.BeginChangeCheck();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label(prefix);
            GUILayout.FlexibleSpace();
            int x = IntField(pos.x, new GUIContent("X"));

            GUILayout.Space(2);
            // GUILayout.FlexibleSpace();
            int y = IntField(pos.y, new GUIContent("Y"));

            GUILayout.Space(2);
            int z = IntField(pos.z, new GUIContent("Z"));

            // GUILayout.FlexibleSpace();
            if (PickField(ref pos))
            {
                Debug.Log(pos.ToString());
            }
            else if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(mission, "Modify Grid Position");
                pos.x = x;
                pos.y = y;
                pos.z = z;

                if (pos.x < 0)
                {
                    pos.x = 0;
                }
                else if (pos.x > grid.columns)
                {
                    pos.x = grid.columns;
                }
                if (pos.y < 0)
                {
                    pos.y = 0;
                }
                else if (pos.y > grid.rows)
                {
                    pos.y = grid.rows;
                }
                if (pos.z < 0)
                {
                    pos.z = 0;
                }
                else if (pos.z > grid.layers.Count)
                {
                    pos.z = grid.layers.Count;
                }
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
        }
Esempio n. 3
0
        public List <Character> EnemiesInsideRange(List <GridPosition> lst)
        {
            List <Character> characters = new List <Character>();

            foreach (GridPosition pos in lst)
            {
                GameGrid.AddToListIfNotNull <Character>(GetEnemyAtTile(pos, this), characters);
            }
            characters.Sort((a, b) => (Position.Distance(a.Position).CompareTo(Position.Distance(b.Position))));
            return(characters);
        }
Esempio n. 4
0
        public static List <GameTile> ToGameTiles(List <GridPosition> list, GameGrid grid)
        {
            List <GameTile> tiles = new List <GameTile>();

            foreach (GridPosition pos in list)
            {
                AddToListIfNotNull <GameTile>(grid.GetTile(pos), tiles);
            }

            return(tiles);
        }
Esempio n. 5
0
        void WasdListener(GameGrid t)
        {
            Event e = Event.current;

            switch (e.type)
            {
            case EventType.KeyDown:
            {
                if (Event.current.keyCode == (KeyCode.A) || Event.current.keyCode == KeyCode.LeftArrow)
                {
                    Move(1, -1, t);
                }

                if (Event.current.keyCode == (KeyCode.D) || Event.current.keyCode == KeyCode.RightArrow)
                {
                    Move(1, 1, t);
                }

                if (Event.current.keyCode == (KeyCode.W) || Event.current.keyCode == KeyCode.UpArrow)
                {
                    if (Event.current.shift)
                    {
                        Move(2, 1, t);
                    }
                    else
                    {
                        Move(0, 1, t);
                    }
                }

                if (Event.current.keyCode == (KeyCode.S) || Event.current.keyCode == KeyCode.DownArrow)
                {
                    if (Event.current.shift)
                    {
                        Move(2, -1, t);
                    }
                    else
                    {
                        Move(0, -1, t);
                    }
                }


                if (Event.current.keyCode == (KeyCode.Backspace) || Event.current.keyCode == KeyCode.Delete)
                {
                    t.DestroyBlock(Selected.y, Selected.x, Selected.z);
                }

                e.Use();
                break;
            }
            }
        }
Esempio n. 6
0
        public void ShowAllLayers()
        {
            GameGrid t = target as GameGrid;

            if (t == null)
            {
                return;
            }

            for (int i = 0; i < t.layers.Count; i++)
            {
                t.layers[i].ReturnNormalOpacity();
            }
        }
Esempio n. 7
0
        public void OnEnable()
        {
            GameGrid t = target as GameGrid;

            if (t == null)
            {
                return;
            }

            database = (TileTemplateDatabase)AssetDatabase.LoadAssetAtPath("Assets/TileTempalteDatabase.asset", typeof(TileTemplateDatabase));

            SetLayerOpacity();


            if (EditorPrefs.HasKey("selectedX"))
            {
                Selected.x = EditorPrefs.GetInt("selectedX");
                Selected.y = EditorPrefs.GetInt("selectedY");
                Selected.z = EditorPrefs.GetInt("selectedZ");


                if (!t.isInBounds(new GridPosition(Selected.z, Selected.y, Selected.z)))
                {
                    Selected.x = 0;
                    Selected.y = 0;
                    Selected.z = 0;

                    EditorPrefs.SetInt("selectedX", Selected.x);
                    EditorPrefs.SetInt("selectedY", Selected.y);
                    EditorPrefs.SetInt("selectedZ", Selected.z);
                }
            }

            if (EditorPrefs.HasKey("selectedX"))
            {
                ShowAll = EditorPrefs.GetBool("ShowAll");
            }
        }
Esempio n. 8
0
        void Move(int dir, int amount, GameGrid t)
        {
            int[] dirs = new int[] { t.rows - 1, t.columns - 1, t.layers.Count - 1 };

            if (dir == 0)
            {
                Selected.x += amount;
                Selected.x  = FitToGrid(Selected.x, dirs[dir]);
            }
            else if (dir == 1)
            {
                Selected.y += amount;
                Selected.y  = FitToGrid(Selected.y, dirs[dir]);
            }
            else if (dir == 2)
            {
                Selected.z += amount;
                Selected.z  = FitToGrid(Selected.z, dirs[dir]);
                SetLayerOpacity();
            }

            SceneView.RepaintAll();
            this.Repaint();
        }
Esempio n. 9
0
        void OnSceneGUI()
        {
            if (skini == null)
            {
                skini = EditorGUIUtility.Load("Navigation.guiskin") as GUISkin;
            }
            // get the chosen game object
            GameGrid t = target as GameGrid;

            if (t == null || t.layers.Count == 0)
            {
                return;
            }



            Color orgColor = Handles.color;

            Handles.color = PreferenceWindow.GridColor;
            // grab the center of the parent
            Vector3 center = Selected.z * GameGrid.BlockDirections.UP + t.transform.position - GameGrid.BlockDirections.SE + verticalOffset;

            //Outline
            Handles.DrawLine(center + Vector3.zero, center + GameGrid.BlockDirections.SE * t.rows);
            Handles.DrawLine(center + Vector3.zero, center + GameGrid.BlockDirections.NE * t.columns);

            Handles.DrawLine(center + GameGrid.BlockDirections.SE * t.rows, center + GameGrid.BlockDirections.SE * t.rows + GameGrid.BlockDirections.NE * t.columns);
            Handles.DrawLine(center + GameGrid.BlockDirections.NE * t.columns, center + GameGrid.BlockDirections.NE * t.columns + GameGrid.BlockDirections.SE * t.rows);

            center += GameGrid.BlockDirections.Down;
            //Outline
            Handles.DrawLine(center + Vector3.zero, center + GameGrid.BlockDirections.SE * t.rows);
            Handles.DrawLine(center + GameGrid.BlockDirections.SE * t.rows, center + GameGrid.BlockDirections.SE * t.rows + GameGrid.BlockDirections.NE * t.columns);
            center += GameGrid.BlockDirections.UP;

            //SW outline
            for (int r = 0; r < t.rows; r++)
            {
                Vector3 offset = GameGrid.BlockDirections.SE * r;
                Handles.DrawLine(center + offset + Vector3.zero, offset + center + GameGrid.BlockDirections.Down);
            }

            //SE outline
            for (int c = 0; c < t.columns; c++)
            {
                Vector3 SS_edge = Selected.z * GameGrid.BlockDirections.UP + t.transform.position - GameGrid.BlockDirections.SE + verticalOffset + GameGrid.BlockDirections.SE * t.rows;
                Vector3 offset  = GameGrid.BlockDirections.NE * c;
                Handles.DrawLine(SS_edge + offset + Vector3.zero, offset + SS_edge + GameGrid.BlockDirections.Down);
            }

            //Ground
            for (int r = 0; r < t.rows; r++)
            {
                Vector3 offset = GameGrid.BlockDirections.SE * r;
                Handles.DrawLine(center + offset + Vector3.zero, offset + center + GameGrid.BlockDirections.NE * t.columns);
            }
            for (int c = 0; c < t.columns; c++)
            {
                Vector3 offset = GameGrid.BlockDirections.NE * c;
                Handles.DrawLine(center + offset + Vector3.zero, offset + center + GameGrid.BlockDirections.SE * t.rows);
            }


            orgColor      = Handles.color;
            Handles.color = Color.red;


            //Selecter object
            Handles.color = PreferenceWindow.CapColor;
            Vector3 temCenter = center;


            Vector3 nw = temCenter + Selected.x * GameGrid.BlockDirections.NE + Selected.y * GameGrid.BlockDirections.SE;
            Vector3 sw = temCenter + GameGrid.BlockDirections.SE * (Selected.y + 1) + GameGrid.BlockDirections.NE * (Selected.x);
            Vector3 ne = temCenter + GameGrid.BlockDirections.NE * (Selected.x + 1) + GameGrid.BlockDirections.SE * (Selected.y);
            Vector3 se = temCenter + GameGrid.BlockDirections.SE * (Selected.y + 1) + GameGrid.BlockDirections.NE * (Selected.x + 1);

            Vector3[] rectPints = new Vector3[] { nw, sw, se, ne };


            Handles.DrawSolidRectangleWithOutline(rectPints, PreferenceWindow.CapColor, Color.red);
            Handles.color = orgColor;
            WasdListener(t);
            MouseListener(t);
            GUILayout.BeginArea(new Rect(10, 10, 200, 200));
            Navigation(t);
            GUILayout.EndArea();
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        public override void Think(AIHandlerer handlerer, GameGrid currentGrid)
        {
            if (!handlerer.body.GetData().isAvailable())
            {
                return;
            }

            if (handlerer.body.charadata.GetAllEnemies().Count == 0)
            {
                return;
            }

            Character target = handlerer.body.GetData();

            int attackRange = target.stats.attackRange;

            if (!target.TurnActionsPreformed[1])
            {
                attackRange += target.stats.movementPoints;
            }
            //Get all tiles that unit can walk to
            List <GridPosition> tilesInWalkRange = GameGrid.currentGrid.GetAllWalkableTileInRange(target.Position, target.stats.movementPoints, false);
            //Get all tile that are within units wal+attack range
            List <GridPosition> tilesInAttackRange = GameGrid.currentGrid.GetAllWalkableTileInRange(target.Position, attackRange, true);

            //Get every unit that exist inside attack range
            List <Character> enemiesInsideAttackRange = target.EnemiesInsideRange(tilesInAttackRange);

            enemiesInsideAttackRange = Character.sortByPredictedDamage(target, enemiesInsideAttackRange);


            if (target.TurnActionsPreformed[0] && target.TurnActionsPreformed[1])
            {
                GameManager._intance.turnManager.EndTurnWait();
                return;
            }

            if (!target.TurnActionsPreformed[0] && !target.TurnActionsPreformed[1])
            {
                if (enemiesInsideAttackRange.Count != 0)
                {
                    Character found = null;
                    for (int i = 0; i < enemiesInsideAttackRange.Count; i++)
                    {
                        if (found != null)
                        {
                            break;
                        }
                        foreach (GridPosition pos in tilesInAttackRange)
                        {
                            if (GameGrid.currentGrid.CanISeeTile(enemiesInsideAttackRange[i].Position, target.stats.attackRange, pos))
                            {
                                Debug.Log("Enemy was inside attackRange!");
                                found = enemiesInsideAttackRange[i];
                                break;
                            }
                        }
                    }


                    if (found != null)
                    {
                        if (target.TurnActionsPreformed[1])
                        {
                            Target.SetTarget(found);
                            AttackAction action = new AttackAction(target);

                            action.Execute();
                        }
                        else
                        {
                            List <GridPosition> PotentialWalktiles = new List <GridPosition>();
                            PotentialWalktiles.Add(target.Position);
                            //Get closest attackable tile!
                            if ((int)(Mathf.Abs(target.Position.x - found.Position.x)) > target.stats.attackRange || (int)(Mathf.Abs(target.Position.y - found.Position.y)) > target.stats.attackRange || (int)(Mathf.Abs(target.Position.z - found.Position.z)) > target.stats.attackRange)
                            {
                                PotentialWalktiles = GameGrid.currentGrid.GetAllWalkableTileInRange(found.Position, target.stats.attackRange, false);
                                PotentialWalktiles.Sort((a, b) => (target.Position.Distance(a).CompareTo(target.Position.Distance(b))));
                            }

                            //  Debug.Log("Attackking Enemy: " + found._Name);
                            AStar pathfinder = AStar.GetPath(target.Position, PotentialWalktiles[0], GameGrid.currentGrid, null);
                            Target.SetTarget(found);


                            List <GridPosition> path = pathfinder.CellsFromPath();

                            AttackAction action = new AttackAction(target);


                            target.OnPathComplete += action.Execute;

                            //  Debug.Log("Attack!!!");


                            //  if (pathDraw != null) pathDraw.ClearPath();
                            if (path.Count != 0)
                            {
                                target.TurnActionsPreformed[1] = true;
                                target.body.StartCoroutine(target.MoveAlongPath(path));
                            }
                            else
                            {
                                target.OnPathComplete.Invoke();
                            }
                        }
                    }
                }
                else if (!target.TurnActionsPreformed[1] && target.onStartPath.Count == 0)
                {
                    List <Character> allenemies = target.GetAllEnemies();

                    List <GridPosition> closest = new List <GridPosition>();
                    bool found = false;
                    for (int i = 0; i < allenemies.Count; i++)
                    {
                        AStar pathfinder = AStar.GetPath(target.Position, allenemies[i].Position, GameGrid.currentGrid, null);
                        if (pathfinder.CellsFromPath().Count < closest.Count || closest.Count == 0)
                        {
                            closest = pathfinder.CellsFromPath();
                            found   = true;
                        }
                    }
                    if (closest.Count > 0)
                    {
                        closest.RemoveAt(closest.Count - 1);
                    }


                    if (closest.Count > target.stats.movementPoints)
                    {
                        closest.RemoveRange(target.stats.movementPoints, closest.Count - target.stats.movementPoints);
                    }
                    target.OnPathComplete += GameManager._intance.turnManager.ActionOVer;
                    if (closest.Count != 0 && found)
                    {
                        target.body.StartCoroutine(target.MoveAlongPath(closest));
                        target.TurnActionsPreformed[1] = true;
                    }
                    else
                    {
                        target.OnPathComplete.Invoke();
                    }
                }
                else
                {
                    if (target.onStartPath.Any())
                    {
                        List <List <GridPosition> > pathsToWaypoints = new List <List <GridPosition> >();

                        for (int i = 0; i < target.onStartPath.Count; i++)
                        {
                            AStar pathfinder = AStar.GetPath(target.Position, target.onStartPath[i], GameGrid.currentGrid, null);
                            pathsToWaypoints.Add(pathfinder.CellsFromPath());
                        }

                        pathsToWaypoints.Sort((a, b) => (a.Count.CompareTo(b.Count)));

                        Debug.Log(pathsToWaypoints.Count);
                        Debug.Log(target.onStartPath.Count);
                        if (!pathsToWaypoints[0].Last().Equals(target.onStartPath[0]))
                        {
                            int indexOfClosest = target.onStartPath.FindIndex(item => item.Equals(pathsToWaypoints[0].Last()));
                            target.onStartPath.RemoveRange(0, indexOfClosest);
                        }


                        if (pathsToWaypoints[0].Count > target.stats.movementPoints)
                        {
                            pathsToWaypoints[0].RemoveRange(target.stats.movementPoints, pathsToWaypoints[0].Count - target.stats.movementPoints);
                        }
                        else
                        {
                            int indexOfClosest = target.onStartPath.FindIndex(item => item.Equals(pathsToWaypoints[0].Last()));
                            target.onStartPath.RemoveAt(indexOfClosest);
                        }
                        target.OnPathComplete += GameManager._intance.turnManager.ActionOVer;
                        target.body.StartCoroutine(target.MoveAlongPath(pathsToWaypoints[0]));
                        target.TurnActionsPreformed[1] = true;
                    }
                    else
                    {
                        GameManager._intance.turnManager.EndTurnWait();
                    }
                }
            }
            else
            {
                GameManager._intance.turnManager.EndTurnWait();
            }
        }
Esempio n. 12
0
 public override void Think(AIHandlerer handlerer, GameGrid currentGrid)
 {
     GameManager._intance.turnManager.EndTurnWait();
 }
Esempio n. 13
0
        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();
            }
        }
Esempio n. 14
0
 public abstract void Think(AIHandlerer handlerer, GameGrid currentGrid);
Esempio n. 15
0
        public void FindPath(GridPosition startCell, GridPosition goalCell, int layer, bool targetCellMustBeFree, List <GridPosition> range, GameGrid grid)
        {
            if (grid.GetTile(goalCell) == null)
            {
                return;
            }
            start = new Node(startCell, 0, 0, 0, null);
            end   = new Node(goalCell, 0, 0, 0, null);
            openList.Add(start);
            bool keepSearching = true;
            bool pathExists    = true;

            while ((keepSearching) && (pathExists))
            {
                Node currentNode = ExtractBestNodeFromOpenList();
                if (currentNode == null)
                {
                    pathExists = false;
                    break;
                }
                closeList.Add(currentNode);
                if (NodeIsGoal(currentNode))
                {
                    keepSearching = false;
                }
                else
                {
                    if (targetCellMustBeFree)
                    {
                        FindValidFourNeighbours(currentNode);
                    }
                    else
                    {
                        FindValidFourNeighboursIgnoreTargetCell(currentNode);
                    }


                    if (range != null)
                    {
                        Node[] tempList = neighbours.ToArray();
                        foreach (Node neighbour in tempList)
                        {
                            if (range.Find(find => find.Equals(neighbour.pos)) == null)
                            {
                                neighbours.Remove(neighbour);
                            }
                        }
                    }

                    foreach (Node neighbour in neighbours)
                    {
                        if (FindInCloseList(neighbour) != null)
                        {
                            continue;
                        }
                        Node inOpenList = FindInOpenList(neighbour);
                        if (inOpenList == null)
                        {
                            openList.Add(neighbour);
                        }
                        else
                        {
                            if (neighbour.G < inOpenList.G)
                            {
                                inOpenList.G      = neighbour.G;
                                inOpenList.F      = inOpenList.G + inOpenList.H;
                                inOpenList.parent = currentNode;
                            }
                        }
                    }
                }
            }

            if (pathExists)
            {
                Node n = FindInCloseList(end);
                while (n != null)
                {
                    finalPath.Add(n);
                    n = n.parent;
                }
            }
        }
Esempio n. 16
0
 void Awake()
 {
     currentGrid      = this;
     Player._instance = null;
     Character.allCharacters.Clear();
 }