private void AssetFieldWithCreateButton( SerializedProperty property, string title, string defaultName, string extension, string message) { EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(property); if (GUILayout.Button(m_CreateButtonGUIContent, GUILayout.ExpandWidth(false), GUILayout.MaxHeight(EditorGUIUtility.singleLineHeight))) { string newAssetPath = EditorUtility.SaveFilePanelInProject( title, defaultName, extension, message); if (!string.IsNullOrEmpty(newAssetPath)) { T asset = ScriptableObjectUtility.CreateAt <T>(newAssetPath); property.objectReferenceValue = asset; m_Owner.serializedObject.ApplyModifiedProperties(); } } EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { m_Owner.serializedObject.ApplyModifiedProperties(); UpdateEditor(); } }
private void AssetFieldWithCreateButton( SerializedProperty property, string title, string defaultName, string extension, string message) { EditorGUI.BeginChangeCheck(); float hSpace = 5; float buttonWidth = GUI.skin.button.CalcSize(m_CreateButtonGUIContent).x; Rect r = EditorGUILayout.GetControlRect(true); r.width -= buttonWidth + hSpace; EditorGUI.PropertyField(r, property); r.x += r.width + hSpace; r.width = buttonWidth; if (GUI.Button(r, m_CreateButtonGUIContent)) { string newAssetPath = EditorUtility.SaveFilePanelInProject( title, defaultName, extension, message); if (!string.IsNullOrEmpty(newAssetPath)) { T asset = ScriptableObjectUtility.CreateAt <T>(newAssetPath); property.objectReferenceValue = asset; m_Owner.serializedObject.ApplyModifiedProperties(); } } if (EditorGUI.EndChangeCheck()) { m_Owner.serializedObject.ApplyModifiedProperties(); UpdateEditor(property); } }
NoiseSettings CreateProfile(SerializedProperty property, string label, NoiseSettings copyFrom) { string path = GetObjectName(property) + " " + label; path = EditorUtility.SaveFilePanelInProject( "Create Noise Profile asset", path, "asset", "This asset will generate a procedural noise signal"); if (!string.IsNullOrEmpty(path)) { NoiseSettings profile = null; if (copyFrom != null) { string fromPath = AssetDatabase.GetAssetPath(copyFrom); if (AssetDatabase.CopyAsset(fromPath, path)) { profile = AssetDatabase.LoadAssetAtPath( path, typeof(NoiseSettings)) as NoiseSettings; } } else { profile = ScriptableObjectUtility.CreateAt( typeof(NoiseSettings), path) as NoiseSettings; } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); return(profile); } return(null); }
ScriptableObject CreateAsset( Type assetType, ScriptableObject copyFrom, string defaultName, string dialogTitle) { ScriptableObject asset = null; string path = EditorUtility.SaveFilePanelInProject( dialogTitle, defaultName, "asset", string.Empty); if (!string.IsNullOrEmpty(path)) { if (copyFrom != null) { string fromPath = AssetDatabase.GetAssetPath(copyFrom); if (AssetDatabase.CopyAsset(fromPath, path)) { asset = AssetDatabase.LoadAssetAtPath(path, assetType) as ScriptableObject; } } else { asset = ScriptableObjectUtility.CreateAt(assetType, path); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } return(asset); }
ScriptableObject CreateAsset(Type assetType, string defaultName, string dialogTitle) { ScriptableObject asset = null; string newAssetPath = EditorUtility.SaveFilePanelInProject( dialogTitle, defaultName, "asset", string.Empty); if (!string.IsNullOrEmpty(newAssetPath)) { asset = ScriptableObjectUtility.CreateAt(assetType, newAssetPath); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } return(asset); }