Skip to content

Instantly share code, notes, and snippets.

using UnityEngine;
using UnityEditor;
public class AutoSnap : EditorWindow
{
private Vector3 prevPosition;
private bool doSnap = true;
private float snapValue = 1;
[MenuItem( "Edit/Auto Snap %_l" )]
@mindryu
mindryu / ShowOnlyAttribute.cs
Last active August 29, 2015 14:07
Unity ShowOnly(ReadOnly) Attribute
// Asset/Script/ShowOnlyAttribute.cs
using UnityEngine;
public class ShowOnlyAttribute : PropertyAttribute
{
}
@mindryu
mindryu / Sequence.cs
Created October 9, 2014 07:28
Untiy3D Sequnce Coroutine
// Sequence
IEnumerator Sequence(params IEnumerator[] sequence)
{
for (int i = 0; i < sequence.Length; ++i)
{
while (sequence[i].MoveNext())
yield return sequence[i].Current;
}
}
@mindryu
mindryu / MultiScaleCamera.cs
Last active May 21, 2020 03:29
[Unity3D] Multi Resolution Scale Policy Camera.
using System;
using UnityEngine;
/**
* Multi Resolution Scale Policy Camera.
*
* @author Robert Ryu
* @date 10/13/2014
*/
@mindryu
mindryu / AssetPostProcessLogger.cs
Last active October 27, 2015 16:35
[Unity3D] Post Process Utility
using UnityEditor;
using UnityEngine;
public class AssetPostProcessLogger : AssetPostprocessor {
static void OnPostprocessAllAssets(
string[] importedAssets,
string[] deletedAssets,
string[] movedAssets, string[] movedFromAssetPaths
)
@mindryu
mindryu / WaitThenCallback
Created November 9, 2014 12:57
Unity3D WaitThenCallback
private IEnumerator waitThenCallback(float time, Action callback)
{
yield return new WaitForSeconds(time);
callback();
}
void Start()
{
splashScreen.show();
@mindryu
mindryu / LabelManager
Last active October 27, 2015 16:34
Unity4.6 World to Canvas Position
label.transform.SetParent(transform,false);
// Canvas = Screen Space - Overlay
label.transform.position = RectTransformUtility.WorldToScreenPoint(Camera.main, pos);
// Canvas = Screen Space - Camera
label.transform.position = RectTransformUtility.WorldToScreenPoint(Camera.main, Camera.main.ScreenToWorldPoint(pos));
@mindryu
mindryu / DamageLabelController
Last active August 29, 2015 14:09
unity4.6 Text FadeOutAndSelfDestroy DamageLabelController
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class LabelController : MonoBehaviour
{
public float fadeDuration = 0.5f;
public float moveDuration = 0.8f;
private Text _text;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var groundPlane = new Plane(Vector3.up,Vector3.zero);
float rayDistance;
if (groundPlane.Raycast(ray, out rayDistance))
{
var point = ray.GetPoint(rayDistance);
}
@mindryu
mindryu / RotateToMousePosition.cs
Created February 4, 2016 18:14
Rotate to mouse position
using UnityEngine;
public class RotateToMousePosition : Monobehaviour
{
public int RotationOffset = 90;
void Update()
{
// Difference is direction vector from current position to mouse position.
Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;