fzhangtj
6 年前
当前提交
67b248f3
共有 16 个文件被更改,包括 416 次插入 和 316 次删除
-
6Assets/UIWidgets/Tests/Menu.cs
-
2Assets/UIWidgets/painting/text_span.cs
-
1Assets/UIWidgets/painting/text_style.cs
-
2Assets/UIWidgets/rendering/shifted_box.cs
-
1Assets/UIWidgets/ui/painting/canvas_impl.cs
-
2Assets/UIWidgets/ui/text.cs
-
11Assets/UIWidgets/ui/txt/linebreaker.cs
-
251Assets/UIWidgets/ui/txt/paragraph.cs
-
1Assets/UIWidgets/ui/txt/paragraph_builder.cs
-
70Assets/UIWidgets/Resources/UIWidgets_Text.shader
-
3Assets/UIWidgets/Resources/UIWidgets_Text.shader.meta
-
152Assets/UIWidgets/Tests/Paragraph.cs
-
3Assets/UIWidgets/Tests/Text.cs.meta
-
106Assets/UIWidgets/Tests/Text.cs
-
118Assets/UIWidgets/editor/TextMesh.cs
-
3Assets/UIWidgets/editor/TextMesh.cs.meta
|
|||
Shader "UIWidgets/Text Shader" { |
|||
Properties { |
|||
_MainTex ("Font Texture", 2D) = "white" {} |
|||
_Color ("Text Color", Color) = (1,1,1,1) |
|||
} |
|||
|
|||
SubShader { |
|||
|
|||
Tags { |
|||
"Queue"="Transparent" |
|||
"IgnoreProjector"="True" |
|||
"RenderType"="Transparent" |
|||
"PreviewType"="Plane" |
|||
} |
|||
Lighting Off Cull Off ZTest Always ZWrite Off |
|||
Blend SrcAlpha OneMinusSrcAlpha |
|||
|
|||
Pass { |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON |
|||
#include "UnityCG.cginc" |
|||
|
|||
struct appdata_t { |
|||
float4 vertex : POSITION; |
|||
fixed4 color : COLOR; |
|||
float2 texcoord : TEXCOORD0; |
|||
UNITY_VERTEX_INPUT_INSTANCE_ID |
|||
}; |
|||
|
|||
struct v2f { |
|||
float4 vertex : SV_POSITION; |
|||
fixed4 color : COLOR; |
|||
float2 texcoord : TEXCOORD0; |
|||
float2 clipUV : TEXCOORD1; |
|||
UNITY_VERTEX_OUTPUT_STEREO |
|||
}; |
|||
|
|||
sampler2D _MainTex; |
|||
uniform float4 _MainTex_ST; |
|||
uniform fixed4 _Color; |
|||
|
|||
#include "UIWidgets_CG.cginc" |
|||
|
|||
v2f vert (appdata_t v) |
|||
{ |
|||
v2f o; |
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
o.vertex = UnityObjectToClipPos(v.vertex); |
|||
float3 eyePos = UnityObjectToViewPos(v.vertex); |
|||
o.color = v.color * _Color; |
|||
o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); |
|||
o.clipUV = mul(UIWidgets_GUIClipMatrix, float4(eyePos.xy, 0, 1.0)); |
|||
return o; |
|||
} |
|||
|
|||
fixed4 frag (v2f i) : SV_Target |
|||
{ |
|||
fixed4 col = i.color; |
|||
col.a *= tex2D(_MainTex, i.texcoord).a; |
|||
float pixelScale = 1.0f / abs(ddx(i.clipUV.x)); |
|||
col.a *= getClipAlpha(i.clipUV, pixelScale); |
|||
return col; |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 3d9aebae673b434491eb311fc9d0df0f |
|||
timeCreated: 1536033642 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UIWidgets.editor; |
|||
using UIWidgets.painting; |
|||
using UIWidgets.rendering; |
|||
using UIWidgets.ui; |
|||
using UnityEditor; |
|||
using UnityEngine; |
|||
using Color = UIWidgets.ui.Color; |
|||
using FontStyle = UIWidgets.ui.FontStyle; |
|||
using Rect = UIWidgets.ui.Rect; |
|||
|
|||
namespace UIWidgets.Tests |
|||
{ |
|||
public class Paragraph : EditorWindow |
|||
{ |
|||
private readonly Func<RenderBox>[] _options; |
|||
|
|||
private readonly string[] _optionStrings; |
|||
|
|||
private int _selected; |
|||
|
|||
Paragraph() { |
|||
this._options = new Func<RenderBox>[] { |
|||
this.text, |
|||
this.textHeight, |
|||
this.textOverflow |
|||
}; |
|||
this._optionStrings = this._options.Select(x => x.Method.Name).ToArray(); |
|||
this._selected = 0; |
|||
|
|||
this.titleContent = new GUIContent("RenderBoxes"); |
|||
} |
|||
|
|||
private WindowAdapter windowAdapter; |
|||
|
|||
private RendererBindings rendererBindings; |
|||
|
|||
[NonSerialized] private bool hasInvoked = false; |
|||
|
|||
void OnGUI() { |
|||
var selected = EditorGUILayout.Popup("test case", this._selected, this._optionStrings); |
|||
if (selected != this._selected || !this.hasInvoked) { |
|||
this._selected = selected; |
|||
this.hasInvoked = true; |
|||
|
|||
var renderBox = this._options[this._selected](); |
|||
this.rendererBindings.setRoot(renderBox); |
|||
} |
|||
|
|||
if (this.windowAdapter != null) { |
|||
this.windowAdapter.OnGUI(); |
|||
} |
|||
} |
|||
|
|||
void Update() { |
|||
if (this.windowAdapter != null) { |
|||
this.windowAdapter.Update(); |
|||
} |
|||
} |
|||
|
|||
private void OnEnable() { |
|||
this.windowAdapter = new WindowAdapter(this); |
|||
this.rendererBindings = new RendererBindings(this.windowAdapter); |
|||
} |
|||
|
|||
void OnDestroy() { |
|||
this.windowAdapter = null; |
|||
this.rendererBindings = null; |
|||
} |
|||
|
|||
RenderBox none() { |
|||
return null; |
|||
} |
|||
|
|||
private RenderBox box(RenderParagraph p, int width = 300, int height = 300) |
|||
{ |
|||
return new RenderConstrainedOverflowBox( |
|||
minWidth: width, |
|||
maxWidth: width, |
|||
minHeight: height, |
|||
maxHeight: height, |
|||
alignment: Alignment.center, |
|||
child: new RenderDecoratedBox( |
|||
decoration: new BoxDecoration( |
|||
color: new Color(0xFFFFFFFF), |
|||
borderRadius: BorderRadius.all(3), |
|||
border: Border.all(Color.fromARGB(255, 255, 0, 0), 1) |
|||
), |
|||
child: new RenderPadding(EdgeInsets.all(10), p |
|||
) |
|||
) |
|||
); |
|||
} |
|||
|
|||
RenderBox text() |
|||
{ |
|||
return box( |
|||
new RenderParagraph(new TextSpan("", children: |
|||
new List<TextSpan>() |
|||
{ |
|||
new TextSpan("Real-time 3D revolutioni淡粉色的方式地方zes the animation pipeline ", null), |
|||
new TextSpan(style: new painting.TextStyle(color: Color.fromARGB(255, 255, 0, 0)), |
|||
text: "for Disney Television Animation's “Baymax Dreams"), |
|||
new TextSpan(" Unity Widgets"), |
|||
new TextSpan(" Text"), |
|||
new TextSpan("Real-time 3D revolutionizes the animation pipeline "), |
|||
new TextSpan(style: new painting.TextStyle(color: Color.fromARGB(125, 255, 0, 0)), |
|||
text: "Transparent Red Text\n\n"), |
|||
new TextSpan(style: new painting.TextStyle(fontWeight: FontWeight.w700), |
|||
text: "Bold Text Test Bold Textfs Test: FontWeight.w70\n\n"), |
|||
new TextSpan(style: new painting.TextStyle(fontStyle: FontStyle.italic), |
|||
text: "This is FontStyle.italic Text This is FontStyle.italic Text\n\n"), |
|||
new TextSpan(style: new painting.TextStyle(fontStyle: FontStyle.italic, fontWeight: FontWeight.w700), |
|||
text: "This is FontStyle.italic And 发撒放豆腐sad 发生的 Bold Text This is FontStyle.italic And Bold Text\n\n"), |
|||
new TextSpan(style: new painting.TextStyle(fontSize: 18), |
|||
text: "FontSize 18: Get a named matrix value from the shader."), |
|||
new TextSpan(style: new painting.TextStyle(fontSize: 14), |
|||
text: "FontSize 14"), |
|||
}))); |
|||
} |
|||
|
|||
RenderBox textOverflow() |
|||
{ |
|||
return box( |
|||
new RenderParagraph(new TextSpan("", children: |
|||
new List<TextSpan>() |
|||
{ |
|||
new TextSpan("Real-time 3D revolutionizes:\n the animation pipeline.\n\n\revolutionizesn\n\nReal-time 3D revolutionizes the animation pipeline ", null), |
|||
})), 200, 80); |
|||
} |
|||
|
|||
RenderBox textHeight() |
|||
{ |
|||
var text = |
|||
"Hello UIWidgets. Real-time 3D revolutionize \nReal-time 3D revolutionize\nReal-time 3D revolutionize\n\n"; |
|||
return box( |
|||
new RenderParagraph(new TextSpan(text: "", children: |
|||
new List<TextSpan>() |
|||
{ |
|||
new TextSpan(style: new painting.TextStyle(height: 1), |
|||
text: "Height 1.0 Text:" + text), |
|||
new TextSpan(style: new painting.TextStyle(height: 1.2), |
|||
text: "Height 1.2 Text:" + text), |
|||
new TextSpan(style: new painting.TextStyle(height: 1.5), |
|||
text: "Height 1.5 Text:" + text), |
|||
}))); |
|||
} |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f4121086094d45de9e29781269270102 |
|||
timeCreated: 1535424100 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UIWidgets.editor; |
|||
using UIWidgets.painting; |
|||
using UIWidgets.rendering; |
|||
using UIWidgets.ui; |
|||
using UnityEditor; |
|||
using UnityEngine; |
|||
using Color = UIWidgets.ui.Color; |
|||
using FontStyle = UIWidgets.ui.FontStyle; |
|||
using Rect = UIWidgets.ui.Rect; |
|||
|
|||
namespace UIWidgets.Tests |
|||
{ |
|||
public class Text : EditorWindow |
|||
{ |
|||
private readonly Func<RenderBox>[] _options; |
|||
|
|||
private readonly string[] _optionStrings; |
|||
|
|||
private int _selected; |
|||
|
|||
Text() { |
|||
this._options = new Func<RenderBox>[] { |
|||
this.text, |
|||
}; |
|||
this._optionStrings = this._options.Select(x => x.Method.Name).ToArray(); |
|||
this._selected = 0; |
|||
|
|||
this.titleContent = new GUIContent("RenderBoxes"); |
|||
} |
|||
|
|||
private WindowAdapter windowAdapter; |
|||
|
|||
private RendererBindings rendererBindings; |
|||
|
|||
[NonSerialized] private bool hasInvoked = false; |
|||
|
|||
void OnGUI() { |
|||
var selected = EditorGUILayout.Popup("test case", this._selected, this._optionStrings); |
|||
if (selected != this._selected || !this.hasInvoked) { |
|||
this._selected = selected; |
|||
this.hasInvoked = true; |
|||
|
|||
var renderBox = this._options[this._selected](); |
|||
this.rendererBindings.setRoot(renderBox); |
|||
} |
|||
|
|||
if (this.windowAdapter != null) { |
|||
this.windowAdapter.OnGUI(); |
|||
} |
|||
} |
|||
|
|||
void Update() { |
|||
if (this.windowAdapter != null) { |
|||
this.windowAdapter.Update(); |
|||
} |
|||
} |
|||
|
|||
private void OnEnable() { |
|||
this.windowAdapter = new WindowAdapter(this); |
|||
this.rendererBindings = new RendererBindings(this.windowAdapter); |
|||
} |
|||
|
|||
void OnDestroy() { |
|||
this.windowAdapter = null; |
|||
this.rendererBindings = null; |
|||
} |
|||
|
|||
RenderBox none() { |
|||
return null; |
|||
} |
|||
|
|||
RenderBox text() |
|||
{ |
|||
/* |
|||
*bool inherit, Color color, double? fontSize, FontWeight fontWeight, |
|||
FontStyle fontStyle, double letterSpacing, double wordSpacing, |
|||
TextBaseline textBaseline, double height, TextDecoration decoration |
|||
* |
|||
*/ |
|||
var style1 = new painting.TextStyle(true, Color.fromARGB(255, 0, 0, 0), null, FontWeight.w400, FontStyle.normal, 1, |
|||
1, TextBaseline.alphabetic, 1, TextDecoration.none); |
|||
var style2 = new painting.TextStyle(true, Color.fromARGB(255, 255, 0, 0), null, FontWeight.w400, FontStyle.normal, 1, |
|||
1, TextBaseline.alphabetic, 1, TextDecoration.none, fontFamily:"Helvetica"); |
|||
return new RenderConstrainedOverflowBox( |
|||
minWidth: 200, |
|||
maxWidth: 200, |
|||
minHeight: 100, |
|||
maxHeight: 100, |
|||
alignment: Alignment.center, |
|||
// child: new RenderParagraph(new TextSpan(style1, "is is FontStyle fontStyle, double letterSpacing, double wordSpacing, ",
|
|||
// null))
|
|||
child: new RenderParagraph(new TextSpan(style1, "", |
|||
new List<TextSpan>() |
|||
{ |
|||
new TextSpan(null, "Hello sda fdf asdf asd fadsfdfs fdsffsdf d sdfsfsf sd fsfsdf", null), |
|||
new TextSpan(null, "TextBaseline textBaseline, double height, TextDecoration decoration", null), |
|||
new TextSpan(style2, " Unity Widgets", null), |
|||
new TextSpan(null, " Text", null) |
|||
})) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
using UnityEditor; |
|||
using UnityEngine; |
|||
|
|||
namespace UIWidgets.editor |
|||
{ |
|||
public class TextMeshWindow : EditorWindow |
|||
{ |
|||
Font font; |
|||
string str = "Hello World"; |
|||
Mesh mesh; |
|||
|
|||
// Add menu named "My Window" to the Window menu
|
|||
[MenuItem("TextMeshWindow/TextMeshWindow")] |
|||
static void Init() |
|||
{ |
|||
// Get existing open window or if none, make a new one:
|
|||
TextMeshWindow window = (TextMeshWindow)EditorWindow.GetWindow(typeof(TextMeshWindow)); |
|||
window.Show(); |
|||
} |
|||
|
|||
void OnFontTextureRebuilt(Font changedFont) |
|||
{ |
|||
if (changedFont != font) |
|||
return; |
|||
TextGenerator t = new TextGenerator(); |
|||
RebuildMesh(); |
|||
} |
|||
|
|||
|
|||
void RebuildMesh() |
|||
{ |
|||
// Generate a mesh for the characters we want to print.
|
|||
var vertices = new Vector3[str.Length * 4]; |
|||
var triangles = new int[str.Length * 6]; |
|||
var uv = new Vector2[str.Length * 4]; |
|||
Vector3 pos = Vector3.zero; |
|||
for (int i = 0; i < str.Length; i++) |
|||
{ |
|||
// Get character rendering information from the font
|
|||
CharacterInfo ch; |
|||
font.GetCharacterInfo(str[i], out ch); |
|||
|
|||
vertices[4 * i + 0] = pos + new Vector3(ch.minX, -ch.maxY + 100, 0); |
|||
vertices[4 * i + 1] = pos + new Vector3(ch.maxX, -ch.maxY + 100, 0); |
|||
vertices[4 * i + 2] = pos + new Vector3(ch.maxX, -ch.minY + 100, 0); |
|||
vertices[4 * i + 3] = pos + new Vector3(ch.minX, -ch.minY + 100, 0); |
|||
|
|||
uv[4 * i + 0] = ch.uvTopLeft; |
|||
uv[4 * i + 1] = ch.uvTopRight; |
|||
uv[4 * i + 2] = ch.uvBottomRight; |
|||
uv[4 * i + 3] = ch.uvBottomLeft; |
|||
|
|||
triangles[6 * i + 0] = 4 * i + 0; |
|||
triangles[6 * i + 1] = 4 * i + 1; |
|||
triangles[6 * i + 2] = 4 * i + 2; |
|||
|
|||
triangles[6 * i + 3] = 4 * i + 0; |
|||
triangles[6 * i + 4] = 4 * i + 2; |
|||
triangles[6 * i + 5] = 4 * i + 3; |
|||
|
|||
|
|||
|
|||
// Advance character position
|
|||
pos += new Vector3(ch.advance, 0, 0); |
|||
|
|||
} |
|||
mesh.vertices = vertices; |
|||
mesh.triangles = triangles; |
|||
mesh.uv = uv; |
|||
|
|||
} |
|||
|
|||
private void OnEnable() |
|||
{ |
|||
font = Font.CreateDynamicFontFromOSFont("Helvetica", 16); |
|||
// Set the rebuild callback so that the mesh is regenerated on font changes.
|
|||
Font.textureRebuilt += OnFontTextureRebuilt; |
|||
|
|||
// Request characters.
|
|||
font.RequestCharactersInTexture(str); |
|||
|
|||
// Set up mesh.
|
|||
mesh = new Mesh(); |
|||
// Generate font mesh.
|
|||
RebuildMesh(); |
|||
} |
|||
|
|||
void OnGUI() |
|||
{ |
|||
if (Event.current.type == EventType.Repaint) |
|||
{ |
|||
font.RequestCharactersInTexture(str); |
|||
Material mat = font.material; |
|||
mat.SetPass(0); |
|||
Graphics.DrawMeshNow(mesh, Matrix4x4.identity); |
|||
// Graphics.DrawMesh(mesh, new Vector3(0, 0, 100), Quaternion.identity, font.material, 0);
|
|||
} |
|||
|
|||
if (GUI.Button(new Rect(200, 200, 100, 100), "Set Font")) |
|||
{ |
|||
font = Font.CreateDynamicFontFromOSFont("Helvetica", 16); |
|||
|
|||
// Request characters.
|
|||
font.RequestCharactersInTexture(str); |
|||
|
|||
// Set up mesh.
|
|||
mesh = new Mesh(); |
|||
// Generate font mesh.
|
|||
RebuildMesh(); |
|||
} |
|||
} |
|||
|
|||
void OnUpdate() |
|||
{ |
|||
font.RequestCharactersInTexture(str); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 3f658931d0dc4f06817e18cb3a999189 |
|||
timeCreated: 1535014129 |
撰写
预览
正在加载...
取消
保存
Reference in new issue