95 lines
1.9 KiB
C#
95 lines
1.9 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections;
|
|
|
|
public class tchat_anim : MonoBehaviour {
|
|
|
|
public Text chat;
|
|
public Animator machine;
|
|
public Text charac_nb;
|
|
public InputField myfield;
|
|
public Text timer;
|
|
float timer_sec;
|
|
int max_timer;
|
|
|
|
|
|
// Use this for initialization
|
|
void Start () {
|
|
|
|
timer_sec = 0;
|
|
max_timer = 15;
|
|
}
|
|
|
|
|
|
void Awake(){
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update () {
|
|
|
|
print (machine.GetInteger("etat_chat"));
|
|
//transition vers chat_up
|
|
if (myfield.textComponent.cachedTextGenerator.lineCount > 1 && machine.GetInteger("etat_chat")==0) {
|
|
print ("trop long");
|
|
machine.SetInteger ("etat_chat", 1);
|
|
charac_nb.text = " ";
|
|
|
|
}
|
|
|
|
//transition vers chat_long
|
|
if (chat.text.Length > 110 && machine.GetInteger("etat_chat")==1) {
|
|
print ("trop trop long");
|
|
machine.SetInteger ("etat_chat", 2);
|
|
}
|
|
|
|
|
|
//affichage nombre de caractère restant.
|
|
if(Input.anyKey && machine.GetInteger("etat_chat")==2 ){
|
|
charac_nb.text = (myfield.characterLimit - myfield.text.Length).ToString();
|
|
}
|
|
|
|
//En cas de validation du message
|
|
if(Input.GetKeyDown("space") && myfield.isFocused){
|
|
|
|
myfield.text="";
|
|
charac_nb.text="";
|
|
print ("space pressed");
|
|
|
|
//texte long
|
|
if(machine.GetInteger("etat_chat")==1 || machine.GetInteger("etat_chat")==2){
|
|
machine.SetInteger ("etat_chat", 3);
|
|
}
|
|
|
|
//texte court
|
|
if(machine.GetInteger("etat_chat")==0){
|
|
machine.SetInteger("etat_chat",3);
|
|
}
|
|
|
|
}
|
|
|
|
//a voir avec des trigger...
|
|
if (machine.GetInteger ("etat_chat") == 3) {
|
|
timer_sec += Time.deltaTime;
|
|
timer.text = (max_timer - timer_sec ).ToString();
|
|
|
|
if(timer_sec == 14){
|
|
timer_sec=0;
|
|
timer.text="";
|
|
}
|
|
|
|
}
|
|
|
|
//on vérifie qu'on est toujours dans chat_down pour un texte court (transition timer->chat_down)
|
|
if (chat.text.Length < 20 && chat.text.Length > 0) {
|
|
machine.SetInteger ("etat_chat", 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|