Exemple #1
0
 void Update()
 {
     // Update the menu state if it needs to suddenly open or close
     if (!dummyParent && IsButtonClicked())
     {
         SetMenuLocation();
         if (IsMenuInFOV())
         {
             dummyParent          = (ClickMenuIcon)Instantiate(menuIconPrefab, transform);
             dummyParent.menuRoot = this;
             ClickMenuIcon.ShowMenu(this, menuTree.tree.Root, dummyParent,
                                    menuCenter, menuOrientation, iconScale);
             dummyParent.SetDummy();
             if (OnMenuOpened != null)
             {
                 OnMenuOpened.Invoke();
             }
         }
     }
     else if ((GvrControllerInput.ClickButtonDown && !selected) ||
              IsPointingAway())
     {
         CloseAll();
     }
     else if (dummyParent && GvrControllerInput.AppButtonUp)
     {
         MakeSelection(null);
         dummyParent.DeepestMenu().ShowParentMenu();
     }
 }
Exemple #2
0
 public void CloseAll()
 {
     selected = false;
     if (dummyParent)
     {
         dummyParent.CloseAll();
         Destroy(dummyParent.gameObject);
         dummyParent = null;
         if (OnMenuClosed != null)
         {
             OnMenuClosed.Invoke();
         }
     }
 }
 public void CloseAll()
 {
     selected = false;
     if (dummyParent)
     {
         dummyParent.CloseAll();
         Destroy(dummyParent.gameObject);
         dummyParent = null;
         laserPointer.maxReticleDistance = reticleDistance;
         if (OnMenuClosed != null)
         {
             OnMenuClosed.Invoke();
         }
     }
 }
Exemple #4
0
        /// Shows a new menu, returns true if a fade needs to occur.
        public static bool ShowMenu(ClickMenuRoot root, AssetTree.Node treeNode, ClickMenuIcon parent,
                                    Vector3 center, Quaternion orientation, float scale)
        {
            // Determine how many children are in the sub-menu
            List <AssetTree.Node> childItems = treeNode.children;

            // If this is the end of a menu, invoke the action and return early
            if (childItems.Count == 0)
            {
                if (parent.menuItem.closeAfterSelected)
                {
                    root.CloseAll();
                }
                return(false);
            }

            // Radius needs to expand when there are more icons
            float radius = ITEM_SPACING * Mathf.Max(childItems.Count, MIN_ITEM_SPACE) / (2.0f * Mathf.PI);

            // Create and arrange the icons in a circle
            float arcAngle = 2.0f * Mathf.PI / childItems.Count;

            for (int i = 0; i < childItems.Count; ++i)
            {
                float   angle     = i * arcAngle;
                Vector3 posOffset = new Vector3(Mathf.Sin(angle), Mathf.Cos(angle), 0.0f) * radius;

                ClickMenuIcon childMenu = (ClickMenuIcon)Instantiate(root.menuIconPrefab, root.transform);
                childMenu.transform.position   = center + (orientation * posOffset);
                childMenu.transform.rotation   = orientation;
                childMenu.transform.localScale = Vector3.one * scale;
                childMenu.startAngle           = angle - arcAngle / 2;
                childMenu.endAngle             = angle + arcAngle / 2;
                childMenu.Initialize(root, parent, childItems[i], center, scale, posOffset / scale);
            }

            // Also create a back button
            ClickMenuIcon backButton = (ClickMenuIcon)Instantiate(root.menuIconPrefab, root.transform);

            backButton.transform.position   = center;
            backButton.transform.rotation   = orientation;
            backButton.transform.localScale = Vector3.one * scale;
            backButton.Initialize(root, parent, null, center, scale, Vector3.zero);
            return(true);
        }
        void Update()
        {
            // Shorten laser when menus are open
            if (dummyParent)
            {
                float newDist = laserPointer.maxReticleDistance - reticleDelta;
                laserPointer.maxReticleDistance = Mathf.Max(newDist, menuDistance * POINTER_DISTANCE_SCALE);
            }

            // Update the menu state if it needs to suddenly open or close
            if (!dummyParent && IsButtonClicked())
            {
                SetMenuLocation();
                if (IsMenuInFOV())
                {
                    reticleDistance      = laserPointer.maxReticleDistance;
                    dummyParent          = (ClickMenuIcon)Instantiate(menuIconPrefab, transform);
                    dummyParent.menuRoot = this;
                    ClickMenuIcon.OpenMenu(this, menuTree.tree.Root, dummyParent,
                                           menuCenter, menuOrientation, 0.1f);
                    dummyParent.SetDummy();
                    if (OnMenuOpened != null)
                    {
                        OnMenuOpened.Invoke();
                    }
                }
            }
            else if ((GvrController.ClickButtonDown && !selected) ||
                     IsPointingAway())
            {
                CloseAll();
            }
            else if (dummyParent && GvrController.AppButtonUp)
            {
                MakeSelection(-1);
                dummyParent.DeepestMenu().CloseSubMenu();
            }
        }
Exemple #6
0
        /// Called to make this icon visible and interactable
        public void Initialize(ClickMenuRoot root, ClickMenuIcon _parentMenu, AssetTree.Node node,
                               Vector3 _menuCenter, float scale, Vector3 offset)
        {
            string name = (node == null ? "Back " : ((ClickMenuItem)node.value).toolTip);

            gameObject.name = name + " Item";
            parentMenu      = _parentMenu;
            startPosition   = transform.position;
            startScale      = transform.localScale;
            menuRoot        = root;
            menuNode        = node;
            menuCenter      = _menuCenter;
            menuOrientation = transform.rotation;
            menuScale       = scale;
            localOffset     = offset;
            background      = null;
            if (node != null)
            {
                // Set foreground icon
                menuItem = (ClickMenuItem)node.value;
                spriteRenderer.sprite = menuItem.icon;

                // Set background icon
                if (menuItem.background)
                {
                    background = new GameObject(name + " Item Background");
                    background.transform.parent        = transform.parent;
                    background.transform.localPosition = transform.localPosition + transform.forward * BACKGROUND_PUSH;
                    background.transform.localRotation = transform.localRotation;
                    background.transform.localScale    = transform.localScale;
                    backgroundSpriteRenderer           = background.AddComponent <SpriteRenderer>();
                    backgroundSpriteRenderer.sprite    = menuItem.background;
                }

                // Set tooltip text
                tooltip                                = Instantiate(tooltipPrefab);
                tooltip.name                           = name + " Tooltip";
                tooltip.transform.parent               = transform.parent;
                tooltip.transform.localPosition        = menuCenter;
                tooltip.transform.localRotation        = menuOrientation;
                tooltip.transform.localScale           = transform.localScale * TOOLTIP_SCALE;
                tooltip.GetComponent <TextMesh>().text = menuItem.toolTip.Replace('\\', '\n');
                tooltipRenderer                        = tooltip.GetComponent <MeshRenderer>();
                SetTooltipAlpha(0.0f);
            }
            else
            {
                // This is a back button
                spriteRenderer.sprite = root.backIcon;
                isBackButton          = true;
            }

            pieBackground   = null;
            pieMeshRenderer = null;
            if (root.pieMaterial)
            {
                pieBackground = new GameObject(name + " Pie Background");
                pieBackground.transform.SetParent(transform.parent, false);
                pieBackground.transform.localPosition = transform.localPosition;
                pieBackground.transform.localRotation = transform.localRotation;
                pieBackground.transform.localScale    = transform.localScale;
                pieBackground.AddComponent <MeshFilter>().sharedMesh = sharedMesh;
                pieMeshRenderer = pieBackground.AddComponent <MeshRenderer>();
                pieMeshRenderer.sharedMaterial = root.pieMaterial;
                pieStartColor = root.pieMaterial.GetColor("_Color");
            }

            parentMenu.childMenus.Add(this);
            StartFade(FadeState.Shown);
            SetButtonTransparency(0.0f);
            SetPieMeshTransparency(0.0f, 0.0f);
        }