KITASENJU DESIGN BLOG

humans are imperfect

c#

Fusen

using System.Collections; using System.Collections.Generic; using UnityEngine; public class Fusen : MonoBehaviour { #if UNITY_EDITOR [SerializeField, MultilineAttribute (2)] string message; #endif } }

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…

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: …

text mesh pro よく使うtag

c#

http://digitalnativestudios.com/textmeshpro/docs/rich-text/ 縦の位置 <voffset=1em>up</voffset> 任意のスペース挿入 <space=5em>aaa 文字スペース <cspace=-0.2em>space</cspace>

Dateを文字列で取得

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

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…

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…

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で曜日・日付を使う

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…

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

_distMat.CopyPropertiesFromMaterial(_srcMat)

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

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[] …

イベント書く delegate

c#

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; // コールバックテスト public class MyCallbackTest : MonoBehaviour { // スタート時に呼ばれる void Start () { MyProcess myProcess = new …

Date を 00:00 mmss表示

c#

var t = Mathf.Floor(Time.realtimeSinceStartup-_startTime); var min = Mathf.Floor( t / 60 ); var sec = t % 60; _timeText.text = "" + min.ToString("00") + ":" + sec.ToString("00");

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(…

draggable UI from side to side

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

enum 2 string

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

3Dアクションゲーム的にLRジョイスティックでキャラとカメラを動かす

c#

How to move the character and camera with the LR joystick like a 3D action game. charaを動かす(左スティック) CharaControllerを使う。 Unity - Scripting API: CharacterController.Moveを改造。 Charaを進む方向は、カメラが向いている方向を使う…

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

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

get decimal number

c#

小数部分を得る float value = 6.7071f; value = value - Mathf.Floor (value); print (value); float value2 = Mathf.PI; value2 = value2 % 1; print (value2);

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>…

how to use transform.localToWorldMatrix on c#

answers.unity.com Vector3 lPos; // your local pos Vector3 wPos = transform.TransformPoint(lPos); //is the same as Vector3 wPos = transform.localToWorld * new Vector4(lPos.x, lPos.y, lPos.z, 1f); //or just Vector3 wPos = transform.localToWo…

PostProcessingV2をスクリプトからコントロール

PostProcessingV2をscriptからcontrolする。 public PostProcessVolume ppVolume; var bloom = ppVolume.profile.GetSetting<UnityEngine.Rendering.PostProcessing.Bloom>(); bloom.active=true; bloom.intensity.value=30f;</unityengine.rendering.postprocessing.bloom>

IEnumerator Start()

C# - Unity)IEnumerator Start()の使い方|teratail

struct(構造体)の使い所

c#

使い所 【C#】構造体の使い方(クラスとの違い、初期化や配列の使用も解説) | 侍エンジニア塾ブログ(Samurai Blog) - プログラミング入門者向けサイト 参照型の機能が必要ない場合は、クラスとして実装するよりは構造体として定義した方が効率的に処理され…

〠FOOTER〠