zoukankan      html  css  js  c++  java
  • NGUI使用3——制作图集&自定义按钮&切换按钮图片

    1,准备素材
    新建一个文件夹,命名为UITexture。

    2,创建Atlas
    在Project面板中,进入UITexture 文件夹,选中这两张图片,然后 右键-->【NGUI】-->【Atlas Maker】,之后你会看到 Atlas Maker 的界面:
    在 Atlas Maker 界面中,点击【Create】按钮。

    之后给这个Atlas 起名为MyAtlas.prefab,点击【保存】。

    3,预览Atlas和Sprite
    保存之后,这个新的Atlas 就创建好了。可以点击一下【View Sprites】,预览一下创建好的精灵。

    制作自定义按钮

    (1)在Project面板中,搜索“Control”,也就是搜索控件。之后,会发现NGUI的一堆控件。
    (2)找到 Simple Button,拖拽到层级面板下面。我这里把它拖拽到Container下面了。
    (3)删除label子对象,在Container组建中(UIscript)Atlas选择图集,在scripte中选择精灵,可以调整精灵大小
    (4)OK

    切换图片
    01
    using UnityEngine;
    02
    using System.Collections;
    03

    04
    public class TestButton : MonoBehaviour {
    05
    protected bool switchFlag = true;
    06

    07
    // Use this for initialization
    08
    void Start () {
    09

    10
    }
    11

    12
    void OnClick () {
    13
    if (this.switchFlag) {
    14
    this.GetComponent<UISprite> ().spriteName = "pause";
    15
    this.GetComponent<UIButton> ().normalSprite = "pause";
    16
    this.switchFlag = false;
    17
    }
    18
    else{
    19
    this.GetComponent<UISprite>().spriteName = "start";
    20
    this.GetComponent<UIButton>().normalSprite = "start";
    21
    this.switchFlag = true;
    22
    }
    23
    }
    24
    }

  • 相关阅读:
    使用a标签制作tooltips
    使用editorconfig配置你的编辑器
    JointJS绘制流程图
    用highcharts展现你的数据
    css段落首字母下沉
    sklearn框架的系统学习
    numpy删除二维数据矩阵的行和列
    sklearn中机器学习算法评价指标
    sklearn调用逻辑回归算法
    sklearn调用多项式回归
  • 原文地址:https://www.cnblogs.com/lv-sally/p/4555599.html
Copyright © 2011-2022 走看看