Tanoda
LeapMesherBaseDrawer.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.Collections;
10using System.Collections.Generic;
11using UnityEngine;
12using UnityEditor;
13using Leap.Unity.Query;
14
16
17 [CustomPropertyDrawer(typeof(LeapMesherBase), useForChildren: true)]
19 private const float HEADER_HEADROOM = 8;
20 private const float MESH_LABEL_WIDTH = 100.0f;
21 private const float REFRESH_BUTTON_WIDTH = 100;
22
23 private static float SHADER_WARNING_HEIGHT = 40;
24 private static float SHADER_WARNING_FIX_WIDTH = 50;
25
26 private SerializedProperty _uv0, _uv1, _uv2, _uv3, _colors, _bakedTint, _normals;
27
28 protected override void init(SerializedProperty property) {
29 base.init(property);
30
31 _uv0 = property.FindPropertyRelative("_useUv0");
32 _uv1 = property.FindPropertyRelative("_useUv1");
33 _uv2 = property.FindPropertyRelative("_useUv2");
34 _uv3 = property.FindPropertyRelative("_useUv3");
35 _colors = property.FindPropertyRelative("_useColors");
36 _bakedTint = property.FindPropertyRelative("_bakedTint");
37 _normals = property.FindPropertyRelative("_useNormals");
38
39 drawCustom(rect => {
40 rect.y += HEADER_HEADROOM;
41 EditorGUI.LabelField(rect, "Mesh Settings", EditorStyles.boldLabel);
42 }, HEADER_HEADROOM + EditorGUIUtility.singleLineHeight);
43
45
46 drawCustom(rect => {
47 Rect left, right;
48 rect.SplitHorizontally(out left, out right);
49 EditorGUI.PropertyField(left, _uv0);
50 EditorGUI.PropertyField(right, _uv1);
51 }, EditorGUIUtility.singleLineHeight);
52
53 drawCustom(rect => {
54 Rect left, right;
55 rect.SplitHorizontally(out left, out right);
56 EditorGUI.PropertyField(left, _uv2);
57 EditorGUI.PropertyField(right, _uv3);
58 }, EditorGUIUtility.singleLineHeight);
59
60 drawCustom(rect => {
61 Rect left, right;
62 rect.SplitHorizontally(out left, out right);
63 EditorGUI.PropertyField(left, _colors);
64 if (_colors.boolValue) {
65 EditorGUI.PropertyField(right, _bakedTint);
66 }
67 }, EditorGUIUtility.singleLineHeight);
68
69 drawCustom(rect => {
70 Rect left, right;
71 rect.SplitHorizontally(out left, out right);
72 EditorGUI.PropertyField(left, _normals);
73 }, EditorGUIUtility.singleLineHeight);
74
76
77 drawCustom(rect => {
78 rect.y += HEADER_HEADROOM;
79 rect.height = EditorGUIUtility.singleLineHeight;
80 EditorGUI.LabelField(rect, "Rendering Settings", EditorStyles.boldLabel);
81 }, HEADER_HEADROOM + EditorGUIUtility.singleLineHeight);
82
84
85 SerializedProperty shaderProp;
86 tryGetProperty("_shader", out shaderProp);
87
88 drawCustom(rect => {
89 if (!shaderProp.hasMultipleDifferentValues) {
90 Shader shader = shaderProp.objectReferenceValue as Shader;
91 if (VariantEnabler.DoesShaderHaveVariantsDisabled(shader)) {
92 Rect left, right;
93 rect.SplitHorizontallyWithRight(out left, out right, SHADER_WARNING_FIX_WIDTH);
94
95 EditorGUI.HelpBox(left, "This shader has disabled variants, and will not function until they are enabled.", MessageType.Warning);
96 if (GUI.Button(right, "Enable")) {
97 if (EditorUtility.DisplayDialog("Import Time Warning!", "The import time for this surface shader can take up to 2-3 minutes! Are you sure you want to enable?", "Enable", "Not right now")) {
98 VariantEnabler.SetShaderVariantsEnabled(shader, enable: true);
99 AssetDatabase.Refresh();
100 }
101 }
102 }
103 }
104 },
105 () => {
106 Shader shader = shaderProp.objectReferenceValue as Shader;
107 if (VariantEnabler.DoesShaderHaveVariantsDisabled(shader)) {
108 return SHADER_WARNING_HEIGHT;
109 } else {
110 return 0;
111 }
112 });
113
114 drawProperty("_shader");
115 drawProperty("_visualLayer", includeChildren: true, disable: EditorApplication.isPlaying);
116 drawProperty("_atlas", includeChildren: true, disable: EditorApplication.isPlaying);
117 }
118 }
119}
void drawProperty(string name, bool includeChildren=true, bool disable=false)
void drawCustom(Action< Rect > drawFunc, float height)
bool tryGetProperty(string name, out SerializedProperty property)
override void init(SerializedProperty property)