0. Download and Install

Core Sourcecode Download

Get the latest version of the source code from BitBucket repository here: Download repository from bitbucket

After downloading the source code copy the files downloaded into your Unity project “Assets” folder.

Recommended location is “/Toggle Play/Core/”. If you use other Toggle Play source code libraries then this will keep them all in the same location.

Back To Top

1. CoroutineEx

About Extended Coroutine

Unity Coroutine and TogglePlay CoroutineEx differences

There are some differences that can affect anyone using standard Unity Coroutine and Toggle Play Coroutine. Is that Unity Coroutines break when an object is disabled and do not continue when the GameObject is re-enabled. Toggle Play Coroutines will pause the coroutine when the GameObject is disabled and resume it upon being enabled.

To use the extended coroutines, inherit from MonoBehaviourEx instead of MonoBehaviour.

MonoBehaviourEx overwrites the StartCoroutine and StopCoroutine functions. If adapting an existing project to use these features then for the most part it will work as normal. However if yield using CoroutineEx using a MonoBehaviour class this may work incorrectly as Unity MonoBehaviour coroutines do not accept the TogglePlay yield instructions.

If you are using standard MonoBehaviour but want to yield another classes Coroutine using MonoBehaviourEx then you cannot just yield it instead use the following example.

In addition to StartCoroutine, Unity will also control unity event functions that are using IEnumerator such as IEnumerator Start().

 

There is a collection of yields as standard with the source code. But can easily be extended with your own.

Core includes the following yield instructions

Standard Unity yield instructions
  • yield return null;

This will wait until the next frame until continuing with the routine.

  • yield return new WaitForSeconds( float seconds: );

This is will wait until the specified amount of time has passed.

  • yield return new WaitForFixedUpdate();

This will wait until the next fixed update and continue with the routine. Use this instead of yield return null; to work on the fixed update, e.g. physics

Standard extended yield instructions. (These are under the “Yield” namespace)

  • yield return new WaitForEnumerable(IEnumerable enumerable:);

This will wait until the enumerable has finished until progress continues.

  • yield return new WaitForYieldable(IYieldable waitFor:);

This will wait until any class interfacing with IYieldable will hold progress until it is complete. Note: TogglePlayCoroutine inherits IYieldable and can be chained.

  • yield return new WaitWhileAnimating(Animation waitFor:);

This will wait until the target animation has completed until progress continues.

  • yield return new WaitForUpdates(int countFor:);

This will wait until countFor frames have completed until progress continues.

  • yield return new WaitForLength( float seconds: );
    yield return new WaitForLength( float seconds:, bool realTime: );

This will wait until the amount of time has passed. This is different to WaitForSeconds as WaitForLength loops a null instruction until the time has passed, so it can also be paused. Also can be run using Time.deltaTime or real time.

  • yield return new WaitForCondition(Conditional.ICondition waitUntil);

This will wait until the condition has been met until progress continues. See Conditions documentation.

  • yield return Yield.PauseBreak;

This will pause the progress until Coroutine.Resume(); or ResumeCoroutine(); is called outside of the function.

  • yield return Yield.ContinueBreak;

This will continue running the function through Unity’s standard Coroutines but end the TogglePlay.Coroutine.

  • yield return new ErrorBreak(string message:);

This will act the same as yield.break; but stores a message within the MonoBehaviourEx for debugging.

Back To Top

Pausing Coroutines

[rescue_box color=”gray” text_align=”left” width=”100%” float=”none”]
Class: MonoBehaviourEx
Class: TogglePlay.CoroutineEx
[/rescue_box]

 

Pausing CoroutineEx will pause the execution of any more YieldInstruction’s.

To pause all running CoroutineEx on the MonoBehaviourEx MonoBehaviourEx.PauseAllCoroutines(); can be called. And MonoBehaviourEx.ResumeAllCoroutines(); to resume them.

To pause the Coroutine with the given function name MonoBehaviourEx.PauseCoroutine( string routineName: ); can be called. Note that this will pause all Coroutines that are running with the given name not just the first one found. And MonoBehaviourEx.ResumeCoroutine( string routineName: ); to resume.

 

MonoBehaviourEx.StartCoroutine returns the CoroutineEx class, which can be used to control the state of the specific coroutine. Here is an example showing how to pause the coroutine using the CoroutineEx class.

Caution should be taken when pausing and using single instructions that occur over a period of time such as new WaitForSeconds( seconds: ); as this is a single instruction and will not resume with the next instruction if the time has passed. A pause-able alternative is included with Core called yield new TogglePlay.Yield.WaitForLength( float seconds: ); use this as an alternative to yield new WaitForSeconds( float seconds: );.

Back To Top

Stopping Coroutines

[rescue_box color=”gray” text_align=”left” width=”100%” float=”none”]
Class: MonoBehaviourEx
Class: TogglePlay.CoroutineEx
[/rescue_box]

 

Stopping CoroutineEx will end the execution of the CoroutineEx, CoroutineEx.isRunning will become false and it will be removed from MonoBehaviourEx.runningRoutines.

Any other routines waiting for or yielding the stopped CoroutineEx will move onto the next instruction.

To stop all running CoroutineEx on the MonoBehaviourEx MonoBehaviourEx.StopAllCoroutines(); can be called.

To stop the Coroutine with the given function name MonoBehaviourEx.StopCoroutine( string routineName: ); can be called. Note that this will stop all Coroutines that are running with the given name not just the first one found.

 

MonoBehaviourEx.StartCoroutine returns the CoroutineEx class, which can be used to control the state of the specific coroutine. Here is an example showing how to stop the coroutine using the CoroutineEx class.

Back To Top

Extending with IYieldable

Objects and Namespaces:
Class: MonoBehaviourEx
Interface: TogglePlay.IYieldable

Any class can be extended to allow it to be simply yielded when using MonoBehaviourEx.StartCoroutine.

To extend a class to inherit with IYieldable and have the property IEnumerator Enumerator { get{} }
Having IYieldable as a get property that returns a IEnumerator instead of a direct function allows a class to provide different ‘Coroutines’ depending upon the needs of the class, or simply return null to effectively yield return null; on any coroutine yielding this class.

After this has been setup a class can easily be yielded, with gives control to that class on with coroutine to begin and return to the system.

v

Back To Top

Debugging Coroutines

Active coroutines managed by the MonoBehaviourEx can be seen in the inspector by changing to debug mode view.

We see a number of values displayed in the editor

Function Name : The name of the function that is running as a Coroutine.

Active : If the Coroutine is actively running (Not been stopped or has completed).

Paused : Indicates if the Coroutine has been paused and is awaiting Resume to continue where it left off.

Routine Started Time : The time in seconds when the Coroutine began (Since the start of the game).

Running Time : The time in seconds that the coroutine has been active for (Including time when paused).

Back To Top

2. Conditions

ConditionalComponent

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

Core ConditionalComponents

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

ICondition

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

Extending by inheriting ConditionalComponent

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

3. Value types

Core Value Classes

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

BoolValue

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

ColorValue

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

DoubleValue

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

FloatValue

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

IntValue

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

QuaternionValue

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

StringValue

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

Vector2Value

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

Vector3Value

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

Vector4Value

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

4. Globals

TypeDictionary

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

 

Back To Top

SharedDictionary

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

5. Generics

DynamicArray

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

Hierarchy

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

NumberedLookup

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

ListedDictionary

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

WeightedList

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

Singleton

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

InstantSingleton

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

6. Utilities

Screen Logger

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

7. Decorators

Box Header Attribute

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

8. Gizmos

Mogwai

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Mogwai is a static class containing helpful gizmo draw functions to extend your gizmo drawing capability.

  • DrawDashLine
  • DrawDuelColorLine
  • DrawUmbrella
  • DrawDisc
  • DrawCylinder
  • DrawKite
  • DrawDiamond

Back To Top

GizmoAtSelf

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

GizmoBetweenObjects

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

GizmoHierarchy

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top

GizmoRendererBounds

[rescue_box color=”red” text_align=”left” width=”100%” float=”none”]
Documentation under development check back soon
[/rescue_box]

Back To Top