效果预览

视频: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动画)的更多相关文章

  1. 【转】发布一个基于NGUI编写的UI框架

    发布一个基于NGUI编写的UI框架 1.加载,显示,隐藏,关闭页面,根据标示获得相应界面实例 2.提供界面显示隐藏动画接口 3.单独界面层级,Collider,背景管理 4.根据存储的导航信息完成界面 ...

  2. Unity3D-深入剖析NGUI的游戏UI架构

    Unity3D-NGUI分析,使用NGUI做UI须要注意的几个要点在此我想罗列一下,对我在U3D上做UI的一些总结,最后解剖一下NGUI的源码.它是假设架构和运作的. 在此前我介绍了自己项目的架构方式 ...

  3. iOS - Core Animation 核心动画

    1.UIView 动画 具体讲解见 iOS - UIView 动画 2.UIImageView 动画 具体讲解见 iOS - UIImageView 动画 3.CADisplayLink 定时器 具体 ...

  4. Unity3D学习笔记(十四):Animation旧动画

        animator(新动画系统):骨骼动画,骨骼驱动,格式化编辑,动画机图形化 animation(旧动画系统):物理系统,帧动画 一.如何建立动画文件 Animation Clip 手动添加动 ...

  5. 帧动画 连续播放多张图片动画 以及ui动画 SoundPool

    drawable下有很多图片  可以 <?xml version="1.0" encoding="utf-8"?> <animation-li ...

  6. COCOS2D-X中UI动画导致闪退与UI动画浅析

    前两天和同事一起查一个游戏的闪退问题,log日志显示最后挂在CCNode* ActionNode::getActionNode()函数中的首行CCNode* cNode = dynamic_cast& ...

  7. iOS开发基础知识:Core Animation(核心动画)

    Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍.也就是说,使用少量的代码就可以实现非常强大的功能. Core A ...

  8. Android动画总结#补间动画(Tween Animation/View Animation) #帧动画(Frame Animation/Drawable Animation)#属性动画(PropertyAnimation)

    1.共有三种动画,英文名字多种叫法如下 第一种动画:补间动画(Tween Animation/View Animation) 四个:RotateAnimation旋转. AlphaAnimation透 ...

  9. Android Property Animation 物业动画

    效果图:   Property Animation介绍: 出生在sdk3.0,是利用了View所拥有的属性,进行一系列的操作. 比方一个View有什么样的setAbc的属性,那么理论上就能够设置它. ...

随机推荐

  1. VIM学习网址和资料收集

     摘要:这篇博客主要收集一些学习VIM的好网址和资料 娄老师的一篇VIM 原文地址:http://www.cnblogs.com/rocedu/p/6012444.html Github上VIM的学习 ...

  2. java日期互转:LocalDateTime、String、TimeStamp、Long、Instant、Date

    由于java版本的迭代,一个使用java开发的项目中可能出现多种日期对象,例如LocalDateTime.LocalDate.Date,不像C#只有一个DateTime,因此在各种日期格式或者对象之间 ...

  3. c语言-遍历pci设备(1)io访问

    前言 最近楼主比较苦逼啊,主管布置了一道访问pci的作业,这个作业使用io方式还可以非常浪地将所有的东西都给读取出来,虽然不能读取出pci-e设备的所有信息,但是还是可以将256位的其他东西给读出来的 ...

  4. es6学习笔记9--函数的扩展

    函数参数的默认值 基本用法 在ES6之前,不能直接为函数的参数指定默认值,为了避免这个问题,通常需要先判断一下参数y是否被赋值,如果没有,再等于默认值. ES6允许为函数的参数设置默认值,即直接写在参 ...

  5. POJ 2234 Matches Game (尼姆博弈)

    题目链接: https://cn.vjudge.net/problem/POJ-2234 题目描述: Here is a simple game. In this game, there are se ...

  6. [转]Microsoft SQL SERVER 2008 R2 REPORT SERVICE 匿名登录

    本文转自:https://www.cnblogs.com/Zouzhe/p/5736070.html SQL SERVER 2008 R2 是微软目前最新的数据库版本,在之前的SQL SERVER 2 ...

  7. ASP.NET 之 EntityFramework实体框架搭建

    前段时间接触了EntityFramework,对ORM框架也是有了初步的认识,现在对其进行一点小总结. 一.ORM简介 对象关系映射(Object Relational Mapping,简称ORM)模 ...

  8. .net 多线程的使用(Thread)

    上篇 net 同步异步 中篇 多线程的使用(Thread) 下篇 net 任务工厂实现异步多线程 Thread多线程概述 上一篇我们介绍了net 的同步与异步,我们异步演示的时候使用的是委托多线程来实 ...

  9. [PHP] B2B2C商品模块数据库设计

    /**************2016年4月25日 更新********************************************/ 知乎:产品 SKU 是什么意思?与之相关的还有哪些? ...

  10. 37.Linux驱动调试-根据oops的栈信息,确定函数调用过程

    上章链接入口: http://www.cnblogs.com/lifexy/p/8006748.html 在上章里,我们分析了oops的PC值在哪个函数出错的 本章便通过栈信息来分析函数调用过程 1. ...