private void UpdateMaterial() { if (m_renderer != null) { SplineRuntimeEditor runtimeEditor = SplineRuntimeEditor.Instance; if (runtimeEditor != null) { if (m_index % 3 == 0) { if (m_spline.HasBranches(m_index)) { m_renderer.sharedMaterial = runtimeEditor.ConnectedMaterial; } else { 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 CheckBranches(int curveIndex) { int pointIndex = curveIndex * 3; if (m_t >= 1.0f) { pointIndex += 3; } m_curveIndex = curveIndex; if (m_spline.HasBranches(pointIndex)) { ForkEventArgs args = new ForkEventArgs(m_spline, pointIndex); Fork.Invoke(args); if (args.SelectBranchIndex > -1 && args.SelectBranchIndex < args.Branches.Length) { Debug.Log("CurveIndex " + m_curveIndex); Debug.Log("Selected Branch " + args.SelectBranchIndex); m_spline = args.Branches[args.SelectBranchIndex]; m_t = 0.0f; m_curveIndex = 0; } } }
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); }