C# Class RTSObject, ES2015C

Inheritance: MonoBehaviour
Show file Open project: jgirald/ES2015C Class Usage Examples

Public Properties

Property Type Description
baseMoveSpeed float
cost int
objectIconAttack Sprite
objectIconAttackRange Sprite
objectIconDefense Sprite
objectIconResource Sprite
objectIconSprite Sprite
objectName string
owner Player,
target RTSObject,

Protected Properties

Property Type Description
aiming bool
anim Animator
attacking bool
audio UnityEngine.AudioSource
baseAttackRange int
baseAttackSpeed float
baseAttackStrength int
baseBuildFactor float
baseDefense int?
creationSound UnityEngine.AudioClip
currentlySelected bool
dieSound UnityEngine.AudioClip
dying bool
ent LOSEntity,
fightSound UnityEngine.AudioClip
healthPercentage float
nearbyObjects List
programmedAttackPosition Vector3
remainingTimeToAttack float
remainingTimeToDead float
rigbody UnityEngine.Rigidbody

Private Properties

Property Type Description
BeginDead void
EndAttack void
OnMouseExit void
OnMouseOver void
PerformAttack void
UpdateDeadObject bool
updateSelection void

Public Methods

Method Description
AssignBuildingProject ( Building, newProject ) : void

Assigns a new building project to this object.

AttackObject ( RTSObject, target ) : void

Begins an attack on the given target object. To stop the current attack sequence, pass null to this method.

BeginAttack ( RTSObject, newTarget ) : void

Begins an attack sequence on the given target.

CanAttack ( ) : bool

Tells if the object can attack.

CanBeAttacked ( ) : bool

Tell if the object can be attacked by military units.

CanBeBuilt ( ) : bool
CanBuild ( ) : bool
CanMove ( ) : bool

Tells if the object can change its position.

GetActions ( ) : Action[],

Get the list of actions available for this object.

GetAttackRange ( ) : float

Gets the distance at which the unit can attack, if it is a range unit (e.g. an archer). Otherwise, returns zero if the unit is not a range unit.

GetAttackSpeed ( ) : float

Gets the attack strengh that the unit has when it is attacking, in attack/second.

GetAttackStrength ( ) : int

Gets the attack strengh that the unit has when it is attacking.

GetDefense ( ) : int

Gets the defense points that the unit has when it is being attacked.

GetHarvestAmount ( ) : float

Get the current amount of resource that the unit has harvested.

GetHarvestType ( ) : ResourceType,

Get the current type of resource that the unit is harvesting.

GetMovementSpeed ( ) : float

Gets the movement speed of a object.

IsBuilding ( ) : bool

Checks if the object is currently building another object.

IsHarvesting ( ) : bool

Check if the unit is currently harvesting.

IsOwnedBy ( Player, owner ) : bool
MouseClick ( GameObject hitObject, Vector3 hitPoint, Player, controller ) : void
MoveTo ( Vector3 target, bool isRunning ) : void

Tells the object to start a free (non-attack) movement to the given position.

OnDestroy ( ) : void

This method is called when the object is destroyed. In this case, we need to update the paths for A* to no longer consider our destroyed object.

PerformAction ( string actionToPerform ) : void
ReplaceChildWithChildFromGameObjectTemplate ( GameObject newGameObjectTemplate ) : void

Replaces all the child nodes of the GameObject associated with this object, with the child nodes of the given GameObject template. This can be used, for instance, to exchange the model that is used to display the different versions (on construction, semidemolished, complete, ...) of a building.

SetSelection ( bool selected ) : void
TakeDamage ( int damage ) : void

Substract health points from this object.

makeCreationSound ( ) : void

Protected Methods

Method Description
AimAtTarget ( ) : void
Animating ( ) : void
Awake ( ) : void
CalculateCurrentHealth ( ) : void
CancelPath ( ) : void

Tell the object to cancel the movement path to the given position.

ExtendBounds ( Transform t, Bounds &b ) : void
HasPath ( ) : bool

Returns true if the unit has programmed a movement path to a given position.

OnGUI ( ) : void
SetNewPath ( Vector3 target, bool isRunning ) : void

Tells the object to move to the given position, by generating and following a route to the desired position.

Start ( ) : void
Update ( ) : void
UseWeapon ( ) : void
chargeSounds ( string objectName ) : void

Private Methods

Method Description
BeginDead ( ) : void

Begins the dead transition.

EndAttack ( ) : void

Cancels an attack sequence on the given target.

OnMouseExit ( ) : void
OnMouseOver ( ) : void
PerformAttack ( ) : void

If the object is performing an attack, inflicts damage to the target according to the attack speed, strength and target defense, or moves closer to the target in order to perform the attack.

UpdateDeadObject ( ) : bool

Checks if the required time between the unit having zero health points and the unit disappearing has elapsed.

updateSelection ( ) : void

Method Details

AimAtTarget() protected method

protected AimAtTarget ( ) : void
return void

Animating() protected method

protected Animating ( ) : void
return void

AssignBuildingProject() public method

Assigns a new building project to this object.
public AssignBuildingProject ( Building, newProject ) : void
newProject Building, The new project to assign, or null to deassign the current project.
return void

AttackObject() public method

Begins an attack on the given target object. To stop the current attack sequence, pass null to this method.
public AttackObject ( RTSObject, target ) : void
target RTSObject, The target of the attack. If null is given, the attack will stop.
return void

Awake() protected method

protected Awake ( ) : void
return void

BeginAttack() public method

Begins an attack sequence on the given target.
public BeginAttack ( RTSObject, newTarget ) : void
newTarget RTSObject, The target of the attack.
return void

CalculateCurrentHealth() protected method

protected CalculateCurrentHealth ( ) : void
return void

CanAttack() public method

Tells if the object can attack.
public CanAttack ( ) : bool
return bool

CanBeAttacked() public method

Tell if the object can be attacked by military units.
public CanBeAttacked ( ) : bool
return bool

CanBeBuilt() public method

public CanBeBuilt ( ) : bool
return bool

CanBuild() public method

public CanBuild ( ) : bool
return bool

CanMove() public method

Tells if the object can change its position.
public CanMove ( ) : bool
return bool

CancelPath() protected method

Tell the object to cancel the movement path to the given position.
protected CancelPath ( ) : void
return void

ExtendBounds() protected method

protected ExtendBounds ( Transform t, Bounds &b ) : void
t Transform
b Bounds
return void

GetActions() public method

Get the list of actions available for this object.
public GetActions ( ) : Action[],
return Action[],

GetAttackRange() public method

Gets the distance at which the unit can attack, if it is a range unit (e.g. an archer). Otherwise, returns zero if the unit is not a range unit.
public GetAttackRange ( ) : float
return float

GetAttackSpeed() public method

Gets the attack strengh that the unit has when it is attacking, in attack/second.
public GetAttackSpeed ( ) : float
return float

GetAttackStrength() public method

Gets the attack strengh that the unit has when it is attacking.
public GetAttackStrength ( ) : int
return int

GetDefense() public method

Gets the defense points that the unit has when it is being attacked.
public GetDefense ( ) : int
return int

GetHarvestAmount() public method

Get the current amount of resource that the unit has harvested.
public GetHarvestAmount ( ) : float
return float

GetHarvestType() public method

Get the current type of resource that the unit is harvesting.
public GetHarvestType ( ) : ResourceType,
return ResourceType,

GetMovementSpeed() public method

Gets the movement speed of a object.
public GetMovementSpeed ( ) : float
return float

HasPath() protected method

Returns true if the unit has programmed a movement path to a given position.
protected HasPath ( ) : bool
return bool

IsBuilding() public method

Checks if the object is currently building another object.
public IsBuilding ( ) : bool
return bool

IsHarvesting() public method

Check if the unit is currently harvesting.
public IsHarvesting ( ) : bool
return bool

IsOwnedBy() public method

public IsOwnedBy ( Player, owner ) : bool
owner Player,
return bool

MouseClick() public method

public MouseClick ( GameObject hitObject, Vector3 hitPoint, Player, controller ) : void
hitObject GameObject
hitPoint Vector3
controller Player,
return void

MoveTo() public method

Tells the object to start a free (non-attack) movement to the given position.
public MoveTo ( Vector3 target, bool isRunning ) : void
target Vector3 The position we want the object to move to.
isRunning bool
return void

OnDestroy() public method

This method is called when the object is destroyed. In this case, we need to update the paths for A* to no longer consider our destroyed object.
public OnDestroy ( ) : void
return void

OnGUI() protected method

protected OnGUI ( ) : void
return void

PerformAction() public method

public PerformAction ( string actionToPerform ) : void
actionToPerform string
return void

ReplaceChildWithChildFromGameObjectTemplate() public method

Replaces all the child nodes of the GameObject associated with this object, with the child nodes of the given GameObject template. This can be used, for instance, to exchange the model that is used to display the different versions (on construction, semidemolished, complete, ...) of a building.
public ReplaceChildWithChildFromGameObjectTemplate ( GameObject newGameObjectTemplate ) : void
newGameObjectTemplate GameObject The object to use as a template for the new child nodes.
return void

SetNewPath() protected method

Tells the object to move to the given position, by generating and following a route to the desired position.
protected SetNewPath ( Vector3 target, bool isRunning ) : void
target Vector3 The position we want the object to move to.
isRunning bool
return void

SetSelection() public method

public SetSelection ( bool selected ) : void
selected bool
return void

Start() protected method

protected Start ( ) : void
return void

TakeDamage() public method

Substract health points from this object.
public TakeDamage ( int damage ) : void
damage int The number of health points to substract to this object.
return void

Update() protected method

protected Update ( ) : void
return void

UseWeapon() protected method

protected UseWeapon ( ) : void
return void

chargeSounds() protected method

protected chargeSounds ( string objectName ) : void
objectName string
return void

makeCreationSound() public method

public makeCreationSound ( ) : void
return void

Property Details

aiming protected property

protected bool aiming
return bool

anim protected property

protected Animator anim
return Animator

attacking protected property

true if the unit is attacking or moving into position to attack another unit.
protected bool attacking
return bool

audio protected property

protected AudioSource,UnityEngine audio
return UnityEngine.AudioSource

baseAttackRange protected property

Default attack strength. Leave at zero if the object isn't a range unit.
protected int baseAttackRange
return int

baseAttackSpeed protected property

Default number of hits per second of the object. Leave at zero if the object can't attack.
protected float baseAttackSpeed
return float

baseAttackStrength protected property

Default attack strength. Leave at zero if the object can't attack.
protected int baseAttackStrength
return int

baseBuildFactor protected property

Default speed factor of building (x1 = default building time, x2 = half building time, etc). Leave at zero if the unit can't build.
protected float baseBuildFactor
return float

baseDefense protected property

Default attack defense. Leave at null if the object can't defend.
protected int? baseDefense
return int?

baseMoveSpeed public property

Default movement speed. Leave at zero if the object can't move.
public float baseMoveSpeed
return float

cost public property

public int cost
return int

creationSound protected property

protected AudioClip,UnityEngine creationSound
return UnityEngine.AudioClip

currentlySelected protected property

protected bool currentlySelected
return bool

dieSound protected property

protected AudioClip,UnityEngine dieSound
return UnityEngine.AudioClip

dying protected property

true if the unit is dying (it has zero hit points and it playing the dead animation).
protected bool dying
return bool

ent protected property

protected LOSEntity, ent
return LOSEntity,

fightSound protected property

protected AudioClip,UnityEngine fightSound
return UnityEngine.AudioClip

healthPercentage protected property

protected float healthPercentage
return float

nearbyObjects protected property

protected List nearbyObjects
return List

objectIconAttack public property

public Sprite objectIconAttack
return Sprite

objectIconAttackRange public property

public Sprite objectIconAttackRange
return Sprite

objectIconDefense public property

public Sprite objectIconDefense
return Sprite

objectIconResource public property

public Sprite objectIconResource
return Sprite

objectIconSprite public property

public Sprite objectIconSprite
return Sprite

objectName public property

public string objectName
return string

owner public property

public Player, owner
return Player,

programmedAttackPosition protected property

If attacking, position where the unit is programmed to move in order to attack another unit.
protected Vector3 programmedAttackPosition
return Vector3

remainingTimeToAttack protected property

If attacking, number of seconds remaining until the unit takes another hit to the target.
protected float remainingTimeToAttack
return float

remainingTimeToDead protected property

Number of seconds until the unit is considered dead and it disappears from the map.
protected float remainingTimeToDead
return float

rigbody protected property

protected Rigidbody,UnityEngine rigbody
return UnityEngine.Rigidbody

target public property

public RTSObject, target
return RTSObject,