using UnityEngine;
using System.Collections;
using DG.Tweening;
public class TheExplosionFigure : MonoBehaviour {
//動畫要到達(dá)的目標(biāo)位置
public Vector3 TheTargetLocation;
//動畫所需要的時間
public float duration;
//目標(biāo)物體
public Transform TargetPart;
//是否處于展開狀態(tài)
public bool IsSpread;
//是否完全展開了模型
public bool FullyExpanded;
public bool Reset;
public Vector3 StartPosition;
//模型當(dāng)前的位置
private Transform currentLocation;
// Use this for initialization
void Start () {
//當(dāng)前位置
currentLocation = GetComponent<Transform >();
TargetPart = GetComponent<Transform >();
StartPosition = TargetPart.position;
//是否展開模型
IsSpread = false;
Reset = true;
//是否完全展開
FullyExpanded = false;
//從當(dāng)前位置到目標(biāo)位置的過度
Tweener tweener = TargetPart.DOMove(TheTargetLocation, duration);
//自動銷毀設(shè)置為false
tweener.SetAutoKill(false );
//動畫暫停
tweener.Pause();
}
//public void IsFullyExpanded()
//{
//}
// Update is called once per frame
void Update () {
//如果當(dāng)前的位置 = 目標(biāo)位置
if (currentLocation.position == TheTargetLocation)
{
//完全展開了
FullyExpanded = true;
Reset = false;
}
//如果當(dāng)前位置 不等于 目標(biāo)位置
else
if (currentLocation.position == StartPosition)
{
//沒有完全展開
FullyExpanded = false;
Reset = true;
}
}
//Button點擊事件
public void OnClick()
{
//如果沒有處于展開狀態(tài)
if (IsSpread == false)
{
//如果模型沒有完全展開
if (Reset)
{
//前放展開動畫
TargetPart.DOPlayForward();
IsSpread = true;
}
}
// FullyExpanded = true;
else
//如果模型處于展開狀態(tài)
if (IsSpread)
{
//如果模型完全展開了
if (FullyExpanded)
{
//倒放展開動畫(合攏模型)
TargetPart.DOPlayBackwards();
IsSpread = false;
}
//FullyExpanded = false;
}
}
}