Example #1
0
    public void ClickToggleLayersState(PressableButtonHoloLens2 button)
    {
        var layerState = LayerSubmenuState;

        CloseSubmenus();
        LayerSubmenuState = !layerState;
    }
Example #2
0
 public PressableButtonHoloLens2 GetPlayButton()
 {
     if (playButton == null)
     {
         playButton = transform.GetChild(1).GetChild(1).GetChild(0).GetComponent <PressableButtonHoloLens2>();
     }
     return(playButton);
 }
Example #3
0
 private void Awake()
 {
     tabButton       = GetComponentInParent <PressableButtonHoloLens2>();
     tabInteractable = tabButton.GetComponent <Interactable>();
     tabInteractable.OnClick.AddListener(ShowTab);
     tabManager = tabButton.GetComponentInParent <TabManager>();
     tabManager.SetTab(this);
     HideTab();
 }
 private void Awake()
 {
     GetComponent <CanvasGroup>().alpha = 0;
     rectTransform = transform.parent.GetComponent <RectTransform>();
     GetComponent <BoxCollider>().size = new Vector3(rectTransform.rect.width, rectTransform.rect.height, rectTransform.localPosition.z);
     pressableButton = transform.parent.GetComponent <PressableButtonHoloLens2>();
     anim            = GetComponent <Animator>();
     pressableButton.ButtonPressed.AddListener(AnimPush);
     pressableButton.ButtonReleased.AddListener(AnimRelease);
 }
Example #5
0
    // Start is called before the first frame update
    void Start()
    {
        contextMenu    = GameObject.Instantiate(ContextMenuPrefab);
        contextMenuBar = contextMenu.GetComponent <AppBar>();
        contextMenu.SetActive(false);

        // add listener to remove button
        Transform buttonRemove          = contextMenu.transform.Find("BaseRenderer/ButtonParent/Remove");
        PressableButtonHoloLens2 button = buttonRemove.GetComponent <PressableButtonHoloLens2>();

        button.ButtonPressed.AddListener(Remove);
    }
Example #6
0
 void Start()
 {
     manipHandler = GetComponent <ManipulationHandler>();
     if (manipHandler != null)
     {
         manipHandler.OnManipulationStarted.AddListener(LogManipulationStart);
     }
     pressButton = GetComponent <PressableButtonHoloLens2>();
     if (pressButton != null)
     {
         pressButton.ButtonPressed.AddListener(LogManipulationStartButtonPress);
     }
 }
Example #7
0
        public string FakePressRandomButton()
        {
            if (pressableButtons == null)
            {
                pressableButtons = GetComponentsInChildren <PressableButtonHoloLens2>();
            }
            PressableButtonHoloLens2 button = pressableButtons[Random.Range(0, pressableButtons.Length)];
            FakePressButton          fbp    = button.GetComponent <FakePressButton>();

            if (fbp == null)
            {
                fbp = button.gameObject.AddComponent <FakePressButton>();
            }
            return(fbp.PressButton());
        }
Example #8
0
 private GameObject FindButton(string name)
 {
     foreach (GameObject buttonGameObject in ColorButtons)
     {
         if (buttonGameObject.name == name)
         {
             PressableButtonHoloLens2 button = buttonGameObject.GetComponent <PressableButtonHoloLens2>();
             if (button == null)
             {
                 throw new Exception("Colormap named " + name + " found, but it is not a button");
             }
             return(buttonGameObject);
         }
     }
     throw new Exception("Colormap " + name + " not found");
 }
Example #9
0
 void Start()
 {
     manipHandler   = GetComponent <ManipulationHandler>();
     loggingManager = LoggingManager.instance;
     if (manipHandler != null)
     {
         manipHandler.OnManipulationStarted.AddListener(LogManipulationStart);
         manipHandler.OnManipulationEnded.AddListener(StopLogging);
     }
     pressButton = GetComponent <PressableButtonHoloLens2>();
     if (pressButton != null)
     {
         pressButton.ButtonPressed.AddListener(LogManipulationStart);
         pressButton.ButtonReleased.AddListener(StopLogging);
     }
     interactable = GetComponent <Interactable>();
     if (interactable != null)
     {
         // handled by `OnStateChange`
     }
 }
Example #10
0
        // Gameobject Extensions
        public static string TryGetNiceNameOfObjectForLogging(this GameObject go)
        {
            CodeBlockObjectMesh cbom = go.GetComponentInParent <CodeBlockObjectMesh>();

            if (cbom != null)
            {
                return(cbom.GetMyCodeBlock().name);
            }
            SnapCollider sc = go.GetComponent <SnapCollider>();

            if (sc != null)
            {
                return(sc.MyCodeBlock.name);
            }
            PressableButtonHoloLens2 pbh2 = go.GetComponentInParent <PressableButtonHoloLens2>();

            if (pbh2 != null)
            {
                return(pbh2.name);
            }

            return(go.name);
        }
Example #11
0
    public static void SetButtonStateText(PressableButtonHoloLens2 button, bool active)
    {
        var text = button.transform.Find("IconAndText/Text").gameObject;

        if (text == null)
        {
            Debug.LogWarning("Missing Text GameObject");
            return;
        }
        TextMeshPro textMesh = text.GetComponent <TextMeshPro>();

        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.
        textMesh.color = newColor;
    }
Example #12
0
    public static void SetButtonState(PressableButtonHoloLens2 button, bool active)
    {
        var icon = button.transform.Find("IconAndText/UIButtonSquareIcon").gameObject;

        if (icon == null)
        {
            Debug.LogWarning("Missing UIButtonSquareIcon on " + button.name);
            return;
        }
        MeshRenderer iconRenderer = icon.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);
    }
Example #13
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 LayersLoaded();
        ColorMap.LayersLoaded = layersLoaded;

        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;

            //FIXME: this is a hack on instance not rotating properly if we move plate
            instanceTransformation.transform.localRotation = new Quaternion(0f, 0f, 0f, 0f);
        }

        // 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>() .

        // reset animation speed slider to value 1
        animationSpeed = 1f;
        SliderAnimationSpeed.GetComponent <PinchSlider>().SliderValue = animationSpeed / SliderSpeedFactor;

        // reset transparency to false
        Transparent = false;

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

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

            // configure button text
            PressableButtonHoloLens2 button = buttonGameObject.GetComponent <PressableButtonHoloLens2>();
            if (button == null)
            {
                Debug.LogWarning("Missing component PressableButtonHoloLens2 in ButtonLayerTemplate");
                continue;
            }
            button.GetComponent <ButtonConfigHelper>().MainLabelText = layer.Caption;
            button.GetComponent <Interactable>().OnClick.AddListener(() => Click(buttonGameObject));

            // update layersButtons dictionary
            layersButtons[layer] = button;
        }
        directionalIndicator.DirectionalTarget = instanceTransformation.transform;
    }