public override void OnInspectorGUI( ) { SplineMesh mesh = (SplineMesh)target; EditorGUILayout.BeginVertical( ); EditorGUILayout.Space( ); spline = (Spline)EditorGUILayout.ObjectField(" Spline", mesh.spline, typeof(Spline), true); baseMesh = (Mesh)EditorGUILayout.ObjectField(" Base Mesh", mesh.baseMesh, typeof(Mesh), false); int materialCount = (int)EditorGUILayout.IntField(" Materials Count", mesh.materials.Length); if (materials == null || materialCount != materials.Length) { materials = new Material[materialCount]; } for (int q = 0; q < materialCount; ++q) { materials[q] = (q < mesh.materials.Length)? mesh.materials[q]: null; materials[q] = (Material)EditorGUILayout.ObjectField(" Material " + q, materials[q], typeof(Material), false); } EditorGUILayout.Space(); uMode = (Spline.UpdateMode)EditorGUILayout.EnumPopup(" Update Mode", mesh.uMode); if (uMode == Spline.UpdateMode.EveryXFrames) { deltaFrames = EditorGUILayout.IntField(" Delta Frames", mesh.deltaFrames); } else if (uMode == Spline.UpdateMode.EveryXSeconds) { deltaSeconds = EditorGUILayout.FloatField(" Delta Seconds", mesh.deltaSeconds); } uvWrapAt = EditorGUILayout.FloatField(" UV Wrap", mesh.uvWrapAt); segmentCount = Mathf.Max(EditorGUILayout.IntField(" Segment Count", mesh.segmentCount), 1); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(" Offset"); xyOffset.x = EditorGUILayout.FloatField(mesh.xyOffset.x, GUILayout.MinWidth(10)); xyOffset.y = EditorGUILayout.FloatField(mesh.xyOffset.y, GUILayout.MinWidth(10)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal( ); EditorGUILayout.PrefixLabel(" Scale"); xyScale.x = EditorGUILayout.FloatField(mesh.xyScale.x, GUILayout.MinWidth(10)); xyScale.y = EditorGUILayout.FloatField(mesh.xyScale.y, GUILayout.MinWidth(10)); EditorGUILayout.EndHorizontal( ); EditorGUILayout.BeginHorizontal( ); EditorGUILayout.PrefixLabel(" UV-Scale"); uvScale.x = EditorGUILayout.FloatField(mesh.uvScale.x, GUILayout.MinWidth(10)); uvScale.y = EditorGUILayout.FloatField(mesh.uvScale.y, GUILayout.MinWidth(10)); EditorGUILayout.EndHorizontal( ); swapUV = EditorGUILayout.Toggle(" Swap UV", mesh.swapUV); splitMesh = EditorGUILayout.Toggle(" Split Mesh", mesh.splitMesh); EditorGUILayout.Space(); // lightprobes lightProbeSegmentCount = Mathf.Max(EditorGUILayout.IntField(" Light Volume Count", mesh.lightProbeSegmentCount), 0); EditorGUILayout.BeginHorizontal( ); EditorGUILayout.PrefixLabel(" Light Volume Extrude"); lightProbeExtrude.x = EditorGUILayout.FloatField(mesh.lightProbeExtrude.x, GUILayout.MinWidth(10)); lightProbeExtrude.y = EditorGUILayout.FloatField(mesh.lightProbeExtrude.y, GUILayout.MinWidth(10)); EditorGUILayout.EndHorizontal( ); lightProbeHeight = EditorGUILayout.FloatField(" Light Volume Height", mesh.lightProbeHeight); EditorGUILayout.Space(); persistent = EditorGUILayout.Toggle(" Persistent Mesh", mesh.persistent); if (persistent) { uMode = Spline.UpdateMode.DontUpdate; } EditorGUILayout.Space(); EditorGUILayout.EndVertical( ); bool rebuild = GUILayout.Button("Rebuild"); if (GUI.changed) { Undo.RegisterUndo(target, "Change Spline Mesh Settings"); EditorUtility.SetDirty(target); } if (GUI.changed || rebuild) { if (baseMesh == null) { Debug.LogWarning("There is no base mesh assigned to your spline mesh! Check the inspector to assign it!", mesh.gameObject); } mesh.uMode = uMode; mesh.spline = spline; mesh.swapUV = swapUV; mesh.uvWrapAt = uvWrapAt; mesh.xyOffset = xyOffset; mesh.xyScale = xyScale; mesh.uvScale = uvScale; mesh.baseMesh = baseMesh; mesh.materials = materials; mesh.deltaFrames = deltaFrames; mesh.deltaSeconds = deltaSeconds; mesh.segmentCount = segmentCount; mesh.lightProbeSegmentCount = lightProbeSegmentCount; mesh.lightProbeExtrude = lightProbeExtrude; mesh.lightProbeHeight = lightProbeHeight; mesh.persistent = persistent; mesh.splitMesh = splitMesh; if (mesh.persistent) { foreach (var m in mesh.BentMeshes) { AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(m)); } } mesh.UpdateMesh(); if (mesh.persistent) { foreach (var m in mesh.BentMeshes) { var assetPath = AssetHelper.GetPathForGeneratedAsset(m, mesh.gameObject); Debug.Log("PATH: " + assetPath); AssetDatabase.CreateAsset(m, assetPath); AssetDatabase.SaveAssets(); } } } }
public override void OnInspectorGUI( ) { SplineMesh mesh = (SplineMesh)target; EditorGUILayout.BeginVertical( ); EditorGUILayout.Space( ); spline = (Spline)EditorGUILayout.ObjectField(" Spline", mesh.spline, typeof(Spline), true); baseMesh = (Mesh)EditorGUILayout.ObjectField(" Base Mesh", mesh.baseMesh, typeof(Mesh), false); EditorGUILayout.Space( ); uMode = (Spline.UpdateMode)EditorGUILayout.EnumPopup(" Update Mode", mesh.uMode); if (uMode == Spline.UpdateMode.EveryXFrames) { deltaFrames = EditorGUILayout.IntField(" Delta Frames", mesh.deltaFrames); } else if (uMode == Spline.UpdateMode.EveryXSeconds) { deltaSeconds = EditorGUILayout.FloatField(" Delta Seconds", mesh.deltaSeconds); } segmentCount = Mathf.Max(EditorGUILayout.IntField(" Segment Count", mesh.segmentCount), 1); EditorGUILayout.BeginHorizontal( ); EditorGUILayout.PrefixLabel(" Scale"); xyScale.x = EditorGUILayout.FloatField(mesh.xyScale.x, GUILayout.MinWidth(10)); xyScale.y = EditorGUILayout.FloatField(mesh.xyScale.y, GUILayout.MinWidth(10)); EditorGUILayout.EndHorizontal( ); EditorGUILayout.BeginHorizontal( ); EditorGUILayout.PrefixLabel(" UV-Scale"); uvScale.x = EditorGUILayout.FloatField(mesh.uvScale.x, GUILayout.MinWidth(10)); uvScale.y = EditorGUILayout.FloatField(mesh.uvScale.y, GUILayout.MinWidth(10)); EditorGUILayout.EndHorizontal( ); swapUV = EditorGUILayout.Toggle(" Swap UV", mesh.swapUV); splitMesh = EditorGUILayout.Toggle(" Split Mesh", (mesh.splineSegment != -1)); if (splitMesh && spline != null) { splineSegment = Mathf.Clamp(EditorGUILayout.IntField(" Segment Index", mesh.splineSegment), 0, spline.SegmentCount - 1); } EditorGUILayout.Space( ); EditorGUILayout.EndVertical( ); if (GUI.changed) { Undo.RecordObject(target, "Change Spline Mesh Settings"); EditorUtility.SetDirty(target); if (baseMesh == null) { Debug.LogWarning("There is no base mesh assigned to your spline mesh! Check the inspector to assign it!", mesh.gameObject); } mesh.uMode = uMode; mesh.spline = spline; mesh.swapUV = swapUV; mesh.xyScale = xyScale; mesh.uvScale = uvScale; mesh.baseMesh = baseMesh; mesh.deltaFrames = deltaFrames; mesh.deltaSeconds = deltaSeconds; mesh.segmentCount = segmentCount; if (splitMesh) { mesh.splineSegment = splineSegment; } else { mesh.splineSegment = -1; } mesh.UpdateMesh( ); } }
public override void OnInspectorGUI( ) { SplineMesh mesh = (SplineMesh) target; EditorGUILayout.BeginVertical( ); EditorGUILayout.Space( ); spline = (Spline) EditorGUILayout.ObjectField( " Spline", mesh.spline, typeof( Spline ), true ); baseMesh = (Mesh) EditorGUILayout.ObjectField( " Base Mesh", mesh.baseMesh, typeof( Mesh ), false ); EditorGUILayout.Space( ); uMode = (Spline.UpdateMode) EditorGUILayout.EnumPopup( " Update Mode", mesh.uMode ); if( uMode == Spline.UpdateMode.EveryXFrames ) deltaFrames = EditorGUILayout.IntField( " Delta Frames", mesh.deltaFrames ); else if( uMode == Spline.UpdateMode.EveryXSeconds ) deltaSeconds = EditorGUILayout.FloatField( " Delta Seconds", mesh.deltaSeconds ); segmentCount = Mathf.Max( EditorGUILayout.IntField( " Segment Count", mesh.segmentCount ), 1 ); EditorGUILayout.BeginHorizontal( ); EditorGUILayout.PrefixLabel( " Scale" ); xyScale.x = EditorGUILayout.FloatField( mesh.xyScale.x, GUILayout.MinWidth( 10 ) ); xyScale.y = EditorGUILayout.FloatField( mesh.xyScale.y, GUILayout.MinWidth( 10 ) ); EditorGUILayout.EndHorizontal( ); EditorGUILayout.BeginHorizontal( ); EditorGUILayout.PrefixLabel( " UV-Scale" ); uvScale.x = EditorGUILayout.FloatField( mesh.uvScale.x, GUILayout.MinWidth( 10 ) ); uvScale.y = EditorGUILayout.FloatField( mesh.uvScale.y, GUILayout.MinWidth( 10 ) ); EditorGUILayout.EndHorizontal( ); swapUV = EditorGUILayout.Toggle( " Swap UV", mesh.swapUV ); splitMesh = EditorGUILayout.Toggle( " Split Mesh", (mesh.splineSegment != -1) ); if( splitMesh && spline != null ) splineSegment = Mathf.Clamp( EditorGUILayout.IntField( " Segment Index", mesh.splineSegment ), 0, spline.SegmentCount - 1 ); EditorGUILayout.Space( ); EditorGUILayout.EndVertical( ); if( GUI.changed ) { Undo.RegisterUndo( target, "Change Spline Mesh Settings" ); EditorUtility.SetDirty( target ); if( baseMesh == null ) Debug.LogWarning( "There is no base mesh assigned to your spline mesh! Check the inspector to assign it!", mesh.gameObject ); mesh.uMode = uMode; mesh.spline = spline; mesh.swapUV = swapUV; mesh.xyScale = xyScale; mesh.uvScale = uvScale; mesh.baseMesh = baseMesh; mesh.deltaFrames = deltaFrames; mesh.deltaSeconds = deltaSeconds; mesh.segmentCount = segmentCount; if( splitMesh ) mesh.splineSegment = splineSegment; else mesh.splineSegment = -1; mesh.UpdateMesh( ); } }
public override void OnInspectorGUI() { spline = (Spline)target; EditorGUILayout.BeginVertical(); uMode = (Spline.UpdateMode)EditorGUILayout.EnumPopup(" Update Mode", spline.updateMode); if (uMode == Spline.UpdateMode.EveryXFrames) { deltaFrames = EditorGUILayout.IntField(" Delta Frames", spline.deltaFrames); EditorGUILayout.Space(); } else if (uMode == Spline.UpdateMode.EveryXSeconds) { deltaSeconds = EditorGUILayout.FloatField(" Delta Seconds", spline.deltaSeconds); EditorGUILayout.Space(); } nMode = (Spline.ControlNodeMode)EditorGUILayout.EnumPopup(" Control Nodes", spline.nodeMode); iMode = (Spline.InterpolationMode)EditorGUILayout.EnumPopup(" Interpolation", spline.interpolationMode); if (iMode == Spline.InterpolationMode.Hermite) { tMode = (Spline.TangentMode)EditorGUILayout.EnumPopup(" Tangent Mode", spline.tangentMode); } rMode = (Spline.RotationMode)EditorGUILayout.EnumPopup(" Rotation Mode", spline.rotationMode); EditorGUILayout.Space(); accuarcy = Mathf.Clamp(EditorGUILayout.IntField(" Accuracy", spline.interpolationAccuracy), 1, 20); EditorGUILayout.Space(); if (iMode == Spline.InterpolationMode.Hermite) { tension = EditorGUILayout.FloatField(" Spline Tension", spline.tension); } if (rMode == Spline.RotationMode.Tangent) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(" Up-Vector"); tanUpVector.x = EditorGUILayout.FloatField(spline.tanUpVector.x, GUILayout.MinWidth(10)); tanUpVector.y = EditorGUILayout.FloatField(spline.tanUpVector.y, GUILayout.MinWidth(10)); tanUpVector.z = EditorGUILayout.FloatField(spline.tanUpVector.z, GUILayout.MinWidth(10)); EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); if (iMode != Spline.InterpolationMode.Bezier) { autoClose = EditorGUILayout.Toggle(" Auto Close", spline.autoClose); } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); bool isAddNodePressed = GUILayout.Button("Add Spline Node", GUILayout.MinWidth(250f)); EditorGUILayout.Space(); EditorGUILayout.EndHorizontal(); bool isAddNodeControllersPressed = false; if (spline.nodeMode == Spline.ControlNodeMode.UseChildren) { EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); isAddNodeControllersPressed = GUILayout.Button("Add CtrlNode-Component To Children", GUILayout.MinWidth(250f)); EditorGUILayout.Space(); EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); EditorGUILayout.Space(); //Draw Array-GUI if (nMode == Spline.ControlNodeMode.UseArray) { showNodeArray = EditorGUILayout.Foldout(showNodeArray, " Spline Nodes"); if (showNodeArray) { numTransformNodes = EditorGUILayout.IntField(" Size", spline.splineNodesTransform.Length); for (int i = 0; i < spline.splineNodesTransform.Length; i++) { spline.splineNodesTransform[i] = (Transform)EditorGUILayout.ObjectField(" Element " + i.ToString(), spline.splineNodesTransform[i], typeof(Transform), true); } } DragAndDrop.activeControlID = 0; DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (Event.current.type == EventType.DragPerform && DragAndDrop.objectReferences[0].GetType() == typeof(GameObject)) { DragAndDrop.AcceptDrag(); Undo.RecordObject(target, "Add Node To " + spline.name); AddTransformNode(((GameObject)DragAndDrop.objectReferences[0]).transform); UpdateSplineComponents(); EditorUtility.SetDirty(target); } } EditorGUILayout.Space(); EditorGUILayout.EndVertical(); if (isAddNodePressed) { AddSplineNode(); } if (isAddNodeControllersPressed) { AddCtrlCmpntToChildren(); } //Apply changes if (GUI.changed) { Undo.RecordObject(target, "Change Spline Settings"); spline.updateMode = uMode; spline.nodeMode = nMode; spline.rotationMode = rMode; spline.tangentMode = tMode; spline.interpolationMode = iMode; spline.interpolationAccuracy = accuarcy; if (uMode == Spline.UpdateMode.EveryXFrames) { spline.deltaFrames = deltaFrames; } else if (uMode == Spline.UpdateMode.EveryXSeconds) { spline.deltaSeconds = deltaSeconds; } if (iMode == Spline.InterpolationMode.Hermite) { spline.tension = tension; } if (iMode != Spline.InterpolationMode.Bezier) { spline.autoClose = autoClose; } if (rMode == Spline.RotationMode.Tangent) { spline.tanUpVector = tanUpVector; } //check for errors if (nMode == Spline.ControlNodeMode.UseChildren) { if (spline.transform.childCount == 0) { if (!errorNoChildrenShown) { Debug.LogWarning(errorNoChildren, spline.gameObject); } errorNoChildrenShown = true; } else { errorNoChildrenShown = false; } } else { if (numTransformNodes == 0) { if (!errorNoNodesShown) { Debug.LogWarning(errorNoNodes, spline.gameObject); } errorNoNodesShown = true; } else { errorNoNodesShown = false; } } if (nMode == Spline.ControlNodeMode.UseArray && showNodeArray) { ResizeTransformNodeArray(); bool nullReference = false; //Check for null references and inform the user if any have been found foreach (Transform item in spline.splineNodesTransform) { if (item == null) { nullReference = true; } } if (nullReference) { if (!errorNullNodesShown) { Debug.LogWarning(errorNullNodes, spline.gameObject); } errorNullNodesShown = true; } else { errorNullNodesShown = false; } } UpdateSplineComponents(); EditorUtility.SetDirty(target); } }
public override void OnInspectorGUI( ) { spline = (Spline) target; EditorGUILayout.BeginVertical( ); uMode = (Spline.UpdateMode) EditorGUILayout.EnumPopup( " Update Mode", spline.updateMode ); if( uMode == Spline.UpdateMode.EveryXFrames ) { deltaFrames = EditorGUILayout.IntField( " Delta Frames", spline.deltaFrames ); EditorGUILayout.Space( ); } else if( uMode == Spline.UpdateMode.EveryXSeconds ) { deltaSeconds = EditorGUILayout.FloatField( " Delta Seconds", spline.deltaSeconds ); EditorGUILayout.Space( ); } nMode = (Spline.ControlNodeMode) EditorGUILayout.EnumPopup( " Control Nodes", spline.nodeMode ); iMode = (Spline.InterpolationMode) EditorGUILayout.EnumPopup( " Interpolation", spline.interpolationMode ); if( iMode == Spline.InterpolationMode.Hermite ) tMode = (Spline.TangentMode) EditorGUILayout.EnumPopup( " Tangent Mode", spline.tangentMode ); rMode = (Spline.RotationMode) EditorGUILayout.EnumPopup( " Rotation Mode", spline.rotationMode ); EditorGUILayout.Space( ); accuarcy = Mathf.Clamp( EditorGUILayout.IntField( " Accuracy", spline.interpolationAccuracy ), 1, 20 ); EditorGUILayout.Space( ); if( iMode == Spline.InterpolationMode.Hermite ) tension = EditorGUILayout.FloatField( " Spline Tension", spline.tension ); if( rMode == Spline.RotationMode.Tangent ) { EditorGUILayout.BeginHorizontal( ); EditorGUILayout.PrefixLabel( " Up-Vector" ); tanUpVector.x = EditorGUILayout.FloatField( spline.tanUpVector.x, GUILayout.MinWidth( 10 ) ); tanUpVector.y = EditorGUILayout.FloatField( spline.tanUpVector.y, GUILayout.MinWidth( 10 ) ); tanUpVector.z = EditorGUILayout.FloatField( spline.tanUpVector.z, GUILayout.MinWidth( 10 ) ); EditorGUILayout.EndHorizontal( ); } EditorGUILayout.Space( ); if( iMode != Spline.InterpolationMode.Bezier ) autoClose = EditorGUILayout.Toggle( " Auto Close", spline.autoClose ); EditorGUILayout.Space( ); EditorGUILayout.BeginHorizontal( ); EditorGUILayout.Space( ); bool isAddNodePressed = GUILayout.Button( "Add Spline Node", GUILayout.MinWidth( 250f ) ); EditorGUILayout.Space( ); EditorGUILayout.EndHorizontal( ); bool isAddNodeControllersPressed = false; if( spline.nodeMode == Spline.ControlNodeMode.UseChildren ) { EditorGUILayout.Space( ); EditorGUILayout.BeginHorizontal( ); EditorGUILayout.Space( ); isAddNodeControllersPressed = GUILayout.Button( "Add CtrlNode-Component To Children", GUILayout.MinWidth( 250f ) ); EditorGUILayout.Space( ); EditorGUILayout.EndHorizontal( ); } EditorGUILayout.Space( ); EditorGUILayout.Space( ); //Draw Array-GUI if( nMode == Spline.ControlNodeMode.UseArray ) { showNodeArray = EditorGUILayout.Foldout( showNodeArray, " Spline Nodes" ); if( showNodeArray ) { numTransformNodes = EditorGUILayout.IntField( " Size", spline.splineNodesTransform.Length ); for( int i = 0; i < spline.splineNodesTransform.Length; i++ ) spline.splineNodesTransform[i] = (Transform) EditorGUILayout.ObjectField( " Element " + i.ToString( ), spline.splineNodesTransform[i], typeof( Transform ), true ); } DragAndDrop.activeControlID = 0; DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if( Event.current.type == EventType.DragPerform && DragAndDrop.objectReferences[0].GetType( ) == typeof( GameObject ) ) { DragAndDrop.AcceptDrag( ); Undo.RegisterUndo( target, "Add Node To " + spline.name ); AddTransformNode( ((GameObject)DragAndDrop.objectReferences[0]).transform ); UpdateSplineComponents( ); EditorUtility.SetDirty( target ); } } EditorGUILayout.Space( ); EditorGUILayout.EndVertical( ); if( isAddNodePressed ) AddSplineNode( ); if( isAddNodeControllersPressed ) AddCtrlCmpntToChildren( ); //Apply changes if( GUI.changed ) { Undo.RegisterUndo( target, "Change Spline Settings" ); spline.updateMode = uMode; spline.nodeMode = nMode; spline.rotationMode = rMode; spline.tangentMode = tMode; spline.interpolationMode = iMode; spline.interpolationAccuracy = accuarcy; if( uMode == Spline.UpdateMode.EveryXFrames ) spline.deltaFrames = deltaFrames; else if( uMode == Spline.UpdateMode.EveryXSeconds ) spline.deltaSeconds = deltaSeconds; if( iMode == Spline.InterpolationMode.Hermite ) spline.tension = tension; if( iMode != Spline.InterpolationMode.Bezier ) spline.autoClose = autoClose; if( rMode == Spline.RotationMode.Tangent ) spline.tanUpVector = tanUpVector; //check for errors if( nMode == Spline.ControlNodeMode.UseChildren ) { if( spline.transform.childCount == 0 ) { if( !errorNoChildrenShown ) Debug.LogWarning( errorNoChildren, spline.gameObject ); errorNoChildrenShown = true; } else { errorNoChildrenShown = false; } } else { if( numTransformNodes == 0 ) { if( !errorNoNodesShown ) Debug.LogWarning( errorNoNodes, spline.gameObject ); errorNoNodesShown = true; } else { errorNoNodesShown = false; } } if( nMode == Spline.ControlNodeMode.UseArray && showNodeArray ) { ResizeTransformNodeArray( ); bool nullReference = false; //Check for null references and inform the user if any have been found foreach( Transform item in spline.splineNodesTransform ) if( item == null ) nullReference = true; if( nullReference ) { if( !errorNullNodesShown ) Debug.LogWarning( errorNullNodes, spline.gameObject ); errorNullNodesShown = true; } else { errorNullNodesShown = false; } } UpdateSplineComponents( ); EditorUtility.SetDirty( target ); } }