Example #1
0
    /// <summary>
    /// 显示BuffIcon
    /// </summary>
    public void OnAddBufferIcon(SpacecraftEntity target)
    {
        RectTransform view = null;

        if (m_UIDToRectTranform1.ContainsKey(target.GetUId()))
        {
            view = m_UIDToRectTranform1[target.GetUId()].view;
        }
        else
        {
            if (m_UIDToRectTranform2.ContainsKey(target.GetUId()))
            {
                view = m_UIDToRectTranform2[target.GetUId()].view;
            }
            else
            {
                return;
            }
        }

        Transform bufferIconBox = view.Find("BuffIconBox");

        if (bufferIconBox == null)
        {
            return;
        }
        bufferIconBox.gameObject.SetActive(true);
        Transform iconTemplate = bufferIconBox.GetChild(0);

        iconTemplate.gameObject.SetActive(false);
        int index = 0;

        if (target.GetAllBuffs().Count > 0)
        {
            foreach (KeyValuePair <uint, Buff> buffID2Value in target.GetAllBuffs())
            {
                SkillBuff configVO = m_SkillProxy.GetBuff((int)buffID2Value.Key);


                Transform iconTras;
                if (configVO.ByteBuffer != null)
                {
                    if ((BufferType)configVO.BuffHudShow == BufferType.None)
                    {
                        continue;
                    }
                    // Debug.LogError(target.GetName() + "==============" + configVO.Id + "========"
                    //+ target.GetAllBuffs().Count + "=======" + (BufferType)configVO.BuffHudShow);
                    index++;
                    if (bufferIconBox.childCount >= index)
                    {
                        iconTras = bufferIconBox.GetChild(index - 1);
                    }
                    else
                    {
                        iconTras = Object.Instantiate(iconTemplate);
                        iconTras.SetParent(bufferIconBox);
                        iconTras.localScale    = Vector3.one;
                        iconTras.localPosition = Vector3.zero;
                        iconTras.SetAsLastSibling();
                    }
                    bufferIconBox.localScale = Vector3.one;
                    if (m_MainEntity == target)
                    {
                        bufferIconBox.localScale = Vector3.one * 1.5f;
                    }
                    if ((uint)configVO.BuffHudIcon > 0)
                    {
                        UIUtil.SetIconImage(iconTras.GetComponent <Image>(), (uint)configVO.BuffHudIcon);
                    }
                    else
                    {
                        Debug.LogWarning("报错" + configVO.Id);
                    }
                    //Debug.Log(configVO.BuffHudIcon + "-=-=-=-=-=-" + configVO.BuffHudShow);
                    switch ((BufferType)configVO.BuffHudShow)
                    {
                    case BufferType.All:                            //   1 全体
                        iconTras.gameObject.SetActive(true);
                        break;

                    case BufferType.Friend:                            //	2 友方

                        if (m_TeamProxy.GetMember(target.GetPlayerId()) != null)
                        {
                            iconTras.gameObject.SetActive(true);
                        }
                        break;

                    case BufferType.Enemy:                            //   3 敌方
                        if (m_MainEntity != target && m_TeamProxy.GetMember(target.GetPlayerId()) == null)
                        {
                            iconTras.gameObject.SetActive(true);
                        }
                        break;

                    case BufferType.Self:                            //   4 自己
                        if (m_MainEntity = target)
                        {
                            iconTras.gameObject.SetActive(true);
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            // Debug.Log(index);
            for (int i = index; i < bufferIconBox.childCount; i++)
            {
                bufferIconBox.GetChild(i).gameObject.SetActive(false);
            }
        }
        else
        {
            for (int i = 0; i < bufferIconBox.childCount; i++)
            {
                bufferIconBox.GetChild(i).gameObject.SetActive(false);
            }
        }
    }