Skip to content

Instantly share code, notes, and snippets.

@mao-test-h
mao-test-h / CosApproximate.cs
Last active August 1, 2018 17:02
級数展開でcosの近似値を出すテスト
// https://twitter.com/TEST_H_/status/1023975602494169092
using System;
using System.Diagnostics;
namespace MyContents
{
class Test
{
static void Main()
@mao-test-h
mao-test-h / AudioCueSample.cs
Last active August 4, 2018 16:50
Unity用SoundCue(っぽいもの)サンプル
namespace MainContents.AudioUtility
{
using UnityEngine;
// UE4のSoundCueを参考にしたもの。
// 内容的にはAudioClipのラッパー的な立ち位置で、AudioClipを取得する際の振る舞いを実装するもの。
// →例 : ランダムでClipを返すもの、配列に登録したClipを順番に取得など。
// ※本当はinterfaceにしたいけどSerializeFieldで登録する都合上、敢えて基底クラスとする...
public abstract class AudioCue : ScriptableObject
{
@mao-test-h
mao-test-h / AutoGraphicsEmulatorSetting.cs
Created September 3, 2018 16:47
自動でGraphics Emulationを設定してくれるやつのサンプル。(これはWebGL2.0に自動で設定してくれる)
#if UNITY_EDITOR && UNITY_WEBGL
namespace MyContents.Editor
{
using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
public class EditInitialSetting
{
static EditInitialSetting()
@mao-test-h
mao-test-h / DokabenGeometry.shader
Created October 13, 2018 13:11
ジオメトリシェーダ―を用いて形状関係なしに強制的にドカベンロゴに塗り替えるシェーダー
Shader "Unlit/DokabenGeometry"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags
@mao-test-h
mao-test-h / Dokaben-Sprite-Default.shader
Created October 29, 2018 14:11
ドカベンロゴアニメーションシェーダー(書き直し版)
Shader "Custom/Sprites/Dokaben"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
[HideInInspector] _RendererColor ("RendererColor", Color) = (1,1,1,1)
[HideInInspector] _Flip ("Flip", Vector) = (1,1,1,1)
[PerRendererData] _AlphaTex ("External Alpha", 2D) = "white" {}
@mao-test-h
mao-test-h / ProgressBarDrawer.cs
Created February 21, 2019 18:48
Inspectorにプログレスバーを表示する奴のサンプル
// usage:
// [SerializeField] [ProgressBar] float _sample;
// [SerializeField] [ProgressBar("hoge")] float _sample;
// [SerializeField] [ProgressBar(0f, 1f)] float _sample;
// [SerializeField] [ProgressBar(0f, 1f, "hoge")] float _sample;
namespace Sample
{
using System;
using UnityEngine;
@mao-test-h
mao-test-h / NativeObject.cs
Created February 23, 2019 18:09
少し保守的にしてみたネイティブメモリ側に作るオブジェクト。(ぶっちゃけ長さが1のNativeArrayと変わらない)
namespace LowLevel.Unsafe
{
using System;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
public unsafe struct NativeObject<T> : IDisposable
where T : unmanaged
{
[NativeDisableUnsafePtrRestriction] readonly T* _buffer;
@mao-test-h
mao-test-h / InsertDefault.cs
Last active March 29, 2019 07:37
[SerializeField] private 変数にdefault代入してくれる君
// Unity2018.3からprivateな[SerializeField]が初期化しないと警告吐くようになってきたので、
// 各CSソースを解析して一括で"= default;"を付ける奴。
// ※ sedコマンドとかでも出来なくは無いが..改行や既存の代入などを踏まえるとこっちの方が早かった。
namespace Tools // HACK: 適当なので都合に合わせて命名
{
using System;
using System.IO;
using UnityEngine;
using UnityEditor;
@mao-test-h
mao-test-h / Native2DArray.cs
Last active December 31, 2020 05:15
Unityでのネイティブメモリ確保用のラッパー
using System;
using System.Runtime.InteropServices;
using Unity.Collections.LowLevel.Unsafe;
namespace Unity.Collections
{
/// <summary>
/// ネイティブメモリでの2次元配列のメモリ確保用ラッパー
/// </summary>
[NativeContainer]
@mao-test-h
mao-test-h / NativeUtility.cs
Created September 15, 2019 11:42
ポインタをNativeArrayに変換
namespace Unity.Collections.LowLevel.Unsafe
{
public static unsafe class NativeUtility
{
public static NativeArray<T> PtrToNativeArray<T>(T* ptr, int length)
where T : unmanaged
{
var arr = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<T>(ptr, length, Allocator.Invalid);
// これをやらないとNativeArrayのインデクサアクセス時に死ぬ