From e0ff9f069ae89f5bd52e77a4ce40a88075faf7c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Pell=C3=A9?= Date: Sun, 25 Jan 2015 18:05:54 +0100 Subject: [PATCH] Correction de l'API pour les logs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- Assets/prefabs/LogNotification.prefab | 216 +++++++++++++++++++++ Assets/prefabs/LogNotification.prefab.meta | 4 + Assets/scene.unity | 4 +- Assets/scripts/ChatWindow.cs | 17 +- Assets/scripts/CreateScrollList.cs | 48 +++-- Assets/scripts/DayController.cs | 8 + Assets/scripts/LogNotification.cs | 9 + Assets/scripts/LogNotification.cs.meta | 8 + Assets/scripts/TchatAnim.cs | 15 +- 9 files changed, 292 insertions(+), 37 deletions(-) create mode 100644 Assets/prefabs/LogNotification.prefab create mode 100644 Assets/prefabs/LogNotification.prefab.meta create mode 100644 Assets/scripts/LogNotification.cs create mode 100644 Assets/scripts/LogNotification.cs.meta diff --git a/Assets/prefabs/LogNotification.prefab b/Assets/prefabs/LogNotification.prefab new file mode 100644 index 0000000..f4d8d49 --- /dev/null +++ b/Assets/prefabs/LogNotification.prefab @@ -0,0 +1,216 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &100000 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 4 + m_Component: + - 224: {fileID: 22400000} + - 222: {fileID: 22200000} + - 114: {fileID: 11400004} + m_Layer: 5 + m_Name: message + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!1 &100002 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 4 + m_Component: + - 224: {fileID: 22400002} + - 222: {fileID: 22200002} + - 114: {fileID: 11400008} + - 114: {fileID: 11400006} + - 114: {fileID: 11400002} + - 114: {fileID: 11400000} + m_Layer: 5 + m_Name: LogNotification + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 100002} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c83607d8812e5a74495cf9db277c299c, type: 3} + m_Name: + m_EditorClassIdentifier: + message: {fileID: 11400004} +--- !u!114 &11400002 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 100002} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 1679637790, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} + m_Name: + m_EditorClassIdentifier: + m_IgnoreLayout: 0 + m_MinWidth: -1 + m_MinHeight: 60 + m_PreferredWidth: -1 + m_PreferredHeight: -1 + m_FlexibleWidth: -1 + m_FlexibleHeight: -1 +--- !u!114 &11400004 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 100000} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 708705254, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_FontData: + m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + m_FontSize: 20 + m_FontStyle: 0 + m_BestFit: 0 + m_MinSize: 10 + m_MaxSize: 40 + m_Alignment: 4 + m_RichText: 1 + m_HorizontalOverflow: 0 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: Bonjour c'est moi!!! +--- !u!114 &11400006 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 100002} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 1392445389, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 3 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 1 + m_Colors: + m_NormalColor: {r: .588235259, g: .248240069, b: .233564019, a: 1} + m_HighlightedColor: {r: .960784316, g: .960784316, b: .960784316, a: 1} + m_PressedColor: {r: .784313738, g: .784313738, b: .784313738, a: 1} + m_DisabledColor: {r: .784313738, g: .784313738, b: .784313738, a: .501960814} + m_ColorMultiplier: 1 + m_FadeDuration: .100000001 + m_SpriteState: + m_HighlightedSprite: {fileID: 0} + m_PressedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 11400008} + m_OnClick: + m_PersistentCalls: + m_Calls: [] + m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, + Culture=neutral, PublicKeyToken=null +--- !u!114 &11400008 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 100002} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: -765806418, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0} + m_Type: 1 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 +--- !u!222 &22200000 +CanvasRenderer: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 100000} +--- !u!222 &22200002 +CanvasRenderer: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 100002} +--- !u!224 &22400000 +RectTransform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 100000} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 22400002} + m_RootOrder: 0 + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: .5, y: .5} +--- !u!224 &22400002 +RectTransform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 100002} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 22400000} + m_Father: {fileID: 0} + m_RootOrder: 0 + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: .5, y: .5} +--- !u!1001 &100100000 +Prefab: + m_ObjectHideFlags: 1 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: [] + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 0} + m_RootGameObject: {fileID: 100002} + m_IsPrefabParent: 1 + m_IsExploded: 1 diff --git a/Assets/prefabs/LogNotification.prefab.meta b/Assets/prefabs/LogNotification.prefab.meta new file mode 100644 index 0000000..d4fa94b --- /dev/null +++ b/Assets/prefabs/LogNotification.prefab.meta @@ -0,0 +1,4 @@ +fileFormatVersion: 2 +guid: 6e871277765bcd14dafac073d9775a42 +NativeFormatImporter: + userData: diff --git a/Assets/scene.unity b/Assets/scene.unity index fcfb447..ffce3c1 100644 --- a/Assets/scene.unity +++ b/Assets/scene.unity @@ -27282,7 +27282,7 @@ GameObject: - 4: {fileID: 2022993159} - 114: {fileID: 2022993158} m_Layer: 0 - m_Name: GameController + m_Name: log_controller m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -27304,6 +27304,8 @@ MonoBehaviour: contentPanel: {fileID: 1593353186} portrait: {fileID: 235015811} scrollrect: {fileID: 737082149} + logNotification: {fileID: 100002, guid: 6e871277765bcd14dafac073d9775a42, type: 2} + notificationList: [] --- !u!4 &2022993159 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/scripts/ChatWindow.cs b/Assets/scripts/ChatWindow.cs index 1695611..c9e6a95 100644 --- a/Assets/scripts/ChatWindow.cs +++ b/Assets/scripts/ChatWindow.cs @@ -7,32 +7,17 @@ public class ChatWindow : MonoBehaviour { public Text text_chat; public ScrollRect scrollrect; - //GameObject chat_input; - //TchatAnim tchatAnim; string message_old; // Use this for initialization void Start () { - - //chat_input = GameObject.Find ("tchat_complet"); - //tchatAnim = chat_input.GetComponent (); text_chat.text = ""; } // Update is called once per frame - void Update () { - - - /* a supp une fois le nouveau système de message fonctionelle - if (Input.GetKeyDown ("space") && tchatAnim.message != message_old) { - - scrollrect.verticalNormalizedPosition = 0; - text_chat.text += "perceval > " + tchatAnim.message + "\n"; - message_old= tchatAnim.message; - }*/ - + void Update () { } diff --git a/Assets/scripts/CreateScrollList.cs b/Assets/scripts/CreateScrollList.cs index 514c355..7c9bba5 100644 --- a/Assets/scripts/CreateScrollList.cs +++ b/Assets/scripts/CreateScrollList.cs @@ -12,6 +12,12 @@ public class Item{ Button.ButtonClickedEvent clickEvent; } +[System.Serializable] +public class Notification{ + public string message; + Button.ButtonClickedEvent clickEvent; +} + public class CreateScrollList : MonoBehaviour { public GameObject sampleButton; @@ -24,10 +30,13 @@ public class CreateScrollList : MonoBehaviour { TchatAnim tchatAnim; string message_old; + //tentative d'ajout des notifications: + public GameObject logNotification; + public List notificationList; // Use this for initialization void Start () { - PopulateList (); + //PopulateList (); chat_input = GameObject.Find ("tchat_complet"); tchatAnim = chat_input.GetComponent (); @@ -51,21 +60,28 @@ public class CreateScrollList : MonoBehaviour { // Update is called once per frame void Update () { - - scrollrect.verticalNormalizedPosition = 0; - - if (Input.GetKeyDown ("space")&& tchatAnim.message != message_old) { - GameObject myNewButton = Instantiate (sampleButton) as GameObject; - SampleButton button = myNewButton.GetComponent (); - button.nameLabel.text="perceval"; - button.message.text = tchatAnim.message; - button.icon.sprite= portrait.sprite; - button.gameObject.SetActive(true); - myNewButton.transform.SetParent(contentPanel); - - message_old= tchatAnim.message; - - } } + + public void writeMessage(string name, string message){ + + scrollrect.verticalNormalizedPosition = 0; + GameObject myNewButton = Instantiate (sampleButton) as GameObject; + SampleButton button = myNewButton.GetComponent (); + 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 (); + notif.message.text = message; + myNewButton.transform.SetParent (contentPanel); + } } diff --git a/Assets/scripts/DayController.cs b/Assets/scripts/DayController.cs index ccb2627..cdfc482 100644 --- a/Assets/scripts/DayController.cs +++ b/Assets/scripts/DayController.cs @@ -17,6 +17,9 @@ public class DayController : MonoBehaviour { GameObject chatWindowScroll; ChatWindow chatWindow; + //appel de CreateScrollList + GameObject createScrollListObject; + CreateScrollList createScrollList; // Use this for initialization @@ -31,6 +34,10 @@ public class DayController : MonoBehaviour { chatWindowScroll = GameObject.Find ("ChatWindowScroll"); chatWindow = chatWindowScroll.GetComponent (); + //appel de CreateScrollList + createScrollListObject = GameObject.Find ("log_controller"); + createScrollList = createScrollListObject.GetComponent (); + dayNb = 1; chatWindow.writeDay (dayNb); @@ -46,6 +53,7 @@ public class DayController : MonoBehaviour { if (timer >= (float)maxDiscussion){ machine.SetInteger("day_status",1); print("Accusation!"); + createScrollList.writeNotification("Denoncez-vous, pauvres fous!!!"); } else{ diff --git a/Assets/scripts/LogNotification.cs b/Assets/scripts/LogNotification.cs new file mode 100644 index 0000000..828ec60 --- /dev/null +++ b/Assets/scripts/LogNotification.cs @@ -0,0 +1,9 @@ +using UnityEngine; +using System.Collections; +using UnityEngine.UI; + +public class LogNotification : MonoBehaviour { + + public Text message; + +} diff --git a/Assets/scripts/LogNotification.cs.meta b/Assets/scripts/LogNotification.cs.meta new file mode 100644 index 0000000..fc01160 --- /dev/null +++ b/Assets/scripts/LogNotification.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c83607d8812e5a74495cf9db277c299c +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/scripts/TchatAnim.cs b/Assets/scripts/TchatAnim.cs index b454032..1611736 100644 --- a/Assets/scripts/TchatAnim.cs +++ b/Assets/scripts/TchatAnim.cs @@ -13,21 +13,27 @@ public class TchatAnim : MonoBehaviour { int max_timer; public string message; - //appel de Window Chat + //appel de WindowChat GameObject chatWindowScroll; ChatWindow chatWindow; - + //appel de TchatAnim + GameObject createScrollListObject; + CreateScrollList createScrollList; // Use this for initialization void Start () { timer_sec = 0; max_timer = 15; - //appel de Window Chat + //appel de WindowChat chatWindowScroll = GameObject.Find ("ChatWindowScroll"); chatWindow = chatWindowScroll.GetComponent (); + //appel de CreateScrollList + createScrollListObject = GameObject.Find ("log_controller"); + createScrollList = createScrollListObject.GetComponent (); + } @@ -93,7 +99,8 @@ public class TchatAnim : MonoBehaviour { //En cas de validation du message if(Input.GetKeyDown("space") && myfield.isFocused){ - chatWindow.writeMessage("perceval",myfield.text); + chatWindow.writeMessage("perceval",myfield.text); //inscription du message dans la fenetre de chat + createScrollList.writeMessage("perceval", myfield.text); //inscription du message dans les logs. myfield.gameObject.SetActive(false); myfield.text=" "; charac_nb.text="";