Esempio n. 1
0
        private void Awake()
        {
            if (ReticleTransform == null)
            {
                ReticleTransform = transform;
            }
            if (ReticleImage == null)
            {
                ReticleImage = transform.Find("Image").GetComponent <Image>();
            }
            if (Source == null)
            {
                Source = transform.parent.GetComponent <VRControllerRaycaster>();
            }

            // Store the original scale and rotation.
            m_OriginalScale    = ReticleTransform.localScale;
            m_OriginalRotation = ReticleTransform.localRotation;
        }
Esempio n. 2
0
        // Use this for initialization
        void Start()
        {
            if (Source == null)
            {
                Source = transform.parent.GetComponent <VRControllerRaycaster>();
            }
            if (Reticle == null)
            {
                Reticle = GetComponent <Reticle>();
            }
            if (FromTransform == null)
            {
                FromTransform = Source.Input.transform;
            }

            if (hasOff)
            {
                m_OffRenderer               = new GameObject("OffLine").AddComponent <LineRenderer>();
                m_OffRenderer.startWidth    = OffStartWidth;
                m_OffRenderer.endWidth      = OffEndWidth;
                m_OffRenderer.startColor    = OffColor;
                m_OffRenderer.material      = OffMaterial;
                m_OffRenderer.endColor      = new Color(OffColor.r, OffColor.g, OffColor.b, 0);
                m_OffRenderer.useWorldSpace = true;
                m_OffRenderer.enabled       = false;
            }

            if (hasOn)
            {
                m_OnRendererColor = new GameObject("OnLineColor").AddComponent <LineRenderer>();
                m_OnRendererWhite = new GameObject("OnLineWhite").AddComponent <LineRenderer>();

                Vector3[] v3LinePositions = new Vector3[] { Vector3.zero, new Vector3(0, 0, 1) };
                foreach (LineRenderer r in new LineRenderer[] { m_OnRendererColor, m_OnRendererWhite })
                {
                    r.numCapVertices = CapVerts;
                    r.positionCount  = v3LinePositions.Length;
                    r.SetPositions(v3LinePositions);
                    r.useWorldSpace = true;
                    r.material      = OnMaterial;
                }

                m_OnRendererColor.startWidth = OnWidth;
                m_OnRendererColor.endWidth   = OnWidth;
                m_OnRendererColor.startColor = OnColor;
                m_OnRendererColor.endColor   = OnColor;
                m_OnRendererWhite.startWidth = CenterWidthRel * OnWidth;
                m_OnRendererWhite.endWidth   = CenterWidthRel * OnWidth;
                m_OnRendererWhite.startColor = Color.white;
                m_OnRendererWhite.endColor   = Color.white;
                m_OnRendererColor.enabled    = false;
                m_OnRendererWhite.enabled    = false;
            }

            foreach (LineRenderer r in new LineRenderer[] { m_OffRenderer, m_OnRendererColor, m_OnRendererWhite })
            {
                if (r)
                {
                    r.transform.SetParent(transform);
                    r.transform.localPosition = Vector3.zero;
                }
            }
        }