예제 #1
0
    /// <summary>
    /// 显示开宝箱
    /// </summary>
    public void ShowOpenChest()
    {
        if (!IsDead() && !IsBattling() && !IsLeaping() && !IsWatchOrUIInputMode())
        {
            SpacecraftEntity entity = m_RaycastProxy.Raycast();
            if (entity && (entity.GetCurrentState().GetMainState() != EnumMainState.Dead) && entity.GetHeroType() == KHeroType.htLockChest)
            {
                Vector3 titleOffset = Vector3.zero;
                m_TargetNpcUID = entity.GetUId();
                //头顶偏移

                Npc entityVO = m_CfgEternityProxy.GetNpcByKey(entity.GetTemplateID());
                if (Vector3.Distance(entity.transform.position, m_MainEntity.transform.position) > entityVO.TriggerRange)
                {
                    return;
                }
                if (entityVO.HeroHeaderLength >= 3)
                {
                    titleOffset = new Vector3(entityVO.HeroHeader(0), entityVO.HeroHeader(1), entityVO.HeroHeader(2));
                }

                //忽略屏幕外的
                Vector3 screenPosition = m_MainCamera.WorldToScreenPoint(entity.transform.TransformPoint(titleOffset));
                if (screenPosition.z > m_MainCamera.nearClipPlane && screenPosition.x >= 0 && screenPosition.x <= m_MainCamera.pixelWidth && screenPosition.y > 0 && screenPosition.y <= Camera.main.pixelHeight)
                {
                    Vector2 anchoredPosition;
                    if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_Root, screenPosition, m_Camera, out anchoredPosition))
                    {
                        m_Content.anchorMin        = m_Content.anchorMax = Vector2.one * 0.5f;
                        m_Content.anchoredPosition = anchoredPosition;
                    }

                    if (!m_Content.gameObject.activeSelf && entity.GetIsActive())
                    {
                        m_Content.gameObject.SetActive(true);
                        ResetAnimators(null, HotkeyPhase.Disabled, true);
                    }
                }
                else
                {
                    m_Content.gameObject.SetActive(false);
                }
                return;
            }
            else
            {
                m_Content.gameObject.SetActive(false);
            }
        }
        else
        {
            m_Content.gameObject.SetActive(false);
        }
    }