KITASENJU DESIGN BLOG

memo, html, javascript, unity

unity

Dateを文字列で取得

//using System; System.DateTime.Now.ToString("yyMMddHHmmss");

layerをinspectorから管理したい時

LayerMaskというのがあるのだが、これは単一のレイヤーを指定するものではないようだ。 enumをinspectorに表示し、ドロップダウンで選び、その値をgameObject.layerにつっこむようにした。 enumを定義 スマートでは無いが、layer名が一致するように文字列を…

inspectorに独自の型を表示する

インスペクタに独自の型 using UnityEngine; using System.Collections; using System.Collections.Generic; [System.Serializable] public class HogeClass { public string name; public int index2; public int index3; } public class UITest : MonoBeha…

ComputeScreenPos in Compute Shader

元のComputeScreenPos #define V2F_SCREEN_TYPE float4 inline float4 ComputeScreenPos (float4 pos) { float4 o = pos * 0.5f; //why myltiply by .5f #if defined(UNITY_HALF_TEXEL_OFFSET) o.xy = float2(o.x, o.y*_ProjectionParams.x) + o.w * _Screen…

rendertextureのgetPixelを高速に得る

めちゃくちゃ高速化したー! It's so much faster! 参考 light11.hatenadiary.com コード public override Color32[] GetPixels() { var colors = _texture.GetPixels32(); return colors; } void Update() { if(!IsInit) return; _Request(); } private voi…

Cubemap shader for sphere

cubemap shader for sphere (without skybox) Shader "Unlit/CubeMapForSphere" { Properties { _Cube ("Cubemap", Cube) = "grey" {} } SubShader { Tags { "RenderType"="Opaque" } LOD 100 cull front Pass { CGPROGRAM #pragma vertex vert #pragma frag…

Clone mesh in Unity

Clone mesh on Unity using System.Collections; using System.Collections.Generic; using UnityEngine; public class MeshUtil { public static Mesh CloneMesh(Mesh m, string name ){ var mesh = new Mesh(); mesh.name = name; mesh.vertices = m.verti…

Binding bones only script

How to bind bones only on Unity 骨をバインドする方法 Binding on Unity C# · GitHub using System.Collections; using System.Collections.Generic; using UnityEngine; public class BindTest : MonoBehaviour { [SerializeField] private Mesh _mesh; […

skinnedmeshとbone

手順 BoneWeight[] weightsを頂点数ぶん用意 weights[2].boneIndex0 = 1;//2番目の頂点のウェイトは1番目のボーンの影響下 weights[2].weight0 = 1;//その度合い _mesh.boneWeights = weights;//ウェイトぶちこみ ボーンを用意 ボーン作る。ボーンはgameOb…

Draw Cube with Line

関連:https://kitasenjudesign.hatenablog.com/entry/2021/11/13/133126 using System.Collections; using System.Collections.Generic; using UnityEngine; public class LineMesh : MonoBehaviour { [SerializeField] private MeshFilter _meshFilter; [S…

Unityで影が出ない時

以下の四つ projectSettingのqualityがlowとかになっていないかチェック Sceneのウィンドウの上部で、ライトがオンになっているのをチェック DirectionalLightとかで、shadow castがオンになっているのをチェック 対象物のshadow caster recieverをチェック

Unity Default Panorama Texutre 2048

Simple FPS Counter

count frame every second. using System.Collections; using System.Collections.Generic; using UnityEngine; public class FPSCounter : MonoBehaviour { private int _counter=0; private float _time = 0; public int fps =0; public static int Fps=0;…

Unityで作ったアプリがAndroidで上部などに黒い帯が入る時

render outside safe areaにチェックを入れる

unityでfeedbackEffectを作る

feedbackするためには、現在のフレームframe(t)に過去フレームframe(t-1)を描画する必要がある。 frame(t) = effect( frame(t), frame(t-1) ); ① メインcameraのonRenderImageでrenderTextureAに描画(ノイズ等でずらしたり、位置を動かしたり)。これは描画…

1秒ごとにInstantiate

using System.Collections; using System.Collections.Generic; using UnityEngine; public class Rakka : MonoBehaviour { [SerializeField] private Ball[] _prefabs; private int _count=0; void Start() { _loop(); } private void _loop(){ int index =…

unityで曜日・日付を使う

string[] youbiAry = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; string[] monthAry = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}; var time = DateTime.Now; var hh = time.Hour.ToString("00"); va…

draw lines randomly on unity

ランダムに線を描く using System.Collections; using System.Collections.Generic; using UnityEngine; public class Lines : MonoBehaviour { [SerializeField] private MeshFilter _meshFilter; private Vector3[] _positions; private Mesh _mesh; // St…

trail rendererのresetがおかしい

おかしいので trail rendererだけgameObjectを単独にし、使う時だけInstansiateする。

vfx graph start/stop

using UnityEngine.VFX; VisualEffect _effect; _effect.Play(); _effect.Stop();

generating 3d texture on script

var info = new RenderTextureDescriptor(); info.dimension=UnityEngine.Rendering.TextureDimension.Tex3D; info.colorFormat = RenderTextureFormat.ARGB32; info.width = 512; info.height=256; info.volumeDepth=90; info.depthBufferBits = 0; info.ms…

singleton

using UnityEngine; public class SingletonExample : MonoBehaviour { private static SingletonExample _instance; void Awake(){ if (_instance == null){ _instance = this; DontDestroyOnLoad(this.gameObject); //Rest of your Awake code } else { De…

Header attributeに複数行書く時 orderをかく

must add order number to write multi line texts [Header("●ARBackgroundからテクスチャを作るクラス",order = 1)] [Space(10,order = 2)] [Header("ARFoundation機能への参照",order = 3)]

alpha test (cut off) on VFX Graph

Select "output particle quad". Check "use alpha clipping" on inspector.

sound sine generator

You can made sine wave sound like this in Unity using UnityEngine; public class SineGanerator : MonoBehaviour { private AudioSource AudioSource; [SerializeField, Range(0, 1)] private float Volume = 1; [SerializeField, Range(100, 1000)] pri…

set webcams to dropdown

WebcamをDropdownから選べるようにする using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; public class WebCamSelector : MonoBehaviour { [SerializeField] private TMP_Dropdown _dro…

dotween Sequence

複数のdotweenを一つにする 関数名 Append Sequenceの最後にTween/Sequenceを追加する Insert 指定した秒数後に再生開始するTween/Sequenceを追加する Join 直前に追加されたTween/Sequenceと同時再生する Prepend Sequenceの最初にTween/Sequenceを追加する…

3d texture + slit-scan

slitscan with 3d texture using System.Collections; using System.Collections.Generic; using UnityEngine; public class slitscan3d : MonoBehaviour { public RenderTexture _rt3d; public Material _mat; private WebCamTexture _tex; private int _in…

スクリプト上でマテリアルのプロパティをコピー

_distMat.CopyPropertiesFromMaterial(_srcMat)

ChromaKey PostEffect

Unity でクロマキーシェーダを作ってみた - 凹みTips をpost effectで使えるようにしてみました。 Shader "ChromaKey/ChromaKey_PostEffect" { Properties { [Header(Material)] _Color ("Color", Color) = (1, 1, 1, 1) _MainTex("Texture", 2D) = "white" …

"FOOTER"