NGUI Clip Animation (UI动画)
效果预览
视频:http://pan.baidu.com/s/1ntr3XSt
运行环境
Unity 4.5, NGUI3.5, iTween
场景搭建
创建一个UIPanel,UIPanel下再创建一个UISprite,UIPanel选择SoftClip,然后给Panel绑定上PanelController.cs,拷贝4份。结构如下图
MaskManager
给UIRoot绑定PanelController.cs,Targets绑定上面创建的四个Panel,点击Play ,按数字键 0,1,2,3,4 切换效果

MaskManager代码
using UnityEngine;
using System.Collections;
using System.Collections.Generic; public class MaskManager : MonoBehaviour {
public GameObject[] Targets; private List<PanelController> clipList;
private float sw = 1024f;
private float sh = 576f; // Use this for initialization
void Start () {
clipList = new List<PanelController>();
foreach(var target in Targets) {
clipList.Add(target.AddComponent<PanelController>());
} Init();
} // Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.Alpha1)) {
ShowFullImage(0);
} else if(Input.GetKeyDown(KeyCode.Alpha2)) {
ShowFullImage(1);
} else if(Input.GetKeyDown(KeyCode.Alpha3)) {
ShowFullImage(2);
} else if(Input.GetKeyDown(KeyCode.Alpha4)) {
ShowFullImage(3);
} else if(Input.GetKeyDown(KeyCode.Alpha0)) {
Init();
}
} void Init() {
for(int i=0; i<clipList.Count; i++) {
var size = new Vector2((sw / clipList.Count), sh);
var offset = new Vector2(-sw * 0.5f + (i + 0.5f) * (sw / clipList.Count), 0f);
clipList[i].UpdateOffset(offset);
clipList[i].UpdateSize(size);
}
} void ShowFullImage(int id) {
for(int i =0; i<clipList.Count; i++) {
if(i != id) {
clipList[i].SetDepth(i);
} else {
clipList[i].SetDepth(clipList.Count);
}
}
clipList[id].UpdateOffset(new Vector2(0f, 0f));
clipList[id].UpdateSize(new Vector2(sw, sh));
}
}
using UnityEngine;
using System.Collections; public class PanelController : MonoBehaviour {
private UIPanel panel;
static private float animTime = 0.6f; void Awake() {
panel = GetComponent<UIPanel>();
} // Use this for initialization
void Start () {
} // Update is called once per frame
void Update () { } public void SetDepth(int depth) {
panel.depth = depth;
} public void UpdateSize(Vector2 size) {
var current = new Vector2(panel.baseClipRegion.z, panel.baseClipRegion.w);
iTween.ValueTo(gameObject, iTween.Hash("from", current, "to", size, "time", animTime, "onupdate", "OnUpdateSize"));
} public void UpdateOffset(Vector2 offset) {
iTween.ValueTo(gameObject, iTween.Hash("from", panel.clipOffset, "to", offset, "time", animTime, "onupdate", "OnUpdateOffset"));
} private void OnUpdateSize(Vector2 size) {
panel.baseClipRegion = new Vector4(0f, 0f, size.x, size.y);
} private void OnUpdateOffset(Vector2 offset) {
panel.clipOffset = offset;
}
}
NGUI Clip Animation (UI动画)的更多相关文章
- 【转】发布一个基于NGUI编写的UI框架
发布一个基于NGUI编写的UI框架 1.加载,显示,隐藏,关闭页面,根据标示获得相应界面实例 2.提供界面显示隐藏动画接口 3.单独界面层级,Collider,背景管理 4.根据存储的导航信息完成界面 ...
- Unity3D-深入剖析NGUI的游戏UI架构
Unity3D-NGUI分析,使用NGUI做UI须要注意的几个要点在此我想罗列一下,对我在U3D上做UI的一些总结,最后解剖一下NGUI的源码.它是假设架构和运作的. 在此前我介绍了自己项目的架构方式 ...
- iOS - Core Animation 核心动画
1.UIView 动画 具体讲解见 iOS - UIView 动画 2.UIImageView 动画 具体讲解见 iOS - UIImageView 动画 3.CADisplayLink 定时器 具体 ...
- Unity3D学习笔记(十四):Animation旧动画
animator(新动画系统):骨骼动画,骨骼驱动,格式化编辑,动画机图形化 animation(旧动画系统):物理系统,帧动画 一.如何建立动画文件 Animation Clip 手动添加动 ...
- 帧动画 连续播放多张图片动画 以及ui动画 SoundPool
drawable下有很多图片 可以 <?xml version="1.0" encoding="utf-8"?> <animation-li ...
- COCOS2D-X中UI动画导致闪退与UI动画浅析
前两天和同事一起查一个游戏的闪退问题,log日志显示最后挂在CCNode* ActionNode::getActionNode()函数中的首行CCNode* cNode = dynamic_cast& ...
- iOS开发基础知识:Core Animation(核心动画)
Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍.也就是说,使用少量的代码就可以实现非常强大的功能. Core A ...
- Android动画总结#补间动画(Tween Animation/View Animation) #帧动画(Frame Animation/Drawable Animation)#属性动画(PropertyAnimation)
1.共有三种动画,英文名字多种叫法如下 第一种动画:补间动画(Tween Animation/View Animation) 四个:RotateAnimation旋转. AlphaAnimation透 ...
- Android Property Animation 物业动画
效果图: Property Animation介绍: 出生在sdk3.0,是利用了View所拥有的属性,进行一系列的操作. 比方一个View有什么样的setAbc的属性,那么理论上就能够设置它. ...
随机推荐
- Andrew Ng机器学习课程笔记(一)之线性回归
Andrew Ng机器学习课程笔记(一)之线性回归 版权声明:本文为博主原创文章,转载请指明转载地址 http://www.cnblogs.com/fydeblog/p/7364598.html 前言 ...
- mysql 解决 timestamp 的2038问题
当 timestamp 存储的时间大于 '2038-01-19 03:14:07' UTC,mysql就会报错,因为这是 mysql自身的问题,也就是说 timestamp是有上限的,超过了,自然会报 ...
- C语言版 Hello World
C语言的Hello World 程序, 需要引入 <stdio.h> 头文件,输出使用 printf()方法: #include <stdio.h> int main() { ...
- 第七章 过滤器基础 Filter
简介:SUN从Servlet2.3开始添加一项激动人心的功能,就是过滤器(Filter).WEB开发人员通过Filter技术,对web服务器管理的所有web资源:例如Jsp, Servlet, 静态图 ...
- Rectangles(第七届ACM省赛原题+最长上升子序列)
题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=1255 描述 Given N (4 <= N <= 100) rec ...
- 深入出不来nodejs源码-流程总览
花了差不多两周时间过了下primer C++5th,完成了<C++从入门到精通>.(手动滑稽) 这两天看了下node源码的一些入口方法,其实还是比较懵逼的,语法倒不是难点,主要是大量的宏造 ...
- [转]Microsoft SQL SERVER 2008 R2 REPORT SERVICE 匿名登录
本文转自:https://www.cnblogs.com/Zouzhe/p/5736070.html SQL SERVER 2008 R2 是微软目前最新的数据库版本,在之前的SQL SERVER 2 ...
- python模块之xlrd
python处理excel的模块,xlrd读取excel,xlwt写入excel 一.安装 pip install xlrd 二.使用 1. 打开excel,得到Book对象 import xlrd ...
- WebFrom 【内置对象】— —跳转页面,页面传值
Response -- 响应请求对象 传值 Response.Redirect("url"); -- 地址?变量= 值 Response -- ...
- 使用pl/sql的文本导入器时如何设置主键自增长
在使用文本导入器批量导入数据时,如果需要设置主键自增长,可以先创建一个序列: create sequence SEQ_Userinf start with 1 increment by 1nomaxv ...
