はじめに
「UrFairy」を Unity プロジェクトに導入することで
便利な拡張メソッドが使用できるようになります
使い方
using UrFairy;
ソースコードの先頭に上記の using を追加することで使用できるようになります
拡張メソッド一覧(引用)
Vector3
transform.localPosition = transform.localPosition.X( 10 ).Y( 20 ); // var pos = transform.localPosition; // pos.x = 10; // pos.y = 20; // transform.localPosition = pos;
transform.localPosition = transform.localPosition .X( ( x ) => x + 10 ) .Y( ( y ) => y - 20 ) ; // var pos = transform.localPosition; // pos.x += 10; // pos.y -= 20; // transform.localPosition = pos;
Transform
g.transform.parent = transform; g.transform.Identity(); // g.transform.parent = transform; // g.transform.localPosition = Vector3.zero; // g.transform.localRotation = Quaternion.identity; // g.transform.localScale = Vector3.one;
var rep = g.transform.Replicate(); g.transform.parent = transform; g.transform.Restore( rep ); // var lp = g.transform.localPosition; // var ls = g.transform.localScale; // var lr = g.transform.localRotation; // g.transform.parent = transform; // g.transform.localPosition = lp; // g.transform.localScale = ls; // g.transform.localRotation = lr;
g.transform.AutoRestore( () => g.transform.parent = transform ); // var lp = g.transform.localPosition; // var ls = g.transform.localScale; // var lr = g.transform.localRotation; // g.transform.parent = transform; // g.transform.localPosition = lp; // g.transform.localScale = ls; // g.transform.localRotation = lr;
g.transform.LocalPosition( pos => pos.X( 10 ) ); // var pos = g.transform.localPosition; // pos.x = 10; // g.transform.localPosition = pos;
foreach ( var n in transform.Children() ) { } foreach ( var n in transform.Children( true ) ) { }
var d = transform.FindDesendant( "DesendantName" );
Color
var c = 0x112233.Color();
graphics.color = graphics.color.A( 0.5f ); // var col = graphics.color; // col.a = 0.5f; // graphics.color = col;
var hsv = color.HSV();
hsv.s = hsv.s - 0.5f;
var col = hsv.Color();
MonoBehaviour
this.Delay( () => { } ); // 1 フレーム後に実行 this.Delay( 3, () => { } ); // 3 フレーム後に実行 this.Delay( 3f, () => { } ); // 3 秒後に実行
Random
var n = Random.Range( 2f, 3f ).RandomSign();
List
list.Shuffle();
Enumerator
var e = default( IEnumerable<string> ); if ( list.Count > 0 ) { e = list; } else { e = "".Enumerable(); }
var list = g1 .GetComponents<Light>() .AddFirst( g2.GetComponent<Light>() ) ;
var list = g1 .GetComponents<Light>() .AddLast( g2.GetComponent<Light>() ) ;
list.Each( c => { } ); list.EachWithIndex( (c, i ) => { } );
object
g.GetComponents<Light>()
.Where( c => c.intensity > 1 )
.Tap( c => Debug.Log( c.ToList().Count ) )
.Select( c => c.gameObject )
;