public void DrawObserverActionSection() { EditorGUILayout.LabelField("Actions", EditorStyles.boldLabel); if (GUILayout.Button(RefreshObserversLabel, GUILayout.MaxWidth(130))) { Undo.RecordObject(Target, "Refresh Observers"); StandardOutfit.RefreshObservers(Target); EditorGUILayout.Space(); } }
/* * Design notes: * * The design is meant to minimize the need to hard code field values in the editor * while maintaining the use of serialized properties to format each field properly. * * With the exception of the core fields and the observers list, all sections are expected * to start with a 'start' property field and end with the section's namesake 'complex' * field. 'Complex' in this context means a field with child fields. They are used * to control the foldout state for their associated section. All other fields that * belong to a section are expected to be between the start and end fields. (The * property iterator follows the field order in the class definition.) * * All fields are expected to be in a section with sections layed out internally as follows: * * Section start field * .... * .... Other section fields * .... * Section end complex field * * The order of the fields in each section is the same as defined in the source class. * The order of the sections is controlled by this editor code. * * To allow reordering of sections, each section goes through separate load and draw * draw steps. The load step gathers the persistant serialized properties from the * property iterator. The draw step draws the properties. */ #region Editor Members void OnEnable() { var outfit = target as StandardOutfit; // Assume auto-detect has already been performed if the motion root is assigned // Want to be conservative. if (!Application.isPlaying && outfit && !outfit.MotionRoot) { StandardOutfit.UnsafeRefreshAllSettings(outfit); EditorUtility.SetDirty(outfit); } }
void OnEnable() { var outfit = target as StandardOutfit; // Assume auto-detect has already been performed if the motion root is assigned // Want to be conservative. if (!Application.isPlaying && outfit && !StandardOutfit.IsMotionRootAssigned(outfit)) { StandardOutfitEditor.RefreshAllSettings(outfit); } m_IsAsset = AssetDatabase.Contains(target); m_ContextChoice = outfit.gameObject; }
private static void RefreshAllSettings( StandardOutfit outfit, bool singleUndo = true, string undoLabel = "Refresh All Outfit Settings") { if (singleUndo) { Undo.IncrementCurrentGroup(); } Undo.RecordObjects(StandardOutfit.UnsafeGetUndoObjects(outfit).ToArray(), undoLabel); StandardOutfit.UnsafeRefreshAllSettings(outfit); if (singleUndo) { Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); } }
public void DrawBodyPartActions() { EditorGUILayout.LabelField("Body Parts"); LizEditorGUIUtil.BeginLabelWidth(70); m_ContextChoice = EditorGUILayout.ObjectField(ContextLabel, m_ContextChoice, typeof(GameObject), true) as GameObject; var outfit = Target; EditorGUILayout.BeginHorizontal(); m_PartTypeChoice = (BodyPartType)EditorGUILayout.EnumPopup(m_PartTypeChoice); if (m_ColliderPopup == null) { m_ColliderPopup = new LocalComponentPopup(typeof(Collider), false); } m_ColliderChoice = m_ColliderPopup.OnGUI( EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight * 1.1f), m_ColliderChoice, GUIContent.none, outfit.gameObject) as Collider; EditorGUILayout.EndHorizontal(); GUI.enabled = m_ColliderChoice; if (GUILayout.Button("Create Boby Part")) { if (m_ColliderChoice.gameObject.GetComponent <BodyPart>()) { Debug.LogError(m_ColliderChoice.name + " Already has a body part attached.", outfit); } else if (outfit.GetBodyPart(m_PartTypeChoice)) { Debug.LogError("Outfit already has a body part of type: " + m_PartTypeChoice, outfit); } else { // Note for prefabs: If there is a missing body part in the array before the action and the // user undoes the action, the mount point array may end up containing an invalid reference // to the prefab's asset. This appears to be some kind of prefab related bug. const string undoLabel = "Create Body Part"; Undo.IncrementCurrentGroup(); Undo.RecordObjects(Outfit.UnsafeGetUndoObjects(outfit).ToArray(), undoLabel); // For refresh. var bp = Undo.AddComponent <BodyPart>(m_ColliderChoice.gameObject); Undo.RecordObject(bp, undoLabel); bp.Collider = m_ColliderChoice; bp.PartType = m_PartTypeChoice; bp.Context = m_ContextChoice; StandardOutfit.UnsafeRefreshBodyParts(outfit); Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); m_ColliderChoice = null; } } GUI.enabled = true; EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(ApplyBodyPartContextLabel)) { string undoLabel = "Apply Body Part Context"; Undo.IncrementCurrentGroup(); Undo.RecordObjects(Outfit.UnsafeGetUndoObjects(outfit).ToArray(), undoLabel); outfit.ApplyBodyPartContext(m_ContextChoice); Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); } if (GUILayout.Button(RefreshBodyPartsLabel)) { Undo.RecordObject(outfit, "Refresh Body Parts"); StandardOutfit.UnsafeRefreshBodyParts(outfit, false); } if (GUILayout.Button(ResetBodyPartsLabel)) { Undo.RecordObject(outfit, "Reset Body Parts"); StandardOutfit.UnsafeClearBodyParts(outfit); } EditorGUILayout.EndHorizontal(); LizEditorGUIUtil.EndLabelWidth(); }