added emotes

This commit is contained in:
2026-04-17 16:48:13 +05:30
parent 210722a472
commit 4ba7623b13
2754 changed files with 217704 additions and 1729 deletions
+102
View File
@@ -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)