Skip to content

Instantly share code, notes, and snippets.

@rutcreate
rutcreate / ExampleRotate.cs
Created June 16, 2015 03:14
Unity3D: Rotate specific angle
using UnityEngine;
using System.Collections;
namespace Opendream {
public class ExampleRotate : MonoBehaviour {
public Transform m_Transform;
public Vector3 angle;
@rutcreate
rutcreate / GUIControlEditorWindow.cs
Created July 25, 2015 01:56
Unity3D: GUI control name explanation.
using UnityEngine;
using UnityEditor;
using System.Collections;
public class GUIControlEditorWindow : EditorWindow {
[MenuItem("Window/GUIControl Test")]
public static void OpenGUIControlEditorWindow() {
EditorWindow.GetWindow<GUIControlEditorWindow>();
}
@rutcreate
rutcreate / BaseField.cs
Last active September 8, 2015 03:32
Unity3D: Basic Editor Field
[System.Serializable]
public class BaseField<T> {
public string name;
public T value;
public Field(string name) {
this.name = name;
this.value = default(T);
@rutcreate
rutcreate / ProcessBuild.cs
Created October 19, 2015 05:01
Unity3D: Example of post process build
using UnityEditor;
using UnityEditor.Callbacks;
using System.Diagnostics;
using System.IO;
public static class ProcessBuild
{
[PostProcessBuild(1000)]
public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
@rutcreate
rutcreate / AnimationBroadcastStateMachineBehaviour.cs
Last active July 21, 2016 10:32
Unity3D: Broadcast message to all object in state machine behaviour.
using System.Text.RegularExpressions;
using UnityEngine;
public class AnimationBroadcastStateMachineBehaviour : StateMachineBehaviour {
// Could not find the way to get current state name.
// So end up with this. Define variable again.
public string stateName;
@rutcreate
rutcreate / script.sh
Created December 16, 2015 02:35
Using ImageMagick crop images in folders.
# convert Input/*.png -crop [width]x[height]+[pos.x]+[pos.y] -set filename:fname '%t_tn' +adjoin 'Output/[filename:fname].png'
convert Input/*.png -crop 1136x640+418+138 -set filename:fname '%t_tn' +adjoin 'Output/[filename:fname].png'
@rutcreate
rutcreate / validate.js
Created March 20, 2016 08:03
JavaScript: Integer and Float validation
function isInt(n){
return Number(n).toString() === n.toString() && n % 1 === 0;
}
function isFloat(n){
return Number(n).toString() === n.toString() && n % 1 !== 0;
}
@rutcreate
rutcreate / reflection.cs
Last active July 28, 2016 04:10
C# Reflection Example
// Get private or protected field of items
FieldInfo fieldInfo = obj.GetType().GetField("items", BindingFlags.NonPublic | BindingFlags.Instance);
object field = fieldInfo.GetValue(obj);
// Invoke simple method.
// instance.Clear();
MethodInfo methodInfo = type.GetMethod("Clear");
methodInfo.Invoke(obj, null);
// Invoke method with parameter(s).
@rutcreate
rutcreate / pot_images.py
Last active July 14, 2016 01:55
Expand image's canvas to Power of 2.
#!/usr/bin/env python
from PIL import Image
import math
import os
from glob import glob
allowed_sizes = [2, 4, 8, 16, 64, 128, 256, 512, 1024, 2048]
@rutcreate
rutcreate / DragAndDropEditorWindow.cs
Last active September 23, 2022 07:24
How to use DragAndDrop function in Unity3D custom editor. This is just handle when user drag anything outside to THIS EditorWindow only.
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
public class DragAndDropEditorWindow : EditorWindow
{
[MenuItem("Window/Drag And Drop")]
public static void Open()
{