public List <CurvyConnection> GetAllConnections(int minMatchesNeeded, params string[] tags) { List <CurvyConnection> res = new List <CurvyConnection>(); CurvyConnection con = Connection; if (con != null && con.MatchingTags(tags).Count >= minMatchesNeeded) { res.Add(con); } for (int i = ConnectedBy.Count - 1; i > -1; i--) { if (ConnectedBy[i].Connection != null) { if (ConnectedBy[i].Connection.Other != this) { ConnectedBy.RemoveAt(i); } else if (ConnectedBy[i].Connection.MatchingTags(tags).Count >= minMatchesNeeded) { res.Add(ConnectedBy[i].Connection); } } else { ConnectedBy.RemoveAt(i); } } return(res); }
void OnHierarchyWindowItemOnGUI(int instanceid, Rect selectionrect) { GameObject obj = EditorUtility.InstanceIDToObject(instanceid) as GameObject; if (obj) { var cp = obj.GetComponent <CurvySplineSegment>(); if (cp) { CurvyConnection con = cp.ConnectionAny; if (con != null) { Color c = GUI.color; switch (con.Sync) { case CurvyConnection.SyncMode.NoSync: GUI.color = new Color(0, 0, 0); break; case CurvyConnection.SyncMode.SyncPosAndRot: GUI.color = new Color(1, 1, 1); break; case CurvyConnection.SyncMode.SyncRot: GUI.color = new Color(1, 1, 0); break; case CurvyConnection.SyncMode.SyncPos: GUI.color = CurvySpline.GizmoColor; break; } GUI.DrawTexture(new Rect(selectionrect.xMax - 14, selectionrect.yMin + 4, 10, 10), mTexSelect); GUI.color = c; } } } if (targets.Length == 1 && Target && Target.gameObject.GetInstanceID() == instanceid) { // Shortcut-Keys Toolbar.ProcessEvents(); } }
void OnHierarchyWindowItemOnGUI(int instanceid, Rect selectionrect) { UnityEngine.GameObject obj = EditorUtility.InstanceIDToObject(instanceid) as UnityEngine.GameObject; if (obj) { var cp = obj.GetComponent <CurvySplineSegment>(); if (cp) { CurvyConnection con = cp.ConnectionAny; if (con != null) { UnityEngine.Color c = GUI.color; switch (con.Sync) { case CurvyConnection.SyncMode.NoSync: GUI.color = new UnityEngine.Color(0, 0, 0); break; case CurvyConnection.SyncMode.SyncPosAndRot: GUI.color = new UnityEngine.Color(1, 1, 1); break; case CurvyConnection.SyncMode.SyncRot: GUI.color = new UnityEngine.Color(1, 1, 0); break; case CurvyConnection.SyncMode.SyncPos: GUI.color = CurvySpline.GizmoColor; break; } GUI.DrawTexture(new Rect(selectionrect.xMax - 14, selectionrect.yMin + 4, 10, 10), mTexSelect); GUI.color = c; } } } }
void OnHierarchyWindowItemOnGUI(int instanceid, Rect selectionrect) { GameObject obj = EditorUtility.InstanceIDToObject(instanceid) as GameObject; if (obj) { var cp = obj.GetComponent <CurvySplineSegment>(); if (cp) { CurvyConnection con = cp.ConnectionAny; if (con != null) { Color c = GUI.color; switch (con.Sync) { case CurvyConnection.SyncMode.NoSync: GUI.color = new Color(0, 0, 0); break; case CurvyConnection.SyncMode.SyncPosAndRot: GUI.color = new Color(1, 1, 1); break; case CurvyConnection.SyncMode.SyncRot: GUI.color = new Color(1, 1, 0); break; case CurvyConnection.SyncMode.SyncPos: GUI.color = CurvySpline.GizmoColor; break; } GUI.DrawTexture(new Rect(selectionrect.xMax - 14, selectionrect.yMin + 4, 10, 10), mTexSelect); GUI.color = c; } } } if (targets.Length == 1 && Target && Target.gameObject.GetInstanceID() == instanceid) { // Shortcut-Keys if (CurvyPreferences.kNext.IsKeyDown(Event.current) && Target.NextControlPoint) { Selection.activeObject = Target.NextControlPoint; } else if (CurvyPreferences.kPrev.IsKeyDown(Event.current) && Target.PreviousControlPoint) { Selection.activeObject = Target.PreviousControlPoint; } else if (CurvyPreferences.kInsertBefore.IsKeyDown(Event.current)) { InsBefore(); } else if (CurvyPreferences.kInsertAfter.IsKeyDown(Event.current)) { InsAfter(); } else if (CurvyPreferences.kDelete.IsKeyDown(Event.current)) { Delete(); EditorGUIUtility.ExitGUI(); } else if (CurvyPreferences.kToggleFreeMove.IsKeyDown(Event.current)) { Target.FreeHandles = !Target.FreeHandles; } } }
/// <summary> /// Returns the connection with the most matching tags /// </summary> /// <param name="connections">one or more connections</param> /// <param name="tags">one or more tags to match</param> /// <returns>the connection with the most matching tag count</returns> public static CurvyConnection GetBestMatchingConnection(List <CurvyConnection> connections, params string[] tags) { CurvyConnection res = null; int maxcount = 0; for (int i = 0; i < connections.Count; i++) { int cnt = connections[i].MatchingTags(tags).Count; if (cnt > maxcount) { maxcount = cnt; res = connections[i]; } } return(res); }
void DoGizmos(bool selected) { if (CurvySpline.Gizmos == CurvySplineGizmos.None) { return; } bool viewCurve = CurvySpline.Gizmos.HasFlag(CurvySplineGizmos.Curve); bool viewNet = CurvySpline.Gizmos.HasFlag(CurvySplineGizmos.Network); // Connections CurvyConnection con = ConnectionAny; if (con != null && (viewCurve || viewNet)) { switch (con.Sync) { case CurvyConnection.SyncMode.NoSync: Gizmos.color = new Color(0, 0, 0, 0.6f); break; case CurvyConnection.SyncMode.SyncPosAndRot: Gizmos.color = new Color(1, 1, 1, 0.6f); break; case CurvyConnection.SyncMode.SyncRot: Gizmos.color = new Color(1, 1, 0, 0.6f); break; case CurvyConnection.SyncMode.SyncPos: Gizmos.color = CurvySpline.GizmoColor; break; } Gizmos.DrawWireSphere(Transform.position, CurvyUtility.GetHandleSize(Transform.position) * CurvySpline.GizmoControlPointSize * 1.4f); } // Control Point if (viewNet) { #if UNITY_EDITOR Gizmos.color = (selected) ? CurvySpline.GizmoSelectionColor : CurvySpline.GizmoColor; Gizmos.DrawSphere(Transform.position, CurvyUtility.GetHandleSize(Transform.position) * 0.7f * CurvySpline.GizmoControlPointSize); #endif } else if (viewCurve) { Gizmos.color = (selected) ? CurvySpline.GizmoSelectionColor : CurvySpline.GizmoColor; Gizmos.DrawSphere(Transform.position, CurvyUtility.GetHandleSize(Transform.position) * 0.7f * CurvySpline.GizmoControlPointSize); } if (!IsValidSegment) { return; } if (viewCurve || viewNet) { Gizmos.color = (selected) ? CurvySpline.GizmoSelectionColor : CurvySpline.GizmoColor; Vector3 p = Transform.position; for (float f = 0.05f; f < 1; f += 0.05f) { Vector3 p1 = Interpolate(f); Gizmos.DrawLine(p, p1); p = p1; } Gizmos.DrawLine(p, NextTransform.position); } if (Approximation.Length > 0 && CurvySpline.Gizmos.HasFlag(CurvySplineGizmos.Approximation)) { Gizmos.color = Color.gray; foreach (Vector3 pa in Approximation) { Gizmos.DrawCube(pa, new Vector3(0.1f, 0.1f, 0.1f)); } } if (Spline.Orientation != CurvyOrientation.None && ApproximationUp.Length > 0 && CurvySpline.Gizmos.HasFlag(CurvySplineGizmos.Orientation)) { Gizmos.color = Color.yellow; for (int i = 0; i < ApproximationUp.Length; i++) { Gizmos.DrawLine(Approximation[i], Approximation[i] + ApproximationUp[i] * CurvySpline.GizmoOrientationLength); } } if (ApproximationT.Length > 0 && CurvySpline.Gizmos.HasFlag(CurvySplineGizmos.Tangents)) { Gizmos.color = new Color(0, 0.7f, 0); for (int i = 0; i < ApproximationT.Length; i++) { Gizmos.DrawLine(Approximation[i], Approximation[i] + ApproximationT[i]); } } }
void DoGizmos(bool selected) { if (!Spline.ShowGizmos) { return; } Gizmos.color = (selected) ? CurvySpline.GizmoSelectionColor : CurvySpline.GizmoColor; float s = CurvyUtility.GetHandleSize(Transform.position) * 0.1f * CurvySpline.GizmoControlPointSize; Gizmos.DrawSphere(Transform.position, s); CurvyConnection con = ConnectionAny; if (con != null) { switch (con.Sync) { case CurvyConnection.SyncMode.NoSync: Gizmos.color = new Color(0, 0, 0, 0.6f); break; case CurvyConnection.SyncMode.SyncPosAndRot: Gizmos.color = new Color(1, 1, 1, 0.6f); break; case CurvyConnection.SyncMode.SyncRot: Gizmos.color = new Color(1, 1, 0, 0.6f); break; case CurvyConnection.SyncMode.SyncPos: Gizmos.color = CurvySpline.GizmoColor; break; } Gizmos.DrawWireSphere(Transform.position, CurvyUtility.GetHandleSize(Transform.position) * 0.3f * CurvySpline.GizmoControlPointSize); } if (!IsValidSegment) { return; } Gizmos.color = (selected) ? CurvySpline.GizmoSelectionColor : CurvySpline.GizmoColor; Vector3 p = Transform.position; for (float f = 0.05f; f < 1; f += 0.05f) { Vector3 p1 = Interpolate(f); Gizmos.DrawLine(p, p1); p = p1; } Gizmos.DrawLine(p, NextTransform.position); if (Spline.ShowApproximation && Approximation.Length > 0) { Gizmos.color = Color.gray; foreach (Vector3 pa in Approximation) { Gizmos.DrawCube(pa, new Vector3(0.1f, 0.1f, 0.1f)); } Vector3 p3 = Approximation[0]; for (int i = 1; i < Approximation.Length; i++) { Vector3 p1 = Approximation[i]; Gizmos.DrawLine(p3, p1); p3 = p1; } } if (Spline.ShowOrientation && Spline.Orientation != CurvyOrientation.None && ApproximationUp.Length > 0) { Gizmos.color = Color.yellow; for (int i = 0; i < ApproximationUp.Length; i++) { Gizmos.DrawLine(Approximation[i], Approximation[i] + ApproximationUp[i] * CurvySpline.GizmoOrientationLength); } } if (Spline.ShowTangents && ApproximationT.Length > 0) { Gizmos.color = new Color(0, 0.7f, 0); for (int i = 0; i < ApproximationT.Length; i++) { Gizmos.DrawLine(Approximation[i], Approximation[i] + ApproximationT[i]); } } }
/// <summary> /// Connect this Control Point to another Control Point or remove an existing connection initiated by this Control Point /// </summary> /// <remarks>Set targetCP to null to remove an existing connection</remarks> /// <param name="targetCP">the Control Point to connect to, or null to release a connection initiated by this Control Point</param> /// <param name="heading">the connection type</param> /// <param name="sync">the connection mode</param> /// <param name="tags">any number of tags to assign to this junction</param> public void ConnectTo(CurvySplineSegment targetCP, CurvyConnection.HeadingMode heading, CurvyConnection.SyncMode sync, params string[] tags) { var con = Connection; if (con!=null) Connection.Disconnect(); if (targetCP) mConnection.Set(this, targetCP, heading, sync, tags); }