Skip to content

Commit

Permalink
thank you scene works
Browse files Browse the repository at this point in the history
  • Loading branch information
syKevinPeng committed May 1, 2024
1 parent 7451ae8 commit 0deab67
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 27 deletions.
60 changes: 41 additions & 19 deletions Assets/Scripts/TimelineController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class TimelineController : MonoBehaviour
// Start is called before the first frame update
public static Boolean isStationaryLoaded = false;
public static Boolean isMovingLoaded = false;
public static Boolean isBreaked = false;
private GameObject timeline;

private void LoadStationaryScene()
Expand All @@ -34,7 +35,7 @@ IEnumerator LoadAsyncScene(string sceneName = "IllusionInMotionScene")
}
yield return null;
}
GameObject.Find("MenuCanvas").GetComponent<WelcomeCanvasController>().SetupBreakPage();

}

IEnumerator AsyncLoadBreakScene()
Expand All @@ -51,6 +52,25 @@ IEnumerator AsyncLoadBreakScene()
}
yield return null;
}
GameObject.Find("MenuCanvas").GetComponent<WelcomeCanvasController>().SetupBreakPage();

}

IEnumerator AsyncLoadThankyouScene()
{
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync("WelcomeScene");
asyncLoad.allowSceneActivation = false;
while (!asyncLoad.isDone)
{
Debug.LogWarning("Loading progress: " + asyncLoad.progress);
// if (asyncLoad.progress >= 0.9f)
if (isMovingSceneLoaded())
{
asyncLoad.allowSceneActivation = true;
}
yield return null;
}
GameObject.Find("MenuCanvas").GetComponent<WelcomeCanvasController>().SetupThankyouPage();

}

Expand All @@ -68,19 +88,17 @@ private Boolean isMovingSceneLoaded()
return camera.transform.hasChanged;

}
private void ListAllObj()
{
GameObject[] allObjects = UnityEngine.Object.FindObjectsOfType<GameObject>();
foreach (GameObject obj in allObjects)
{
Debug.Log(obj.name);
}
}

private void LoadBreakScene()
{
StartCoroutine(LoadAsyncScene("WelcomeScene"));
StartCoroutine(AsyncLoadBreakScene());

}

private void LoadThankyouScene()
{
StartCoroutine(AsyncLoadThankyouScene());
}
public void GetNextScene()
{
if (!isStationaryLoaded && !isMovingLoaded)
Expand All @@ -100,28 +118,32 @@ public void GetNextScene()
isMovingLoaded = true;
}
}
else if (isStationaryLoaded && !isMovingLoaded)
else if (!isBreaked)
{
// move to break scene
// if one of the scenes is loaded, load the break scene
LoadBreakScene();
isBreaked = true;
}
else if (isStationaryLoaded && !isMovingLoaded)
{
Debug.Log(" === Then Loading moving scene === ");
// LoadMovingScene();
LoadMovingScene();
isMovingLoaded = true;

}
else if (!isStationaryLoaded && isMovingLoaded)
{
LoadBreakScene();
Debug.Log(" === Then Loading stationary scene === ");
// LoadStationaryScene();
LoadStationaryScene();
isStationaryLoaded = true;
}
else if (isStationaryLoaded && isMovingLoaded && isBreaked)
{
LoadThankyouScene();
}
else
{
Debug.Log("Expereinment is over, both scenes are loaded.");
Debug.Log(" == Total Time: " + (Time.time - startTime) + " == ");
// quit the application
Application.Quit();
Debug.LogError(" === Something went wrong === ");
}

}
Expand Down
33 changes: 25 additions & 8 deletions Assets/Scripts/WelcomeCanvasController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class WelcomeCanvasController : MonoBehaviour
private Toggle BSPCheckBox3;
private GameObject TimelineController;
private Boolean startTimer = false;
private float timeRemaining = 60; // seconds
private float timeRemaining = 10; // seconds

private GameObject TimeText;
public void NextBtnClick()
Expand All @@ -47,8 +47,11 @@ public void NextBtnClick()
{
TimelineController.GetComponent<TimelineController>().GetNextScene();
}
else if (currentPage == BreakPage)
{
TimelineController.GetComponent<TimelineController>().GetNextScene();
}
NxtButton.GetComponent<Button>().interactable = false; // avoid double click
// NxtButton.interactable = false; // avoid double click
}

public void WhenHover()
Expand All @@ -66,9 +69,16 @@ public void WhenUnhover()

void DisplayTime(float timeToDisplay)
{
float minutes = Mathf.FloorToInt(timeToDisplay / 60);
float seconds = Mathf.FloorToInt(timeToDisplay % 60);
TimeText.GetComponent<TextMeshProUGUI>().text = string.Format("{0:00}:{1:00}", minutes, seconds);
if (timeToDisplay <= 0)
{
TimeText.GetComponent<TextMeshProUGUI>().text = "Break Completed";
}
else
{
float minutes = Mathf.FloorToInt(timeToDisplay / 60);
float seconds = Mathf.FloorToInt(timeToDisplay % 60);
TimeText.GetComponent<TextMeshProUGUI>().text = string.Format("{0:00}:{1:00}", minutes, seconds);
}
}

public void SetupBreakPage()
Expand All @@ -79,6 +89,14 @@ public void SetupBreakPage()
startTimer = true;
}

public void SetupThankyouPage()
{
currentPage.SetActive(false);
ThankyouPage.SetActive(true);
currentPage = ThankyouPage;
NxtButton.SetActive(false);
}

void Start()
{
MenuCanvas = GameObject.Find("MenuCanvas");
Expand Down Expand Up @@ -118,9 +136,6 @@ void Start()
Debug.LogError("<color=red>CheckBox1 is not found</color>");
}




}

// Update is called once per frame
Expand All @@ -131,10 +146,12 @@ void Update()
// deal with timer
if (startTimer)
{
NxtButton.GetComponent<Button>().interactable = false;
timeRemaining -= Time.deltaTime;
if (timeRemaining < 0)
{
startTimer = false;
NxtButton.GetComponent<Button>().interactable = true;
// NextBtnClick();
Debug.LogError("Time is up");

Expand Down

0 comments on commit 0deab67

Please sign in to comment.