private void CreateButtonBody(ButtonProfile profile)
        {
            if (buttonBodyInstance)
            {
                return;
            }
            buttonBodyInstance = Instantiate(profile.buttonBody);

#if UNITY_EDITOR
            Undo.RegisterCreatedObjectUndo(buttonBodyInstance, "Created ButtonBody");
#endif
            buttonBodyInstance.SetActive(true);
            buttonBodyInstance.transform.localScale    = profile.bodyScale;
            buttonBodyInstance.transform.parent        = buttonInstance.transform;
            buttonBodyInstance.transform.localPosition = Vector3.zero;
            buttonBodyInstance.transform.localRotation = Quaternion.identity;
            buttonBodyInstance.name = "ButtonBody";

            MeshRenderer meshRenderer = buttonBodyInstance.GetComponent <MeshRenderer>();
            meshRenderer.materials = new Material[1] {
                profile.material
            };

            Selectable selectable = buttonBodyInstance.AddComponent <Selectable>();
            selectable.highlightMaterial   = profile.highlight;
            selectable.outlineMaterial     = profile.outline;
            selectable.textColor           = profile.fontColor;
            selectable.unselectedMaterials = new Material[] { profile.material };

            if (!buttonBodyInstance.GetComponent <BoxCollider>())
            {
                buttonBodyInstance.AddComponent <BoxCollider>();
            }
        }
        protected GameObject DisplayRow(GameObject parent)
        {
            ButtonProfile profile = Defaults.GetMomentaryButtonProfile(momentaryButtonProfile);

            GameObject row   = Row(parent, "DisplayRow", TextAlignment.Left);
            GameObject label = EmptyChild(row, "Display");

            label.transform.localScale = profile.labelScale;
            Vector3 localPosition = new Vector3(0, 0, profile.labelZ);

            label.transform.localPosition = localPosition;
            TextMesh textMesh = Undoable.AddComponent <TextMesh>(label);

            textMesh.text     = "keyboard display";
            textMesh.fontSize = profile.fontSize;
            textMesh.color    = profile.fontColor;
            textMesh.anchor   = TextAnchor.MiddleCenter;

            KeyboardLabel keyboardLabel = Undoable.AddComponent <KeyboardLabel>(label);

            keyboardLabel.keyboard = keyboard;
            keyboardLabel.textMesh = textMesh;

            BoxCollider boxCollider = Undoable.AddComponent <BoxCollider>(label);

            UpdateBoxColliderFromTextMesh updateBoxCollider = Undoable.AddComponent <UpdateBoxColliderFromTextMesh>(label);

            updateBoxCollider.textMesh    = textMesh;
            updateBoxCollider.boxCollider = boxCollider;

            return(row);
        }
Пример #3
0
        protected GameObject Label(GameObject parent, string name, string text)
        {
            PanelContainerProfile pcProfile = Defaults.GetProfile(panelContainerProfile);
            ButtonProfile         profile   = Defaults.GetMomentaryButtonProfile(momentaryButtonProfile);
            GameObject            label     = EmptyChild(parent, name);

            label.transform.localScale = profile.labelScale;
            Vector3 localPosition = new Vector3(0, 0, profile.labelZ);

            label.transform.localPosition = localPosition;
            TextMesh textMesh = Undoable.AddComponent <TextMesh>(label);

            textMesh.text          = text;
            textMesh.fontSize      = profile.fontSize;
            textMesh.color         = profile.fontColor;
            textMesh.characterSize = pcProfile.labelCharacterSize;
            textMesh.anchor        = TextAnchor.MiddleCenter;

            BoxCollider boxCollider = Undoable.AddComponent <BoxCollider>(label);

            UpdateBoxColliderFromTextMesh updateBoxCollider = Undoable.AddComponent <UpdateBoxColliderFromTextMesh>(label);

            updateBoxCollider.textMesh    = textMesh;
            updateBoxCollider.boxCollider = boxCollider;
            return(label);
        }
        private void CreateKeyProfile()
        {
            ButtonProfile buttonProfile = Defaults.GetMomentaryButtonProfile(momentaryButtonProfile);

            keyProfile = ScriptUtils.CopyComponent(buttonProfile, disposable);
            keyProfile.characterSize = keyCharacterSize;
        }
Пример #5
0
        public static void DrawProfileInspector(ButtonProfile profile, Component targetComponent)
        {
            ProfileInspector profileEditor = (ProfileInspector)Editor.CreateEditor(profile);

            profileEditor.targetComponent = targetComponent;

            profileEditor.OnInspectorGUI();
        }
        protected GameObject SaveAsButtonRow(GameObject parent)
        {
            GameObject    row     = Row(parent, "SaveAsButtonRow", TextAlignment.Right);
            ButtonProfile profile = Defaults.GetMomentaryButtonProfile(momentaryButtonProfile);

            SaveAsButton(fileSaveAs, row, profile, "Save As");
            return(row);
        }
        private void CreateNumLockKeyProfile()
        {
            ButtonProfile buttonProfile = Defaults.GetToggleButtonProfile(toggleButtonProfile);

            numLockKeyProfile = ScriptUtils.CopyComponent(buttonProfile, disposable);
            numLockKeyProfile.characterSize = numLockCharacterSize;
            numLockKeyProfile.minWidth      = modeKeyMinWidth;
        }
        private void CreateReturnKeyProfile()
        {
            ButtonProfile buttonProfile = Defaults.GetMomentaryButtonProfile(momentaryButtonProfile);

            returnKeyProfile = ScriptUtils.CopyComponent(buttonProfile, disposable);
            returnKeyProfile.characterSize = keyCharacterSize;
            returnKeyProfile.minWidth      = returnMinWidth;
        }
        protected GameObject KeyboardButton(StandardPanel panel, GameObject parent, ButtonProfile profile, string buttonText)
        {
            KeyboardMomentaryKeyButtonFactory factory = Undoable.AddComponent <KeyboardMomentaryKeyButtonFactory>(disposable);

            SetKeyboardButtonValues(factory, panel, parent);
            factory.buttonText    = buttonText;
            factory.value         = buttonText;
            factory.buttonProfile = profile;
            return(GenerateKeyboardButtonAndSetPosition(factory));
        }
        private ButtonProfile GetButtonProfile()
        {
            ButtonProfile profile = Defaults.GetMomentaryButtonProfile(buttonProfile);

            if (buttonBehavior == ButtonBehavior.Toggle)
            {
                profile = Defaults.GetToggleButtonProfile(buttonProfile);
            }
            return(profile);
        }
Пример #11
0
        protected GameObject DriveButton(FileBase panel, GameObject parent, ButtonProfile buttonProfile, string buttonText)
        {
            DriveButtonFactory factory = Undoable.AddComponent <DriveButtonFactory>(disposable);

            SetButtonValues(factory, panel, parent);
            factory.buttonText    = buttonText;
            factory.filePanel     = panel;
            factory.buttonProfile = buttonProfile;
            return(GenerateKeyboardButtonAndSetPosition(factory));
        }
        protected GameObject ColorPicker(StandardPanel panel, GameObject parent)
        {
            ButtonProfile             profile = Defaults.GetMomentaryButtonProfile(momentaryButtonProfile);
            ExampleColorPickerFactory factory = Undoable.AddComponent <ExampleColorPickerFactory>(disposable);

            factory.parent             = parent;
            factory.colorPickerProfile = Defaults.GetProfile(colorPickerProfile);
            GameObject colorPicker = factory.Generate();

            colorPicker.transform.localPosition = new Vector3(0, 0, profile.labelZ);
            return(colorPicker);
        }
Пример #13
0
        protected GameObject CreateKineticScrollerItem(GameObject parent)
        {
            KineticScrollerItemFactory kineticScrollerItemFactory = Undoable.AddComponent <KineticScrollerItemFactory>(disposable);
            ButtonProfile profile = Defaults.GetMomentaryButtonProfile(momentaryButtonProfile);

            kineticScrollerItemFactory.parent    = parent;
            kineticScrollerItemFactory.material  = profile.material;
            kineticScrollerItemFactory.highlight = profile.highlight;
            kineticScrollerItemFactory.outline   = profile.outline;
            kineticScrollerItemFactory.fontColor = profile.fontColor;
            return(kineticScrollerItemFactory.Generate());
        }
Пример #14
0
        protected GameObject DriveButtonRow(GameObject parent)
        {
            GameObject row = Row(parent, "DriveButtonRow", TextAlignment.Left);

            Label(row, "DrivesLabel", "              Drives");
            ButtonProfile profile = Defaults.GetMomentaryButtonProfile(momentaryButtonProfile);

            GameObject driveButtonPrefab = DriveButton(filePanel, row, profile, "C");

            drives.driveButtonPrefab = driveButtonPrefab;
            return(row);
        }
Пример #15
0
        protected GameObject SpecialFoldersRow(GameObject parent)
        {
            GameObject row = Row(parent, "SpecialFoldersRow", TextAlignment.Left);

            Label(row, "SpecialFoldersLabel", "Special Folders");
            ButtonProfile profile = Defaults.GetMomentaryButtonProfile(momentaryButtonProfile);

            KnownFolderButton(filePanel, row, profile, "Documents", KnownFolder.Documents);
            KnownFolderButton(filePanel, row, profile, "Downloads", KnownFolder.Downloads);
            KnownFolderButton(filePanel, row, profile, "Desktop", KnownFolder.Desktop);

            return(row);
        }
Пример #16
0
    //This function adds button to the List
    private void AddButtons()
    {
        for (int i = 0; i < itemList.Length; i++)
        {
            string name = itemList[i];

            Button newButton = GameObject.Instantiate(PrefabButton);
            newButton.transform.SetParent(ContentPanel, false);

            ButtonProfile sampleButton = newButton.GetComponent <ButtonProfile>();
            sampleButton.Setup(name);
        }
    }
        protected GameObject FileNameButtonRow(GameObject parent)
        {
            GameObject row = Row(parent, "FileNameButtonRow", TextAlignment.Left);

            Label(row, "FileNameLabel", "         FileName");
            ButtonProfile profile = Defaults.GetMomentaryButtonProfile(momentaryButtonProfile);

            GameObject fileNameObject = FileNameButton(fileSaveAs, row, profile, "FileName");

            fileNameButton            = fileNameObject.GetComponent <SaveAsFileNameButton>();
            fileSaveAs.fileNameButton = fileNameButton;
            Label(row, "ExtLabel", fileNameExtension);
            return(row);
        }
        protected GameObject ButtonSpacer(GameObject parent, float width)
        {
            ButtonProfile       profile = Defaults.GetMomentaryButtonProfile(momentaryButtonProfile);
            ButtonSpacerFactory factory = Undoable.AddComponent <ButtonSpacerFactory>(disposable);

            factory.parent = parent;
            Vector3 size = profile.bodyScale;

            size.x       = width;
            factory.size = size;
            GameObject button = factory.Generate();

            SetKeyboardButtonPosition(button);
            return(button);
        }
        private void BuildButton(ButtonProfile profile)
        {
            if (!buttonBodyInstance)
            {
                return;
            }

#if UNITY_EDITOR
            Undo.RegisterCompleteObjectUndo(buttonInstance, "Change name before");
#endif
            if (buttonBehavior == ButtonBehavior.Momentary)
            {
            }

            buttonInstance.name = "Button_" + buttonText;

            AudioSource audioSourceDown = AddAudioSource(buttonInstance, profile.buttonClickDown);
            AudioSource audioSourceUp   = AddAudioSource(buttonInstance, profile.buttonClickUp);

            BoxCollider boxCollider = Undoable.AddComponent <BoxCollider>(buttonInstance);
            boxCollider.size      = profile.bodyScale;
            boxCollider.isTrigger = true;

            AddButton(buttonInstance, audioSourceDown, audioSourceUp);

            GrowButtonByTextMesh growButton = Undoable.AddComponent <GrowButtonByTextMesh>(buttonInstance);
            growButton.buttonBody = buttonBodyInstance;
            growButton.textMesh   = buttonTextLabelInstance.GetComponent <TextMesh>();
            growButton.alignment  = alignment;
            growButton.minWidth   = profile.minWidth;
            growButton.padding    = profile.padding;

            Rigidbody rigidBody = Undoable.AddComponent <Rigidbody>(buttonInstance);
            rigidBody.isKinematic = true;

#if VRTK
            Undoable.AddComponent <CreateThis_VRTK_Interactable>(buttonInstance);
#endif

            Selectable selectable = Undoable.AddComponent <Selectable>(buttonInstance);
            selectable.highlightMaterial   = profile.highlight;
            selectable.outlineMaterial     = profile.outline;
            selectable.textColor           = profile.fontColor;
            selectable.unselectedMaterials = new Material[] { profile.material };
            selectable.recursive           = true;

            growButton.Resize();
        }
        private void CreateTextLabel(ButtonProfile profile)
        {
            if (buttonTextLabelInstance)
            {
                return;
            }
            buttonTextLabelInstance = EmptyChild(buttonInstance, "ButtonTextLabel", profile.labelScale);
            buttonTextLabelInstance.transform.localPosition = new Vector3(0, 0, profile.labelZ);

            TextMesh textMesh = buttonTextLabelInstance.AddComponent <TextMesh>();

            textMesh.text          = buttonText;
            textMesh.fontSize      = profile.fontSize;
            textMesh.color         = profile.fontColor;
            textMesh.anchor        = TextAnchor.MiddleCenter;
            textMesh.alignment     = TextAlignment.Left;
            textMesh.characterSize = profile.characterSize;
        }
        public override GameObject Generate()
        {
            base.Generate();

#if UNITY_EDITOR
            Undo.SetCurrentGroupName("ButtonFactory Generate");
            int group = Undo.GetCurrentGroup();

            Undo.RegisterCompleteObjectUndo(this, "ButtonFactory state");
#endif
            ButtonProfile profile = GetButtonProfile();
            CreateButton();
            CreateButtonBody(profile);
            CreateTextLabel(profile);
            BuildButton(profile);
#if UNITY_EDITOR
            Undo.CollapseUndoOperations(group);
#endif
            return(buttonInstance);
        }
Пример #22
0
        protected GameObject CreateKineticScroller(GameObject parent)
        {
            FilePanelProfile fpProfile = Defaults.GetProfile(filePanelProfile);

            kineticScrollerInstance   = EmptyChild(parent, "KineticScroller");
            kineticScroller           = Undoable.AddComponent <KineticScroller>(kineticScrollerInstance);
            kineticScroller.space     = fpProfile.kineticScrollerSpacing;
            filePanel.kineticScroller = kineticScroller;

            Rigidbody rigidbody = Undoable.AddComponent <Rigidbody>(kineticScrollerInstance);

            rigidbody.useGravity = false;

            ButtonProfile profile = Defaults.GetMomentaryButtonProfile(momentaryButtonProfile);

            Selectable selectable = Undoable.AddComponent <Selectable>(kineticScrollerInstance);

            selectable.highlightMaterial   = profile.highlight;
            selectable.outlineMaterial     = profile.outline;
            selectable.textColor           = profile.fontColor;
            selectable.unselectedMaterials = new Material[] { profile.material };
            selectable.recursive           = true;

            ConfigurableJoint configurableJoint = Undoable.AddComponent <ConfigurableJoint>(kineticScrollerInstance);

            configurableJoint.connectedBody  = filePanelContainerRigidbody;
            configurableJoint.anchor         = Vector3.zero;
            configurableJoint.xMotion        = ConfigurableJointMotion.Limited;
            configurableJoint.yMotion        = ConfigurableJointMotion.Locked;
            configurableJoint.zMotion        = ConfigurableJointMotion.Locked;
            configurableJoint.angularXMotion = ConfigurableJointMotion.Locked;
            configurableJoint.angularYMotion = ConfigurableJointMotion.Locked;
            configurableJoint.angularZMotion = ConfigurableJointMotion.Locked;
            configurableJoint.breakForce     = float.PositiveInfinity;
            configurableJoint.breakTorque    = float.PositiveInfinity;

            return(kineticScrollerInstance);
        }
            protected override void DrawCustomFooter()
            {
                CompoundButtonToggle toggle = (CompoundButtonToggle)target;

                FieldInfo fieldInfo   = null;
                Type      profileType = null;

                if (toggle.Target == null)
                {
                    DrawError("Target must be set.");
                    return;
                }
                else
                {
                    fieldInfo = toggle.Target.GetType().GetField("Profile");

                    if (fieldInfo == null)
                    {
                        DrawError("Target component has no 'Profile' field - are you use this class inherits from ProfileButtonBase?");
                        return;
                    }

                    GUIStyle labelStyle = new GUIStyle(UnityEditor.EditorStyles.label);
                    labelStyle.fontSize  = 18;
                    labelStyle.fontStyle = FontStyle.Bold;

                    profileType = fieldInfo.FieldType;
                    UnityEditor.EditorGUILayout.LabelField("Type: " + toggle.Target.GetType().Name + " / " + fieldInfo.FieldType.Name, labelStyle, GUILayout.MinHeight(24));
                }

                UnityEditor.EditorGUILayout.LabelField("Select on/off profiles of the type " + profileType.Name);
                if (toggle.OnProfile == null)
                {
                    toggle.OnProfile = (ButtonProfile)fieldInfo.GetValue(toggle.Target);
                }
                if (toggle.OffProfile == null)
                {
                    toggle.OffProfile = toggle.OnProfile;
                }
                ButtonProfile onProfile  = (ButtonProfile)UnityEditor.EditorGUILayout.ObjectField("On Profile", toggle.OnProfile, typeof(ButtonProfile), false);
                ButtonProfile offProfile = (ButtonProfile)UnityEditor.EditorGUILayout.ObjectField("Off Profile", toggle.OffProfile, typeof(ButtonProfile), false);

                if (onProfile.GetType() == profileType)
                {
                    toggle.OnProfile = onProfile;
                }
                if (offProfile.GetType() == profileType)
                {
                    toggle.OffProfile = offProfile;
                }

                if (toggle.OnProfile.GetType() != profileType)
                {
                    DrawError("On profile object does not match type " + profileType.Name);
                }
                if (toggle.OffProfile.GetType() != profileType)
                {
                    DrawError("Off profile object does not match type " + profileType.Name);
                }

                if (onProfile == offProfile)
                {
                    DrawWarning("Profiles are the same - toggle will have no effect");
                }

                toggle.Behavior = (ToggleBehaviorEnum)UnityEditor.EditorGUILayout.EnumPopup("Toggle behavior", toggle.Behavior);
            }
        public override void OnInspectorGUI()
        {
            CompoundButtonToggle toggle = (CompoundButtonToggle)target;

            HUXEditorUtils.BeginSectionBox("Target");

            toggle.Target = HUXEditorUtils.DropDownComponentField <MonoBehaviour>("Component", toggle.Target, toggle.transform, true);
            FieldInfo fieldInfo   = null;
            Type      profileType = null;

            if (toggle.Target == null)
            {
                HUXEditorUtils.ErrorMessage("Target must be set.");
                HUXEditorUtils.EndSectionBox();
                HUXEditorUtils.SaveChanges(target, serializedObject);
                return;
            }
            else
            {
                fieldInfo = toggle.Target.GetType().GetField("Profile");

                if (fieldInfo == null)
                {
                    HUXEditorUtils.ErrorMessage("Target component has no 'Profile' field - are you use this class inherits from ProfileButtonBase?");
                    HUXEditorUtils.EndSectionBox();
                    HUXEditorUtils.SaveChanges(target, serializedObject);
                    return;
                }

                GUIStyle labelStyle = new GUIStyle(EditorStyles.label);
                labelStyle.fontSize  = 18;
                labelStyle.fontStyle = FontStyle.Bold;

                profileType = fieldInfo.FieldType;
                EditorGUILayout.LabelField("Type: " + toggle.Target.GetType().Name + " / " + fieldInfo.FieldType.Name, labelStyle, GUILayout.MinHeight(24));
            }
            HUXEditorUtils.EndSectionBox();

            HUXEditorUtils.BeginSectionBox("Toggling");
            HUXEditorUtils.DrawSubtleMiniLabel("Select on/off profiles of the type " + profileType.Name);
            if (toggle.OnProfile == null)
            {
                toggle.OnProfile = (ButtonProfile)fieldInfo.GetValue(toggle.Target);
            }
            if (toggle.OffProfile == null)
            {
                toggle.OffProfile = toggle.OnProfile;
            }
            ButtonProfile onProfile  = (ButtonProfile)EditorGUILayout.ObjectField("On Profile", toggle.OnProfile, typeof(ButtonProfile), false);
            ButtonProfile offProfile = (ButtonProfile)EditorGUILayout.ObjectField("Off Profile", toggle.OffProfile, typeof(ButtonProfile), false);

            if (onProfile.GetType() == profileType)
            {
                toggle.OnProfile = onProfile;
            }
            if (offProfile.GetType() == profileType)
            {
                toggle.OffProfile = offProfile;
            }

            if (toggle.OnProfile.GetType() != profileType)
            {
                HUXEditorUtils.ErrorMessage("On profile object does not match type " + profileType.Name);
            }
            if (toggle.OffProfile.GetType() != profileType)
            {
                HUXEditorUtils.ErrorMessage("Off profile object does not match type " + profileType.Name);
            }

            if (onProfile == offProfile)
            {
                HUXEditorUtils.WarningMessage("Profiles are the same - toggle will have no effect");
            }

            toggle.Behavior = (CompoundButtonToggle.ToggleBehaviorEnum)EditorGUILayout.EnumPopup("Toggle behavior", toggle.Behavior);
            HUXEditorUtils.EndSectionBox();

            HUXEditorUtils.BeginSectionBox("State");
            if (!Application.isPlaying)
            {
                toggle.State = EditorGUILayout.Toggle(toggle.State);
            }
            else
            {
                EditorGUILayout.Toggle(toggle.State);
            }
            HUXEditorUtils.EndSectionBox();

            HUXEditorUtils.SaveChanges(target, serializedObject);
        }
Пример #25
0
 public static IInputParser ToInputParser(this ButtonProfile profile) =>
 profile switch
 {