Here I have collected a large number of convenient and useful methods for faster use within Unity. Below will be described, in my opinion, the most interesting and requiring explanations.
There is two windows :
The select method, accepts the Func and returns the first item of collection suitable for the condition
void MyFoo(int[] array)
{
array.Select((x) => x % 2 == 0).Print(); //Method Print use the Debug.Log for display value in console
}
void MyFoo(int[] array)
{
array.Replace(2,100);//First `2` value in collection will be replaced to `1000`
array.Swap(100, 50); //Value 100 will be replaced by 50 will be replaced by previous position 100
}
void MyFoo(GameObject[] array)
{
array.AllDo((item) => item.Destroy(2)); // Destroy all GameObjects from array in 2 seconds
}
Now the methods are directly related to Unity, first is WaitAndDo, works with local coroutine, can be calld from every object Inherited from UnityEngine.Object
void MyFoo(GameObject someObj)
{
bool flag = false;
this.WaitAndDo(2, (currentObj) => flag = true ); //after 2 seconds flag will become true
someObj.WaitAndDo(5, (item) => item.transform.position = Vector3.Zero);
}
void MyFoo(GameObject someObj)
{
var objectArray = someObj.ToArray(new GameObject(), new GameObject()); // Take params for the new objects
}
void Update()
{
_rigidobdy.AutoControl2D(_speed, _jumpForce, KeyCode.Space, MovingType2D.Platformer); // Must be called only in Update
}
[SerializeField] private List<Transform> _traectory, _polygonTest;
[SerializeField] private Transform _bezierObject, _movableObject;
void Update()
{
if (_time < 1) _time += 0.01f;
else _time = 0;
_bezierObject.MoveByCurve(_traectory, _time);
_movableObject.MoveByPolygon(_polygonTest, _time, true);
}
Use this for create usefull multi-type collections and comfort work with them
public void MyFoo()
{
var array = new MTPArray() {123, "string value", 125f};
array.GetAll<int>().First().value.Print(); //Console output 123
}
Save system can save the default type and custom serializeble classes. Also system have an extentions
public void TestSave()
{
int value = 100;
value.Save("intValue");
var savedValue = value.Load("intValue");
}
public void SaveCollection()
{
int[] saveArray = new int[] {10,20,30};
saveArray.Save("saveArray");
var array = HelperPrefs.GetCollection("saveArray", SaveTypes.Int);
}