public void Initialize(AppBar newParentToolBar, AppBar.ButtonTemplate newTemplate, ButtonIconProfile newCustomProfile)
        {
            template          = newTemplate;
            customIconProfile = newCustomProfile;
            parentToolBar     = newParentToolBar;

            cButton = GetComponent <CompoundButton>();
            cButton.MainRenderer.enabled = false;
            text                  = GetComponent <CompoundButtonText>();
            text.Text             = template.Text;
            icon                  = GetComponent <CompoundButtonIcon>();
            highlightMeshRenderer = cButton.GetComponent <CompoundButtonMesh>().Renderer;

            if (customIconProfile != null)
            {
                icon.Profile  = customIconProfile;
                icon.IconName = string.Empty;
            }
            icon.IconName = template.Icon;
            initialized   = true;
            Hide();

            if (newTemplate.EventTarget != null)
            {
                // Register the button with its target interactable
                newTemplate.EventTarget.Registerinteractable(gameObject);
            }
            else
            {
                // Register the button with the parent app bar
                newParentToolBar.Registerinteractable(gameObject);
            }
        }
Example #2
0
        public void Initialize(AppBar newParentToolBar, AppBar.ButtonTemplate newTemplate, ButtonIconProfile newCustomProfile)
        {
            // TODO move this into the tag manager
            VisibleFilterTag     = new FilterTag();
            VisibleFilterTag.Tag = "Default";
            HiddenFilterTag      = new FilterTag();
            HiddenFilterTag.Tag  = "Hidden";

            template          = newTemplate;
            customIconProfile = newCustomProfile;
            parentToolBar     = newParentToolBar;

            cButton = GetComponent <CompoundButton>();
            cButton.MainRenderer.enabled = false;
            text      = GetComponent <CompoundButtonText>();
            text.Text = template.Text;
            icon      = GetComponent <CompoundButtonIcon>();
            if (customIconProfile != null)
            {
                icon.IconProfile = customIconProfile;
                icon.IconName    = string.Empty;
            }
            icon.IconName = template.Icon;
            initialized   = true;
            Hide();
        }
Example #3
0
        private void CreateButton(ButtonTemplate template, ButtonIconProfile customIconProfile)
        {
            if (template.IsEmpty)
            {
                return;
            }

            switch (template.Type)
            {
            case ButtonTypeEnum.Custom:
                numDefaultButtons++;
                break;

            case ButtonTypeEnum.Adjust:
                numDefaultButtons++;
                break;

            case ButtonTypeEnum.Done:
                numManipulationButtons++;
                break;

            case ButtonTypeEnum.Remove:
                numManipulationButtons++;
                numDefaultButtons++;
                break;

            //AS
            case ButtonTypeEnum.Reset:
                numManipulationButtons++;
                numDefaultButtons++;
                break;
            //

            case ButtonTypeEnum.Hide:
                numDefaultButtons++;
                break;

            case ButtonTypeEnum.Show:
                numHiddenButtons++;
                break;
            }

            GameObject newButton = GameObject.Instantiate(SquareButtonPrefab, buttonParent);

            newButton.name = template.Name;
            newButton.transform.localPosition = Vector3.zero;
            newButton.transform.localRotation = Quaternion.identity;
            AppBarButton mtb = newButton.AddComponent <AppBarButton>();

            mtb.Initialize(this, template, customIconProfile);
        }
Example #4
0
        public void Initialize(AppBar newParentToolBar, AppBar.ButtonTemplate newTemplate, ButtonIconProfile newCustomProfile)
        {
            // TODO move this into the tag manager
            VisibleFilterTag     = new FilterTag();
            VisibleFilterTag.Tag = "Default";
            HiddenFilterTag      = new FilterTag();
            HiddenFilterTag.Tag  = "Hidden";

            template          = newTemplate;
            customIconProfile = newCustomProfile;
            parentToolBar     = newParentToolBar;

            cButton = GetComponent <CompoundButton>();
            cButton.MainRenderer.enabled = false;
            text      = GetComponent <CompoundButtonText>();
            text.Text = template.Text;
            icon      = GetComponent <CompoundButtonIcon>();
            if (customIconProfile != null)
            {
                icon.Profile  = customIconProfile;
                icon.IconName = string.Empty;
            }
            icon.IconName = template.Icon;
            initialized   = true;
            Hide();

            if (newTemplate.EventTarget != null)
            {
                // Register the button with its target interactable
                newTemplate.EventTarget.RegisterInteractible(gameObject);
            }
            else
            {
                // Register the button with the parent app bar
                newParentToolBar.RegisterInteractible(gameObject);
            }
        }
Example #5
0
        public override void OnInspectorGUI()
        {
            AppBar appBar = (AppBar)target;

            appBar.DisplayType = (AppBar.AppBarDisplayTypeEnum)EditorGUILayout.EnumPopup("Display Type", appBar.DisplayType);

            if (appBar.DisplayType == AppBar.AppBarDisplayTypeEnum.Manipulation)
            {
                HUXEditorUtils.BeginSectionBox("Bounding box");
                appBar.BoundingBox = HUXEditorUtils.SceneObjectField <BoundingBoxManipulate>(null, appBar.BoundingBox);
                if (appBar.BoundingBox == null)
                {
                    HUXEditorUtils.WarningMessage("Manipulation state will not function correctly at runtime without a bounding box. (If you're using BoundingBoxTarget this is not a problem.)");
                }
                HUXEditorUtils.EndSectionBox();
            }

            HUXEditorUtils.BeginSectionBox("App bar options");
            appBar.HoverOffsetYScale  = EditorGUILayout.Slider("Hover Offset (Y)", appBar.HoverOffsetYScale, -1f, 2f);
            appBar.HoverOffsetZ       = EditorGUILayout.Slider("Hover Offset (Z)", appBar.HoverOffsetZ, 0f, 2f);
            appBar.SquareButtonPrefab = (GameObject)EditorGUILayout.ObjectField("Button Prefab", appBar.SquareButtonPrefab, typeof(GameObject));
            GUI.color = (appBar.CustomButtonIconProfile == null) ? HUXEditorUtils.DisabledColor : HUXEditorUtils.DefaultColor;
            appBar.CustomButtonIconProfile = (ButtonIconProfile)EditorGUILayout.ObjectField("Custom Icon Profile", appBar.CustomButtonIconProfile, typeof(ButtonIconProfile));
            HUXEditorUtils.DrawSubtleMiniLabel("(Leave blank to use the button's default profile)");
            GUI.color = HUXEditorUtils.DefaultColor;

            if (appBar.SquareButtonPrefab == null)
            {
                HUXEditorUtils.ErrorMessage("You must specify a button prefab");
                HUXEditorUtils.EndSectionBox();
                return;
            }

            CompoundButtonIcon icon = appBar.SquareButtonPrefab.GetComponent <CompoundButtonIcon>();

            if (icon == null)
            {
                HUXEditorUtils.ErrorMessage("You must use a button prefab that has a CompoundButtonIcon component");
                HUXEditorUtils.EndSectionBox();
                return;
            }

            HUXEditorUtils.BeginSubSectionBox("Default buttons");
            GUI.color        = appBar.UseHide ? HUXEditorUtils.DefaultColor : HUXEditorUtils.DisabledColor;
            appBar.UseHide   = EditorGUILayout.Toggle("Show / Hide Buttons", appBar.UseHide);
            GUI.color        = appBar.UseAdjust ? HUXEditorUtils.DefaultColor : HUXEditorUtils.DisabledColor;
            appBar.UseAdjust = EditorGUILayout.Toggle("Adjust / Done Buttons", appBar.UseAdjust);
            GUI.color        = appBar.UseRemove ? HUXEditorUtils.DefaultColor : HUXEditorUtils.DisabledColor;
            appBar.UseRemove = EditorGUILayout.Toggle("Remove Button", appBar.UseRemove);
            GUI.color        = HUXEditorUtils.DefaultColor;
            HUXEditorUtils.EndSubSectionBox();

            HUXEditorUtils.BeginSubSectionBox("Custom buttons");
            HUXEditorUtils.DrawSubtleMiniLabel("Up to " + AppBar.MaxCustomButtons + " allowed. Un-named buttons will be ignored.");
            //HUXEditorUtils.DrawProfileField <ButtonIconProfile> (appBar.CustomButtonIconProfile)

            // Get the profile we'll be using for our icons
            ButtonIconProfile profile = appBar.CustomButtonIconProfile;

            if (profile == null)
            {
                profile = icon.Profile;
                if (profile == null)
                {
                    HUXEditorUtils.ErrorMessage("The button prefab does not specify an icon profile. Can't continue.");
                    HUXEditorUtils.EndSectionBox();
                    return;
                }
            }

            AppBar.ButtonTemplate[] buttons = appBar.Buttons;
            if (buttons.Length != AppBar.MaxCustomButtons)
            {
                System.Array.Resize <AppBar.ButtonTemplate>(ref buttons, AppBar.MaxCustomButtons);
            }
            int numCustomButtons = appBar.UseHide ? 0 : -1;

            for (int i = 0; i < buttons.Length; i++)
            {
                buttons[i] = DrawButtonEditor(buttons[i], profile, ref numCustomButtons, "buttons", i);
            }
            appBar.Buttons = buttons;
            HUXEditorUtils.EndSubSectionBox();

            // Force the buttons to refresh based on the options we've specified
            appBar.EditorRefreshTemplates();

            HUXEditorUtils.BeginSubSectionBox("App bar preview");
            HUXEditorUtils.DrawSubtleMiniLabel("An approximation of what the final bar will look like. 'Hidden' and 'Manipulation' states depend on default button settings and may not be available.");
            previewState = (AppBar.AppBarStateEnum)EditorGUILayout.EnumPopup(previewState);
            List <AppBar.ButtonTemplate> buttonList = new List <AppBar.ButtonTemplate>();

            buttonList.AddRange(appBar.DefaultButtons);
            buttonList.AddRange(buttons);

            if (previewState == AppBar.AppBarStateEnum.Default)
            {
                buttonList.Sort(delegate(AppBar.ButtonTemplate b1, AppBar.ButtonTemplate b2) { return(b1.DefaultPosition.CompareTo(b2.DefaultPosition)); });
            }
            else
            {
                buttonList.Sort(delegate(AppBar.ButtonTemplate b1, AppBar.ButtonTemplate b2) { return(b1.ManipulationPosition.CompareTo(b2.ManipulationPosition)); });
            }


            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, false, false, GUILayout.MaxHeight(previewButtonSize + 15f));
            EditorGUILayout.BeginHorizontal();
            bool drewOneButton = false;

            for (int i = 0; i < buttonList.Count; i++)
            {
                drewOneButton |= DrawPreviewButton(buttonList[i], previewState, appBar.UseHide, appBar.UseAdjust, appBar.UseRemove);
            }
            if (!drewOneButton)
            {
                HUXEditorUtils.WarningMessage("This state has no buttons due to the options you've chosen. It won't be permitted during play mode.");
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndScrollView();

            HUXEditorUtils.EndSubSectionBox();

            HUXEditorUtils.EndSectionBox();

            HUXEditorUtils.SaveChanges(appBar);
        }
Example #6
0
        private AppBar.ButtonTemplate DrawButtonEditor(AppBar.ButtonTemplate template, ButtonIconProfile profile, ref int numCustomButtons, string arrayName, int templateIndex)
        {
            // Set the button's position immediately
            template.DefaultPosition = 0;
            if (!template.IsEmpty)
            {
                numCustomButtons++;
                template.DefaultPosition = numCustomButtons;
            }

            HUXEditorUtils.BeginSectionBox(template.IsEmpty ? "(Empty)" : template.Name + " (" + template.DefaultPosition + ")", HUXEditorUtils.ObjectColor);
            template.Type = AppBar.ButtonTypeEnum.Custom;
            GUI.color     = template.IsEmpty ? HUXEditorUtils.DisabledColor : HUXEditorUtils.DefaultColor;
            EditorGUILayout.BeginHorizontal();
            template.Name = EditorGUILayout.TextField("Button Name", template.Name);
            if (GUILayout.Button("Clear", EditorStyles.miniButton))
            {
                template.Name = string.Empty;
            }
            EditorGUILayout.EndHorizontal();
            if (!template.IsEmpty)
            {
                if (string.IsNullOrEmpty(template.Text))
                {
                    GUI.color = HUXEditorUtils.WarningColor;
                }
                template.Text = EditorGUILayout.TextField("Label Text", template.Text);
                GUI.color     = HUXEditorUtils.DefaultColor;
                string[] keys          = profile.GetIconKeys().ToArray();
                int      selectedIndex = 0;
                for (int i = 0; i < keys.Length; i++)
                {
                    if (keys[i].Equals(template.Icon))
                    {
                        selectedIndex = i;
                        break;
                    }
                }
                selectedIndex = EditorGUILayout.Popup("Icon", selectedIndex, keys);
                template.Icon = keys[selectedIndex];

                template.EventTarget = HUXEditorUtils.SceneObjectField <InteractionReceiver>("Interaction Receiver", template.EventTarget);
                if (template.EventTarget == null)
                {
                    HUXEditorUtils.WarningMessage("This button will have no effect until you choose an interaction receiver to register it with.");
                }
            }

            // Draw the unity message section

            /*string propertyName = string.Format("{0}.Array.data[{1}].OnTappedEvent", arrayName, templateIndex);
             * SerializedProperty buttonEvent = serializedObject.FindProperty(propertyName);
             * EditorGUILayout.PropertyField(buttonEvent);
             * if (GUI.changed) {
             *  serializedObject.ApplyModifiedProperties();
             * }*/

            HUXEditorUtils.EndSectionBox();
            return(template);
        }
Example #7
0
        public override void OnInspectorGUI()
        {
            SimpleMenuCollection menu = (SimpleMenuCollection)target;

            HUXEditorUtils.BeginSectionBox("Menu settings");

            menu.DisplayTitle = EditorGUILayout.Toggle("Display Title", menu.DisplayTitle);
            if (menu.DisplayTitle)
            {
                //menu.TitleText.font = (Font)EditorGUILayout.ObjectField("Title font", menu.TitleText.font, typeof(Font), false);
                menu.Title     = EditorGUILayout.TextArea(menu.Title);
                menu.TitleText = HUXEditorUtils.DropDownComponentField <TextMesh>("Title TextMesh", menu.TitleText, menu.transform);
            }

            menu.DisplaySubtitle = EditorGUILayout.Toggle("Display Subtitle", menu.DisplaySubtitle);
            if (menu.DisplaySubtitle)
            {
                //menu.TitleText.font = (Font)EditorGUILayout.ObjectField("Title font", menu.TitleText.font, typeof(Font), false);
                menu.Subtitle     = EditorGUILayout.TextArea(menu.Subtitle);
                menu.SubtitleText = HUXEditorUtils.DropDownComponentField <TextMesh>("Subtitle TextMesh", menu.SubtitleText, menu.transform);
            }
            menu.ButtonPrefab     = (GameObject)EditorGUILayout.ObjectField("Button prefab", menu.ButtonPrefab, typeof(GameObject), false);
            menu.ParentCollection = HUXEditorUtils.DropDownComponentField <ObjectCollection>("Collection parent", menu.ParentCollection, menu.transform);

            if (menu.ButtonPrefab == null)
            {
                HUXEditorUtils.ErrorMessage("You must specify a button prefab");
                HUXEditorUtils.EndSectionBox();
                return;
            }

            if (menu.ParentCollection == null)
            {
                HUXEditorUtils.ErrorMessage("This menu needs a collection component to work", AddCollection, "Fix");
                HUXEditorUtils.EndSectionBox();
                return;
            }

            bool showIcon = false;
            bool showText = false;

            CompoundButtonIcon icon = menu.ButtonPrefab.GetComponent <CompoundButtonIcon>();

            showIcon = icon != null;


            CompoundButtonText text = menu.ButtonPrefab.GetComponent <CompoundButtonText>();

            showText = text != null;

            ButtonIconProfile profile = null;

            if (icon != null)
            {
                profile = icon.IconProfile;
            }

            HUXEditorUtils.BeginSubSectionBox("Buttons");
            HUXEditorUtils.DrawSubtleMiniLabel("Up to " + SimpleMenuCollection.MaxButtons + " allowed. Un-named buttons will be ignored.");

            SimpleMenuCollectionButton[] buttons          = menu.Buttons;
            HashSet <string>             buttonNamesSoFar = new HashSet <string>();
            int numButtons = 0;

            for (int i = 0; i < buttons.Length; i++)
            {
                if (!buttons[i].IsEmpty)
                {
                    numButtons++;
                }
                DrawButtonEditor(buttons[i], showIcon, showText, profile, "buttons", i, buttonNamesSoFar);
            }
            HUXEditorUtils.EndSubSectionBox();

            menu.EditorRefreshButtons();

            HUXEditorUtils.BeginSubSectionBox("Menu preview");
            HUXEditorUtils.DrawSubtleMiniLabel("An approximation of what the menu will look like.");

            List <SimpleMenuCollectionButton> buttonsList = new List <SimpleMenuCollectionButton>(buttons);

            buttonsList.Sort(delegate(SimpleMenuCollectionButton b1, SimpleMenuCollectionButton b2) { return(b1.Index.CompareTo(b2.Index)); });

            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, false, false, GUILayout.MinHeight(previewButtonSizeY * numButtons + 50f));
            EditorGUILayout.BeginVertical();
            bool drewOneButton = false;

            foreach (SimpleMenuCollectionButton button in buttonsList)
            {
                drewOneButton |= DrawPreviewButton(button, showText);
            }
            if (!drewOneButton)
            {
                HUXEditorUtils.WarningMessage("This state has no buttons due to the options you've chosen. It won't be permitted during play mode.");
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndScrollView();

            HUXEditorUtils.EndSubSectionBox();

            HUXEditorUtils.EndSectionBox();

            HUXEditorUtils.SaveChanges(menu);
        }
Example #8
0
        private void DrawButtonEditor(SimpleMenuCollectionButton template, bool showIcon, bool showText, ButtonIconProfile profile, string arrayName, int templateIndex, HashSet <string> buttonNamesSoFar)
        {
            if (!string.IsNullOrEmpty(template.Name))
            {
                HUXEditorUtils.BeginSectionBox(template.Name + " (" + template.Index + ")", HUXEditorUtils.ObjectColor);
            }
            else
            {
                HUXEditorUtils.BeginSectionBox(string.Empty, HUXEditorUtils.ObjectColorEmpty);
            }
            GUI.color = template.IsEmpty ? HUXEditorUtils.DisabledColor : HUXEditorUtils.DefaultColor;
            EditorGUILayout.BeginHorizontal();
            template.Name = EditorGUILayout.TextField(string.IsNullOrEmpty(template.Name) ? "Button Name (Empty)" : "Button Name", template.Name);
            if (GUILayout.Button("Clear", EditorStyles.miniButton))
            {
                template.Name = string.Empty;
            }
            EditorGUILayout.EndHorizontal();
            if (!string.IsNullOrEmpty(template.Name) && buttonNamesSoFar.Contains(template.Name))
            {
                HUXEditorUtils.ErrorMessage("Buttons must have unique names.");
            }
            else
            {
                buttonNamesSoFar.Add(template.Name);
            }
            if (!template.IsEmpty)
            {
                if (showText)
                {
                    if (string.IsNullOrEmpty(template.Text))
                    {
                        GUI.color = HUXEditorUtils.WarningColor;
                    }
                    template.Text = EditorGUILayout.TextField("Label Text", template.Text);
                }

                if (showIcon)
                {
                    GUI.color = HUXEditorUtils.DefaultColor;
                    string[] keys          = profile.GetIconKeys().ToArray();
                    int      selectedIndex = 0;
                    for (int i = 0; i < keys.Length; i++)
                    {
                        if (keys[i].Equals(template.Icon))
                        {
                            selectedIndex = i;
                            break;
                        }
                    }
                    selectedIndex = EditorGUILayout.Popup("Icon", selectedIndex, keys);
                    template.Icon = keys[selectedIndex];
                }

                if (!Application.isPlaying)
                {
                    template.Target = HUXEditorUtils.SceneObjectField <InteractionReceiver>("Interaction Receiver", template.Target);
                    if (template.Target == null)
                    {
                        HUXEditorUtils.WarningMessage("This button will have no effect until you choose an interaction receiver to register it with.");
                    }
                }
            }

            // Draw the unity message section

            /*string propertyName = string.Format("{0}.Array.data[{1}].OnTappedEvent", arrayName, templateIndex);
             * SerializedProperty buttonEvent = serializedObject.FindProperty(propertyName);
             * EditorGUILayout.PropertyField(buttonEvent);
             * if (GUI.changed) {
             *  serializedObject.ApplyModifiedProperties();
             * }*/

            HUXEditorUtils.EndSectionBox();
        }