using System; using UnityEngine; namespace PhysicsTools { [Serializable] public class ControlPoint { [Tooltip("Optional: Object")] public GameObject obj; [Tooltip("Position through which rope will pass... If Object is specified then it is the local to the object otherwise it is global position")] public Vector3 localPos; [Range(1f, 5f)] [Tooltip("SlackFraction: How much of the rope length should be created between two control points... If it is more than 1 then a catenary is formed between the control points")] public float slackFraction; [Tooltip("Specify whether it is attached to the control point or not")] public bool attached; public ControlPoint() { obj = null; slackFraction = 1f; attached = true; } public override string ToString() { return ((!(obj != null)) ? "Object: null" : ("Object:" + obj.ToString())) + ", Position: " + localPos.ToString() + ", SlackFraction: " + slackFraction + ", Attached: " + attached; } public bool compare(ControlPoint rhs) { if (obj != rhs.obj || localPos != rhs.localPos || slackFraction != rhs.slackFraction || attached != rhs.attached) { return false; } return true; } public ControlPoint clone() { ControlPoint controlPoint = new ControlPoint(); controlPoint.obj = obj; controlPoint.localPos = localPos; controlPoint.slackFraction = slackFraction; controlPoint.attached = attached; return controlPoint; } public Vector3 globalPos(Rope rope) { if (obj != null) { return obj.transform.TransformPoint(localPos); } return rope.transform.TransformPoint(localPos); } } }