Add chests animations
This commit is contained in:
parent
442a3617f1
commit
aa3e62b78e
@ -5,6 +5,7 @@ using UnityEngine.UI;
|
|||||||
|
|
||||||
public class KeyBindScript : MonoBehaviour
|
public class KeyBindScript : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is the dictionary, that contains all our keybinds
|
/// This is the dictionary, that contains all our keybinds
|
||||||
@ -49,7 +50,7 @@ public class KeyBindScript : MonoBehaviour
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
@ -83,7 +84,7 @@ public class KeyBindScript : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}*/
|
}
|
||||||
void OnGUI()
|
void OnGUI()
|
||||||
{
|
{
|
||||||
if (currentKey != null) //If we have selected a key, that we want to edit
|
if (currentKey != null) //If we have selected a key, that we want to edit
|
||||||
@ -128,5 +129,6 @@ public class KeyBindScript : MonoBehaviour
|
|||||||
|
|
||||||
PlayerPrefs.Save();
|
PlayerPrefs.Save();
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,11 @@ public class ChestController : MonoBehaviour
|
|||||||
|
|
||||||
private void OnTriggerExit2D(Collider2D collision)
|
private void OnTriggerExit2D(Collider2D collision)
|
||||||
{
|
{
|
||||||
if (collision.tag == "Player")
|
if (collision.tag == "Player" && ChestUIManager.Instance.CurrentChestName != null)
|
||||||
{
|
{
|
||||||
ChestUIManager.Instance.CurrentChestName = null;
|
|
||||||
|
|
||||||
ChestUIManager.Instance.ClosePanel();
|
ChestUIManager.Instance.ClosePanel();
|
||||||
|
|
||||||
|
ChestUIManager.Instance.CurrentChestName = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,66 +34,23 @@ public abstract class UIBaseManager<T> : MonoBehaviour, ManagerInterface<T>
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Log(gameObject);
|
|
||||||
Debug.Log(Instance);
|
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//public GameObject Chest1 = GameObject.Find("Gold Chest");
|
// async
|
||||||
|
public virtual void Update()
|
||||||
|
|
||||||
public async void Update()
|
|
||||||
{
|
{
|
||||||
if (Input.GetKeyDown(keyToOpen))
|
if (Input.GetKeyDown(keyToOpen))
|
||||||
{
|
{
|
||||||
if (!DynamicPanel)
|
if (!DynamicPanel)
|
||||||
{
|
{
|
||||||
//condition to be near to the chest
|
|
||||||
if (ChestUIManager.Instance.CurrentChestName != null && ChestUIManager.Instance.CurrentChestName != "")
|
|
||||||
{
|
|
||||||
//delay using async Yield and triggering chests to start open animation
|
|
||||||
var end = Time.time + 0.3;
|
|
||||||
animateOpening();
|
|
||||||
while (Time.time < end)
|
|
||||||
{
|
|
||||||
await System.Threading.Tasks.Task.Yield();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.OpenPanel();
|
this.OpenPanel();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.ClosePanel();
|
this.ClosePanel();
|
||||||
var end2 = Time.time + 0.1;
|
|
||||||
while (Time.time < end2)
|
|
||||||
{
|
|
||||||
await System.Threading.Tasks.Task.Yield();
|
|
||||||
}
|
}
|
||||||
animateClosing();
|
|
||||||
end2 = Time.time + 0.3;
|
|
||||||
while (Time.time < end2)
|
|
||||||
{
|
|
||||||
await System.Threading.Tasks.Task.Yield();
|
|
||||||
}
|
|
||||||
resettriggers();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ChestUIManager.Instance.CurrentChestName == null || ChestUIManager.Instance.CurrentChestName == "")
|
|
||||||
{
|
|
||||||
var end2 = Time.time + 0.1;
|
|
||||||
while (Time.time < end2)
|
|
||||||
{
|
|
||||||
await System.Threading.Tasks.Task.Yield();
|
|
||||||
}
|
|
||||||
animateClosing();
|
|
||||||
end2 = Time.time + 0.3;
|
|
||||||
while (Time.time < end2)
|
|
||||||
{
|
|
||||||
await System.Threading.Tasks.Task.Yield();
|
|
||||||
}
|
|
||||||
resettriggers();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,39 +64,6 @@ public abstract class UIBaseManager<T> : MonoBehaviour, ManagerInterface<T>
|
|||||||
//DynamicPanel = dynamicPanelController;
|
//DynamicPanel = dynamicPanelController;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void animateOpening()
|
|
||||||
{
|
|
||||||
/* GameObject.Find("Gold Chest").GetComponent<Animator>().SetTrigger("OpenIt");
|
|
||||||
GameObject.Find("Prize Chest").GetComponent<Animator>().SetTrigger("OpenIt");
|
|
||||||
GameObject.Find("Wodden Chest").GetComponent<Animator>().SetTrigger("OpenIt");*/
|
|
||||||
}
|
|
||||||
|
|
||||||
private async void animateClosing()
|
|
||||||
{
|
|
||||||
/* GameObject.Find("Gold Chest").GetComponent<Animator>().ResetTrigger("OpenIt");
|
|
||||||
GameObject.Find("Prize Chest").GetComponent<Animator>().ResetTrigger("OpenIt");
|
|
||||||
GameObject.Find("Wodden Chest").GetComponent<Animator>().ResetTrigger("OpenIt");
|
|
||||||
GameObject.Find("Gold Chest").GetComponent<Animator>().SetTrigger("CloseIt");
|
|
||||||
GameObject.Find("Prize Chest").GetComponent<Animator>().SetTrigger("CloseIt");
|
|
||||||
GameObject.Find("Wodden Chest").GetComponent<Animator>().SetTrigger("CloseIt");*/
|
|
||||||
}
|
|
||||||
|
|
||||||
private async void resettriggers()
|
|
||||||
{
|
|
||||||
var end3 = Time.time + 0.0;
|
|
||||||
while (Time.time < end3)
|
|
||||||
{
|
|
||||||
await System.Threading.Tasks.Task.Yield();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* GameObject.Find("Gold Chest").GetComponent<Animator>().ResetTrigger("CloseIt");
|
|
||||||
GameObject.Find("Prize Chest").GetComponent<Animator>().ResetTrigger("CloseIt");
|
|
||||||
GameObject.Find("Wodden Chest").GetComponent<Animator>().ResetTrigger("CloseIt");
|
|
||||||
GameObject.Find("Wodden Chest").GetComponent<Animator>().SetTrigger("reactivate");
|
|
||||||
GameObject.Find("Prize Chest").GetComponent<Animator>().SetTrigger("reactivate");
|
|
||||||
GameObject.Find("Gold Chest").GetComponent<Animator>().SetTrigger("reactivate");*/
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual bool OpenPanel()
|
public virtual bool OpenPanel()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Panel opened");
|
Console.WriteLine("Panel opened");
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -14,6 +15,11 @@ public class ChestUIManager : UIBaseManager<Chest>
|
|||||||
|
|
||||||
public string CurrentChestName = null;
|
public string CurrentChestName = null;
|
||||||
|
|
||||||
|
public bool OpenAfterDelay = false;
|
||||||
|
public bool CloseAfterDelay = false;
|
||||||
|
|
||||||
|
private IEnumerator coroutine;
|
||||||
|
|
||||||
public void Awake()
|
public void Awake()
|
||||||
{
|
{
|
||||||
if (Instance == null)
|
if (Instance == null)
|
||||||
@ -26,9 +32,41 @@ public class ChestUIManager : UIBaseManager<Chest>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update()
|
|
||||||
|
public override void Update()
|
||||||
{
|
{
|
||||||
keyToOpen = (KeyCode) System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("Interact"));
|
base.Update();
|
||||||
|
|
||||||
|
/* if (OpenAfterDelay && DynamicPanel == null && CurrentChestName != null && CurrentChestName != "")
|
||||||
|
{
|
||||||
|
Debug.Log("Open in Update");
|
||||||
|
OpenAfterDelay = false;
|
||||||
|
|
||||||
|
|
||||||
|
// Open additiona panels
|
||||||
|
if (!EquipmentUIManager.Instance.GetPanelStatus()) EquipmentUIManager.Instance.OpenPanel();
|
||||||
|
|
||||||
|
if (!InventoryUIManager.Instance.GetPanelStatus()) InventoryUIManager.Instance.OpenPanel();
|
||||||
|
|
||||||
|
base.OpenPanel();
|
||||||
|
}
|
||||||
|
//keyToOpen = (KeyCode) System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("Interact"));
|
||||||
|
|
||||||
|
|
||||||
|
if (CloseAfterDelay && DynamicPanel != null && CurrentChestName != null && CurrentChestName != "")
|
||||||
|
{
|
||||||
|
CloseAfterDelay = false;
|
||||||
|
|
||||||
|
|
||||||
|
base.ClosePanel();
|
||||||
|
|
||||||
|
ChestContentUIManager.Instance.DynamicPanel = null;
|
||||||
|
|
||||||
|
// Close additionals panels
|
||||||
|
if (EquipmentUIManager.Instance.GetPanelStatus()) EquipmentUIManager.Instance.ClosePanel();
|
||||||
|
|
||||||
|
if (InventoryUIManager.Instance.GetPanelStatus()) InventoryUIManager.Instance.ClosePanel();
|
||||||
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,12 +79,13 @@ public class ChestUIManager : UIBaseManager<Chest>
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open additiona panels
|
|
||||||
if (!EquipmentUIManager.Instance.GetPanelStatus()) EquipmentUIManager.Instance.OpenPanel();
|
|
||||||
|
|
||||||
if (!InventoryUIManager.Instance.GetPanelStatus()) InventoryUIManager.Instance.OpenPanel();
|
// Animacje otwierania
|
||||||
|
OpeningAnimate();
|
||||||
|
|
||||||
return base.OpenPanel();
|
StartCoroutine(OpenWithDelay(0.3f));
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool ClosePanel()
|
public override bool ClosePanel()
|
||||||
@ -60,6 +99,11 @@ public class ChestUIManager : UIBaseManager<Chest>
|
|||||||
|
|
||||||
if (InventoryUIManager.Instance.GetPanelStatus()) InventoryUIManager.Instance.ClosePanel();
|
if (InventoryUIManager.Instance.GetPanelStatus()) InventoryUIManager.Instance.ClosePanel();
|
||||||
|
|
||||||
|
// Animacje zmykania
|
||||||
|
ClosingAnimate(CurrentChestName);
|
||||||
|
StartCoroutine(CloseWithDelay(0.3f, CurrentChestName)); // delay to display closing without breaking
|
||||||
|
|
||||||
|
//CloseWithDelay(0.3f);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -112,4 +156,58 @@ public class ChestUIManager : UIBaseManager<Chest>
|
|||||||
{
|
{
|
||||||
return Elements.Find(chest => chest.Name == _chestName);
|
return Elements.Find(chest => chest.Name == _chestName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Animation API
|
||||||
|
private IEnumerator OpenWithDelay(float waitTime)
|
||||||
|
{
|
||||||
|
yield return new WaitForSeconds(waitTime);
|
||||||
|
|
||||||
|
// Open additiona panels
|
||||||
|
if (!EquipmentUIManager.Instance.GetPanelStatus()) EquipmentUIManager.Instance.OpenPanel();
|
||||||
|
|
||||||
|
if (!InventoryUIManager.Instance.GetPanelStatus()) InventoryUIManager.Instance.OpenPanel();
|
||||||
|
|
||||||
|
base.OpenPanel();
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator CloseWithDelay(float waitTime, string chestName)
|
||||||
|
{
|
||||||
|
yield return new WaitForSeconds(waitTime);
|
||||||
|
|
||||||
|
ResetingTriggerAnimate(chestName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OpeningAnimate()
|
||||||
|
{
|
||||||
|
var currentChest = GameObject.FindGameObjectWithTag("ChestCollection").transform.Find(CurrentChestName);
|
||||||
|
|
||||||
|
if(currentChest != null)
|
||||||
|
{
|
||||||
|
currentChest.GetComponent<Animator>().SetTrigger("OpenIt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ClosingAnimate(string chestName)
|
||||||
|
{
|
||||||
|
var currentChest = GameObject.FindGameObjectWithTag("ChestCollection").transform.Find(chestName);
|
||||||
|
|
||||||
|
if (currentChest != null)
|
||||||
|
{
|
||||||
|
currentChest.GetComponent<Animator>().ResetTrigger("OpenIt");
|
||||||
|
currentChest.GetComponent<Animator>().SetTrigger("CloseIt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResetingTriggerAnimate(string chestName)
|
||||||
|
{
|
||||||
|
var currentChest = GameObject.FindGameObjectWithTag("ChestCollection").transform.Find(chestName);
|
||||||
|
|
||||||
|
if (currentChest != null)
|
||||||
|
{
|
||||||
|
currentChest.GetComponent<Animator>().ResetTrigger("CloseIt");
|
||||||
|
currentChest.GetComponent<Animator>().SetTrigger("reactivate");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user