欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

UGUI Image 动态更换纹理图片

程序员文章站 2022-05-30 17:38:35
...

UGUI Image 动态更换纹理图片

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class UIShop : View
{
    #region 常量
    #endregion

    #region 事件
    #endregion

    #region 字段
    public int selectIndex = 0;//选择
    public MeshRenderer ball;//足球材质

    public ItemState state = ItemState.UnBuy;//装备状态
    GameModel gm;
    //图片资源
    public Sprite spBuy; //已购买图片
    public Sprite spEquip; //已装备图片
    public Image imgBuyFootBall;//持有按钮图片
    #endregion

    #region 属性
    public override string Name
    {
        get
        {
            return Consts.V_Shop;
        }
    }
    #endregion

    #region 方法
    #region 足球
    public void NormalFootBall()
    {
        selectIndex = 0;
        ball.material = Game.Instance.staticData.GetFootballInfo(selectIndex).Material;
        UpdateBuyButton(selectIndex);
    }
    public void FireFootBall()
    {
        selectIndex = 1;
        ball.material = Game.Instance.staticData.GetFootballInfo(selectIndex).Material;
        UpdateBuyButton(selectIndex);
    }
    public void ColorFootBall()
    {
        selectIndex = 2;
        ball.material = Game.Instance.staticData.GetFootballInfo(selectIndex).Material;
        UpdateBuyButton(selectIndex);
    }
    //更新按钮显示
    public void UpdateBuyButton(int i)
    {
        state = gm.CheckFootBallState(i);
        switch (state)
        {
            case ItemState.UnBuy://未购买
                imgBuyFootBall.transform.gameObject.SetActive(true);
                imgBuyFootBall.overrideSprite = spBuy;//按钮图片显示购买
                break;
            case ItemState.Buy://已购买
                imgBuyFootBall.transform.gameObject.SetActive(true);
                imgBuyFootBall.overrideSprite = spEquip;//按钮图片显示装备
                break;
            case ItemState.Equip://已装备
                imgBuyFootBall.transform.gameObject.SetActive(false);
                break;
            default:
                break;
        }
    }
    #endregion
    #endregion

    #region Unity回调
    private void Awake()
    {
        gm = GetModel<GameModel>();
    }
    #endregion

    #region 事件回调
    public override void HandleEvent(string name, object data)
    {
    }
    #endregion

    #region 帮助方法
    #endregion

    

   
}

 

相关标签: UGUI