𓅹 kitasenju design blog 𓅸

humans are imperfect

unity

unityEditorでは問題ないのにwebcamを使うアプリが落ちる時

usage descriptionに記述がないのが原因

複数webcamからひとつを選択

using System.Collections; using System.Collections.Generic; using UnityEngine; public class MyWebcam2 : MonoBehaviour { private WebCamDevice[] devices; private WebCamTexture webCamTexture; [SerializeField] private Material outputMat; priva…

UnityRecorderをscriptから呼ぶ

//using UnityEditor.Recorder; var window = (RecorderWindow)EditorWindow.GetWindow(typeof(RecorderWindow)); if(!window.IsRecording()){ window.StartRecording(); } //stop! if(window.IsRecording()){ window.StopRecording(); } reference How to m…

UnityEditor play/pause

UnityEditor.EditorApplication.isPaused = true;//pause or resume UnityEditorEditorApplication.EnterPlaymode();//play UnityEditorEditorApplication.ExitPlaymode();//exit

Screen.width was sometimes wrong.

On UnityEditor, when I put my own button on inspector and press it, the Screen.width/Screen.height is wrong. It does not change on update() function. I think this is a very rare phenomenon. Screen.widthがおかしい時があった。 UnityEditor上…

RenderTextureをpngに保存(高速版)

save render texture as png pngとして画像を保存 using System.IO; using UnityEngine; using UnityEngine.Assertions; using UnityEngine.Rendering; using UnityEngine.UI; public class RenderTex2PNG : MonoBehaviour { [SerializeField] private Rende…

rayを使わずマウス位置を取得

Vector3 getMousePos(){ var p = Input.mousePosition; _mousePos.x = 2f*(p.x / (float)Screen.width - 0.5f); _mousePos.y = 2f*(p.y / (float)Screen.height -0.5f); float screenH = (float)_camera.orthographicSize;//OrthographicCameraにおける高さ …

meshをwireframe化する

using System.Collections; using System.Collections.Generic; using UnityEngine; public class LineMesh : MonoBehaviour { [SerializeField] private int[] _triangles; // Start is called before the first frame update void Start() { MeshFilter me…

DrawMeshIndirectedを何度か呼ぶ

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering; public class Duplicator : MonoBehaviour { [SerializeField] protected Mesh _mesh; [SerializeField] protected Material _mat; protecte…

How to use Graphics.DrawMesh

using System.Collections; using System.Collections.Generic; using UnityEngine; public class Duplicator : MonoBehaviour { [SerializeField] private Mesh _mesh; [SerializeField] private Material _mat; private MaterialPropertyBlock _block; pri…

iosのdialogueをunityで出す

iOSのダイアログを出す github.com _button.onClick.AddListener(_onClick); private void _onClick(){ string url = MyNativeBindings.GetSettingsURL(); CBNativeDialog.Instance.Show(title: "アクセス許可", message: "動画を保存するには写真へのアクセ…

canvas上のオブジェクトをマウスに追従

void Update(){ var mousePos = Input.mousePosition; var p = new Vector3( (float)mousePos.x / Screen.width-0.5f, (float)mousePos.y / Screen.height-0.5f, 0 ); hoge.localPosition = new Vector3( p.x*1125,//canvasの大きさ p.y*2436, 0 ); }

MyWebcam

gist.github.com

GraphicsFormat/RenderTextureFormatの命名ルールとその性質を調べる

Unity - Scripting API: GraphicsFormat Unity - Scripting API: RenderTextureFormat チャンネルの名称 RGBA D=デプス S=ステンシル 数字=ビット数 8bit=2の8乗=256階調 16bit=2の16乗=65536階調 数値の名称 SNorm=signed normalized=[-1,1]の範囲 UNorm: …

iPhoneのカメラでUnityから利用可能な解像度

11proで調べた。以下のようなコードで調べられた。 WebCamTexture.devices[i].availableResolutions 前面・背面ともに 192x144 352x288 480x360 640x480 1280x720 1920x1080 3840x2160 で、「横長」。 場合によっては縦横方向を変える必要あり。

FlyingText3D 使い方

assetstore.unity.com using System.Collections; using System.Collections.Generic; using UnityEngine; public class FontGen : MonoBehaviour { int _index = 0; string _texts="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"; // S…

EventDispatcher使い方

Event System - Dispatcher | Integration | Unity Asset Store 有料paid asset using System.Collections; using System.Collections.Generic; using UnityEngine; using com.ootii.Messages; public class EventDispatcher : MonoBehaviour { // Start is …

GUI.Button Style変える

private void OnGUI(){ if(_style==null){ _style = new GUIStyle(GUI.skin.button); _style.fontSize = 22; _style.normal.textColor = Color.white; } if( GUI.Button(new Rect(0, Screen.height-100, 100, 100),"[BALL]",_style) ){ for(int i=0;i

checker shader

clip( abs(fmod(round(uvv.x*ss)+stp1,2)-fmod(round(uvv.y*ss+_Time.x)+stp2,2))-0.5 );

add new value to "Required device capabilities" on plist

Add a new string value to "UIRequiredDeviceCapabilities" available strings Apple Developer Documentation using System.IO; using UnityEditor; using UnityEditor.Callbacks; using UnityEditor.iOS.Xcode; namespace Kitasenju { public class AddPl…

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…

〠FOOTER〠