init
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VOID.Generic.Trajectory
|
||||
{
|
||||
[Serializable]
|
||||
public abstract class AbstractTrajectory
|
||||
{
|
||||
public Vector3 startPosition { get; protected set; }
|
||||
public Vector3 endPosition { get; protected set; }
|
||||
public float lineDistance { get; protected set; }
|
||||
public float trajectoryDistance { get; protected set; }
|
||||
|
||||
public AbstractTrajectory Clone()
|
||||
{
|
||||
return MemberwiseClone() as AbstractTrajectory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize (again) whole trajectory.
|
||||
/// </summary>
|
||||
public void Init(Vector3 startPosition, Vector3 endPosition)
|
||||
{
|
||||
this.startPosition = startPosition;
|
||||
this.endPosition = endPosition;
|
||||
lineDistance = Vector3.Distance(startPosition, endPosition);
|
||||
trajectoryDistance = lineDistance;
|
||||
|
||||
OnInit();
|
||||
}
|
||||
|
||||
/// <returns>Position on trajectory, by given distance (in line)</returns>
|
||||
public Vector3 GetPositionByDistance(float distance)
|
||||
{
|
||||
return GetPositionByProgress(GetProgressForDistance(distance));
|
||||
}
|
||||
|
||||
/// <returns>Progress (0-1) to end position, by given distance (in line)</returns>
|
||||
public virtual float GetProgressForDistance(float currentDistance)
|
||||
{
|
||||
return Mathf.Clamp01(currentDistance / lineDistance);
|
||||
}
|
||||
|
||||
/// <returns>Whole trajectory path with given number of points</returns>
|
||||
public Vector3[] GetPositions(int count)
|
||||
{
|
||||
var positions = new Vector3[count];
|
||||
var step = 1f / (count-1);
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
positions[i] = GetPositionByProgress(i * step);
|
||||
|
||||
return positions;
|
||||
}
|
||||
|
||||
protected abstract void OnInit();
|
||||
public abstract Vector3 GetPositionByProgress(float progress);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3edb500d8efe409081dbdc880e24a4b6
|
||||
timeCreated: 1668803266
|
||||
@@ -0,0 +1,23 @@
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VOID.Generic.Trajectory
|
||||
{
|
||||
[TypeRegistryItem("Instant")]
|
||||
public sealed class InstantTrajectory : AbstractTrajectory
|
||||
{
|
||||
protected override void OnInit()
|
||||
{
|
||||
}
|
||||
|
||||
public override float GetProgressForDistance(float currentDistance)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public override Vector3 GetPositionByProgress(float progress)
|
||||
{
|
||||
return endPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7ea6d38e9d104d4bab987c6c9b57fbbe
|
||||
timeCreated: 1668803559
|
||||
@@ -0,0 +1,18 @@
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VOID.Generic.Trajectory
|
||||
{
|
||||
[TypeRegistryItem("Line")]
|
||||
public sealed class LineTrajectory : AbstractTrajectory
|
||||
{
|
||||
protected override void OnInit()
|
||||
{
|
||||
}
|
||||
|
||||
public override Vector3 GetPositionByProgress(float progress)
|
||||
{
|
||||
return Vector3.Lerp(startPosition, endPosition, Mathf.Clamp01(progress));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cfb3d5c302a45e7bc016b0a3b46e5f3
|
||||
timeCreated: 1668806204
|
||||
@@ -0,0 +1,24 @@
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VOID.Generic.Trajectory
|
||||
{
|
||||
[TypeRegistryItem("Parabolic")]
|
||||
public sealed class ParabolicTrajectory : AbstractTrajectory
|
||||
{
|
||||
[SerializeField, Required, MinValue(0)]
|
||||
public float height;
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
if (height > 0f) trajectoryDistance = Mathf.PI*Mathf.Sqrt(Mathf.Pow(lineDistance/2,2)*Mathf.Pow(height,2)/2);
|
||||
}
|
||||
|
||||
public override Vector3 GetPositionByProgress(float progress)
|
||||
{
|
||||
var result = Vector3.Lerp(startPosition, endPosition, Mathf.Clamp01(progress));
|
||||
result.y += Mathf.Sin(progress * Mathf.PI) * height;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb6f5514ee554e78b83f0ca8794c5a01
|
||||
timeCreated: 1668807114
|
||||
Reference in New Issue
Block a user