58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
using System.Collections;
|
|
using DG.Tweening;
|
|
using Mirror;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class NetEmotes : NetworkBehaviour
|
|
{
|
|
public GameObject textEmotePrefab;
|
|
public Transform textEmotesParent;
|
|
|
|
public float textEmoteDuration = 5f;
|
|
public Vector3 textEmoteMovement = new Vector3(0,100,0);
|
|
|
|
public static NetEmotes instance;
|
|
void Awake()
|
|
{
|
|
instance = this;
|
|
}
|
|
|
|
|
|
public void SendTextEmote(string txtName){
|
|
if(isServer){
|
|
RpcSendTextEmote(txtName);
|
|
ShowTextEmote(txtName);
|
|
}else{
|
|
CmdSendTextEmote(txtName);
|
|
}
|
|
}
|
|
|
|
[Command]
|
|
void CmdSendTextEmote(string txtName){
|
|
RpcSendTextEmote(txtName);
|
|
}
|
|
|
|
[ClientRpc]
|
|
void RpcSendTextEmote(string txtName){
|
|
ShowTextEmote(txtName);
|
|
}
|
|
|
|
void ShowTextEmote(string txtName){
|
|
Debug.Log("Showing text emote: " + txtName);
|
|
GameObject textEmote = Instantiate(textEmotePrefab, textEmotesParent);
|
|
textEmote.GetComponentInChildren<TMP_Text>().text = txtName;
|
|
textEmote.transform.localScale = new Vector3(0, 0, 0);
|
|
StartCoroutine(TextEmoteRoutine(textEmote));
|
|
}
|
|
|
|
IEnumerator TextEmoteRoutine(GameObject textEmote){
|
|
textEmote.transform.DOScale(1, 0.5f).SetEase(Ease.OutBack);
|
|
textEmote.transform.DOMove(textEmote.transform.position + textEmoteMovement, textEmoteDuration).SetEase(Ease.OutBack);
|
|
yield return new WaitForSeconds(textEmoteDuration);
|
|
textEmote.transform.DOScale(0, 0.5f).SetEase(Ease.InBack);
|
|
yield return new WaitForSeconds(0.5f);
|
|
Destroy(textEmote);
|
|
}
|
|
}
|