ポートフォリオゲーム:DOTween導入、場所名表示【193日目】(2019/02/28)
https://gyazo.com/fede0791ecb69832a4cab5ac67a5a4fd
Porin.icon今日はカラメルカラムの業務の作業記録だよん!
◆作業記録の目次
1. ポートフォリオゲーム:DOTween導入、場所名表示
https://gyazo.com/ea38e8d40023a4d62a667463b859b1d4
1. ポートフォリオゲーム:DOTween導入、場所名表示
◆ DOTween導入
. ▼ 調べる
ドキュメントを読んだら便利な使い方をたくさん発見した
▼ 導入
DOTweenをダウンロードして、Asset/Scripts下に放り込む
指示が出るままにセットアップする
▼ DOTween用のスクリプトを作成
ゲーム開始と共にuseSmoothDeltaTimeをtrueに
こんな風に書いてあったので試してみることに
If TRUE, DOTween will use Time.smoothDeltaTime instead of Time.deltaTime for UpdateType.Normal and UpdateType.Late tweens (unless they're set as timeScaleIndependent, in which case a value between the last timestep and maxSmoothUnscaledTime will be used instead). Setting this to TRUE will lead to smoother animations.
code:AppUtil.cs
using DG.Tweening;
public class AppUtil : MonoBehaviour
{
public static void InitTween(){
DOTween.useSmoothDeltaTime = true;
}
}
code:SceneBase.cs
protected virtual void Awake(){
if(!isInitialized){
GameObject debugMenu = Instantiate(debugCanvas) as GameObject;
DontDestroyOnLoad(debugMenu);
isInitialized = true;
SceneManager.sceneLoaded += OnSceneLoaded;
AppUtil.InitTween();
}
}
◆ 場所名表示
▼ 場所表示オブジェクトの読み込み
code:SceneBase.cs
public static string currentPlace;
protected virtual void Awake(){
if(SceneManager.GetActiveScene().name != "スタート"){
placeRect = GameObject.Find("CurrentPlace").GetComponent<RectTransform>();
placeOriginPos = placeRect.anchoredPosition;
}
}
▼ 表示
探索シーン開始時
code:SceneInvestigation.cs
private void Start(){
SceneBase.ShowCurrentPlace("目覚めた場所");
}
フィールドの移動はコライダのTriggerで検知
code:Wanko.cs
public void OnTriggerEnter2D(Collider2D collider){
Debug.Log(collider.name);
switch(collider.name){
case "WakeUpPlace":
if(SceneBase.currentPlace == "目覚めた場所") {
SceneBase.ShowCurrentPlace("だれかの部屋");
} else if(SceneBase.currentPlace == "だれかの部屋") {
SceneBase.ShowCurrentPlace("目覚めた場所");
}
break;
}
}
表示用メソッド
DOTweenのSequenceを使ってみた
WaitForCompletionはコルーチンでしか使えないので、普通のメソッドで使えるSequence便利
code:SceneBase.cs
public static void ShowCurrentPlace(string placeName){
placeRect.GetChild(0).GetComponent<Text>().text = placeName;
placeRect.anchoredPosition = placeOriginPos;
AppUtil.DOSequence(
new DG.Tweening.Tween[] {
AppUtil.MoveRect(placeRect, "上", true, 1f, "InOutQuart"),
AppUtil.MoveRect(placeRect, "上", false, 0.8f, "InOutQuart", 2f)
},
0f,
0f
);
currentPlace = placeName;
// 演出別パターン
// AppUtil.DOSequence(
// new DG.Tweening.Tween[] {
// AppUtil.ShowRect(placeRect, "x", 0f, 0.25f, "InOutQuart", 1f),
// AppUtil.HideRect(placeRect, "x", 0.25f, "InOutQuart", 2f)
// },
// 0f,
// 0f
// );
}
https://gyazo.com/72dea0ce00cba190b794b595e71061ef
ついでにプレイヤーデータ周りのコードが怪しかったのでリファクタした
code:SceneBase.cs
// プレイヤーステータス
public static SCENE currentScene {
get { return (SCENE)Enum.Parse(typeof(SCENE), PlayerPrefs.GetString("Scene", "NONE")); }
private set { PlayerPrefs.SetString("Scene", Enum.GetName(typeof(SCENE), value)); }
}
public static SCENARIO currentScinario {
get { return (SCENARIO)Enum.Parse(typeof(SCENARIO), PlayerPrefs.GetString("Scinario", "NONE")); }
private set { PlayerPrefs.SetString("Scinario", Enum.GetName(typeof(SCENARIO), value)); }
}