Skip to content

Instantly share code, notes, and snippets.

View divide-by-zero's full-sized avatar

ksz divide-by-zero

View GitHub Profile
@divide-by-zero
divide-by-zero / BlurTest.cs
Last active May 30, 2016 20:02
Animation Sprite Blur Effect
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
public class BlurTest : MonoBehaviour {
private SpriteRenderer _spriteRenderer;
private Dictionary<Sprite, Sprite> _blurSprites = new Dictionary<Sprite, Sprite>();
private SpriteRenderer _blurSpriteRenderer;
private Texture2D _blurTexture;
using UnityEngine;
public class MyMonoBehaviour : MonoBehaviour{
private Rigidbody _rigidbody;
public Rigidbody rigidbody {
get { return _rigidbody ?? (_rigidbody = GetComponent<Rigidbody>()); }
}
private Rigidbody2D _rigidbody2D;
public Rigidbody2D rigidbody2D {
public static class TransformExtension{
public static void SetPosition(this Transform t, float? x = null, float? y = null, float? z = null) {
var pos = t.transform.localPosition;
if (x.HasValue) pos.x = x.Value;
if (y.HasValue) pos.y = y.Value;
if (z.HasValue) pos.z = z.Value;
t.transform.localPosition = pos;
}
public static void AddPosition(this Transform t, float? x = null, float? y = null, float? z = null) {
var pos = t.transform.localPosition;
@divide-by-zero
divide-by-zero / GearVRHelper.cs
Last active January 5, 2017 15:42
GearVR用
using UnityEngine;
public class GearVRHelper : MonoBehaviour{
//タップ・フリック検出用の
public delegate void TrackPad(float x, float y);
//戻るボタンの短押しと、長押し用
public delegate void Trigger();
//戻るボタンの長押し検出時間
@divide-by-zero
divide-by-zero / TouchEventTest.cs
Created May 16, 2015 17:10
GearVRHelper使用例
using UnityEngine;
public class TouchEventTest : MonoBehaviour {
void Start () {
GearVRHelper.OnBackHold += () => {
Debug.Log("BACK HOLD!");
};
GearVRHelper.OnBackPush += () => {
Debug.Log("BACK PUSH!");
};
@divide-by-zero
divide-by-zero / gist:d4bbaefc89c14bae7469
Last active August 29, 2015 14:25
1秒長押しStream
var longClickStream = UpdateAsObservable().Select(_ => Input.GetMouseButton(0)).DistinctUntilChanged().Throttle(TimeSpan.FromMilliseconds(1000)).Where(b => b);
@divide-by-zero
divide-by-zero / ObservableButtonDownTrigger.cs
Created July 19, 2015 14:34
uGUIが押されている間はtrue,離されている間はfalseをStreamに流し続けるTrigger
using UniRx;
using UniRx.Triggers;
using UnityEngine.EventSystems;
public class ObservableButtonDownTrigger : ObservableTriggerBase, IPointerDownHandler, IPointerUpHandler{
private bool isPointerDown;
private Subject<bool> onButtonDown;
public IObservable<bool> OnButtonDown
{
@divide-by-zero
divide-by-zero / gist:8c3da9c1ee1f46a2b3de
Created July 19, 2015 14:39
ObservableButtonDownTrigger を使う
var btnDownTrigger = button.gameObject.AddComponent<ObservableButtonDownTrigger>();
btnDownTrigger.OnButtonDown.DistinctUntilChanged().Throttle(TimeSpan.FromMilliseconds(1000)).Where(b => b).Subscribe(b => {
Debug.Log("1秒押された");
});
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace GameUtil
{
public class TaskScheduler : MonoBehaviour
{
using UniRx;
using UniRx.Triggers;
using UnityEngine.EventSystems;
public class ObservableButtonDownTrigger : ObservableTriggerBase, IPointerDownHandler, IPointerUpHandler{
public bool IsPointerDown { private set; get; }
private Subject<bool> onButtonDown;
private int repeatStartFrame = 50;
private int repeatSpanFrame = 5;
private bool isOldPointerDown;