Skip to content

Instantly share code, notes, and snippets.

@arun02139
Created March 15, 2017 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arun02139/d91e94954117dc7441dff756020bdfb9 to your computer and use it in GitHub Desktop.
Save arun02139/d91e94954117dc7441dff756020bdfb9 to your computer and use it in GitHub Desktop.
Abstract base class for a generic 'cell'
using UnityEngine;
using UnityEngine.Networking;
using System;
using System.Collections.Generic;
public abstract class Cell : NetworkBehaviour, IGraphNode, ITouchable
{
public OffsetCoordinate offsetCoord
{
get { return _offsetCoord; }
}
public bool isTaken; // indicates if something is occupying the cell.
public int movementCost; // cost of moving through the cell
// events invoked when user clicks the cell (requires a collider on the cell game object to work)
public event EventHandler CellPressed;
public event EventHandler<ReleaseEventArgs> CellReleased;
// event invoked when user moves cursor over the cell (requires a collider on the cell game object to work)
public event EventHandler CellHighlighted;
public event EventHandler CellDehighlighted;
//[HideInInspector]
[SerializeField]
OffsetCoordinate _offsetCoord;
public void SetOffsetCoord(OffsetCoordinate offsetCoord)
{
_offsetCoord = offsetCoord;
}
string _debugString;
string _debugString2;
protected virtual void OnMouseEnter()
{
if (CellHighlighted != null)
CellHighlighted.Invoke(this, new EventArgs());
}
protected virtual void OnMouseExit()
{
if (CellDehighlighted != null)
CellDehighlighted.Invoke(this, new EventArgs());
}
// void OnMouseDown()
// {
// if (CellClicked != null)
// CellClicked.Invoke(this, new EventArgs());
// }
// AMM add input event handlers – seperate input code (TouchScript, vanilla Unity) from core Cell logic
public void OnPress()
{
// string debugString = string.Format ("Cell.OnCellPress:", "");
// ClientDebugUI.i.Log (debugString);
// Debug.Log (debugString);
if (CellPressed != null)
CellPressed.Invoke (this, new EventArgs ());
}
public void OnTransform(Vector2 screenPosition)
{
}
public void OnRelease(GameObject objReleasedOver)
{
// _debugString2 = objReleasedOver == null ? "null" : objReleasedOver.name;
// _debugString = string.Format ("Cell.OnCellRelease: objReleasedOver={0}", _debugString2);
// ClientDebugUI.i.Log (_debugString);
// Debug.Log (_debugString);
if (CellReleased != null)
CellReleased.Invoke (this, new ReleaseEventArgs(objReleasedOver));
}
/// <summary>
/// Method returns distance to other cell, that is given as parameter.
/// </summary>
public abstract int GetDistance(Cell other);
// returns all adjacent cells from list of cells
public abstract List<Cell> GetNeighbours(List<Cell> cells);
public abstract Vector3 GetCellDimensions(); //Cell dimensions are necessary for grid generators.
// marks the cell to give user an indication that selected unit can reach it
public abstract void MarkAsReachable();
// marks the cell to give user an indication that selected unit attack it (from it's current cell)
public abstract void MarkAsAttackable();
// marks the cell as a part of a path
public abstract void MarkAsPath();
// marks the cell as highlighted. It gets called when the mouse is over the cell
public abstract void MarkAsHighlighted();
// returns the cell to its base appearance.
public abstract void UnMark();
public int GetDistance(IGraphNode other)
{
return GetDistance(other as Cell);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment