给物体增加NGUI动画并供外界调用
把类做成单例模式来使用:
TransformState()在外部调用时的效果:如果正在显示则关闭,如果关闭则显示。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Inventory : MonoBehaviour
{
public static Inventory _instance;
private TweenPosition tween;
void Awake()
{
_instance = this;
tween = this.GetComponent<TweenPosition>();//获取组件
tween.AddOnFinished(this.OnTweenPlayFinished);
this.gameObject.SetActive(false);//默认是隐藏的
}
private bool isShow = false;
void Show()//——————播放
{
isShow = true;
this.gameObject.SetActive(true);
tween.PlayForward();
}
void Hide()//——————隐藏
{
isShow = false;
tween.PlayReverse();
}
void OnTweenPlayFinished()//-----------动画是否结束
{
if (isShow == false)
{
this.gameObject.SetActive(false);
}
}
public void TransformState()//对外调用
{
if(isShow == false)
{
Show();
}
else
{
Hide();
}
}
}