Add newlines to text rendering and display item info

This commit is contained in:
excitedneon 2017-05-14 01:39:10 +03:00
parent 43eb01e9de
commit 5fafaad691
6 changed files with 148 additions and 73 deletions

View File

@ -2211,8 +2211,8 @@ Transform:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1292364954462330} m_GameObject: {fileID: 1292364954462330}
m_LocalRotation: {x: 0.5, y: -0.5, z: 0.5, w: 0.5} m_LocalRotation: {x: 0.5, y: -0.5, z: 0.5, w: 0.5}
m_LocalPosition: {x: -0.03500003, y: 0.564, z: -0.5200002} m_LocalPosition: {x: -0.03500003, y: 0.564, z: -0.54}
m_LocalScale: {x: 0.04500006, y: 0.010000011, z: 0.040000014} m_LocalScale: {x: 0.05, y: 0.01, z: 0.04}
m_Children: [] m_Children: []
m_Father: {fileID: 4236387573765288} m_Father: {fileID: 4236387573765288}
m_RootOrder: 9 m_RootOrder: 9
@ -2448,8 +2448,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1491104319836832} m_GameObject: {fileID: 1491104319836832}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -2480,8 +2480,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1883316003296622} m_GameObject: {fileID: 1883316003296622}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -2512,8 +2512,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1173974356424114} m_GameObject: {fileID: 1173974356424114}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -2576,8 +2576,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1169828016369232} m_GameObject: {fileID: 1169828016369232}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -2608,8 +2608,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1763859699079746} m_GameObject: {fileID: 1763859699079746}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -2640,8 +2640,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1798430208900394} m_GameObject: {fileID: 1798430208900394}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -2672,8 +2672,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1161476972701840} m_GameObject: {fileID: 1161476972701840}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -2704,8 +2704,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1423050520125662} m_GameObject: {fileID: 1423050520125662}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -2736,8 +2736,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1138410146323874} m_GameObject: {fileID: 1138410146323874}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -2768,8 +2768,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1099916689909070} m_GameObject: {fileID: 1099916689909070}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -2832,8 +2832,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1312791058985896} m_GameObject: {fileID: 1312791058985896}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -2896,8 +2896,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1073554920665706} m_GameObject: {fileID: 1073554920665706}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -2960,8 +2960,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1847434687487808} m_GameObject: {fileID: 1847434687487808}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -2992,8 +2992,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1025623427266330} m_GameObject: {fileID: 1025623427266330}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -3024,8 +3024,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1467080138821004} m_GameObject: {fileID: 1467080138821004}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -3056,8 +3056,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1296316799000626} m_GameObject: {fileID: 1296316799000626}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -3120,8 +3120,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1750284427022208} m_GameObject: {fileID: 1750284427022208}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -3152,8 +3152,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1248976874401108} m_GameObject: {fileID: 1248976874401108}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -3216,8 +3216,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1603012649709942} m_GameObject: {fileID: 1603012649709942}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -3248,8 +3248,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1509849257957848} m_GameObject: {fileID: 1509849257957848}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -3376,8 +3376,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1611770961802438} m_GameObject: {fileID: 1611770961802438}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -3408,8 +3408,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1371998637789986} m_GameObject: {fileID: 1371998637789986}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -3440,8 +3440,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1008365958193210} m_GameObject: {fileID: 1008365958193210}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -3472,8 +3472,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1966794789270002} m_GameObject: {fileID: 1966794789270002}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -3536,8 +3536,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1631952559203138} m_GameObject: {fileID: 1631952559203138}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -3568,8 +3568,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1614693744922738} m_GameObject: {fileID: 1614693744922738}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -3635,8 +3635,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1848307522325432} m_GameObject: {fileID: 1848307522325432}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -3699,8 +3699,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1585839934909782} m_GameObject: {fileID: 1585839934909782}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -3731,8 +3731,8 @@ MeshRenderer:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1318315545082708} m_GameObject: {fileID: 1318315545082708}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 1 m_CastShadows: 0
m_ReceiveShadows: 1 m_ReceiveShadows: 0
m_MotionVectors: 1 m_MotionVectors: 1
m_LightProbeUsage: 1 m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1 m_ReflectionProbeUsage: 1
@ -4649,6 +4649,8 @@ MonoBehaviour:
Inventory: {fileID: 114702404122310282} Inventory: {fileID: 114702404122310282}
Camera: {fileID: 20678872378488080} Camera: {fileID: 20678872378488080}
Hologram: {fileID: 114633016952828368} Hologram: {fileID: 114633016952828368}
ItemNameText: {fileID: 114883821079952200}
ItemDescriptionText: {fileID: 114599527678381310}
ItemPreviewMesh: {fileID: 33585471952367662} ItemPreviewMesh: {fileID: 33585471952367662}
ItemPreviewSpinner: {fileID: 114807753601238226} ItemPreviewSpinner: {fileID: 114807753601238226}
IconInventory: {fileID: 23114746529417128} IconInventory: {fileID: 23114746529417128}
@ -4796,15 +4798,14 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
TextProperties: TextProperties:
Text: This item is a rare\npiece of the "way\ntoo long of a name"\ntechnology, Text:
invented\nby space goblins in\nancient times.
OffsetX: 5 OffsetX: 5
OffsetY: 0 OffsetY: 0
Centered: 0 Centered: 0
Background: {r: 0, g: 0, b: 0, a: 0} Background: {r: 0, g: 0, b: 0, a: 0}
FontSize: 32 FontSize: 32
Width: 256 Width: 256
Height: 228 Height: 204
Mesh: {fileID: 23667304044291600} Mesh: {fileID: 23667304044291600}
MaterialIndex: 0 MaterialIndex: 0
Emissive: 0 Emissive: 0
@ -5002,7 +5003,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
TextProperties: TextProperties:
Text: Very Long Item\nName Text:
OffsetX: 5 OffsetX: 5
OffsetY: 0 OffsetY: 0
Centered: 0 Centered: 0

View File

@ -199,12 +199,8 @@ namespace Cyber.Console {
// Set an accurate row length (if the panel is set) // Set an accurate row length (if the panel is set)
if (Panel != null && Panel.GetComponent<RectTransform>() != null) { if (Panel != null && Panel.GetComponent<RectTransform>() != null) {
CharacterInfo CharInfo; float CharacterWidth = FontUtil.GetCharacterWidth(TextField.font,
TextField.font.RequestCharactersInTexture("W", TextField.fontSize,
TextField.fontStyle);
TextField.font.GetCharacterInfo('W', out CharInfo,
TextField.fontSize, TextField.fontStyle); TextField.fontSize, TextField.fontStyle);
float CharacterWidth = CharInfo.glyphWidth - 1;
float PanelWidth = Panel.GetComponent<RectTransform>().rect.width; float PanelWidth = Panel.GetComponent<RectTransform>().rect.width;
RowLength = (int) (PanelWidth / CharacterWidth); RowLength = (int) (PanelWidth / CharacterWidth);
} }

View File

@ -28,6 +28,16 @@ namespace Cyber.Controls {
/// </summary> /// </summary>
public Hologram Hologram; public Hologram Hologram;
/// <summary>
/// The text texture that shows the selected item's name.
/// </summary>
public TextTextureApplier ItemNameText;
/// <summary>
/// The text texture that shows the selected item's description.
/// </summary>
public TextTextureApplier ItemDescriptionText;
/// <summary> /// <summary>
/// The item preview mesh. /// The item preview mesh.
/// </summary> /// </summary>
@ -197,7 +207,21 @@ namespace Cyber.Controls {
Spinning = true; Spinning = true;
} }
if (ItemGridSelectedIndex == i) { if (ItemGridSelectedIndex == i) {
SetPreviewMesh(ItemGridCellMeshes[i].mesh); // Set preview information
SetPreviewMesh(Mesh);
TextTextureProperties NameProps = ItemNameText.TextProperties;
TextTextureProperties DescriptionProps = ItemDescriptionText.TextProperties;
if (Item != null) {
NameProps.Text = Item.Name;
DescriptionProps.Text = Item.Description;
} else {
NameProps.Text = "NULL NAME";
DescriptionProps.Text = "NULL DESC";
}
ItemNameText.SetTextProperties(NameProps);
ItemDescriptionText.SetTextProperties(DescriptionProps);
// Move selector
if ((ItemGridSelector.position - ItemGridCells[i].position).magnitude < 0.01f) { if ((ItemGridSelector.position - ItemGridCells[i].position).magnitude < 0.01f) {
ItemGridSelector.position = ItemGridCells[i].position; ItemGridSelector.position = ItemGridCells[i].position;
} else { } else {

View File

@ -0,0 +1,12 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FontUtil : MonoBehaviour {
public static float GetCharacterWidth(Font font, int fontSize, FontStyle fontStyle) {
CharacterInfo CharInfo;
font.RequestCharactersInTexture("W", fontSize, fontStyle);
font.GetCharacterInfo('W', out CharInfo, fontSize, fontStyle);
return CharInfo.glyphWidth - 1;
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0ab6dbfbebe4b4e11bde0d78e6b3de79
timeCreated: 1494711505
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -31,14 +31,38 @@ namespace Cyber.Util {
} }
private Texture2D RenderText(TextTextureProperties text) { private Texture2D RenderText(TextTextureProperties text) {
// Set scales
float Scale = 2.0f / text.Width; float Scale = 2.0f / text.Width;
Text.text = text.Text.Replace("\\n", "\n");
Text.fontSize = text.FontSize; Text.fontSize = text.FontSize;
Text.characterSize = text.FontSize * Scale * 0.25f; Text.characterSize = text.FontSize * Scale * 0.25f;
// Fix newlines
Text.text = text.Text.Replace("\\n", "\n");
float CharacterWidth = FontUtil.GetCharacterWidth(Text.font,
Text.fontSize, Text.fontStyle);
string FixedText = "";
int CutAmount = 0;
for (int i = 0; i < Text.text.Length; i++) {
int RowLength = i - CutAmount;
string Line = Text.text.Substring(CutAmount, RowLength).Trim() + "\n";
int NextWordLength = 0;
if (Text.text[i] == ' ' && i + 1 < Text.text.Length) {
NextWordLength = Text.text.Substring(i + 1).Split(' ')[0].Length;
}
if ((Line.Length + NextWordLength) * CharacterWidth > text.Width - text.OffsetX ||
Text.text[i] == '\n') {
FixedText += Line;
CutAmount = i;
}
}
FixedText += Text.text.Substring(CutAmount).Trim();
Text.text = FixedText;
// Setup render textures
RenderTexture TextTexture = RenderTexture.GetTemporary(text.Width, text.Height); RenderTexture TextTexture = RenderTexture.GetTemporary(text.Width, text.Height);
RenderTexture OldRT = Camera.targetTexture; RenderTexture OldRT = Camera.targetTexture;
// Calculate positions
float OffsetX = -text.Width / 2f; float OffsetX = -text.Width / 2f;
float OffsetY = -text.Height / 2f; float OffsetY = -text.Height / 2f;
if (text.Centered) { if (text.Centered) {
@ -48,20 +72,26 @@ namespace Cyber.Util {
Text.anchor = TextAnchor.UpperLeft; Text.anchor = TextAnchor.UpperLeft;
} }
Camera.orthographicSize = 1.0f * text.Height / text.Width; Camera.orthographicSize = 1.0f * text.Height / text.Width;
Camera.targetTexture = TextTexture;
Camera.backgroundColor = text.Background;
Camera.transform.localPosition = new Vector3( Camera.transform.localPosition = new Vector3(
-(text.OffsetX + OffsetX) * Scale, -(text.OffsetX + OffsetX) * Scale,
(text.OffsetY + OffsetY) * Scale); (text.OffsetY + OffsetY) * Scale);
// Setup camera
Camera.targetTexture = TextTexture;
Camera.backgroundColor = text.Background;
// *click*
Camera.Render(); Camera.Render();
Camera.targetTexture = OldRT; Camera.targetTexture = OldRT;
// Copy the result to a Texture2D
OldRT = RenderTexture.active; OldRT = RenderTexture.active;
Texture2D Result = new Texture2D(text.Width, text.Height); Texture2D Result = new Texture2D(text.Width, text.Height);
RenderTexture.active = TextTexture; RenderTexture.active = TextTexture;
Result.ReadPixels(new Rect(0, 0, Result.width, Result.height), 0, 0); Result.ReadPixels(new Rect(0, 0, Result.width, Result.height), 0, 0);
Result.Apply(); Result.Apply();
// Clean up
RenderTexture.active = OldRT; RenderTexture.active = OldRT;
RenderTexture.ReleaseTemporary(TextTexture); RenderTexture.ReleaseTemporary(TextTexture);