public static Spline CreateSpline(Vector3 position, Thickness thickness, Twist twist, ControlPointMode mode = ControlPointMode.Mirrored, string undorecord = "Battlehub.Spline.Create") { GameObject spline = new GameObject(); spline.name = "Spline"; if (!FindObjectOfType <GLRenderer>()) { GameObject go = new GameObject(); go.name = "GLRenderer"; go.AddComponent <GLRenderer>(); } Undo.RegisterCreatedObjectUndo(spline, undorecord); Spline splineComponent = spline.AddComponent <Spline>(); splineComponent.SetControlPointMode(mode); splineComponent.SetTwist(0, twist); splineComponent.SetTwist(3, twist); splineComponent.SetThickness(0, thickness); splineComponent.SetThickness(3, thickness); spline.transform.position = position; return(splineComponent); }
private static void SetMode(GameObject selected, ControlPointMode mode) { Spline spline = selected.GetComponentInParent <Spline>(); if (spline == null) { return; } SplineControlPoint selectedControlPoint = selected.GetComponent <SplineControlPoint>(); Undo.RecordObject(spline, "Battlehub.Spline.SetMode"); EditorUtility.SetDirty(spline); if (selectedControlPoint != null) { spline.SetControlPointMode(selectedControlPoint.Index, mode); } else { spline.SetControlPointMode(mode); } }
public static void Create() { GameObject spline = new GameObject(); spline.name = "Spline"; Undo.RegisterCreatedObjectUndo(spline, "Battlehub.Spline.Create"); Spline splineComponent = spline.AddComponent <Spline>(); splineComponent.SetControlPointMode(ControlPointMode.Mirrored); Camera sceneCam = SceneView.lastActiveSceneView.camera; spline.transform.position = sceneCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 5f)); Selection.activeGameObject = spline.gameObject; }
protected override void OnInspectorGUIOverride() { if (m_spline == null) { m_spline = (Spline)GetTarget(); } if (m_spline == null) { return; } EditorGUI.BeginChangeCheck(); bool loop = EditorGUILayout.Toggle("Loop", m_spline.Loop); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(m_spline, UNDO_TOGGLELOOP); EditorUtility.SetDirty(m_spline); m_spline.Loop = loop; } GUILayout.BeginHorizontal(); { if (GUILayout.Button("Append")) { Undo.RecordObject(m_spline, "Battlehub.Spline.Append"); m_spline.Extend(); EditorUtility.SetDirty(m_spline); } if (GUILayout.Button("Prepend")) { Undo.RecordObject(m_spline, "Battlehub.Spline.Prepend"); m_spline.Extend(true); EditorUtility.SetDirty(m_spline); } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { if (GUILayout.Button("Set Free Mode")) { Undo.RecordObject(m_spline, "Battlehub.Spline.SetMode"); m_spline.SetControlPointMode(ControlPointMode.Free); EditorUtility.SetDirty(m_spline); } if (GUILayout.Button("Set Aligned Mode")) { Undo.RecordObject(m_spline, "Battlehub.Spline.SetMode"); m_spline.SetControlPointMode(ControlPointMode.Aligned); EditorUtility.SetDirty(m_spline); } if (GUILayout.Button("Set Mirrored Mode")) { Undo.RecordObject(m_spline, "Battlehub.Spline.SetMode"); m_spline.SetControlPointMode(ControlPointMode.Mirrored); EditorUtility.SetDirty(m_spline); } } GUILayout.EndHorizontal(); if (GUILayout.Button("Smooth")) { Undo.RecordObject(m_spline, "Battlehub.Spline.SetMode"); m_spline.Smooth(); EditorUtility.SetDirty(m_spline); } }