UGUI 帧动画插件

最近在开发一款功夫猫游戏,本来使用Unity Sprite制作,但是发现Sprite对各种分辨率不支持. 看着游戏很简单就使用UGUI制作,在中途发现有很多帧动画播放,使用了Animation调整使用多了的确很不方便.
于是改成脚本来控制Sprite帧动画切换,慢慢开始形成了写一个插件来调整. 写了两个通宵终于搞定了. O(∩_∩)O~
效果图:


代码:
组件类:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using System; /// <summary>
/// 帧动画组件
/// </summary>
[System.Serializable]
public class ImageAnimation : MonoBehaviour
{ private float animationDeltaTime;
public float animationDeltaTimer;
public List<AnimationInfoEntity> animationInfo;
public int type;
public Image visualize;
public int index;
public string animationTypeList;
public string tempAnimationTypeList;
public string[] animationTypeProp; public void Awake()
{
visualize = this.transform.GetComponent<Image>();
} public void Update()
{
animationDeltaTime += Time.deltaTime; #region List的用法
if (animationInfo != null && animationInfo.Count > 0 && animationDeltaTime > animationInfo[type].deltaTime)
{
if (animationInfo[type].animationSprite != null && animationInfo[type].animationSprite.Count != 0)
{
index++;
index = index % animationInfo[type].animationSprite.Count;
visualize.sprite = animationInfo[type].animationSprite[index];
animationDeltaTime = 0;
visualize.SetNativeSize();
}
}
#endregion
} /// <summary>
/// 切换动画状态
/// </summary>
/// <param name="index">输入动画状态下标值</param>
public void ChangeAnimationState(int index)
{
if (animationTypeProp != null)
{
if (index < animationTypeProp.Length)
{
type = index;
}
}
} /// <summary>
/// 切换动画状态
/// </summary>
/// <param name="animationStateName">输入动画状态的名称</param>
public void ChangeAnimationState(string animationStateName)
{
if (animationTypeProp != null)
{
for (int i = 0; i < animationTypeProp.Length; i++)
{
if (animationTypeProp[i].Equals(animationStateName))
{
type = i;
return;
}
}
}
} } [System.Serializable]
public class AnimationInfoEntity
{
/// <summary>
/// 动画状态
/// </summary>
public int type; /// <summary>
/// 播放当前帧需要的时间
/// </summary>
public float deltaTime; /// <summary>
/// 动画状态所需要的图片集合
/// </summary> public List<Sprite> animationSprite; public AnimationInfoEntity() { } public AnimationInfoEntity(int type, float deltaTime, int spriteNum = 1)
{
this.type = type;
this.deltaTime = deltaTime;
animationSprite = new List<Sprite>();
}
}
编辑器类:
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
using System;
using System.Reflection;
using System.Reflection.Emit; [CustomEditor(typeof(ImageAnimation))]
public class AnimationEditor : Editor
{
public void OnEnable()
{
ImageAnimation model = target as ImageAnimation; if (model.tempAnimationTypeList == null)
{
model.tempAnimationTypeList = string.Empty;
} if (model.animationInfo == null)
{
model.animationInfo = new List<AnimationInfoEntity>();
}
} public override void OnInspectorGUI()
{ ImageAnimation model = target as ImageAnimation;
if (!string.IsNullOrEmpty(model.animationTypeList)) {
model.animationTypeProp = model.animationTypeList.Split (';');
} #region 动画分割 GUILayout.BeginHorizontal();
GUILayout.Label("所有图片每帧时间: ", new GUILayoutOption[] { GUILayout.Width(120) });
model.animationDeltaTimer = EditorGUILayout.FloatField(model.animationDeltaTimer);
if (GUILayout.Button("统一时间"))
{
for (int j = 0; j < model.animationInfo.Count; j++)
{
model.animationInfo[j].deltaTime = model.animationDeltaTimer;
}
}
GUILayout.EndHorizontal(); GUILayout.BeginHorizontal ();
GUILayout.Label("动画类型分隔符: ",new GUILayoutOption[]{ GUILayout.Width(120)});
model.tempAnimationTypeList = GUILayout.TextField(model.tempAnimationTypeList, 50);
if (GUILayout.Button ("重新定义动画类型"))
{
model.animationInfo = new List<AnimationInfoEntity>();
model.animationTypeList = model.tempAnimationTypeList;
model.animationTypeProp = model.animationTypeList.Split (';'); //初始化动画类型集合
for (int j = 0; j < model.animationTypeProp.Length; j++)
{
model.animationInfo.Add(new AnimationInfoEntity(j, model.animationDeltaTimer));
}
}
GUILayout.EndHorizontal ();
#endregion #region 绘制各个动画属性
if (model.animationTypeProp != null && !string.IsNullOrEmpty(model.animationTypeProp[0]))
{
for (int i = 0; i < model.animationTypeProp.Length; i++) { //draw animation typea
GUILayout.BeginHorizontal();
GUILayout.Label("动画类型: ", new GUILayoutOption[] { GUILayout.Width(60) });
int index = EditorGUILayout.Popup(i, model.animationTypeProp, new GUILayoutOption[] { GUILayout.Width(150) });
if (GUILayout.Button("+"))
{
model.animationInfo[i].animationSprite.Add(new Sprite());
} if (GUILayout.Button("-"))
{
if (model.animationInfo[i].animationSprite.Count > 0)
{
model.animationInfo[i].animationSprite.RemoveAt(model.animationInfo[i].animationSprite.Count - 1);
}
}
GUILayout.EndHorizontal(); //draw image list
GUILayout.BeginVertical();
if (model.animationInfo != null && model.animationInfo.Count > 0)
{
for (int k = 0; k < model.animationInfo[i].animationSprite.Count; k++)
{
GUILayout.BeginHorizontal();
GUILayout.Label("动画帧数: ", new GUILayoutOption[] { GUILayout.Width(60) });
EditorGUILayout.FloatField(model.animationInfo[i].deltaTime, new GUILayoutOption[] { GUILayout.Width(60) });
model.animationInfo[i].animationSprite[k] = EditorGUILayout.ObjectField("增加一个贴图", model.animationInfo[i].animationSprite[k], typeof(Sprite)) as Sprite;
GUILayout.EndHorizontal();
}
}
GUILayout.EndVertical();
}
}
#endregion serializedObject.ApplyModifiedProperties(); DrawAnimationButton();
} /// <summary>
/// 绘制动画切换按钮,方便用户切换动画,查看动画是否正确
/// </summary>
private void DrawAnimationButton()
{
ImageAnimation model = target as ImageAnimation;
if (model.animationTypeProp != null)
{
GUILayout.BeginHorizontal();
GUILayout.Label("切换动画状态: ",GUILayout.Width(80));
for (int i = 0; i < model.animationTypeProp.Length; i++)
{
if (GUILayout.Button(model.animationTypeProp[i],GUILayout.Width(50)))
{
model.ChangeAnimationState(i);
}
}
GUILayout.EndHorizontal();
}
}
}
下载地址: http://yunpan.cn/cFRfdgXhK6ff2 访问密码 3aed
UGUI 帧动画插件的更多相关文章
- UGUI 过渡动画插件,模仿NGUI的Tween (转载)
最近在相亲,后来好朋友跟我说他写了一个好插件,于是我就把女朋友甩了,看看他的插件,可以在UGUI制作简单过渡动画. 我看了下是模仿NGUI的Tween, 我在筱程的基础上稍微改到人性化, 简单支持的让 ...
- [UGUI]帧动画
ImageFrameAnimation.cs using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; [R ...
- Unity CCTween UGUI 动画插件
在这简单的介绍一下 CCTween 动画插件的使用 因为GIF 制作软件不太好(网上随便下载的)所以导致效果不太好,有时间我重新制作一下 这是一下简单的效果 下面介绍怎么使用 首先 先下载 CCTwe ...
- 让网站动起来!12款优秀的 jQuery 动画插件推荐
如今,大多数设计师和开发人员被要客户要求开发动态的网站.创造视觉震撼和醒目的动态网站是艰巨的任务,因为它需要大量的努力和创造力.在网络上有大量的工具和插件可用于创建网站动画.许多开发人员正在使用 HT ...
- 程序猿必备的10款web前端动画插件一
1.动画SVG框架幻灯片 在幻灯片之间切换时显示动画SVG帧的实验性幻灯片.不同的形状可以用来创建各种风格. 我们想和大家分享一个实验幻灯片.我们的想法是在从一个幻灯片转换到另一张幻灯片时,使SVG帧 ...
- Lottie在手,动画我有:ios/Android/Web三端复杂帧动画解决方案
为什么需要Lottie 在相对复杂的移动端应用中,我们可能会需要使用到复杂的帧动画.例如: 刚进入APP时候可能会看到的入场小动画,带来愉悦的视觉享受 许多Icon的互动变化比较复杂多变的时候,研 ...
- 深入理解CSS3 Animation 帧动画
CSS3我在5年之前就有用了,包括公司项目都一直在很前沿的技术. 最近在写慕课网的七夕主题,用了大量的CSS3动画,但是真的沉淀下来仔细的去深入CSS3动画的各个属性发现还是很深的,这里就写下关于帧动 ...
- Android动画效果之Frame Animation(逐帧动画)
前言: 上一篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画),今天来总结下Android的另外一种动画Frame ...
- android 帧动画,补间动画,属性动画的简单总结
帧动画——FrameAnimation 将一系列图片有序播放,形成动画的效果.其本质是一个Drawable,是一系列图片的集合,本身可以当做一个图片一样使用 在Drawable文件夹下,创建ani ...
随机推荐
- 由mysql数据库基础上的php程序实现单词的查询、删除、更改和查询
我做了一个php程序,将表单数据添加到数据库,借用mysql扩展库函数实现对mysql数据库的操作,能够实现添加单词.删除单词.更新和查询单词.运行环境是普通的mysql数据库和php.Apache服 ...
- AssemblyInfo.cs文件的作用
在asp.net中有一个配置文件AssemblyInfo.cs主要用来设定生成的有关程序集的常规信息dll文件的一些參数,以下是默认的AssemblyInfo.cs文件的内容详细介绍 //是否符合公共 ...
- NoSQL 数据库的使用场景
摘要:对比传统关系型数据库,NoSQL有着更为复杂的分类——键值.面向文档.列存储.图数据库.这里就带你一览NoSQL各种类型的适用场景及一些知名公司的方案选择. 在过去几年,关系型数据库一直是数据持 ...
- stat(),lstat(),fstat() 获取文件/目录的相关信息
stat 的使用 Linux有个命令,ls -l,效果如下: 这个命令能显示文件的类型.操作权限.硬链接数量.属主.所属组.大小.修改时间.文件名.它是怎么获得这些信息的呢,请看下面的讲解. stat ...
- JavaScript学习笔记:检测数组方法
检查数组的方法 很多时候我们需要对JavaScript中数据类型(Function.String.Number.Undefined.Boolean和Object)做判断.在JavaScript中提供了 ...
- (转)android客户端从服务器端获取json数据并解析的实现代码
今天总结一下android客户端从服务器端获取json数据的实现代码,需要的朋友可以参考下 首先客户端从服务器端获取json数据 1.利用HttpUrlConnection 复制代码 ...
- Android SQLite API的使用(非原创)
1.使用SQLite的API来进行数据库的添加.删除.修改.查询 package com.example.sqlitedatabase.test; import android.content.Con ...
- 浅谈js闭包
相信很多人只知道闭包这个词但是具体是怎么回事就不太清楚了,最近在群里有很多小伙伴讨论这个问题但还是蒙眬眬的赶脚.索性就写了这篇文章来帮助大家一起理解闭包. 变量作用域 闭包其实想明白了很简单,但是在理 ...
- 练习—单链表—Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2-& ...
- 《转载》深入理解 cocos2d-x 坐标系
原文地址:http://www.cnblogs.com/lyout/p/3292702.html. 首先我们添加两个测试精灵(宽:27,高:40)到场景里面: CCSprite *sprite1 = ...