89 lines
2.5 KiB
C#
89 lines
2.5 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public enum FishingLineNodeType
|
|
{
|
|
Start,
|
|
Float,
|
|
Weight,
|
|
Terminal,
|
|
Normal
|
|
}
|
|
|
|
public class FishingLineNode : MonoBehaviour
|
|
{
|
|
[SerializeField] private string nodeId = "Node";
|
|
[SerializeField] private FishingLineNodeType nodeType = FishingLineNodeType.Normal;
|
|
[SerializeField] [Min(0f)] private float distanceFromPrevious = 0f;
|
|
[SerializeField] [Min(0)] private int virtualNodeCount = 3;
|
|
[SerializeField] [Min(0f)] private float gravityScale = 1f;
|
|
[SerializeField] [Range(0f, 1f)] private float damping = 0.04f;
|
|
[SerializeField] private bool alignToLine = true;
|
|
[SerializeField] private Vector3 localForwardAxis = Vector3.forward;
|
|
[SerializeField] private Vector3 upAxis = Vector3.up;
|
|
[SerializeField] private Color debugColor = Color.white;
|
|
|
|
private readonly List<FishingLineNodeBehaviour> behaviours = new List<FishingLineNodeBehaviour>();
|
|
|
|
public string NodeId => nodeId;
|
|
public FishingLineNodeType NodeType => nodeType;
|
|
public int VirtualNodeCount => virtualNodeCount;
|
|
public float GravityScale => gravityScale;
|
|
public float Damping => damping;
|
|
public bool AlignToLine => alignToLine;
|
|
public Vector3 LocalForwardAxis => localForwardAxis;
|
|
public Vector3 UpAxis => upAxis;
|
|
public Color DebugColor => debugColor;
|
|
public IReadOnlyList<FishingLineNodeBehaviour> Behaviours => behaviours;
|
|
|
|
private void Reset()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(nodeId))
|
|
{
|
|
nodeId = gameObject.name;
|
|
}
|
|
|
|
RefreshBehaviours();
|
|
}
|
|
|
|
private void OnValidate()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(nodeId))
|
|
{
|
|
nodeId = gameObject.name;
|
|
}
|
|
}
|
|
|
|
[ContextMenu("Refresh Node Behaviours")]
|
|
public void RefreshBehaviours()
|
|
{
|
|
behaviours.Clear();
|
|
FishingLineNodeBehaviour[] found = GetComponents<FishingLineNodeBehaviour>();
|
|
for (int index = 0; index < found.Length; index++)
|
|
{
|
|
FishingLineNodeBehaviour behaviour = found[index];
|
|
if (behaviour == null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
behaviours.Add(behaviour);
|
|
}
|
|
}
|
|
|
|
public float ResolveDistanceFromPrevious(FishingLineNode previousNode)
|
|
{
|
|
if (distanceFromPrevious > 0f)
|
|
{
|
|
return distanceFromPrevious;
|
|
}
|
|
|
|
if (previousNode == null)
|
|
{
|
|
return 0f;
|
|
}
|
|
|
|
return Vector3.Distance(previousNode.transform.position, transform.position);
|
|
}
|
|
}
|