Skip to content

Instantly share code, notes, and snippets.

View hk1ll3r's full-sized avatar
👨‍💻
Happily Coding

Hoss hk1ll3r

👨‍💻
Happily Coding
  • No Such Studio
  • Planet Earth
View GitHub Profile
@hk1ll3r
hk1ll3r / 20200127-valuetuples.cs
Last active January 27, 2020 22:57
gist to demonstrate c# 7.0's new value tuple syntax for returning multiple values from functions.
using System;
public struct Vector2 {
public float x;
public float y;
public Vector2(float x, float y) {
this.x = x;
this.y = y;
}
}
@hk1ll3r
hk1ll3r / 20200127-valuetuples-1.cs
Last active January 27, 2020 22:52
gist 1: basic usage
float x, y;
public ValueTuple<float, float> GetPosition() {
return ValueTuple.Create(_x, _y);
}
// Is exactly the same as GetPosition above
public (float, float) GetPositionAlternateSyntax() {
return (_x, _y);
}
@hk1ll3r
hk1ll3r / 20200127-valuetuples-2.cs
Last active January 27, 2020 23:01
gist 2: call using the shorthand syntax
// declare and assign
(float x, float y) = GetPosition();
// just assign
float x, y; // declare variables elsewhere
(x, y) = GetPosition();
// tuple usage (explicit)
ValueTuple<float, float> ret = GetPosition();
float x = ret.Item1, y = ret.Item2;
// mix and match
float y;
(float x, y) = GetPosition();
// throw away some returned values
(float x, _) = GetPosition();
@hk1ll3r
hk1ll3r / 20200127-curlybraces-1.cs
Created January 27, 2020 23:36
sample bad format
void Awake()
{
if (!Debug.isDebugBuild)
{
Debug.Log("prod build");
enabled = false;
}
}
void Awake() {
if (!Debug.isDebugBuild) {
Debug.Log("prod build");
enabled = false;
}
}
{
"FormattingOptions": {
"NewLinesForBracesInLambdaExpressionBody": false,
"NewLinesForBracesInAnonymousMethods": false,
"NewLinesForBracesInAnonymousTypes": false,
"NewLinesForBracesInControlBlocks": false,
"NewLinesForBracesInTypes": false,
"NewLinesForBracesInMethods": false,
"NewLinesForBracesInProperties": false,
"NewLinesForBracesInObjectCollectionArrayInitializers": false,
@hk1ll3r
hk1ll3r / 20200205-rundelayed-usage.cs
Last active February 5, 2020 23:11
20200205-rundelayed-usage
public void OnBuff()
{
Debug.Log("buffed!");
RunDelayed(2f, () => {
Debug.Log("debuffed!");
});
}
public class Buff : MonoBehaviour
{
public void OnBuff()
{
Debug.Log("buffed!");
RunDelayed(2f, () => {
Debug.Log("debuffed!");
});
}
public class MyMonoBehaviour : MonoBehaviour {
protected IEnumerator DelayedCoroutine(float delay, System.Action a)
{
yield return new WaitForSecondsRealtime(delay);
a();
}
protected Coroutine RunDelayed(float delay, System.Action a)
{
return StartCoroutine(DelayedCoroutine(delay, a));