using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace MyFrameworkPure
{
    /// 
    /// 集合工具类
    /// 
    public class CollectionsTool
    {
        /// 
        /// 合并两个数组
        /// 
        /// 
        /// 
        /// 
        /// 
        public static T[] Merge(T[] arr, T[] other)
        {
            T[] buffer = new T[arr.Length + other.Length];
            arr.CopyTo(buffer, 0);
            other.CopyTo(buffer, arr.Length);
            return buffer;
        }
        /// 
        /// 合并多个数组
        /// 
        /// 
        /// 
        /// 
        public static T[] MergerArray(params T[][] arrays)
        {
            List list = new List();
            foreach (var array in arrays)
            {
                list.AddRange(array);
            }
            return list.ToArray();
        }
        /// 
        /// 从数组中随机取出若干个元素,重新组成数组;
        /// 
        /// 
        /// 
        /// 
        /// 
        public static T[] GetRandomArray(T[] array,int length)
        {
            if (array.Length < length)
                return null;
            List temp = new List(array);
            T[] finalArray = new T[length];
            for(int i = 0;i< finalArray.Length;i++)
            {
                int randomValue = Random.Range(0, temp.Count);
                finalArray[i] = temp[randomValue];
                temp.RemoveAt(randomValue);
            }
            return finalArray;
        }
        /// 
        /// 比较两个数组是否相同
        /// 
        /// 
        /// 
        /// 
        /// 
        public static bool EqualArray(T[] first, T[] second)
        {
            return first.SequenceEqual(second);
        }
    }
}