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
    }

  • 相关阅读:
    dayⅦ:元组、字典的其他操作+集合类型
    dayⅥ:作业
    dayⅥ:字符串操作+列表操作
    dayⅣ:赋值运算+if判断
    dayⅣ:赋值运算+if判断作业
    dayⅢ、基本数据类型+运算符
    爬虫解析bs4
    爬虫请求库之requests库
    爬虫原理
    各主流Linux系统解决方案pip安装mysqlclient报错
  • 原文地址:https://www.cnblogs.com/lv-sally/p/4555599.html
Copyright © 2011-2022 走看看