|
|
@@ -0,0 +1,58 @@ |
|
|
using UnityEngine; |
|
|
using System.Collections; |
|
|
using System.Collections.Generic; |
|
|
|
|
|
public class ExampleClass : MonoBehaviour // Try to name classes so other developers can infer their functionality. Abstract classes are prefixed with 'Base' |
|
|
{ |
|
|
private enum WidgetType // Enums should end in 'Type' and can be inlined with the class if private, but generally should be relocated if public |
|
|
{ |
|
|
None, |
|
|
Circle, |
|
|
Sphere |
|
|
} |
|
|
|
|
|
private struct SomeWidgetData // Custom structs used by the class can use public fields, if custom classes or structs need to be public, break them out |
|
|
{ |
|
|
public int WidgetId; |
|
|
public string WidgetName; |
|
|
} |
|
|
|
|
|
private const int WIDGET_OFFSET = 10; // Consts come before serialized fields, but after any enums, classes or structs used by the class |
|
|
|
|
|
[Header("Widget Properties")] // Use the Header attribute to organize your serializable fields |
|
|
|
|
|
[SerializeField] private Transform m_TargetTransform; // Serialized fields should be marked private, and start with 'm_' |
|
|
|
|
|
private string m_SomeString; // Non-serialized fields come after serialized fields, and start with 'm_' |
|
|
|
|
|
protected bool m_SomeBool; // Use the protected access modifier to allow inherited classes to access the field |
|
|
|
|
|
public bool IsWidgetReady { get; private set; } // Properties should have a private or protected set where possible, and follow normal Pascal case |
|
|
|
|
|
public Transform Transform { get; private set; } // Note that it is OK to have public properties named the same as their type - the compiler can infer what you want to use |
|
|
|
|
|
private Dictionary<int,Transform> m_WidgetTransforms; // Use dictionaries where possible, retrieval via key is fast |
|
|
|
|
|
private void Awake() // Use awake to initialize variables that are used for the duration of the class lifecycle |
|
|
{ |
|
|
m_WidgetTransforms = new Dictionary<int, Transform>(); // Initialize in Awake rather than in the fields declaration |
|
|
} |
|
|
|
|
|
private void Start() // Unity Monobehaviour methods should come first |
|
|
{ |
|
|
// Comments should have a space after the '//' and be written as proper sentences |
|
|
|
|
|
int someValue = 3; // Local variables should be camel case |
|
|
|
|
|
Transform someTransform = this.GetComponent<Transform>(); // When using Monobehaviour derived methods, prefix with 'this.' |
|
|
} |
|
|
|
|
|
public string GetWidgetName(int widgetId) // Public methods are Pascal case and parameters are camel case - note that 'ID' is written 'Id' - try to avoid consecutive uppercase |
|
|
{ |
|
|
Debug.LogFormat("Output:{0}, {1}, {2}", "hello", widgetId, "world"); // Use Debug.LogFormat where possible |
|
|
|
|
|
Vector3 position = this.transform.position; // As of Unity 5, there's no point caching transforms as it's done internally |
|
|
|
|
|
return "hello world"; |
|
|
} |
|
|
} |