using UnityEngine; using System.Collections; public class TweenFlipCARDS : MonoBehaviour { /// <summary> 牌正面 </summary> public GameObject positive; /// <summary> 牌背面 </summary> public GameObject reverse; /// <summary> 半圈时间 </summary> public float duration = 1; float mfTime = 1.0f; TweenRotation mPositiveTween; TweenRotation mReverseTween; void Start() { mPositiveTween = positive.GetComponent<TweenRotation>(); if (mPositiveTween == null) mPositiveTween = positive.AddComponent<TweenRotation>(); mReverseTween = reverse.GetComponent<TweenRotation>(); if (mReverseTween == null) mReverseTween = reverse.AddComponent<TweenRotation>(); mPositiveTween.enabled = false; mReverseTween.enabled = false; reverse.gameObject.transform.localEulerAngles = new Vector3(0, 90, 0); //mPositiveTween.onFinished.Add(new EventDelegate(PositiveEventDelegate)); //mReverseTween.onFinished.Add(new EventDelegate(ReverseEventDelegate)); //mPositiveTween.callWhenFinished = "PositiveEventDelegate"; //mReverseTween.callWhenFinished = "ReverseEventDelegate"; // a是正面,b是反面, 分为4个时间段 1. a 从0转到90 ,b静止。2.a静止,b 从90-0. 3.a静止,b0-90. 4.a从90-0,b静止。 StartCoroutine(waitShowReverseTime(mfTime));//显示一定的时间后再翻牌 } IEnumerator waitShowReverseTime(float time) { yield return new WaitForSeconds(time); mPositiveTween.from = Vector3.zero; mPositiveTween.to = new Vector3(0, 90, 0); mPositiveTween.duration = duration; mReverseTween.from = new Vector3(0, 90, 0); mReverseTween.to = Vector3.zero; mReverseTween.duration = duration; UIEventListener listener = UIEventListener.Get(positive.gameObject); listener.onClick = ClickUIButton; listener = UIEventListener.Get(reverse.gameObject); listener.onClick = ClickUIButton; // mPositiveTween.onFinished.Add(PositiveEventDelegate); // mReverseTween.onFinished = ReverseEventDelegate; EventDelegate.Add (mPositiveTween.onFinished, PositiveEventDelegate); EventDelegate.Add (mReverseTween.onFinished, ReverseEventDelegate); ClickUIButton(positive); } GameObject mNowDown; void ClickUIButton(GameObject click) { mNowDown = click; if (click == positive) { PlayPositive(); } else if (click == reverse) { PlayReverse(); } } /// <summary>翻牌</summary> void PlayPositive() { mPositiveTween.Play(true); } /// <summary>复位 </summary> void PlayReverse() { mReverseTween.Play(false); } /// <summary> 翻牌回调</summary> void PositiveEventDelegate() { if (mNowDown == mPositiveTween.gameObject) mReverseTween.Play(true); Debug.Log ("翻牌回调"); } /// <summary> 复位回调 </summary> void ReverseEventDelegate() { if (mNowDown == mReverseTween.gameObject) mPositiveTween.Play(false); Debug.Log ("复位回调"); } }
时间: 2024-10-12 18:30:43