Tanoda
LeapSpriteDataDrawer.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using System;
10using UnityEngine;
11using UnityEditor;
12
14
15 [CustomPropertyDrawer(typeof(LeapSpriteData))]
17
18 protected override void init(SerializedProperty property) {
19 base.init(property);
20
22 Func<string> nameFunc = () => {
23 if (channelFeature == null) {
24 return null;
25 } else {
26 return channelFeature.propertyName;
27 }
28 };
29
30 var spriteProp = property.FindPropertyRelative("_sprite");
31
32 drawCustom(rect => {
33 if (rect.height != 0) {
34 var indentedRect = EditorGUI.IndentedRect(rect);
35 EditorGUI.HelpBox(indentedRect, "Sprite is not packed!", MessageType.Error);
36 }
37 }, () => {
38 Sprite sprite = spriteProp.objectReferenceValue as Sprite;
39 if (sprite != null && !sprite.packed) {
40 return EditorGUIUtility.singleLineHeight * 2;
41 } else {
42 return 0;
43 }
44 });
45
46 drawProperty("_sprite", nameFunc);
47 }
48 }
49}
void drawProperty(string name, bool includeChildren=true, bool disable=false)
void drawCustom(Action< Rect > drawFunc, float height)
override void init(SerializedProperty property)