Skip to content

Instantly share code, notes, and snippets.

@michidk
Last active April 8, 2018 02:31
Show Gist options
  • Save michidk/9719f4c3cbcf071d3a38 to your computer and use it in GitHub Desktop.
Save michidk/9719f4c3cbcf071d3a38 to your computer and use it in GitHub Desktop.
C# + Unity Convention
using System.Collections;
using System.Collections.Generic;
namespace Default // or <Company>.(<Product>|<Technology>)[.<Feature>][.<Subnamespace>]
{
public class Example
{
// first consts
public const int TheAnswer = 42;
// then statics
public static string Message = "Hello World!"
// public variables on top of privates
public float Speed = 10;
public int Foo { get; private set; }
private float currTestVal;
[ExampleAttribute(Value = "Test")]
public enum ErrorLevel
{
Warning = 0,
Error = 1,
Fatal = 99
};
public static void Main()
{
if (this.currTestVal > 10)
{
DoSomething();
}
else
{
var result = new LongExampleClassNameResult();
var val = "I am a string!";
}
foreach (var player in PlayerManager.List)
{
if (player.Level > 10000)
Alert.Show("Hacker detected!");
else
DoNothing();
}
}
public void Log(LogType logType)
{
if ((logType.Foo == 3) || (logType.Bar > 10))
{
// ...
}
}
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Default
{
public class Unity : MonoBehaviour
{
[SerializedField]
private SomeClass someClass1;
public SomeClass SomeClass1
{
get
{
return someClass1;
}
set
{
someClass1 = value;
}
}
// use Awake() to initialize any variables
// note that awake is called even if the script is disabled
void Awake()
{
}
// use this method to start your logic
void Start()
{
}
// don't use a modifier on MonobBhaviours methods to mark it as one of them
void Update()
{
}
private void MyMethod()
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment