/// <summary>
        /// Validate button settings to ensure button will work in current scene
        /// TODO strengthen this check against new MRTK system
        /// </summary>
        protected override void DrawCustomFooter()
        {
            CompoundButton cb = (CompoundButton)target;

            // Don't perform this check at runtime
            if (!Application.isPlaying)
            {
                // First, check our colliders
                // Get the components we need for the button to be visible
                Rigidbody parentRigidBody = cb.GetComponent <Rigidbody>();
                Collider  parentCollider  = cb.GetComponent <Collider>();
                // Get all child colliders that AREN'T the parent collider
                HashSet <Collider> childColliders = new HashSet <Collider>(cb.GetComponentsInChildren <Collider>());
                childColliders.Remove(parentCollider);

                bool foundError = false;
                UnityEditor.EditorGUILayout.BeginVertical(UnityEditor.EditorStyles.helpBox);
                if (parentCollider == null)
                {
                    if (childColliders.Count == 0)
                    {
                        foundError = true;
                        DrawError("Button must have at least 1 collider to be visible, preferably on the root transform.");
                        if (GUILayout.Button("Fix now"))
                        {
                            cb.gameObject.AddComponent <BoxCollider>();
                        }
                    }
                    else if (parentRigidBody == null)
                    {
                        foundError = true;
                        DrawError("Button requires a Rigidbody if colliders are only present on child transforms.");
                        if (GUILayout.Button("Fix now"))
                        {
                            Rigidbody rb = cb.gameObject.AddComponent <Rigidbody>();
                            rb.isKinematic = true;
                        }
                    }
                    else if (!parentRigidBody.isKinematic)
                    {
                        foundError = true;
                        GUI.color  = warningColor;
                        DrawWarning("Warning: Button rigid body is not kinematic - this is not recommended.");
                        if (GUILayout.Button("Fix now"))
                        {
                            parentRigidBody.isKinematic = true;
                        }
                    }
                }

                if (!foundError)
                {
                    GUI.color = successColor;
                    UnityEditor.EditorGUILayout.LabelField("Button is good to go!", UnityEditor.EditorStyles.wordWrappedLabel);
                }
                UnityEditor.EditorGUILayout.EndVertical();
            }
        }
        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);
            }
        }
Exemplo n.º 3
0
    public static void SetButtonStateText(CompoundButton button, bool active)
    {
        CompoundButtonText text = button.GetComponent <CompoundButtonText>();

        if (text == null)
        {
            Debug.LogWarning("Missing CompoundButtonText");
            return;
        }
        TextMesh textMesh = text.TextMesh;

        if (textMesh == null)
        {
            Debug.LogWarning("Missing TextMesh");
            return;
        }
        // using material, not sharedMaterial, deliberately: we only change color of this material instance
        Color newColor = active ? ButtonActiveColor : ButtonInactiveColor;
        //Debug.Log("changing color of " + button.name + " to " + newColor.ToString());
        // both _EmissiveColor and _Color (Albedo in editor) should be set to make proper effect.
        MeshRenderer renderer = textMesh.GetComponent <MeshRenderer>();

        renderer.material.SetColor("_EmissiveColor", newColor);
        renderer.material.SetColor("_Color", newColor);
    }
Exemplo n.º 4
0
 /// <summary>
 /// Disables button's main collider and sets text alpha to 1/2
 /// </summary>
 /// <param name="buttonName"></param>
 /// <param name="enabled"></param>
 public void SetButtonEnabled(string buttonName, bool enabled)
 {
     for (int i = 0; i < instantiatedButtons.Length; i++)
     {
         if (instantiatedButtons[i].name.Equals(buttonName))
         {
             CompoundButton button = instantiatedButtons[i].GetComponent <CompoundButton>();
             button.ButtonState = enabled ? Button.ButtonStateEnum.Interactive : Button.ButtonStateEnum.Disabled;
             CompoundButtonText text = button.GetComponent <CompoundButtonText>();
             text.Alpha = enabled ? 1f : 0.5f;
             break;
         }
     }
 }
Exemplo n.º 5
0
    private void RefreshUserInterface()
    {
        ButtonsModel.SetActive(instanceLoaded && !instanceIsPreview);
        ButtonsModelPreview.SetActive(instanceLoaded && instanceIsPreview);
        PlateVisible = (!instanceLoaded) || instanceIsPreview;

        // update ButtonTogglePlay caption and icon
        bool   playing         = AnimationPlaying;
        string playOrPauseText = playing ? "PAUSE" : "PLAY";

        ButtonTogglePlay.GetComponent <CompoundButtonText>().Text = playOrPauseText;
        Texture2D    playOrPatseIcon = playing ? ButtonIconPause : ButtonIconPlay;
        MeshRenderer iconRenderer    = ButtonTogglePlay.GetComponent <CompoundButtonIcon>().IconMeshFilter.GetComponent <MeshRenderer>();

        if (iconRenderer != null)
        {
            iconRenderer.sharedMaterial.mainTexture = playOrPatseIcon;
        }
        else
        {
            Debug.LogWarning("ButtonTogglePlay icon does not have MeshRenderer");
        }
    }
Exemplo n.º 6
0
    public static void SetButtonState(CompoundButton button, bool active)
    {
        CompoundButtonIcon icon = button.GetComponent <CompoundButtonIcon>();

        if (icon == null)
        {
            Debug.LogWarning("Missing CompoundButtonIcon on " + button.name);
            return;
        }
        MeshRenderer iconRenderer = icon.IconMeshFilter.GetComponent <MeshRenderer>();

        if (iconRenderer == null)
        {
            Debug.LogWarning("Missing MeshRenderer on CompoundButtonIcon.IconMeshFilter attached to " + button.name);
            return;
        }
        // using material, not sharedMaterial, deliberately: we only change color of this material instance
        Color newColor = active ? ButtonActiveColor : ButtonInactiveColor;

        //Debug.Log("changing color of " + button.name + " to " + newColor.ToString());
        // both _EmissiveColor and _Color (Albedo in editor) should be set to make proper effect.
        iconRenderer.material.SetColor("_EmissiveColor", newColor);
        iconRenderer.material.SetColor("_Color", newColor);
    }
Exemplo n.º 7
0
    /* Load new model.
     *
     * newInstanceBundleName is a bundle name known to the ModelsCollection bundle.
     *
     * No layer is initially loaded -- you usually want to call
     * LoadLayer immediately after this.
     *
     * After calling this, remember to call RefreshUserInterface at some point.
     */
    private void LoadInstance(string newInstanceBundleName, bool newIsPreview)
    {
        if (instanceBundle != null)
        {
            Debug.Log("LoadInstance - currentInstanceName: " + instanceBundle.Name + ", newInstanceName: " + newInstanceBundleName);
            if (instanceIsPreview != newIsPreview && instanceBundle.Layers.All(l => l.DataType == DataType.Volumetric))
            {
                Debug.Log("LoadInstance - preview accepted!");
                instanceIsPreview = newIsPreview;
                return;
            }
        }

        UnloadInstance();

        instanceLoaded = true;
        instanceBundle = ModelsCollection.Singleton.BundleLoad(newInstanceBundleName);
        // Load Volumetric Data
        if (instanceBundle.Layers.All(x => x.GetComponent <ModelLayer>().DataType == DataType.Volumetric))
        {
            instanceBundle.VolumetricMaterial = DefaultVolumetricMaterial;
            instanceBundle.LoadVolumetricData();
        }
        instanceIsPreview = newIsPreview;
        layersLoaded      = new Dictionary <ModelLayer, LayerLoaded>();

        /* Instantiate BoundingBoxRig dynamically, as in the next frame (when BoundingBoxRig.Start is run)
         * it will assume that bounding box of children is not empty.
         * So we cannot create BoundingBoxRig (for rotations) earlier.
         * We also cannot create it later, right before calling Activate, as then BoundingBoxRig.Activate would
         * happen before BoundingBoxRig.Start.
         */
        rotationBoxRig = Instantiate <GameObject>(RotationBoxRigTemplate, InstanceParent.transform);

        instanceTransformation = new GameObject("InstanceTransformation");
        instanceTransformation.transform.parent = rotationBoxRig.transform;

        Vector3 boundsSize = Vector3.one;
        float   scale      = 1f;

        if (instanceBundle.Bounds.HasValue)
        {
            Bounds b = instanceBundle.Bounds.Value;
            boundsSize = b.size;
            float maxSize = Mathf.Max(new float[] { boundsSize.x, boundsSize.y, boundsSize.z });
            if (maxSize > Mathf.Epsilon)
            {
                scale = instanceMaxSize / maxSize;
            }
            instanceTransformation.transform.localScale    = new Vector3(scale, scale, scale);
            instanceTransformation.transform.localPosition = -b.center * scale + instanceMove;
        }

        // set proper BoxCollider bounds
        BoxCollider rotationBoxCollider = rotationBoxRig.GetComponent <BoxCollider>();

        rotationBoxCollider.center = instanceMove;
        rotationBoxCollider.size   = boundsSize * scale;
        // Disable the component, to not prevent mouse clicking on buttons.
        // It will be taken into account to calculate bbox in BoundingBoxRig anyway,
        // since inside BoundingBox.GetColliderBoundsPoints it looks at all GetComponentsInChildren<Collider>() .
        rotationBoxCollider.enabled = false;

        // reset animation speed slider to value 1
        animationSpeed = 1f;
        SliderAnimationSpeed.GetComponent <SliderGestureControl>().SetSliderValue(animationSpeed);

        // reset transparency to false
        Transparent = false;

        // add buttons to toggle layers
        layersButtons = new Dictionary <ModelLayer, CompoundButton>();
        int buttonIndex = 0;

        foreach (ModelLayer layer in instanceBundle.Layers)
        {
            // add button to scene
            GameObject buttonGameObject = Instantiate <GameObject>(ButtonLayerTemplate, LayersSection.transform);
            buttonGameObject.transform.localPosition =
                buttonGameObject.transform.localPosition + new Vector3(0f, 0f, buttonLayerHeight * buttonIndex);
            buttonIndex++;

            // configure button text
            CompoundButton button = buttonGameObject.GetComponent <CompoundButton>();
            if (button == null)
            {
                Debug.LogWarning("Missing component CompoundButton in ButtonLayerTemplate");
                continue;
            }
            button.GetComponent <CompoundButtonText>().Text = layer.Caption;

            // extend ButtonsClickReceiver.interactables
            ButtonsClickReceiver clickReceiver = GetComponent <ButtonsClickReceiver>();
            clickReceiver.interactables.Add(buttonGameObject);

            // update layersButtons dictionary
            layersButtons[layer] = button;
        }
    }
        public override void OnInspectorGUI()
        {
            CompoundButton cb = (CompoundButton)target;

            // Don't perform this check at runtime
            if (!Application.isPlaying)
            {
                // First, check our colliders
                // Get the components we need for the button to be visible
                Rigidbody parentRigidBody = cb.GetComponent <Rigidbody>();
                Collider  parentCollider  = cb.GetComponent <Collider>();
                // Get all child colliders that AREN'T the parent collider
                HashSet <Collider> childColliders = new HashSet <Collider>(cb.GetComponentsInChildren <Collider>());
                childColliders.Remove(parentCollider);

                bool foundError = false;
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                if (parentCollider == null)
                {
                    if (childColliders.Count == 0)
                    {
                        foundError = true;
                        GUI.color  = HUXEditorUtils.ErrorColor;
                        EditorGUILayout.LabelField("Error: Button must have at least 1 collider to be visible, preferably on the root transform.", EditorStyles.wordWrappedLabel);
                        if (GUILayout.Button("Fix now"))
                        {
                            cb.gameObject.AddComponent <BoxCollider>();
                        }
                    }
                    else if (parentRigidBody == null)
                    {
                        foundError = true;
                        GUI.color  = HUXEditorUtils.ErrorColor;
                        EditorGUILayout.LabelField("Error: Button requires a rigidbody if colliders are only present on child transforms.", EditorStyles.wordWrappedLabel);
                        if (GUILayout.Button("Fix now"))
                        {
                            Rigidbody rb = cb.gameObject.AddComponent <Rigidbody>();
                            rb.isKinematic = true;
                        }
                    }
                    else if (!parentRigidBody.isKinematic)
                    {
                        foundError = true;
                        GUI.color  = HUXEditorUtils.WarningColor;
                        EditorGUILayout.LabelField("Warning: Button rigid body is not kinematic - this is not recommended.", EditorStyles.wordWrappedLabel);
                        if (GUILayout.Button("Fix now"))
                        {
                            parentRigidBody.isKinematic = true;
                        }
                    }
                }

                // If our colliders were fine, next check the interaction manager to make sure the button will be visible
                if (!foundError)
                {
                    FocusManager fm = GameObject.FindObjectOfType <FocusManager>();
                    if (fm != null)
                    {
                        if (fm.RaycastLayerMask != (fm.RaycastLayerMask | (1 << cb.gameObject.layer)))
                        {
                            foundError = true;
                            GUI.color  = HUXEditorUtils.WarningColor;
                            EditorGUILayout.LabelField("Warning: Button is not on a layer that the focus manager can see. Button will not receive input until either the button's layer or the FocusManager's RaycastLayerMask is changed. (This may be intentional.)", EditorStyles.wordWrappedLabel);
                            if (fm.RaycastLayerMask.value != 0)
                            {
                                if (GUILayout.Button("Fix now"))
                                {
                                    // Put the button on the first layer that the layer mask can see
                                    for (int i = 0; i < 32; i++)
                                    {
                                        if (fm.RaycastLayerMask == (fm.RaycastLayerMask | (1 << i)))
                                        {
                                            cb.gameObject.layer = i;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        EditorGUILayout.LabelField("(Couldn't find a focus manager to perform visibility check)", EditorStyles.wordWrappedLabel);
                    }
                }

                if (!foundError)
                {
                    GUI.color = HUXEditorUtils.SuccessColor;
                    EditorGUILayout.LabelField("Button is good to go!", EditorStyles.wordWrappedLabel);
                }
                EditorGUILayout.EndVertical();
            }

            GUI.color = HUXEditorUtils.DefaultColor;
            HUXEditorUtils.BeginSectionBox("Button properties", HUXEditorUtils.DefaultColor);
            // Draw the filter tag field
            HUXEditorUtils.DrawFilterTagField(serializedObject, "FilterTag");
            cb.RequireGaze = EditorGUILayout.Toggle("Require Gaze", cb.RequireGaze);
            cb.ButtonState = (Button.ButtonStateEnum)EditorGUILayout.EnumPopup("Button State", cb.ButtonState);
            HUXEditorUtils.EndSectionBox();

            HUXEditorUtils.BeginSectionBox("Commonly referenced components", HUXEditorUtils.DefaultColor);
            cb.MainCollider = HUXEditorUtils.DropDownComponentField <Collider>("Main collider", cb.MainCollider, cb.transform);
            cb.MainRenderer = HUXEditorUtils.DropDownComponentField <MeshRenderer>("Main renderer", cb.MainRenderer, cb.transform);
            HUXEditorUtils.EndSectionBox();

            HUXEditorUtils.SaveChanges(cb);
        }