Tanoda
BuildDefinitionEditor.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 System.Linq;
11using UnityEngine;
12using UnityEditor;
13
14namespace Leap.Unity.Packaging {
15
16 [CustomEditor(typeof(BuildDefinition))]
17 public class BuildDefinitionEditor : DefinitionBaseEditor<BuildDefinition> {
18
19 protected override void OnEnable() {
20 base.OnEnable();
21
22 specifyCustomDecorator("_options", prop => drawExportFolder(prop, "Build", "Build Folder"));
23 specifyCustomDrawer("_options", drawOptions);
24
25 specifyCustomDecorator("_playerSettings", decorateBuildPlayerSettings);
26 specifyCustomPostDecorator("_playerSettings", postDecorateBuildPlayerSettings);
27
28 createList("_scenes", drawScene);
29 createList("_targets", drawBuildTarget);
30 }
31
32 protected override void OnBuild() {
33 target.Build();
34 }
35
36 protected override int GetBuildMenuPriority() {
37 return 20;
38 }
39
40 protected override string GetBuildMethodName() {
41 return "Build";
42 }
43
44 private void drawScene(Rect rect, SerializedProperty property) {
45 float originalWidth = EditorGUIUtility.labelWidth;
46 EditorGUIUtility.labelWidth *= 0.2f;
47
48 string label = new string(property.displayName.Where(c => char.IsDigit(c)).ToArray());
49 EditorGUI.PropertyField(rect, property, new GUIContent(label));
50
51 EditorGUIUtility.labelWidth = originalWidth;
52 }
53
54 private void drawBuildTarget(Rect rect, SerializedProperty property) {
55 EditorGUI.PropertyField(rect, property, GUIContent.none);
56 }
57
58 private void drawOptions(SerializedProperty prop) {
59 EditorGUILayout.BeginHorizontal();
60
61 EditorGUILayout.PropertyField(prop);
62
63 if (GUILayout.Button("Debug", GUILayout.ExpandWidth(false))) {
64 prop.intValue = (int)(BuildOptions.AllowDebugging |
65 BuildOptions.ConnectWithProfiler |
66 BuildOptions.Development |
67 BuildOptions.ForceEnableAssertions);
68 }
69
70 EditorGUILayout.EndHorizontal();
71 }
72
73 private void decorateBuildPlayerSettings(SerializedProperty prop) {
74 var shouldDisable =
75 !serializedObject.FindProperty("_useSpecificPlayerSettings").boolValue;
76
77 EditorGUI.BeginDisabledGroup(shouldDisable);
78 }
79 private void postDecorateBuildPlayerSettings(SerializedProperty prop) {
80 EditorGUI.EndDisabledGroup();
81 }
82 }
83}
ReorderableList createList(string propertyName, Action< Rect, SerializedProperty > drawMethod)
void drawExportFolder(SerializedProperty prop, string buildText, string label)