Last active
October 29, 2015 18:15
-
-
Save hiyorin/f797d024d03747424d30 to your computer and use it in GitHub Desktop.
特定の種類(拡張子)のファイルだけを設定したい
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class Example : MonoBehaviour | |
{ | |
[SerializeField, FilterFileExtension ("unity")] | |
private Object[] sceneFileList = new Object[] {}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class FilterFileExtensionAttribute : PropertyAttribute | |
{ | |
public string fileExtension = string.Empty; | |
public FilterFileExtensionAttribute (string fileExtension) | |
{ | |
this.fileExtension = fileExtension; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEngine; | |
using System.IO; | |
[CustomPropertyDrawer (typeof (FilterFileExtensionAttribute))] | |
public class FilterFileExtensionDrawer : PropertyDrawer | |
{ | |
public override float GetPropertyHeight (SerializedProperty property, GUIContent label) | |
{ | |
return EditorGUI.GetPropertyHeight(property, label, true); | |
} | |
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) | |
{ | |
FilterFileExtensionAttribute attr = attribute as FilterFileExtensionAttribute; | |
if (property.objectReferenceValue != null) | |
{ | |
string path = AssetDatabase.GetAssetPath (property.objectReferenceValue); | |
if (Path.GetExtension (path).Equals ("." + attr.fileExtension) == false) | |
{ | |
Debug.LogErrorFormat ("{0} is not {1}", property.objectReferenceValue.name, attr.fileExtension); | |
property.objectReferenceValue = null; | |
} | |
} | |
EditorGUI.PropertyField (position, property, label); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment