Example #1
0
 public void OnEventUpdateHeadUI(BattleHeadUILogic.HeadUIParam param)
 {
     if (param.type != Monster.MonsterType.Boss)
     {
         OnEventUpdateMonsterHeadUI(param);
     }
     else
     {
         OnEventUpdateBossHeadUI(param);
     }
     HeadUIParam.Store(param);
 }
Example #2
0
    public void OnEventAppendFloatArtNumber(BattleHeadUILogic.HeadUIParam param)
    {
        int    score = param.damage;
        string text  = score.ToString();

        // 计算每个位置的数值
        int[] value = new int[4];
        int   level = 100;
        int   count = 1;
        bool  sign  = false;

        for (int index = 1; index < 4; ++index)
        {
            int number = (score / level) % 10;
            if (number > 0 && sign == false)
            {
                sign = true;
            }

            if (sign)
            {
                value[count++] = number;
            }
            level /= 10;
        }

        // 临时数据保存
        FloatUI floatUI = new FloatUI();

        floatUI.uiGo = GameObject.Instantiate(view.panel_FloatArtNumber.gameObject) as GameObject;
        floatUI.uiGo.transform.SetParent(view.ui_Parent.transform);
        floatUI.uiGo.transform.localScale = Vector3.one;

        // 获得Image组件
        Image[] artNumberSprite = new Image[4];
        for (int i = 0; i < 4; i++)
        {
            int number = i + 1;
            artNumberSprite[i] = floatUI.uiGo.transform.FindChild("Image_Number" + number.ToString()).GetComponent <Image>();
            artNumberSprite[i].gameObject.SetActive(false);
        }

        // 根据要显示的文字进行位置显示
        SetSpritePositionByLength(score.ToString().Length + 1, artNumberSprite);

        // 设置颜色
        Color color;

        if (param.type == Monster.MonsterType.NPC)
        {
            color = Color.green;
        }
        else
        {
            color = Color.red;
        }

        // 设置图片并显示
        Vector2 size = new Vector2(21, 29);

        for (int i = 0; i < text.Length; i++)
        {
            int  num    = 0;
            bool result = int.TryParse(text.Substring(i, 1), out num);
            if (i == 0)
            {
                artNumberSprite[0].gameObject.SetActive(true);
                artNumberSprite[0].color = color;
            }
            artNumberSprite[i + 1].sprite = view.image_Numbers[value[i + 1]].sprite;
            artNumberSprite[i + 1].gameObject.SetActive(true);
            artNumberSprite[i + 1].rectTransform.sizeDelta = size;
            artNumberSprite[i + 1].color = color;
        }

        // 映射头顶位置进行显示
        Vector2 pos;
        Canvas  canvas = floatUI.uiGo.GetComponent <Image>().canvas;

        pos = Camera.main.WorldToScreenPoint(param.goHead.transform.position);
        if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, pos, null, out pos))
        {
            floatUI.uiGo.GetComponent <RectTransform>().anchoredPosition = pos;
        }

        floatUI.uiGo.SetActive(true);
        // 动画表现
        RectTransform rectTransform = floatUI.uiGo.GetComponent <RectTransform>();
        Sequence      sequence      = DOTween.Sequence();

        pos.y += 50;
        sequence.Append(rectTransform.DOAnchorPos(pos, 1.0f));
        if (param.min == 0)
        {
            pos.Set(-554f, -409);
            sequence.Append(rectTransform.DOAnchorPos(pos, 0.75f));
        }
        else if (param.min == 1)
        {
            pos.Set(72f, -409);
            sequence.Append(rectTransform.DOAnchorPos(pos, 0.75f));
        }
        else if (param.min == 2)
        {
            pos.Set(711f, -409);
            sequence.Append(rectTransform.DOAnchorPos(pos, 0.75f));
        }
        sequence.OnComplete(OnFloatUIDisappearEnd);
        floatUI.index  = param.min;
        floatUI.damage = score;
        floatUIList.Add(floatUI);
        HeadUIParam.Store(param);
        // 1: -554  -409

        // 2:  72   -409

        // 3:  711  -409
    }