KITASENJU DESIGN BLOG

memo, html, javascript, unity

unity

uGUIでblendMode反転シェーダー

UnityEngine.UI.Imageなどの要素を、blendModeを使って反転したい。 https://baba-s.hatenablog.com/entry/2019/02/03/192500 を参考にさせてもらった。 透明度の反映の仕方がよくわからなかったのでclipした。 BlendOp, Blendを使って計算していると思うが…

unity+macで書き出したappが動かない

A Mac+Unity-exported app that downloaded from web doesn't work. It is a security problem. You have to do below on Terminal. Unityから書き出したappがネット経由でダウンロードしたappが動かない。 壊れていると言われる。ターミナルで以下を入力。 …

操作後、sliderにフォーカスを渡さないように

I didn't want uGUI to focus a slider after using it on Unity. unityのuguiにて。 private Slider _slider1; _slider1.onValueChanged.AddListener(_onChange); private void _onChange(float value){ EventSystem.current.SetSelectedGameObject(null);/…

unityから書き出したmacのアプリが動かなかった

https://qiita.com/aike@github/items/5df284620059bfc07364 macのappをunityから書き出してwebにファイルをアップ それがローカルファイルを参照するようなものだったとき、動かない! セキュリティの問題で 新規フォルダを作成→appをコピペ→それ以外をコピ…

onguiで背景を設定

[SerializeField] private Texture2D _bg; private void OnGUI(){ if (style == null) { style = new GUIStyle(); style.fontSize = 30; style.normal.textColor = Color.white; style.normal.background = _bg; } GUI.Label( new Rect(0, 700, 200, 50), _i…

unityからdirectoryを作る

public static void MakeNewDir(string newPath){ if ( Directory.Exists( newPath )) { // フォルダが存在する. Debug.Log("既に存在しているのでディレクトリつくらない " + newPath); }else{ Directory.CreateDirectory( newPath ); Debug.Log("ディレク…

Animatorの時間

using System.Collections; using System.Collections.Generic; using UnityEngine; public class CharaBase : MonoBehaviour { [SerializeField] protected Animator _animator; void Update() { CheckAnim(); } void CheckAnim() { if (_animator == null)…

シェーダー内で任意の階層の座標系にする

targetTransform.worldToLocalMatrixをc#で得て、shaderに渡す shaderの中で mul(unity_ObjectToWorld, v.vertex)で一回ワールド座標系に ワールド座標系から対象の座標系にmul(worldToLocal,vertex)

hitTest

using System.Collections; using System.Collections.Generic; using UnityEngine; public class HitTest : MonoBehaviour { // Start is called before the first frame update void Start() { } void OnCollisionStay(Collision collision) { Debug.Log("…

Fusen

付箋(比喩)のようにインスペクターにメモ欄を入れる using System.Collections; using System.Collections.Generic; using UnityEngine; public class Fusen : MonoBehaviour { #if UNITY_EDITOR [SerializeField, MultilineAttribute (2)] string message…

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から呼ぶ

how to call UnityRecorder from scripts //using UnityEditor.Recorder; var window = (RecorderWindow)EditorWindow.GetWindow(typeof(RecorderWindow)); if(!window.IsRecording()){ window.StartRecording(); } //stop! if(window.IsRecording()){ windo…

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…

"FOOTER"