Now that I had stuff tucked away hidden in the PDA I wanted to let the player know of these a little bit. So I decided to do a simple on screen notify when new to-do list items are added or then new messages arrive.

In-game notification demo

I did not make the in-game notifications automatic though, you still need to send the notify message manually with custom text at the same time as new objectives or messages are added. But I figured this would be fine. I am able to make it fully automatic too if I like. But for now let’s stick to adventure creator action lists!

Adventure Creator did not have a built in action that allows you to change the text of an UI label. I figured I would use a global variable for the text, but it did not seem to work with UI scaling, so I ended up having to write my own custom action. I pasted the code here if you want to do something similar.

Custom action for setting the in-game notification Ui element text trough Adventure Creator
Action_ChangeMenuText
/*
 *
 *	Adventure Creator
 *	by Chris Burton, 2013-2023
 *	
 *	"ActionTemplate.cs"
 * 
 *	This is a blank action template.
 * 
 */

using UnityEngine;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace AC
{

	[System.Serializable]
	public class Action_ChangeMenuText : Action
	{
		public string stringValue;
		public string menuName;
		public string elementName;

		public int labelParameterID = -1;


		// Declare properties here
		public override ActionCategory Category { get { return ActionCategory.Menu; }}
		public override string Title { get { return "Set Label Text"; }}
		public override string Description { get { return "Set the text of a menu element with an action"; }}

		public override void AssignValues(List<ActionParameter> parameters)
        {
			stringValue = AssignString(parameters, labelParameterID, stringValue);
		}

		public override float Run ()
		{
			/* 
			 * This function is called when the action is performed.
			 * 
			 * The float to return is the time that the game
			 * should wait before moving on to the next action.
			 * Return 0f to make the action instantenous.
			 * 
			 * For actions that take longer than one frame,
			 * you can return "defaultPauseTime" to make the game
			 * re-run this function a short time later. You can
			 * use the isRunning boolean to check if the action is
			 * being run for the first time, eg: 
			 */

			MenuLabel notificationlabel = PlayerMenus.GetElementWithName(menuName, elementName) as MenuLabel;
			notificationlabel.label = stringValue;

			if (!isRunning)
			{
				isRunning = true;
				return defaultPauseTime;
			}
			else
			{
				isRunning = false;
				return 0f;
			}
		}


		public override void Skip ()
		{
			/*
			 * This function is called when the Action is skipped, as a
			 * result of the player invoking the "EndCutscene" input.
			 * 
			 * It should perform the instructions of the Action instantly -
			 * regardless of whether or not the Action itself has been run
			 * normally yet.  If this method is left blank, then skipping
			 * the Action will have no effect.  If this method is removed,
			 * or if the Run() method call is left below, then skipping the
			 * Action will cause it to run itself as normal.
			 */

			 Run ();
		}


#if UNITY_EDITOR

		public override void ShowGUI (List<ActionParameter> parameters)
		{
			labelParameterID = Action.ChooseParameterGUI("Label text:", parameters, labelParameterID, new ParameterType[2] { ParameterType.String, ParameterType.PopUp });
			if (labelParameterID < 0)
			{
				stringValue = TextField("Label text: ", stringValue);
			}

			// Action-specific Inspector GUI code here
			// Set the menu name
			EditorGUILayout.BeginHorizontal();
			EditorGUILayout.LabelField("menu", GUILayout.Width(140f));
			EditorStyles.textField.wordWrap = true;
			menuName = TextArea(menuName);
			EditorGUILayout.EndHorizontal();

			EditorGUILayout.BeginHorizontal();
			EditorGUILayout.LabelField("element", GUILayout.Width(140f));
			EditorStyles.textField.wordWrap = true;
			elementName = TextArea(elementName);
			EditorGUILayout.EndHorizontal();
		}

		public void UpdateTranslatableString(int index, string updatedText)
		{
		}

		public override string SetLabel ()
		{
			// (Optional) Return a string used to describe the specific action's job.
			
			return string.Empty;
		}

#endif

	}

}

This component is then used in an action list I can run to show a notification whenever I want. The action list is simple. First it changes the text in the in-game notifications UI to whatever I like, then it displays the in-game notifications UI for 5 seconds. I named this action list “NewNotification”.

In-game notification actionlist in adventure creator

Parameter is used to allow the text to be changed when I run the action list. Adventure Creator makes creating these lists very easy, Once you get the hang of it it allows you to do some pretty complex stuff! Actions lists are a bit like functions in programming. You can have multiple actions inside one and use input variables (parameters) to affect the outcome.

In game notification trigger event in adventure creator action list

After I had the notifications working. I set to work on a simple UI to show them. As these would be in-world notifications I would be making a specific themed UI for these. Not the Echoes Of Somewhere overarching UI style, but these would be in the style of the PDA.

UI setup for the notifications

I went with a very simple top left corner text that is accompanied by the PDA icon. I will be adding animations to this element later to make it stand out even more. Also it will be accompanied by audio that will be different for messages and to-do list items.

Ui setup within Adventure Creator

To get the menu working, I simply dragged the Unity UI text element into the link well in the adventure creator menu label element. Now the label text from this menu would always be displayed in the Unity UI.

I think the PDA turned out great! It is not something that the game absolutely necessary requires, but will be a great tool for world building and keeping track of progress.

Read the part1, where I create the PDA UI. Interface with the help of some AI

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts


Archive


Social Links