mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 10:46:17 +00:00
提交FairyGUI
This commit is contained in:
@@ -0,0 +1,248 @@
|
||||
// Author: Daniele Giardini - http://www.demigiant.com
|
||||
// Created: 2014/07/19 14:11
|
||||
//
|
||||
// License Copyright (c) Daniele Giardini.
|
||||
// This work is subject to the terms at http://dotween.demigiant.com/license.php
|
||||
//
|
||||
// =============================================================
|
||||
// Contains Daniele Giardini's C# port of the easing equations created by Robert Penner
|
||||
// (all easing equations except for Flash, InFlash, OutFlash, InOutFlash,
|
||||
// which use some parts of Robert Penner's equations but were created by Daniele Giardini)
|
||||
// http://robertpenner.com/easing, see license below:
|
||||
// =============================================================
|
||||
//
|
||||
// TERMS OF USE - EASING EQUATIONS
|
||||
//
|
||||
// Open source under the BSD License.
|
||||
//
|
||||
// Copyright ? 2001 Robert Penner
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
// - Neither the name of the author nor the names of contributors may be used to endorse
|
||||
// or promote products derived from this software without specific prior written permission.
|
||||
// - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
#pragma warning disable 1591
|
||||
namespace FairyGUI
|
||||
{
|
||||
public static class EaseManager
|
||||
{
|
||||
const float _PiOver2 = Mathf.PI * 0.5f;
|
||||
const float _TwoPi = Mathf.PI * 2;
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value between 0 and 1 (inclusive) based on the elapsed time and ease selected
|
||||
/// </summary>
|
||||
public static float Evaluate(EaseType easeType, float time, float duration,
|
||||
float overshootOrAmplitude = 1.70158f,
|
||||
float period = 0,
|
||||
CustomEase customEase = null)
|
||||
{
|
||||
if (duration <= 0)
|
||||
return 1;
|
||||
|
||||
switch (easeType)
|
||||
{
|
||||
case EaseType.Linear:
|
||||
return time / duration;
|
||||
case EaseType.SineIn:
|
||||
return -(float)Math.Cos(time / duration * _PiOver2) + 1;
|
||||
case EaseType.SineOut:
|
||||
return (float)Math.Sin(time / duration * _PiOver2);
|
||||
case EaseType.SineInOut:
|
||||
return -0.5f * ((float)Math.Cos(Mathf.PI * time / duration) - 1);
|
||||
case EaseType.QuadIn:
|
||||
return (time /= duration) * time;
|
||||
case EaseType.QuadOut:
|
||||
return -(time /= duration) * (time - 2);
|
||||
case EaseType.QuadInOut:
|
||||
if ((time /= duration * 0.5f) < 1) return 0.5f * time * time;
|
||||
return -0.5f * ((--time) * (time - 2) - 1);
|
||||
case EaseType.CubicIn:
|
||||
return (time /= duration) * time * time;
|
||||
case EaseType.CubicOut:
|
||||
return ((time = time / duration - 1) * time * time + 1);
|
||||
case EaseType.CubicInOut:
|
||||
if ((time /= duration * 0.5f) < 1) return 0.5f * time * time * time;
|
||||
return 0.5f * ((time -= 2) * time * time + 2);
|
||||
case EaseType.QuartIn:
|
||||
return (time /= duration) * time * time * time;
|
||||
case EaseType.QuartOut:
|
||||
return -((time = time / duration - 1) * time * time * time - 1);
|
||||
case EaseType.QuartInOut:
|
||||
if ((time /= duration * 0.5f) < 1) return 0.5f * time * time * time * time;
|
||||
return -0.5f * ((time -= 2) * time * time * time - 2);
|
||||
case EaseType.QuintIn:
|
||||
return (time /= duration) * time * time * time * time;
|
||||
case EaseType.QuintOut:
|
||||
return ((time = time / duration - 1) * time * time * time * time + 1);
|
||||
case EaseType.QuintInOut:
|
||||
if ((time /= duration * 0.5f) < 1) return 0.5f * time * time * time * time * time;
|
||||
return 0.5f * ((time -= 2) * time * time * time * time + 2);
|
||||
case EaseType.ExpoIn:
|
||||
return (time == 0) ? 0 : (float)Math.Pow(2, 10 * (time / duration - 1));
|
||||
case EaseType.ExpoOut:
|
||||
if (time == duration) return 1;
|
||||
return (-(float)Math.Pow(2, -10 * time / duration) + 1);
|
||||
case EaseType.ExpoInOut:
|
||||
if (time == 0) return 0;
|
||||
if (time == duration) return 1;
|
||||
if ((time /= duration * 0.5f) < 1) return 0.5f * (float)Math.Pow(2, 10 * (time - 1));
|
||||
return 0.5f * (-(float)Math.Pow(2, -10 * --time) + 2);
|
||||
case EaseType.CircIn:
|
||||
return -((float)Math.Sqrt(1 - (time /= duration) * time) - 1);
|
||||
case EaseType.CircOut:
|
||||
return (float)Math.Sqrt(1 - (time = time / duration - 1) * time);
|
||||
case EaseType.CircInOut:
|
||||
if ((time /= duration * 0.5f) < 1) return -0.5f * ((float)Math.Sqrt(1 - time * time) - 1);
|
||||
return 0.5f * ((float)Math.Sqrt(1 - (time -= 2) * time) + 1);
|
||||
case EaseType.ElasticIn:
|
||||
float s0;
|
||||
if (time == 0) return 0;
|
||||
if ((time /= duration) == 1) return 1;
|
||||
if (period == 0) period = duration * 0.3f;
|
||||
if (overshootOrAmplitude < 1)
|
||||
{
|
||||
overshootOrAmplitude = 1;
|
||||
s0 = period / 4;
|
||||
}
|
||||
else s0 = period / _TwoPi * (float)Math.Asin(1 / overshootOrAmplitude);
|
||||
return -(overshootOrAmplitude * (float)Math.Pow(2, 10 * (time -= 1)) * (float)Math.Sin((time * duration - s0) * _TwoPi / period));
|
||||
case EaseType.ElasticOut:
|
||||
float s1;
|
||||
if (time == 0) return 0;
|
||||
if ((time /= duration) == 1) return 1;
|
||||
if (period == 0) period = duration * 0.3f;
|
||||
if (overshootOrAmplitude < 1)
|
||||
{
|
||||
overshootOrAmplitude = 1;
|
||||
s1 = period / 4;
|
||||
}
|
||||
else s1 = period / _TwoPi * (float)Math.Asin(1 / overshootOrAmplitude);
|
||||
return (overshootOrAmplitude * (float)Math.Pow(2, -10 * time) * (float)Math.Sin((time * duration - s1) * _TwoPi / period) + 1);
|
||||
case EaseType.ElasticInOut:
|
||||
float s;
|
||||
if (time == 0) return 0;
|
||||
if ((time /= duration * 0.5f) == 2) return 1;
|
||||
if (period == 0) period = duration * (0.3f * 1.5f);
|
||||
if (overshootOrAmplitude < 1)
|
||||
{
|
||||
overshootOrAmplitude = 1;
|
||||
s = period / 4;
|
||||
}
|
||||
else s = period / _TwoPi * (float)Math.Asin(1 / overshootOrAmplitude);
|
||||
if (time < 1) return -0.5f * (overshootOrAmplitude * (float)Math.Pow(2, 10 * (time -= 1)) * (float)Math.Sin((time * duration - s) * _TwoPi / period));
|
||||
return overshootOrAmplitude * (float)Math.Pow(2, -10 * (time -= 1)) * (float)Math.Sin((time * duration - s) * _TwoPi / period) * 0.5f + 1;
|
||||
case EaseType.BackIn:
|
||||
return (time /= duration) * time * ((overshootOrAmplitude + 1) * time - overshootOrAmplitude);
|
||||
case EaseType.BackOut:
|
||||
return ((time = time / duration - 1) * time * ((overshootOrAmplitude + 1) * time + overshootOrAmplitude) + 1);
|
||||
case EaseType.BackInOut:
|
||||
if ((time /= duration * 0.5f) < 1) return 0.5f * (time * time * (((overshootOrAmplitude *= (1.525f)) + 1) * time - overshootOrAmplitude));
|
||||
return 0.5f * ((time -= 2) * time * (((overshootOrAmplitude *= (1.525f)) + 1) * time + overshootOrAmplitude) + 2);
|
||||
case EaseType.BounceIn:
|
||||
return Bounce.EaseIn(time, duration);
|
||||
case EaseType.BounceOut:
|
||||
return Bounce.EaseOut(time, duration);
|
||||
case EaseType.BounceInOut:
|
||||
return Bounce.EaseInOut(time, duration);
|
||||
|
||||
case EaseType.Custom:
|
||||
return customEase != null ? customEase.Evaluate(time / duration) : (time / duration);
|
||||
|
||||
default:
|
||||
return -(time /= duration) * (time - 2);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This class contains a C# port of the easing equations created by Robert Penner (http://robertpenner.com/easing).
|
||||
/// </summary>
|
||||
static class Bounce
|
||||
{
|
||||
/// <summary>
|
||||
/// Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in: accelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="time">
|
||||
/// Current time (in frames or seconds).
|
||||
/// </param>
|
||||
/// <param name="duration">
|
||||
/// Expected easing duration (in frames or seconds).
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The eased value.
|
||||
/// </returns>
|
||||
public static float EaseIn(float time, float duration)
|
||||
{
|
||||
return 1 - EaseOut(duration - time, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out: decelerating from zero velocity.
|
||||
/// </summary>
|
||||
/// <param name="time">
|
||||
/// Current time (in frames or seconds).
|
||||
/// </param>
|
||||
/// <param name="duration">
|
||||
/// Expected easing duration (in frames or seconds).
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The eased value.
|
||||
/// </returns>
|
||||
public static float EaseOut(float time, float duration)
|
||||
{
|
||||
if ((time /= duration) < (1 / 2.75f))
|
||||
{
|
||||
return (7.5625f * time * time);
|
||||
}
|
||||
if (time < (2 / 2.75f))
|
||||
{
|
||||
return (7.5625f * (time -= (1.5f / 2.75f)) * time + 0.75f);
|
||||
}
|
||||
if (time < (2.5f / 2.75f))
|
||||
{
|
||||
return (7.5625f * (time -= (2.25f / 2.75f)) * time + 0.9375f);
|
||||
}
|
||||
return (7.5625f * (time -= (2.625f / 2.75f)) * time + 0.984375f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in/out: acceleration until halfway, then deceleration.
|
||||
/// </summary>
|
||||
/// <param name="time">
|
||||
/// Current time (in frames or seconds).
|
||||
/// </param>
|
||||
/// <param name="duration">
|
||||
/// Expected easing duration (in frames or seconds).
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The eased value.
|
||||
/// </returns>
|
||||
public static float EaseInOut(float time, float duration)
|
||||
{
|
||||
if (time < duration * 0.5f)
|
||||
{
|
||||
return EaseIn(time * 2, duration) * 0.5f;
|
||||
}
|
||||
return EaseOut(time * 2 - duration, duration) * 0.5f + 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 080d1dce1c76e154c9c8f50151e6d69e
|
||||
timeCreated: 1531473796
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,141 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public enum EaseType
|
||||
{
|
||||
Linear,
|
||||
SineIn,
|
||||
SineOut,
|
||||
SineInOut,
|
||||
QuadIn,
|
||||
QuadOut,
|
||||
QuadInOut,
|
||||
CubicIn,
|
||||
CubicOut,
|
||||
CubicInOut,
|
||||
QuartIn,
|
||||
QuartOut,
|
||||
QuartInOut,
|
||||
QuintIn,
|
||||
QuintOut,
|
||||
QuintInOut,
|
||||
ExpoIn,
|
||||
ExpoOut,
|
||||
ExpoInOut,
|
||||
CircIn,
|
||||
CircOut,
|
||||
CircInOut,
|
||||
ElasticIn,
|
||||
ElasticOut,
|
||||
ElasticInOut,
|
||||
BackIn,
|
||||
BackOut,
|
||||
BackInOut,
|
||||
BounceIn,
|
||||
BounceOut,
|
||||
BounceInOut,
|
||||
Custom
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class CustomEase
|
||||
{
|
||||
Vector2[] _points;
|
||||
int _pointDensity;
|
||||
|
||||
static GPath helperPath = new GPath();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="pointDensity"></param>
|
||||
public CustomEase(int pointDensity = 200)
|
||||
{
|
||||
_points = new Vector2[pointDensity + 1];
|
||||
_pointDensity = pointDensity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="pathPoints"></param>
|
||||
public void Create(IEnumerable<GPathPoint> pathPoints)
|
||||
{
|
||||
helperPath.Create(pathPoints);
|
||||
for (int i = 0; i <= _pointDensity; i++)
|
||||
{
|
||||
Vector3 pt = helperPath.GetPointAt(i / (float)_pointDensity);
|
||||
_points[i] = pt;
|
||||
}
|
||||
_points[0] = Vector2.zero;
|
||||
_points[_pointDensity] = Vector2.one;
|
||||
|
||||
Array.Sort(_points, (Vector2 p1, Vector2 p2) =>
|
||||
{
|
||||
return p1.x.CompareTo(p2.x);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="time"></param>
|
||||
/// <returns></returns>
|
||||
public float Evaluate(float time)
|
||||
{
|
||||
if (time <= 0)
|
||||
return 0;
|
||||
else if (time >= 1)
|
||||
return 1;
|
||||
|
||||
int low = 0;
|
||||
int high = _pointDensity;
|
||||
int cur = 0;
|
||||
while (low != high)
|
||||
{
|
||||
cur = low + (int)((high - low) / 2f);
|
||||
float x = _points[cur].x;
|
||||
if (time == x)
|
||||
break;
|
||||
else if (time > x)
|
||||
{
|
||||
if (low == cur)
|
||||
{
|
||||
cur = high;
|
||||
break;
|
||||
}
|
||||
low = cur;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (high == cur)
|
||||
{
|
||||
cur = low;
|
||||
break;
|
||||
}
|
||||
high = cur;
|
||||
}
|
||||
}
|
||||
|
||||
Vector2 v0 = _points[cur];
|
||||
Vector2 v1;
|
||||
if (cur == _pointDensity)
|
||||
v1 = Vector2.one;
|
||||
else
|
||||
v1 = _points[cur + 1];
|
||||
float k = (v1.y - v0.y) / (v1.x - v0.x);
|
||||
if (float.IsNaN(k))
|
||||
k = 0;
|
||||
|
||||
return v0.y + (time - v0.x) * k;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3faa49ad96d1cb45acf0a5534094d09
|
||||
timeCreated: 1535374215
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
475
JNFrame2/Assets/Plugins/FairyGUI/Runtime/Scripts/Tween/GPath.cs
Normal file
475
JNFrame2/Assets/Plugins/FairyGUI/Runtime/Scripts/Tween/GPath.cs
Normal file
@@ -0,0 +1,475 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public struct GPathPoint
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Vector3 pos;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Vector3 control1;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Vector3 control2;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public CurveType curveType;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool smooth;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public enum CurveType
|
||||
{
|
||||
CRSpline,
|
||||
Bezier,
|
||||
CubicBezier,
|
||||
Straight
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
public GPathPoint(Vector3 pos)
|
||||
{
|
||||
this.pos = pos;
|
||||
this.control1 = Vector3.zero;
|
||||
this.control2 = Vector3.zero;
|
||||
this.curveType = CurveType.CRSpline;
|
||||
this.smooth = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
/// <param name="control"></param>
|
||||
public GPathPoint(Vector3 pos, Vector3 control)
|
||||
{
|
||||
this.pos = pos;
|
||||
this.control1 = control;
|
||||
this.control2 = Vector3.zero;
|
||||
this.curveType = CurveType.Bezier;
|
||||
this.smooth = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
/// <param name="control1"></param>
|
||||
/// <param name="control2"></param>
|
||||
public GPathPoint(Vector3 pos, Vector3 control1, Vector3 control2)
|
||||
{
|
||||
this.pos = pos;
|
||||
this.control1 = control1;
|
||||
this.control2 = control2;
|
||||
this.curveType = CurveType.CubicBezier;
|
||||
this.smooth = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
/// <param name="curveType"></param>
|
||||
public GPathPoint(Vector3 pos, CurveType curveType)
|
||||
{
|
||||
this.pos = pos;
|
||||
this.control1 = Vector3.zero;
|
||||
this.control2 = Vector3.zero;
|
||||
this.curveType = curveType;
|
||||
this.smooth = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class GPath
|
||||
{
|
||||
protected struct Segment
|
||||
{
|
||||
public GPathPoint.CurveType type;
|
||||
public float length;
|
||||
public int ptStart;
|
||||
public int ptCount;
|
||||
}
|
||||
|
||||
protected List<Segment> _segments;
|
||||
protected List<Vector3> _points;
|
||||
protected float _fullLength;
|
||||
|
||||
static List<GPathPoint> helperList = new List<GPathPoint>();
|
||||
static List<Vector3> splinePoints = new List<Vector3>();
|
||||
|
||||
public GPath()
|
||||
{
|
||||
_segments = new List<Segment>();
|
||||
_points = new List<Vector3>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public float length
|
||||
{
|
||||
get { return _fullLength; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="pt1"></param>
|
||||
/// <param name="pt2"></param>
|
||||
public void Create(GPathPoint pt1, GPathPoint pt2)
|
||||
{
|
||||
helperList.Clear();
|
||||
helperList.Add(pt1);
|
||||
helperList.Add(pt2);
|
||||
Create(helperList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="pt1"></param>
|
||||
/// <param name="pt2"></param>
|
||||
/// <param name="pt3"></param>
|
||||
public void Create(GPathPoint pt1, GPathPoint pt2, GPathPoint pt3)
|
||||
{
|
||||
helperList.Clear();
|
||||
helperList.Add(pt1);
|
||||
helperList.Add(pt2);
|
||||
helperList.Add(pt3);
|
||||
Create(helperList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="pt1"></param>
|
||||
/// <param name="pt2"></param>
|
||||
/// <param name="pt3"></param>
|
||||
/// <param name="pt4"></param>
|
||||
public void Create(GPathPoint pt1, GPathPoint pt2, GPathPoint pt3, GPathPoint pt4)
|
||||
{
|
||||
helperList.Clear();
|
||||
helperList.Add(pt1);
|
||||
helperList.Add(pt2);
|
||||
helperList.Add(pt3);
|
||||
helperList.Add(pt4);
|
||||
Create(helperList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="points"></param>
|
||||
public void Create(IEnumerable<GPathPoint> points)
|
||||
{
|
||||
_segments.Clear();
|
||||
_points.Clear();
|
||||
splinePoints.Clear();
|
||||
_fullLength = 0;
|
||||
|
||||
var et = points.GetEnumerator();
|
||||
if (!et.MoveNext())
|
||||
return;
|
||||
|
||||
GPathPoint prev = et.Current;
|
||||
if (prev.curveType == GPathPoint.CurveType.CRSpline)
|
||||
splinePoints.Add(prev.pos);
|
||||
|
||||
while (et.MoveNext())
|
||||
{
|
||||
GPathPoint current = et.Current;
|
||||
|
||||
if (prev.curveType != GPathPoint.CurveType.CRSpline)
|
||||
{
|
||||
Segment seg = new Segment();
|
||||
seg.type = prev.curveType;
|
||||
seg.ptStart = _points.Count;
|
||||
if (prev.curveType == GPathPoint.CurveType.Straight)
|
||||
{
|
||||
seg.ptCount = 2;
|
||||
_points.Add(prev.pos);
|
||||
_points.Add(current.pos);
|
||||
}
|
||||
else if (prev.curveType == GPathPoint.CurveType.Bezier)
|
||||
{
|
||||
seg.ptCount = 3;
|
||||
_points.Add(prev.pos);
|
||||
_points.Add(current.pos);
|
||||
_points.Add(prev.control1);
|
||||
}
|
||||
else if (prev.curveType == GPathPoint.CurveType.CubicBezier)
|
||||
{
|
||||
seg.ptCount = 4;
|
||||
_points.Add(prev.pos);
|
||||
_points.Add(current.pos);
|
||||
_points.Add(prev.control1);
|
||||
_points.Add(prev.control2);
|
||||
}
|
||||
seg.length = Vector3.Distance(prev.pos, current.pos);
|
||||
_fullLength += seg.length;
|
||||
_segments.Add(seg);
|
||||
}
|
||||
|
||||
if (current.curveType != GPathPoint.CurveType.CRSpline)
|
||||
{
|
||||
if (splinePoints.Count > 0)
|
||||
{
|
||||
splinePoints.Add(current.pos);
|
||||
CreateSplineSegment();
|
||||
}
|
||||
}
|
||||
else
|
||||
splinePoints.Add(current.pos);
|
||||
|
||||
prev = current;
|
||||
}
|
||||
|
||||
if (splinePoints.Count > 1)
|
||||
CreateSplineSegment();
|
||||
}
|
||||
|
||||
void CreateSplineSegment()
|
||||
{
|
||||
int cnt = splinePoints.Count;
|
||||
splinePoints.Insert(0, splinePoints[0]);
|
||||
splinePoints.Add(splinePoints[cnt]);
|
||||
splinePoints.Add(splinePoints[cnt]);
|
||||
cnt += 3;
|
||||
|
||||
Segment seg = new Segment();
|
||||
seg.type = GPathPoint.CurveType.CRSpline;
|
||||
seg.ptStart = _points.Count;
|
||||
seg.ptCount = cnt;
|
||||
_points.AddRange(splinePoints);
|
||||
|
||||
seg.length = 0;
|
||||
for (int i = 1; i < cnt; i++)
|
||||
seg.length += Vector3.Distance(splinePoints[i - 1], splinePoints[i]);
|
||||
_fullLength += seg.length;
|
||||
_segments.Add(seg);
|
||||
splinePoints.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
_segments.Clear();
|
||||
_points.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
/// <returns></returns>
|
||||
public Vector3 GetPointAt(float t)
|
||||
{
|
||||
t = Mathf.Clamp01(t);
|
||||
int cnt = _segments.Count;
|
||||
if (cnt == 0)
|
||||
return Vector3.zero;
|
||||
|
||||
Segment seg;
|
||||
if (t == 1)
|
||||
{
|
||||
seg = _segments[cnt - 1];
|
||||
|
||||
if (seg.type == GPathPoint.CurveType.Straight)
|
||||
return Vector3.Lerp(_points[seg.ptStart], _points[seg.ptStart + 1], t);
|
||||
else if (seg.type == GPathPoint.CurveType.Bezier || seg.type == GPathPoint.CurveType.CubicBezier)
|
||||
return onBezierCurve(seg.ptStart, seg.ptCount, t);
|
||||
else
|
||||
return onCRSplineCurve(seg.ptStart, seg.ptCount, t);
|
||||
}
|
||||
|
||||
float len = t * _fullLength;
|
||||
Vector3 pt = new Vector3();
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
seg = _segments[i];
|
||||
|
||||
len -= seg.length;
|
||||
if (len < 0)
|
||||
{
|
||||
t = 1 + len / seg.length;
|
||||
|
||||
if (seg.type == GPathPoint.CurveType.Straight)
|
||||
pt = Vector3.Lerp(_points[seg.ptStart], _points[seg.ptStart + 1], t);
|
||||
else if (seg.type == GPathPoint.CurveType.Bezier || seg.type == GPathPoint.CurveType.CubicBezier)
|
||||
pt = onBezierCurve(seg.ptStart, seg.ptCount, t);
|
||||
else
|
||||
pt = onCRSplineCurve(seg.ptStart, seg.ptCount, t);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return pt;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int segmentCount
|
||||
{
|
||||
get { return _segments.Count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="segmentIndex"></param>
|
||||
/// <returns></returns>
|
||||
public float GetSegmentLength(int segmentIndex)
|
||||
{
|
||||
return _segments[segmentIndex].length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="segmentIndex"></param>
|
||||
/// <param name="t0"></param>
|
||||
/// <param name="t1"></param>
|
||||
/// <param name="points"></param>
|
||||
/// <param name="ts"></param>
|
||||
public void GetPointsInSegment(int segmentIndex, float t0, float t1, List<Vector3> points, List<float> ts = null, float pointDensity = 0.1f)
|
||||
{
|
||||
if (points == null)
|
||||
points = new List<Vector3>();
|
||||
|
||||
if (ts != null)
|
||||
ts.Add(t0);
|
||||
Segment seg = _segments[segmentIndex];
|
||||
if (seg.type == GPathPoint.CurveType.Straight)
|
||||
{
|
||||
points.Add(Vector3.Lerp(_points[seg.ptStart], _points[seg.ptStart + 1], t0));
|
||||
points.Add(Vector3.Lerp(_points[seg.ptStart], _points[seg.ptStart + 1], t1));
|
||||
}
|
||||
else if (seg.type == GPathPoint.CurveType.Bezier || seg.type == GPathPoint.CurveType.CubicBezier)
|
||||
{
|
||||
points.Add(onBezierCurve(seg.ptStart, seg.ptCount, t0));
|
||||
int SmoothAmount = (int)Mathf.Min(seg.length * pointDensity, 50);
|
||||
for (int j = 0; j <= SmoothAmount; j++)
|
||||
{
|
||||
float t = (float)j / SmoothAmount;
|
||||
if (t > t0 && t < t1)
|
||||
{
|
||||
points.Add(onBezierCurve(seg.ptStart, seg.ptCount, t));
|
||||
if (ts != null)
|
||||
ts.Add(t);
|
||||
}
|
||||
}
|
||||
points.Add(onBezierCurve(seg.ptStart, seg.ptCount, t1));
|
||||
}
|
||||
else
|
||||
{
|
||||
points.Add(onCRSplineCurve(seg.ptStart, seg.ptCount, t0));
|
||||
int SmoothAmount = (int)Mathf.Min(seg.length * pointDensity, 50);
|
||||
for (int j = 0; j <= SmoothAmount; j++)
|
||||
{
|
||||
float t = (float)j / SmoothAmount;
|
||||
if (t > t0 && t < t1)
|
||||
{
|
||||
points.Add(onCRSplineCurve(seg.ptStart, seg.ptCount, t));
|
||||
if (ts != null)
|
||||
ts.Add(t);
|
||||
}
|
||||
}
|
||||
points.Add(onCRSplineCurve(seg.ptStart, seg.ptCount, t1));
|
||||
}
|
||||
|
||||
if (ts != null)
|
||||
ts.Add(t1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="points"></param>
|
||||
public void GetAllPoints(List<Vector3> points, float pointDensity = 0.1f)
|
||||
{
|
||||
int cnt = _segments.Count;
|
||||
for (int i = 0; i < cnt; i++)
|
||||
GetPointsInSegment(i, 0, 1, points, null, pointDensity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Catmull rom spline implementation
|
||||
/// by Stéphane Drouot, laei - http://games.laei.org
|
||||
///
|
||||
/// Actual translation of math gebrish to C# credit is due to
|
||||
/// Boon Cotter - http://www.booncotter.com/waypoints-catmull-rom-splines/
|
||||
///
|
||||
/// This takes a list of vector3 (or an array) and gives a function called .onCurve(t)
|
||||
/// returning a value on a Catmull-Rom spline for 0 <= t <= 1
|
||||
/// </summary>
|
||||
Vector3 onCRSplineCurve(int ptStart, int ptCount, float t)
|
||||
{
|
||||
int adjustedIndex = Mathf.FloorToInt(t * (ptCount - 4)) + ptStart; //Since the equation works with 4 points, we adjust the starting point depending on t to return a point on the specific segment
|
||||
|
||||
Vector3 result = new Vector3();
|
||||
|
||||
Vector3 p0 = _points[adjustedIndex];
|
||||
Vector3 p1 = _points[adjustedIndex + 1];
|
||||
Vector3 p2 = _points[adjustedIndex + 2];
|
||||
Vector3 p3 = _points[adjustedIndex + 3];
|
||||
|
||||
float adjustedT = (t == 1f) ? 1f : Mathf.Repeat(t * (ptCount - 4), 1f); // Then we adjust t to be that value on that new piece of segment... for t == 1f don't use repeat (that would return 0f);
|
||||
|
||||
float t0 = ((-adjustedT + 2f) * adjustedT - 1f) * adjustedT * 0.5f;
|
||||
float t1 = (((3f * adjustedT - 5f) * adjustedT) * adjustedT + 2f) * 0.5f;
|
||||
float t2 = ((-3f * adjustedT + 4f) * adjustedT + 1f) * adjustedT * 0.5f;
|
||||
float t3 = ((adjustedT - 1f) * adjustedT * adjustedT) * 0.5f;
|
||||
|
||||
result.x = p0.x * t0 + p1.x * t1 + p2.x * t2 + p3.x * t3;
|
||||
result.y = p0.y * t0 + p1.y * t1 + p2.y * t2 + p3.y * t3;
|
||||
result.z = p0.z * t0 + p1.z * t1 + p2.z * t2 + p3.z * t3;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Vector3 onBezierCurve(int ptStart, int ptCount, float t)
|
||||
{
|
||||
float t2 = 1f - t;
|
||||
Vector3 p0 = _points[ptStart];
|
||||
Vector3 p1 = _points[ptStart + 1];
|
||||
Vector3 cp0 = _points[ptStart + 2];
|
||||
|
||||
if (ptCount == 4)
|
||||
{
|
||||
Vector3 cp1 = _points[ptStart + 3];
|
||||
return t2 * t2 * t2 * p0 + 3f * t2 * t2 * t * cp0 + 3f * t2 * t * t * cp1 + t * t * t * p1;
|
||||
}
|
||||
else
|
||||
return t2 * t2 * p0 + 2f * t2 * t * cp0 + t * t * p1;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3755f976b6dd17c408731fa87b3cb006
|
||||
timeCreated: 1546592349
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
189
JNFrame2/Assets/Plugins/FairyGUI/Runtime/Scripts/Tween/GTween.cs
Normal file
189
JNFrame2/Assets/Plugins/FairyGUI/Runtime/Scripts/Tween/GTween.cs
Normal file
@@ -0,0 +1,189 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class GTween
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static bool catchCallbackExceptions = false;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="startValue"></param>
|
||||
/// <param name="endValue"></param>
|
||||
/// <param name="duration"></param>
|
||||
/// <returns></returns>
|
||||
public static GTweener To(float startValue, float endValue, float duration)
|
||||
{
|
||||
return TweenManager.CreateTween()._To(startValue, endValue, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="startValue"></param>
|
||||
/// <param name="endValue"></param>
|
||||
/// <param name="duration"></param>
|
||||
/// <returns></returns>
|
||||
public static GTweener To(Vector2 startValue, Vector2 endValue, float duration)
|
||||
{
|
||||
return TweenManager.CreateTween()._To(startValue, endValue, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="startValue"></param>
|
||||
/// <param name="endValue"></param>
|
||||
/// <param name="duration"></param>
|
||||
/// <returns></returns>
|
||||
public static GTweener To(Vector3 startValue, Vector3 endValue, float duration)
|
||||
{
|
||||
return TweenManager.CreateTween()._To(startValue, endValue, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="startValue"></param>
|
||||
/// <param name="endValue"></param>
|
||||
/// <param name="duration"></param>
|
||||
/// <returns></returns>
|
||||
public static GTweener To(Vector4 startValue, Vector4 endValue, float duration)
|
||||
{
|
||||
return TweenManager.CreateTween()._To(startValue, endValue, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="startValue"></param>
|
||||
/// <param name="endValue"></param>
|
||||
/// <param name="duration"></param>
|
||||
/// <returns></returns>
|
||||
public static GTweener To(Color startValue, Color endValue, float duration)
|
||||
{
|
||||
return TweenManager.CreateTween()._To(startValue, endValue, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="startValue"></param>
|
||||
/// <param name="endValue"></param>
|
||||
/// <param name="duration"></param>
|
||||
/// <returns></returns>
|
||||
public static GTweener ToDouble(double startValue, double endValue, float duration)
|
||||
{
|
||||
return TweenManager.CreateTween()._To(startValue, endValue, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="delay"></param>
|
||||
/// <returns></returns>
|
||||
public static GTweener DelayedCall(float delay)
|
||||
{
|
||||
return TweenManager.CreateTween().SetDelay(delay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="startValue"></param>
|
||||
/// <param name="amplitude"></param>
|
||||
/// <param name="duration"></param>
|
||||
/// <returns></returns>
|
||||
public static GTweener Shake(Vector3 startValue, float amplitude, float duration)
|
||||
{
|
||||
return TweenManager.CreateTween()._Shake(startValue, amplitude, duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="target"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsTweening(object target)
|
||||
{
|
||||
return TweenManager.IsTweening(target, TweenPropType.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="target"></param>
|
||||
/// <param name="propType"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsTweening(object target, TweenPropType propType)
|
||||
{
|
||||
return TweenManager.IsTweening(target, propType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="target"></param>
|
||||
public static void Kill(object target)
|
||||
{
|
||||
TweenManager.KillTweens(target, TweenPropType.None, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="target"></param>
|
||||
/// <param name="complete"></param>
|
||||
public static void Kill(object target, bool complete)
|
||||
{
|
||||
TweenManager.KillTweens(target, TweenPropType.None, complete);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="target"></param>
|
||||
/// <param name="propType"></param>
|
||||
/// <param name="complete"></param>
|
||||
public static void Kill(object target, TweenPropType propType, bool complete)
|
||||
{
|
||||
TweenManager.KillTweens(target, propType, complete);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="target"></param>
|
||||
/// <returns></returns>
|
||||
public static GTweener GetTween(object target)
|
||||
{
|
||||
return TweenManager.GetTween(target, TweenPropType.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="target"></param>
|
||||
/// <param name="propType"></param>
|
||||
/// <returns></returns>
|
||||
public static GTweener GetTween(object target, TweenPropType propType)
|
||||
{
|
||||
return TweenManager.GetTween(target, propType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static void Clean()
|
||||
{
|
||||
TweenManager.Clean();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 613566965c56f6e4e9a95936b8128f90
|
||||
timeCreated: 1531222519
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,859 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
#if FAIRYGUI_TOLUA
|
||||
using LuaInterface;
|
||||
#endif
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public delegate void GTweenCallback();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="tweener"></param>
|
||||
public delegate void GTweenCallback1(GTweener tweener);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public interface ITweenListener
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="tweener"></param>
|
||||
void OnTweenStart(GTweener tweener);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="tweener"></param>
|
||||
void OnTweenUpdate(GTweener tweener);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="tweener"></param>
|
||||
void OnTweenComplete(GTweener tweener);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class GTweener
|
||||
{
|
||||
internal object _target;
|
||||
internal TweenPropType _propType;
|
||||
internal bool _killed;
|
||||
internal bool _paused;
|
||||
|
||||
float _delay;
|
||||
float _duration;
|
||||
float _breakpoint;
|
||||
EaseType _easeType;
|
||||
float _easeOvershootOrAmplitude;
|
||||
float _easePeriod;
|
||||
int _repeat;
|
||||
bool _yoyo;
|
||||
float _timeScale;
|
||||
bool _ignoreEngineTimeScale;
|
||||
bool _snapping;
|
||||
object _userData;
|
||||
GPath _path;
|
||||
CustomEase _customEase;
|
||||
|
||||
GTweenCallback _onUpdate;
|
||||
GTweenCallback _onStart;
|
||||
GTweenCallback _onComplete;
|
||||
GTweenCallback1 _onUpdate1;
|
||||
GTweenCallback1 _onStart1;
|
||||
GTweenCallback1 _onComplete1;
|
||||
ITweenListener _listener;
|
||||
|
||||
TweenValue _startValue;
|
||||
TweenValue _endValue;
|
||||
TweenValue _value;
|
||||
TweenValue _deltaValue;
|
||||
int _valueSize;
|
||||
|
||||
bool _started;
|
||||
int _ended;
|
||||
float _elapsedTime;
|
||||
float _normalizedTime;
|
||||
int _smoothStart;
|
||||
|
||||
public GTweener()
|
||||
{
|
||||
_startValue = new TweenValue();
|
||||
_endValue = new TweenValue();
|
||||
_value = new TweenValue();
|
||||
_deltaValue = new TweenValue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public GTweener SetDelay(float value)
|
||||
{
|
||||
_delay = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public float delay
|
||||
{
|
||||
get { return _delay; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public GTweener SetDuration(float value)
|
||||
{
|
||||
_duration = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public float duration
|
||||
{
|
||||
get { return _duration; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public GTweener SetBreakpoint(float value)
|
||||
{
|
||||
_breakpoint = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public GTweener SetEase(EaseType value)
|
||||
{
|
||||
_easeType = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="customEase"></param>
|
||||
/// <returns></returns>
|
||||
public GTweener SetEase(EaseType value, CustomEase customEase)
|
||||
{
|
||||
_easeType = value;
|
||||
_customEase = customEase;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public GTweener SetEasePeriod(float value)
|
||||
{
|
||||
_easePeriod = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public GTweener SetEaseOvershootOrAmplitude(float value)
|
||||
{
|
||||
_easeOvershootOrAmplitude = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="times"></param>
|
||||
/// <param name="yoyo"></param>
|
||||
/// <returns></returns>
|
||||
public GTweener SetRepeat(int times, bool yoyo = false)
|
||||
{
|
||||
_repeat = times;
|
||||
_yoyo = yoyo;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int repeat
|
||||
{
|
||||
get { return _repeat; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public GTweener SetTimeScale(float value)
|
||||
{
|
||||
_timeScale = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public GTweener SetIgnoreEngineTimeScale(bool value)
|
||||
{
|
||||
_ignoreEngineTimeScale = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public GTweener SetSnapping(bool value)
|
||||
{
|
||||
_snapping = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public GTweener SetPath(GPath value)
|
||||
{
|
||||
_path = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public GTweener SetTarget(object value)
|
||||
{
|
||||
_target = value;
|
||||
_propType = TweenPropType.None;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="propType"></param>
|
||||
/// <returns></returns>
|
||||
public GTweener SetTarget(object value, TweenPropType propType)
|
||||
{
|
||||
_target = value;
|
||||
_propType = propType;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public object target
|
||||
{
|
||||
get { return _target; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public GTweener SetUserData(object value)
|
||||
{
|
||||
_userData = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public object userData
|
||||
{
|
||||
get { return _userData; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="callback"></param>
|
||||
/// <returns></returns>
|
||||
#if FAIRYGUI_TOLUA
|
||||
[NoToLua]
|
||||
#endif
|
||||
public GTweener OnUpdate(GTweenCallback callback)
|
||||
{
|
||||
_onUpdate = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="callback"></param>
|
||||
/// <returns></returns>
|
||||
#if FAIRYGUI_TOLUA
|
||||
[NoToLua]
|
||||
#endif
|
||||
public GTweener OnStart(GTweenCallback callback)
|
||||
{
|
||||
_onStart = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="callback"></param>
|
||||
/// <returns></returns>
|
||||
#if FAIRYGUI_TOLUA
|
||||
[NoToLua]
|
||||
#endif
|
||||
public GTweener OnComplete(GTweenCallback callback)
|
||||
{
|
||||
_onComplete = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="callback"></param>
|
||||
/// <returns></returns>
|
||||
public GTweener OnUpdate(GTweenCallback1 callback)
|
||||
{
|
||||
_onUpdate1 = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="callback"></param>
|
||||
/// <returns></returns>
|
||||
public GTweener OnStart(GTweenCallback1 callback)
|
||||
{
|
||||
_onStart1 = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="callback"></param>
|
||||
/// <returns></returns>
|
||||
public GTweener OnComplete(GTweenCallback1 callback)
|
||||
{
|
||||
_onComplete1 = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public GTweener SetListener(ITweenListener value)
|
||||
{
|
||||
_listener = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public TweenValue startValue
|
||||
{
|
||||
get { return _startValue; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public TweenValue endValue
|
||||
{
|
||||
get { return _endValue; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public TweenValue value
|
||||
{
|
||||
get { return _value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public TweenValue deltaValue
|
||||
{
|
||||
get { return _deltaValue; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public float normalizedTime
|
||||
{
|
||||
get { return _normalizedTime; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool completed
|
||||
{
|
||||
get { return _ended != 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool allCompleted
|
||||
{
|
||||
get { return _ended == 1; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="paused"></param>
|
||||
/// <returns></returns>
|
||||
public GTweener SetPaused(bool paused)
|
||||
{
|
||||
_paused = paused;
|
||||
if (_paused)
|
||||
_smoothStart = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="time"></param>
|
||||
public void Seek(float time)
|
||||
{
|
||||
if (_killed)
|
||||
return;
|
||||
|
||||
_elapsedTime = time;
|
||||
if (_elapsedTime < _delay)
|
||||
{
|
||||
if (_started)
|
||||
_elapsedTime = _delay;
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="complete"></param>
|
||||
public void Kill(bool complete = false)
|
||||
{
|
||||
if (_killed)
|
||||
return;
|
||||
|
||||
if (complete)
|
||||
{
|
||||
if (_ended == 0)
|
||||
{
|
||||
if (_breakpoint >= 0)
|
||||
_elapsedTime = _delay + _breakpoint;
|
||||
else if (_repeat >= 0)
|
||||
_elapsedTime = _delay + _duration * (_repeat + 1);
|
||||
else
|
||||
_elapsedTime = _delay + _duration * 2;
|
||||
Update();
|
||||
}
|
||||
|
||||
CallCompleteCallback();
|
||||
}
|
||||
|
||||
_killed = true;
|
||||
}
|
||||
|
||||
internal GTweener _To(float start, float end, float duration)
|
||||
{
|
||||
_valueSize = 1;
|
||||
_startValue.x = start;
|
||||
_endValue.x = end;
|
||||
_value.x = start;
|
||||
_duration = duration;
|
||||
return this;
|
||||
}
|
||||
|
||||
internal GTweener _To(Vector2 start, Vector2 end, float duration)
|
||||
{
|
||||
_valueSize = 2;
|
||||
_startValue.vec2 = start;
|
||||
_endValue.vec2 = end;
|
||||
_value.vec2 = start;
|
||||
_duration = duration;
|
||||
return this;
|
||||
}
|
||||
|
||||
internal GTweener _To(Vector3 start, Vector3 end, float duration)
|
||||
{
|
||||
_valueSize = 3;
|
||||
_startValue.vec3 = start;
|
||||
_endValue.vec3 = end;
|
||||
_value.vec3 = start;
|
||||
_duration = duration;
|
||||
return this;
|
||||
}
|
||||
|
||||
internal GTweener _To(Vector4 start, Vector4 end, float duration)
|
||||
{
|
||||
_valueSize = 4;
|
||||
_startValue.vec4 = start;
|
||||
_endValue.vec4 = end;
|
||||
_value.vec4 = start;
|
||||
_duration = duration;
|
||||
return this;
|
||||
}
|
||||
|
||||
internal GTweener _To(Color start, Color end, float duration)
|
||||
{
|
||||
_valueSize = 4;
|
||||
_startValue.color = start;
|
||||
_endValue.color = end;
|
||||
_value.color = start;
|
||||
_duration = duration;
|
||||
return this;
|
||||
}
|
||||
|
||||
internal GTweener _To(double start, double end, float duration)
|
||||
{
|
||||
_valueSize = 5;
|
||||
_startValue.d = start;
|
||||
_endValue.d = end;
|
||||
_value.d = start;
|
||||
_duration = duration;
|
||||
return this;
|
||||
}
|
||||
|
||||
internal GTweener _Shake(Vector3 start, float amplitude, float duration)
|
||||
{
|
||||
_valueSize = 6;
|
||||
_startValue.vec3 = start;
|
||||
_startValue.w = amplitude;
|
||||
_duration = duration;
|
||||
_easeType = EaseType.Linear;
|
||||
return this;
|
||||
}
|
||||
|
||||
internal void _Init()
|
||||
{
|
||||
_delay = 0;
|
||||
_duration = 0;
|
||||
_breakpoint = -1;
|
||||
_easeType = EaseType.QuadOut;
|
||||
_timeScale = 1;
|
||||
_ignoreEngineTimeScale = false;
|
||||
_easePeriod = 0;
|
||||
_easeOvershootOrAmplitude = 1.70158f;
|
||||
_snapping = false;
|
||||
_repeat = 0;
|
||||
_yoyo = false;
|
||||
_valueSize = 0;
|
||||
_started = false;
|
||||
_paused = false;
|
||||
_killed = false;
|
||||
_elapsedTime = 0;
|
||||
_normalizedTime = 0;
|
||||
_ended = 0;
|
||||
_path = null;
|
||||
_customEase = null;
|
||||
_smoothStart = Time.frameCount == 1 ? 3 : 1;//刚启动时会有多帧的超时
|
||||
}
|
||||
|
||||
internal void _Reset()
|
||||
{
|
||||
_target = null;
|
||||
_listener = null;
|
||||
_userData = null;
|
||||
_onStart = _onUpdate = _onComplete = null;
|
||||
_onStart1 = _onUpdate1 = _onComplete1 = null;
|
||||
}
|
||||
|
||||
internal void _Update()
|
||||
{
|
||||
if (_ended != 0) //Maybe completed by seek
|
||||
{
|
||||
CallCompleteCallback();
|
||||
_killed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
float dt;
|
||||
if (_smoothStart > 0)
|
||||
{
|
||||
_smoothStart--;
|
||||
dt = Mathf.Clamp(Time.unscaledDeltaTime, 0, Application.targetFrameRate > 0 ? (1.0f / Application.targetFrameRate) : 0.016f);
|
||||
if (!_ignoreEngineTimeScale)
|
||||
dt *= Time.timeScale;
|
||||
}
|
||||
else if (_ignoreEngineTimeScale)
|
||||
dt = Time.unscaledDeltaTime;
|
||||
else
|
||||
dt = Time.deltaTime;
|
||||
if (_timeScale != 1)
|
||||
dt *= _timeScale;
|
||||
if (dt == 0)
|
||||
return;
|
||||
|
||||
_elapsedTime += dt;
|
||||
Update();
|
||||
|
||||
if (_ended != 0)
|
||||
{
|
||||
if (!_killed)
|
||||
{
|
||||
CallCompleteCallback();
|
||||
_killed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
_ended = 0;
|
||||
|
||||
if (_valueSize == 0) //DelayedCall
|
||||
{
|
||||
if (_elapsedTime >= _delay + _duration)
|
||||
_ended = 1;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_started)
|
||||
{
|
||||
if (_elapsedTime < _delay)
|
||||
return;
|
||||
|
||||
_started = true;
|
||||
CallStartCallback();
|
||||
if (_killed)
|
||||
return;
|
||||
}
|
||||
|
||||
bool reversed = false;
|
||||
float tt = _elapsedTime - _delay;
|
||||
if (_breakpoint >= 0 && tt >= _breakpoint)
|
||||
{
|
||||
tt = _breakpoint;
|
||||
_ended = 2;
|
||||
}
|
||||
|
||||
if (_repeat != 0)
|
||||
{
|
||||
int round = Mathf.FloorToInt(tt / _duration);
|
||||
tt -= _duration * round;
|
||||
if (_yoyo)
|
||||
reversed = round % 2 == 1;
|
||||
|
||||
if (_repeat > 0 && _repeat - round < 0)
|
||||
{
|
||||
if (_yoyo)
|
||||
reversed = _repeat % 2 == 1;
|
||||
tt = _duration;
|
||||
_ended = 1;
|
||||
}
|
||||
}
|
||||
else if (tt >= _duration)
|
||||
{
|
||||
tt = _duration;
|
||||
_ended = 1;
|
||||
}
|
||||
|
||||
_normalizedTime = EaseManager.Evaluate(_easeType, reversed ? (_duration - tt) : tt, _duration,
|
||||
_easeOvershootOrAmplitude, _easePeriod, _customEase);
|
||||
|
||||
_value.SetZero();
|
||||
_deltaValue.SetZero();
|
||||
|
||||
if (_valueSize == 5)
|
||||
{
|
||||
double d = _startValue.d + (_endValue.d - _startValue.d) * _normalizedTime;
|
||||
if (_snapping)
|
||||
d = Math.Round(d);
|
||||
_deltaValue.d = d - _value.d;
|
||||
_value.d = d;
|
||||
_value.x = (float)d;
|
||||
}
|
||||
else if (_valueSize == 6)
|
||||
{
|
||||
if (_ended == 0)
|
||||
{
|
||||
Vector3 r = UnityEngine.Random.insideUnitSphere;
|
||||
r.x = r.x > 0 ? 1 : -1;
|
||||
r.y = r.y > 0 ? 1 : -1;
|
||||
r.z = r.z > 0 ? 1 : -1;
|
||||
r *= _startValue.w * (1 - _normalizedTime);
|
||||
|
||||
_deltaValue.vec3 = r;
|
||||
_value.vec3 = _startValue.vec3 + r;
|
||||
}
|
||||
else
|
||||
_value.vec3 = _startValue.vec3;
|
||||
}
|
||||
else if (_path != null)
|
||||
{
|
||||
Vector3 vec3 = _path.GetPointAt(_normalizedTime);
|
||||
if (_snapping)
|
||||
{
|
||||
vec3.x = Mathf.Round(vec3.x);
|
||||
vec3.y = Mathf.Round(vec3.y);
|
||||
vec3.z = Mathf.Round(vec3.z);
|
||||
}
|
||||
_deltaValue.vec3 = vec3 - _value.vec3;
|
||||
_value.vec3 = vec3;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < _valueSize; i++)
|
||||
{
|
||||
float n1 = _startValue[i];
|
||||
float n2 = _endValue[i];
|
||||
float f = n1 + (n2 - n1) * _normalizedTime;
|
||||
if (_snapping)
|
||||
f = Mathf.Round(f);
|
||||
_deltaValue[i] = f - _value[i];
|
||||
_value[i] = f;
|
||||
}
|
||||
_value.d = _value.x;
|
||||
}
|
||||
|
||||
if (_target != null && _propType != TweenPropType.None)
|
||||
TweenPropTypeUtils.SetProps(_target, _propType, _value);
|
||||
|
||||
CallUpdateCallback();
|
||||
}
|
||||
|
||||
void CallStartCallback()
|
||||
{
|
||||
if (GTween.catchCallbackExceptions)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_onStart1 != null)
|
||||
_onStart1(this);
|
||||
if (_onStart != null)
|
||||
_onStart();
|
||||
if (_listener != null)
|
||||
_listener.OnTweenStart(this);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogWarning("FairyGUI: error in start callback > " + e.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_onStart1 != null)
|
||||
_onStart1(this);
|
||||
if (_onStart != null)
|
||||
_onStart();
|
||||
if (_listener != null)
|
||||
_listener.OnTweenStart(this);
|
||||
}
|
||||
}
|
||||
|
||||
void CallUpdateCallback()
|
||||
{
|
||||
if (GTween.catchCallbackExceptions)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_onUpdate1 != null)
|
||||
_onUpdate1(this);
|
||||
if (_onUpdate != null)
|
||||
_onUpdate();
|
||||
if (_listener != null)
|
||||
_listener.OnTweenUpdate(this);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogWarning("FairyGUI: error in update callback > " + e.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_onUpdate1 != null)
|
||||
_onUpdate1(this);
|
||||
if (_onUpdate != null)
|
||||
_onUpdate();
|
||||
if (_listener != null)
|
||||
_listener.OnTweenUpdate(this);
|
||||
}
|
||||
}
|
||||
|
||||
void CallCompleteCallback()
|
||||
{
|
||||
if (GTween.catchCallbackExceptions)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_onComplete1 != null)
|
||||
_onComplete1(this);
|
||||
if (_onComplete != null)
|
||||
_onComplete();
|
||||
if (_listener != null)
|
||||
_listener.OnTweenComplete(this);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogWarning("FairyGUI: error in complete callback > " + e.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_onComplete1 != null)
|
||||
_onComplete1(this);
|
||||
if (_onComplete != null)
|
||||
_onComplete();
|
||||
if (_listener != null)
|
||||
_listener.OnTweenComplete(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48e1b5ac4a90a5649962a3e75fd666c2
|
||||
timeCreated: 1531222519
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,180 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
internal static class TweenManager
|
||||
{
|
||||
static GTweener[] _activeTweens = new GTweener[30];
|
||||
static List<GTweener> _tweenerPool = new List<GTweener>(30);
|
||||
static int _totalActiveTweens = 0;
|
||||
static bool _inited = false;
|
||||
|
||||
internal static GTweener CreateTween()
|
||||
{
|
||||
if (!_inited)
|
||||
Init();
|
||||
|
||||
GTweener tweener;
|
||||
int cnt = _tweenerPool.Count;
|
||||
if (cnt > 0)
|
||||
{
|
||||
tweener = _tweenerPool[cnt - 1];
|
||||
_tweenerPool.RemoveAt(cnt - 1);
|
||||
}
|
||||
else
|
||||
tweener = new GTweener();
|
||||
tweener._Init();
|
||||
_activeTweens[_totalActiveTweens++] = tweener;
|
||||
|
||||
if (_totalActiveTweens == _activeTweens.Length)
|
||||
{
|
||||
GTweener[] newArray = new GTweener[_activeTweens.Length + Mathf.CeilToInt(_activeTweens.Length * 0.5f)];
|
||||
_activeTweens.CopyTo(newArray, 0);
|
||||
_activeTweens = newArray;
|
||||
}
|
||||
|
||||
return tweener;
|
||||
}
|
||||
|
||||
internal static bool IsTweening(object target, TweenPropType propType)
|
||||
{
|
||||
if (target == null)
|
||||
return false;
|
||||
|
||||
bool anyType = propType == TweenPropType.None;
|
||||
for (int i = 0; i < _totalActiveTweens; i++)
|
||||
{
|
||||
GTweener tweener = _activeTweens[i];
|
||||
if (tweener != null && tweener.target == target && !tweener._killed
|
||||
&& (anyType || tweener._propType == propType))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
internal static bool KillTweens(object target, TweenPropType propType, bool completed)
|
||||
{
|
||||
if (target == null)
|
||||
return false;
|
||||
|
||||
bool flag = false;
|
||||
int cnt = _totalActiveTweens;
|
||||
bool anyType = propType == TweenPropType.None;
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
GTweener tweener = _activeTweens[i];
|
||||
if (tweener != null && tweener.target == target && !tweener._killed
|
||||
&& (anyType || tweener._propType == propType))
|
||||
{
|
||||
tweener.Kill(completed);
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
internal static GTweener GetTween(object target, TweenPropType propType)
|
||||
{
|
||||
if (target == null)
|
||||
return null;
|
||||
|
||||
int cnt = _totalActiveTweens;
|
||||
bool anyType = propType == TweenPropType.None;
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
GTweener tweener = _activeTweens[i];
|
||||
if (tweener != null && tweener.target == target && !tweener._killed
|
||||
&& (anyType || tweener._propType == propType))
|
||||
{
|
||||
return tweener;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static void Update()
|
||||
{
|
||||
int cnt = _totalActiveTweens;
|
||||
int freePosStart = -1;
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
GTweener tweener = _activeTweens[i];
|
||||
if (tweener == null)
|
||||
{
|
||||
if (freePosStart == -1)
|
||||
freePosStart = i;
|
||||
}
|
||||
else if (tweener._killed)
|
||||
{
|
||||
tweener._Reset();
|
||||
_tweenerPool.Add(tweener);
|
||||
_activeTweens[i] = null;
|
||||
|
||||
if (freePosStart == -1)
|
||||
freePosStart = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((tweener._target is GObject) && ((GObject)tweener._target)._disposed)
|
||||
tweener._killed = true;
|
||||
else if (!tweener._paused)
|
||||
tweener._Update();
|
||||
|
||||
if (freePosStart != -1)
|
||||
{
|
||||
_activeTweens[freePosStart] = tweener;
|
||||
_activeTweens[i] = null;
|
||||
freePosStart++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (freePosStart >= 0)
|
||||
{
|
||||
if (_totalActiveTweens != cnt) //new tweens added
|
||||
{
|
||||
int j = cnt;
|
||||
cnt = _totalActiveTweens - cnt;
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
_activeTweens[freePosStart++] = _activeTweens[j];
|
||||
_activeTweens[j] = null;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
_totalActiveTweens = freePosStart;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Clean()
|
||||
{
|
||||
_tweenerPool.Clear();
|
||||
}
|
||||
|
||||
static void Init()
|
||||
{
|
||||
_inited = true;
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
GameObject gameObject = new GameObject("[FairyGUI.TweenManager]");
|
||||
gameObject.hideFlags = HideFlags.HideInHierarchy;
|
||||
gameObject.SetActive(true);
|
||||
Object.DontDestroyOnLoad(gameObject);
|
||||
|
||||
gameObject.AddComponent<TweenEngine>();
|
||||
}
|
||||
}
|
||||
|
||||
class TweenEngine : MonoBehaviour
|
||||
{
|
||||
void Update()
|
||||
{
|
||||
TweenManager.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3048174c9aaf2e840953e3cab497a426
|
||||
timeCreated: 1531222519
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,103 @@
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public enum TweenPropType
|
||||
{
|
||||
None,
|
||||
X,
|
||||
Y,
|
||||
Z,
|
||||
XY,
|
||||
Position,
|
||||
Width,
|
||||
Height,
|
||||
Size,
|
||||
ScaleX,
|
||||
ScaleY,
|
||||
Scale,
|
||||
Rotation,
|
||||
RotationX,
|
||||
RotationY,
|
||||
Alpha,
|
||||
Progress
|
||||
}
|
||||
|
||||
internal class TweenPropTypeUtils
|
||||
{
|
||||
internal static void SetProps(object target, TweenPropType propType, TweenValue value)
|
||||
{
|
||||
GObject g = target as GObject;
|
||||
if (g == null)
|
||||
return;
|
||||
|
||||
switch (propType)
|
||||
{
|
||||
case TweenPropType.X:
|
||||
g.x = value.x;
|
||||
break;
|
||||
|
||||
case TweenPropType.Y:
|
||||
g.y = value.x;
|
||||
break;
|
||||
|
||||
case TweenPropType.Z:
|
||||
g.z = value.x;
|
||||
break;
|
||||
|
||||
case TweenPropType.XY:
|
||||
g.xy = value.vec2;
|
||||
break;
|
||||
|
||||
case TweenPropType.Position:
|
||||
g.position = value.vec3;
|
||||
break;
|
||||
|
||||
case TweenPropType.Width:
|
||||
g.width = value.x;
|
||||
break;
|
||||
|
||||
case TweenPropType.Height:
|
||||
g.height = value.x;
|
||||
break;
|
||||
|
||||
case TweenPropType.Size:
|
||||
g.size = value.vec2;
|
||||
break;
|
||||
|
||||
case TweenPropType.ScaleX:
|
||||
g.scaleX = value.x;
|
||||
break;
|
||||
|
||||
case TweenPropType.ScaleY:
|
||||
g.scaleY = value.x;
|
||||
break;
|
||||
|
||||
case TweenPropType.Scale:
|
||||
g.scale = value.vec2;
|
||||
break;
|
||||
|
||||
case TweenPropType.Rotation:
|
||||
g.rotation = value.x;
|
||||
break;
|
||||
|
||||
case TweenPropType.RotationX:
|
||||
g.rotationX = value.x;
|
||||
break;
|
||||
|
||||
case TweenPropType.RotationY:
|
||||
g.rotationY = value.x;
|
||||
break;
|
||||
|
||||
case TweenPropType.Alpha:
|
||||
g.alpha = value.x;
|
||||
break;
|
||||
|
||||
case TweenPropType.Progress:
|
||||
g.asProgress.Update(value.d);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7000822d8123b4344b21dcfb230f8938
|
||||
timeCreated: 1531473796
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,151 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class TweenValue
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public float x;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public float y;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public float z;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public float w;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public double d;
|
||||
|
||||
public TweenValue()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Vector2 vec2
|
||||
{
|
||||
get { return new Vector2(x, y); }
|
||||
set
|
||||
{
|
||||
x = value.x;
|
||||
y = value.y;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Vector3 vec3
|
||||
{
|
||||
get { return new Vector3(x, y, z); }
|
||||
set
|
||||
{
|
||||
x = value.x;
|
||||
y = value.y;
|
||||
z = value.z;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Vector4 vec4
|
||||
{
|
||||
get { return new Vector4(x, y, z, w); }
|
||||
set
|
||||
{
|
||||
x = value.x;
|
||||
y = value.y;
|
||||
z = value.z;
|
||||
w = value.w;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Color color
|
||||
{
|
||||
get { return new Color(x, y, z, w); }
|
||||
set
|
||||
{
|
||||
x = value.r;
|
||||
y = value.g;
|
||||
z = value.b;
|
||||
w = value.a;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
public float this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
return y;
|
||||
case 2:
|
||||
return z;
|
||||
case 3:
|
||||
return w;
|
||||
default:
|
||||
throw new System.Exception("Index out of bounds: " + index);
|
||||
}
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
x = value;
|
||||
break;
|
||||
case 1:
|
||||
y = value;
|
||||
break;
|
||||
case 2:
|
||||
z = value;
|
||||
break;
|
||||
case 3:
|
||||
w = value;
|
||||
break;
|
||||
default:
|
||||
throw new System.Exception("Index out of bounds: " + index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void SetZero()
|
||||
{
|
||||
x = y = z = w = 0;
|
||||
d = 0;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97e8a1ca496b4d34cad5f2420a9f8809
|
||||
timeCreated: 1531473796
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user