public void OnInspectorGUI() { if (RigidBody == null || GetChildren().Length == 0) { PerformRemoveFromParent(); return; } var skin = InspectorEditor.Skin; InspectorGUI.OnDropdownToolBegin("Create visual representation of this rigid body given all supported shapes."); foreach (var tool in GetChildren <ShapeVisualCreateTool>()) { if (ShapeVisual.HasShapeVisual(tool.Shape)) { continue; } EditorGUILayout.PrefixLabel(GUI.MakeLabel(tool.Shape.name, true), skin.Label); using (InspectorGUI.IndentScope.Single) tool.OnInspectorGUI(true); } var createCancelState = InspectorGUI.PositiveNegativeButtons(true, "Create", "Create shape visual for shapes that hasn't already got one.", "Cancel"); if (createCancelState == InspectorGUI.PositiveNegativeResult.Positive) { foreach (var tool in GetChildren <ShapeVisualCreateTool>()) { if (!ShapeVisual.HasShapeVisual(tool.Shape)) { tool.CreateShapeVisual(); } } } InspectorGUI.OnDropdownToolEnd(); if (createCancelState != InspectorGUI.PositiveNegativeResult.Neutral) { PerformRemoveFromParent(); } }
public void OnInspectorGUI() { if (AttachmentFrameTool == null || AttachmentFrameTool.AttachmentPairs[0] == null) { PerformRemoveFromParent(); return; } InspectorGUI.OnDropdownToolBegin("Create constraint given type and use additional tools to " + "configure the constraint frames."); var skin = InspectorEditor.Skin; m_createConstraintData.Name = EditorGUILayout.TextField(GUI.MakeLabel("Name", true), m_createConstraintData.Name, skin.TextField); #if UNITY_2018_1_OR_NEWER m_createConstraintData.ConstraintType = (ConstraintType)EditorGUILayout.EnumPopup(GUI.MakeLabel("Type", true), m_createConstraintData.ConstraintType, val => (ConstraintType)val != ConstraintType.Unknown, false, skin.Popup); #else m_createConstraintData.ConstraintType = (ConstraintType)EditorGUILayout.EnumPopup(GUI.MakeLabel("Type", true), m_createConstraintData.ConstraintType, skin.Popup); #endif AttachmentFrameTool.OnPreTargetMembersGUI(); AttachmentFrameTool.AttachmentPairs[0].Synchronize(); m_createConstraintData.CollisionState = ConstraintTool.ConstraintCollisionsStateGUI(m_createConstraintData.CollisionState); m_createConstraintData.SolveType = ConstraintTool.ConstraintSolveTypeGUI(m_createConstraintData.SolveType); var createCancelState = InspectorGUI.PositiveNegativeButtons(m_createConstraintData.AttachmentPair.ReferenceObject != null && m_createConstraintData.AttachmentPair.ReferenceObject.GetComponentInParent <RigidBody>() != null, "Create", "Create the constraint", "Cancel"); if (createCancelState == InspectorGUI.PositiveNegativeResult.Positive) { GameObject constraintGameObject = Factory.Create(m_createConstraintData.ConstraintType, m_createConstraintData.AttachmentPair); Constraint constraint = constraintGameObject.GetComponent <Constraint>(); constraintGameObject.name = m_createConstraintData.Name; constraint.CollisionsState = m_createConstraintData.CollisionState; if (MakeConstraintChildToParent) { constraintGameObject.transform.SetParent(Parent.transform); } Undo.RegisterCreatedObjectUndo(constraintGameObject, "New constraint '" + constraintGameObject.name + "' created"); m_onCreate?.Invoke(constraint); m_createConstraintData.Reset(); } if (createCancelState != InspectorGUI.PositiveNegativeResult.Neutral) { PerformRemoveFromParent(); } InspectorGUI.OnDropdownToolEnd(); }
public void OnInspectorGUI() { if (AttachmentFrameTool == null || AttachmentFrameTool.AttachmentPairs[0] == null) { PerformRemoveFromParent(); return; } InspectorGUI.OnDropdownToolBegin("Create constraint given type and use additional tools to " + "configure the constraint frames."); var skin = InspectorEditor.Skin; m_createConstraintData.Name = EditorGUILayout.TextField(GUI.MakeLabel("Name", true), m_createConstraintData.Name, skin.TextField); #if UNITY_2018_1_OR_NEWER m_createConstraintData.ConstraintType = (ConstraintType)EditorGUILayout.EnumPopup(GUI.MakeLabel("Type", true), m_createConstraintData.ConstraintType, val => (ConstraintType)val != ConstraintType.Unknown, false, skin.Popup); #else m_createConstraintData.ConstraintType = (ConstraintType)EditorGUILayout.EnumPopup(GUI.MakeLabel("Type", true), m_createConstraintData.ConstraintType, skin.Popup); #endif AttachmentFrameTool.OnPreTargetMembersGUI(); AttachmentFrameTool.AttachmentPairs[0].Synchronize(); m_createConstraintData.CollisionState = ConstraintTool.ConstraintCollisionsStateGUI(m_createConstraintData.CollisionState); m_createConstraintData.SolveType = ConstraintTool.ConstraintSolveTypeGUI(m_createConstraintData.SolveType); if (Parent != null) { MakeConstraintChildToParent = InspectorGUI.Toggle(GUI.MakeLabel($"Create as child", true, $"Add the created constraint game object as child " + $"to \"{Parent.name}\". If false, the game object is " + $"created without a parent or under the prefab root if " + $"created inside a prefab stage."), MakeConstraintChildToParent); } var createCancelState = InspectorGUI.PositiveNegativeButtons(m_createConstraintData.AttachmentPair.ReferenceObject != null && m_createConstraintData.AttachmentPair.ReferenceObject.GetComponentInParent <RigidBody>() != null, "Create", "Create the constraint", "Cancel"); if (createCancelState == InspectorGUI.PositiveNegativeResult.Positive) { GameObject constraintGameObject = Factory.Create(m_createConstraintData.ConstraintType, m_createConstraintData.AttachmentPair); Constraint constraint = constraintGameObject.GetComponent <Constraint>(); constraintGameObject.name = m_createConstraintData.Name; constraint.CollisionsState = m_createConstraintData.CollisionState; if (MakeConstraintChildToParent) { constraintGameObject.transform.SetParent(Parent.transform); } else { // If we're in the Prefab Stage this call will add the constraint // game object as child of the root prefab. UnityEditor.SceneManagement.StageUtility.PlaceGameObjectInCurrentStage(constraintGameObject); } Undo.RegisterCreatedObjectUndo(constraintGameObject, "New constraint '" + constraintGameObject.name + "' created"); m_onCreate?.Invoke(constraint); m_createConstraintData.Reset(); } if (createCancelState != InspectorGUI.PositiveNegativeResult.Neutral) { PerformRemoveFromParent(); } InspectorGUI.OnDropdownToolEnd(); }