using UnityEngine;
namespace TGS {
public delegate void CellEvent(TerrainGridSystem tgs, int cellIndex);
public delegate void CellHighlightEvent(TerrainGridSystem tgs, int cellIndex, ref bool cancelHighlight);
public delegate void CellClickEvent(TerrainGridSystem tgs, int cellIndex, int buttonIndex);
public delegate void CellDragEvent(TerrainGridSystem tgs, int cellOriginIndex, int cellTargetIndex);
public delegate void TerritoryEvent(TerrainGridSystem tgs, int territoryIndex);
public delegate void TerritoryRegionEvent(TerrainGridSystem tgs, int territoryIndex, int regionIndex);
public delegate void TerritoryHighlightEvent(TerrainGridSystem tgs, int territoryIndex, ref bool cancelHighlight);
public delegate void TerritoryClickEvent(TerrainGridSystem tgs, int territoryIndex, int regionIndex, int buttonIndex);
public delegate void TerritoryRegionClickEvent(TerrainGridSystem tgs, int territoryIndex, int regionIndex, int buttonIndex);
public delegate int PathFindingEvent(TerrainGridSystem tgs, int cellIndex);
public delegate void OnGridSettingsChangedEvent(TerrainGridSystem tgs);
public delegate void OnRectangleSelectionEvent(TerrainGridSystem tgs, Vector2 localStartPos, Vector2 localEndPos);
#if UNITY_EDITOR
#region Custom
public delegate void CellClickInSceneEvent(TerrainGridSystem tgs, int cellIndex, int buttonIndex);
public delegate void CellClickOutsideTheGridEvent();
public delegate void CellMoveInSceneEvent(TerrainGridSystem tgs,int cellIndex,bool isControl,bool isShift);
#endregion
#endif
public partial class TerrainGridSystem : MonoBehaviour {
#region Cell events
///
/// Occurs when the pointer enters a cell
///
public event CellEvent OnCellEnter;
///
/// Occurs when the pointer exits a cell
///
public event CellEvent OnCellExit;
///
/// Occurs when user presses the mouse button on a cell
///
public event CellClickEvent OnCellMouseDown;
///
/// Occurs when user releases the mouse button on the same cell that started clicking
///
public event CellClickEvent OnCellClick;
///
/// Occurs when user releases the mouse button on any cell
///
public event CellClickEvent OnCellMouseUp;
///
/// Occurs when a cell is about to get highlighted
///
public event CellHighlightEvent OnCellHighlight;
///
/// Occurs when user starts dragging on a cell
///
public event CellEvent OnCellDragStart;
///
/// Occurs when user drags a cell
///
public event CellDragEvent OnCellDrag;
///
/// Occurs when user ends drag on a cell
///
public event CellDragEvent OnCellDragEnd;
#if UNITY_EDITOR
#region Custom
//在Scene中点击网格
public event CellClickInSceneEvent OnMouseClickOnGrid;
//在Scene中点出网格
public event CellClickOutsideTheGridEvent OnMouseClickOutsideTheGrid;
//在Scene中网格上移动鼠标
public event CellMoveInSceneEvent OnMouseMoveOnGrid;
public void InvokeCellClickInSceneEvent(TerrainGridSystem tgs, int cellIndex, int buttonIndex)
{
if (!Application.isPlaying)
OnMouseClickOnGrid?.Invoke(tgs, cellIndex, buttonIndex);
}
public void InvokeCellClickOutsideTheGridEvent()
{
if (!Application.isPlaying)
OnMouseClickOutsideTheGrid?.Invoke();
}
public void InvokeOnMouseMoveOnGrid(TerrainGridSystem tgs, int cellIndex, bool isControl,bool isShift)
{
if (!Application.isPlaying)
OnMouseMoveOnGrid?.Invoke(tgs, cellIndex, isControl,isShift);
}
#endregion
#endif
#endregion
#region Territory events
///
/// Occurs when the pointer enters a territory
///
public event TerritoryEvent OnTerritoryEnter;
///
/// Occurs when the pointer exits a territory
///
public event TerritoryEvent OnTerritoryExit;
///
/// Occurs when the pointer enters a territory region
///
public event TerritoryRegionEvent OnTerritoryRegionEnter;
///
/// Occurs when the pointer exits a territory region
///
public event TerritoryRegionEvent OnTerritoryRegionExit;
///
/// Occurs when user press the mouse button on a territory
///
public event TerritoryClickEvent OnTerritoryMouseDown;
///
/// Occurs when user releases the mouse button on the same territory that started clicking
///
public event TerritoryClickEvent OnTerritoryClick;
///
/// Occurs when user releases the mouse button on a territory
///
public event TerritoryClickEvent OnTerritoryMouseUp;
///
/// Occurs when user press the mouse button on a territory region
///
public event TerritoryRegionClickEvent OnTerritoryRegionMouseDown;
///
/// Occurs when user releases the mouse button on the same territory region that started clicking
///
public event TerritoryRegionClickEvent OnTerritoryRegionClick;
///
/// Occurs when user releases the mouse button on a territory region
///
public event TerritoryRegionClickEvent OnTerritoryRegionMouseUp;
///
/// Occurs when a territory is about to get highlighted
///
public event TerritoryHighlightEvent OnTerritoryHighlight;
#endregion
#region Rectangle selection events
///
/// Occurs when user performs a rectangle selection
///
public OnRectangleSelectionEvent OnRectangleSelection;
///
/// Occurs when user starts draggins a rectangle selection
///
public OnRectangleSelectionEvent OnRectangleDrag;
#endregion
#region Other events
///
/// Fired when path finding algorithmn evaluates a cell. Return the increased cost for cell.
///
public event PathFindingEvent OnPathFindingCrossCell;
///
/// Occurs when some grid settings are changed
///
public event OnGridSettingsChangedEvent OnGridSettingsChanged;
#endregion
}
}