Last active
August 29, 2015 14:24
-
-
Save anzfactory/88c6d4017361da1266b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using Callback = System.Action<UnityEngine.GameObject>; | |
public class ITweenAdapter : MonoBehaviour | |
{ | |
// 接続するアニメーションタイプ | |
// 必要になったら順次追加 | |
public enum RunType { | |
ScaleTo | |
} | |
private static ITweenAdapter sInstance; | |
public static ITweenAdapter Instance { | |
get { return GetInstance(); } | |
} | |
private static ITweenAdapter GetInstance() | |
{ | |
if (sInstance != null) { | |
return sInstance; | |
} | |
sInstance = FindObjectOfType<ITweenAdapter>(); | |
if (sInstance == null) { | |
GameObject gameObject = new GameObject("ITweenAdapter"); | |
sInstance = gameObject.AddComponent<ITweenAdapter>(); | |
} | |
return sInstance; | |
} | |
private void Awake() | |
{ | |
if (sInstance == null) { | |
sInstance = this; | |
DontDestroyOnLoad(this); | |
} else { | |
Destroy(this); | |
} | |
} | |
public void Popup(GameObject target) { | |
Popup(target, null); | |
} | |
public void Popup(GameObject target, Callback callback) | |
{ | |
// 必要なパラメータを作成 | |
var args = iTween.Hash( | |
"x", 1.0f, | |
"y", 1.0f, | |
"time", 0.5f, | |
"islocal", true, | |
"easetype", iTween.EaseType.easeOutBack | |
); | |
// 実行 | |
Run(RunType.ScaleTo, target, args, callback); | |
} | |
public void Dismiss(GameObject target) | |
{ | |
Dismiss(target, null); | |
} | |
public void Dismiss(GameObject target, Callback callback) | |
{ | |
var args = iTween.Hash( | |
"x", 0, | |
"y", 0, | |
"time", 0.3f, | |
"islocal", true, | |
"easetype", iTween.EaseType.easeInBack | |
); | |
Run(RunType.ScaleTo, target, args, callback); | |
} | |
public void Run( | |
RunType type, | |
GameObject target, | |
System.Collections.Hashtable args, | |
Callback callback | |
) { | |
// 終了処理に必要なやつらを追加 | |
args.Add("oncompletetarget", this.gameObject); | |
// null追加すると怒られるのでチェック | |
// sendMessageがoverloadできないので、対応するメソッドも分ける | |
if (callback == null) { | |
args.Add("oncomplete", "FinAnimation"); | |
} else { | |
args.Add("oncomplete", "FinAnimationWithCallback"); | |
var completeParams = new System.Collections.Hashtable(); | |
completeParams.Add("callback", callback); | |
completeParams.Add("sender", target); | |
args.Add("oncompleteparams", completeParams); | |
} | |
// タイプに従って実行 | |
switch (type) { | |
case RunType.ScaleTo: | |
iTween.ScaleTo(target, args); | |
break; | |
default: | |
throw new UnityException("unknown run type..." + type.ToString()); | |
} | |
} | |
public void FinAnimation() | |
{ | |
FinAnimationWithCallback(null); | |
} | |
public void FinAnimationWithCallback(System.Collections.Hashtable args) | |
{ | |
// MEMO 何かで共通的に終了処理やりたいことあったらここで | |
if (args != null) { | |
((Callback)args["callback"])((GameObject)args["sender"]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment