void Update()
        {
            if (HideMouse && Screen.showCursor)
            {
                Screen.showCursor = false;
            }
            else if (!HideMouse && !Screen.showCursor)
            {
                Screen.showCursor = true;
            }

            HoverObject = null;
            if (UseCursor == true && Cursor != null)
            {
                Camera guiCamera = GetMouseCamera();
                if (guiCamera != null)
                {
                    // Ray
                    Vector3 projectedPosition = guiCamera.WorldToScreenPoint(Cursor.transform.position);
                    Ray     ray = guiCamera.ScreenPointToRay(projectedPosition);

                    // Raycast Hit
                    RaycastHit hit;

                    if (Physics.Raycast(ray, out hit, 1000, 1 << LayerMask.NameToLayer("Gui3D")))
                    {
                        HoverObject = GetContainingGuiObject(hit.transform.gameObject);
                    }
                }
            }
        }
Exemple #2
0
        public static int IndexCompare(Gui3DObject obj1, Gui3DObject obj2)
        {
            if ((obj1 == null) && (obj2 == null))
            {
                Debug.LogError("Gui3DMenuUtils: Objects are null");
                return(0);
            }
            else if (obj1 == null)
            {
                Debug.LogError("Gui3DMenuUtils: Object1 is null");
                return(1);
            }
            else if (obj2 == null)
            {
                Debug.LogError("Gui3DMenuUtils: Object2 is null");
                return(-1);
            }

            if (obj1.MenuIndex < obj2.MenuIndex)
            {
                return(-1);
            }
            else if (obj1.MenuIndex > obj2.MenuIndex)
            {
                return(1);
            }
            else
            {
                return(LocationCompare(obj1, obj2));
            }
        }
Exemple #3
0
        public static int LocationCompare(Gui3DObject obj1, Gui3DObject obj2)
        {
            if ((obj1 == null) && (obj2 == null))
            {
                Debug.LogError("Gui3DMenuUtils: Objects are null");
                return(0);
            }
            else if (obj1 == null)
            {
                Debug.LogError("Gui3DMenuUtils: Object1 is null");
                return(1);
            }
            else if (obj2 == null)
            {
                Debug.LogError("Gui3DMenuUtils: Object2 is null");
                return(-1);
            }

            Vector3 object1position = obj1.gameObject.transform.position;
            Vector3 object2position = obj2.gameObject.transform.position;

            CompareValue xcompare = Compare(object1position.x, object2position.x);
            CompareValue ycompare = Compare(object1position.y, object2position.y);
            CompareValue zcompare = Compare(object1position.z, object2position.z);

            if (ycompare == CompareValue.MORE)
            {
                return(-1);
            }
            else if (ycompare == CompareValue.LESS)
            {
                return(1);
            }

            if (xcompare == CompareValue.LESS)
            {
                return(-1);
            }
            else if (xcompare == CompareValue.MORE)
            {
                return(1);
            }

            if (zcompare == CompareValue.LESS)
            {
                return(-1);
            }
            else if (zcompare == CompareValue.MORE)
            {
                return(1);
            }

            return(0);
        }
        Gui3DObject GetContainingGuiObject(GameObject obj)
        {
            Gui3DObject guiObject = obj.GetComponent <Gui3DObject>();

            if (guiObject != null)
            {
                return(guiObject);
            }
            if (obj.transform.parent == null)
            {
                return(null);
            }
            return(GetContainingGuiObject(obj.transform.parent.gameObject));
        }
Exemple #5
0
 virtual protected void FillMenuAutomatically()
 {
     MenuObjects = new List <Gui3DObject>();
     foreach (Transform child in transform)
     {
         Gui3DObject obj = child.gameObject.GetComponent <Gui3DObject>();
         if (obj != null)
         {
             if (obj.Selectable == true)
             {
                 obj.Deselect();
                 MenuObjects.Add(obj);
             }
         }
     }
     MenuObjects.Sort(Gui3DMenuUtils.LocationCompare);
 }
        void OnGUI()
        {
            Gui3DObject guiObject = gameObject.GetComponent <Gui3DObject>();

            foreach (Camera camera in guiObject.GetGui3D().GuiCameras)
            {
                if (camera.enabled)
                {
                    Vector3 screenPosition = camera.WorldToScreenPoint(gameObject.transform.position);

                    Rect imageRect   = new Rect(screenPosition.x + Offset.x, camera.pixelHeight - screenPosition.y + Offset.y, Size.x, Size.y);
                    Rect clampedRect = imageRect;
                    if (camera.pixelRect.xMin > clampedRect.xMin)
                    {
                        clampedRect.xMin = camera.pixelRect.xMin;
                    }
                    if (camera.pixelRect.yMin > clampedRect.yMin)
                    {
                        clampedRect.yMin = camera.pixelRect.yMin;
                    }
                    if (camera.pixelRect.xMax < clampedRect.xMax)
                    {
                        clampedRect.xMax = camera.pixelRect.xMax;
                    }
                    if (camera.pixelRect.yMax < clampedRect.yMax)
                    {
                        clampedRect.yMax = camera.pixelRect.yMax;
                    }
                    Rect texCoordRect = new Rect(
                        (clampedRect.xMin - imageRect.xMin) / imageRect.width,
                        (imageRect.yMax - clampedRect.yMax) / imageRect.height,
                        clampedRect.width / imageRect.width,
                        clampedRect.height / imageRect.height);

                    if (clampedRect.width > 0 && clampedRect.height > 0)
                    {
                        GUI.DrawTextureWithTexCoords(clampedRect, Image, texCoordRect);
                    }
                }
            }
        }
Exemple #7
0
 void OnClick()
 {
     if (GetGui3D().HoverObject != null)
     {
         Gui3DObject hoverobj = MenuObjects.Find(obj => obj.gameObject == GetGui3D().HoverObject.gameObject);
         if (hoverobj != null)
         {
             SelectedIndex = MenuObjects.IndexOf(hoverobj);
         }
         for (int i = 0; i < MenuObjects.Count; i++)
         {
             if (i != SelectedIndex)
             {
                 (MenuObjects[i] as Gui3DCheckBox).UnCheck();
             }
             else
             {
                 (MenuObjects[i] as Gui3DCheckBox).Check();
             }
         }
     }
     else
     {
         if (!Locked)
         {
             foreach (Gui3DObject obj in MenuObjects)
             {
                 if (!obj.Selected)
                 {
                     (obj as Gui3DCheckBox).UnCheck();
                 }
                 else
                 {
                     (obj as Gui3DCheckBox).Check();
                 }
             }
         }
     }
 }
Exemple #8
0
        // Update is called once per frame
        void Update()
        {
            parent = Gui3DMenuUtils.GetParentMenu(transform);
            if (LockedByParent)
            {
                if (parent != null)
                {
                    if (!parent.Locked)
                    {
                        Locked         = false;
                        LockedByParent = false;
                    }
                }
            }
            if (Locked)
            {
                return;
            }
            if (parent != null)
            {
                if (parent.Locked)
                {
                    Locked         = true;
                    LockedByParent = true;
                }
            }
            if (Selected && !Focused)
            {
                Focus();
            }
            if ((MenuObjects.Count <= 0))
            {
                return;
            }

            MenuObjects[SelectedIndex].GetComponent <Gui3DObject>().Deselect();

            if (Focused)
            {
                if (Input.GetButtonDown(DownButton))
                {
                    UpdateIndex(GridColumns);
                }
                else if (Input.GetButtonDown(UpButton))
                {
                    UpdateIndex(-GridColumns);
                }

                if (Input.GetButtonDown(RightButton))
                {
                    UpdateIndex(1);
                }
                else if (Input.GetButtonDown(LeftButton))
                {
                    UpdateIndex(-1);
                }
            }

            if (UseMouse)
            {
                if (GetGui3D().HoverObject != null)
                {
                    Gui3DObject hoverobj = MenuObjects.Find(obj => obj.gameObject == GetGui3D().HoverObject.gameObject);
                    if (hoverobj != null)
                    {
                        if (!Focused)
                        {
                            Focus();
                        }
                        SelectedIndex = MenuObjects.IndexOf(hoverobj);
                    }
                    else
                    {
                        UnFocus();
                    }
                }
            }

            if (Focused)
            {
                MenuObjects[SelectedIndex].Select();
            }
        }