RangedTooltipDrawer.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. Copyright 2014 Google Inc. All rights reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * Custom Property Drawer for Ranged inspector properties that also
  15. * have a tooltip
  16. *
  17. **/
  18. @CustomPropertyDrawer(RangedTooltipAttribute)
  19. class RangedTooltipDrawer extends PropertyDrawer {
  20. // Draw the property inside the given rect
  21. function OnGUI(position : Rect, property : SerializedProperty,
  22. label : GUIContent) {
  23. // First get the attribute since it contains the range for the slider
  24. var range : RangedTooltipAttribute = attribute as RangedTooltipAttribute;
  25. var content = new GUIContent(label.text, range.text);
  26. if (property.propertyType == SerializedPropertyType.Float) {
  27. EditorGUI.Slider(position, property, range.min, range.max, content);
  28. } else if (property.propertyType == SerializedPropertyType.Integer) {
  29. EditorGUI.IntSlider(position, property, range.min, range.max, content);
  30. } else {
  31. EditorGUI.LabelField(position, label.text,
  32. 'Use Range with float or int.');
  33. }
  34. }
  35. }