63 lines
1.2 KiB
C#
63 lines
1.2 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace BitStrap.Examples
|
|
{
|
|
public class VectorHelperExample : MonoBehaviour
|
|
{
|
|
[Header("Edit the fields and look at the checkboxes below!", order = 1)]
|
|
public Vector2 vector = new Vector2(1E-05f, 0f);
|
|
|
|
[Range(0f, 360f)]
|
|
public float vectorAAngle;
|
|
|
|
[Range(0f, 360f)]
|
|
public float vectorBAngle = 90f;
|
|
|
|
[Range(0f, 360f)]
|
|
public float vectorCAngle = 45f;
|
|
|
|
[ReadOnly]
|
|
public Vector2 vectorA = Vector2.zero;
|
|
|
|
[ReadOnly]
|
|
public Vector2 vectorB = Vector2.zero;
|
|
|
|
[ReadOnly]
|
|
public Vector2 vectorC = Vector2.zero;
|
|
|
|
public bool IsVectorZero()
|
|
{
|
|
return vector.IsZero();
|
|
}
|
|
|
|
public bool IsVectorCBetweenVectorsAAndB()
|
|
{
|
|
return VectorHelper.IsBetweenVectors(vectorC, vectorA, vectorB);
|
|
}
|
|
|
|
public bool IsVectorCOnTheSameSideAsVectorBInRelationToA()
|
|
{
|
|
return VectorHelper.IsOnVectorSide(vectorC, vectorA, vectorB);
|
|
}
|
|
|
|
public void OnValidate()
|
|
{
|
|
SetVector(ref vectorA, vectorAAngle);
|
|
SetVector(ref vectorB, vectorBAngle);
|
|
SetVector(ref vectorC, vectorCAngle);
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
OnValidate();
|
|
}
|
|
|
|
private void SetVector(ref Vector2 vector, float degrees)
|
|
{
|
|
float f = degrees * ((float)Math.PI / 180f);
|
|
vector = new Vector2(Mathf.Cos(f), Mathf.Sin(f));
|
|
}
|
|
}
|
|
}
|