Skip to content

Instantly share code, notes, and snippets.

@rutcreate
rutcreate / TestLoopThroughMembers.cs
Created March 1, 2015 13:57
Unity3D: C# Loop through class member using Reflection.
using UnityEngine;
using System.Collections;
using System.Reflection;
public class Configuration {
public const float musicVolume = 1.0f;
public const float sfxVolume = 1.0f;
@rutcreate
rutcreate / InspectorEditor.cs
Last active October 28, 2022 14:30
Unity3D: How to iterate properties through inspector
using UnityEngine;
using UnityEditor;
using System.Collections;
namespace Opendream {
[CustomEditor(typeof(MovingPlatform))]
public class InspectorEditor : Editor {
public override void OnInspectorGUI() {
@rutcreate
rutcreate / CameraBoundary.cs
Last active August 29, 2015 14:21
Draw camera boundary in scene view.
using UnityEngine;
namespace Opendream {
public class CameraBoundary : MonoBehaviour {
public Color faceColor = new Color(0f, 0f, 0f, 0f);
public Color outlineColor = new Color(1f, 1f, 1f);
@rutcreate
rutcreate / ScenePopup.cs
Created May 19, 2015 02:10
Unity3D Editor: Scene popup
using UnityEngine;
using System.Collections;
public class ScenePopup : PropertyAttribute {
public bool required = false;
public ScenePopup() {}
public ScenePopup(bool required) {
@rutcreate
rutcreate / MyProperty.cs
Created May 19, 2015 02:29
Unity3D Editor : How to get other fields in PropertyDrawer.OnGUI
using UnityEngine;
public class MyProperty : PropertyAttribute {
public int intValue = 33;
public float floatValue = 12.5f;
public bool boolValue = true;
@rutcreate
rutcreate / SceneManager.cs
Last active March 21, 2020 00:27
Unity3D: Scene Manager (Loading asynchronously)
using UnityEngine;
public class SceneManager : MonoBehaviour {
private const string LOADING_LEVEL_KEY = "Loading Level";
private static AsyncOperation operation;
public float delayBefore = 0.5f;
@rutcreate
rutcreate / MyButton.cs
Last active March 11, 2024 00:02
Unity3D: Best way to add listener programmatically for Button onClick
using UnityEngine;
public class MyButton {
public Button[] buttons;
private void Start() {
for (int i = 0; i < buttons.Length; i++) {
Button button = buttons[i];
var index = i;
@rutcreate
rutcreate / CameraLayout.cs
Created May 30, 2015 10:33
Unity3d: 2D Pixel Perfect Camera
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
namespace RutCreate {
[ExecuteInEditMode]
public class CameraLayout : MonoBehaviour {
public Vector2 referenceResolution = new Vector2(800f, 600f);
@rutcreate
rutcreate / StringExample.cs
Created June 15, 2015 03:02
Unity3D: String extension ToInt(), ToFloat(), ToBool(), BetterFormat().
public class StringExample {
private int intFromString;
private float floatFromString;
private bool boolFromString;
private string format = "Hi {Name} {Last}, I'm {Age} years old. I'm from {Country}.";
@rutcreate
rutcreate / CustomEditorWindow.cs
Last active October 3, 2016 11:13
Unity3D: Master-detail layout in custom editor.
using UnityEngine;
using UnityEditor;
using System.Collections;
using Opendream.Layouts;
namespace Opendream {
public partial class CustomEditorWindow : EditorWindow {
[MenuItem("Window/Custom Editor", false, 2)]