public static QuickPolygon LoadPreset(QuickPolygon polygon, string name, bool loadMesh = false, bool recalculate = true) { if (PresetsManager.IsPresetExists(name)) { PresetsManager.LoadPresetFor(name, polygon, loadMesh); } else { Debug.LogWarning(MSG.Warnings.PRESET_NOT_FOUND); } return(polygon); }
private void DrawPresetsSaveInspector() { // Don't allow saving presets if multiobject editing. if (!serializedObject.isEditingMultipleObjects) { PresetName = EditorGUILayout.TextField("Name", PresetName); if (PresetsManager.IsPresetExists(PresetName)) { if (GUILayout.Button("Update")) { if (!string.IsNullOrEmpty(PresetName)) { PresetsManager.SavePreset(PresetName, (QuickPolygon)targets[0]); PresetName = ""; GUI.FocusControl(null); } } } else { if (GUILayout.Button("Save")) { if (!string.IsNullOrEmpty(PresetName) && PresetName != "None") { PresetsManager.SavePreset(PresetName, (QuickPolygon)targets[0]); PresetName = ""; GUI.FocusControl(null); } } } if (!string.IsNullOrEmpty(((QuickPolygon)targets[0]).CurrentPresetName) && ((QuickPolygon)targets[0]).CurrentPresetName != "None" && PresetsManager.IsPresetExists(((QuickPolygon)targets[0]).CurrentPresetName)) { EditorGUILayout.LabelField("Selected", ((QuickPolygon)targets[0]).CurrentPresetName); if (GUILayout.Button("Update")) { if (!string.IsNullOrEmpty(((QuickPolygon)targets[0]).CurrentPresetName)) { PresetsManager.SavePreset(((QuickPolygon)targets[0]).CurrentPresetName, (QuickPolygon)targets[0]); GUI.FocusControl(null); } } } } else { EditorGUILayout.HelpBox(MSG.Warnings.PRESET_MULTIOBJECT_SAVING_DISABLED, MessageType.Info); } }
public static QuickPolygon CreateFromLastPreset(string name, MeshType meshIndex, Vector3 position, Quaternion rotation, bool isUI) { PresetsRecord lastPreset = PresetsManager.GetLastUsedPreset(); QuickPolygon mesh = Create(name, meshIndex, position, rotation, isUI); if (lastPreset != null && PresetsManager.IsPresetExists(lastPreset)) { PresetsManager.LoadPresetFor(lastPreset, mesh); } else { Debug.LogWarning(MSG.Warnings.PRESET_LAST_NOT_FOUND); } mesh.RecalculateMesh(); return(mesh); }
private void DrawPresetsLoadInspector() { // Check if all selected shapes share the same UI setup. bool allowMultiobjectLoading = true; bool isFirstShapeUI = ((QuickPolygon)targets[0]).IsUI; for (int i = 1; i < targets.Length && allowMultiobjectLoading; i++) { if (((QuickPolygon)targets[i]).IsUI != isFirstShapeUI) { allowMultiobjectLoading = false; } } if (allowMultiobjectLoading) { // Check if all selected shapes share the same selected preset. bool arePresetsMatching = true; string firstShapePresetName = ((QuickPolygon)targets[0]).CurrentPresetName; for (int i = 1; i < targets.Length && arePresetsMatching; i++) { if (((QuickPolygon)targets[i]).CurrentPresetName != firstShapePresetName) { arePresetsMatching = false; } } // Build popup options list. List <PresetsRecord> presets = PresetsManager.presetsContainer.PresetsGOList; if (presets.Any()) { string[] presetNames = presets.OrderBy(p => p.name).Select(p => p.name).ToArray(); string[] options = arePresetsMatching ? new string[] { "None" } : new string[] { "—", "None" }; options = options.Concat(presetNames).ToArray(); int selectedPreset = 0; if (arePresetsMatching) { selectedPreset = Array.IndexOf(options, firstShapePresetName); if (selectedPreset < 0) { selectedPreset = 0; ((QuickPolygon)targets[0]).CurrentPresetName = ""; } } int newPreset = EditorGUILayout.Popup("Load", selectedPreset, options); if (newPreset != selectedPreset && options[newPreset] != "—" && options[newPreset] != "None") { // Load the preset for all of the targets. Undo.RecordObjects(targets, "Preset Load"); for (int i = 0; i < targets.Length; i++) { PresetsManager.LoadPresetFor(options[newPreset], (QuickPolygon)targets[i]); } } if (options[newPreset] == "None") { for (int i = 0; i < targets.Length; i++) { ((QuickPolygon)targets[i]).CurrentPresetName = "None"; } } SerializedProperty allowLoadGeometryProp = serializedObject.FindProperty("AllowLoadPresetGeometry"); allowLoadGeometryProp.boolValue = GUILayout.Toggle(allowLoadGeometryProp.boolValue, "Load Mesh", "Button"); if (options[selectedPreset] != "—" && options[selectedPreset] != "None") { if (GUILayout.Button("Delete")) { for (int i = 0; i < targets.Length; i++) { if (((QuickPolygon)targets[i]).CurrentPresetName == options[selectedPreset]) { ((QuickPolygon)targets[i]).CurrentPresetName = "None"; } } PresetsManager.DeletePreset(options[selectedPreset]); } } } } else { EditorGUILayout.HelpBox(MSG.Warnings.PRESET_MULTIOBJECT_LOADING_DISABLED, MessageType.Info); } }
private void Awake() { RefreshTargets(); PresetsManager.RefreshPresetContainer(); HideScriptIcon(false); }
public void SaveAsPreset(string name) { CurrentPresetName = name; PresetsManager.SavePreset(CurrentPresetName, this); }