/// <summary> /// draws a check box to toggle persist state ON / OFF for a /// component. will be disabled if the 'Default' state has /// been overridden /// </summary> public static void PersistToggle(vp_AIComponentPersister persister) { bool oldPersistState = persister.Component.Persist; GUI.color = Color.white; if (persister.Component.DefaultState.TextAsset != null) { persister.Component.Persist = false; GUI.color = m_ColorTransparentWhite; } persister.Component.Persist = vp_EditorGUIUtility.SmallToggle("Persist Play Mode Changes", persister.Component.Persist); if (persister.Component.DefaultState.TextAsset != null && persister.Component.Persist == true) { string s = "Can't Persist Play Mode Changes when the 'Default' state has been overridden with a text file preset."; if (!Application.isPlaying) { s += "\n\nClick 'Unlock' to reenable inspector changes to this component."; } vp_MessageBox.Create(vp_MessageBox.Mode.OK, "Locked", s); persister.Component.Persist = false; } if (oldPersistState != persister.Component.Persist) { persister.Persist(); } GUI.color = Color.white; }
/// <summary> /// draws a field allowing the user to create, reorganize, /// name, assign presets to and delete states on a component /// </summary> public static bool StateFoldout(bool foldout, vp_AIComponent component, List <vp_AIState> stateList, vp_AIComponentPersister persister = null) { bool before = foldout; foldout = EditorGUILayout.Foldout(foldout, (foldout && !Application.isPlaying) ? "State Preset" : "States" ); if (foldout != before) { m_ShowBlockListFor = null; component.RefreshDefaultState(); } if (foldout) { if (m_ShowBlockListFor != null) { if (!stateList.Contains(m_ShowBlockListFor)) { foldout = false; } } } if (foldout) { for (int v = 0; v < stateList.Count; v++) { vp_AIState s = stateList[v]; if (!Application.isPlaying) { vp_AIPresetEditorGUIUtility.StateField(s, stateList, component); if ((m_ShowBlockListFor != null) && m_ShowBlockListFor == s) { StateBlockList(component, s); } } else { vp_AIPresetEditorGUIUtility.RunTimeStateField(component, s, stateList); } } GUILayout.BeginHorizontal(); if (!Application.isPlaying) { if (GUILayout.Button("Add State", GUILayout.MinWidth(90), GUILayout.MaxWidth(90))) { m_ShowBlockListFor = null; string newStateName = "Untitled"; int n = 1; while (GetStateId(component, newStateName) != -1) { n++; newStateName = newStateName.Substring(0, 8) + (n < 10?"0":"") + n.ToString(); } stateList.Add(new vp_AIState(component.GetType().Name, newStateName, "")); component.RefreshDefaultState(); EditorUtility.SetDirty(component); } } else { GUI.color = Color.clear; GUILayout.Button("", GUILayout.MinWidth(36), GUILayout.MaxWidth(36)); GUI.color = Color.white; } if (!Application.isPlaying) { GUILayout.EndHorizontal(); } if (persister != null) { vp_AIPresetEditorGUIUtility.PersistToggle(persister); } if (Application.isPlaying) { GUILayout.EndHorizontal(); } vp_EditorGUIUtility.Separator(); } return(foldout); }