初めに
プログラミングしていると「なんでこの機能ないんだろ?」とか「この機能が欲しい」ということが度々行ったりするようにいつもなっているのでそろそろ拡張していきたいと思いました。
ダウンロード先
概要
Unityでの作業を幾分か楽にする目的が作成しました。
拡張機能内容目次
- Extension
- BoolExtension
- ArrayExtension
- ListExtension
- GameObjectExtension
- TransformExtension
- RenderTextuerExtension
- Texture2DExtension
Utils目次
SaveLoadSystem
-
SaveLoadSystem
- Save
- Load
- EncryptionSave
- EncryptionLoad
Extension
//入れ替え処理一部intなどは普通の入れ替えより少し処理速度が速いです。
private void Hoge( string[] array )
{
Extension.Swap(ref sbyte,ref sbyte);
Extension.Swap(ref byte,ref byte);
Extension.Swap(ref short,ref short);
Extension.Swap(ref ushort,ref ushort);
Extension.Swap(ref int,ref int);
Extension.Swap(ref uint,ref uint);
Extension.Swap(ref long,ref long);
Extension.Swap(ref ulong,ref ulong);
Extension.Swap(ref char,ref char);
Extension.Swap(ref float,ref float);
Extension.Swap(ref double,ref double);
Extension.Swap(ref string,ref string);
Extension.Swap<T>(ref T, ref T)where T:UnityEngine.Object;
}
BoolExtension
private void Hoge(bool flag=true)
{
//trueならfalseにfalseならtrue。
flag.Switching();
}
ArrayExtension
private void Hoge<T>(T[] array)
{
//一番先頭の要素を返す。
T t=array.First();
//一番最後の要素を返す。
T t=array.Last();
//大量のソートを行う場合既存のソートより早いです。
QuickSort(int[] array,int left,int right,bool ascending = true);
}
ListExtension
private void Hoge<T>(List<T> list)
{
//一番先頭の要素を返す。
T t=list.First();
//一番最後の要素を返す。
T t=list.Last();
//要素の中にあるnullを削除する
list.RemoveNull();
//要素の中にnullがあればそこに割り振る場合によってはAddする
list.Allocation(T _add,bool _addFlag=false);
}
GameObjectExtension
private void Hoge(GameObject gameObject)
{
//自身のオブジェクトから一番近いオブジェクトを返します
GameObject game=gameObject.GetClosestObjectArray(GameObject[] array);
//自身のオブジェクトから一番近いオブジェクトを返します
game=gameObject.GetClosestObjectList(GameObject[] array);
//自身を破壊
gameObject.Destroy();
//コンポーネントを取得、なければ追加
gameObject.GetOrAddComponent<T>();
//最上層の親オブジェクトを返します。親オブジェクトが存在しない場合自身を返す。
game=gameObject.GetTopParent();
//深い階層まで子オブジェクトを名前で検索します
game=gameObject.GetTopParent(string name,bool includeInactive = false);
//全ての子オブジェクトを返します
GameObject[] games=gameObject.GetChildren(bool includeInactive = false);
//X座標を設定します
gameObject.SetPositionX(float x);
//Y座標を設定します
gameObject.SetPositionY(float y);
//Z座標を設定します
gameObject.SetPositionZ(float z);
//X座標を加算します
gameObject.AddPositionX(int x);
//Y座標を加算します
gameObject.AddPositionY(int y);
//Z座標を加算します
gameObject.AddPositionZ(int z);
//座標を0にリセットします
gameObject.ResetPosition();
}
TransformExtension
private void Hoge(Transform transform)
{
//最上層の親オブジェクトを返します。親オブジェクトが存在しない場合自身を返す。
Transform tr = transform.GetTopParent();
//深い階層まで子オブジェクトを名前で検索します
tr = transform.GetTopParent(string name,bool includeInactive = false);
//全ての子オブジェクトを返します
Transform[] trs=transform.GetChildren(bool includeInactive = false);
//X座標を設定します
transform.SetPositionX(float x);
//Y座標を設定します
transform.SetPositionY(float y);
//Z座標を設定します
transform.SetPositionZ(float z);
//X座標を加算します
transform.AddPositionX(int x);
//Y座標を加算します
transform.AddPositionY(int y);
//Z座標を加算します
transform.AddPositionZ(int z);
//座標を0にリセットします
transform.ResetPosition();
}
RenderTextuerExtension
private void Hoge(RenderTexture rt)
{
//レンダラーテクスチャからテクスチャ2Dを生成する(かなり重たい処理なので使用には注意)
Texture2D tex2D=rt.CreateTexture2D(Camera camera);
}
Texture2DExtension
private void Hoge(Texture2D tex2D)
{
//Texture2DからSpriteを作成
Sprite sprite=tex2D.CreateSprite();
}
GameObjectUtils
private void Hoge()
{
//指定した文字列が含まれているオブジェクトを取得
GameObject[] game=GameObjectUtils.FindContainsName(string name);
}
RandomUtils
private void Hoge()
{
//配列の中の要素をランダムで返す
T t=RandomUtils .RandomArray<T>(T[] array);;
//listの中の要素をランダムで返す
T t=RandomUtils .RandomList<T>(List<T> list);
//ランダムでtrueかfalseを返す
bool flag=RandomUtils .BoolValue();
}
DebugUtils
private void Hoge()
{
//ログを出力
DebugUtils.Log(string message);
DebugUtils.Log(object message, UnityEngine.Object context);
DebugUtils.Log(string message,float size);
DebugUtils.Log(string message, float size, UnityEngine.Object context);
//色を変更してログを出力
DebugUtils.Log(string message, Color color);
DebugUtils.Log(string message, Color color, UnityEngine.Object context);
//サイズと色を変えてログを出力
DebugUtils.Log(string message, float size,Color color);
DebugUtils.Log(string message, float size, Color color, UnityEngine.Object context);
//エラーログを出力します
DebugUtils.LogError(string message);
DebugUtils.LogError(string message, UnityEngine.Object context);
//警告ログを出力します
DebugUtils.LogWarning(string message);
DebugUtils.LogWarning(string message, UnityEngine.Object context);
//配列のログを出します
DebugUtils.ArrayLog(T[] array);
DebugUtils.ArrayLog(T[,] array);
}
SaveLoadSystem
//仮の保存用データ
[Serializable]
private class Date()
{
int a=10;
float b=20f;
}
private void Hoge()
{
Date date=new date();
//セーブ
SaveLoadSystem.Save(date,string fileName,string folderName=SaveFolder);
//ロード
date=(Date)SaveLoadSystem.Load(string fileName,string folderName=SaveFolder);
//暗号化セーブ
SaveLoadSystem.EncryptionSave(date,string fileName,string folderName=SaveFolder);
//暗号化ロード
date=(Date)SaveLoadSystem.EncryptionLoad(string fileName,string folderName=SaveFolder);
//パスワードなどを設定、しなければ初期値でセーブします。
SaveLoadSystem._password = "password";
SaveLoadSystem._salt = "salt ";
}