Skip to content

Instantly share code, notes, and snippets.

@tsubaki
tsubaki / SingletonObject.cs
Last active August 29, 2015 13:55
オブジェクト単位でのシングルトン。名前で判断
using UnityEngine;
using System.Collections;
/// <summary>
/// このコンポーネントがアタッチされているオブジェクトは、 単一のオブジェクトに含まれる
/// 既にある場は削除される
/// </summary>
public class SingletonObject : MonoBehaviour
{
/// <summary>
@tsubaki
tsubaki / DataSet.cs
Created March 8, 2014 06:45
【試作】変更通知ディクショナリと、シングルトンなデータ管理クラス
using UnityEngine;
using System.Collections;
public class DataSet : SingletonMonoBehaviour<DataSet> {
public ObserverDictionary<bool> notiBool = new ObserverDictionary<bool>();
public ObserverDictionary<int> notiInt = new ObserverDictionary<int>();
public static void Attatch(string key, ObserverDictionary<bool>.NotificationAction action)
{
@tsubaki
tsubaki / EasyAnchor.cs
Created March 17, 2014 16:40
maincameraから見た左上・右下等にゲームオブジェクトを移動する。左上を(0,0)にしたい場合等
using UnityEngine;
using System.Collections;
public class EasyAnchor : MonoBehaviour
{
public enum VerticalPosition
{
Top = 2,
Center = 1,
Bottom = 0
@tsubaki
tsubaki / FindReference.cs
Last active August 29, 2015 13:58
選択したオブジェクトを参照しているシーン内のオブジェクト一覧を表示する
using UnityEngine;
using System.Collections;
using UnityEditor;
public class FindReference
{
[MenuItem("GameObject/FindReferenceInSceneObject")]
static void Find ()
{
@tsubaki
tsubaki / RendererTest.cs
Created April 16, 2014 02:54
子オブジェクトの表示を一気に消す
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class RenderTest : MonoBehaviour
{
void OnEnable ()
{
var rendererList = GetComponentsInChildren<Renderer> ();
foreach (var renderer in rendererList) {
@tsubaki
tsubaki / FreezRigidbody.cs
Last active August 29, 2015 13:59
rigidbodyをkinematicにする例(別コンポーネントとの連携)
using UnityEngine;
using System.Collections;
public class FreezRigidbody : MonoBehaviour
{
Rigidbody _rigidbody;
// 定義しておくとコンポーネント起動時に1回呼ばれるイベント。詳しくはMonoBehaviour参照
void Start ()
{
@tsubaki
tsubaki / HideObjectManager.cs
Created April 23, 2014 14:54
ヒエラルキーから選択したオブジェクトを消す
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class HideObjectManager : MonoBehaviour
{
#if UNITY_EDITOR
public List<GameObject> hideObjectList = new List<GameObject> ();
using UnityEngine;
using System.Collections;
public class InputTest : MonoBehaviour
{
void Update()
{
if( Input.GetKeyDown(KeyCode.LeftArrow) )
{
GetComponent<Handler>().param.Value += 1;
@tsubaki
tsubaki / GetRootInstancePrepared.cs
Last active August 29, 2015 14:00
ルートオブジェクト一覧を取得する
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class GetRootInstancePrepared : MonoBehaviour {
@tsubaki
tsubaki / ScrollTexture.cs
Created May 23, 2014 11:17
複雑なスプライトをUVスクロールしたい場合の例。textureのread/writeにチェックが入っていることが必須条件
using UnityEngine;
using System.Collections;
public class ScrollTexture : MonoBehaviour
{
public Vector2 UVDirection;
private Texture2D tex2d;
private Vector2 currentUVOffset = new Vector2 (0, 1);