using UnityEngine; using System.Collections; public class TweenFlipCARDS : MonoBehaviour { private float mfTime = 1.0f; public GameObject positive;//牌正面 public GameObject reverse;//牌背面 private TweenRotation mPositiveTween; private TweenRotation mReverseTween; /// <summary> 半圈时间 </summary> public float duration = 1; 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 = PositiveEventDelegate; mReverseTween.onFinished = ReverseEventDelegate; ClickUIButton(positive); } GameObject mNowDown; void ClickUIButton(GameObject click) { mNowDown = click; if (click == positive) { PlayPositive(); } else if (click == reverse) { PlayReverse(); } } /// <summary> /// 翻牌 /// </summary> public void PlayPositive() { mPositiveTween.Play(true); } /// <summary> /// 复位 /// </summary> public void PlayReverse() { mReverseTween.Play(false); } /// <summary> /// 翻牌回调 /// </summary> public void PositiveEventDelegate(UITweener tween) { if (mNowDown == mPositiveTween.gameObject) mReverseTween.Play(true); } /// <summary> /// 复位回调 /// </summary> public void ReverseEventDelegate(UITweener tween) { if (mNowDown == mReverseTween.gameObject) mPositiveTween.Play(false); } }上述代码均来自http://www.xiaobao1993.com/486.html
时间: 2024-10-29 12:51:18