コード例 #1
0
    void Update()
    {
#if UNITY_EDITOR
        if (m_gameFlow == null)
        {
            m_gameFlow = GameFlow.Instance;
        }
#endif

        if (m_gameFlow.CurrentControlContext != GameFlow.ControlContext.World)
        {
            return;
        }

        if (m_objectsInView.Count > 0)
        {
            if (m_currentTab >= m_objectsInRange.Count)
            {
                m_currentTab = m_objectsInRange.Count - 1;
            }

            if (m_currentTab >= m_objectsInRange.Count)
            {
                m_currentTab = m_objectsInRange.Count - 1;
            }

            List <Interaction> interactions = m_objectsInView[0].GetInteractions(ContextFlag.World);

            if (Input.GetButtonUp("option_0") && interactions[0].Enabled)
            {
                interactions[0].Callback(interactions[0], gameObject);
            }

            if (interactions.Count > 1)
            {
                if (Input.GetButtonUp("option_1") && interactions[1].Enabled)
                {
                    interactions[1].Callback(interactions[1], gameObject);
                }
            }
        }

        for (int i = 0; i < m_objectsInView.Count; i++)
        {
            m_objectsInView[i].SetHighlightActive(false);
        }

        m_objectsInView.Clear();

        float minAngle = m_view.DirectionAngleDeg - InspectionFocusAngle;

        const float iterationCount = 10.0f;

        float sweepDelta = (InspectionFocusAngle * 2.0f) / iterationCount;

        for (int sweepCount = 0; sweepCount < iterationCount; ++sweepCount)
        {
            float   progress         = minAngle + (sweepCount * sweepDelta);
            Vector3 currentDirection = (Quaternion.Euler(0.0f, progress, 0.0f)) * Vector3.forward;
            if (m_renderDebug)
            {
                Debug.DrawLine(transform.position + new Vector3(0.0f, -1.0f, 0.0f), transform.position + new Vector3(0.0f, -1.0f, 0.0f) + currentDirection, Color.red);
            }

            RaycastHit[] hits = Physics.RaycastAll(transform.position, currentDirection, 1.0f, m_layerMask);

            System.Array.Sort(hits, CompareHits);
            if (hits.Length > 0 && (hits[0].collider.gameObject.layer & m_worldCollisionLayerID) != 0)
            {
                continue;
            }
            else
            {
                foreach (var currentHit in hits)
                {
                    InteractiveObject interactiveObject = currentHit.collider.gameObject.GetComponent <InteractiveObject>();
                    if (interactiveObject != null && !m_objectsInView.Contains(interactiveObject) && interactiveObject.GetInteractions(ContextFlag.World).Count > 0)
                    {
                        m_objectsInView.Add(interactiveObject);
                        interactiveObject.SetHighlightActive(true);
                    }
                }
            }
        }
    }