Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
UxxHans committed Sep 24, 2021
1 parent 0aba03d commit c0ffbbb
Show file tree
Hide file tree
Showing 53 changed files with 7,080 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Control Center/ControlCenter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using UnityEngine;

/// <summary>
/// This script controls the toggle between different functions
/// </summary>
public class ControlCenter : MonoBehaviour
{
//Variables declaration
public TeleportManager teleportManager;
public SeedManager seedManager;
public GridManager gridManager;
public PlaceableManager placeableManager;

public void SetFunction(int functionIndex)
{
//Set all to inactive
placeableManager.SetActive(false);
seedManager.SetActive(false);
gridManager.SetActive(false);
teleportManager.SetActive(false);

//Set active selected function
switch (functionIndex)
{
case -1:
break;
case 0:
teleportManager.SetActive(true);
break;
case 1:
seedManager.SetActive(true);
break;
case 2:
gridManager.SetActive(true);
placeableManager.SetActive(true);
break;
}
}
}
55 changes: 55 additions & 0 deletions Control Center/PlayerUIFollow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using UnityEngine;

/// <summary>
/// Make the UI follow the player's look direction when y rotation exceeds 180 Deg
/// </summary>
public class PlayerUIFollow : MonoBehaviour
{
//Rotate axis
public enum Axis { x, y, z };
public Axis rotateAxis;

//Record original
private Vector3 originalRotation;

/// <summary>
/// Start repeating check the look direction
/// </summary>
private void Start()
{
//Record original rotation
originalRotation = transform.eulerAngles;
// Use slow update to improve the performance
InvokeRepeating(nameof(Check), 0, 0.25f);
}

/// <summary>
/// Check the player's look direction and adjust the UI postion
/// </summary>
private void Check()
{
//Get player's y rotation
float angle = Camera.main.transform.eulerAngles.y;
//UI follow the player's angle
switch (rotateAxis) {
case Axis.x:
if (angle < 180 && angle > 0)
gameObject.transform.eulerAngles = new Vector3(90, originalRotation.y, originalRotation.z);
else
gameObject.transform.eulerAngles = new Vector3(270, originalRotation.y, originalRotation.z);
break;
case Axis.y:
if (angle < 180 && angle > 0)
gameObject.transform.eulerAngles = new Vector3(originalRotation.x, 90, originalRotation.z);
else
gameObject.transform.eulerAngles = new Vector3(originalRotation.x, 270, originalRotation.z);
break;
case Axis.z:
if (angle < 180 && angle > 0)
gameObject.transform.eulerAngles = new Vector3(originalRotation.x, originalRotation.y, 90);
else
gameObject.transform.eulerAngles = new Vector3(originalRotation.x, originalRotation.y, 270);
break;
}
}
}
131 changes: 131 additions & 0 deletions Dialogue Manager/DialogAnimation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using System.Collections.Generic;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// This script gives the UI animation of typing
/// </summary>
public class DialogAnimation : MonoBehaviour
{
//String content
[TextArea]
public List<string> content;
//Show speed
public float speed;
//The sound of each letter
public AudioClip sound;
//End button
public Button endbutton;

//Private variables
private int c_ContentIndex;
private Text c_TextComponent;
private int c_LetterCount;
private string c_Content;
private AudioSource c_AudioSource;

/// <summary>
/// Show one letter, this will be called only once to start, the loop will do its thing
/// Instead of invokeRepeating, I think this has more stability and controls.
/// </summary>
/// <returns></returns>
public IEnumerator StartAnimation(int contentIndex)
{
//Clean the Content
c_Content = "";

//For every letter in the content
for(int i = 0; i < c_LetterCount; i++)
{
//Set the speed as normal speed
float c_Speed = speed;
//Set current letter using index
char c_letter = content[contentIndex][i];
//Add letter to the text to display
c_Content += c_letter;
//Refresh the text
c_TextComponent.text = c_Content;

//If the letter is comma, dot or space
switch (c_letter)
{
//Double the wait time if letter is space
case ' ':
c_Speed *= 2;
break;
//Triple the wait time if letter is comma
case ',':
c_Speed *= 3;
break;
//Quad the wait time if letter is dot
case '.':
c_Speed *= 4;
break;
}

//Stop the overlap audio to prevent messy hearing
if (c_AudioSource.isPlaying) c_AudioSource.Stop();
//Play sound once
c_AudioSource.PlayOneShot(sound);

//Wait the interval
yield return new WaitForSeconds(c_Speed);
}
}

/// <summary>
/// Initialize each time its enabled
/// </summary>
public void OnEnable()
{
//Hide the end button
endbutton.gameObject.SetActive(false);

//Set content index
c_ContentIndex = 0;
//Get text component
c_TextComponent = GetComponent<Text>();
//Get the count of letters
c_LetterCount = content[c_ContentIndex].Length;
//Get the audio component
c_AudioSource = FindObjectOfType<AudioSource>();

//Start Animation
StartCoroutine(StartAnimation(c_ContentIndex));
}

/// <summary>
/// Display the content with given index
/// </summary>
/// <param name="contentIndex">Index</param>
public bool DisplayContent(int contentIndex)
{
//Set end button
if (contentIndex >= content.Count || contentIndex < 0)
return false;
if (contentIndex >= content.Count-1)
endbutton.gameObject.SetActive(true);
else
endbutton.gameObject.SetActive(false);

//Stop all animation
StopAllCoroutines();

//Set content index
c_ContentIndex = contentIndex;
//Get text component
c_TextComponent = GetComponent<Text>();
//Get the count of letters
c_LetterCount = content[contentIndex].Length;
//Get the audio component
c_AudioSource = FindObjectOfType<AudioSource>();

//Start Animation
StartCoroutine(StartAnimation(contentIndex));

return true;
}
public void DisplayNextContent() => DisplayContent(c_ContentIndex+1);
public void DisplayPreviousContent() => DisplayContent(c_ContentIndex-1);
}
Loading

0 comments on commit c0ffbbb

Please sign in to comment.