using UnityEngine; using System.Collections.Generic; namespace TGS { public partial class TerrainGridSystem : MonoBehaviour { /// /// Moves a given game object from current position to the center of a destination cell specified by row and column /// /// The game object /// Index of the destination cell /// Speed in meters per seconds. A value of 0 moves the gameobject immediately to the destination. /// Optional offset from the grid surface public GridMove MoveTo(GameObject o, int row, int column, float velocity = 0, float elevation = 0) { int destinationCellIndex = CellGetIndex(row, column); return MoveTo(o, destinationCellIndex, velocity, elevation); } /// /// Moves a given game object from current position to the center of a destination cell specified by index /// /// The game object /// Index of the destination cell /// Speed in meters per seconds. A value of 0 moves the gameobject immediately to the destination. /// Optional offset from the grid surface public GridMove MoveTo(GameObject o, int cellIndex, float velocity = 0, float elevation = 0) { List positions = new List(); positions.Add(cellIndex); return MoveTo(o, positions, velocity, elevation); } /// /// Moves a given game object from current position to the center of a destination cell specified by row and column /// /// The game object /// Index of the destination cell /// Speed in meters per seconds. A value of 0 moves the gameobject immediately to the destination. /// Optional offset from the grid surface public GridMove MoveTo(GameObject o, List positions, float velocity = 0, float elevation = 0) { GridMove mv = o.GetComponent(); if (mv == null) { mv = o.AddComponent(); } mv.grid = this; mv.positions = positions; mv.velocity = velocity; mv.elevation = elevation; mv.Begin(); return mv; } /// /// Pauses a moving object /// public void MovePause(GameObject o) { GridMove mv = o.GetComponent(); if (mv != null) { mv.enabled = false; } } /// /// Pauses or resumes a moving object /// public void MovePauseToggle(GameObject o) { GridMove mv = o.GetComponent(); if (mv != null) { mv.enabled = !mv.enabled; } } /// /// Resumes movement of an object /// public void MoveResume(GameObject o) { GridMove mv = o.GetComponent(); if (mv != null) { mv.enabled = true; } } /// /// Cancels movement of an object /// public void MoveCancel(GameObject o) { GridMove mv = o.GetComponent(); if (mv != null) { DestroyImmediate(mv); } } } }