TextObject
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f44254cc1f80ea34398a1da6d2bdca37
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,254 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using DG.Tweening;
|
||||
using I2.Loc;
|
||||
using Ichni.Editor;
|
||||
using Ichni.RhythmGame.Beatmap;
|
||||
using Ichni.RhythmGame.ThemeBundles.Basic.Beatmap;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ichni.RhythmGame.ThemeBundles.Basic
|
||||
{
|
||||
public partial class TextObject : EnvironmentObject
|
||||
{
|
||||
[SerializeField]
|
||||
private TMP_Text textObject;
|
||||
[SerializeField]
|
||||
private Localize localize;
|
||||
|
||||
public override bool haveEmissionColor => true;
|
||||
|
||||
public float width;
|
||||
public float height;
|
||||
|
||||
public bool isLocalized;
|
||||
public string content;
|
||||
public string fontName;
|
||||
public float size;
|
||||
public HorizontalAlignmentOptions horizontalAlignment;
|
||||
public VerticalAlignmentOptions verticalAlignment;
|
||||
|
||||
public bool isGeneratingOneByOne;
|
||||
public float generateTime;
|
||||
public Tweener oneByOneTweener;
|
||||
|
||||
public static TextObject GenerateElement(string elementName, Guid id, List<string> tags,
|
||||
bool isFirstGenerated, GameElement parentElement, string themeBundleName, string objectName,
|
||||
bool isStatic, float width, float height, string content, bool isLocalized, string fontName, float size,
|
||||
HorizontalAlignmentOptions horizontalAlignment, VerticalAlignmentOptions verticalAlignment,
|
||||
bool isGeneratingOneByOne, float generateTime)
|
||||
{
|
||||
TextObject text = EnvironmentObject.GenerateElement(elementName, id, tags,
|
||||
isFirstGenerated, themeBundleName, objectName, parentElement, isStatic).GetComponent<TextObject>();
|
||||
|
||||
text.width = width;
|
||||
text.height = height;
|
||||
text.content = content;
|
||||
text.fontName = fontName;
|
||||
text.isLocalized = isLocalized;
|
||||
text.size = size;
|
||||
text.horizontalAlignment = horizontalAlignment;
|
||||
text.verticalAlignment = verticalAlignment;
|
||||
text.isGeneratingOneByOne = isGeneratingOneByOne;
|
||||
text.generateTime = generateTime;
|
||||
text.textObject.font = EditorManager.instance.basePrefabs.fonts[fontName];
|
||||
|
||||
//text.textObject.fontMaterial = Instantiate(EditorManager.instance.basePrefabs.fonts[fontName].material);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
public override void AfterInitialize()
|
||||
{
|
||||
base.AfterInitialize();
|
||||
|
||||
timeDurationSubmodule.SetUpObserver(() =>
|
||||
{
|
||||
if (isGeneratingOneByOne)
|
||||
{
|
||||
oneByOneTweener.Kill(true);
|
||||
textObject.text = "";
|
||||
oneByOneTweener = textObject.DOText(GetContent(), generateTime).Play();
|
||||
Debug.Log($"TextObject {objectName} is generating text one by one with duration {generateTime}");
|
||||
}
|
||||
});
|
||||
|
||||
SetWidthAndHeight();
|
||||
SetFont();
|
||||
SetFontSize();
|
||||
SetAlignment();
|
||||
SetContent();
|
||||
}
|
||||
|
||||
public override void Refresh()
|
||||
{
|
||||
base.Refresh();
|
||||
textObject.color = colorSubmodule.currentBaseColor;
|
||||
textObject.fontMaterial.SetColor("_FaceColor", colorSubmodule.GetCurrentEmissionColor());
|
||||
textObject.SetAllDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public partial class TextObject
|
||||
{
|
||||
public override void SaveBM()
|
||||
{
|
||||
matchedBM = new TextObject_BM(elementName, elementGuid, tags, parentElement.matchedBM as GameElement_BM,
|
||||
themeBundleName, objectName, isStatic, width, height, content, isLocalized, fontName, size,
|
||||
horizontalAlignment, verticalAlignment, isGeneratingOneByOne, generateTime);
|
||||
}
|
||||
|
||||
public override void SetUpInspector()
|
||||
{
|
||||
base.SetUpInspector();
|
||||
|
||||
IHaveInspection inspector = EditorManager.instance.uiManager.inspector;
|
||||
var container = inspector.GenerateContainer("Directional Light");
|
||||
var objectSettings = container.GenerateSubcontainer(3);
|
||||
|
||||
var widthField = inspector.GenerateInputField(this, objectSettings, "Width", nameof(width))
|
||||
.AddListenerFunction(SetWidthAndHeight);
|
||||
var heightField = inspector.GenerateInputField(this, objectSettings, "Height", nameof(height))
|
||||
.AddListenerFunction(SetWidthAndHeight);
|
||||
var contentField = inspector.GenerateInputField(this, objectSettings, "Content", nameof(content))
|
||||
.AddListenerFunction(SetContent);
|
||||
var isLocalizedToggle = inspector.GenerateToggle(this, objectSettings, "Is Localized", nameof(isLocalized))
|
||||
.AddListenerFunction(SetContent);
|
||||
var fontNameInputField = inspector.GenerateInputField(this, objectSettings, "Font Name", nameof(fontName))
|
||||
.AddListenerFunction(SetFont);
|
||||
var sizeField = inspector.GenerateInputField(this, objectSettings, "Size", nameof(size))
|
||||
.AddListenerFunction(SetFontSize);
|
||||
var horizontalAlignmentDropdown = inspector.GenerateDropdown(this, objectSettings, "Horizontal Alignment",
|
||||
typeof(HorizontalAlignmentOptions), nameof(horizontalAlignment))
|
||||
.AddListenerFunction(SetAlignment);
|
||||
var verticalAlignmentDropdown = inspector.GenerateDropdown(this, objectSettings, "Vertical Alignment",
|
||||
typeof(VerticalAlignmentOptions), nameof(verticalAlignment))
|
||||
.AddListenerFunction(SetAlignment);
|
||||
var isGeneratingOneByOneToggle = inspector.GenerateToggle(this, objectSettings, "Generate One By One", nameof(isGeneratingOneByOne));
|
||||
var generateTimeField = inspector.GenerateInputField(this, objectSettings, "Generate Time", nameof(generateTime))
|
||||
.AddListenerFunction(() =>
|
||||
{
|
||||
timeDurationSubmodule.SetUpObserver(() =>
|
||||
{
|
||||
if (isGeneratingOneByOne)
|
||||
{
|
||||
oneByOneTweener.Kill(true);
|
||||
textObject.text = "";
|
||||
oneByOneTweener = textObject.DOText(GetContent(), generateTime).Play();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public partial class TextObject
|
||||
{
|
||||
private void SetContent()
|
||||
{
|
||||
if (isLocalized)
|
||||
{
|
||||
localize.SetTerm(content);
|
||||
}
|
||||
else
|
||||
{
|
||||
textObject.text = content;
|
||||
}
|
||||
}
|
||||
|
||||
private string GetContent()
|
||||
{
|
||||
if (isLocalized)
|
||||
{
|
||||
return LocalizationManager.GetTermTranslation(content);
|
||||
}
|
||||
else
|
||||
{
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetWidthAndHeight()
|
||||
{
|
||||
RectTransform rectTransform = textObject.GetComponent<RectTransform>();
|
||||
rectTransform.sizeDelta = new Vector2(width, height);
|
||||
}
|
||||
|
||||
private void SetFont()
|
||||
{
|
||||
if (!EditorManager.instance.basePrefabs.fonts.ContainsKey(fontName))
|
||||
{
|
||||
fontName = "SarasaGothic";
|
||||
}
|
||||
|
||||
textObject.font = EditorManager.instance.basePrefabs.fonts[fontName];
|
||||
//textObject.fontMaterial = Instantiate(EditorManager.instance.basePrefabs.fonts[fontName].material);
|
||||
}
|
||||
|
||||
private void SetFontSize()
|
||||
{
|
||||
textObject.fontSize = size;
|
||||
}
|
||||
|
||||
private void SetAlignment()
|
||||
{
|
||||
textObject.alignment = (TextAlignmentOptions) ((int)horizontalAlignment | (int)verticalAlignment);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace Beatmap
|
||||
{
|
||||
public class TextObject_BM : EnvironmentObject_BM
|
||||
{
|
||||
public float width;
|
||||
public float height;
|
||||
public string content;
|
||||
public bool isLocalized;
|
||||
public string fontName;
|
||||
public float size;
|
||||
public HorizontalAlignmentOptions horizontalAlignment;
|
||||
public VerticalAlignmentOptions verticalAlignment;
|
||||
public bool isGeneratingOneByOne;
|
||||
public float generateTime;
|
||||
|
||||
public TextObject_BM()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public TextObject_BM(string elementName, Guid elementGuid, List<string> tags, GameElement_BM attachedElement,
|
||||
string themeBundleName, string objectName, bool isStatic, float width, float height, string content, bool isLocalized,
|
||||
string fontName, float size, HorizontalAlignmentOptions horizontalAlignment, VerticalAlignmentOptions verticalAlignment,
|
||||
bool isGeneratingOneByOne, float generateTime)
|
||||
: base(elementName, elementGuid, tags, attachedElement, themeBundleName, objectName, isStatic)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.content = content;
|
||||
this.isLocalized = isLocalized;
|
||||
this.fontName = fontName;
|
||||
this.size = size;
|
||||
this.horizontalAlignment = horizontalAlignment;
|
||||
this.verticalAlignment = verticalAlignment;
|
||||
this.isGeneratingOneByOne = isGeneratingOneByOne;
|
||||
this.generateTime = generateTime;
|
||||
}
|
||||
|
||||
public override void ExecuteBM()
|
||||
{
|
||||
matchedElement = TextObject.GenerateElement(elementName, elementGuid, tags, false,
|
||||
GetElement(attachedElementGuid), themeBundleName, objectName, isStatic, width, height, content,
|
||||
isLocalized, fontName, size, horizontalAlignment, verticalAlignment, isGeneratingOneByOne, generateTime);
|
||||
}
|
||||
|
||||
public override GameElement DuplicateBM(GameElement parent)
|
||||
{
|
||||
return TextObject.GenerateElement(elementName, Guid.NewGuid(), tags, false, parent,
|
||||
themeBundleName, objectName, isStatic, width, height, content, isLocalized, fontName, size,
|
||||
horizontalAlignment, verticalAlignment, isGeneratingOneByOne, generateTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e90e53c61dbed234e90f7b745fc89ba1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,43 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ichni.RhythmGame.ThemeBundles.Basic
|
||||
{
|
||||
public class TextTransitionSubmodule : SubmoduleBase
|
||||
{
|
||||
public TextObject textObject;
|
||||
public float startTime;
|
||||
public float startTransitionTime;
|
||||
public float endTime;
|
||||
public float endTransitionTime;
|
||||
|
||||
public TextTransitionSubmodule(TextObject textObject, float startTransitionTime, float endTransitionTime) : base(textObject)
|
||||
{
|
||||
this.textObject = textObject;
|
||||
this.startTime = (textObject as IHaveTimeDurationSubmodule).timeDurationSubmodule.startTime;
|
||||
this.endTime = (textObject as IHaveTimeDurationSubmodule).timeDurationSubmodule.endTime;
|
||||
this.startTransitionTime = startTransitionTime;
|
||||
this.endTransitionTime = endTransitionTime;
|
||||
}
|
||||
|
||||
public virtual void UpdateTransition(float songTime)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void SaveBM()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class TextTransitionSubmoduleFade : TextTransitionSubmodule
|
||||
{
|
||||
public TextTransitionSubmoduleFade(TextObject textObject, float startTransitionTime, float endTransitionTime) :
|
||||
base(textObject, startTransitionTime, endTransitionTime)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f55bcc971764c841a507fa710679034
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user