UIContentScalerEditor.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using UnityEditor;
  2. using FairyGUI;
  3. namespace FairyGUIEditor
  4. {
  5. /// <summary>
  6. ///
  7. /// </summary>
  8. [CustomEditor(typeof(UIContentScaler))]
  9. public class UIContentScalerEditor : Editor
  10. {
  11. SerializedProperty scaleMode;
  12. SerializedProperty screenMatchMode;
  13. SerializedProperty designResolutionX;
  14. SerializedProperty designResolutionY;
  15. SerializedProperty fallbackScreenDPI;
  16. SerializedProperty defaultSpriteDPI;
  17. SerializedProperty constantScaleFactor;
  18. SerializedProperty ignoreOrientation;
  19. string[] propertyToExclude;
  20. void OnEnable()
  21. {
  22. scaleMode = serializedObject.FindProperty("scaleMode");
  23. screenMatchMode = serializedObject.FindProperty("screenMatchMode");
  24. designResolutionX = serializedObject.FindProperty("designResolutionX");
  25. designResolutionY = serializedObject.FindProperty("designResolutionY");
  26. fallbackScreenDPI = serializedObject.FindProperty("fallbackScreenDPI");
  27. defaultSpriteDPI = serializedObject.FindProperty("defaultSpriteDPI");
  28. constantScaleFactor = serializedObject.FindProperty("constantScaleFactor");
  29. ignoreOrientation = serializedObject.FindProperty("ignoreOrientation");
  30. propertyToExclude = new string[] { "m_Script", "scaleMode", "screenMatchMode", "designResolutionX", "designResolutionY",
  31. "fallbackScreenDPI", "defaultSpriteDPI", "constantScaleFactor", "ignoreOrientation"};
  32. }
  33. public override void OnInspectorGUI()
  34. {
  35. serializedObject.Update();
  36. DrawPropertiesExcluding(serializedObject, propertyToExclude);
  37. EditorGUILayout.PropertyField(scaleMode);
  38. if ((UIContentScaler.ScaleMode)scaleMode.enumValueIndex == UIContentScaler.ScaleMode.ScaleWithScreenSize)
  39. {
  40. EditorGUILayout.PropertyField(designResolutionX);
  41. EditorGUILayout.PropertyField(designResolutionY);
  42. EditorGUILayout.PropertyField(screenMatchMode);
  43. EditorGUILayout.PropertyField(ignoreOrientation);
  44. }
  45. else if ((UIContentScaler.ScaleMode)scaleMode.enumValueIndex == UIContentScaler.ScaleMode.ConstantPhysicalSize)
  46. {
  47. EditorGUILayout.PropertyField(fallbackScreenDPI);
  48. EditorGUILayout.PropertyField(defaultSpriteDPI);
  49. }
  50. else
  51. EditorGUILayout.PropertyField(constantScaleFactor);
  52. if (serializedObject.ApplyModifiedProperties())
  53. (target as UIContentScaler).ApplyModifiedProperties();
  54. }
  55. }
  56. }