Skip to content

Commit

Permalink
Upload of snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
tmmvn authored Dec 17, 2021
1 parent dab4d91 commit 0f605a9
Show file tree
Hide file tree
Showing 10 changed files with 927 additions and 0 deletions.
50 changes: 50 additions & 0 deletions ACAnnouncer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ACAnnouncer : MonoBehaviour {

public static ACAnnouncer Instance { get; private set; }

public Text text;

public class tickerMessage
{
public string message;
public float timeShown;
public float timeVisible;
}

Queue<tickerMessage> messages;
tickerMessage currentMessage;

void Awake() {
currentMessage = null;
messages = new Queue<tickerMessage> ();
Instance = this;
}

public void pushMessage( tickerMessage message ) {
messages.Enqueue (message);
}

// Update is called once per frame
void Update () {
if (currentMessage != null) {
if (currentMessage.timeVisible >= currentMessage.timeShown) {
currentMessage = null;
text.text = "";
} else {
currentMessage.timeVisible += Time.deltaTime;
}
} else {
if(messages.Count <= 0 )
return;

currentMessage = messages.Dequeue ();
text.text = currentMessage.message;
currentMessage.timeVisible = 0.0f;
}
}
}
53 changes: 53 additions & 0 deletions Announcer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

[RequireComponent(typeof(TextMesh))]
public class Announcer : MonoBehaviour {

public float messageShowTime;
float messageTime;
static Announcer instance;
TextMesh mesh;
Queue<string> messageQueue;

public static Announcer Instance
{
get
{
return instance;
}
}

void Awake()
{
if (instance != null)
{
Debug.LogWarning("Announcer instance already created.");
Destroy(gameObject);
}

instance = this;
mesh = GetComponent<TextMesh>();
messageQueue = new Queue<string>();
}

public void ShowMessage(string message)
{
messageQueue.Enqueue( message );
}

void Update()
{
if (messageTime <= Time.time)
{
if (messageQueue.Count > 0)
{
messageTime = Time.time + messageShowTime;
mesh.text = messageQueue.Dequeue();
}
else
mesh.text = "";
}
}
}
49 changes: 49 additions & 0 deletions CombatText.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CombatText : MonoBehaviour
{
private Camera uiCamera;
private Canvas uiCanvas;
private RectTransform uiCanvasRectTransform;
private Vector3 spawnPos;
private string textShown;

public void SetInitialValues(Vector3 position, string textToShow)
{
spawnPos = position;
textShown = textToShow;
}

/// <summary>
/// Initiate
/// </summary>
void Start ()
{
uiCamera = GameObject.Find("UICamera").GetComponent<Camera>();
uiCanvas = GameObject.Find("CombatTextCanvas").GetComponent<Canvas>();
uiCanvasRectTransform = GameObject.Find("CombatTextCanvas").GetComponent<RectTransform>();
GetComponent<RectTransform>().SetParent(uiCanvasRectTransform, false);
GetComponent<Text>().text = textShown;
}

/// <summary>
/// Move the UI element to the world position
/// </summary>
/// <param name="objectTransformPosition"></param>
void LateUpdate()
{
Vector3 viewPos = uiCamera.WorldToViewportPoint(spawnPos);
GetComponent<RectTransform>().anchoredPosition = new Vector2(viewPos.x * uiCanvas.pixelRect.width, viewPos.y * uiCanvas.pixelRect.height);
spawnPos.y += Time.deltaTime;
var a = GetComponent<Text>().color;
a.a -= Time.deltaTime;

if(a.a <= 0.0f)
Destroy(gameObject);
else
GetComponent<Text>().color = a;
}
}
22 changes: 22 additions & 0 deletions MenuFloat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using UnityEngine;
using System.Collections;

public class MenuFloat : MonoBehaviour {

public float yDifference;
public float ySpeed;
Transform myTransform;
float yStart;

void Start()
{
myTransform = transform;
yStart = myTransform.position.y;
}
void Update()
{
Vector3 position = myTransform.position;
position.y = yStart + Mathf.Sin(Time.time * ySpeed * yDifference);
myTransform.position = position;
}
}
72 changes: 72 additions & 0 deletions SpeechBubble.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using UnityEngine;
using System.Collections;

public class SpeechBubble : MonoBehaviour
{
Transform myTransform;
Vector3 screenPos;
Vector3 viewportPos;

public int bubbleWidth = 200;
public int bubbleHeight = 100;
public float padding = 10;
public float offsetX = 0;
public float offsetY = 150;

int centerOffsetX;
int centerOffsetY;

public Material mat;
public GUISkin guiSkin;
public Camera cameraToUse;
public string shownText;

void Awake()
{
myTransform = transform;
}

//use this for initialization
void Start()
{
//Calculate the X and Y offsets to center the speech balloon exactly on the center of the game object
centerOffsetX = bubbleWidth / 2;
centerOffsetY = bubbleHeight / 2;
}

void LateUpdate()
{
screenPos = cameraToUse.WorldToScreenPoint(myTransform.position);

viewportPos.x = screenPos.x / (float)Screen.width;
viewportPos.y = screenPos.y / (float)Screen.height;
}

void OnGUI()
{
//Begin the GUI group centering the speech bubble at the same position of this game object. After that, apply the offset
GUI.BeginGroup(new Rect(screenPos.x - centerOffsetX - offsetX, Screen.height - screenPos.y - centerOffsetY - offsetY, bubbleWidth, bubbleHeight));

//Render the round part of the bubble
GUI.Label(new Rect(0, 0, bubbleWidth, bubbleHeight), "", guiSkin.customStyles[0]);

//Render the text
GUI.Label(new Rect(padding, padding, bubbleWidth - padding, bubbleHeight - padding), shownText, guiSkin.label);

GUI.EndGroup();
}

void OnRenderObject()
{
GL.PushMatrix();
mat.SetPass(0);
GL.LoadOrtho();
GL.Begin(GL.TRIANGLES);
GL.Color(Color.white);
GL.Vertex3(viewportPos.x, viewportPos.y + (offsetY / 3) / Screen.height, 0.1f);
GL.Vertex3(viewportPos.x - (bubbleWidth / 3) / (float)Screen.width, viewportPos.y + offsetY / Screen.height, 0.1f);
GL.Vertex3(viewportPos.x - (bubbleWidth / 8) / (float)Screen.width, viewportPos.y + offsetY / Screen.height, 0.1f);
GL.End();
GL.PopMatrix();
}
}
17 changes: 17 additions & 0 deletions UIScaler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using UnityEngine;
using System.Collections;

public class UIScaler : MonoBehaviour {

public static float uiScaleWidth { get; private set; }
public static float uiScaleHeight { get; private set; }
public static float uiScale { get; private set; }

void Awake()
{
uiScaleWidth = Screen.width / 800.0f;
uiScaleHeight = Screen.height / 480.0f;
uiScale = uiScaleWidth / uiScaleHeight;
transform.localScale = new Vector3(uiScaleWidth, uiScaleHeight, uiScale);
}
}
36 changes: 36 additions & 0 deletions fbt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class fbt : MonoBehaviour {

public float duration;
public float speed;
public Text textmessage;

float startY;
float playingtime;

void Start() {
startY = transform.position.y;
}

public void Play(string message) {
textmessage.text = message;
playingtime = duration;
Vector3 oldpos = transform.position;
oldpos.y = startY;
transform.position = oldpos;
}

void Update () {
if (playingtime > 0.0f) {
Vector3 oldpos = transform.position;
oldpos.y += speed * Time.deltaTime;
transform.position = oldpos;
playingtime -= Time.deltaTime;
if (playingtime <= 0.0f)
textmessage.text = "";
}
}
}
Loading

0 comments on commit 0f605a9

Please sign in to comment.