C #
(features)
Coroutine
IEnumerator
The IEnumerator allows the program to yield things like the WaitForSeconds function, which lets you tell the script to wait without hogging the CPU
Coroutines are excellent when modelling behaviour over several frames. Coroutines have virtually no performance overhead
The execution of a coroutine can be paused at any point using the yield statement. The yield return value specifies when the coroutine is resumed.
StartCoroutine function always returns immediately, however you can yield the result. This will wait until the coroutine has finished executio
EX:
(init)
public override void Play(){ ... }
StartCoroutine(SpawnPipes());
public IEnumerator SpawnPipes(){ ... }
while(mtonFlapperGame.State == mtonFlapperState.Playing){ ... }
mtonFlapperGame.Pipes.Add(new PipeViewModel(PipeController));
yield return new WaitForSeconds(mtonFlapperGame.PipeSpawnSpeed);
(cleanup)
public override void GameOver(){ ... }
StopAllCoroutines();
(Interface)
__InterfaceMT.cs
public interface IXform{ ... }
(methods)
void doMove();
(properties)
Transform xform{ get; set;}
Vector3 position{ get; set; }
public interface IHealth{ ... }
(Abstract)
//Interface with default methods and properties ???
(Events)
io_MTView.cs
public
delegate
void
bnEVENT() ;
static
event
bnEVENT
OnJumpDN ;
//onJump Press
OnJumpRL ;
//onJump Release
void Update(){ ... }
if(Input.GetButtonDown("Jump")){ ... }
OnJumpDN();
(Delegates)
//events vs. delegates : events more secure, can not be overwritten and adjusted by externals
(source)
(Interface)
MonobehaviourClass.cs
public class Player : IHealth, IXform, IInput{...}
//implement IXform ....IHealth....etc
public
//MUST : Else error
//Interface property must be public???
//All properties and methods must be implemented in importing class
(methods)
void
doMove(){ ... }
// insert normal function code here
(properties)
Transform
xform{ get; set; }
//not understanding {get; set; } template???
Vector3
position{ ... }
get{ ... }
return xform.position;
set{ ... }
xform.position = value;
//WTH is "value" coming from...keyword???
(Events)
gCOREView.cs
public
override
void
OnEnable(){ ... }
io_MTView.OnJumpDN += jumpDNHandler;
//binding IO events
OnDisable(){ ... }
io_MTView.OnJumpDN -= jumpDNHandler;
//MUST : remove events on disable, else memory leaks and other catastrophes
void
jumpDNHandler(){ ... }