Example #1
0
    /// <summary>
    /// 创建时
    /// </summary>
    private void OnTargetCreate(SpacecraftEntity target, RectTransform view)
    {
        KHeroType entityType = target.GetHeroType();

        if (entityType == KHeroType.htMine)
        {
            TMP_Text nameField = view.Find("Name/Name/Label_Name").GetComponent <TMP_Text>();
            nameField.text = entityType == KHeroType.htPlayer ? target.GetName() : TableUtil.GetNpcName(target.GetTemplateID());

            //血段
            m_LineGrid = FindComponent <Transform>(view, "Slider/Image_Bar/LineGrid");

            int bloodVolumeLength = m_CfgEternityProxy.GetDoppingBloodVolumeLengthByKey((uint)target.GetTemplateID()) - 1;
            if (m_OldPrivew != bloodVolumeLength)
            {
                m_OldPrivew = bloodVolumeLength;
                while (m_LineGrid.childCount - 2 < bloodVolumeLength)
                {
                    Transform lineItem = Object.Instantiate(m_LineGrid.GetChild(1), m_LineGrid);
                    lineItem.gameObject.SetActive(true);
                }
                for (int i = bloodVolumeLength + 2; i < m_LineGrid.childCount; i++)
                {
                    m_LineGrid.GetChild(i).gameObject.SetActive(false);
                }
            }
        }
        else
        {
            //目标名称
            TMP_Text nameField = view.Find("Name/Name").GetComponent <TMP_Text>();
            nameField.text = entityType == KHeroType.htPlayer ? target.GetName() : TableUtil.GetNpcName(target.GetTemplateID());

            //目标图标
            Image image = view.Find("Name/Icon/ImageIcon").GetComponent <Image>();
            image.gameObject.SetActive(entityType != KHeroType.htPlayer);
            if (image.gameObject.activeSelf)
            {
                Npc entityVO = m_CfgEternityProxy.GetNpcByKey(target.GetTemplateID());
                if (entityVO.NameBoardIcon == 0)
                {
                    image.color = Color.clear;
                }
                else
                {
                    image.color = Color.white;
                    UIUtil.SetIconImage(image, entityVO.NameBoardIcon);
                }
            }
        }
    }