博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
动画缩放和移动
阅读量:6683 次
发布时间:2019-06-25

本文共 4412 字,大约阅读时间需要 14 分钟。

using DG.Tweening;using System.Collections;using System.Collections.Generic;using UnityEngine;namespace XGUI{
public class XScaleTween : MonoBehaviour {
public Ease m_ease = Ease.InOutBack; public Vector3 startValue = new Vector3(0.8f, 0.8f, 0.8f); public Vector3 endValue = new Vector3(1f, 1f, 1f); public float duration = 1.0f; public float delay = 0.0f; public int loops = 0; public LoopType loopType; private RectTransform rm_transform; public bool playAutomatically = false; private void Awake() {
rm_transform = gameObject.GetComponent
(); } public void SetPivot(float fx, float fy) {
Vector2 sizeD = rm_transform.sizeDelta; rm_transform.pivot = new Vector2(sizeD.x / fx, sizeD.y / fy); } private void OnEnable() {
if (playAutomatically) Play(); } private void OnDisable() {
Stop(); } public void Play() {
if (rm_transform == null) return; ResetEx(); if (delay > 0) Invoke("DoPlay", this.delay); else DoPlay(); } private void DoPlay() {
rm_transform.localScale = startValue; rm_transform.DOScale(endValue, duration).SetLoops(loops, loopType); } public void ResetEx() {
CancelInvoke(); rm_transform.localScale = startValue; rm_transform.DOKill(); } public void Stop() {
rm_transform.localScale = endValue; rm_transform.DOKill(); } private void OnDestroy() {
rm_transform.DOKill(); } }}
using DG.Tweening;using System.Collections;using System.Collections.Generic;using UnityEngine;using System;namespace XGUI{
public class XSimpleMove : MonoBehaviour {
public enum EaseType {
dotweenEase = 1, animCurve = 2, } [SerializeField] private AnimationCurve animCurve = new AnimationCurve(new Keyframe[] {
new Keyframe(0f, 0f), new Keyframe(3f, 40f) }); public EaseType m_easeType = EaseType.dotweenEase; public Ease m_ease = Ease.InOutBack; public RectTransform startPos; public RectTransform endPos; public float duration = 1.0f; public float delay = 0.0f; private RectTransform m_transform; public bool playAutomatically = false; void Awake() {
m_transform = gameObject.GetComponent
(); } private void OnEnable() {
if (playAutomatically) Play(null); } private void OnDisable() {
Stop(); } public void Play(TweenCallback onCompleFun) {
if (m_transform == null || startPos == null) return; ResetEx(); m_transform.anchoredPosition = startPos.anchoredPosition; if (delay > 0) StartCoroutine(DoWait(onCompleFun)); else DoPlay(onCompleFun); } private IEnumerator DoWait(TweenCallback onCompleFun) {
yield return new WaitForSeconds(delay); DoPlay(onCompleFun); } private void DoPlay(TweenCallback onCompleFun) {
Tweener tweener = m_transform.DOAnchorPos(endPos.anchoredPosition, duration); if (m_easeType == EaseType.animCurve) tweener.SetEase(animCurve); else tweener.SetEase(m_ease); if (onCompleFun != null) {
tweener.OnComplete(delegate () {
onCompleFun(); }); } } public void ResetEx() {
if (startPos == null) return; m_transform.anchoredPosition = startPos.anchoredPosition; m_transform.DOKill(); } public void Stop() {
if(m_transform != null && endPos != null) {
m_transform.anchoredPosition = endPos.anchoredPosition; m_transform.DOKill(); } } private void OnDestroy() {
m_transform.DOKill(); } }}

转载地址:http://kbrxo.baihongyu.com/

你可能感兴趣的文章
SSH::Batch,在公有云中使用 ssh 工具箱
查看>>
“外围”消亡 企业安全防护需要新形态
查看>>
红杉计越:AI、大数据、SaaS、云计算为何在中国一体迸发?
查看>>
阿里张勇:数据驱动的透明是平台治理的基础
查看>>
ActiveMQ - JMS,Transport,Persistence
查看>>
互联网大数据支撑生态银行建设
查看>>
视频会议系统迎来第四次浪潮
查看>>
报告显示:被调研中国企业超85%已从数字转型中获得回报
查看>>
东方日升拉美光伏电站项目 将进入首期施工
查看>>
软件探索性测试 笔记二
查看>>
将来也不会被破译的分布式存储系统
查看>>
光伏电站或成辅助服务市场“输家”
查看>>
今年光伏“领跑者”计划将升级扩围
查看>>
Java程序运行超时后退出或进行其他操作的实现
查看>>
手把手教你启用RemoteFX以及Hyper-V GPU卸载
查看>>
《交互式程序设计 第2版》一3.10 更进一步
查看>>
英伟达发布Tesla P4&P40两款基于Pascal架构的深度学习芯片
查看>>
《ANSYS Workbench有限元分析实例详解(静力学)》——2.5 Windows界面相应操作
查看>>
《代码整洁之道:程序员的职业素养》一一1.3 首先,不行损害之事
查看>>
intellij 创建java web项目(maven管理的SSH)
查看>>