예제 #1
0
        protected virtual void SetupCanvas()
        {
            Canvas canvas = GetComponent <Canvas>();

            if (canvas == null || canvas.renderMode != RenderMode.WorldSpace)
            {
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.REQUIRED_COMPONENT_MISSING_FROM_GAMEOBJECT, "VRTK_UICanvas", "Canvas", "the same", " that is set to `Render Mode = World Space`"));
                return;
            }

            RectTransform canvasRectTransform = canvas.GetComponent <RectTransform>();
            Vector2       canvasSize          = canvasRectTransform.rect.size;
            //copy public params then disable existing graphic raycaster
            GraphicRaycaster        defaultRaycaster = canvas.gameObject.GetComponent <GraphicRaycaster>();
            VRTK_UIGraphicRaycaster customRaycaster  = canvas.gameObject.GetComponent <VRTK_UIGraphicRaycaster>();

            //if it doesn't already exist, add the custom raycaster
            if (customRaycaster == null)
            {
                customRaycaster = canvas.gameObject.AddComponent <VRTK_UIGraphicRaycaster>();
            }

            if (defaultRaycaster != null && defaultRaycaster.enabled)
            {
                customRaycaster.ignoreReversedGraphics = defaultRaycaster.ignoreReversedGraphics;
                customRaycaster.blockingObjects        = defaultRaycaster.blockingObjects;

                //Use Reflection to transfer the BlockingMask
                customRaycaster.GetType().GetField("m_BlockingMask", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(customRaycaster, defaultRaycaster.GetType().GetField("m_BlockingMask", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(defaultRaycaster));

                defaultRaycaster.enabled = false;
            }

            //add a box collider and background image to ensure the rays always hit
            if (canvas.gameObject.GetComponent <BoxCollider>() == null)
            {
                Vector2 pivot  = canvasRectTransform.pivot;
                float   zSize  = 0.1f;
                float   zScale = zSize / canvasRectTransform.localScale.z;

                canvasBoxCollider           = canvas.gameObject.AddComponent <BoxCollider>();
                canvasBoxCollider.size      = new Vector3(canvasSize.x, canvasSize.y, zScale);
                canvasBoxCollider.center    = new Vector3(canvasSize.x / 2 - canvasSize.x * pivot.x, canvasSize.y / 2 - canvasSize.y * pivot.y, zScale / 2f);
                canvasBoxCollider.isTrigger = true;
            }

            if (canvas.gameObject.GetComponent <Rigidbody>() == null)
            {
                canvasRigidBody             = canvas.gameObject.AddComponent <Rigidbody>();
                canvasRigidBody.isKinematic = true;
            }

            if (CREATE_DRAGGABLE_PANEL)
            {
                draggablePanelCreation = StartCoroutine(CreateDraggablePanel(canvas, canvasSize));
            }

            CreateActivator(canvas, canvasSize);
        }
예제 #2
0
        protected virtual void RemoveCanvas()
        {
            Canvas canvas = GetComponent <Canvas>();

            if (canvas == null)
            {
                return;
            }

            GraphicRaycaster        defaultRaycaster = canvas.gameObject.GetComponent <GraphicRaycaster>();
            VRTK_UIGraphicRaycaster customRaycaster  = canvas.gameObject.GetComponent <VRTK_UIGraphicRaycaster>();

            //if a custom raycaster exists then remove it
            if (customRaycaster != null)
            {
                Destroy(customRaycaster);
            }

            //If the default raycaster is disabled, then re-enable it
            if (defaultRaycaster != null && !defaultRaycaster.enabled)
            {
                defaultRaycaster.enabled = true;
            }

            //Check if there is a collider and remove it if there is
            if (canvasBoxCollider != null)
            {
                Destroy(canvasBoxCollider);
            }

            if (canvasRigidBody != null)
            {
                Destroy(canvasRigidBody);
            }

            if (draggablePanelCreation != null)
            {
                StopCoroutine(draggablePanelCreation);
            }

            Transform draggablePanel = canvas.transform.Find(CANVAS_DRAGGABLE_PANEL);

            if (draggablePanel != null)
            {
                Destroy(draggablePanel.gameObject);
            }

            Transform frontTrigger = canvas.transform.Find(ACTIVATOR_FRONT_TRIGGER_GAMEOBJECT);

            if (frontTrigger != null)
            {
                Destroy(frontTrigger.gameObject);
            }
        }
예제 #3
0
        // Token: 0x06001A97 RID: 6807 RVA: 0x0008C2EC File Offset: 0x0008A4EC
        protected virtual void SetupCanvas()
        {
            Canvas component = base.GetComponent <Canvas>();

            if (!component || component.renderMode != RenderMode.WorldSpace)
            {
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.REQUIRED_COMPONENT_MISSING_FROM_GAMEOBJECT, new object[]
                {
                    "VRTK_UICanvas",
                    "Canvas",
                    "the same",
                    " that is set to `Render Mode = World Space`"
                }));
                return;
            }
            RectTransform           component2 = component.GetComponent <RectTransform>();
            Vector2                 sizeDelta  = component2.sizeDelta;
            GraphicRaycaster        component3 = component.gameObject.GetComponent <GraphicRaycaster>();
            VRTK_UIGraphicRaycaster vrtk_UIGraphicRaycaster = component.gameObject.GetComponent <VRTK_UIGraphicRaycaster>();

            if (!vrtk_UIGraphicRaycaster)
            {
                vrtk_UIGraphicRaycaster = component.gameObject.AddComponent <VRTK_UIGraphicRaycaster>();
            }
            if (component3 && component3.enabled)
            {
                vrtk_UIGraphicRaycaster.ignoreReversedGraphics = component3.ignoreReversedGraphics;
                vrtk_UIGraphicRaycaster.blockingObjects        = component3.blockingObjects;
                component3.enabled = false;
            }
            if (!component.gameObject.GetComponent <BoxCollider>())
            {
                Vector2 pivot = component2.pivot;
                float   num   = 0.1f / component2.localScale.z;
                this.canvasBoxCollider           = component.gameObject.AddComponent <BoxCollider>();
                this.canvasBoxCollider.size      = new Vector3(sizeDelta.x, sizeDelta.y, num);
                this.canvasBoxCollider.center    = new Vector3(sizeDelta.x / 2f - sizeDelta.x * pivot.x, sizeDelta.y / 2f - sizeDelta.y * pivot.y, num / 2f);
                this.canvasBoxCollider.isTrigger = true;
            }
            if (!component.gameObject.GetComponent <Rigidbody>())
            {
                this.canvasRigidBody             = component.gameObject.AddComponent <Rigidbody>();
                this.canvasRigidBody.isKinematic = true;
            }
            this.draggablePanelCreation = base.StartCoroutine(this.CreateDraggablePanel(component, sizeDelta));
            this.CreateActivator(component, sizeDelta);
        }
예제 #4
0
        // Token: 0x06001A9A RID: 6810 RVA: 0x0008C61C File Offset: 0x0008A81C
        protected virtual void RemoveCanvas()
        {
            Canvas component = base.GetComponent <Canvas>();

            if (!component)
            {
                return;
            }
            GraphicRaycaster        component2 = component.gameObject.GetComponent <GraphicRaycaster>();
            VRTK_UIGraphicRaycaster component3 = component.gameObject.GetComponent <VRTK_UIGraphicRaycaster>();

            if (component3)
            {
                Object.Destroy(component3);
            }
            if (component2 && !component2.enabled)
            {
                component2.enabled = true;
            }
            if (this.canvasBoxCollider)
            {
                Object.Destroy(this.canvasBoxCollider);
            }
            if (this.canvasRigidBody)
            {
                Object.Destroy(this.canvasRigidBody);
            }
            base.StopCoroutine(this.draggablePanelCreation);
            Transform transform = component.transform.Find("VRTK_UICANVAS_DRAGGABLE_PANEL");

            if (transform)
            {
                Object.Destroy(transform.gameObject);
            }
            Transform transform2 = component.transform.Find("VRTK_UICANVAS_ACTIVATOR_FRONT_TRIGGER");

            if (transform2)
            {
                Object.Destroy(transform2.gameObject);
            }
        }