KITASENJU DESIGN BLOG

memo, html, javascript, unity

unity

Resize renderTex that already exists in assets

renderTex.Release(); renderTex.width = _stageWidth; renderTex.height = _stageHeight; renderTex.Create();

RenderTexture + GetPixels

using UnityEngine; public class RenderTextureColorPicker : MonoBehaviour { [SerializeField] private RenderTexture _target; private Texture2D _texture; private void Awake(){ _texture = new Texture2D(_target.width, _target.height); } private…

Event Hundler in ARTrackedImageManager

//ARTrackedImageManager _trackedImageManager; void Awake() { _trackedImageManager.trackedImagesChanged += _onChange; } private void _onChange(ARTrackedImagesChangedEventArgs args){ List<ARTrackedImage> added = args.added; List<ARTrackedImage> updated = args.updated; List<ARTrackedImage></artrackedimage></artrackedimage></artrackedimage>…

URPでVisualEffectGraphを使う

PackageManagerからインストールする com.unity.visualeffectgraph ってキーワードでgitからインストールする Asset作る addComponent VisualEffectというコンポーネントを追加 作ったAssetをセットする 4つの構成要素 Visual Effect Graph 入門 - Qiita そ…

shader graphのcustom functionの書き方

Custom Function ノード | Shader Graph | 10.0.0-preview.27 ファイルを作って、その中に書くとき stringをコピペするとき フォーマットが違う。 stringにかいた例 その他、参考 レーダースキャンしてるっぽいシェーダーを作りたかった(失敗) - 女子高生…

ツールバーから画面キャプチャするスクリプト

using System.IO; using UnityEditor; using UnityEngine; [ExecuteInEditMode] public class CapturePNG { private static int _index = 0; [MenuItem("Tools/Screen Capture")] public static void Capture() { var str = System.DateTime.Now.ToString("y…

simply draw 1 pixel line

シンプルに1pxの線を描く line rendererを使わず、の方法。 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Lines : MonoBehaviour { [SerializeField] private MeshFilter _meshFilter; private Vector3[] …

package managerでvector graphicsがでない時

Unity2020でバグがあるっぽい。検索窓に入力して出てこない時 左端のgitから追加するみたいなところからパッケージ名をいれる。com.unity.vectorgraphics 一覧 https://helpdesk.unity3d.co.jp/hc/ja/articles/900002171066-Unity-2020-1-%E3%81%8B%E3%82%89…

gradation shader

in fragment shader fixed4 frag (v2f i) : SV_Target { fixed4 col = float4(1,0,0,1); col = lerp(col,float4(0,1,0,1),smoothstep(0,0.333,i.uv.x)); col = lerp(col,float4(0,0,1,1),smoothstep(0.333,0.666,i.uv.x)); col = lerp(col,float4(1,0,0,1),s…

quadtree

gist.github.com

Why 30fps with AR Foundation

in ARSession.cs Application.targetFrameRate = subsystem.frameRate; It seems that the frameRate is specified by subsystem. subsystemによって、フレームレートが指定されているようだ;(

Unity+Macでファイルのドラッグ&ドロップ

以下を使わせていただきました。 UniDragAndDropForMac GitHub - baobao/UniDragAndDropForMac: A library that implements drag and drop in Unity's macOS build でも、使い方に悪戦苦闘しました。以下サンプルコードです。 WWWの使い方 IEnumeratorの使い…

simple boids with c#

// based https://p5js.org/examples/simulate-flocking.html using System.Collections; using System.Collections.Generic; using UnityEngine; public class Boids : MonoBehaviour { [SerializeField] private int NUM = 100; [SerializeField] BoidsPie…

ARFoundation + Canvas(ScreenSpaceCamera)

canvasがunity editor上より大きくなったり、位置が少しずれたりします。 The canvas may be larger than in the unity editor, or slightly out of position.

AssetのPathを得る

#if UNITY_EDITOR Debug.Log( "JsonPath " + UnityEditor.AssetDatabase.GetAssetPath(textAsset) ); #endif

日付の文字列を作る

System.DateTime.Now.ToString("yyMMdd_HHmmss");

.pcache parser

simple point cache file(.pcache) parser using UnityEngine; using System; public class PCacheParser { public static Vector3[] Parse(string text, int elements){ string str = text; string[] splitStr = {"end_header"}; string[] ary = str.Split(…

pcache baker

visual effect graph をpackage managerで入れる。 Window>VisualEffects>Utilities から Point cache bake tool でpcacheファイルを作る using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using System…

vector3の高速化

【Unite 2018 Tokyo】60fpsのその先へ!スマホの物量限界に挑んだSTG「アカとブルー」の開発設計 from UnityTechnologiesJapan002 www.slideshare.net public static float Normalize(ref Vector3 v) { // Magnitude関数のインライン化 float mag = (float)S…

Handheld.Vibrate() does not work with Unity + iOS

If you use Microphone.Start(), the vibration on iOS doesn't seem to work. AudioServicesPlaySystemSound(soundId) on Obj-C does not work as well. Microphone.Start()を使っていると、バイブレーションが動かないようだ。

draggable UI from side to side

for smartphone and pc. 左右にドラッグできるUI タッチまたはマウスダウンで左右にドラッグするスクリプト。 スマホ、PC対応 めんどくさいので、もうつくりたくない・・ using System.Collections; using System.Collections.Generic; using UnityEngine; u…

Quaternionで徐々に対象の回転に向かう

毎フレームこれをやって、徐々に近づけた。 data.rotation = Quaternion.Lerp(data.rotation, tgtRot, 0.05f);

sceneビューのカメラ固定について

sceneビューでオブジェクトを中心にする ゲームオブジェクトが中心になるようにシーンビューをセンタリングするには、Hierarchy でゲームオブジェクトを選択し、マウスをシーンビューへ移動し、F を押します。メニューバーで Edit > Frame Selected を選択し…

Reset AR Foundation

AR FoundationをResetしたときのコード public static void ReloadMain(){ //ARKitリセット _arMeshManager.DestroyAllMeshes(); _arSession.Reset(); _arSession.enabled=false; _arSessionOrigin.enabled=false; Destroy(_arSession.gameObject); DOVirtua…

ヒエラルキーで、子供や孫を取得する

GetComponentsInChildren が入れ子の末端まで取得できる。スーパー便利。 _container.GetComponentsInChildren<MeshRenderer>() ※けどactiveSelf=trueじゃないと取得されないかも その場合は for(int i=0;i</meshrenderer>

enum 2 string

How to get Enum from String YourEnumType parsed_enum = (YourEnumType)System.Enum.Parse( typeof(YourEnumType), your_string );

インスペクターにボタンを作る

how to make a button on inspector https://kan-kikuchi.hatenablog.com/entry/CustomEditor_Button ExampleScript.cs using UnityEngine; [ExecuteInEditMode] //エディター再生してない時、動くように? 場合によって使う public class ExampleScript : M…

Bake vertices to PNG with compute shader

compute shaderをつかって頂点をベイクする using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; #if UNITY_EDITOR using UnityEditor; using System.IO; #endif public class MeshVertBaker2 : MonoBehavi…

Texture2Dに頂点をベイクする

bake vertices to texture2d using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; #if UNITY_EDITOR using UnityEditor; using System.IO; #endif public class MeshVertBaker1 : MonoBehaviour { [Seriali…

How to use JSONObject

JSONObject使い方 import using UnityEngine; using System.IO; public class JsonLoader : MonoBehaviour { public TextAsset data; // private List<Vector3> _hoge; void Start() { Debug.Log(data.text); //読み込む var a = new JSONObject(data.text); var n = </vector3>…

"FOOTER"