diff --git a/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Editor/FormattableTextMeshProEditorPanel.cs b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Editor/FormattableTextMeshProEditorPanel.cs new file mode 100644 index 00000000..b4a27ce6 --- /dev/null +++ b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Editor/FormattableTextMeshProEditorPanel.cs @@ -0,0 +1,87 @@ +/* + * MIT License + * + * Copyright (c) 2018 Clark Yang + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +using TMPro.EditorUtilities; +using UnityEditor; +using UnityEngine; + +namespace Loxodon.Framework.Views.TextMeshPro.Editor +{ + [CustomEditor(typeof(FormattableTextMeshPro), true), CanEditMultipleObjects] + public class FormattableTextMeshProEditorPanel : TMP_EditorPanel + { + static readonly GUIContent k_FormatLabel = new GUIContent("Format", "text formatting"); + static readonly GUIContent k_ParameterCountLabel = new GUIContent("Parameter Count", "Parameter Count"); + + SerializedProperty m_FormatProp; + SerializedProperty m_ParameterCountProp; + + protected override void OnEnable() + { + base.OnEnable(); + m_FormatProp = serializedObject.FindProperty("m_Format"); + m_ParameterCountProp = serializedObject.FindProperty("m_ParameterCount"); + } + + public override void OnInspectorGUI() + { + // Make sure Multi selection only includes TMP Text objects. + if (IsMixSelectionTypes()) return; + + serializedObject.Update(); + + DrawFormatParameters(); + + DrawMainSettings(); + + DrawExtraSettings(); + + EditorGUILayout.Space(); + + if (serializedObject.ApplyModifiedProperties() || m_HavePropertiesChanged) + { + m_TextComponent.havePropertiesChanged = true; + m_HavePropertiesChanged = false; + EditorUtility.SetDirty(target); + } + } + + protected void DrawFormatParameters() + { + EditorGUI.BeginChangeCheck(); + EditorGUILayout.PropertyField(m_FormatProp, k_FormatLabel); + if (EditorGUI.EndChangeCheck()) + { + m_HavePropertiesChanged = true; + } + + EditorGUI.BeginChangeCheck(); + EditorGUILayout.PropertyField(m_ParameterCountProp, k_ParameterCountLabel); + if (EditorGUI.EndChangeCheck()) + { + m_HavePropertiesChanged = true; + } + } + } +} diff --git a/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Editor/FormattableTextMeshProEditorPanel.cs.meta b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Editor/FormattableTextMeshProEditorPanel.cs.meta new file mode 100644 index 00000000..fa2cb9ba --- /dev/null +++ b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Editor/FormattableTextMeshProEditorPanel.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4f1081399855f474f8ba0dafd5d092a5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Editor/FormattableTextMeshProUIEditorPanel.cs b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Editor/FormattableTextMeshProUIEditorPanel.cs index a708bb93..0df49f34 100644 --- a/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Editor/FormattableTextMeshProUIEditorPanel.cs +++ b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Editor/FormattableTextMeshProUIEditorPanel.cs @@ -22,29 +22,24 @@ * SOFTWARE. */ -using TMPro; using TMPro.EditorUtilities; using UnityEditor; using UnityEngine; -using UnityEngine.UI; namespace Loxodon.Framework.Views.TextMeshPro.Editor { [CustomEditor(typeof(FormattableTextMeshProUGUI), true), CanEditMultipleObjects] - public class FormattableTextMeshProUIEditorPanel : TMP_BaseEditorPanel + public class FormattableTextMeshProUIEditorPanel : TMP_EditorPanelUI { - static readonly GUIContent k_RaycastTargetLabel = new GUIContent("Raycast Target", "Whether the text blocks raycasts from the Graphic Raycaster."); static readonly GUIContent k_FormatLabel = new GUIContent("Format", "text formatting"); static readonly GUIContent k_ParameterCountLabel = new GUIContent("Parameter Count", "Parameter Count"); - SerializedProperty m_RaycastTargetProp; SerializedProperty m_FormatProp; SerializedProperty m_ParameterCountProp; protected override void OnEnable() { base.OnEnable(); - m_RaycastTargetProp = serializedObject.FindProperty("m_RaycastTarget"); m_FormatProp = serializedObject.FindProperty("m_Format"); m_ParameterCountProp = serializedObject.FindProperty("m_ParameterCount"); } @@ -64,40 +59,12 @@ public override void OnInspectorGUI() EditorGUILayout.Space(); - if (m_HavePropertiesChanged) + if (serializedObject.ApplyModifiedProperties() || m_HavePropertiesChanged) { - m_HavePropertiesChanged = false; m_TextComponent.havePropertiesChanged = true; - m_TextComponent.ComputeMarginSize(); + m_HavePropertiesChanged = false; EditorUtility.SetDirty(target); } - - serializedObject.ApplyModifiedProperties(); - } - - protected override void DrawExtraSettings() - { - Foldout.extraSettings = EditorGUILayout.Foldout(Foldout.extraSettings, k_ExtraSettingsLabel, true, TMP_UIStyleManager.boldFoldout); - if (Foldout.extraSettings) - { - EditorGUI.indentLevel += 1; - - DrawMargins(); - - DrawGeometrySorting(); - - DrawRichText(); - - DrawRaycastTarget(); - - DrawParsing(); - - DrawKerning(); - - DrawPadding(); - - EditorGUI.indentLevel -= 1; - } } protected void DrawFormatParameters() @@ -116,50 +83,5 @@ protected void DrawFormatParameters() m_HavePropertiesChanged = true; } } - - protected void DrawRaycastTarget() - { - EditorGUI.BeginChangeCheck(); - EditorGUILayout.PropertyField(m_RaycastTargetProp, k_RaycastTargetLabel); - if (EditorGUI.EndChangeCheck()) - { - // Change needs to propagate to the child sub objects. - Graphic[] graphicComponents = m_TextComponent.GetComponentsInChildren(); - for (int i = 1; i < graphicComponents.Length; i++) - graphicComponents[i].raycastTarget = m_RaycastTargetProp.boolValue; - - m_HavePropertiesChanged = true; - } - } - - // Method to handle multi object selection - protected override bool IsMixSelectionTypes() - { - GameObject[] objects = Selection.gameObjects; - if (objects.Length > 1) - { - for (int i = 0; i < objects.Length; i++) - { - if (objects[i].GetComponent() == null) - return true; - } - } - return false; - } - protected override void OnUndoRedo() - { - int undoEventId = Undo.GetCurrentGroup(); - int lastUndoEventId = s_EventId; - - if (undoEventId != lastUndoEventId) - { - for (int i = 0; i < targets.Length; i++) - { - //Debug.Log("Undo & Redo Performed detected in Editor Panel. Event ID:" + Undo.GetCurrentGroup()); - TMPro_EventManager.ON_TEXTMESHPRO_UGUI_PROPERTY_CHANGED(true, targets[i] as FormattableTextMeshProUGUI); - s_EventId = undoEventId; - } - } - } } } \ No newline at end of file diff --git a/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Editor/ParametersDrawer.cs b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Editor/ParametersDrawer.cs index 6b173445..eebe5dd8 100644 --- a/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Editor/ParametersDrawer.cs +++ b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Editor/ParametersDrawer.cs @@ -47,7 +47,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten { if (textProperty.objectReferenceValue != null) { - FormattableTextMeshProUGUI formableText = (FormattableTextMeshProUGUI)textProperty.objectReferenceValue; + IFormattableText formableText = (IFormattableText)textProperty.objectReferenceValue; if (capacityProperty != null) { int count = formableText.ParameterCount; diff --git a/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Editor/TemplateTextMeshProUIEditorPanel.cs b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Editor/TemplateTextMeshProUIEditorPanel.cs index ca76bedb..e6b352a4 100644 --- a/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Editor/TemplateTextMeshProUIEditorPanel.cs +++ b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Editor/TemplateTextMeshProUIEditorPanel.cs @@ -22,27 +22,22 @@ * SOFTWARE. */ -using TMPro; using TMPro.EditorUtilities; using UnityEditor; using UnityEngine; -using UnityEngine.UI; namespace Loxodon.Framework.Views.TextMeshPro.Editor { [CustomEditor(typeof(TemplateTextMeshProUGUI), true), CanEditMultipleObjects] - public class TemplateTextMeshProUIEditorPanel : TMP_BaseEditorPanel + public class TemplateTextMeshProUIEditorPanel : TMP_EditorPanelUI { - static readonly GUIContent k_RaycastTargetLabel = new GUIContent("Raycast Target", "Whether the text blocks raycasts from the Graphic Raycaster."); static readonly GUIContent k_TemplateLabel = new GUIContent("Template", "text template"); - SerializedProperty m_RaycastTargetProp; SerializedProperty m_TemplateProp; protected override void OnEnable() { base.OnEnable(); - m_RaycastTargetProp = serializedObject.FindProperty("m_RaycastTarget"); m_TemplateProp = serializedObject.FindProperty("m_Template"); } @@ -54,7 +49,6 @@ public override void OnInspectorGUI() serializedObject.Update(); DrawTemplateInput(); - //DrawTextInput(); DrawMainSettings(); @@ -62,40 +56,12 @@ public override void OnInspectorGUI() EditorGUILayout.Space(); - if (m_HavePropertiesChanged) + if (serializedObject.ApplyModifiedProperties() || m_HavePropertiesChanged) { - m_HavePropertiesChanged = false; m_TextComponent.havePropertiesChanged = true; - m_TextComponent.ComputeMarginSize(); + m_HavePropertiesChanged = false; EditorUtility.SetDirty(target); } - - serializedObject.ApplyModifiedProperties(); - } - - protected override void DrawExtraSettings() - { - Foldout.extraSettings = EditorGUILayout.Foldout(Foldout.extraSettings, k_ExtraSettingsLabel, true, TMP_UIStyleManager.boldFoldout); - if (Foldout.extraSettings) - { - EditorGUI.indentLevel += 1; - - DrawMargins(); - - DrawGeometrySorting(); - - DrawRichText(); - - DrawRaycastTarget(); - - DrawParsing(); - - DrawKerning(); - - DrawPadding(); - - EditorGUI.indentLevel -= 1; - } } protected void DrawTemplateInput() @@ -107,50 +73,5 @@ protected void DrawTemplateInput() m_HavePropertiesChanged = true; } } - - protected void DrawRaycastTarget() - { - EditorGUI.BeginChangeCheck(); - EditorGUILayout.PropertyField(m_RaycastTargetProp, k_RaycastTargetLabel); - if (EditorGUI.EndChangeCheck()) - { - // Change needs to propagate to the child sub objects. - Graphic[] graphicComponents = m_TextComponent.GetComponentsInChildren(); - for (int i = 1; i < graphicComponents.Length; i++) - graphicComponents[i].raycastTarget = m_RaycastTargetProp.boolValue; - - m_HavePropertiesChanged = true; - } - } - - // Method to handle multi object selection - protected override bool IsMixSelectionTypes() - { - GameObject[] objects = Selection.gameObjects; - if (objects.Length > 1) - { - for (int i = 0; i < objects.Length; i++) - { - if (objects[i].GetComponent() == null) - return true; - } - } - return false; - } - protected override void OnUndoRedo() - { - int undoEventId = Undo.GetCurrentGroup(); - int lastUndoEventId = s_EventId; - - if (undoEventId != lastUndoEventId) - { - for (int i = 0; i < targets.Length; i++) - { - //Debug.Log("Undo & Redo Performed detected in Editor Panel. Event ID:" + Undo.GetCurrentGroup()); - TMPro_EventManager.ON_TEXTMESHPRO_UGUI_PROPERTY_CHANGED(true, targets[i] as FormattableTextMeshProUGUI); - s_EventId = undoEventId; - } - } - } } } \ No newline at end of file diff --git a/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/FormattableTextMeshPro.cs b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/FormattableTextMeshPro.cs new file mode 100644 index 00000000..cbb7dffc --- /dev/null +++ b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/FormattableTextMeshPro.cs @@ -0,0 +1,107 @@ +using System; +using UnityEngine; +using static Loxodon.Framework.Views.TextMeshPro.IFormattableText; + +namespace Loxodon.Framework.Views.TextMeshPro +{ + public class FormattableTextMeshPro : TMPro.TextMeshPro, IFormattableText + { + [SerializeField] + protected string m_Format = "{0}"; + [SerializeField] + protected int m_ParameterCount = 1; + protected internal Parameters m_Parameters; + public string Format + { + get { return this.m_Format; } + set { this.m_Format = value; } + } + + public int ParameterCount + { + get { return this.m_ParameterCount; } + set { this.m_ParameterCount = value; } + } + + public Parameters Parameters + { + get { return m_Parameters; } + set { this.m_Parameters = value; } + } + + //protected override void OnEnable() + //{ + // base.OnEnable(); + // Initialize(); + //} + + public override void SetAllDirty() + { + base.SetAllDirty(); + Initialize(); + } + + protected virtual void Initialize() + { + if (m_Parameters != null) + m_Parameters.OnParameterChanged(); + else + SetText(BUFFER.Clear().Append(m_Format)); + } + + public ArrayParameters AsArray() + { + if (m_Parameters == null) + m_Parameters = new ArrayParameters(this, this.ParameterCount); + + if (m_Parameters is ArrayParameters parameters) + return parameters; + + throw new NotSupportedException($"The current parameter type has been set to \"{m_Parameters.GetType()}\" and cannot be converted to other types."); + } + + public GenericParameters AsParameters() + { + if (m_Parameters == null) + m_Parameters = new GenericParameters() { Text = this }; + + if (m_Parameters is GenericParameters parameters) + return parameters; + + throw new NotSupportedException($"The current parameter type has been set to \"{m_Parameters.GetType()}\" and cannot be converted to other types."); + } + + public GenericParameters AsParameters() + { + if (m_Parameters == null) + m_Parameters = new GenericParameters() { Text = this }; + + if (m_Parameters is GenericParameters parameters) + return parameters; + + throw new NotSupportedException($"The current parameter type has been set to \"{m_Parameters.GetType()}\" and cannot be converted to other types."); + } + + public GenericParameters AsParameters() + { + if (m_Parameters == null) + m_Parameters = new GenericParameters() { Text = this }; + + if (m_Parameters is GenericParameters parameters) + return parameters; + + throw new NotSupportedException($"The current parameter type has been set to \"{m_Parameters.GetType()}\" and cannot be converted to other types."); + } + + public GenericParameters AsParameters() + { + if (m_Parameters == null) + m_Parameters = new GenericParameters() { Text = this }; + + if (m_Parameters is GenericParameters parameters) + return parameters; + + throw new NotSupportedException($"The current parameter type has been set to \"{m_Parameters.GetType()}\" and cannot be converted to other types."); + } + } +} diff --git a/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/FormattableTextMeshPro.cs.meta b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/FormattableTextMeshPro.cs.meta new file mode 100644 index 00000000..d49a6072 --- /dev/null +++ b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/FormattableTextMeshPro.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a1b7cd3c5729f8e4c81e89960441d38e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/FormattableTextMeshProUGUI.cs b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/FormattableTextMeshProUGUI.cs index 5051fd60..3c1da315 100644 --- a/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/FormattableTextMeshProUGUI.cs +++ b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/FormattableTextMeshProUGUI.cs @@ -23,15 +23,14 @@ */ using System; -using System.Text; using TMPro; using UnityEngine; +using static Loxodon.Framework.Views.TextMeshPro.IFormattableText; namespace Loxodon.Framework.Views.TextMeshPro { - public class FormattableTextMeshProUGUI : TextMeshProUGUI - { - internal static StringBuilder BUFFER = new StringBuilder(); + public class FormattableTextMeshProUGUI : TextMeshProUGUI, IFormattableText + { [SerializeField] protected string m_Format = "{0}"; [SerializeField] @@ -49,6 +48,12 @@ public int ParameterCount set { this.m_ParameterCount = value; } } + public Parameters Parameters + { + get { return m_Parameters; } + set { this.m_Parameters = value; } + } + //protected override void OnEnable() //{ // base.OnEnable(); diff --git a/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/IFormattableText.cs b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/IFormattableText.cs new file mode 100644 index 00000000..a01a0145 --- /dev/null +++ b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/IFormattableText.cs @@ -0,0 +1,38 @@ +/* + * MIT License + * + * Copyright (c) 2018 Clark Yang + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +using System.Text; + +namespace Loxodon.Framework.Views.TextMeshPro +{ + public interface IFormattableText + { + internal static StringBuilder BUFFER = new StringBuilder(); + string Format { get; set; } + + int ParameterCount { get; set; } + + Parameters Parameters { get; set; } + } +} diff --git a/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/IFormattableText.cs.meta b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/IFormattableText.cs.meta new file mode 100644 index 00000000..2b0cb875 --- /dev/null +++ b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/IFormattableText.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0e1adebdbb9751c4890542718da8e31f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/Parameters.cs b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/Parameters.cs index 78070c8c..d96838dc 100644 --- a/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/Parameters.cs +++ b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/Parameters.cs @@ -26,8 +26,9 @@ using System; using System.Collections; using System.Collections.Generic; +using TMPro; using UnityEngine; -using static Loxodon.Framework.Views.TextMeshPro.FormattableTextMeshProUGUI; +using static Loxodon.Framework.Views.TextMeshPro.IFormattableText; namespace Loxodon.Framework.Views.TextMeshPro { @@ -35,17 +36,20 @@ namespace Loxodon.Framework.Views.TextMeshPro public abstract class Parameters { [SerializeField] - protected FormattableTextMeshProUGUI m_Text; - public FormattableTextMeshProUGUI Text + protected TMP_Text m_Text; + public TMP_Text Text { get { return this.m_Text; } set { this.m_Text = value; } } + protected IFormattableText FormattableText { get { return m_Text as IFormattableText; } } + protected internal virtual void OnParameterChanged() { - if (m_Text != null && m_Text.m_Parameters == null) - this.m_Text.m_Parameters = this; + var formattableText = FormattableText; + if (formattableText != null && formattableText.Parameters == null) + formattableText.Parameters = this; } } @@ -60,7 +64,7 @@ public ArrayParameters() { } - internal ArrayParameters(FormattableTextMeshProUGUI text, int capacity) + internal ArrayParameters(TMP_Text text, int capacity) { if (capacity < 0) throw new ArgumentException("The capacity cannot be less than 0."); @@ -104,7 +108,7 @@ protected internal override void OnParameterChanged() return; this.Initialize(); - m_Text.SetText(BUFFER.Clear().AppendFormat(m_Text.Format, m_Items)); + m_Text.SetText(BUFFER.Clear().AppendFormat(FormattableText.Format, m_Items)); } catch (Exception e) { @@ -112,7 +116,7 @@ protected internal override void OnParameterChanged() if (Application.isEditor) Debug.LogWarning(e); #endif - m_Text.SetText(BUFFER.Clear().Append(m_Text.Format)); + m_Text.SetText(BUFFER.Clear().Append(FormattableText.Format)); } } @@ -195,7 +199,7 @@ protected internal override void OnParameterChanged() base.OnParameterChanged(); if (m_Text == null || !m_Text.enabled) return; - m_Text.SetText(BUFFER.Clear().AppendFormat(m_Text.Format, parameter1)); + m_Text.SetText(BUFFER.Clear().AppendFormat(FormattableText.Format, parameter1)); } catch (Exception e) { @@ -203,7 +207,7 @@ protected internal override void OnParameterChanged() if (Application.isEditor) Debug.LogWarning(e); #endif - m_Text.SetText(BUFFER.Clear().Append(m_Text.Format)); + m_Text.SetText(BUFFER.Clear().Append(FormattableText.Format)); } } } @@ -241,7 +245,7 @@ protected internal override void OnParameterChanged() if (m_Text == null || !m_Text.enabled) return; - m_Text.SetText(BUFFER.Clear().AppendFormat(m_Text.Format, parameter1, parameter2)); + m_Text.SetText(BUFFER.Clear().AppendFormat(FormattableText.Format, parameter1, parameter2)); } catch (Exception e) { @@ -249,7 +253,7 @@ protected internal override void OnParameterChanged() if (Application.isEditor) Debug.LogWarning(e); #endif - m_Text.SetText(BUFFER.Clear().Append(m_Text.Format)); + m_Text.SetText(BUFFER.Clear().Append(FormattableText.Format)); } } } @@ -298,7 +302,7 @@ protected internal override void OnParameterChanged() if (m_Text == null || !m_Text.enabled) return; - m_Text.SetText(BUFFER.Clear().AppendFormat(m_Text.Format, parameter1, parameter2, Parameter3)); + m_Text.SetText(BUFFER.Clear().AppendFormat(FormattableText.Format, parameter1, parameter2, Parameter3)); } catch (Exception e) { @@ -306,7 +310,7 @@ protected internal override void OnParameterChanged() if (Application.isEditor) Debug.LogWarning(e); #endif - m_Text.SetText(BUFFER.Clear().Append(m_Text.Format)); + m_Text.SetText(BUFFER.Clear().Append(FormattableText.Format)); } } } @@ -366,7 +370,7 @@ protected internal override void OnParameterChanged() if (m_Text == null || !m_Text.enabled) return; - m_Text.SetText(BUFFER.Clear().AppendFormat(m_Text.Format, parameter1, parameter2, Parameter3, parameter4)); + m_Text.SetText(BUFFER.Clear().AppendFormat(FormattableText.Format, parameter1, parameter2, Parameter3, parameter4)); } catch (Exception e) { @@ -374,7 +378,7 @@ protected internal override void OnParameterChanged() if (Application.isEditor) Debug.LogWarning(e); #endif - m_Text.SetText(BUFFER.Clear().Append(m_Text.Format)); + m_Text.SetText(BUFFER.Clear().Append(FormattableText.Format)); } } } diff --git a/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/TemplateTextMeshProUGUI.cs b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/TemplateTextMeshProUGUI.cs index 1ab92e55..75b8bc22 100644 --- a/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/TemplateTextMeshProUGUI.cs +++ b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/Runtime/Framework/Views/TextMeshPro/TemplateTextMeshProUGUI.cs @@ -25,7 +25,7 @@ using Loxodon.Framework.TextFormatting; using TMPro; using UnityEngine; -using static Loxodon.Framework.Views.TextMeshPro.FormattableTextMeshProUGUI; +using static Loxodon.Framework.Views.TextMeshPro.IFormattableText; namespace Loxodon.Framework.Views.TextMeshPro { diff --git a/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/package.json b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/package.json index 41136c9f..3f6957b4 100644 --- a/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/package.json +++ b/Loxodon.Framework.TextMeshPro/Assets/LoxodonFramework/TextMeshPro/package.json @@ -1,7 +1,7 @@ { "name": "com.vovgou.loxodon-framework-textmeshpro", "displayName": "Loxodon Framework TextMeshPro", - "version": "2.6.3", + "version": "2.6.4", "unity": "2021.3", "description": "This is a plugin for the TextMeshPro.", "license": "MIT", @@ -27,9 +27,9 @@ }, "relatedPackages": {}, "dependencies": { - "com.vovgou.loxodon-framework": "2.6.3", - "com.vovgou.loxodon-framework-textformatting": "2.6.3", - "com.unity.textmeshpro": "1.4.1" + "com.vovgou.loxodon-framework": "2.6.4", + "com.vovgou.loxodon-framework-textformatting": "2.6.4", + "com.unity.textmeshpro": "3.0.6" }, "samples": [ { diff --git a/Loxodon.Framework.TextMeshPro/Assets/Samples/Loxodon Framework TextMeshPro/2.0.0/Tutorials/FormattableTextMeshProUGUI Tutorials.unity b/Loxodon.Framework.TextMeshPro/Assets/Samples/Loxodon Framework TextMeshPro/2.0.0/Tutorials/FormattableTextMeshProUGUI Tutorials.unity index 9f3d9d52..f42ecbea 100644 --- a/Loxodon.Framework.TextMeshPro/Assets/Samples/Loxodon Framework TextMeshPro/2.0.0/Tutorials/FormattableTextMeshProUGUI Tutorials.unity +++ b/Loxodon.Framework.TextMeshPro/Assets/Samples/Loxodon Framework TextMeshPro/2.0.0/Tutorials/FormattableTextMeshProUGUI Tutorials.unity @@ -362,13 +362,12 @@ MonoBehaviour: m_fontColorGradientPreset: {fileID: 0} m_spriteAsset: {fileID: 0} m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 m_overrideHtmlColors: 0 m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_outlineColor: - serializedVersion: 2 - rgba: 4278190080 m_fontSize: 36 m_fontSizeBase: 36 m_fontWeight: 400 @@ -376,7 +375,9 @@ MonoBehaviour: m_fontSizeMin: 18 m_fontSizeMax: 72 m_fontStyle: 0 - m_textAlignment: 257 + m_HorizontalAlignment: 1 + m_VerticalAlignment: 256 + m_textAlignment: 65535 m_characterSpacing: 0 m_wordSpacing: 0 m_lineSpacing: 0 @@ -386,10 +387,8 @@ MonoBehaviour: m_enableWordWrapping: 1 m_wordWrappingRatios: 0.4 m_overflowMode: 0 - m_firstOverflowCharacterIndex: -1 m_linkedTextComponent: {fileID: 0} - m_isLinkedTextComponent: 0 - m_isTextTruncated: 0 + parentLinkedComponent: {fileID: 0} m_enableKerning: 1 m_enableExtraPadding: 0 checkPaddingRequired: 0 @@ -397,40 +396,18 @@ MonoBehaviour: m_parseCtrlCharacters: 1 m_isOrthographic: 1 m_isCullingEnabled: 0 - m_ignoreRectMaskCulling: 0 - m_ignoreCulling: 1 m_horizontalMapping: 0 m_verticalMapping: 0 m_uvLineOffset: 0 m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 m_VertexBufferAutoSizeReduction: 1 - m_firstVisibleCharacter: 0 m_useMaxVisibleDescender: 1 m_pageToDisplay: 1 m_margin: {x: 0, y: 0, z: 0, w: 0} - m_textInfo: - textComponent: {fileID: 1318457055} - characterCount: 0 - spriteCount: 0 - spaceCount: 0 - wordCount: 0 - linkCount: 0 - lineCount: 0 - pageCount: 0 - materialCount: 1 m_isUsingLegacyAnimationComponent: 0 m_isVolumetricText: 0 - m_spriteAnimator: {fileID: 0} m_hasFontAssetChanged: 0 - m_subTextObjects: - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} m_baseMaterial: {fileID: 0} m_maskOffset: {x: 0, y: 0, z: 0, w: 0} m_Template: @@ -594,7 +571,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: + m_text: Example2,{0:yyyy-MM-dd HH:mm:ss}, FrameCount:{1} m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} @@ -615,13 +592,12 @@ MonoBehaviour: m_fontColorGradientPreset: {fileID: 0} m_spriteAsset: {fileID: 0} m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 m_overrideHtmlColors: 0 m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_outlineColor: - serializedVersion: 2 - rgba: 4278190080 m_fontSize: 36 m_fontSizeBase: 36 m_fontWeight: 400 @@ -629,7 +605,9 @@ MonoBehaviour: m_fontSizeMin: 18 m_fontSizeMax: 72 m_fontStyle: 0 - m_textAlignment: 257 + m_HorizontalAlignment: 1 + m_VerticalAlignment: 256 + m_textAlignment: 65535 m_characterSpacing: 0 m_wordSpacing: 0 m_lineSpacing: 0 @@ -639,10 +617,8 @@ MonoBehaviour: m_enableWordWrapping: 1 m_wordWrappingRatios: 0.4 m_overflowMode: 0 - m_firstOverflowCharacterIndex: 23 m_linkedTextComponent: {fileID: 0} - m_isLinkedTextComponent: 0 - m_isTextTruncated: 0 + parentLinkedComponent: {fileID: 0} m_enableKerning: 1 m_enableExtraPadding: 0 checkPaddingRequired: 0 @@ -650,40 +626,18 @@ MonoBehaviour: m_parseCtrlCharacters: 1 m_isOrthographic: 1 m_isCullingEnabled: 0 - m_ignoreRectMaskCulling: 0 - m_ignoreCulling: 1 m_horizontalMapping: 0 m_verticalMapping: 0 m_uvLineOffset: 0 m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 m_VertexBufferAutoSizeReduction: 1 - m_firstVisibleCharacter: 0 m_useMaxVisibleDescender: 1 m_pageToDisplay: 1 m_margin: {x: 0, y: 0, z: 0, w: 0} - m_textInfo: - textComponent: {fileID: 1623282304} - characterCount: 48 - spriteCount: 0 - spaceCount: 2 - wordCount: 8 - linkCount: 0 - lineCount: 2 - pageCount: 1 - materialCount: 1 m_isUsingLegacyAnimationComponent: 0 m_isVolumetricText: 0 - m_spriteAnimator: {fileID: 0} m_hasFontAssetChanged: 0 - m_subTextObjects: - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} m_baseMaterial: {fileID: 0} m_maskOffset: {x: 0, y: 0, z: 0, w: 0} m_Format: Example2,{0:yyyy-MM-dd HH:mm:ss}, FrameCount:{1} @@ -754,7 +708,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: + m_text: Example1,{0:yyyy-MM-dd HH:mm:ss}, FrameCount:{1} m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} @@ -775,13 +729,12 @@ MonoBehaviour: m_fontColorGradientPreset: {fileID: 0} m_spriteAsset: {fileID: 0} m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 m_overrideHtmlColors: 0 m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_outlineColor: - serializedVersion: 2 - rgba: 4278190080 m_fontSize: 36 m_fontSizeBase: 36 m_fontWeight: 400 @@ -789,7 +742,9 @@ MonoBehaviour: m_fontSizeMin: 18 m_fontSizeMax: 72 m_fontStyle: 0 - m_textAlignment: 257 + m_HorizontalAlignment: 1 + m_VerticalAlignment: 256 + m_textAlignment: 65535 m_characterSpacing: 0 m_wordSpacing: 0 m_lineSpacing: 0 @@ -799,10 +754,8 @@ MonoBehaviour: m_enableWordWrapping: 1 m_wordWrappingRatios: 0.4 m_overflowMode: 0 - m_firstOverflowCharacterIndex: 23 m_linkedTextComponent: {fileID: 0} - m_isLinkedTextComponent: 0 - m_isTextTruncated: 0 + parentLinkedComponent: {fileID: 0} m_enableKerning: 1 m_enableExtraPadding: 0 checkPaddingRequired: 0 @@ -810,40 +763,18 @@ MonoBehaviour: m_parseCtrlCharacters: 1 m_isOrthographic: 1 m_isCullingEnabled: 0 - m_ignoreRectMaskCulling: 0 - m_ignoreCulling: 1 m_horizontalMapping: 0 m_verticalMapping: 0 m_uvLineOffset: 0 m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 m_VertexBufferAutoSizeReduction: 1 - m_firstVisibleCharacter: 0 m_useMaxVisibleDescender: 1 m_pageToDisplay: 1 m_margin: {x: 0, y: 0, z: 0, w: 0} - m_textInfo: - textComponent: {fileID: 1714718359} - characterCount: 48 - spriteCount: 0 - spaceCount: 2 - wordCount: 8 - linkCount: 0 - lineCount: 2 - pageCount: 1 - materialCount: 1 m_isUsingLegacyAnimationComponent: 0 m_isVolumetricText: 0 - m_spriteAnimator: {fileID: 0} m_hasFontAssetChanged: 0 - m_subTextObjects: - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} m_baseMaterial: {fileID: 0} m_maskOffset: {x: 0, y: 0, z: 0, w: 0} m_Format: Example1,{0:yyyy-MM-dd HH:mm:ss}, FrameCount:{1} @@ -914,7 +845,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: + m_text: MoveSpeed:{0:f4} AttackSpeed:{1:f2} m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} @@ -935,13 +866,12 @@ MonoBehaviour: m_fontColorGradientPreset: {fileID: 0} m_spriteAsset: {fileID: 0} m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 m_overrideHtmlColors: 0 m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_outlineColor: - serializedVersion: 2 - rgba: 4278190080 m_fontSize: 36 m_fontSizeBase: 36 m_fontWeight: 400 @@ -949,7 +879,9 @@ MonoBehaviour: m_fontSizeMin: 18 m_fontSizeMax: 72 m_fontStyle: 0 - m_textAlignment: 257 + m_HorizontalAlignment: 1 + m_VerticalAlignment: 256 + m_textAlignment: 65535 m_characterSpacing: 0 m_wordSpacing: 0 m_lineSpacing: 0 @@ -959,10 +891,8 @@ MonoBehaviour: m_enableWordWrapping: 1 m_wordWrappingRatios: 0.4 m_overflowMode: 0 - m_firstOverflowCharacterIndex: 18 m_linkedTextComponent: {fileID: 0} - m_isLinkedTextComponent: 0 - m_isTextTruncated: 0 + parentLinkedComponent: {fileID: 0} m_enableKerning: 1 m_enableExtraPadding: 0 checkPaddingRequired: 0 @@ -970,40 +900,18 @@ MonoBehaviour: m_parseCtrlCharacters: 1 m_isOrthographic: 1 m_isCullingEnabled: 0 - m_ignoreRectMaskCulling: 0 - m_ignoreCulling: 1 m_horizontalMapping: 0 m_verticalMapping: 0 m_uvLineOffset: 0 m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 m_VertexBufferAutoSizeReduction: 1 - m_firstVisibleCharacter: 0 m_useMaxVisibleDescender: 1 m_pageToDisplay: 1 m_margin: {x: 0, y: 0, z: 0, w: 0} - m_textInfo: - textComponent: {fileID: 1823844642} - characterCount: 36 - spriteCount: 0 - spaceCount: 2 - wordCount: 6 - linkCount: 0 - lineCount: 2 - pageCount: 1 - materialCount: 1 m_isUsingLegacyAnimationComponent: 0 m_isVolumetricText: 0 - m_spriteAnimator: {fileID: 0} m_hasFontAssetChanged: 0 - m_subTextObjects: - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} m_baseMaterial: {fileID: 0} m_maskOffset: {x: 0, y: 0, z: 0, w: 0} m_Format: MoveSpeed:{0:f4} AttackSpeed:{1:f2} diff --git a/Loxodon.Framework/Assets/LoxodonFramework/PackageResources/Examples.unitypackage b/Loxodon.Framework/Assets/LoxodonFramework/PackageResources/Examples.unitypackage index ba722ca2..960abbd3 100644 Binary files a/Loxodon.Framework/Assets/LoxodonFramework/PackageResources/Examples.unitypackage and b/Loxodon.Framework/Assets/LoxodonFramework/PackageResources/Examples.unitypackage differ diff --git a/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Examples/Scripts/Repositories/AccountRepository.cs b/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Examples/Scripts/Repositories/AccountRepository.cs index e3b8689f..6ddf9ab9 100644 --- a/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Examples/Scripts/Repositories/AccountRepository.cs +++ b/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Examples/Scripts/Repositories/AccountRepository.cs @@ -22,11 +22,9 @@ * SOFTWARE. */ -using Loxodon.Framework.Asynchronous; -using Loxodon.Framework.Execution; using System; -using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; namespace Loxodon.Framework.Examples { @@ -43,42 +41,28 @@ public AccountRepository() cache.Add(account.Username, account); } - public virtual IAsyncResult Get(string username) - { - return Executors.RunOnCoroutine(promise => DoGet(promise, username)); - } - - protected virtual IEnumerator DoGet(IPromise promise, string username) + public virtual Task Get(string username) { Account account = null; this.cache.TryGetValue(username, out account); - yield return null; - promise.SetResult(account); - } - - public virtual IAsyncResult Save(Account account) - { - return Executors.RunOnCoroutine(promise => DoSave(promise, account)); + return Task.FromResult(account); } - protected virtual IEnumerator DoSave(IPromise promise, Account account) + public virtual async Task Save(Account account) { if (cache.ContainsKey(account.Username)) - { - promise.SetException(new Exception("The account already exists.")); - yield break; - } + throw new Exception("The account already exists."); cache.Add(account.Username, account); - promise.SetResult(account); + return account; } - public virtual IAsyncResult Update(Account account) + public virtual Task Update(Account account) { throw new NotImplementedException(); } - public virtual IAsyncResult Delete(string username) + public virtual Task Delete(string username) { throw new NotImplementedException(); } diff --git a/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Examples/Scripts/Repositories/IAccountRepository.cs b/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Examples/Scripts/Repositories/IAccountRepository.cs index f9f2f2be..51c06e68 100644 --- a/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Examples/Scripts/Repositories/IAccountRepository.cs +++ b/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Examples/Scripts/Repositories/IAccountRepository.cs @@ -22,21 +22,18 @@ * SOFTWARE. */ -using UnityEngine; -using System.Collections; - -using Loxodon.Framework.Asynchronous; +using System.Threading.Tasks; namespace Loxodon.Framework.Examples { - public interface IAccountRepository + public interface IAccountRepository { - IAsyncResult Get (string username); + Task Get (string username); - IAsyncResult Save (Account account); + Task Save (Account account); - IAsyncResult Update (Account account); + Task Update (Account account); - IAsyncResult Delete (string username); + Task Delete (string username); } } \ No newline at end of file diff --git a/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Examples/Scripts/Services/AccountService.cs b/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Examples/Scripts/Services/AccountService.cs index 740a5b67..fed10de0 100644 --- a/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Examples/Scripts/Services/AccountService.cs +++ b/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Examples/Scripts/Services/AccountService.cs @@ -22,77 +22,52 @@ * SOFTWARE. */ -using Loxodon.Framework.Asynchronous; -using Loxodon.Framework.Execution; -using System; +using Loxodon.Framework.Messaging; +using System.Threading.Tasks; namespace Loxodon.Framework.Examples { public class AccountService : IAccountService { private IAccountRepository repository; + private IMessenger messenger; - public event EventHandler LoginFinished; + public IMessenger Messenger { get { return messenger; } } public AccountService(IAccountRepository repository) { this.repository = repository; + this.messenger = new Messenger(); } - public virtual IAsyncResult Register(Account account) + public virtual async Task Register(Account account) { - return this.repository.Save(account); + await this.repository.Save(account); + messenger.Publish(new AccountEventArgs(AccountEventType.Register, account)); + return account; } - public virtual IAsyncResult Update(Account account) + public virtual async Task Update(Account account) { - return this.repository.Update(account); + await this.repository.Update(account); + messenger.Publish(new AccountEventArgs(AccountEventType.Update, account)); + return account; } - public virtual IAsyncResult Login(string username, string password) + public virtual async Task Login(string username, string password) { - AsyncResult result = new AsyncResult(); - DoLogin(result, username, password); - return result; - } + Account account = await this.GetAccount(username); + if (account == null || !account.Password.Equals(password)) + return null; - protected async void DoLogin(IPromise promise, string username, string password) - { - try - { - Account account = await this.GetAccount(username); - if (account == null || !account.Password.Equals(password)) - { - promise.SetResult(null); - this.RaiseLoginFinished(false, null); - } - else - { - promise.SetResult(account); - this.RaiseLoginFinished(true, account); - } - } - catch (Exception e) - { - promise.SetException(e); - this.RaiseLoginFinished(false, null); - } + messenger.Publish(new AccountEventArgs(AccountEventType.Login, account)); + return account; } - public virtual IAsyncResult GetAccount(string username) + public virtual Task GetAccount(string username) { return this.repository.Get(username); } - - protected virtual void RaiseLoginFinished(bool succeed, Account account) - { - try - { - if (this.LoginFinished != null) - this.LoginFinished(this, new LoginEventArgs(succeed, account)); - } - catch (Exception) { } - } } } \ No newline at end of file diff --git a/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Examples/Scripts/Services/IAccountService.cs b/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Examples/Scripts/Services/IAccountService.cs index eb46e553..fc208c4d 100644 --- a/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Examples/Scripts/Services/IAccountService.cs +++ b/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Examples/Scripts/Services/IAccountService.cs @@ -22,34 +22,41 @@ * SOFTWARE. */ -using Loxodon.Framework.Asynchronous; -using System; +using Loxodon.Framework.Messaging; +using System.Threading.Tasks; namespace Loxodon.Framework.Examples { - public class LoginEventArgs : EventArgs + public enum AccountEventType { - public LoginEventArgs(bool succeed, Account account) + Register, + Update, + Deleted, + Login + } + public class AccountEventArgs + { + public AccountEventArgs(AccountEventType type, Account account) { - this.IsSucceed = succeed; + this.Type = type; this.Account = account; } - public bool IsSucceed { get; private set; } + public AccountEventType Type { get; private set; } public Account Account { get; private set; } } public interface IAccountService { - event EventHandler LoginFinished; + IMessenger Messenger { get; } - IAsyncResult Register(Account account); + Task Register(Account account); - IAsyncResult Update(Account account); + Task Update(Account account); - IAsyncResult Login(string username, string password); + Task Login(string username, string password); - IAsyncResult GetAccount(string username); + Task GetAccount(string username); } } \ No newline at end of file diff --git a/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Examples/Scripts/Views/UI/Logins/ViewModels/LoginViewModel.cs b/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Examples/Scripts/Views/UI/Logins/ViewModels/LoginViewModel.cs index fcb5fe85..f877c8f4 100644 --- a/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Examples/Scripts/Views/UI/Logins/ViewModels/LoginViewModel.cs +++ b/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Examples/Scripts/Views/UI/Logins/ViewModels/LoginViewModel.cs @@ -30,7 +30,9 @@ using Loxodon.Framework.Prefs; using Loxodon.Framework.ViewModels; using Loxodon.Log; +using System; using System.Text.RegularExpressions; +using System.Threading.Tasks; namespace Loxodon.Framework.Examples { @@ -167,18 +169,7 @@ public async void Login() if (!(this.ValidateUsername() && this.ValidatePassword())) return; - IAsyncResult result = this.accountService.Login(this.username, this.password); - Account account = await result; - if (result.Exception != null) - { - if (log.IsErrorEnabled) - log.ErrorFormat("Exception:{0}", result.Exception); - - var tipContent = this.localization.GetText("login.exception.tip", "Login exception."); - this.toastRequest.Raise(new ToastNotification(tipContent,2f));/* show toast */ - return; - } - + Account account = await this.accountService.Login(this.username, this.password); if (account != null) { /* login success */ @@ -191,16 +182,24 @@ public async void Login() { /* Login failure */ var tipContent = this.localization.GetText("login.failure.tip", "Login failure."); - this.toastRequest.Raise(new ToastNotification(tipContent,2f));/* show toast */ + this.toastRequest.Raise(new ToastNotification(tipContent, 2f));/* show toast */ } } + catch (Exception e) + { + if (log.IsErrorEnabled) + log.ErrorFormat("Exception:{0}", e); + + var tipContent = this.localization.GetText("login.exception.tip", "Login exception."); + this.toastRequest.Raise(new ToastNotification(tipContent, 2f));/* show toast */ + } finally { this.loginCommand.Enabled = true;/*by databinding, auto set button.interactable = true. */ } } - public IAsyncResult GetAccount() + public Task GetAccount() { return this.accountService.GetAccount(this.Username); } diff --git a/Loxodon.Framework/Assets/LoxodonFramework/package.json b/Loxodon.Framework/Assets/LoxodonFramework/package.json index 860cd00a..384a9fdf 100644 --- a/Loxodon.Framework/Assets/LoxodonFramework/package.json +++ b/Loxodon.Framework/Assets/LoxodonFramework/package.json @@ -1,7 +1,7 @@ { "name": "com.vovgou.loxodon-framework", "displayName": "Loxodon Framework", - "version": "2.6.3", + "version": "2.6.4", "unity": "2018.4", "description": "LoxodonFramework is a lightweight MVVM(Model-View-ViewModel) framework built specifically to target Unity3D. Databinding and localization are supported.It has a very flexible extensibility.It makes your game development faster and easier.\n\nFor tutorials,examples and support,please see the project.You can also discuss the project in the Unity Forums.\n\nThe plugin is compatible with MacOSX,Windows,Linux,UWP,IOS and Android,and provides all the source code of the project.", "license": "MIT", diff --git a/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Repositories/AccountRepository.cs b/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Repositories/AccountRepository.cs index e3b8689f..6ddf9ab9 100644 --- a/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Repositories/AccountRepository.cs +++ b/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Repositories/AccountRepository.cs @@ -22,11 +22,9 @@ * SOFTWARE. */ -using Loxodon.Framework.Asynchronous; -using Loxodon.Framework.Execution; using System; -using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; namespace Loxodon.Framework.Examples { @@ -43,42 +41,28 @@ public AccountRepository() cache.Add(account.Username, account); } - public virtual IAsyncResult Get(string username) - { - return Executors.RunOnCoroutine(promise => DoGet(promise, username)); - } - - protected virtual IEnumerator DoGet(IPromise promise, string username) + public virtual Task Get(string username) { Account account = null; this.cache.TryGetValue(username, out account); - yield return null; - promise.SetResult(account); - } - - public virtual IAsyncResult Save(Account account) - { - return Executors.RunOnCoroutine(promise => DoSave(promise, account)); + return Task.FromResult(account); } - protected virtual IEnumerator DoSave(IPromise promise, Account account) + public virtual async Task Save(Account account) { if (cache.ContainsKey(account.Username)) - { - promise.SetException(new Exception("The account already exists.")); - yield break; - } + throw new Exception("The account already exists."); cache.Add(account.Username, account); - promise.SetResult(account); + return account; } - public virtual IAsyncResult Update(Account account) + public virtual Task Update(Account account) { throw new NotImplementedException(); } - public virtual IAsyncResult Delete(string username) + public virtual Task Delete(string username) { throw new NotImplementedException(); } diff --git a/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Repositories/IAccountRepository.cs b/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Repositories/IAccountRepository.cs index f9f2f2be..51c06e68 100644 --- a/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Repositories/IAccountRepository.cs +++ b/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Repositories/IAccountRepository.cs @@ -22,21 +22,18 @@ * SOFTWARE. */ -using UnityEngine; -using System.Collections; - -using Loxodon.Framework.Asynchronous; +using System.Threading.Tasks; namespace Loxodon.Framework.Examples { - public interface IAccountRepository + public interface IAccountRepository { - IAsyncResult Get (string username); + Task Get (string username); - IAsyncResult Save (Account account); + Task Save (Account account); - IAsyncResult Update (Account account); + Task Update (Account account); - IAsyncResult Delete (string username); + Task Delete (string username); } } \ No newline at end of file diff --git a/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Services/AccountService.cs b/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Services/AccountService.cs index 740a5b67..fed10de0 100644 --- a/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Services/AccountService.cs +++ b/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Services/AccountService.cs @@ -22,77 +22,52 @@ * SOFTWARE. */ -using Loxodon.Framework.Asynchronous; -using Loxodon.Framework.Execution; -using System; +using Loxodon.Framework.Messaging; +using System.Threading.Tasks; namespace Loxodon.Framework.Examples { public class AccountService : IAccountService { private IAccountRepository repository; + private IMessenger messenger; - public event EventHandler LoginFinished; + public IMessenger Messenger { get { return messenger; } } public AccountService(IAccountRepository repository) { this.repository = repository; + this.messenger = new Messenger(); } - public virtual IAsyncResult Register(Account account) + public virtual async Task Register(Account account) { - return this.repository.Save(account); + await this.repository.Save(account); + messenger.Publish(new AccountEventArgs(AccountEventType.Register, account)); + return account; } - public virtual IAsyncResult Update(Account account) + public virtual async Task Update(Account account) { - return this.repository.Update(account); + await this.repository.Update(account); + messenger.Publish(new AccountEventArgs(AccountEventType.Update, account)); + return account; } - public virtual IAsyncResult Login(string username, string password) + public virtual async Task Login(string username, string password) { - AsyncResult result = new AsyncResult(); - DoLogin(result, username, password); - return result; - } + Account account = await this.GetAccount(username); + if (account == null || !account.Password.Equals(password)) + return null; - protected async void DoLogin(IPromise promise, string username, string password) - { - try - { - Account account = await this.GetAccount(username); - if (account == null || !account.Password.Equals(password)) - { - promise.SetResult(null); - this.RaiseLoginFinished(false, null); - } - else - { - promise.SetResult(account); - this.RaiseLoginFinished(true, account); - } - } - catch (Exception e) - { - promise.SetException(e); - this.RaiseLoginFinished(false, null); - } + messenger.Publish(new AccountEventArgs(AccountEventType.Login, account)); + return account; } - public virtual IAsyncResult GetAccount(string username) + public virtual Task GetAccount(string username) { return this.repository.Get(username); } - - protected virtual void RaiseLoginFinished(bool succeed, Account account) - { - try - { - if (this.LoginFinished != null) - this.LoginFinished(this, new LoginEventArgs(succeed, account)); - } - catch (Exception) { } - } } } \ No newline at end of file diff --git a/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Services/IAccountService.cs b/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Services/IAccountService.cs index eb46e553..fc208c4d 100644 --- a/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Services/IAccountService.cs +++ b/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Services/IAccountService.cs @@ -22,34 +22,41 @@ * SOFTWARE. */ -using Loxodon.Framework.Asynchronous; -using System; +using Loxodon.Framework.Messaging; +using System.Threading.Tasks; namespace Loxodon.Framework.Examples { - public class LoginEventArgs : EventArgs + public enum AccountEventType { - public LoginEventArgs(bool succeed, Account account) + Register, + Update, + Deleted, + Login + } + public class AccountEventArgs + { + public AccountEventArgs(AccountEventType type, Account account) { - this.IsSucceed = succeed; + this.Type = type; this.Account = account; } - public bool IsSucceed { get; private set; } + public AccountEventType Type { get; private set; } public Account Account { get; private set; } } public interface IAccountService { - event EventHandler LoginFinished; + IMessenger Messenger { get; } - IAsyncResult Register(Account account); + Task Register(Account account); - IAsyncResult Update(Account account); + Task Update(Account account); - IAsyncResult Login(string username, string password); + Task Login(string username, string password); - IAsyncResult GetAccount(string username); + Task GetAccount(string username); } } \ No newline at end of file diff --git a/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Views/UI/Logins/ViewModels/LoginViewModel.cs b/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Views/UI/Logins/ViewModels/LoginViewModel.cs index fcb5fe85..f877c8f4 100644 --- a/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Views/UI/Logins/ViewModels/LoginViewModel.cs +++ b/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Views/UI/Logins/ViewModels/LoginViewModel.cs @@ -30,7 +30,9 @@ using Loxodon.Framework.Prefs; using Loxodon.Framework.ViewModels; using Loxodon.Log; +using System; using System.Text.RegularExpressions; +using System.Threading.Tasks; namespace Loxodon.Framework.Examples { @@ -167,18 +169,7 @@ public async void Login() if (!(this.ValidateUsername() && this.ValidatePassword())) return; - IAsyncResult result = this.accountService.Login(this.username, this.password); - Account account = await result; - if (result.Exception != null) - { - if (log.IsErrorEnabled) - log.ErrorFormat("Exception:{0}", result.Exception); - - var tipContent = this.localization.GetText("login.exception.tip", "Login exception."); - this.toastRequest.Raise(new ToastNotification(tipContent,2f));/* show toast */ - return; - } - + Account account = await this.accountService.Login(this.username, this.password); if (account != null) { /* login success */ @@ -191,16 +182,24 @@ public async void Login() { /* Login failure */ var tipContent = this.localization.GetText("login.failure.tip", "Login failure."); - this.toastRequest.Raise(new ToastNotification(tipContent,2f));/* show toast */ + this.toastRequest.Raise(new ToastNotification(tipContent, 2f));/* show toast */ } } + catch (Exception e) + { + if (log.IsErrorEnabled) + log.ErrorFormat("Exception:{0}", e); + + var tipContent = this.localization.GetText("login.exception.tip", "Login exception."); + this.toastRequest.Raise(new ToastNotification(tipContent, 2f));/* show toast */ + } finally { this.loginCommand.Enabled = true;/*by databinding, auto set button.interactable = true. */ } } - public IAsyncResult GetAccount() + public Task GetAccount() { return this.accountService.GetAccount(this.Username); } diff --git a/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Views/UI/Startup/ViewModels/StartupViewModel.cs b/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Views/UI/Startup/ViewModels/StartupViewModel.cs index 8558764a..5e36f6d4 100644 --- a/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Views/UI/Startup/ViewModels/StartupViewModel.cs +++ b/Loxodon.Framework/Assets/Samples/Loxodon Framework/2.0.0/Examples/Scripts/Views/UI/Startup/ViewModels/StartupViewModel.cs @@ -22,22 +22,15 @@ * SOFTWARE. */ -using System; -using System.Collections; -using System.Threading; -using UnityEngine; - -using Loxodon.Log; -using Loxodon.Framework.Messaging; using Loxodon.Framework.Asynchronous; using Loxodon.Framework.Commands; -using Loxodon.Framework.ViewModels; -using Loxodon.Framework.Localizations; -using Loxodon.Framework.Interactivity; using Loxodon.Framework.Contexts; -#if NETFX_CORE -using System.Threading.Tasks; -#endif +using Loxodon.Framework.Interactivity; +using Loxodon.Framework.Localizations; +using Loxodon.Framework.Messaging; +using Loxodon.Framework.ViewModels; +using Loxodon.Log; +using UnityEngine; namespace Loxodon.Framework.Examples {