-
Notifications
You must be signed in to change notification settings - Fork 0
/
Extention.cs
36 lines (35 loc) · 1.18 KB
/
Extention.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
public static class Extention
{
public static T Random<T>(this IList<T> list) =>
list[UnityEngine.Random.Range(0, list.Count)];
public static void AddEvent(this EventTrigger trigger, EventTriggerType eventID, UnityAction<BaseEventData> call)
{
var callback = new EventTrigger.TriggerEvent();
callback.AddListener(call);
trigger.triggers.Add(new EventTrigger.Entry() { eventID = eventID, callback = callback });
}
public static int FindIndex<T>(this IEnumerable<T> group, T element)
{
int i = 0;
foreach (var curElement in group)
if (curElement.Equals(element))
return i;
else i++;
return -1;
}
public static T[] ResizeTo<T>(this T[] source, int length) where T : new()
{
T[] ret = new T[length];
int minSize = Mathf.Min(source.Length, ret.Length);
for (int i = 0; i < minSize; i++)
ret[i] = source[i];
for (int i = minSize; i < length; i++)
ret[i] = new T();
return ret;
}
}