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(GUISkin skin) { if (AttachmentFrameTool == null || AttachmentFrameTool.AttachmentPair == null) { PerformRemoveFromParent(); return; } using (new GUI.Indent(16)) { GUILayout.BeginHorizontal(); { GUILayout.Label(GUI.MakeLabel("Name", true), skin.label, GUILayout.Width(64)); m_createConstraintData.Name = GUILayout.TextField(m_createConstraintData.Name, skin.textField, GUILayout.ExpandWidth(true)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label(GUI.MakeLabel("Type", true), skin.label, GUILayout.Width(64)); using (new GUI.ColorBlock(Color.Lerp(UnityEngine.GUI.color, Color.yellow, 0.1f))) m_createConstraintData.ConstraintType = (ConstraintType)EditorGUILayout.EnumPopup(m_createConstraintData.ConstraintType, skin.button, GUILayout.ExpandWidth(true), GUILayout.Height(18)); } GUILayout.EndHorizontal(); } GUI.Separator3D(); AttachmentFrameTool.OnPreTargetMembersGUI(skin); AttachmentFrameTool.AttachmentPair.Synchronize(); m_createConstraintData.CollisionState = ConstraintTool.ConstraintCollisionsStateGUI(m_createConstraintData.CollisionState, skin); m_createConstraintData.SolveType = ConstraintTool.ConstraintSolveTypeGUI(m_createConstraintData.SolveType, skin); GUI.Separator3D(); var createCancelState = GUI.CreateCancelButtons(m_createConstraintData.AttachmentPair.ReferenceObject != null && m_createConstraintData.AttachmentPair.ReferenceObject.GetComponentInParent <RigidBody>() != null, skin, "Create the constraint"); GUI.Separator3D(); if (createCancelState == GUI.CreateCancelState.Create) { 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_createConstraintData.Reset(); } if (createCancelState != GUI.CreateCancelState.Nothing) { 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); 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(); }