This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample sorting by player age: | |
Array.Sort( arrPlayers, delegate(Player a, Player b) | |
{ | |
if( a.Age > b.Age ) // if a is higher than b | |
return 1; | |
else if ( a.Age < b.Age ) // if b is higher than a | |
return -1; | |
return 0; // if both are equals return 0 | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//C# Event using Action delegate: | |
public event Action OnSomeEvent; | |
public event Action<string> OnSomeEventWithParameters; | |
// Rising the event, must check if is null: | |
void SomeMethod() | |
{ | |
if( OnSomeEvent != null ) | |
OnSomeEvent(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Next | |
int i = (i+1) % targetArray.Count | |
//Prev | |
int i = (i + (targetArray.Count-1)) % targetArray.Count; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//C# Delegate: | |
public delegate [return] DelegateName([type parameter]...); | |
//Sample: | |
public delegate void CalbackHandler(int pIndex); | |
//So you can use it as a parameter to other method: | |
public void PassDelegateByParameter( CallbackHandler pHandler ) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<>:;?/\|"'-_=+[]{}M%&*#$@! ()[]{}., | |
qwertyuiopasdfghjklçzxcvbnmQWERTYUIOPASDFGHJKLZXCVBN1234567890 | |
ÁáÉéÍíÓóÚúÀàÂâÊêÔôÃãÕõÜüÇç |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Extensions | |
{ | |
public static Transform Search(this Transform target, string name) | |
{ | |
if (target.name == name) return target; | |
for (int i = 0; i < target.childCount; ++i) | |
{ | |
var result = Search(target.GetChild(i), name); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************************* | |
* Unity Singleton Class (c) by ClockStone 2011 * | |
* | |
* Allows to use a script components like a singleton | |
* | |
* Usage: | |
* | |
* Derive your script class MyScriptClass from | |
* SingletonMonoBehaviour<MyScriptClass> | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
/// <summary> | |
/// Scene auto loader. | |
/// </summary> | |
/// <description> | |
/// This class adds a File > Scene Autoload menu containing options to select | |
/// a "master scene" enable it to be auto-loaded when the user presses play | |
/// in the editor. When enabled, the selected scene will be loaded on play, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static T FindComponentUpwards<T>(this Transform pTarget) where T : Component | |
{ | |
Transform tTransform = pTarget.parent; | |
while (true) | |
{ | |
T tComponent = tTransform.GetComponent<T>(); | |
if (tComponent == null) | |
{ | |
if (tTransform.parent) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Shuffles the element order of the specified list. | |
/// </summary> | |
public static void Shuffle<T>(this IList<T> ts) { | |
var count = ts.Count; | |
var last = count - 1; | |
for (var i = 0; i < last; ++i) { | |
var r = Random.Range(i, count); | |
var tmp = ts[i]; | |
ts[i] = ts[r]; |
OlderNewer