baseposter

BasePoster

This is the class you will be extending if you are to script a custom type of poster.

Contains the poster's id as stated in the json file.

Contains the class name of the class, extending BasePoster, that will be instantiated to manage the poster behaviour and properties.

Contains a reference to the parent mod.

Will contain the sprite name of the thumb image for the poster. Must be located in 'Sprites' folder under the Sprites mod folder.

Will contain the poster thumb Sprite object.

Will contain the poster full size sprite name. Must be located in 'Sprites' folder under the Sprites mod folder.

Will contain the poster Sprite object.

Will contain the id of the achievement set to be fired when using the poster.

Will contain the physical path to the Sprites folder in the local machine.

Will contain the initialization values for custom class properties defined by the user in the custom class extending the BasePoster class.

The Prepare function will be called by the engine when it's needed to render the poster, due to the player having clicked on it. You will have to override this function in your custom poster class in order to perform your custom actions. The posterContainer is provided for you to spawn ui objects in it as you see fit.
Example:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class MYModModPoster : BasePoster
{
	public Text customField;

	public override void InitPoster(BasePoster baseItemData)
	{
		base.InitPoster(baseItemData); 
	}


	public override void Prepare(GameObject posterContainer)
	{        
		base.Prepare(posterContainer);
		//get a reference to the PlayerManager
		PlayerManager playerManager = GameManager.instance.players[0];
		  
		//create a custom text field to hold some data
		UnityEngine.GameObject countDownFieldGo = new UnityEngine.GameObject();
		countDownFieldGo.transform.SetParent(posterContainer.transform);
		RectTransform countdownRect = countDownFieldGo.AddComponent<RectTransform>();
		countdownRect.localScale = new Vector3(1f, 1f, 1f);
		countdownRect.anchoredPosition = new Vector3(0f,-320f,0);
		countdownRect.sizeDelta = new Vector2(500f, 75f);
		countdownRect.pivot = new Vector2(0.5f, 0.5f);

		customField = countDownFieldGo.AddComponent<Text>();
		customField.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
		customField.fontStyle = FontStyle.Normal;
		customField.fontSize = 29;
		customField.lineSpacing = 1;
		customField.supportRichText = true;
		customField.alignment = TextAnchor.MiddleCenter;
		customField.alignByGeometry = true;
		customField.color = Color.black;
		customField.raycastTarget = false;

		//fill textfield with custom data about the player
		customField.text = LocalizationManager.GLV("Hi,") + playerManager.playerName + System.Environment.NewLine;
		customField.text += LocalizationManager.GLV("Your health is: ")+playerManager.healthManager.statValue;
	}
}
{
  "posterId": "mod_poster",
  "posterType": "MYModModPoster",
  "posterSpriteName": "squat_concert_poster.png",
  "posterThumbSpritename" : "squat_concert_poster_thumb.png",
  "extras":[]
}
You could leave a comment if you were logged in.
  • baseposter.txt
  • Last modified: 2019/11/04 11:08
  • by thorfinio