{"id":13786219,"url":"https://github.com/baba-s/kogane-unity-lib","last_synced_at":"2025-08-14T08:05:39.564Z","repository":{"id":110292244,"uuid":"124528196","full_name":"baba-s/kogane-unity-lib","owner":"baba-s","description":"Unity 用の便利な拡張メソッドをまとめた簡易ライブラリ","archived":false,"fork":false,"pushed_at":"2019-11-20T04:36:06.000Z","size":186,"stargazers_count":54,"open_issues_count":1,"forks_count":4,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-24T18:52:27.367Z","etag":null,"topics":["kogane-unity-lib","unity","unity-scripts","unity3d"],"latest_commit_sha":null,"homepage":"http://baba-s.hatenablog.com/entry/2018/03/16/090000","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/baba-s.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-03-09T10:50:32.000Z","updated_at":"2024-12-02T08:32:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"4e2c9c7e-8da1-46b5-bfc0-4c9b0dc84f03","html_url":"https://github.com/baba-s/kogane-unity-lib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baba-s%2Fkogane-unity-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baba-s%2Fkogane-unity-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baba-s%2Fkogane-unity-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baba-s%2Fkogane-unity-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/baba-s","download_url":"https://codeload.github.com/baba-s/kogane-unity-lib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248299026,"owners_count":21080449,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kogane-unity-lib","unity","unity-scripts","unity3d"],"created_at":"2024-08-03T19:01:11.879Z","updated_at":"2025-04-10T21:22:21.669Z","avatar_url":"https://github.com/baba-s.png","language":"C#","readme":"# KoganeUnityLib\n\n「KoganeUnityLib」は便利な拡張メソッドがセットになった簡易ライブラリです  \n\n![](https://img.shields.io/badge/Unity-2018.4%2B-red.svg)\n![](https://img.shields.io/badge/.NET-4.x-orange.svg)\n[![](https://img.shields.io/github/license/baba-s/kogane-unity-lib.svg)](https://github.com/baba-s/kogane-unity-lib/blob/master/LICENSE.md)\n\n# インストール\n\n```json\n\"com.baba_s.kogane_unity_lib\": \"https://github.com/baba-s/kogane-unity-lib.git\",\n```\n\nmanifest.json に上記の記述を追加します  \n\n# 拡張メソッド\n\n## ActionExt\n\n```cs\nprivate void Hoge( Action callback )\n{\n    callback.Call(); // Action を実行。null なら無視\n}\n```\n\n## ArrayExt\n\n```cs\nprivate void Hoge( string[] array )\n{\n    var str = string.Empty;\n    int index = -1;\n\n    var collection = array.AsReadOnly();\n\n    array.Clear();\n\n    str = array.Find( c =\u003e c == \"ピカチュウ\" );\n    str = array.FindLast( c =\u003e c == \"ピカチュウ\" );\n    str = array.First();\n    str = array.Last();\n    str = array.ElementAtRandom();\n\n    index = array.FindIndex( c =\u003e c == \"ピカチュウ\" );\n    index = array.FindLastIndex( c =\u003e c == \"ピカチュウ\" );\n    index = array.IndexOf( \"ピカチュウ\" );\n    index = array.LastIndexOf( \"ピカチュウ\" );\n\n    array = array.FindAll( c =\u003e c == \"ピカチュウ\" );\n    array = array.Reverse();\n    array = array.Shuffle();\n    \n    if ( array.Exists( c =\u003e c == \"ピカチュウ\" ) ) { }\n    if ( array.TrueForAll( c =\u003e c == \"ピカチュウ\" ) ) { }\n\n    array.ForEach( c =\u003e { } );\n    array.Sort( c =\u003e c );\n    array.SortDescending( c =\u003e c );\n}\n```\n\n## BoolExt\n\n```cs\nprivate void Hoge( bool value )\n{\n    var result = value.ToByte(); // byte 型に変換\n}\n```\n\n## ByteExt\n\n```cs\nprivate void Hoge( byte value )\n{\n    var result = value.ToBool(); // bool 型に変換\n\n    Debug.Log( value.ZeroFill( 4 ) ); // 123.ZeroFill( 4 ) → 01234\n}\n```\n\n## ColorExt\n\n```cs\nprivate void Hoge( Color color )\n{\n    Debug.Log( color.EncodeColor() ); // Color.red.EncodeColor() → FF0000\n\n    int num = color.ToInt(); // 16 進数の数値に変換\n}\n```\n\n## ComponentExt\n\n```cs\nprivate void Hoge( Component com )\n{\n    if ( com.HasBeenDestroyed() ) { } // オブジェクトが破棄済みなら true\n    if ( com.HasComponent\u003cRigidbody\u003e() ) { } // コンポーネントがアタッチされていれば true\n    if ( com.HasParent() ) { } // 親が存在する場合 true\n    if ( com.HasChild() ) { } // 子が存在する場合 true\n    if ( com.HasMissingScript() ) { } // 不正なコンポーネントがアタッチされていれば true\n\n    Rigidbody rigidbody = null;\n    rigidbody = com.GetOrAddComponent\u003cRigidbody\u003e(); // コンポーネントを取得もしくはアタッチ\n    rigidbody = com.AddComponent\u003cRigidbody\u003e(); // コンポーネントをアタッチ\n\n    var children = com.GetChildren(); // 子オブジェクトをすべて取得\n\n    // 自分自身を除く指定されたコンポーネントをすべて取得\n    Rigidbody[] rigidbodys = null;\n    rigidbodys = com.GetComponentsInChildrenWithoutSelf\u003cRigidbody\u003e();\n\n    com.RemoveComponent\u003cRigidbody\u003e(); // コンポーネントを削除\n    com.RemoveComponents\u003cRigidbody\u003e(); // コンポーネントをすべて削除\n    com.RemoveComponentImmediate\u003cRigidbody\u003e(); // コンポーネントを削除（エディタ用）\n    com.RemoveComponentsImmediate\u003cRigidbody\u003e(); // コンポーネントをすべて削除（エディタ用）\n\n    com.SetActive( true ); // ゲームオブジェクトのアクティブ設定\n    com.SetParent( cube ); // 親を設定\n    com.LookAt( cube ); // 向きを変更\n\n    GameObject go = null;\n\n    go = com.FindDeep( \"Cube\" ); // 深い階層までゲームオブジェクトを検索\n    go = com.GetParent(); // 親を取得\n    go = com.GetRoot(); // ルートオブジェクトを取得\n\n    var t = com.GetChild( 0 ); // 子を取得\n\n    int layer = com.GetLayer(); // レイヤーを取得\n    com.SetLayer( 0 ); // レイヤーを設定\n    com.SetLayerRecursively( 0 ); // レイヤーを設定（子も対象）\n\n    var vec = Vector3.zero;\n    var x = 0f;\n    var y = 0f;\n    var z = 0f;\n\n    // transform.position を操作\n    com.ResetPosition();\n    vec = com.GetPosition();\n    x = com.GetPositionX();\n    y = com.GetPositionY();\n    z = com.GetPositionZ();\n    com.SetPositionX( 1 );\n    com.SetPositionY( 2 );\n    com.SetPositionZ( 3 );\n    com.SetPosition( 1, 2, 3 );\n    com.SetPosition( new Vector2( 1, 2 ) );\n    com.SetPosition( new Vector3( 1, 2, 3 ) );\n    com.AddPositionX( 1 );\n    com.AddPositionY( 2 );\n    com.AddPositionZ( 3 );\n    com.AddPosition( 1, 2 );\n    com.AddPosition( 1, 2, 3 );\n    com.AddPosition( new Vector2( 1, 2 ) );\n    com.AddPosition( new Vector3( 1, 2, 3 ) );\n\n    // transform.localPositon を操作\n    com.ResetLocalPosition();\n    vec = com.GetLocalPosition();\n    x = com.GetLocalPositionX();\n    y = com.GetLocalPositionY();\n    z = com.GetLocalPositionZ();\n    com.SetLocalPositionX( 1 );\n    com.SetLocalPositionY( 2 );\n    com.SetLocalPositionZ( 3 );\n    com.SetLocalPosition( 1, 2, 3 );\n    com.SetLocalPosition( new Vector2( 1, 2 ) );\n    com.SetLocalPosition( new Vector3( 1, 2, 3 ) );\n    com.AddLocalPositionX( 1 );\n    com.AddLocalPositionY( 2 );\n    com.AddLocalPositionZ( 3 );\n    com.AddLocalPosition( 1, 2 );\n    com.AddLocalPosition( 1, 2, 3 );\n    com.AddLocalPosition( new Vector2( 1, 2 ) );\n    com.AddLocalPosition( new Vector3( 1, 2, 3 ) );\n\n    // transform.localScale を操作\n    com.ResetLocalScale();\n    vec = com.GetLocalScale();\n    x = com.GetLocalScaleX();\n    y = com.GetLocalScaleY();\n    z = com.GetLocalScaleZ();\n    com.SetLocalScaleX( 1 );\n    com.SetLocalScaleY( 2 );\n    com.SetLocalScaleZ( 3 );\n    com.SetLocalScale( 1, 2, 3 );\n    com.SetLocalScale( new Vector2( 1, 2 ) );\n    com.SetLocalScale( new Vector3( 1, 2, 3 ) );\n    com.AddLocalScaleX( 1 );\n    com.AddLocalScaleY( 2 );\n    com.AddLocalScaleZ( 3 );\n    com.AddLocalScale( 1, 2 );\n    com.AddLocalScale( 1, 2, 3 );\n    com.AddLocalScale( new Vector2( 1, 2 ) );\n    com.AddLocalScale( new Vector3( 1, 2, 3 ) );\n\n    // transform.eulerAngles を操作\n    com.ResetEulerAngles();\n    vec = com.GetEulerAngles();\n    x = com.GetEulerAngleX();\n    y = com.GetEulerAngleY();\n    z = com.GetEulerAngleZ();\n    com.SetEulerAngleX( 1 );\n    com.SetEulerAngleY( 2 );\n    com.SetEulerAngleZ( 3 );\n    com.SetEulerAngles( 1, 2, 3 );\n    com.SetEulerAngles( new Vector2( 1, 2 ) );\n    com.SetEulerAngles( new Vector3( 1, 2, 3 ) );\n    com.AddEulerAngleX( 1 );\n    com.AddEulerAngleY( 2 );\n    com.AddEulerAngleZ( 3 );\n\n    // transform.localEulerAngles を操作\n    com.ResetLocalEulerAngles();\n    vec = com.GetLocalEulerAngles();\n    x = com.GetLocalEulerAngleX();\n    y = com.GetLocalEulerAngleY();\n    z = com.GetLocalEulerAngleZ();\n    com.SetLocalEulerAngleX( 1 );\n    com.SetLocalEulerAngleY( 2 );\n    com.SetLocalEulerAngleZ( 3 );\n    com.SetLocalEulerAngles( 1, 2, 3 );\n    com.SetLocalEulerAngles( new Vector2( 1, 2 ) );\n    com.SetLocalEulerAngles( new Vector3( 1, 2, 3 ) );\n    com.AddLocalEulerAngleX( 1 );\n    com.AddLocalEulerAngleY( 2 );\n    com.AddLocalEulerAngleZ( 3 );\n}\n```\n\n## DateTimeExt\n\n```cs\nprivate void Hoge( DateTime dt )\n{\n    Debug.Log( dt.ToPattern() ); // yyyy/MM/dd HH:mm:ss\n    Debug.Log( dt.ToShortDatePattern() ); // yyyy/MM/dd\n    Debug.Log( dt.ToLongDatePattern() ); // yyyy年M月d日\n    Debug.Log( dt.ToFullDateTimePattern() ); // yyyy年M月d日 HH:mm:ss\n    Debug.Log( dt.ToMiddleDateTimePattern() ); // MM/dd HH:mm\n    Debug.Log( dt.ToShortTimePattern() ); // HH:mm\n    Debug.Log( dt.ToLongTimePattern() ); // HH:mm:ss\n}\n```\n\n## DictionaryExt\n\n```cs\nprivate void Hoge( Dictionary\u003cint, string\u003e dict )\n{\n    string str = \"\";\n\n    // 指定されたキーに紐付く値を返す。キーが存在しない場合はデフォルト値を返す\n    str = dict.GetOrDefault( 25 );\n    str = dict.GetOrDefault( 25, \"ピカチュウ\" );\n\n    str = dict.ElementAtRandom(); // ランダムに要素を返す\n\n    var hashtable = dict.ToHashtable(); // Hashtable に変換\n}\n```\n\n## EnumExt\n\n```cs\nprivate void Hoge( JobType type )\n{\n    // 指定されたフラグを含む場合 true\n    if ( type.HasFlag( JobType.SOLDIER | JobType.SORCERER ) ) { }\n}\n```\n\n## FloatExt\n\n```cs\nprivate void Hoge( float value )\n{\n    if ( value.SafeEquals( 25.5f, 0.001f ) ) { } // しきい値を考慮して等しい場合 true\n    if ( value.IsValidated() ) { } // 値が正常なら true\n\n    var result = value.GetValueOrDefault( 10.0f ); // 値が不正ならデフォルト値を返す\n}\n```\n\n## FuncExt\n\n```cs\nprivate void Hoge( Func\u003cbool\u003e callback )\n{\n    \n    if ( callback.Call() ) { } // Func を実行。null なら無視\n    if ( callback.All() ) { } // Func に登録されているすべてのデリゲートが true を返す場合 true\n    if ( callback.Any() ) { } // Func に登録されているいずれかのデリゲートが true を返す場合 true\n}\n```\n\n## GameObjectExt\n\n```cs\nprivate void Hoge( GameObject com )\n{\n    if ( com.HasComponent\u003cRigidbody\u003e() ) { } // コンポーネントがアタッチされていれば true\n    if ( com.HasParent() ) { } // 親が存在する場合 true\n    if ( com.HasChild() ) { } // 子が存在する場合 true\n    if ( com.HasMissingScript() ) { } // 不正なコンポーネントがアタッチされていれば true\n\n    var rigidbody = com.GetOrAddComponent\u003cRigidbody\u003e(); // コンポーネントを取得もしくはアタッチ\n    var children = com.GetChildren(); // 子オブジェクトをすべて取得\n\n    // 自分自身を除く指定されたコンポーネントをすべて取得\n    var rigidbodys = com.GetComponentsInChildrenWithoutSelf\u003cRigidbody\u003e();\n\n    com.RemoveComponent\u003cRigidbody\u003e(); // コンポーネントを削除\n    com.RemoveComponents\u003cRigidbody\u003e(); // コンポーネントをすべて削除\n    com.RemoveComponentImmediate\u003cRigidbody\u003e(); // コンポーネントを削除（エディタ用）\n\n    com.SetParent( cube ); // 親を設定\n    com.LookAt( cube ); // 向きを変更\n\n    GameObject go = null;\n\n    go = com.FindDeep( \"Cube\" ); // 深い階層までゲームオブジェクトを検索\n    go = com.GetParent(); // 親を取得\n    go = com.GetRoot(); // ルートオブジェクトを取得\n\n    var t = com.GetChild( 0 ); // 子を取得\n\n    int layer = com.GetLayer(); // レイヤーを取得\n    com.SetLayer( 0 ); // レイヤーを設定\n    com.SetLayerRecursively( 0 ); // レイヤーを設定（子も対象）\n\n    var vec = Vector3.zero;\n    var x = 0f;\n    var y = 0f;\n    var z = 0f;\n\n    // transform.position を操作\n    com.ResetPosition();\n    vec = com.GetPosition();\n    x = com.GetPositionX();\n    y = com.GetPositionY();\n    z = com.GetPositionZ();\n    com.SetPositionX( 1 );\n    com.SetPositionY( 2 );\n    com.SetPositionZ( 3 );\n    com.SetPosition( 1, 2, 3 );\n    com.SetPosition( new Vector2( 1, 2 ) );\n    com.SetPosition( new Vector3( 1, 2, 3 ) );\n    com.AddPositionX( 1 );\n    com.AddPositionY( 2 );\n    com.AddPositionZ( 3 );\n    com.AddPosition( 1, 2 );\n    com.AddPosition( 1, 2, 3 );\n    com.AddPosition( new Vector2( 1, 2 ) );\n    com.AddPosition( new Vector3( 1, 2, 3 ) );\n\n    // transform.localPositon を操作\n    com.ResetLocalPosition();\n    vec = com.GetLocalPosition();\n    x = com.GetLocalPositionX();\n    y = com.GetLocalPositionY();\n    z = com.GetLocalPositionZ();\n    com.SetLocalPositionX( 1 );\n    com.SetLocalPositionY( 2 );\n    com.SetLocalPositionZ( 3 );\n    com.SetLocalPosition( 1, 2, 3 );\n    com.SetLocalPosition( new Vector2( 1, 2 ) );\n    com.SetLocalPosition( new Vector3( 1, 2, 3 ) );\n    com.AddLocalPositionX( 1 );\n    com.AddLocalPositionY( 2 );\n    com.AddLocalPositionZ( 3 );\n    com.AddLocalPosition( 1, 2 );\n    com.AddLocalPosition( 1, 2, 3 );\n    com.AddLocalPosition( new Vector2( 1, 2 ) );\n    com.AddLocalPosition( new Vector3( 1, 2, 3 ) );\n\n    // transform.localScale を操作\n    com.ResetLocalScale();\n    vec = com.GetLocalScale();\n    x = com.GetLocalScaleX();\n    y = com.GetLocalScaleY();\n    z = com.GetLocalScaleZ();\n    com.SetLocalScaleX( 1 );\n    com.SetLocalScaleY( 2 );\n    com.SetLocalScaleZ( 3 );\n    com.SetLocalScale( 1, 2, 3 );\n    com.SetLocalScale( new Vector2( 1, 2 ) );\n    com.SetLocalScale( new Vector3( 1, 2, 3 ) );\n    com.AddLocalScaleX( 1 );\n    com.AddLocalScaleY( 2 );\n    com.AddLocalScaleZ( 3 );\n    com.AddLocalScale( 1, 2 );\n    com.AddLocalScale( 1, 2, 3 );\n    com.AddLocalScale( new Vector2( 1, 2 ) );\n    com.AddLocalScale( new Vector3( 1, 2, 3 ) );\n\n    // transform.eulerAngles を操作\n    com.ResetEulerAngles();\n    vec = com.GetEulerAngles();\n    x = com.GetEulerAngleX();\n    y = com.GetEulerAngleY();\n    z = com.GetEulerAngleZ();\n    com.SetEulerAngleX( 1 );\n    com.SetEulerAngleY( 2 );\n    com.SetEulerAngleZ( 3 );\n    com.SetEulerAngles( 1, 2, 3 );\n    com.SetEulerAngles( new Vector2( 1, 2 ) );\n    com.SetEulerAngles( new Vector3( 1, 2, 3 ) );\n    com.AddEulerAngleX( 1 );\n    com.AddEulerAngleY( 2 );\n    com.AddEulerAngleZ( 3 );\n\n    // transform.localEulerAngles を操作\n    com.ResetLocalEulerAngles();\n    vec = com.GetLocalEulerAngles();\n    x = com.GetLocalEulerAngleX();\n    y = com.GetLocalEulerAngleY();\n    z = com.GetLocalEulerAngleZ();\n    com.SetLocalEulerAngleX( 1 );\n    com.SetLocalEulerAngleY( 2 );\n    com.SetLocalEulerAngleZ( 3 );\n    com.SetLocalEulerAngles( 1, 2, 3 );\n    com.SetLocalEulerAngles( new Vector2( 1, 2 ) );\n    com.SetLocalEulerAngles( new Vector3( 1, 2, 3 ) );\n    com.AddLocalEulerAngleX( 1 );\n    com.AddLocalEulerAngleY( 2 );\n    com.AddLocalEulerAngleZ( 3 );\n}\n```\n\n## GenericExt\n\n```cs\nprivate void Hoge( int value )\n{\n    if ( value.ContainsAny( 5, 10, 15 ) ) { } // 指定されたいずれかの項目に等しいなら true\n}\n```\n\n## IDisposableExt\n\n```cs\nprivate void Hoge( IDisposable value )\n{\n    // Dispose を実行。null なら無視\n    value.DisposeIfNotNull();\n}\n```\n\n## IEnumerableExt\n\n```cs\nprivate void Hoge( IEnumerable\u003cCharaData\u003e list )\n{\n    CharaData result = null;\n    int num = 0;\n\n    // foreach\n    list.ForEach( c =\u003e { } );\n    list.ForEach( ( val, index ) =\u003e { } );\n\n    if ( list.IsEmpty() ) { } // シーケンスが空なら true\n    if ( list.IsNullOrEmpty() ) { } // シーケンスが null か空なら true\n    if ( list.IsNotNullOrEmpty() ) { } // シーケンスが null でも空でもないなら true\n    if ( list.SequenceEqual( list2, c =\u003e c.id ) ) { } // 指定されたシーケンスと等しい場合 true\n\n    list = list.Pager( 10, 5 ); // list.Skip( 10 * 5 ).Take( 5 )\n    list = list.DefaultIfNull(); // シーケンスが null なら空のシーケンスを返す\n    list = list.NotNull(); // list.Where( c =\u003e c != null )\n    list = list.WhereNot( c =\u003e c.id == 25 ); // 指定された条件を満たさない要素を返す\n    list = list.StartWith( new [] { new CharaData() } ); // シーケンスの先頭に挿入\n    list = list.Concat( list2, list3, list4 ); // シーケンスを連結\n    list = list.Concat( new CharaData() ); // シーケンスを連結\n    list = list.Distinct( c =\u003e c.id ); // 重複削除\n\n    var chunk = list.Chunks( 10 ); // シーケンスを分割\n\n    // 目的の値に最も近い値を持つ要素を返す\n    result = list.FindNearest( 25, c =\u003e c.id ); // 見つからなかったら例外\n    result = list.FindNearestOrDefault( 25, c =\u003e c.id ); // 見つからなかったらデフォルト値を返す\n\n    // 目的の値に最も近く、目的の値より大きい値を持つ要素を返す\n    result = list.FindNearestMoreThan( 25, c =\u003e c.id ); // 見つからなかったら例外\n    result = list.FindNearestMoreThanOrDefault( 25, c =\u003e c.id ); // 見つからなかったらデフォルト値を返す\n\n    // 目的の値に最も近く、目的の値以上の値を持つ要素を返す\n    result = list.FindNearestOrMore( 25, c =\u003e c.id ); // 見つからなかったら例外\n    result = list.FindNearestOrMoreOrDefault( 25, c =\u003e c.id ); // 見つからなかったらデフォルト値を返す\n\n    // 目的の値に最も近く、目的の値以下の値を持つ要素を返す\n    result = list.FindNearestOrLess( 25, c =\u003e c.id ); // 見つからなかったら例外\n    result = list.FindNearestOrLessOrDefault( 25, c =\u003e c.id ); // 見つからなかったらデフォルト値を返す\n\n    // 目的の値に最も近く、目的の値より小さい値を持つ要素を返す\n    result = list.FindNearestMoreLess( 25, c =\u003e c.id ); // 見つからなかったら例外\n    result = list.FindNearestMoreLessOrDefault( 25, c =\u003e c.id ); // 見つからなかったらデフォルト値を返す\n\n    // 目的の値に最も近い値を持つ値を返す\n    num = list.Nearest( 25, c =\u003e c.id ); // 見つからなかったら例外\n    num = list.NearestOrDefault( 25, c =\u003e c.id ); // 見つからなかったらデフォルト値を返す\n\n    // 目的の値に最も近く、目的の値より大きい値を持つ値を返す\n    num = list.NearestMoreThan( 25, c =\u003e c.id ); // 見つからなかったら例外\n    num = list.NearestMoreThanOrDefault( 25, c =\u003e c.id ); // 見つからなかったらデフォルト値を返す\n\n    // 目的の値に最も近く、目的の値以上の値を返す\n    num = list.NearestOrMore( 25, c =\u003e c.id ); // 見つからなかったら例外\n    num = list.NearestOrMoreOrDefault( 25, c =\u003e c.id ); // 見つからなかったらデフォルト値を返す\n\n    // 目的の値に最も近く、目的の値以下の値を返す\n    num = list.NearestOrLess( 25, c =\u003e c.id ); // 見つからなかったら例外\n    num = list.NearestOrLessOrDefault( 25, c =\u003e c.id ); // 見つからなかったらデフォルト値を返す\n\n    // 目的の値に最も近く、目的の値より小さい値を持つ値を返す\n    num = list.NearestMoreLess( 25, c =\u003e c.id ); // 見つからなかったら例外\n    num = list.NearestMoreLessOrDefault( 25, c =\u003e c.id ); // 見つからなかったらデフォルト値を返す\n}\n```\n\n## IListExt\n\n```cs\nprivate void Hoge( IList\u003cCharaData\u003e list )\n{\n    // foreach\n    list.ForEach( c =\u003e { } );\n    list.ForEach( ( val, index ) =\u003e { } );\n    list.ForEachReverse( c =\u003e { } );\n    list.ForEachReverse( ( val, index ) =\u003e { } );\n\n    // 検索\n    result = list.Find( c =\u003e c.name == \"ピカチュウ\" ) );\n    result = list.FindLast( c =\u003e c.name == \"ピカチュウ\" ) );\n    result = list.FindIndex( c =\u003e c.name == \"ピカチュウ\" ) );\n    result = list.FindLastIndex( c =\u003e c.name == \"ピカチュウ\" ) );\n    \n    result = list.ElementAtRandom(); // 要素をランダムに返す\n    result = list.ElementAtOrDefault( 25 ); // 要素を取得。範囲外ならデフォルト値を返す\n    result = list.Dequeue(); // 先頭の要素を返してリストから削除\n\n    result = list.FindMin( c =\u003e c.id ); // 最小値を持つ要素を返す\n    result = list.FindMax( c =\u003e c.id ); // 最大値を持つ要素を返す\n\n    if ( list.IsDefinedAt( 25 ) ) { } // 指定されたインデックスが範囲内なら true\n}\n```\n\n## IntExt\n\n```cs\nprivate void Hoge( int value )\n{\n    // 指定された回数分処理を繰り返す\n    value.Times( () =\u003e { } );\n    value.Times( i =\u003e { } );\n\n    Debug.Log( value.ZeroFill( 4 ) ); // 123.ZeroFill( 4 ) → 01234\n    Debug.Log( value.FixedPoint( 4 ) ); // 123.FixedPoint( 4 ) → 123.0000\n\n    int repeat = value.Repeat( 1, 5 ) // 数値を加算。範囲を超えた分は 0 から処理\n\n    if ( value.IsEven() ) { } // 偶数なら true\n    if ( value.IsOdd() ) { } // 奇数なら true\n}\n```\n\n## ListExt\n\n```cs\nprivate void Hoge( List\u003cstring\u003e list )\n{\n    list.AddRange( \"フシギダネ\", \"フシギソウ\", \"フシギバナ\" ); // 指定されたコレクションを末尾に追加\n    list.Set( \"フシギダネ\", \"フシギソウ\", \"フシギバナ\" ); // 指定されたコレクションで上書き\n    list.Sort( c =\u003e c ) // 指定された要素でソート\n    list.SortDescending( c =\u003e c ) // 指定された要素で逆順にソート\n    list.Shuffle(); // 要素をランダムに並べ替え\n    list.Remove( c =\u003e c.Contains( \"ピ\" ) ); // 指定された条件を満たす要素を削除\n    list.InsertFirst( \"ヒトカゲ\" ); // 指定された要素を先頭に挿入\n    list.RemoveSince( 3 ); // 指定された数になるまで末尾から要素を削除\n}\n```\n\n## MulticastDelegateExt\n\n```cs\nprivate void Hoge( Action callback )\n{\n    // デリゲートの登録数を返す\n    int length1 = callback.GetLength();\n    int length2 = callback.GetLengthIfNotNull();\n\n    if ( callback.IsNullOrEmpty() ) { } // デリゲートが登録されている場合 true\n    if ( callback.IsNotNullOrEmpty() ) { } // デリゲートが登録されていない場合 true\n}\n```\n\n## ObjectExt\n\n```cs\nprivate void Hoge( object obj )\n{\n    Debug.Log( obj.FormatWithComma() ); // 数値を 3 桁区切りの文字列に変換\n}\n```\n\n## RectExt\n\n```cs\nprivate void Hoge( Rect rect )\n{\n    // ずらす\n    rect = rect.Shift( new Vector2( 1, 2 ) );\n    rect = rect.Shift( 1, 2 );\n}\n```\n\n## StringBuilderExt\n\n```cs\nprivate void Hoge( StringBuilder sb )\n{\n    sb.AppendLine( \"{0}/{1}\", 5, 25 ); // AppendLine で書式指定可能\n}\n```\n\n## StringExt\n\n```cs\nprivate void Hoge( string str )\n{\n    // 正規表現\n    if ( str.IsMatch( \".*\" ) ) { } // パターンマッチする場合 true\n    var match = str.Match( \".*\" ); // パターンマッチした箇所の情報を返す\n    var matchCollection = str.Matches( \".*\" ); // パターンマッチした箇所の情報をすべて返す\n    var replaced = str.ReplaceRegex( \".*\", \"$1\" ); // 置換\n\n    Debug.Log( str.FormatWith( 25, \"ピカチュウ\" ) ) // string.Format の拡張メソッド版\n    Debug.Log( texts.ConcatWith( \"\\n\" ) ); // string.Join の拡張メソッド版\n\n    if ( str.IsNullOrEmpty() ) { } // null もしくは空文字列なら true\n    if ( str.IsNotNullOrEmpty() ) { } // null でも空文字列でもないなら true \n    if ( str.IsNullOrWhiteSpace() ) { } // null もしくは空文字列もしくは空白文字のみなら true\n    if ( str.IsNotNullOrWhiteSpace() ) { } // null でも空文字列でも空白文字のみでもないなら true\n\n    // 文字列が null もしくは空文字列ならデフォルト値を返す\n    Debug.Log( str.DefaultIfEmpty( \"ピカチュウ\" ) );\n    Debug.Log( str.DefaultIfWhiteSpace( \"ピカチュウ\" ) );\n\n    var list = str.Split( \"\\n\" ); // 指定された区切り文字で分割して返す\n\n    Debug.Log( str.Limit( 5 ) ); // 指定された長さに制限した文字列を返す\n    Debug.Log( str.ReplaceEmpty( \"ピカチュウ\" ) ); // 指定された文字列を削除\n    Debug.Log( str.AddFront( \"ピカチュウ\" ) ); // 先頭に文字列を挿入\n    Debug.Log( str.ToTitleCase() ) // 先頭文字を大文字に変換\n\n    // スネークケースの文字列をキャメルケースに変換\n    Debug.Log( str.SnakeToUpperCamel() ); // quoted_printable_encode → QuotedPrintableEncode\n    Debug.Log( str.SnakeToLowerCamel() ); // quoted_printable_encode → quotedPrintableEncode\n\n    Debug.Log( str.ToWindowsPath() ); // temp/doc.txt → temp\\\\doc.txt\n    Debug.Log( str.ToMacPath() ); // temp\\\\doc.txt → temp/doc.txt\n\n    int byteCount = str.GetByteCount(); // バイト数を返す\n    Debug.Log( str.SubstringInByte( 5 ) ); // 指定されたバイト単位で部分文字列を返す\n\n    Debug.Log( str.Trim( \"\\n\" ) ); // \\n王国兵士\\n魔法使い\\n → 王国兵士\\n魔法使い\n    Debug.Log( str.TrimEnd( \"\\n\" ) ); // \\n王国兵士\\n魔法使い\\n → \\n王国兵士\\n魔法使い\n    Debug.Log( str.TrimStart( \"\\n\" ) ); // \\n王国兵士\\n魔法使い\\n → 王国兵士\\n魔法使い\\n\n\n    Debug.Log( str.Repeat( 5 ) ); // 指定された回数分繰り返し連結した文字列を返す\n    Debug.Log( str.RemoveNewLine() ); // 改行コードを削除\n\n    if ( str.CompareIgnoreWidthAndCase( \"ABC\") ) { } // 全角半角を無視して比較\n\n    if ( str.IncludeAny(  \"ピカチュウ\", \"カイリュー\" ) ) // いずれかの文字列を含む場合 true\n\n    Debug.Log( str.Coloring( \"ff0000\" ) ); // \u003ccolor={0}\u003estr\u003c/color\u003e\n    Debug.Log( str.Red() ); // \u003ccolor=red\u003estr\u003c/color\u003e\n    Debug.Log( str.Green() ); // \u003ccolor=green\u003estr\u003c/color\u003e\n    Debug.Log( str.Blue() ); // \u003ccolor=blue\u003estr\u003c/color\u003e\n    Debug.Log( str.Resize( 16 ) ); // \u003csize={0}\u003estr\u003c/size\u003e\n    Debug.Log( str.Small() ); // \u003csize=9\u003estr\u003c/size\u003e\n    Debug.Log( str.Medium() ); // \u003csize=11\u003estr\u003c/size\u003e\n    Debug.Log( str.Large() ); // \u003csize=16\u003estr\u003c/size\u003e\n    Debug.Log( str.Bold() ); // \u003cb\u003estr\u003c/b\u003e\n    Debug.Log( str.Italic() ); // \u003ci\u003estr\u003c/i\u003e\n\n    int count = str.CountString( \"ピ\" ); // 指定された文字列の出現回数を返す\n\n    Debug.Log( str.Reduce( \"\\n\", 2 ) ); // あ\\nい\\nう\\nえ\\nお → あいう\\nえ\\nお\n    Debug.Log( str.LastReduce( \"\\n\", 2 ) ); // あ\\nい\\nう\\nえ\\nお → あ\\nい\\nうえお\n\n    Debug.Log( str.ToShiftJis() ); // Unicode から Shift-JIS に変換\n}\n```\n\n## StringParseExt\n\n```cs\nprivate void Hoge( string str )\n{\n    // 文字列と次の型の変換に関する拡張メソッド\n    // sbyte, byte, char, short, ushort, int, uint, long, ulong\n    // float, double, decimal, DateTime, bool, enum\n\n    int i1 = str.ToInt(); // int に変換\n    int? i2 = str.ToIntOrNull(); // int に変換。変換できない場合は null を返す\n    int i3 = str.ToIntOrDefault(); // int に変換。変換できない場合はデフォルト値を返す\n    int i4 = str.ToIntOrDefault( 25 ); // int に変換。変換できない場合はデフォルト値を返す\n    if ( str.IsInt() ) { } // int に変換できる場合 true\n}\n```\n\n## TimeSpanExt\n\n```cs\nprivate void Hoge( TimeSpan ts )\n{\n    // DateTime 型に変換\n    var dateTime = ts.ToDateTime();\n\n    Debug.Log( ts.ToPattern() ); // yyyy/MM/dd HH:mm:ss\n    Debug.Log( ts.ToShortDatePattern() ); // yyyy/MM/dd\n    Debug.Log( ts.ToLongDatePattern() ); // yyyy年M月d日\n    Debug.Log( ts.ToFullDateTimePattern() ); // yyyy年M月d日 HH:mm:ss\n    Debug.Log( ts.ToMiddleDateTimePattern() ); // MM/dd HH:mm\n    Debug.Log( ts.ToShortTimePattern() ); // HH:mm\n    Debug.Log( ts.ToLongTimePattern() ); // HH:mm:ss\n}\n```\n\n## UintExt\n\n```cs\nprivate void Hoge( uint value )\n{\n    // 指定された回数分処理を繰り返す\n    value.Times( () =\u003e { } );\n    value.Times( i =\u003e { } );\n\n    Debug.Log( value.ZeroFill( 4 ) ); // 123.ZeroFill( 4 ) → 01234\n}\n```\n\n## Vector3Ext\n\n```cs\nprivate void Hoge( Vector3 v )\n{\n    if ( v.IsUniform() ) { } // x, y, z の値が等しい場合 true\n}\n```\n\n## WWWExt\n\n```cs\nprivate void Hoge( WWW www )\n{\n    if ( www.IsError() ) { }\n\n    if ( www.IsNotError() ) { }\n}\n```\n\n# 便利クラス\n\n## CoroutineUtils\n\n```cs\nCoroutineUtils.CallWaitForCondition( () =\u003e IsOn, () =\u003e { } ); // 条件を満たしたらデリゲートを実行\nCoroutineUtils.CallWaitForEndOfFrame( () =\u003e { } ); // 1 フレーム後にデリゲートを実行\nCoroutineUtils.CallWaitForSeconds( 1f, () =\u003e { } ); // 指定秒後にデリゲートを実行\nCoroutineUtils.StartCoroutine( Hoge() ); // 指定されたコルーチンを実行\n```\n\n## MultiDictionary\n\n```cs\nvar m = new MultiDictionary\u003cstring, string\u003e();\n\nm.Add( \"ほのお\", \"ヒトカゲ\" );\nm.Add( \"ほのお\", \"リザード\" );\nm.Add( \"ほのお\", \"リザードン\" );\nm.Add( \"でんき\", \"ピカチュウ\", \"ライチュウ\" );\n\nm.Remove( \"でんき\", \"ライチュウ\" );\nm.Remove( \"ほのお\" );\n\nm.Clear();\n\nif ( m.Contains( \"でんき\", \"ピカチュウ\" ) )\n{\n}\n\nif ( m.ContainsKey( \"でんき\" ) )\n{\n}\n\nforeach ( var pair in m )\n{\n    foreach ( var n in pair.Value )\n    {\n        Debug.Log( pair.Key + \": \" + n );\n    }\n}\n\nforeach ( var key in m.Keys )\n{\n    Debug.Log( key );\n}\n\nforeach ( var value in m.Values )\n{\n    foreach ( var n in value )\n    {\n        Debug.Log( n );\n    }\n}\n\nDebug.Log( m.Count );\n```\n\n## MultiTask\n\n```cs\nvar task = new MultiTask();\n\ntask.Add( onEnded =\u003e\n{\n    Debug.Log( \"1\" );\n    onEnded();\n} );\n\ntask.Add( onEnded =\u003e\n{\n    Debug.Log( \"2\" );\n    onEnded();\n} );\n\ntask.Add( onEnded =\u003e\n{\n    Debug.Log( \"3\" );\n    onEnded();\n} );\n\ntask.Play( () =\u003e\n{\n    Debug.Log( \"completed\" );\n} );\n```\n\n## SingleTask\n\n```cs\nvar task = new SingleTask();\n\ntask.Add( onEnded =\u003e\n{\n    Debug.Log( \"1\" );\n    onEnded();\n} );\n\ntask.Add( onEnded =\u003e\n{\n    Debug.Log( \"2\" );\n    onEnded();\n} );\n\ntask.Add( onEnded =\u003e\n{\n    Debug.Log( \"3\" );\n    onEnded();\n} );\n\ntask.Play( () =\u003e\n{\n    Debug.Log( \"completed\" );\n} );\n```\n\n## ColorUtils\n\n```cs\nDebug.Log( ColorUtils.DecimalToHex( 1234) ); // 1234.DecimalToHex() → 0004D2\n\ncolor = ColorUtils.ToARGB( 0xFFFF8000 ); // RGBA(1.000, 0.502, 0.000, 1.000)\ncolor = ColorUtils.ToRGBA( 0xFF8000FF ); // RGBA(1.000, 0.502, 0.000, 1.000)\ncolor = ColorUtils.ToRGB( 0xFF8000 ); // RGBA(1.000, 0.502, 0.000, 1.000)\n```\n\n## DebugUtils\n\n```cs\n// DEBUG_LOG が定義されている場合にのみ出力\nDebugUtils.Log( \"ピカチュウ\" );\nDebugUtils.LogFormat( \"{0}\", \"ピカチュウ\" );\nDebugUtils.Warning( \"ピカチュウ\" );\nDebugUtils.WarningFormat( \"{0}\", \"ピカチュウ\" );\nDebugUtils.Error( \"ピカチュウ\" );\nDebugUtils.ErrorFormat( \"{0}\", \"ピカチュウ\" );\n```\n\n## EnumerableUtils\n\n```cs\n// var list = Enumerable.Range( 0, 10 );\nvar list = EnumerableUtils.Range( 10 );\n```\n\n## EnumUtils\n\n```cs\nPARAM_TYPE type = 0;\n\ntype = EnumUtils.RandomAt( PARAM_TYPE.FIRE, PARAM_TYPE.AQUA ); // ランダムに返す\ntype = EnumUtils.Random\u003cPARAM_TYPE\u003e(); // ランダムに返す\ntype = EnumUtils.Parse\u003cPARAM_TYPE\u003e( \"FIRE\" ); // 文字列を列挙型に変換\n\nint length = EnumUtils.GetLength\u003cPARAM_TYPE\u003e(); // 列挙型の要素数を取得\nvar list = EnumUtils.GetValues\u003cPARAM_TYPE\u003e(); // 列挙型の要素をすべて取得\n\nif ( EnumUtils.IsEnum\u003cPARAM_TYPE\u003e( \"FIRE\" ) ) { } // 文字列を列挙型に変換できるなら true\n```\n\n## GameObjectUtils\n\n```cs\nif ( GameObjectUtils.Exists( \"Cube\" ) ) { } // 指定した名前のオブジェクトが存在する場合 true\n```\n\n## RandomUtils\n\n```cs\nDebug.Log( RandomUtils.Value ); // 0.0 から 1.0 の浮動小数点数をランダムに返す\nDebug.Log( RandomUtils.BoolValue ); // true か false を返す\nDebug.Log( RandomUtils.Flag ); // 1 か 0 を返す\nDebug.Log( RandomUtils.Range( 10 ) ); // 0 から max - 1 を返す\n```\n\n## StringUtils\n\n```cs\n// string.Format よりも GC Alloc が発生しない\nDebug.Log( StringUtils.Format( \"{0}/{1}\", 5, 25) );\n\n// string.Join で IEnumerable\u003cT\u003e を指定できる\nDebug.Log( StringUtils.Join( \"\\n\", texts ) );\n\n// 文字が全角なら true\nif ( StringUtils.IsChar2Byte( 'A' ) ) { }\n```\n","funding_links":[],"categories":["Extension Methods"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaba-s%2Fkogane-unity-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaba-s%2Fkogane-unity-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaba-s%2Fkogane-unity-lib/lists"}