private void UpdateMaterial() { if (m_renderer != null) { SplineRuntimeEditor runtimeEditor = SplineRuntimeEditor.Instance; if (runtimeEditor != null) { if (m_index % 3 == 0) { m_renderer.sharedMaterial = runtimeEditor.NormalMaterial; } else { if (m_index >= m_spline.ControlPointCount) { return; } ControlPointMode mode = m_spline.GetControlPointMode(m_index); if (mode == ControlPointMode.Mirrored) { m_renderer.sharedMaterial = runtimeEditor.MirroredModeMaterial; } else if (mode == ControlPointMode.Aligned) { m_renderer.sharedMaterial = runtimeEditor.AlignedModeMaterial; } else { m_renderer.sharedMaterial = runtimeEditor.FreeModeMaterial; } } } } }
private void DrawSelectedPointInspector() { if (DrawSelectedPointInspectorOverride()) { EditorGUI.BeginChangeCheck(); ControlPointMode mode = (ControlPointMode) EditorGUILayout.EnumPopup("Mode", m_splineBase.GetControlPointMode(m_selectedIndex)); if (EditorGUI.EndChangeCheck()) { SetMode(m_splineBase, mode, m_selectedIndex); } EditorGUI.BeginChangeCheck(); int index = m_selectedIndex; bool isLast = (m_selectedIndex + 1) / 3 == m_splineBase.CurveCount; Twist twist = m_splineBase.GetTwist(index); EditorGUI.BeginChangeCheck(); float twistAngle = EditorGUILayout.FloatField("Twist Angle", twist.Data); if (EditorGUI.EndChangeCheck()) { SetTwistAngle(m_splineBase, index, twistAngle); } if (m_splineBase.Loop || !isLast || m_splineBase.HasBranches(m_selectedIndex)) { float t1 = twist.T1; float t2 = twist.T2; EditorGUI.BeginChangeCheck(); EditorGUILayout.MinMaxSlider(new GUIContent("Twist Offset"), ref t1, ref t2, 0.0f, 1.0f); if (EditorGUI.EndChangeCheck()) { SetTwistOffset(m_splineBase, index, t1, t2); } } Thickness thickness = m_splineBase.GetThickness(index); EditorGUI.BeginChangeCheck(); Vector3 thicknessValue = EditorGUILayout.Vector3Field("Thickness", thickness.Data); if (EditorGUI.EndChangeCheck()) { SetThickness(m_splineBase, index, thicknessValue); } if (m_splineBase.Loop || !isLast || m_splineBase.HasBranches(m_selectedIndex)) { float t1 = thickness.T1; float t2 = thickness.T2; EditorGUI.BeginChangeCheck(); EditorGUILayout.MinMaxSlider(new GUIContent("Thickness Offset"), ref t1, ref t2, 0.0f, 1.0f); if (EditorGUI.EndChangeCheck()) { SetThicknessOffset(m_splineBase, index, t1, t2); } } } else { EditorGUI.BeginChangeCheck(); int index = m_selectedIndex; Twist twist = m_splineBase.GetTwist(index); EditorGUI.BeginChangeCheck(); float twistAngle = EditorGUILayout.FloatField("Twist Angle", twist.Data); if (EditorGUI.EndChangeCheck()) { SetTwistAngle(m_splineBase, index, twistAngle); } Thickness thickness = m_splineBase.GetThickness(index); EditorGUI.BeginChangeCheck(); Vector3 thicknessValue = EditorGUILayout.Vector3Field("Thickness", thickness.Data); if (EditorGUI.EndChangeCheck()) { SetThickness(m_splineBase, index, thicknessValue); } } }
private void ShowPoint(SplineBase spline, int index, Vector3 point, Quaternion handleRotation) { if (!CanShowPoint(index)) { return; } bool hasBranches = spline.HasBranches(index); Handles.color = ModeColors[(int)spline.GetControlPointMode(index)]; if (index % 3 == 0) { if (hasBranches) { Handles.color = m_branchColor; } else { Handles.color = Color.green; } } float size = HandleUtility.GetHandleSize(point); Handles.CapFunction dcf = Handles.DotHandleCap; if (index == 0) { if (!hasBranches) { size *= 1.5f; } } if (Handles.Button(point, handleRotation, size * HandleSize, size * PickSize, dcf)) { SplineBase unselectedSpline = m_selectedSpline; m_selectedSpline = spline; int unselectedIndex = m_selectedIndex; m_selectedIndex = index; if (OnControlPointClick(unselectedIndex, m_selectedIndex)) { SplineControlPoint controlPoint = spline.GetSplineControlPoints().Where(cpt => cpt.Index == index).FirstOrDefault(); if (controlPoint != null) { Selection.activeGameObject = controlPoint.gameObject; } } else { m_selectedIndex = unselectedIndex; m_selectedSpline = unselectedSpline; } Repaint(); } if (m_selectedIndex == index && spline == m_splineBase) { ShowLengths(spline, index, true); } ShowPointOverride(spline, index, point, handleRotation, size); }
private void ShowPoint(int index, Vector3 point) { if (!CanShowPoint(index)) { return; } Handles.color = ModeColors[(int)m_splineBase.GetControlPointMode(index)]; if (index % 3 == 0) { Handles.color = Color.green; } float size = HandleUtility.GetHandleSize(point); Handles.CapFunction dcf = Handles.DotHandleCap; if (index == 0) { size *= 2f; } if (Handles.Button(point, m_handleRotation, size * HandleSize, size * PickSize, dcf)) { m_selectedIndex = index; SplineControlPoint controlPoint = m_splineBase.GetComponentsInChildren <SplineControlPoint>(true).Where(cpt => cpt.Index == index).FirstOrDefault(); if (controlPoint != null) { if (Event.current.control || Event.current.shift) { GameObject[] objects = Selection.gameObjects; Selection.activeGameObject = controlPoint.gameObject; if (!objects.Contains(controlPoint.gameObject)) { ArrayUtility.Add(ref objects, controlPoint.gameObject); } else { if (!Event.current.shift) { ArrayUtility.Remove(ref objects, controlPoint.gameObject); } } Selection.objects = objects; } else { Selection.activeGameObject = controlPoint.gameObject; } } Repaint(); } if (m_selectedIndex == index) { int curveIndex = (m_selectedIndex - 1) / 3; int prevCurveIndex = curveIndex - 1; int nextCurveIndex = curveIndex + 1; if (m_splineBase.Loop) { if (prevCurveIndex < 0) { prevCurveIndex = m_splineBase.CurveCount - 1; } if (nextCurveIndex > m_splineBase.CurveCount - 1) { nextCurveIndex = 0; } } GUIStyle style = new GUIStyle(); style.normal.textColor = Color.green; if (prevCurveIndex >= 0) { float prevLen = m_splineBase.EvalLength(prevCurveIndex); float prevCur = m_splineBase.EvalCurveLength(prevCurveIndex, GetStepsPerCurve()); Handles.Label(m_splineBase.GetPoint(0.5f, prevCurveIndex), string.Format("Len: {0:0.00} m, Cur: {1:0.00} m", prevLen, prevCur), style); } if (nextCurveIndex < m_splineBase.CurveCount) { float nextLen = m_splineBase.EvalLength(nextCurveIndex); float nextCur = m_splineBase.EvalCurveLength(nextCurveIndex, GetStepsPerCurve()); Handles.Label(m_splineBase.GetPoint(0.5f, nextCurveIndex), string.Format("Len: {0:0.00} m, Cur: {1:0.00} m", nextLen, nextCur), style); } float cur = m_splineBase.EvalCurveLength(curveIndex, GetStepsPerCurve()); float len = m_splineBase.EvalLength(curveIndex); Handles.Label(m_splineBase.GetPoint(0.5f, curveIndex), string.Format("Len: {0:0.00} m, Cur: {1:0.00} m", len, cur), style); } }
private void ShowPoint(int index, Vector3 point) { if (!CanShowPoint(index)) { return; } Handles.color = ModeColors[(int)m_splineBase.GetControlPointMode(index)]; if (index % 3 == 0) { Handles.color = Color.green; } float size = HandleUtility.GetHandleSize(point); Handles.DrawCapFunction dcf = Handles.DotCap; if (index == 0) { size *= 2f; } if (Handles.Button(point, m_handleRotation, size * HandleSize, size * PickSize, dcf)) { m_selectedIndex = index; SplineControlPoint controlPoint = m_splineBase.GetComponentsInChildren <SplineControlPoint>(true).Where(cpt => cpt.Index == index).FirstOrDefault(); if (controlPoint != null) { Selection.activeGameObject = controlPoint.gameObject; } Repaint(); } if (m_selectedIndex == index) { int curveIndex = (m_selectedIndex - 1) / 3; int prevCurveIndex = curveIndex - 1; int nextCurveIndex = curveIndex + 1; if (m_splineBase.Loop) { if (prevCurveIndex < 0) { prevCurveIndex = m_splineBase.CurveCount - 1; } if (nextCurveIndex > m_splineBase.CurveCount - 1) { nextCurveIndex = 0; } } GUIStyle style = new GUIStyle(); style.normal.textColor = Color.green; if (prevCurveIndex >= 0) { float prevLen = m_splineBase.EvalLength(prevCurveIndex); float prevCur = m_splineBase.EvalCurveLength(prevCurveIndex, GetStepsPerCurve()); Handles.Label(m_splineBase.GetPoint(0.5f, prevCurveIndex), string.Format("Len: {0:0.00} m, Cur: {1:0.00} m", prevLen, prevCur), style); } if (nextCurveIndex < m_splineBase.CurveCount) { float nextLen = m_splineBase.EvalLength(nextCurveIndex); float nextCur = m_splineBase.EvalCurveLength(nextCurveIndex, GetStepsPerCurve()); Handles.Label(m_splineBase.GetPoint(0.5f, nextCurveIndex), string.Format("Len: {0:0.00} m, Cur: {1:0.00} m", nextLen, nextCur), style); } float cur = m_splineBase.EvalCurveLength(curveIndex, GetStepsPerCurve()); float len = m_splineBase.EvalLength(curveIndex); Handles.Label(m_splineBase.GetPoint(0.5f, curveIndex), string.Format("Len: {0:0.00} m, Cur: {1:0.00} m", len, cur), style); EditorGUI.BeginChangeCheck(); point = Handles.DoPositionHandle(point, m_handleRotation); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(m_splineBase, UNDO_MOVEPOINT); EditorUtility.SetDirty(m_splineBase); m_splineBase.SetControlPointLocal(index, m_handleTransform.InverseTransformPoint(point)); } } }