示例#1
0
        static void DrawLandmarkOutputDropdownButton(Component currentOutput, LandmarkController landmarkController)
        {
            using (new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.PrefixLabel(k_OutputTypeLabel);
                var buttonLabel = ObjectNames.NicifyVariableName(currentOutput != null ? TrimLandmarkOutputName(currentOutput.GetType().Name) : k_OutputDropdownButtonDefaultLabel);

                if (EditorGUILayout.DropdownButton(new GUIContent(buttonLabel), FocusType.Keyboard))
                {
                    var menu       = new GenericMenu();
                    var definition = landmarkController.landmarkDefinition;
                    if (definition != null)
                    {
                        foreach (var outputType in definition.outputTypes)
                        {
                            var showChecked    = currentOutput != null && currentOutput.GetType() == outputType;
                            var outputTypeName = TrimLandmarkOutputName(outputType.Name);
                            menu.AddItem(new GUIContent(outputTypeName), showChecked, () =>
                            {
                                Undo.RegisterFullObjectHierarchyUndo(landmarkController.gameObject, k_ModifyUndoLabel);
                                landmarkController.SetOutputType(outputType);
                            });
                        }

                        menu.ShowAsContext();
                    }
                }
            }
        }
示例#2
0
        static void DrawOutputInfo(SerializedProperty outputProperty, LandmarkController landmarkController)
        {
            EditorGUILayout.PropertyField(outputProperty);
            var output          = outputProperty.objectReferenceValue as Component;
            var validOutputType = false;
            var definition      = landmarkController.landmarkDefinition;

            if (definition == null)
            {
                return;
            }

            if (output != null && definition.outputTypes != null)
            {
                var currentOutputType = output.GetType();
                foreach (var validType in definition.outputTypes)
                {
                    if (validType == currentOutputType)
                    {
                        validOutputType = true;
                    }
                }
            }

            if (!validOutputType)
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    EditorGUILayout.HelpBox("Output component is invalid.", MessageType.Error);
                    if (GUILayout.Button(styles.addDefaultCompButtonContent, GUILayout.Height(k_AddDefaultComponentButtonHeight)))
                    {
                        EditorApplication.delayCall += () =>
                        {
                            Undo.RegisterFullObjectHierarchyUndo(landmarkController.gameObject, k_ModifyUndoLabel);
                            landmarkController.SetOutputType(definition.outputTypes[0]);
                        };
                    }
                }
            }
        }