基础内容
必要插件安装 缓动曲线和动画基础 ElementFolder,Track与其次级模块,PathNode重构
This commit is contained in:
73
Assets/Plugins/Dreamteck/Utilities/Randomizer.cs
Normal file
73
Assets/Plugins/Dreamteck/Utilities/Randomizer.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
namespace Dreamteck.Utilities
|
||||
{
|
||||
using UnityEngine;
|
||||
|
||||
public class Randomizer
|
||||
{
|
||||
private int _seed;
|
||||
private System.Random _random;
|
||||
|
||||
public System.Random random => _random;
|
||||
|
||||
public Randomizer(int seed)
|
||||
{
|
||||
_seed = seed;
|
||||
_random = new System.Random(_seed);
|
||||
}
|
||||
|
||||
public float Random01()
|
||||
{
|
||||
return (float)_random.NextDouble();
|
||||
}
|
||||
|
||||
public float Random(float min, float max)
|
||||
{
|
||||
return (float)DMath.Lerp(min, max, _random.NextDouble());
|
||||
}
|
||||
|
||||
public int Random(int min, int max)
|
||||
{
|
||||
return (int)DMath.Lerp(min, max, _random.NextDouble());
|
||||
}
|
||||
|
||||
public Vector2 RandomVector2(float min, float max)
|
||||
{
|
||||
return new Vector2(Random(min, max), Random(min, max));
|
||||
}
|
||||
|
||||
public Vector3 RandomVector3(float min, float max)
|
||||
{
|
||||
return new Vector3(Random(min, max), Random(min, max), Random(min, max));
|
||||
}
|
||||
|
||||
public Vector3 OnUnitSphere()
|
||||
{
|
||||
return Quaternion.Euler(Random(0f, 360f), Random(0f, 360f), Random(0f, 360f)) * Vector3.forward;
|
||||
}
|
||||
|
||||
public Vector3 OnUnitCircle()
|
||||
{
|
||||
return Quaternion.AngleAxis(Random(0f, 360f), Vector3.forward) * Vector3.up;
|
||||
}
|
||||
|
||||
public Vector3 InsideUnitSphere()
|
||||
{
|
||||
return OnUnitSphere() * Random01();
|
||||
}
|
||||
|
||||
public Vector3 InsideUnitCircle()
|
||||
{
|
||||
return OnUnitCircle() * Random01();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_random = new System.Random(_seed);
|
||||
}
|
||||
|
||||
public void Reset(int seed)
|
||||
{
|
||||
_random = new System.Random(seed);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user