42 lines
1.4 KiB
C#
42 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
namespace Assets.Common
|
|
{
|
|
public static class UnityPointExtensions
|
|
{
|
|
public static Vector3 ToVector3(this Point p)
|
|
{
|
|
return new Vector3((float)p.x, 0, (float)p.y);
|
|
}
|
|
}
|
|
|
|
public static class IEnumerableExtensions
|
|
{
|
|
public static T RandomElement<T>(this IEnumerable<T> collection, System.Random generator)
|
|
{
|
|
var count = collection.Count();
|
|
return collection.ElementAt(generator.Next(count));
|
|
}
|
|
|
|
public static IEnumerable<T> RotateRight<T>(this IEnumerable<T> collection, int count = 1)
|
|
{
|
|
var diff = collection.Count() - count;
|
|
|
|
var head = collection.Take(diff);
|
|
var tail = collection.Skip(diff).Take(count);
|
|
|
|
return tail.Concat(head);
|
|
}
|
|
}
|
|
|
|
public static class HasMetadataExtensions
|
|
{
|
|
|
|
public static bool HasProperty(this IHasMetadata subject, string name) => subject.Metadata.HasProperty(name);
|
|
public static bool HasProperty<T>(this IHasMetadata subject, string name) => subject.Metadata.HasProperty<T>(name);
|
|
public static void SetProperty<T>(this IHasMetadata subject, string name, T property) => subject.Metadata.SetProperty(name, property);
|
|
public static T GetProperty<T>(this IHasMetadata subject, string name) => subject.Metadata.GetProperty<T>(name);
|
|
}
|
|
} |