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 ...
随机推荐
- Hive集成HBase详解
摘要 Hive提供了与HBase的集成,使得能够在HBase表上使用HQL语句进行查询 插入操作以及进行Join和Union等复杂查询 应用场景 1. 将ETL操作的数据存入HBase 2. HB ...
- Android软键盘弹出时布局问题
最近项目需要做一个类似聊天室的模块,基于Socket实现的,这部分稍后一段时间再做总结,功能上的相关点都实现了小例子也做出来了,最后发现一个比较腻歪的问题就是软键盘弹出时总是会把标题“挤出”屏幕,(无 ...
- javascript 模仿 html5 placeholder
<form action="?action=deliver" method="post" class="deliver-form"&g ...
- Code First 数据注释--InverseProperty 和 ForeignKey
ForeignKey 按照约定在Post类中看到BlogId属性,会认为是Blog类的外键,但是在Blog类中并没有BlogId属性,解决方法是,在 Post 中创建一个导航属性,并使用 Foreig ...
- js改变div宽度
document.getElementById('Content_Right_id').style.width = document.documentElement.clientWidth - 250 ...
- Memcached的一些知识
一.内存分配在Memcached内存结构中有两个非常重要的概念:slab 和 chunk,我们先从下图中对这两个概念有一个感性的认识: memcached内存结构Slab是一个内存块,它是memcac ...
- SVN CornerStone的使用
http://www.henishuo.com/mac-cornerstone-svn-use/
- 编写优秀jQuery插件的10个技巧
前言:在开发过很多 jQuery 插件以后,我慢慢的摸索出了一套开发jQuery插件比较标准的结构和模式.这样我就可以 copy & paste 大部分的代码结构,只要专注最主要的逻辑代码就行 ...
- lunix安装jdk(rpm格式)
1.下载后,首先把jdk-7u3-linux-x64.rpm复制到/usr/local/src#cp jdk-7u3-linux-x64.rpm /usr/local/src/2.给所有用户添加可执行 ...
- Android开发重修
Android程序开发的重新学习 #####Mars课程学习笔记20140926 1.Service主要用于完成耗时较长的操作,没有图形化界面. 2.Content Provider数据的提供者,是A ...