private void SaveAsCallback() { string path = EditorUtility.SaveFilePanel("Save Noise Settings", Application.dataPath, "New Noise Settings.asset", "asset"); // saving to project's asset folder if (path.StartsWith(Application.dataPath)) { // TODO(wyatt): need to check if this works with different locales/languages. folder might not be // called "Assets" in non-English Editor builds string assetPath = path.Substring(Application.dataPath.Length - 6); // settingsProfile = NoiseSettings.CreateAsset(assetPath, noiseSettings); var asset = NoiseSettingsFactory.CreateAsset(assetPath); asset.CopySerialized(m_noiseUpdateTarget); } // saving asset somewhere else. why? dunno! else if (!string.IsNullOrEmpty(path)) { Debug.LogError("Invalid path specified for creation of new Noise Settings asset. Must be a valid path within the current Unity project's Assets folder/data path."); } }
private void DoNoiseSettingsObjectField() { bool profileInUse = m_activeNoiseSettingsProfile != null; float buttonWidth = 60; float indentOffset = EditorGUI.indentLevel * 15f; Rect lineRect = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight); Rect labelRect = new Rect(lineRect.x, lineRect.y, EditorGUIUtility.labelWidth - indentOffset, lineRect.height); Rect fieldRect = new Rect(labelRect.xMax, lineRect.y, lineRect.width - labelRect.width - buttonWidth * (profileInUse ? 3 : 2), lineRect.height); Rect resetButtonRect = new Rect(fieldRect.xMax, lineRect.y, buttonWidth, lineRect.height); Rect saveButtonRect = new Rect(resetButtonRect.xMax, lineRect.y, buttonWidth, lineRect.height); Rect saveAsButtonRect = new Rect(profileInUse ? saveButtonRect.xMax : resetButtonRect.xMax, lineRect.y, buttonWidth, lineRect.height); EditorGUI.PrefixLabel(labelRect, Styles.noiseSettingsProfile); NoiseSettings settingsProfile = m_activeNoiseSettingsProfile; settingsProfile = (NoiseSettings)EditorGUI.ObjectField(fieldRect, settingsProfile, typeof(NoiseSettings), false); if (m_activeNoiseSettingsProfile != null) { if (GUI.Button(resetButtonRect, Styles.revert)) { Undo.RecordObject(noiseSettings, "Noise Settings - Revert"); noiseSettings.Copy(m_activeNoiseSettingsProfile); } } else { if (GUI.Button(resetButtonRect, Styles.reset)) { Undo.RecordObject(noiseSettings, "Noise Settings - Reset"); noiseSettings.Reset(); } } if (profileInUse && GUI.Button(saveButtonRect, Styles.apply)) { Undo.RecordObject(m_activeNoiseSettingsProfile, "NoiseHeightTool - Apply Settings"); m_activeNoiseSettingsProfile.CopySerialized(noiseSettings); } if (GUI.Button(saveAsButtonRect, Styles.saveAs)) { string path = EditorUtility.SaveFilePanel("Save Noise Settings", Application.dataPath, "New Noise Settings.asset", "asset"); // saving to project's asset folder if (path.StartsWith(Application.dataPath)) { // TODO(wyatt): need to check if this works with different locales/languages. folder might not be // called "Assets" in non-English Editor builds string assetPath = path.Substring(Application.dataPath.Length - 6); // settingsProfile = NoiseSettings.CreateAsset(assetPath, noiseSettings); settingsProfile = NoiseSettingsFactory.CreateAsset(assetPath); settingsProfile.CopySerialized(noiseSettings); } // saving asset somewhere else. why? dunno! else if (!string.IsNullOrEmpty(path)) { Debug.LogError("Invalid path specified for creation of new Noise Settings asset. Must be a valid path within the current Unity project's Assets folder/data path."); } } // check if the profile in the object field changed bool changed = settingsProfile != m_activeNoiseSettingsProfile; if (changed) { if (settingsProfile == null) { noiseSettings.Copy(noiseSettingsIfNull); } else { if (m_activeNoiseSettingsProfile == null) { noiseSettingsIfNull.Copy(noiseSettings); } noiseSettings.Copy(settingsProfile); } noiseSettingsGUI.Init(noiseSettings); m_activeNoiseSettingsProfile = settingsProfile; } GUILayout.Space(12); }