added emotes
This commit is contained in:
@@ -21,6 +21,7 @@ public class GameCanvas : MonoBehaviour
|
||||
instance = this;
|
||||
|
||||
ShowWaitingForOpponentPanel();
|
||||
HideEmotesPanel();
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
@@ -44,17 +45,118 @@ public class GameCanvas : MonoBehaviour
|
||||
public GameObject timeoutForOpponentPanel;
|
||||
public Button btnLeaveGame;
|
||||
|
||||
[Header("Emotes")]
|
||||
public Button btnEmote;
|
||||
public Transform emotesPanel;
|
||||
public Transform textEmotesParent;
|
||||
public Transform emojiEmotesParent;
|
||||
public GameObject textEmotePrefab;
|
||||
public Transform EmoteSpawnRed, EmoteSpawnBlue;
|
||||
public Vector3 textEmoteMovement = new Vector3(0,100,0);
|
||||
public Vector3 emojiEmoteMovement = new Vector3(0,100,0);
|
||||
public float textEmoteDuration = 5f;
|
||||
public float emojiEmoteDuration = 5f;
|
||||
bool isShowingEmotes=> emotesPanel.gameObject.activeSelf;
|
||||
|
||||
|
||||
|
||||
void Start(){
|
||||
if (btnLeaveGame != null)
|
||||
btnLeaveGame.onClick.AddListener(OnLeaveGamePressed);
|
||||
|
||||
if(btnEmote != null)
|
||||
btnEmote.onClick.AddListener(OnEmotePressed);
|
||||
|
||||
if(textEmotesParent != null){
|
||||
for(int i=0; i<textEmotesParent.childCount; i++){
|
||||
string txtName = textEmotesParent.GetChild(i).GetComponentInChildren<TMP_Text>().text;
|
||||
textEmotesParent.GetChild(i).GetComponent<Button>().onClick.AddListener(() => OnEmoteTextPressed(txtName));
|
||||
}
|
||||
}
|
||||
|
||||
if(emojiEmotesParent != null){
|
||||
for(int i=0; i<emojiEmotesParent.childCount; i++){
|
||||
int index = i;
|
||||
emojiEmotesParent.GetChild(i).GetComponent<Button>().onClick.AddListener(() => OnEmojiPressed(index));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
redName.text = GameManager.RedPlayer.Name;
|
||||
blueName.text = GameManager.BluePlayer.Name;
|
||||
|
||||
}
|
||||
|
||||
void OnEmoteTextPressed(string txtName){
|
||||
Debug.Log("OnEmoteTextPressed: " + txtName);
|
||||
HideEmotesPanel();
|
||||
NetPlayer.localPlayer.SendTextEmote(txtName);
|
||||
}
|
||||
|
||||
void OnEmojiPressed(int id){
|
||||
Debug.Log("OnEmojiPressed: " + id);
|
||||
HideEmotesPanel();
|
||||
NetPlayer.localPlayer.SendEmojiEmote(id);
|
||||
}
|
||||
|
||||
public void ShowTextEmote(string txtName, Team team){
|
||||
Debug.Log("Showing text emote: " + txtName +" from " + team);
|
||||
GameObject textEmote = Instantiate(textEmotePrefab, team == Team.Red ? EmoteSpawnRed : EmoteSpawnBlue);
|
||||
Destroy(textEmote.GetComponent<Button>());
|
||||
textEmote.transform.localPosition = Vector3.zero;
|
||||
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);
|
||||
}
|
||||
|
||||
public void ShowEmojiEmote(int id, Team team){
|
||||
Debug.Log("Showing emoji emote: " + id);
|
||||
GameObject emojiEmote = Instantiate(emojiEmotesParent.GetChild(id).gameObject, team == Team.Red ? EmoteSpawnRed : EmoteSpawnBlue);
|
||||
Destroy(emojiEmote.GetComponent<Button>());
|
||||
emojiEmote.transform.localPosition = Vector3.zero;
|
||||
emojiEmote.transform.localScale = new Vector3(0, 0, 0);
|
||||
StartCoroutine(EmojiEmoteRoutine(emojiEmote));
|
||||
}
|
||||
|
||||
IEnumerator EmojiEmoteRoutine(GameObject emojiEmote){
|
||||
emojiEmote.transform.DOScale(1, 0.5f).SetEase(Ease.OutBack);
|
||||
emojiEmote.transform.DOMove(emojiEmote.transform.position + emojiEmoteMovement, emojiEmoteDuration).SetEase(Ease.OutBack);
|
||||
yield return new WaitForSeconds(emojiEmoteDuration);
|
||||
emojiEmote.transform.DOScale(0, 0.5f).SetEase(Ease.InBack);
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
Destroy(emojiEmote);
|
||||
}
|
||||
|
||||
void OnEmotePressed()
|
||||
{
|
||||
if(isShowingEmotes){
|
||||
HideEmotesPanel();
|
||||
}else{
|
||||
ShowEmotesPanel();
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowEmotesPanel(){
|
||||
emotesPanel.gameObject.SetActive(true);
|
||||
emotesPanel.localScale = new Vector3(0, 0, 0);
|
||||
emotesPanel.DOScale(1, 0.2f).SetEase(Ease.OutBack);
|
||||
}
|
||||
|
||||
public void HideEmotesPanel(){
|
||||
emotesPanel.DOScale(0, 0.25f).SetEase(Ease.InBack).OnComplete(() => {
|
||||
emotesPanel.gameObject.SetActive(false);
|
||||
});
|
||||
}
|
||||
|
||||
void OnLeaveGamePressed()
|
||||
{
|
||||
if (CupidLobby.instance != null)
|
||||
|
||||
@@ -605,10 +605,27 @@ public class GameManager : NetworkBehaviour
|
||||
IEnumerator CoroutineGameOver(Team team){
|
||||
yield return new WaitForSeconds(2f);
|
||||
yield return CoroutineFetchBothPlayersL10();
|
||||
|
||||
StopClient();
|
||||
|
||||
LevelLoadManager.instance.SetupGameOver(team,redScore,blueScore);
|
||||
LevelLoadManager.LoadLevel("MainMenu");
|
||||
}
|
||||
|
||||
public void Leave(){
|
||||
StopClient();
|
||||
LevelLoadManager.LoadLevel("MainMenu");
|
||||
}
|
||||
|
||||
|
||||
void StopClient(){
|
||||
try{
|
||||
NetworkManager.singleton.StopClient();
|
||||
}catch(Exception e){
|
||||
Logger.Log("Error stopping client: " + e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator CoroutineFetchBothPlayersL10()
|
||||
{
|
||||
var my = LevelLoadManager.myPlayer;
|
||||
|
||||
@@ -124,7 +124,7 @@ public class LoginManager : MonoBehaviour
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
static bool EditorWorkspaceLooksLikeClone()
|
||||
public static bool EditorWorkspaceLooksLikeClone()
|
||||
{
|
||||
// Project folder is parent of Assets (same as editor project path).
|
||||
string projectRoot = Path.GetDirectoryName(Application.dataPath);
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d17e1ac28f957254795443173835b577
|
||||
@@ -10,9 +10,20 @@ public class NetPlayer : NetworkBehaviour
|
||||
public override void OnStartLocalPlayer()
|
||||
{
|
||||
base.OnStartLocalPlayer();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// Count current NetPlayers in the scene
|
||||
|
||||
SetMyTeam(GameManager.MyTeam);
|
||||
if(Cupid.RoomPort == -1){
|
||||
//Without cupid, set the team to red
|
||||
bool cloneWorkspace = LoginManager.EditorWorkspaceLooksLikeClone();
|
||||
SetMyTeam(cloneWorkspace ? Team.Red : Team.Blue);
|
||||
|
||||
}else{
|
||||
SetMyTeam(GameManager.MyTeam);
|
||||
}
|
||||
#else
|
||||
SetMyTeam(GameManager.MyTeam);
|
||||
#endif
|
||||
TeamSpecificEffects.instance.SetTeamSpecificEffects(myTeam);
|
||||
}
|
||||
|
||||
@@ -42,6 +53,56 @@ public class NetPlayer : NetworkBehaviour
|
||||
public Vector2 startPosition;
|
||||
public float curPuckPullForce;
|
||||
|
||||
#region EMOTES
|
||||
public void SendTextEmote(string txtName){
|
||||
if(isServer){
|
||||
RpcSendTextEmote(txtName);
|
||||
ShowTextEmote(txtName);
|
||||
}else{
|
||||
CmdSendTextEmote(txtName);
|
||||
}
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdSendTextEmote(string txtName){
|
||||
RpcSendTextEmote(txtName);
|
||||
ShowTextEmote(txtName);
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcSendTextEmote(string txtName){
|
||||
ShowTextEmote(txtName);
|
||||
}
|
||||
|
||||
void ShowTextEmote(string txtName){
|
||||
GameCanvas.instance.ShowTextEmote(txtName, myTeam);
|
||||
}
|
||||
|
||||
|
||||
public void SendEmojiEmote(int id){
|
||||
if(isServer){
|
||||
RpcSendEmojiEmote(id);
|
||||
ShowEmojiEmote(id);
|
||||
}else{
|
||||
CmdSendEmojiEmote(id);
|
||||
}
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdSendEmojiEmote(int id){
|
||||
RpcSendEmojiEmote(id);
|
||||
ShowEmojiEmote(id);
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcSendEmojiEmote(int id){
|
||||
ShowEmojiEmote(id);
|
||||
}
|
||||
|
||||
void ShowEmojiEmote(int id){
|
||||
GameCanvas.instance.ShowEmojiEmote(id, myTeam);
|
||||
}
|
||||
#endregion
|
||||
|
||||
void Start(){
|
||||
if(isLocalPlayer){
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
[ExecuteAlways]
|
||||
public class FrameAnimator : MonoBehaviour
|
||||
{
|
||||
public Sprite[] sprites;
|
||||
public float frameRate = 10f;
|
||||
|
||||
public bool preview;
|
||||
public bool isPlaying = false;
|
||||
public bool loop = true;
|
||||
public int currentFrame = 0;
|
||||
|
||||
float m_frameTimer = 0f;
|
||||
bool m_previewPlaying = false;
|
||||
#if UNITY_EDITOR
|
||||
double m_lastEditorTime = 0d;
|
||||
#endif
|
||||
Image m_img;
|
||||
Image img {
|
||||
get{
|
||||
if(m_img==null){
|
||||
m_img= GetComponent<Image>();
|
||||
}
|
||||
return m_img;
|
||||
}
|
||||
}
|
||||
|
||||
void OnValidate()
|
||||
{
|
||||
if(preview)
|
||||
{
|
||||
preview=false;
|
||||
StartPreviewOnce();
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
m_lastEditorTime = EditorApplication.timeSinceStartup;
|
||||
EditorApplication.update -= OnEditorUpdate;
|
||||
EditorApplication.update += OnEditorUpdate;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EditorApplication.update -= OnEditorUpdate;
|
||||
#endif
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
if (sprites == null || sprites.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
currentFrame = Mathf.Clamp(currentFrame, 0, sprites.Length - 1);
|
||||
ApplyCurrentFrame();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TickAnimation(Time.deltaTime);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void OnEditorUpdate()
|
||||
{
|
||||
if (Application.isPlaying || this == null || !isActiveAndEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
double now = EditorApplication.timeSinceStartup;
|
||||
float dt = (float)(now - m_lastEditorTime);
|
||||
m_lastEditorTime = now;
|
||||
|
||||
if (dt <= 0f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TickAnimation(dt);
|
||||
EditorApplication.QueuePlayerLoopUpdate();
|
||||
}
|
||||
#endif
|
||||
|
||||
void TickAnimation(float deltaTime)
|
||||
{
|
||||
if (frameRate <= 0f || sprites == null || sprites.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool shouldAnimate = m_previewPlaying || isPlaying;
|
||||
if (!shouldAnimate)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_frameTimer += deltaTime;
|
||||
float frameDuration = 1f / frameRate;
|
||||
|
||||
while (m_frameTimer >= frameDuration)
|
||||
{
|
||||
m_frameTimer -= frameDuration;
|
||||
if (m_previewPlaying)
|
||||
{
|
||||
AdvancePreviewFrame();
|
||||
}
|
||||
else
|
||||
{
|
||||
AdvanceFrame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Play(bool restart = false)
|
||||
{
|
||||
if (sprites == null || sprites.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (restart)
|
||||
{
|
||||
currentFrame = 0;
|
||||
m_frameTimer = 0f;
|
||||
ApplyCurrentFrame();
|
||||
}
|
||||
|
||||
isPlaying = true;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
isPlaying = false;
|
||||
m_frameTimer = 0f;
|
||||
}
|
||||
|
||||
public void ResetToFirstFrame()
|
||||
{
|
||||
currentFrame = 0;
|
||||
m_frameTimer = 0f;
|
||||
ApplyCurrentFrame();
|
||||
}
|
||||
|
||||
void StartPreviewOnce()
|
||||
{
|
||||
if (sprites == null || sprites.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
isPlaying = false;
|
||||
m_previewPlaying = true;
|
||||
m_frameTimer = 0f;
|
||||
currentFrame = 0;
|
||||
ApplyCurrentFrame();
|
||||
}
|
||||
|
||||
void AdvancePreviewFrame()
|
||||
{
|
||||
currentFrame++;
|
||||
if (currentFrame >= sprites.Length)
|
||||
{
|
||||
currentFrame = sprites.Length - 1;
|
||||
m_previewPlaying = false;
|
||||
}
|
||||
|
||||
ApplyCurrentFrame();
|
||||
}
|
||||
|
||||
void AdvanceFrame()
|
||||
{
|
||||
currentFrame++;
|
||||
|
||||
if (currentFrame >= sprites.Length)
|
||||
{
|
||||
if (loop)
|
||||
{
|
||||
currentFrame = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentFrame = sprites.Length - 1;
|
||||
isPlaying = false;
|
||||
}
|
||||
}
|
||||
|
||||
ApplyCurrentFrame();
|
||||
}
|
||||
|
||||
void ApplyCurrentFrame()
|
||||
{
|
||||
if (img == null || sprites == null || sprites.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
currentFrame = Mathf.Clamp(currentFrame, 0, sprites.Length - 1);
|
||||
img.sprite = sprites[currentFrame];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b861af9d256faea40b17dd89fad46ee6
|
||||
Reference in New Issue
Block a user