akadoc/Assets/scripts/CreateScrollList.cs
Romain Pellé e0ff9f069a Correction de l'API pour les logs
création de deux méthodes dans la classe CreateScrollList

1) writeMessage qui permet d'afficher un message dans les logs, comme pour ChatWindow. Cette méthode est appelé par TchatAnim.

2) writeNotification qui permet d'envoyer une notification dans les logs. Un nouveau prefab LogNotification a été ajouté. Pour l'instant une notificaiton est envoyé par DayController pour prévenir du début de la phase d'accusation en journée. Comme pour les messages, pour l'instant aucune action ne leur est associé lorsque l'on clique dessus.
2015-01-25 18:05:54 +01:00

87 lines
2.2 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections.Generic;
using System.Collections;
[System.Serializable]
public class Item{
public string name;
public Sprite icon;
public string message;
Button.ButtonClickedEvent clickEvent;
}
[System.Serializable]
public class Notification{
public string message;
Button.ButtonClickedEvent clickEvent;
}
public class CreateScrollList : MonoBehaviour {
public GameObject sampleButton;
public List<Item> itemList;
public Transform contentPanel;
public Image portrait;
public ScrollRect scrollrect;
//public InputField myfield;
GameObject chat_input;
TchatAnim tchatAnim;
string message_old;
//tentative d'ajout des notifications:
public GameObject logNotification;
public List<Notification> notificationList;
// Use this for initialization
void Start () {
//PopulateList ();
chat_input = GameObject.Find ("tchat_complet");
tchatAnim = chat_input.GetComponent<TchatAnim> ();
}
void PopulateList(){
foreach (var item in itemList) {
GameObject newButton = Instantiate (sampleButton) as GameObject;
SampleButton button = newButton.GetComponent <SampleButton> ();
button.nameLabel.text = item.name;
button.icon.sprite = item.icon;
button.message.text = item.message;
newButton.transform.SetParent (contentPanel);
button.gameObject.SetActive(true);
}
}
// Update is called once per frame
void Update () {
}
public void writeMessage(string name, string message){
scrollrect.verticalNormalizedPosition = 0;
GameObject myNewButton = Instantiate (sampleButton) as GameObject;
SampleButton button = myNewButton.GetComponent<SampleButton> ();
button.nameLabel.text= name;
button.message.text = tchatAnim.message;
button.icon.sprite= portrait.sprite;
button.gameObject.SetActive(true);
myNewButton.transform.SetParent(contentPanel);
}
public void writeNotification(string message){
scrollrect.verticalNormalizedPosition = 0;
GameObject myNewButton = Instantiate (logNotification) as GameObject;
LogNotification notif = myNewButton.GetComponent<LogNotification> ();
notif.message.text = message;
myNewButton.transform.SetParent (contentPanel);
}
}