public override void DrawInspector() { base.DrawInspector(); theAlphabet = EditorGUILayout.ObjectField ("The Alphabet", theAlphabet, typeof(SpriteAlphabet), false) as SpriteAlphabet; EditorGUILayout.Space(); DrawColorChange(); EditorGUILayout.Space(); theString.maxTextSize = renderers.Count; if (GUILayout.Button("Update Randoms", GUILayout.Width(150))) { UpdateRandomCharacters(0.5f); } bool stringChanged = theString.DrawInspector("String", theAlphabet); if (stringChanged) { UpdateText(); } _drawRenderersList = EditorGUILayout.Toggle("Display Renderers", _drawRenderersList); if (_drawRenderersList) { OnDrawRenderers(); } }
public override void OnInspectorGUI() { _target = (SpriteAlphabet)target; _target.DrawInspector(); EditorHelper.SetObjectDirtyIfChanged(_target); }
/// <summary> /// For each character in the string, its index in the given alphabet is found. /// Then assigns the indexes to textIndexes. /// The string manipulation and comparing going on internally is inefficient. /// This should only be used in-game when there is no other choice. /// Usually during design-time this translates designer strings to int arrays /// to be used more efficiently during live gameplay. /// </summary> public void SetIndexesFromString(SpriteAlphabet alphabet, string newString) { char[] charArray = newString.ToCharArray(); // Initialize to be either the max size or shortened to the string's size // Chooses whichever is smaller to guarantee no overflow textIndexes = new int[Mathf.Min(maxTextSize, charArray.Length)]; for (int i = 0; i < textIndexes.Length; i++) { textIndexes[i] = alphabet.GetIndexByChar(charArray[i]); } }
/// <summary> /// Draws a TextField to textIndexes inspector. /// Returns true if the text field has changed. /// </summary> public bool DrawInspector(string title, SpriteAlphabet alphabet) { string oldString = GetStringFromIndexes(alphabet); string newString = EditorGUILayout.TextField(title, oldString); // Nothing changed if (oldString.Equals(newString)) { return(false); } SetIndexesFromString(alphabet, newString); return(true); }
private string GetStringFromIndexes(SpriteAlphabet alphabet) { string theString = ""; if (textIndexes.Length == 0) { return(theString); } for (int i = 0; i < textIndexes.Length && i < maxTextSize; i++) { theString = theString + alphabet.GetCharByIndex_NoRng(textIndexes[i]); } return(theString); }