akadoc/Assets/scripts/Gui_CreateScrollList.cs

88 lines
2.2 KiB
C#
Raw Normal View History

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