public int GetNewId(DialogCollection collection) { var collections = new List<DialogCollection>(); var foundAssets = AssetDatabase.FindAssets("t:" + typeof(DialogCollection).Name); for (var i = 0; i < foundAssets.Length; i++) { var lib = AssetDatabase.LoadAssetAtPath<DialogCollection>(AssetDatabase.GUIDToAssetPath(foundAssets[i])); if (lib != null) { collections.Add(lib); } } var usedIDs = new HashSet<int>(); foreach (var library in collections) { var ids = library.GetUsedIds(); foreach (var id in ids) { usedIDs.Add(id); } } var freeId = _lastUsedDialogId; while (usedIDs.Contains(freeId)) { freeId++; } _lastUsedDialogId = freeId; return freeId; }
/// <summary> /// Gets the next dialog based on the continuing dialog key. /// </summary> /// <returns>The next dialog.</returns> /// <param name="dialogCollection">Dialog collection.</param> public Dialog GetNextDialog(DialogCollection dialogCollection) { /*int lookUpIndex = continuingDialogKeyIndex; * if (dialogCollection.currentDialogIndex <= continuingDialogKeyIndex) { * lookUpIndex += 1; * }*/ return(continues ? dialogCollection.dialogs[continuingDialogKeyIndex] : null); }
public void GetCollection(string collectionID) { if (m_dialogCollections.TryGetValue(collectionID, out m_currentCollection)) { m_currentCollection = m_dialogCollections[collectionID]; m_currentCollectionDialogID = 0; } }
/// <summary> /// Builds an instance of <see cref="DialogCollection"/>. Saves a new dialog collection as an asset. /// </summary> /// <returns>The saved dialog asset containing the dialog collection</returns> public static DialogCollection Build() { // Create an instance of a language collection as an asset, save, and return. DialogCollection dialogsAsset = ScriptableObject.CreateInstance <DialogCollection>(); AssetDatabase.CreateAsset(dialogsAsset, "Assets/Resources/Dialogs.asset"); AssetDatabase.SaveAssets(); return(dialogsAsset); }
void OnEnable() { dialogCollection = Resources.Load("Dialogs") as DialogCollection; if (dialogCollection.dialogs.Count == 0) { // Goofed. Application.Quit(); return; } // Start with the active dialog. currentDialog = dialogCollection.currentDialog; ShowDialog(currentDialog); }
void OnEnable() { dialogCollection = Resources.Load("Dialogs") as DialogCollection; languageCollection = Resources.Load("Localization") as LanguageCollection; // If one hasn't been created yet, build one. if (dialogCollection == null) { dialogCollection = DialogCollectionBuilder.Build(); } // If one hasn't been created yet, build one. if (languageCollection == null) { languageCollection = LanguageCollectionBuilder.Build(); } }
public void ShowDialog(DialogCollection collection, System.Action <DialogPanel> closeAction = null) { // Setup member variables currentDialogs = collection; dialogIndex = 0; OnClose = closeAction; // Update the present text presentText.text = CurrentDialog.Text; presentText.color = characterTextColorMap[CurrentDialog.Character]; // Make time stop game.Pause(); timeLastClicked = Time.time; // Play an animation animator.SetBool(visibleBoolField, true); }
public void Load(string xmlFileName) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(xmlFileName); XmlNodeList nodes = xmlDoc.GetElementsByTagName("flow")[0].ChildNodes; for (int i = 0; i < nodes.Count; i++) { DialogCollection newDialogCollection = new DialogCollection(); XmlNodeList dialogList = nodes[i].ChildNodes; for (int dialogID = 0; dialogID < dialogList.Count; dialogID++) { newDialogCollection.m_actions.Add(new ActionNode(dialogList[dialogID].Name, dialogList[dialogID])); } m_dialogCollections.Add(nodes[i].Attributes["id"].Value, newDialogCollection); } }
public void SetDialog(DialogCollection dialogs) { items = dialogs; speechIndex = 0; }
/// <summary> /// Runs before the game starts /// </summary> private void Awake() { if (Instance != null) { Debug.LogWarning("More than one DialogHandler."); return; } Instance = this; // Initialize the font. dialogFont = Resources.Load <Font>("BLKCHCRY"); // Get the DialogCollection dialogCollection = DialogCollection.GetDialogCollection(); // Create the dialog canvas GameObject //dialogCanvasGo = new GameObject(); dialogCanvasGo = GameObject.Find("HUDCanvas/DialogCanvas"); dialogCanvasGo.name = "DialogCanvas"; dialogCanvasGo.AddComponent <Canvas>(); dialogCanvasGo.AddComponent <CanvasScaler>(); dialogCanvasGo.AddComponent <GraphicRaycaster>(); dialogCanvasGo.AddComponent <CanvasGroup>(); //Get the Canvas from the canvas GameObject dialogCanvas = dialogCanvasGo.GetComponent <Canvas>(); // Set the canvas to render as an overlay (and not, say, a physical in game object) dialogCanvas.renderMode = RenderMode.ScreenSpaceOverlay; // Create the dialog text GameObject dialogTextGo = new GameObject(); dialogTextGo.name = "DialogText"; dialogTextGo.transform.parent = dialogCanvas.transform; dialogText = dialogTextGo.AddComponent <Text>(); // Add some shadow and outline to the text for readability Shadow shadow = dialogTextGo.AddComponent <Shadow>(); shadow.effectDistance = new Vector2(2.0f, -2.0f); Outline outline = dialogTextGo.AddComponent <Outline>(); outline.effectDistance = new Vector2(1.0f, -1.0f); // Set the dialog text components properties dialogText.font = dialogFont; dialogText.fontSize = 36; dialogText.alignment = TextAnchor.UpperCenter; dialogText.verticalOverflow = VerticalWrapMode.Overflow; // Lorem ipsum to show that the text has not been set. dialogText.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed et urna in arcu porta tempus. Cras feugiat scelerisque iaculis."; // Set the dialogtexts position with its rectransform RectTransform rectTransform = dialogText.rectTransform; rectTransform.localPosition = new Vector3(0, 0, 0); rectTransform.sizeDelta = new Vector2(600, 200); // Create the GameObject that holds the option buttons. dialogOptionsGo = new GameObject(); dialogOptionsGo.name = "DialogOptions"; dialogOptionsGo.transform.parent = dialogCanvas.transform; // Position it properly under the dialog text. dialogOptionsGo.transform.localPosition = new Vector3(0, -rectTransform.sizeDelta.y, 0); // Disable the canvas so it's not shown *CONSTANTLY* dialogCanvasGo.SetActive(false); buttonSprite = Resources.Load <Sprite>("SquareSemiTransparent"); }
public void OnResponseClick(Response response, DialogCollection dialogCollection) { updateDisplay = true; currentDialog = response.GetNextDialog(dialogCollection); //dialogCollection.currentDialogIndex = dialogCollection.dialogs.IndexOf(currentDialog); }