Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace PowerTools.Quest
- {
- // Add this component to the DialogText prefab and add the fonts you want to use in the 'fonts' list. Then set the id in the character
- public class DialogWithFont: MonoBehaviour, ISpeechGui
- {
- [System.Serializable]
- public class FontStyle
- {
- public Font m_font = null;
- public int m_size = 0;
- }
- // List of available fonts
- [SerializeField] FontStyle[] m_fonts = null;
- TextMesh m_mesh = null;
- QuestText m_questText = null;
- void Awake()
- {
- m_mesh = GetComponent<TextMesh>();
- m_questText = GetComponent<QuestText>();
- }
- public void StartSay(Character character, string text, int currLineId, bool backgroundSpeech)
- {
- if ( m_fonts == null || m_fonts.IsIndexValid(character.FontId) == false )
- return;
- FontStyle style = m_fonts[character.FontId];
- if ( style.m_font != null && style.m_font != m_mesh.font )
- {
- m_mesh.font = style.m_font;
- m_mesh.GetComponent<MeshRenderer>().materials = new Material[] { style.m_font.material };
- if ( style.m_size > 0 )
- m_mesh.fontSize = style.m_size;
- // have to rebuild outline too, hacky since there's no "reset" function
- TextOutline tmp = m_questText.GetOutline();
- m_questText.SetOutline(new TextOutline());
- m_questText.SetOutline(tmp);
- }
- m_questText.SetText(text);
- }
- public void EndSay(Character character)
- {
- }
- }
- public partial interface ICharacter
- {
- // changes the font the character uses for dialog
- int FontId {get;set;}
- }
- public partial class Character
- {
- // Having this as an int or string means you can change it and it'll work with the save system.
- int m_fontId = -1;
- public int FontId { get=>m_fontId; set {m_fontId = value;}}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement