2024.1.19动画更新

This commit is contained in:
黄嘉宇 2024-01-19 14:27:05 +08:00
parent 8f976ac3a4
commit d431d32210
98 changed files with 68078 additions and 20 deletions

8
Assets/Samples.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3383813eda3576b4c9ad58490372a36d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -3484,6 +3484,84 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 41870865}
m_CullTransparentMesh: 1
--- !u!1 &42336345
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 42336346}
- component: {fileID: 42336348}
- component: {fileID: 42336347}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &42336346
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 42336345}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1561155688}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &42336347
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 42336345}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Button
--- !u!222 &42336348
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 42336345}
m_CullTransparentMesh: 0
--- !u!1 &45578779
GameObject:
m_ObjectHideFlags: 0
@ -7725,7 +7803,8 @@ Transform:
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 9.76, y: -0.09, z: 19.94}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Children:
- {fileID: 1669753533}
m_Father: {fileID: 1205334444}
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -40302,6 +40381,77 @@ MeshFilter:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 502690939}
m_Mesh: {fileID: -6754803190723279696, guid: db232fed5d221ec46aaade28f48500d6, type: 3}
--- !u!1 &506849990
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 506849993}
- component: {fileID: 506849992}
- component: {fileID: 506849991}
m_Layer: 5
m_Name: RawImage
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &506849991
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 506849990}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1344c3c82d62a2a41a3576d8abb8e3ea, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Texture: {fileID: 0}
m_UVRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
--- !u!222 &506849992
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 506849990}
m_CullTransparentMesh: 0
--- !u!224 &506849993
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 506849990}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1669753533}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &507034067
GameObject:
m_ObjectHideFlags: 0
@ -92796,7 +92946,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!114 &1177942911
MonoBehaviour:
m_ObjectHideFlags: 0
@ -92882,8 +93032,8 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1177942910}
m_LocalRotation: {x: -0, y: -0.8733101, z: -0, w: 0.48716483}
m_LocalPosition: {x: -0.22999954, y: 0.9023497, z: 0.49404144}
m_LocalRotation: {x: 0.14953026, y: -0.7221233, z: 0.16476724, w: 0.6550042}
m_LocalPosition: {x: 13.158779, y: 3.848235, z: 4.9711695}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1205334444}
@ -97498,6 +97648,114 @@ PrefabInstance:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: b7165b8870e7eac47931694209670168, type: 3}
--- !u!1001 &1240051023
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 4789867882231697234, guid: 19ae056e58cc5234f89f84768234a5db,
type: 3}
propertyPath: m_Name
value: "\u94A2\u7B4B\u65AD\u88C207 (1)"
objectReference: {fileID: 0}
- target: {fileID: 4789867882231697235, guid: 19ae056e58cc5234f89f84768234a5db,
type: 3}
propertyPath: m_LocalPosition.x
value: -2.37
objectReference: {fileID: 0}
- target: {fileID: 4789867882231697235, guid: 19ae056e58cc5234f89f84768234a5db,
type: 3}
propertyPath: m_LocalPosition.y
value: -0.01
objectReference: {fileID: 0}
- target: {fileID: 4789867882231697235, guid: 19ae056e58cc5234f89f84768234a5db,
type: 3}
propertyPath: m_LocalPosition.z
value: -13.76
objectReference: {fileID: 0}
- target: {fileID: 4789867882231697235, guid: 19ae056e58cc5234f89f84768234a5db,
type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4789867882231697235, guid: 19ae056e58cc5234f89f84768234a5db,
type: 3}
propertyPath: m_LocalRotation.y
value: 0.7071068
objectReference: {fileID: 0}
- target: {fileID: 4789867882231697235, guid: 19ae056e58cc5234f89f84768234a5db,
type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4789867882231697235, guid: 19ae056e58cc5234f89f84768234a5db,
type: 3}
propertyPath: m_LocalRotation.w
value: 0.7071068
objectReference: {fileID: 0}
- target: {fileID: 4789867882231697235, guid: 19ae056e58cc5234f89f84768234a5db,
type: 3}
propertyPath: m_RootOrder
value: 32
objectReference: {fileID: 0}
- target: {fileID: 4789867882231697235, guid: 19ae056e58cc5234f89f84768234a5db,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4789867882231697235, guid: 19ae056e58cc5234f89f84768234a5db,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 90
objectReference: {fileID: 0}
- target: {fileID: 4789867882231697235, guid: 19ae056e58cc5234f89f84768234a5db,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents:
- {fileID: 8494441078995723134, guid: 19ae056e58cc5234f89f84768234a5db, type: 3}
m_SourcePrefab: {fileID: 100100000, guid: 19ae056e58cc5234f89f84768234a5db, type: 3}
--- !u!1 &1240051024 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 8900333873607070236, guid: 19ae056e58cc5234f89f84768234a5db,
type: 3}
m_PrefabInstance: {fileID: 1240051023}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1240051025 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 8494441077332719292, guid: 19ae056e58cc5234f89f84768234a5db,
type: 3}
m_PrefabInstance: {fileID: 1240051023}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1240051026 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 8494441078995723132, guid: 19ae056e58cc5234f89f84768234a5db,
type: 3}
m_PrefabInstance: {fileID: 1240051023}
m_PrefabAsset: {fileID: 0}
--- !u!114 &1240051027
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1240051026}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3c23f798462cfa946b7bb3e2f86cd902, type: 3}
m_Name:
m_EditorClassIdentifier:
objectA: {fileID: 1240051025}
objectB: {fileID: 506849990}
objectC: {fileID: 1240051024}
materialB: {fileID: 0}
delayForA: 1
delayForB: 8
delayForC: 15
delayForMaterialChange: 20
--- !u!1 &1240591123
GameObject:
m_ObjectHideFlags: 0
@ -122914,6 +123172,136 @@ MeshFilter:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1557988862}
m_Mesh: {fileID: -981004378944408349, guid: db232fed5d221ec46aaade28f48500d6, type: 3}
--- !u!1 &1561155687
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1561155688}
- component: {fileID: 1561155691}
- component: {fileID: 1561155690}
- component: {fileID: 1561155689}
m_Layer: 5
m_Name: Button
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1561155688
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1561155687}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 42336346}
m_Father: {fileID: 1669753533}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -330, y: 257}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1561155689
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1561155687}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 1561155690}
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 1240051027}
m_MethodName: StartDisplaySequence
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &1561155690
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1561155687}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &1561155691
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1561155687}
m_CullTransparentMesh: 0
--- !u!1 &1561162834
GameObject:
m_ObjectHideFlags: 0
@ -131990,6 +132378,106 @@ MeshFilter:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1666086774}
m_Mesh: {fileID: -3120473496706713227, guid: 80a81eda5e1bf6949930168da38ca0fe, type: 3}
--- !u!1 &1669753532
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1669753533}
- component: {fileID: 1669753536}
- component: {fileID: 1669753535}
- component: {fileID: 1669753534}
m_Layer: 5
m_Name: Canvas
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1669753533
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1669753532}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 506849993}
- {fileID: 1561155688}
m_Father: {fileID: 89313412}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!114 &1669753534
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1669753532}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreReversedGraphics: 1
m_BlockingObjects: 0
m_BlockingMask:
serializedVersion: 2
m_Bits: 4294967295
--- !u!114 &1669753535
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1669753532}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
--- !u!223 &1669753536
Canvas:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1669753532}
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 0
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_AdditionalShaderChannelsFlag: 0
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!1 &1670670236
GameObject:
m_ObjectHideFlags: 0

8
Assets/TextMesh Pro.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 174aac9bad597df4984b6ac7b52b5101
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f2cf7fb238e6eae4bbf5b1960465c95a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: aa835339c946b2745b1f1636cdec8f54
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,280 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &121924
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 4
m_Component:
- 224: {fileID: 22414422}
- 222: {fileID: 22260028}
- 114: {fileID: 11487728}
m_Layer: 0
m_Name: TextMeshPro Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &188050
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 4
m_Component:
- 224: {fileID: 22450954}
- 222: {fileID: 22204918}
- 114: {fileID: 11486278}
- 114: {fileID: 11427010}
- 114: {fileID: 11405862}
- 225: {fileID: 22524478}
m_Layer: 0
m_Name: Text Popup
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &11405862
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 188050}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1741964061, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalFit: 2
m_VerticalFit: 2
--- !u!114 &11427010
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 188050}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1297475563, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Padding:
m_Left: 10
m_Right: 10
m_Top: 10
m_Bottom: 10
m_ChildAlignment: 0
m_Spacing: 0
m_ChildForceExpandWidth: 1
m_ChildForceExpandHeight: 1
--- !u!114 &11486278
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 188050}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.10542818, g: 0.21589755, b: 0.47794116, a: 0.9411765}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
--- !u!114 &11487728
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 121924}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_text: Sample
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
m_enableVertexGradient: 0
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_outlineColor:
serializedVersion: 2
rgba: 4278190080
m_fontSize: 36
m_fontSizeBase: 36
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_textAlignment: 514
m_isAlignmentEnumConverted: 1
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 0
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_firstOverflowCharacterIndex: -1
m_linkedTextComponent: {fileID: 0}
m_isLinkedTextComponent: 0
m_enableKerning: 1
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
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_firstVisibleCharacter: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: 0, w: 0}
m_textInfo:
textComponent: {fileID: 0}
characterCount: 6
spriteCount: 0
spaceCount: 0
wordCount: 1
linkCount: 0
lineCount: 1
pageCount: 1
materialCount: 1
m_havePropertiesChanged: 1
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_spriteAnimator: {fileID: 0}
m_isInputParsingRequired: 1
m_inputSource: 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: 2100000, guid: 316f956b856b45c448987b5018ec3ef4, type: 2}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!222 &22204918
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 188050}
--- !u!222 &22260028
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 121924}
--- !u!224 &22414422
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 121924}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 22450954}
m_RootOrder: 0
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!224 &22450954
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 188050}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 22414422}
m_Father: {fileID: 0}
m_RootOrder: 0
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!225 &22524478
CanvasGroup:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 188050}
m_Enabled: 1
m_Alpha: 1
m_Interactable: 0
m_BlocksRaycasts: 0
m_IgnoreParentGroups: 0
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 188050}
m_IsPrefabParent: 1

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b06f0e6c1dfa4356ac918da1bb32c603
timeCreated: 1435130987
licenseType: Store
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 56e95bb5bff05654fa4ad551212f8fe0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,128 @@
using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class Benchmark01 : MonoBehaviour
{
public int BenchmarkType = 0;
public TMP_FontAsset TMProFont;
public Font TextMeshFont;
private TextMeshPro m_textMeshPro;
private TextContainer m_textContainer;
private TextMesh m_textMesh;
private const string label01 = "The <#0050FF>count is: </color>{0}";
private const string label02 = "The <color=#0050FF>count is: </color>";
//private string m_string;
//private int m_frame;
private Material m_material01;
private Material m_material02;
IEnumerator Start()
{
if (BenchmarkType == 0) // TextMesh Pro Component
{
m_textMeshPro = gameObject.AddComponent<TextMeshPro>();
m_textMeshPro.autoSizeTextContainer = true;
//m_textMeshPro.anchorDampening = true;
if (TMProFont != null)
m_textMeshPro.font = TMProFont;
//m_textMeshPro.font = Resources.Load("Fonts & Materials/Anton SDF", typeof(TextMeshProFont)) as TextMeshProFont; // Make sure the Anton SDF exists before calling this...
//m_textMeshPro.fontSharedMaterial = Resources.Load("Fonts & Materials/Anton SDF", typeof(Material)) as Material; // Same as above make sure this material exists.
m_textMeshPro.fontSize = 48;
m_textMeshPro.alignment = TextAlignmentOptions.Center;
//m_textMeshPro.anchor = AnchorPositions.Center;
m_textMeshPro.extraPadding = true;
//m_textMeshPro.outlineWidth = 0.25f;
//m_textMeshPro.fontSharedMaterial.SetFloat("_OutlineWidth", 0.2f);
//m_textMeshPro.fontSharedMaterial.EnableKeyword("UNDERLAY_ON");
//m_textMeshPro.lineJustification = LineJustificationTypes.Center;
m_textMeshPro.enableWordWrapping = false;
//m_textMeshPro.lineLength = 60;
//m_textMeshPro.characterSpacing = 0.2f;
//m_textMeshPro.fontColor = new Color32(255, 255, 255, 255);
m_material01 = m_textMeshPro.font.material;
m_material02 = Resources.Load<Material>("Fonts & Materials/LiberationSans SDF - Drop Shadow"); // Make sure the LiberationSans SDF exists before calling this...
}
else if (BenchmarkType == 1) // TextMesh
{
m_textMesh = gameObject.AddComponent<TextMesh>();
if (TextMeshFont != null)
{
m_textMesh.font = TextMeshFont;
m_textMesh.GetComponent<Renderer>().sharedMaterial = m_textMesh.font.material;
}
else
{
m_textMesh.font = Resources.Load("Fonts/ARIAL", typeof(Font)) as Font;
m_textMesh.GetComponent<Renderer>().sharedMaterial = m_textMesh.font.material;
}
m_textMesh.fontSize = 48;
m_textMesh.anchor = TextAnchor.MiddleCenter;
//m_textMesh.color = new Color32(255, 255, 0, 255);
}
for (int i = 0; i <= 1000000; i++)
{
if (BenchmarkType == 0)
{
m_textMeshPro.SetText(label01, i % 1000);
if (i % 1000 == 999)
m_textMeshPro.fontSharedMaterial = m_textMeshPro.fontSharedMaterial == m_material01 ? m_textMeshPro.fontSharedMaterial = m_material02 : m_textMeshPro.fontSharedMaterial = m_material01;
}
else if (BenchmarkType == 1)
m_textMesh.text = label02 + (i % 1000).ToString();
yield return null;
}
yield return null;
}
/*
void Update()
{
if (BenchmarkType == 0)
{
m_textMeshPro.text = (m_frame % 1000).ToString();
}
else if (BenchmarkType == 1)
{
m_textMesh.text = (m_frame % 1000).ToString();
}
m_frame += 1;
}
*/
}
}

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: f970ea55f9f84bf79b05dab180b8c125
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,135 @@
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
namespace TMPro.Examples
{
public class Benchmark01_UGUI : MonoBehaviour
{
public int BenchmarkType = 0;
public Canvas canvas;
public TMP_FontAsset TMProFont;
public Font TextMeshFont;
private TextMeshProUGUI m_textMeshPro;
//private TextContainer m_textContainer;
private Text m_textMesh;
private const string label01 = "The <#0050FF>count is: </color>";
private const string label02 = "The <color=#0050FF>count is: </color>";
//private const string label01 = "TextMesh <#0050FF>Pro!</color> The count is: {0}";
//private const string label02 = "Text Mesh<color=#0050FF> The count is: </color>";
//private string m_string;
//private int m_frame;
private Material m_material01;
private Material m_material02;
IEnumerator Start()
{
if (BenchmarkType == 0) // TextMesh Pro Component
{
m_textMeshPro = gameObject.AddComponent<TextMeshProUGUI>();
//m_textContainer = GetComponent<TextContainer>();
//m_textMeshPro.anchorDampening = true;
if (TMProFont != null)
m_textMeshPro.font = TMProFont;
//m_textMeshPro.font = Resources.Load("Fonts & Materials/Anton SDF", typeof(TextMeshProFont)) as TextMeshProFont; // Make sure the Anton SDF exists before calling this...
//m_textMeshPro.fontSharedMaterial = Resources.Load("Fonts & Materials/Anton SDF", typeof(Material)) as Material; // Same as above make sure this material exists.
m_textMeshPro.fontSize = 48;
m_textMeshPro.alignment = TextAlignmentOptions.Center;
//m_textMeshPro.anchor = AnchorPositions.Center;
m_textMeshPro.extraPadding = true;
//m_textMeshPro.outlineWidth = 0.25f;
//m_textMeshPro.fontSharedMaterial.SetFloat("_OutlineWidth", 0.2f);
//m_textMeshPro.fontSharedMaterial.EnableKeyword("UNDERLAY_ON");
//m_textMeshPro.lineJustification = LineJustificationTypes.Center;
//m_textMeshPro.enableWordWrapping = true;
//m_textMeshPro.lineLength = 60;
//m_textMeshPro.characterSpacing = 0.2f;
//m_textMeshPro.fontColor = new Color32(255, 255, 255, 255);
m_material01 = m_textMeshPro.font.material;
m_material02 = Resources.Load<Material>("Fonts & Materials/LiberationSans SDF - BEVEL"); // Make sure the LiberationSans SDF exists before calling this...
}
else if (BenchmarkType == 1) // TextMesh
{
m_textMesh = gameObject.AddComponent<Text>();
if (TextMeshFont != null)
{
m_textMesh.font = TextMeshFont;
//m_textMesh.renderer.sharedMaterial = m_textMesh.font.material;
}
else
{
//m_textMesh.font = Resources.Load("Fonts/ARIAL", typeof(Font)) as Font;
//m_textMesh.renderer.sharedMaterial = m_textMesh.font.material;
}
m_textMesh.fontSize = 48;
m_textMesh.alignment = TextAnchor.MiddleCenter;
//m_textMesh.color = new Color32(255, 255, 0, 255);
}
for (int i = 0; i <= 1000000; i++)
{
if (BenchmarkType == 0)
{
m_textMeshPro.text = label01 + (i % 1000);
if (i % 1000 == 999)
m_textMeshPro.fontSharedMaterial = m_textMeshPro.fontSharedMaterial == m_material01 ? m_textMeshPro.fontSharedMaterial = m_material02 : m_textMeshPro.fontSharedMaterial = m_material01;
}
else if (BenchmarkType == 1)
m_textMesh.text = label02 + (i % 1000).ToString();
yield return null;
}
yield return null;
}
/*
void Update()
{
if (BenchmarkType == 0)
{
m_textMeshPro.text = (m_frame % 1000).ToString();
}
else if (BenchmarkType == 1)
{
m_textMesh.text = (m_frame % 1000).ToString();
}
m_frame += 1;
}
*/
}
}

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 8ef7be1c625941f7ba8ed7cc71718c0d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,97 @@
using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class Benchmark02 : MonoBehaviour
{
public int SpawnType = 0;
public int NumberOfNPC = 12;
//public bool IsTextObjectScaleStatic;
private TextMeshProFloatingText floatingText_Script;
void Start()
{
for (int i = 0; i < NumberOfNPC; i++)
{
if (SpawnType == 0)
{
// TextMesh Pro Implementation
GameObject go = new GameObject();
go.transform.position = new Vector3(Random.Range(-95f, 95f), 0.25f, Random.Range(-95f, 95f));
TextMeshPro textMeshPro = go.AddComponent<TextMeshPro>();
textMeshPro.autoSizeTextContainer = true;
textMeshPro.rectTransform.pivot = new Vector2(0.5f, 0);
textMeshPro.alignment = TextAlignmentOptions.Bottom;
textMeshPro.fontSize = 96;
textMeshPro.enableKerning = false;
textMeshPro.color = new Color32(255, 255, 0, 255);
textMeshPro.text = "!";
//textMeshPro.isTextObjectScaleStatic = IsTextObjectScaleStatic;
// Spawn Floating Text
floatingText_Script = go.AddComponent<TextMeshProFloatingText>();
floatingText_Script.SpawnType = 0;
// floatingText_Script.IsTextObjectScaleStatic = IsTextObjectScaleStatic;
}
else if (SpawnType == 1)
{
// TextMesh Implementation
GameObject go = new GameObject();
go.transform.position = new Vector3(Random.Range(-95f, 95f), 0.25f, Random.Range(-95f, 95f));
TextMesh textMesh = go.AddComponent<TextMesh>();
textMesh.font = Resources.Load<Font>("Fonts/ARIAL");
textMesh.GetComponent<Renderer>().sharedMaterial = textMesh.font.material;
textMesh.anchor = TextAnchor.LowerCenter;
textMesh.fontSize = 96;
textMesh.color = new Color32(255, 255, 0, 255);
textMesh.text = "!";
// Spawn Floating Text
floatingText_Script = go.AddComponent<TextMeshProFloatingText>();
floatingText_Script.SpawnType = 1;
}
else if (SpawnType == 2)
{
// Canvas WorldSpace Camera
GameObject go = new GameObject();
Canvas canvas = go.AddComponent<Canvas>();
canvas.worldCamera = Camera.main;
go.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
go.transform.position = new Vector3(Random.Range(-95f, 95f), 5f, Random.Range(-95f, 95f));
TextMeshProUGUI textObject = new GameObject().AddComponent<TextMeshProUGUI>();
textObject.rectTransform.SetParent(go.transform, false);
textObject.color = new Color32(255, 255, 0, 255);
textObject.alignment = TextAlignmentOptions.Bottom;
textObject.fontSize = 96;
textObject.text = "!";
// Spawn Floating Text
floatingText_Script = go.AddComponent<TextMeshProFloatingText>();
floatingText_Script.SpawnType = 0;
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e8538afcddc14efbb5d9e94b7ae50197
MonoImporter:
serializedVersion: 2
defaultReferences:
- TheFont: {instanceID: 0}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,92 @@
using UnityEngine;
using System.Collections;
using UnityEngine.TextCore.LowLevel;
namespace TMPro.Examples
{
public class Benchmark03 : MonoBehaviour
{
public enum BenchmarkType { TMP_SDF_MOBILE = 0, TMP_SDF__MOBILE_SSD = 1, TMP_SDF = 2, TMP_BITMAP_MOBILE = 3, TEXTMESH_BITMAP = 4 }
public int NumberOfSamples = 100;
public BenchmarkType Benchmark;
public Font SourceFont;
void Awake()
{
}
void Start()
{
TMP_FontAsset fontAsset = null;
// Create Dynamic Font Asset for the given font file.
switch (Benchmark)
{
case BenchmarkType.TMP_SDF_MOBILE:
fontAsset = TMP_FontAsset.CreateFontAsset(SourceFont, 90, 9, GlyphRenderMode.SDFAA, 256, 256, AtlasPopulationMode.Dynamic);
break;
case BenchmarkType.TMP_SDF__MOBILE_SSD:
fontAsset = TMP_FontAsset.CreateFontAsset(SourceFont, 90, 9, GlyphRenderMode.SDFAA, 256, 256, AtlasPopulationMode.Dynamic);
fontAsset.material.shader = Shader.Find("TextMeshPro/Mobile/Distance Field SSD");
break;
case BenchmarkType.TMP_SDF:
fontAsset = TMP_FontAsset.CreateFontAsset(SourceFont, 90, 9, GlyphRenderMode.SDFAA, 256, 256, AtlasPopulationMode.Dynamic);
fontAsset.material.shader = Shader.Find("TextMeshPro/Distance Field");
break;
case BenchmarkType.TMP_BITMAP_MOBILE:
fontAsset = TMP_FontAsset.CreateFontAsset(SourceFont, 90, 9, GlyphRenderMode.SMOOTH, 256, 256, AtlasPopulationMode.Dynamic);
break;
}
for (int i = 0; i < NumberOfSamples; i++)
{
switch (Benchmark)
{
case BenchmarkType.TMP_SDF_MOBILE:
case BenchmarkType.TMP_SDF__MOBILE_SSD:
case BenchmarkType.TMP_SDF:
case BenchmarkType.TMP_BITMAP_MOBILE:
{
GameObject go = new GameObject();
go.transform.position = new Vector3(0, 1.2f, 0);
TextMeshPro textComponent = go.AddComponent<TextMeshPro>();
textComponent.font = fontAsset;
textComponent.fontSize = 128;
textComponent.text = "@";
textComponent.alignment = TextAlignmentOptions.Center;
textComponent.color = new Color32(255, 255, 0, 255);
if (Benchmark == BenchmarkType.TMP_BITMAP_MOBILE)
textComponent.fontSize = 132;
}
break;
case BenchmarkType.TEXTMESH_BITMAP:
{
GameObject go = new GameObject();
go.transform.position = new Vector3(0, 1.2f, 0);
TextMesh textMesh = go.AddComponent<TextMesh>();
textMesh.GetComponent<Renderer>().sharedMaterial = SourceFont.material;
textMesh.font = SourceFont;
textMesh.anchor = TextAnchor.MiddleCenter;
textMesh.fontSize = 130;
textMesh.color = new Color32(255, 255, 0, 255);
textMesh.text = "@";
}
break;
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a73109742c8d47ac822895a473300c29
MonoImporter:
serializedVersion: 2
defaultReferences:
- TheFont: {instanceID: 0}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,85 @@
using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class Benchmark04 : MonoBehaviour
{
public int SpawnType = 0;
public int MinPointSize = 12;
public int MaxPointSize = 64;
public int Steps = 4;
private Transform m_Transform;
//private TextMeshProFloatingText floatingText_Script;
//public Material material;
void Start()
{
m_Transform = transform;
float lineHeight = 0;
float orthoSize = Camera.main.orthographicSize = Screen.height / 2;
float ratio = (float)Screen.width / Screen.height;
for (int i = MinPointSize; i <= MaxPointSize; i += Steps)
{
if (SpawnType == 0)
{
// TextMesh Pro Implementation
GameObject go = new GameObject("Text - " + i + " Pts");
if (lineHeight > orthoSize * 2) return;
go.transform.position = m_Transform.position + new Vector3(ratio * -orthoSize * 0.975f, orthoSize * 0.975f - lineHeight, 0);
TextMeshPro textMeshPro = go.AddComponent<TextMeshPro>();
//textMeshPro.fontSharedMaterial = material;
//textMeshPro.font = Resources.Load("Fonts & Materials/LiberationSans SDF", typeof(TextMeshProFont)) as TextMeshProFont;
//textMeshPro.anchor = AnchorPositions.Left;
textMeshPro.rectTransform.pivot = new Vector2(0, 0.5f);
textMeshPro.enableWordWrapping = false;
textMeshPro.extraPadding = true;
textMeshPro.isOrthographic = true;
textMeshPro.fontSize = i;
textMeshPro.text = i + " pts - Lorem ipsum dolor sit...";
textMeshPro.color = new Color32(255, 255, 255, 255);
lineHeight += i;
}
else
{
// TextMesh Implementation
// Causes crashes since atlas needed exceeds 4096 X 4096
/*
GameObject go = new GameObject("Arial " + i);
//if (lineHeight > orthoSize * 2 * 0.9f) return;
go.transform.position = m_Transform.position + new Vector3(ratio * -orthoSize * 0.975f, orthoSize * 0.975f - lineHeight, 1);
TextMesh textMesh = go.AddComponent<TextMesh>();
textMesh.font = Resources.Load("Fonts/ARIAL", typeof(Font)) as Font;
textMesh.renderer.sharedMaterial = textMesh.font.material;
textMesh.anchor = TextAnchor.MiddleLeft;
textMesh.fontSize = i * 10;
textMesh.color = new Color32(255, 255, 255, 255);
textMesh.text = i + " pts - Lorem ipsum dolor sit...";
lineHeight += i;
*/
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dc20866c0d5e413ab7559440e15333ae
MonoImporter:
serializedVersion: 2
defaultReferences:
- TheFont: {instanceID: 0}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,292 @@
using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class CameraController : MonoBehaviour
{
public enum CameraModes { Follow, Isometric, Free }
private Transform cameraTransform;
private Transform dummyTarget;
public Transform CameraTarget;
public float FollowDistance = 30.0f;
public float MaxFollowDistance = 100.0f;
public float MinFollowDistance = 2.0f;
public float ElevationAngle = 30.0f;
public float MaxElevationAngle = 85.0f;
public float MinElevationAngle = 0f;
public float OrbitalAngle = 0f;
public CameraModes CameraMode = CameraModes.Follow;
public bool MovementSmoothing = true;
public bool RotationSmoothing = false;
private bool previousSmoothing;
public float MovementSmoothingValue = 25f;
public float RotationSmoothingValue = 5.0f;
public float MoveSensitivity = 2.0f;
private Vector3 currentVelocity = Vector3.zero;
private Vector3 desiredPosition;
private float mouseX;
private float mouseY;
private Vector3 moveVector;
private float mouseWheel;
// Controls for Touches on Mobile devices
//private float prev_ZoomDelta;
private const string event_SmoothingValue = "Slider - Smoothing Value";
private const string event_FollowDistance = "Slider - Camera Zoom";
void Awake()
{
if (QualitySettings.vSyncCount > 0)
Application.targetFrameRate = 60;
else
Application.targetFrameRate = -1;
if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android)
Input.simulateMouseWithTouches = false;
cameraTransform = transform;
previousSmoothing = MovementSmoothing;
}
// Use this for initialization
void Start()
{
if (CameraTarget == null)
{
// If we don't have a target (assigned by the player, create a dummy in the center of the scene).
dummyTarget = new GameObject("Camera Target").transform;
CameraTarget = dummyTarget;
}
}
// Update is called once per frame
void LateUpdate()
{
GetPlayerInput();
// Check if we still have a valid target
if (CameraTarget != null)
{
if (CameraMode == CameraModes.Isometric)
{
desiredPosition = CameraTarget.position + Quaternion.Euler(ElevationAngle, OrbitalAngle, 0f) * new Vector3(0, 0, -FollowDistance);
}
else if (CameraMode == CameraModes.Follow)
{
desiredPosition = CameraTarget.position + CameraTarget.TransformDirection(Quaternion.Euler(ElevationAngle, OrbitalAngle, 0f) * (new Vector3(0, 0, -FollowDistance)));
}
else
{
// Free Camera implementation
}
if (MovementSmoothing == true)
{
// Using Smoothing
cameraTransform.position = Vector3.SmoothDamp(cameraTransform.position, desiredPosition, ref currentVelocity, MovementSmoothingValue * Time.fixedDeltaTime);
//cameraTransform.position = Vector3.Lerp(cameraTransform.position, desiredPosition, Time.deltaTime * 5.0f);
}
else
{
// Not using Smoothing
cameraTransform.position = desiredPosition;
}
if (RotationSmoothing == true)
cameraTransform.rotation = Quaternion.Lerp(cameraTransform.rotation, Quaternion.LookRotation(CameraTarget.position - cameraTransform.position), RotationSmoothingValue * Time.deltaTime);
else
{
cameraTransform.LookAt(CameraTarget);
}
}
}
void GetPlayerInput()
{
moveVector = Vector3.zero;
// Check Mouse Wheel Input prior to Shift Key so we can apply multiplier on Shift for Scrolling
mouseWheel = Input.GetAxis("Mouse ScrollWheel");
float touchCount = Input.touchCount;
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift) || touchCount > 0)
{
mouseWheel *= 10;
if (Input.GetKeyDown(KeyCode.I))
CameraMode = CameraModes.Isometric;
if (Input.GetKeyDown(KeyCode.F))
CameraMode = CameraModes.Follow;
if (Input.GetKeyDown(KeyCode.S))
MovementSmoothing = !MovementSmoothing;
// Check for right mouse button to change camera follow and elevation angle
if (Input.GetMouseButton(1))
{
mouseY = Input.GetAxis("Mouse Y");
mouseX = Input.GetAxis("Mouse X");
if (mouseY > 0.01f || mouseY < -0.01f)
{
ElevationAngle -= mouseY * MoveSensitivity;
// Limit Elevation angle between min & max values.
ElevationAngle = Mathf.Clamp(ElevationAngle, MinElevationAngle, MaxElevationAngle);
}
if (mouseX > 0.01f || mouseX < -0.01f)
{
OrbitalAngle += mouseX * MoveSensitivity;
if (OrbitalAngle > 360)
OrbitalAngle -= 360;
if (OrbitalAngle < 0)
OrbitalAngle += 360;
}
}
// Get Input from Mobile Device
if (touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
Vector2 deltaPosition = Input.GetTouch(0).deltaPosition;
// Handle elevation changes
if (deltaPosition.y > 0.01f || deltaPosition.y < -0.01f)
{
ElevationAngle -= deltaPosition.y * 0.1f;
// Limit Elevation angle between min & max values.
ElevationAngle = Mathf.Clamp(ElevationAngle, MinElevationAngle, MaxElevationAngle);
}
// Handle left & right
if (deltaPosition.x > 0.01f || deltaPosition.x < -0.01f)
{
OrbitalAngle += deltaPosition.x * 0.1f;
if (OrbitalAngle > 360)
OrbitalAngle -= 360;
if (OrbitalAngle < 0)
OrbitalAngle += 360;
}
}
// Check for left mouse button to select a new CameraTarget or to reset Follow position
if (Input.GetMouseButton(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 300, 1 << 10 | 1 << 11 | 1 << 12 | 1 << 14))
{
if (hit.transform == CameraTarget)
{
// Reset Follow Position
OrbitalAngle = 0;
}
else
{
CameraTarget = hit.transform;
OrbitalAngle = 0;
MovementSmoothing = previousSmoothing;
}
}
}
if (Input.GetMouseButton(2))
{
if (dummyTarget == null)
{
// We need a Dummy Target to anchor the Camera
dummyTarget = new GameObject("Camera Target").transform;
dummyTarget.position = CameraTarget.position;
dummyTarget.rotation = CameraTarget.rotation;
CameraTarget = dummyTarget;
previousSmoothing = MovementSmoothing;
MovementSmoothing = false;
}
else if (dummyTarget != CameraTarget)
{
// Move DummyTarget to CameraTarget
dummyTarget.position = CameraTarget.position;
dummyTarget.rotation = CameraTarget.rotation;
CameraTarget = dummyTarget;
previousSmoothing = MovementSmoothing;
MovementSmoothing = false;
}
mouseY = Input.GetAxis("Mouse Y");
mouseX = Input.GetAxis("Mouse X");
moveVector = cameraTransform.TransformDirection(mouseX, mouseY, 0);
dummyTarget.Translate(-moveVector, Space.World);
}
}
// Check Pinching to Zoom in - out on Mobile device
if (touchCount == 2)
{
Touch touch0 = Input.GetTouch(0);
Touch touch1 = Input.GetTouch(1);
Vector2 touch0PrevPos = touch0.position - touch0.deltaPosition;
Vector2 touch1PrevPos = touch1.position - touch1.deltaPosition;
float prevTouchDelta = (touch0PrevPos - touch1PrevPos).magnitude;
float touchDelta = (touch0.position - touch1.position).magnitude;
float zoomDelta = prevTouchDelta - touchDelta;
if (zoomDelta > 0.01f || zoomDelta < -0.01f)
{
FollowDistance += zoomDelta * 0.25f;
// Limit FollowDistance between min & max values.
FollowDistance = Mathf.Clamp(FollowDistance, MinFollowDistance, MaxFollowDistance);
}
}
// Check MouseWheel to Zoom in-out
if (mouseWheel < -0.01f || mouseWheel > 0.01f)
{
FollowDistance -= mouseWheel * 5.0f;
// Limit FollowDistance between min & max values.
FollowDistance = Mathf.Clamp(FollowDistance, MinFollowDistance, MaxFollowDistance);
}
}
}
}

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 2d687537154440a3913a9a3c7977978c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,51 @@
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class ChatController : MonoBehaviour {
public TMP_InputField ChatInputField;
public TMP_Text ChatDisplayOutput;
public Scrollbar ChatScrollbar;
void OnEnable()
{
ChatInputField.onSubmit.AddListener(AddToChatOutput);
}
void OnDisable()
{
ChatInputField.onSubmit.RemoveListener(AddToChatOutput);
}
void AddToChatOutput(string newText)
{
// Clear Input Field
ChatInputField.text = string.Empty;
var timeNow = System.DateTime.Now;
string formattedInput = "[<#FFFF80>" + timeNow.Hour.ToString("d2") + ":" + timeNow.Minute.ToString("d2") + ":" + timeNow.Second.ToString("d2") + "</color>] " + newText;
if (ChatDisplayOutput != null)
{
// No special formatting for first entry
// Add line feed before each subsequent entries
if (ChatDisplayOutput.text == string.Empty)
ChatDisplayOutput.text = formattedInput;
else
ChatDisplayOutput.text += "\n" + formattedInput;
}
// Keep Chat input field active
ChatInputField.ActivateInputField();
// Set the scrollbar to the bottom when next text is submitted.
ChatScrollbar.value = 0;
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 53d91f98a2664f5cb9af11de72ac54ec
timeCreated: 1487197841
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,19 @@
using TMPro;
using UnityEngine;
public class DropdownSample: MonoBehaviour
{
[SerializeField]
private TextMeshProUGUI text = null;
[SerializeField]
private TMP_Dropdown dropdownWithoutPlaceholder = null;
[SerializeField]
private TMP_Dropdown dropdownWithPlaceholder = null;
public void OnButtonClick()
{
text.text = dropdownWithPlaceholder.value > -1 ? "Selected values:\n" + dropdownWithoutPlaceholder.value + " - " + dropdownWithPlaceholder.value : "Error: Please make a selection";
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ac1eb05af6d391b4eb0f4c070a99f1d0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,35 @@
using UnityEngine;
using System.Collections;
using TMPro;
public class EnvMapAnimator : MonoBehaviour {
//private Vector3 TranslationSpeeds;
public Vector3 RotationSpeeds;
private TMP_Text m_textMeshPro;
private Material m_material;
void Awake()
{
//Debug.Log("Awake() on Script called.");
m_textMeshPro = GetComponent<TMP_Text>();
m_material = m_textMeshPro.fontSharedMaterial;
}
// Use this for initialization
IEnumerator Start ()
{
Matrix4x4 matrix = new Matrix4x4();
while (true)
{
//matrix.SetTRS(new Vector3 (Time.time * TranslationSpeeds.x, Time.time * TranslationSpeeds.y, Time.time * TranslationSpeeds.z), Quaternion.Euler(Time.time * RotationSpeeds.x, Time.time * RotationSpeeds.y , Time.time * RotationSpeeds.z), Vector3.one);
matrix.SetTRS(Vector3.zero, Quaternion.Euler(Time.time * RotationSpeeds.x, Time.time * RotationSpeeds.y , Time.time * RotationSpeeds.z), Vector3.one);
m_material.SetMatrix("_EnvMatrix", matrix);
yield return null;
}
}
}

View File

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

View File

@ -0,0 +1,69 @@
using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class ObjectSpin : MonoBehaviour
{
#pragma warning disable 0414
public float SpinSpeed = 5;
public int RotationRange = 15;
private Transform m_transform;
private float m_time;
private Vector3 m_prevPOS;
private Vector3 m_initial_Rotation;
private Vector3 m_initial_Position;
private Color32 m_lightColor;
private int frames = 0;
public enum MotionType { Rotation, BackAndForth, Translation };
public MotionType Motion;
void Awake()
{
m_transform = transform;
m_initial_Rotation = m_transform.rotation.eulerAngles;
m_initial_Position = m_transform.position;
Light light = GetComponent<Light>();
m_lightColor = light != null ? light.color : Color.black;
}
// Update is called once per frame
void Update()
{
if (Motion == MotionType.Rotation)
{
m_transform.Rotate(0, SpinSpeed * Time.deltaTime, 0);
}
else if (Motion == MotionType.BackAndForth)
{
m_time += SpinSpeed * Time.deltaTime;
m_transform.rotation = Quaternion.Euler(m_initial_Rotation.x, Mathf.Sin(m_time) * RotationRange + m_initial_Rotation.y, m_initial_Rotation.z);
}
else
{
m_time += SpinSpeed * Time.deltaTime;
float x = 15 * Mathf.Cos(m_time * .95f);
float y = 10; // *Mathf.Sin(m_time * 1f) * Mathf.Cos(m_time * 1f);
float z = 0f; // *Mathf.Sin(m_time * .9f);
m_transform.position = m_initial_Position + new Vector3(x, z, y);
// Drawing light patterns because they can be cool looking.
//if (frames > 2)
// Debug.DrawLine(m_transform.position, m_prevPOS, m_lightColor, 100f);
m_prevPOS = m_transform.position;
frames += 1;
}
}
}
}

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 4f19c7f94c794c5097d8bd11e39c750d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,51 @@
using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class ShaderPropAnimator : MonoBehaviour
{
private Renderer m_Renderer;
private Material m_Material;
public AnimationCurve GlowCurve;
public float m_frame;
void Awake()
{
// Cache a reference to object's renderer
m_Renderer = GetComponent<Renderer>();
// Cache a reference to object's material and create an instance by doing so.
m_Material = m_Renderer.material;
}
void Start()
{
StartCoroutine(AnimateProperties());
}
IEnumerator AnimateProperties()
{
//float lightAngle;
float glowPower;
m_frame = Random.Range(0f, 1f);
while (true)
{
//lightAngle = (m_Material.GetFloat(ShaderPropertyIDs.ID_LightAngle) + Time.deltaTime) % 6.2831853f;
//m_Material.SetFloat(ShaderPropertyIDs.ID_LightAngle, lightAngle);
glowPower = GlowCurve.Evaluate(m_frame);
m_Material.SetFloat(ShaderUtilities.ID_GlowPower, glowPower);
m_frame += Time.deltaTime * Random.Range(0.2f, 0.3f);
yield return new WaitForEndOfFrame();
}
}
}
}

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 2787a46a4dc848c1b4b7b9307b614bfd
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,58 @@
using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class SimpleScript : MonoBehaviour
{
private TextMeshPro m_textMeshPro;
//private TMP_FontAsset m_FontAsset;
private const string label = "The <#0050FF>count is: </color>{0:2}";
private float m_frame;
void Start()
{
// Add new TextMesh Pro Component
m_textMeshPro = gameObject.AddComponent<TextMeshPro>();
m_textMeshPro.autoSizeTextContainer = true;
// Load the Font Asset to be used.
//m_FontAsset = Resources.Load("Fonts & Materials/LiberationSans SDF", typeof(TMP_FontAsset)) as TMP_FontAsset;
//m_textMeshPro.font = m_FontAsset;
// Assign Material to TextMesh Pro Component
//m_textMeshPro.fontSharedMaterial = Resources.Load("Fonts & Materials/LiberationSans SDF - Bevel", typeof(Material)) as Material;
//m_textMeshPro.fontSharedMaterial.EnableKeyword("BEVEL_ON");
// Set various font settings.
m_textMeshPro.fontSize = 48;
m_textMeshPro.alignment = TextAlignmentOptions.Center;
//m_textMeshPro.anchorDampening = true; // Has been deprecated but under consideration for re-implementation.
//m_textMeshPro.enableAutoSizing = true;
//m_textMeshPro.characterSpacing = 0.2f;
//m_textMeshPro.wordSpacing = 0.1f;
//m_textMeshPro.enableCulling = true;
m_textMeshPro.enableWordWrapping = false;
//textMeshPro.fontColor = new Color32(255, 255, 255, 255);
}
void Update()
{
m_textMeshPro.SetText(label, m_frame % 1000);
m_frame += 1 * Time.deltaTime;
}
}
}

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 9eff140b25d64601aabc6ba32245d099
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,158 @@
using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class SkewTextExample : MonoBehaviour
{
private TMP_Text m_TextComponent;
public AnimationCurve VertexCurve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.25f, 2.0f), new Keyframe(0.5f, 0), new Keyframe(0.75f, 2.0f), new Keyframe(1, 0f));
//public float AngleMultiplier = 1.0f;
//public float SpeedMultiplier = 1.0f;
public float CurveScale = 1.0f;
public float ShearAmount = 1.0f;
void Awake()
{
m_TextComponent = gameObject.GetComponent<TMP_Text>();
}
void Start()
{
StartCoroutine(WarpText());
}
private AnimationCurve CopyAnimationCurve(AnimationCurve curve)
{
AnimationCurve newCurve = new AnimationCurve();
newCurve.keys = curve.keys;
return newCurve;
}
/// <summary>
/// Method to curve text along a Unity animation curve.
/// </summary>
/// <param name="textComponent"></param>
/// <returns></returns>
IEnumerator WarpText()
{
VertexCurve.preWrapMode = WrapMode.Clamp;
VertexCurve.postWrapMode = WrapMode.Clamp;
//Mesh mesh = m_TextComponent.textInfo.meshInfo[0].mesh;
Vector3[] vertices;
Matrix4x4 matrix;
m_TextComponent.havePropertiesChanged = true; // Need to force the TextMeshPro Object to be updated.
CurveScale *= 10;
float old_CurveScale = CurveScale;
float old_ShearValue = ShearAmount;
AnimationCurve old_curve = CopyAnimationCurve(VertexCurve);
while (true)
{
if (!m_TextComponent.havePropertiesChanged && old_CurveScale == CurveScale && old_curve.keys[1].value == VertexCurve.keys[1].value && old_ShearValue == ShearAmount)
{
yield return null;
continue;
}
old_CurveScale = CurveScale;
old_curve = CopyAnimationCurve(VertexCurve);
old_ShearValue = ShearAmount;
m_TextComponent.ForceMeshUpdate(); // Generate the mesh and populate the textInfo with data we can use and manipulate.
TMP_TextInfo textInfo = m_TextComponent.textInfo;
int characterCount = textInfo.characterCount;
if (characterCount == 0) continue;
//vertices = textInfo.meshInfo[0].vertices;
//int lastVertexIndex = textInfo.characterInfo[characterCount - 1].vertexIndex;
float boundsMinX = m_TextComponent.bounds.min.x; //textInfo.meshInfo[0].mesh.bounds.min.x;
float boundsMaxX = m_TextComponent.bounds.max.x; //textInfo.meshInfo[0].mesh.bounds.max.x;
for (int i = 0; i < characterCount; i++)
{
if (!textInfo.characterInfo[i].isVisible)
continue;
int vertexIndex = textInfo.characterInfo[i].vertexIndex;
// Get the index of the mesh used by this character.
int materialIndex = textInfo.characterInfo[i].materialReferenceIndex;
vertices = textInfo.meshInfo[materialIndex].vertices;
// Compute the baseline mid point for each character
Vector3 offsetToMidBaseline = new Vector2((vertices[vertexIndex + 0].x + vertices[vertexIndex + 2].x) / 2, textInfo.characterInfo[i].baseLine);
//float offsetY = VertexCurve.Evaluate((float)i / characterCount + loopCount / 50f); // Random.Range(-0.25f, 0.25f);
// Apply offset to adjust our pivot point.
vertices[vertexIndex + 0] += -offsetToMidBaseline;
vertices[vertexIndex + 1] += -offsetToMidBaseline;
vertices[vertexIndex + 2] += -offsetToMidBaseline;
vertices[vertexIndex + 3] += -offsetToMidBaseline;
// Apply the Shearing FX
float shear_value = ShearAmount * 0.01f;
Vector3 topShear = new Vector3(shear_value * (textInfo.characterInfo[i].topRight.y - textInfo.characterInfo[i].baseLine), 0, 0);
Vector3 bottomShear = new Vector3(shear_value * (textInfo.characterInfo[i].baseLine - textInfo.characterInfo[i].bottomRight.y), 0, 0);
vertices[vertexIndex + 0] += -bottomShear;
vertices[vertexIndex + 1] += topShear;
vertices[vertexIndex + 2] += topShear;
vertices[vertexIndex + 3] += -bottomShear;
// Compute the angle of rotation for each character based on the animation curve
float x0 = (offsetToMidBaseline.x - boundsMinX) / (boundsMaxX - boundsMinX); // Character's position relative to the bounds of the mesh.
float x1 = x0 + 0.0001f;
float y0 = VertexCurve.Evaluate(x0) * CurveScale;
float y1 = VertexCurve.Evaluate(x1) * CurveScale;
Vector3 horizontal = new Vector3(1, 0, 0);
//Vector3 normal = new Vector3(-(y1 - y0), (x1 * (boundsMaxX - boundsMinX) + boundsMinX) - offsetToMidBaseline.x, 0);
Vector3 tangent = new Vector3(x1 * (boundsMaxX - boundsMinX) + boundsMinX, y1) - new Vector3(offsetToMidBaseline.x, y0);
float dot = Mathf.Acos(Vector3.Dot(horizontal, tangent.normalized)) * 57.2957795f;
Vector3 cross = Vector3.Cross(horizontal, tangent);
float angle = cross.z > 0 ? dot : 360 - dot;
matrix = Matrix4x4.TRS(new Vector3(0, y0, 0), Quaternion.Euler(0, 0, angle), Vector3.one);
vertices[vertexIndex + 0] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 0]);
vertices[vertexIndex + 1] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 1]);
vertices[vertexIndex + 2] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 2]);
vertices[vertexIndex + 3] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 3]);
vertices[vertexIndex + 0] += offsetToMidBaseline;
vertices[vertexIndex + 1] += offsetToMidBaseline;
vertices[vertexIndex + 2] += offsetToMidBaseline;
vertices[vertexIndex + 3] += offsetToMidBaseline;
}
// Upload the mesh with the revised information
m_TextComponent.UpdateVertexData();
yield return null; // new WaitForSeconds(0.025f);
}
}
}
}

View File

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

View File

@ -0,0 +1,27 @@
using UnityEngine;
using System;
namespace TMPro
{
/// <summary>
/// EXample of a Custom Character Input Validator to only allow digits from 0 to 9.
/// </summary>
[Serializable]
//[CreateAssetMenu(fileName = "InputValidator - Digits.asset", menuName = "TextMeshPro/Input Validators/Digits", order = 100)]
public class TMP_DigitValidator : TMP_InputValidator
{
// Custom text input validation function
public override char Validate(ref string text, ref int pos, char ch)
{
if (ch >= '0' && ch <= '9')
{
text += ch;
pos += 1;
return ch;
}
return (char)0;
}
}
}

View File

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

View File

@ -0,0 +1,64 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using TMPro;
namespace TMPro.Examples
{
public class TMP_ExampleScript_01 : MonoBehaviour
{
public enum objectType { TextMeshPro = 0, TextMeshProUGUI = 1 };
public objectType ObjectType;
public bool isStatic;
private TMP_Text m_text;
//private TMP_InputField m_inputfield;
private const string k_label = "The count is <#0080ff>{0}</color>";
private int count;
void Awake()
{
// Get a reference to the TMP text component if one already exists otherwise add one.
// This example show the convenience of having both TMP components derive from TMP_Text.
if (ObjectType == 0)
m_text = GetComponent<TextMeshPro>() ?? gameObject.AddComponent<TextMeshPro>();
else
m_text = GetComponent<TextMeshProUGUI>() ?? gameObject.AddComponent<TextMeshProUGUI>();
// Load a new font asset and assign it to the text object.
m_text.font = Resources.Load<TMP_FontAsset>("Fonts & Materials/Anton SDF");
// Load a new material preset which was created with the context menu duplicate.
m_text.fontSharedMaterial = Resources.Load<Material>("Fonts & Materials/Anton SDF - Drop Shadow");
// Set the size of the font.
m_text.fontSize = 120;
// Set the text
m_text.text = "A <#0080ff>simple</color> line of text.";
// Get the preferred width and height based on the supplied width and height as opposed to the actual size of the current text container.
Vector2 size = m_text.GetPreferredValues(Mathf.Infinity, Mathf.Infinity);
// Set the size of the RectTransform based on the new calculated values.
m_text.rectTransform.sizeDelta = new Vector2(size.x, size.y);
}
void Update()
{
if (!isStatic)
{
m_text.SetText(k_label, count % 1000);
count += 1;
}
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 6f2c5b59b6874405865e2616e4ec276a
timeCreated: 1449625634
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,134 @@
using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class TMP_FrameRateCounter : MonoBehaviour
{
public float UpdateInterval = 5.0f;
private float m_LastInterval = 0;
private int m_Frames = 0;
public enum FpsCounterAnchorPositions { TopLeft, BottomLeft, TopRight, BottomRight };
public FpsCounterAnchorPositions AnchorPosition = FpsCounterAnchorPositions.TopRight;
private string htmlColorTag;
private const string fpsLabel = "{0:2}</color> <#8080ff>FPS \n<#FF8000>{1:2} <#8080ff>MS";
private TextMeshPro m_TextMeshPro;
private Transform m_frameCounter_transform;
private Camera m_camera;
private FpsCounterAnchorPositions last_AnchorPosition;
void Awake()
{
if (!enabled)
return;
m_camera = Camera.main;
Application.targetFrameRate = 9999;
GameObject frameCounter = new GameObject("Frame Counter");
m_TextMeshPro = frameCounter.AddComponent<TextMeshPro>();
m_TextMeshPro.font = Resources.Load<TMP_FontAsset>("Fonts & Materials/LiberationSans SDF");
m_TextMeshPro.fontSharedMaterial = Resources.Load<Material>("Fonts & Materials/LiberationSans SDF - Overlay");
m_frameCounter_transform = frameCounter.transform;
m_frameCounter_transform.SetParent(m_camera.transform);
m_frameCounter_transform.localRotation = Quaternion.identity;
m_TextMeshPro.enableWordWrapping = false;
m_TextMeshPro.fontSize = 24;
//m_TextMeshPro.FontColor = new Color32(255, 255, 255, 128);
//m_TextMeshPro.edgeWidth = .15f;
//m_TextMeshPro.isOverlay = true;
//m_TextMeshPro.FaceColor = new Color32(255, 128, 0, 0);
//m_TextMeshPro.EdgeColor = new Color32(0, 255, 0, 255);
//m_TextMeshPro.FontMaterial.renderQueue = 4000;
//m_TextMeshPro.CreateSoftShadowClone(new Vector2(1f, -1f));
Set_FrameCounter_Position(AnchorPosition);
last_AnchorPosition = AnchorPosition;
}
void Start()
{
m_LastInterval = Time.realtimeSinceStartup;
m_Frames = 0;
}
void Update()
{
if (AnchorPosition != last_AnchorPosition)
Set_FrameCounter_Position(AnchorPosition);
last_AnchorPosition = AnchorPosition;
m_Frames += 1;
float timeNow = Time.realtimeSinceStartup;
if (timeNow > m_LastInterval + UpdateInterval)
{
// display two fractional digits (f2 format)
float fps = m_Frames / (timeNow - m_LastInterval);
float ms = 1000.0f / Mathf.Max(fps, 0.00001f);
if (fps < 30)
htmlColorTag = "<color=yellow>";
else if (fps < 10)
htmlColorTag = "<color=red>";
else
htmlColorTag = "<color=green>";
//string format = System.String.Format(htmlColorTag + "{0:F2} </color>FPS \n{1:F2} <#8080ff>MS",fps, ms);
//m_TextMeshPro.text = format;
m_TextMeshPro.SetText(htmlColorTag + fpsLabel, fps, ms);
m_Frames = 0;
m_LastInterval = timeNow;
}
}
void Set_FrameCounter_Position(FpsCounterAnchorPositions anchor_position)
{
//Debug.Log("Changing frame counter anchor position.");
m_TextMeshPro.margin = new Vector4(1f, 1f, 1f, 1f);
switch (anchor_position)
{
case FpsCounterAnchorPositions.TopLeft:
m_TextMeshPro.alignment = TextAlignmentOptions.TopLeft;
m_TextMeshPro.rectTransform.pivot = new Vector2(0, 1);
m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 1, 100.0f));
break;
case FpsCounterAnchorPositions.BottomLeft:
m_TextMeshPro.alignment = TextAlignmentOptions.BottomLeft;
m_TextMeshPro.rectTransform.pivot = new Vector2(0, 0);
m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 0, 100.0f));
break;
case FpsCounterAnchorPositions.TopRight:
m_TextMeshPro.alignment = TextAlignmentOptions.TopRight;
m_TextMeshPro.rectTransform.pivot = new Vector2(1, 1);
m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 1, 100.0f));
break;
case FpsCounterAnchorPositions.BottomRight:
m_TextMeshPro.alignment = TextAlignmentOptions.BottomRight;
m_TextMeshPro.rectTransform.pivot = new Vector2(1, 0);
m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 0, 100.0f));
break;
}
}
}
}

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 686ec78b56aa445795335fbadafcfaa4
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,105 @@
using UnityEngine;
using System.Collections;
using System;
namespace TMPro
{
/// <summary>
/// Example of a Custom Character Input Validator to only allow phone number in the (800) 555-1212 format.
/// </summary>
[Serializable]
//[CreateAssetMenu(fileName = "InputValidator - Phone Numbers.asset", menuName = "TextMeshPro/Input Validators/Phone Numbers")]
public class TMP_PhoneNumberValidator : TMP_InputValidator
{
// Custom text input validation function
public override char Validate(ref string text, ref int pos, char ch)
{
Debug.Log("Trying to validate...");
// Return unless the character is a valid digit
if (ch < '0' && ch > '9') return (char)0;
int length = text.Length;
// Enforce Phone Number format for every character input.
for (int i = 0; i < length + 1; i++)
{
switch (i)
{
case 0:
if (i == length)
text = "(" + ch;
pos = 2;
break;
case 1:
if (i == length)
text += ch;
pos = 2;
break;
case 2:
if (i == length)
text += ch;
pos = 3;
break;
case 3:
if (i == length)
text += ch + ") ";
pos = 6;
break;
case 4:
if (i == length)
text += ") " + ch;
pos = 7;
break;
case 5:
if (i == length)
text += " " + ch;
pos = 7;
break;
case 6:
if (i == length)
text += ch;
pos = 7;
break;
case 7:
if (i == length)
text += ch;
pos = 8;
break;
case 8:
if (i == length)
text += ch + "-";
pos = 10;
break;
case 9:
if (i == length)
text += "-" + ch;
pos = 11;
break;
case 10:
if (i == length)
text += ch;
pos = 11;
break;
case 11:
if (i == length)
text += ch;
pos = 12;
break;
case 12:
if (i == length)
text += ch;
pos = 13;
break;
case 13:
if (i == length)
text += ch;
pos = 14;
break;
}
}
return ch;
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 83680ab1a69f4102ac67d1459fe76e1f
timeCreated: 1473056437
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,73 @@
using UnityEngine;
namespace TMPro.Examples
{
public class TMP_TextEventCheck : MonoBehaviour
{
public TMP_TextEventHandler TextEventHandler;
private TMP_Text m_TextComponent;
void OnEnable()
{
if (TextEventHandler != null)
{
// Get a reference to the text component
m_TextComponent = TextEventHandler.GetComponent<TMP_Text>();
TextEventHandler.onCharacterSelection.AddListener(OnCharacterSelection);
TextEventHandler.onSpriteSelection.AddListener(OnSpriteSelection);
TextEventHandler.onWordSelection.AddListener(OnWordSelection);
TextEventHandler.onLineSelection.AddListener(OnLineSelection);
TextEventHandler.onLinkSelection.AddListener(OnLinkSelection);
}
}
void OnDisable()
{
if (TextEventHandler != null)
{
TextEventHandler.onCharacterSelection.RemoveListener(OnCharacterSelection);
TextEventHandler.onSpriteSelection.RemoveListener(OnSpriteSelection);
TextEventHandler.onWordSelection.RemoveListener(OnWordSelection);
TextEventHandler.onLineSelection.RemoveListener(OnLineSelection);
TextEventHandler.onLinkSelection.RemoveListener(OnLinkSelection);
}
}
void OnCharacterSelection(char c, int index)
{
Debug.Log("Character [" + c + "] at Index: " + index + " has been selected.");
}
void OnSpriteSelection(char c, int index)
{
Debug.Log("Sprite [" + c + "] at Index: " + index + " has been selected.");
}
void OnWordSelection(string word, int firstCharacterIndex, int length)
{
Debug.Log("Word [" + word + "] with first character index of " + firstCharacterIndex + " and length of " + length + " has been selected.");
}
void OnLineSelection(string lineText, int firstCharacterIndex, int length)
{
Debug.Log("Line [" + lineText + "] with first character index of " + firstCharacterIndex + " and length of " + length + " has been selected.");
}
void OnLinkSelection(string linkID, string linkText, int linkIndex)
{
if (m_TextComponent != null)
{
TMP_LinkInfo linkInfo = m_TextComponent.textInfo.linkInfo[linkIndex];
}
Debug.Log("Link Index: " + linkIndex + " with ID [" + linkID + "] and Text \"" + linkText + "\" has been selected.");
}
}
}

View File

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

View File

@ -0,0 +1,254 @@
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using System;
namespace TMPro
{
public class TMP_TextEventHandler : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
[Serializable]
public class CharacterSelectionEvent : UnityEvent<char, int> { }
[Serializable]
public class SpriteSelectionEvent : UnityEvent<char, int> { }
[Serializable]
public class WordSelectionEvent : UnityEvent<string, int, int> { }
[Serializable]
public class LineSelectionEvent : UnityEvent<string, int, int> { }
[Serializable]
public class LinkSelectionEvent : UnityEvent<string, string, int> { }
/// <summary>
/// Event delegate triggered when pointer is over a character.
/// </summary>
public CharacterSelectionEvent onCharacterSelection
{
get { return m_OnCharacterSelection; }
set { m_OnCharacterSelection = value; }
}
[SerializeField]
private CharacterSelectionEvent m_OnCharacterSelection = new CharacterSelectionEvent();
/// <summary>
/// Event delegate triggered when pointer is over a sprite.
/// </summary>
public SpriteSelectionEvent onSpriteSelection
{
get { return m_OnSpriteSelection; }
set { m_OnSpriteSelection = value; }
}
[SerializeField]
private SpriteSelectionEvent m_OnSpriteSelection = new SpriteSelectionEvent();
/// <summary>
/// Event delegate triggered when pointer is over a word.
/// </summary>
public WordSelectionEvent onWordSelection
{
get { return m_OnWordSelection; }
set { m_OnWordSelection = value; }
}
[SerializeField]
private WordSelectionEvent m_OnWordSelection = new WordSelectionEvent();
/// <summary>
/// Event delegate triggered when pointer is over a line.
/// </summary>
public LineSelectionEvent onLineSelection
{
get { return m_OnLineSelection; }
set { m_OnLineSelection = value; }
}
[SerializeField]
private LineSelectionEvent m_OnLineSelection = new LineSelectionEvent();
/// <summary>
/// Event delegate triggered when pointer is over a link.
/// </summary>
public LinkSelectionEvent onLinkSelection
{
get { return m_OnLinkSelection; }
set { m_OnLinkSelection = value; }
}
[SerializeField]
private LinkSelectionEvent m_OnLinkSelection = new LinkSelectionEvent();
private TMP_Text m_TextComponent;
private Camera m_Camera;
private Canvas m_Canvas;
private int m_selectedLink = -1;
private int m_lastCharIndex = -1;
private int m_lastWordIndex = -1;
private int m_lastLineIndex = -1;
void Awake()
{
// Get a reference to the text component.
m_TextComponent = gameObject.GetComponent<TMP_Text>();
// Get a reference to the camera rendering the text taking into consideration the text component type.
if (m_TextComponent.GetType() == typeof(TextMeshProUGUI))
{
m_Canvas = gameObject.GetComponentInParent<Canvas>();
if (m_Canvas != null)
{
if (m_Canvas.renderMode == RenderMode.ScreenSpaceOverlay)
m_Camera = null;
else
m_Camera = m_Canvas.worldCamera;
}
}
else
{
m_Camera = Camera.main;
}
}
void LateUpdate()
{
if (TMP_TextUtilities.IsIntersectingRectTransform(m_TextComponent.rectTransform, Input.mousePosition, m_Camera))
{
#region Example of Character or Sprite Selection
int charIndex = TMP_TextUtilities.FindIntersectingCharacter(m_TextComponent, Input.mousePosition, m_Camera, true);
if (charIndex != -1 && charIndex != m_lastCharIndex)
{
m_lastCharIndex = charIndex;
TMP_TextElementType elementType = m_TextComponent.textInfo.characterInfo[charIndex].elementType;
// Send event to any event listeners depending on whether it is a character or sprite.
if (elementType == TMP_TextElementType.Character)
SendOnCharacterSelection(m_TextComponent.textInfo.characterInfo[charIndex].character, charIndex);
else if (elementType == TMP_TextElementType.Sprite)
SendOnSpriteSelection(m_TextComponent.textInfo.characterInfo[charIndex].character, charIndex);
}
#endregion
#region Example of Word Selection
// Check if Mouse intersects any words and if so assign a random color to that word.
int wordIndex = TMP_TextUtilities.FindIntersectingWord(m_TextComponent, Input.mousePosition, m_Camera);
if (wordIndex != -1 && wordIndex != m_lastWordIndex)
{
m_lastWordIndex = wordIndex;
// Get the information about the selected word.
TMP_WordInfo wInfo = m_TextComponent.textInfo.wordInfo[wordIndex];
// Send the event to any listeners.
SendOnWordSelection(wInfo.GetWord(), wInfo.firstCharacterIndex, wInfo.characterCount);
}
#endregion
#region Example of Line Selection
// Check if Mouse intersects any words and if so assign a random color to that word.
int lineIndex = TMP_TextUtilities.FindIntersectingLine(m_TextComponent, Input.mousePosition, m_Camera);
if (lineIndex != -1 && lineIndex != m_lastLineIndex)
{
m_lastLineIndex = lineIndex;
// Get the information about the selected word.
TMP_LineInfo lineInfo = m_TextComponent.textInfo.lineInfo[lineIndex];
// Send the event to any listeners.
char[] buffer = new char[lineInfo.characterCount];
for (int i = 0; i < lineInfo.characterCount && i < m_TextComponent.textInfo.characterInfo.Length; i++)
{
buffer[i] = m_TextComponent.textInfo.characterInfo[i + lineInfo.firstCharacterIndex].character;
}
string lineText = new string(buffer);
SendOnLineSelection(lineText, lineInfo.firstCharacterIndex, lineInfo.characterCount);
}
#endregion
#region Example of Link Handling
// Check if mouse intersects with any links.
int linkIndex = TMP_TextUtilities.FindIntersectingLink(m_TextComponent, Input.mousePosition, m_Camera);
// Handle new Link selection.
if (linkIndex != -1 && linkIndex != m_selectedLink)
{
m_selectedLink = linkIndex;
// Get information about the link.
TMP_LinkInfo linkInfo = m_TextComponent.textInfo.linkInfo[linkIndex];
// Send the event to any listeners.
SendOnLinkSelection(linkInfo.GetLinkID(), linkInfo.GetLinkText(), linkIndex);
}
#endregion
}
else
{
// Reset all selections given we are hovering outside the text container bounds.
m_selectedLink = -1;
m_lastCharIndex = -1;
m_lastWordIndex = -1;
m_lastLineIndex = -1;
}
}
public void OnPointerEnter(PointerEventData eventData)
{
//Debug.Log("OnPointerEnter()");
}
public void OnPointerExit(PointerEventData eventData)
{
//Debug.Log("OnPointerExit()");
}
private void SendOnCharacterSelection(char character, int characterIndex)
{
if (onCharacterSelection != null)
onCharacterSelection.Invoke(character, characterIndex);
}
private void SendOnSpriteSelection(char character, int characterIndex)
{
if (onSpriteSelection != null)
onSpriteSelection.Invoke(character, characterIndex);
}
private void SendOnWordSelection(string word, int charIndex, int length)
{
if (onWordSelection != null)
onWordSelection.Invoke(word, charIndex, length);
}
private void SendOnLineSelection(string line, int charIndex, int length)
{
if (onLineSelection != null)
onLineSelection.Invoke(line, charIndex, length);
}
private void SendOnLinkSelection(string linkID, string linkText, int linkIndex)
{
if (onLinkSelection != null)
onLinkSelection.Invoke(linkID, linkText, linkIndex);
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1312ae25639a4bae8e25ae223209cc50
timeCreated: 1452811039
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,652 @@
using System;
using UnityEngine;
using System.Collections;
using UnityEditor;
namespace TMPro.Examples
{
public class TMP_TextInfoDebugTool : MonoBehaviour
{
// Since this script is used for debugging, we exclude it from builds.
// TODO: Rework this script to make it into an editor utility.
#if UNITY_EDITOR
public bool ShowCharacters;
public bool ShowWords;
public bool ShowLinks;
public bool ShowLines;
public bool ShowMeshBounds;
public bool ShowTextBounds;
[Space(10)]
[TextArea(2, 2)]
public string ObjectStats;
[SerializeField]
private TMP_Text m_TextComponent;
private Transform m_Transform;
private TMP_TextInfo m_TextInfo;
private float m_ScaleMultiplier;
private float m_HandleSize;
void OnDrawGizmos()
{
if (m_TextComponent == null)
{
m_TextComponent = GetComponent<TMP_Text>();
if (m_TextComponent == null)
return;
}
m_Transform = m_TextComponent.transform;
// Get a reference to the text object's textInfo
m_TextInfo = m_TextComponent.textInfo;
// Update Text Statistics
ObjectStats = "Characters: " + m_TextInfo.characterCount + " Words: " + m_TextInfo.wordCount + " Spaces: " + m_TextInfo.spaceCount + " Sprites: " + m_TextInfo.spriteCount + " Links: " + m_TextInfo.linkCount
+ "\nLines: " + m_TextInfo.lineCount + " Pages: " + m_TextInfo.pageCount;
// Get the handle size for drawing the various
m_ScaleMultiplier = m_TextComponent.GetType() == typeof(TextMeshPro) ? 1 : 0.1f;
m_HandleSize = HandleUtility.GetHandleSize(m_Transform.position) * m_ScaleMultiplier;
// Draw line metrics
#region Draw Lines
if (ShowLines)
DrawLineBounds();
#endregion
// Draw word metrics
#region Draw Words
if (ShowWords)
DrawWordBounds();
#endregion
// Draw character metrics
#region Draw Characters
if (ShowCharacters)
DrawCharactersBounds();
#endregion
// Draw Quads around each of the words
#region Draw Links
if (ShowLinks)
DrawLinkBounds();
#endregion
// Draw Quad around the bounds of the text
#region Draw Bounds
if (ShowMeshBounds)
DrawBounds();
#endregion
// Draw Quad around the rendered region of the text.
#region Draw Text Bounds
if (ShowTextBounds)
DrawTextBounds();
#endregion
}
/// <summary>
/// Method to draw a rectangle around each character.
/// </summary>
/// <param name="text"></param>
void DrawCharactersBounds()
{
int characterCount = m_TextInfo.characterCount;
for (int i = 0; i < characterCount; i++)
{
// Draw visible as well as invisible characters
TMP_CharacterInfo characterInfo = m_TextInfo.characterInfo[i];
bool isCharacterVisible = i < m_TextComponent.maxVisibleCharacters &&
characterInfo.lineNumber < m_TextComponent.maxVisibleLines &&
i >= m_TextComponent.firstVisibleCharacter;
if (m_TextComponent.overflowMode == TextOverflowModes.Page)
isCharacterVisible = isCharacterVisible && characterInfo.pageNumber + 1 == m_TextComponent.pageToDisplay;
if (!isCharacterVisible)
continue;
float dottedLineSize = 6;
// Get Bottom Left and Top Right position of the current character
Vector3 bottomLeft = m_Transform.TransformPoint(characterInfo.bottomLeft);
Vector3 topLeft = m_Transform.TransformPoint(new Vector3(characterInfo.topLeft.x, characterInfo.topLeft.y, 0));
Vector3 topRight = m_Transform.TransformPoint(characterInfo.topRight);
Vector3 bottomRight = m_Transform.TransformPoint(new Vector3(characterInfo.bottomRight.x, characterInfo.bottomRight.y, 0));
// Draw character bounds
if (characterInfo.isVisible)
{
Color color = Color.green;
DrawDottedRectangle(bottomLeft, topRight, color);
}
else
{
Color color = Color.grey;
float whiteSpaceAdvance = Math.Abs(characterInfo.origin - characterInfo.xAdvance) > 0.01f ? characterInfo.xAdvance : characterInfo.origin + (characterInfo.ascender - characterInfo.descender) * 0.03f;
DrawDottedRectangle(m_Transform.TransformPoint(new Vector3(characterInfo.origin, characterInfo.descender, 0)), m_Transform.TransformPoint(new Vector3(whiteSpaceAdvance, characterInfo.ascender, 0)), color, 4);
}
float origin = characterInfo.origin;
float advance = characterInfo.xAdvance;
float ascentline = characterInfo.ascender;
float baseline = characterInfo.baseLine;
float descentline = characterInfo.descender;
//Draw Ascent line
Vector3 ascentlineStart = m_Transform.TransformPoint(new Vector3(origin, ascentline, 0));
Vector3 ascentlineEnd = m_Transform.TransformPoint(new Vector3(advance, ascentline, 0));
Handles.color = Color.cyan;
Handles.DrawDottedLine(ascentlineStart, ascentlineEnd, dottedLineSize);
// Draw Cap Height & Mean line
float capline = characterInfo.fontAsset == null ? 0 : baseline + characterInfo.fontAsset.faceInfo.capLine * characterInfo.scale;
Vector3 capHeightStart = new Vector3(topLeft.x, m_Transform.TransformPoint(new Vector3(0, capline, 0)).y, 0);
Vector3 capHeightEnd = new Vector3(topRight.x, m_Transform.TransformPoint(new Vector3(0, capline, 0)).y, 0);
float meanline = characterInfo.fontAsset == null ? 0 : baseline + characterInfo.fontAsset.faceInfo.meanLine * characterInfo.scale;
Vector3 meanlineStart = new Vector3(topLeft.x, m_Transform.TransformPoint(new Vector3(0, meanline, 0)).y, 0);
Vector3 meanlineEnd = new Vector3(topRight.x, m_Transform.TransformPoint(new Vector3(0, meanline, 0)).y, 0);
if (characterInfo.isVisible)
{
// Cap line
Handles.color = Color.cyan;
Handles.DrawDottedLine(capHeightStart, capHeightEnd, dottedLineSize);
// Mean line
Handles.color = Color.cyan;
Handles.DrawDottedLine(meanlineStart, meanlineEnd, dottedLineSize);
}
//Draw Base line
Vector3 baselineStart = m_Transform.TransformPoint(new Vector3(origin, baseline, 0));
Vector3 baselineEnd = m_Transform.TransformPoint(new Vector3(advance, baseline, 0));
Handles.color = Color.cyan;
Handles.DrawDottedLine(baselineStart, baselineEnd, dottedLineSize);
//Draw Descent line
Vector3 descentlineStart = m_Transform.TransformPoint(new Vector3(origin, descentline, 0));
Vector3 descentlineEnd = m_Transform.TransformPoint(new Vector3(advance, descentline, 0));
Handles.color = Color.cyan;
Handles.DrawDottedLine(descentlineStart, descentlineEnd, dottedLineSize);
// Draw Origin
Vector3 originPosition = m_Transform.TransformPoint(new Vector3(origin, baseline, 0));
DrawCrosshair(originPosition, 0.05f / m_ScaleMultiplier, Color.cyan);
// Draw Horizontal Advance
Vector3 advancePosition = m_Transform.TransformPoint(new Vector3(advance, baseline, 0));
DrawSquare(advancePosition, 0.025f / m_ScaleMultiplier, Color.yellow);
DrawCrosshair(advancePosition, 0.0125f / m_ScaleMultiplier, Color.yellow);
// Draw text labels for metrics
if (m_HandleSize < 0.5f)
{
GUIStyle style = new GUIStyle(GUI.skin.GetStyle("Label"));
style.normal.textColor = new Color(0.6f, 0.6f, 0.6f, 1.0f);
style.fontSize = 12;
style.fixedWidth = 200;
style.fixedHeight = 20;
Vector3 labelPosition;
float center = (origin + advance) / 2;
//float baselineMetrics = 0;
//float ascentlineMetrics = ascentline - baseline;
//float caplineMetrics = capline - baseline;
//float meanlineMetrics = meanline - baseline;
//float descentlineMetrics = descentline - baseline;
// Ascent Line
labelPosition = m_Transform.TransformPoint(new Vector3(center, ascentline, 0));
style.alignment = TextAnchor.UpperCenter;
Handles.Label(labelPosition, "Ascent Line", style);
//Handles.Label(labelPosition, "Ascent Line (" + ascentlineMetrics.ToString("f3") + ")" , style);
// Base Line
labelPosition = m_Transform.TransformPoint(new Vector3(center, baseline, 0));
Handles.Label(labelPosition, "Base Line", style);
//Handles.Label(labelPosition, "Base Line (" + baselineMetrics.ToString("f3") + ")" , style);
// Descent line
labelPosition = m_Transform.TransformPoint(new Vector3(center, descentline, 0));
Handles.Label(labelPosition, "Descent Line", style);
//Handles.Label(labelPosition, "Descent Line (" + descentlineMetrics.ToString("f3") + ")" , style);
if (characterInfo.isVisible)
{
// Cap Line
labelPosition = m_Transform.TransformPoint(new Vector3(center, capline, 0));
style.alignment = TextAnchor.UpperCenter;
Handles.Label(labelPosition, "Cap Line", style);
//Handles.Label(labelPosition, "Cap Line (" + caplineMetrics.ToString("f3") + ")" , style);
// Mean Line
labelPosition = m_Transform.TransformPoint(new Vector3(center, meanline, 0));
style.alignment = TextAnchor.UpperCenter;
Handles.Label(labelPosition, "Mean Line", style);
//Handles.Label(labelPosition, "Mean Line (" + ascentlineMetrics.ToString("f3") + ")" , style);
// Origin
labelPosition = m_Transform.TransformPoint(new Vector3(origin, baseline, 0));
style.alignment = TextAnchor.UpperRight;
Handles.Label(labelPosition, "Origin ", style);
// Advance
labelPosition = m_Transform.TransformPoint(new Vector3(advance, baseline, 0));
style.alignment = TextAnchor.UpperLeft;
Handles.Label(labelPosition, " Advance", style);
}
}
}
}
/// <summary>
/// Method to draw rectangles around each word of the text.
/// </summary>
/// <param name="text"></param>
void DrawWordBounds()
{
for (int i = 0; i < m_TextInfo.wordCount; i++)
{
TMP_WordInfo wInfo = m_TextInfo.wordInfo[i];
bool isBeginRegion = false;
Vector3 bottomLeft = Vector3.zero;
Vector3 topLeft = Vector3.zero;
Vector3 bottomRight = Vector3.zero;
Vector3 topRight = Vector3.zero;
float maxAscender = -Mathf.Infinity;
float minDescender = Mathf.Infinity;
Color wordColor = Color.green;
// Iterate through each character of the word
for (int j = 0; j < wInfo.characterCount; j++)
{
int characterIndex = wInfo.firstCharacterIndex + j;
TMP_CharacterInfo currentCharInfo = m_TextInfo.characterInfo[characterIndex];
int currentLine = currentCharInfo.lineNumber;
bool isCharacterVisible = characterIndex > m_TextComponent.maxVisibleCharacters ||
currentCharInfo.lineNumber > m_TextComponent.maxVisibleLines ||
(m_TextComponent.overflowMode == TextOverflowModes.Page && currentCharInfo.pageNumber + 1 != m_TextComponent.pageToDisplay) ? false : true;
// Track Max Ascender and Min Descender
maxAscender = Mathf.Max(maxAscender, currentCharInfo.ascender);
minDescender = Mathf.Min(minDescender, currentCharInfo.descender);
if (isBeginRegion == false && isCharacterVisible)
{
isBeginRegion = true;
bottomLeft = new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.descender, 0);
topLeft = new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.ascender, 0);
//Debug.Log("Start Word Region at [" + currentCharInfo.character + "]");
// If Word is one character
if (wInfo.characterCount == 1)
{
isBeginRegion = false;
topLeft = m_Transform.TransformPoint(new Vector3(topLeft.x, maxAscender, 0));
bottomLeft = m_Transform.TransformPoint(new Vector3(bottomLeft.x, minDescender, 0));
bottomRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, minDescender, 0));
topRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, maxAscender, 0));
// Draw Region
DrawRectangle(bottomLeft, topLeft, topRight, bottomRight, wordColor);
//Debug.Log("End Word Region at [" + currentCharInfo.character + "]");
}
}
// Last Character of Word
if (isBeginRegion && j == wInfo.characterCount - 1)
{
isBeginRegion = false;
topLeft = m_Transform.TransformPoint(new Vector3(topLeft.x, maxAscender, 0));
bottomLeft = m_Transform.TransformPoint(new Vector3(bottomLeft.x, minDescender, 0));
bottomRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, minDescender, 0));
topRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, maxAscender, 0));
// Draw Region
DrawRectangle(bottomLeft, topLeft, topRight, bottomRight, wordColor);
//Debug.Log("End Word Region at [" + currentCharInfo.character + "]");
}
// If Word is split on more than one line.
else if (isBeginRegion && currentLine != m_TextInfo.characterInfo[characterIndex + 1].lineNumber)
{
isBeginRegion = false;
topLeft = m_Transform.TransformPoint(new Vector3(topLeft.x, maxAscender, 0));
bottomLeft = m_Transform.TransformPoint(new Vector3(bottomLeft.x, minDescender, 0));
bottomRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, minDescender, 0));
topRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, maxAscender, 0));
// Draw Region
DrawRectangle(bottomLeft, topLeft, topRight, bottomRight, wordColor);
//Debug.Log("End Word Region at [" + currentCharInfo.character + "]");
maxAscender = -Mathf.Infinity;
minDescender = Mathf.Infinity;
}
}
//Debug.Log(wInfo.GetWord(m_TextMeshPro.textInfo.characterInfo));
}
}
/// <summary>
/// Draw rectangle around each of the links contained in the text.
/// </summary>
/// <param name="text"></param>
void DrawLinkBounds()
{
TMP_TextInfo textInfo = m_TextComponent.textInfo;
for (int i = 0; i < textInfo.linkCount; i++)
{
TMP_LinkInfo linkInfo = textInfo.linkInfo[i];
bool isBeginRegion = false;
Vector3 bottomLeft = Vector3.zero;
Vector3 topLeft = Vector3.zero;
Vector3 bottomRight = Vector3.zero;
Vector3 topRight = Vector3.zero;
float maxAscender = -Mathf.Infinity;
float minDescender = Mathf.Infinity;
Color32 linkColor = Color.cyan;
// Iterate through each character of the link text
for (int j = 0; j < linkInfo.linkTextLength; j++)
{
int characterIndex = linkInfo.linkTextfirstCharacterIndex + j;
TMP_CharacterInfo currentCharInfo = textInfo.characterInfo[characterIndex];
int currentLine = currentCharInfo.lineNumber;
bool isCharacterVisible = characterIndex > m_TextComponent.maxVisibleCharacters ||
currentCharInfo.lineNumber > m_TextComponent.maxVisibleLines ||
(m_TextComponent.overflowMode == TextOverflowModes.Page && currentCharInfo.pageNumber + 1 != m_TextComponent.pageToDisplay) ? false : true;
// Track Max Ascender and Min Descender
maxAscender = Mathf.Max(maxAscender, currentCharInfo.ascender);
minDescender = Mathf.Min(minDescender, currentCharInfo.descender);
if (isBeginRegion == false && isCharacterVisible)
{
isBeginRegion = true;
bottomLeft = new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.descender, 0);
topLeft = new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.ascender, 0);
//Debug.Log("Start Word Region at [" + currentCharInfo.character + "]");
// If Link is one character
if (linkInfo.linkTextLength == 1)
{
isBeginRegion = false;
topLeft = m_Transform.TransformPoint(new Vector3(topLeft.x, maxAscender, 0));
bottomLeft = m_Transform.TransformPoint(new Vector3(bottomLeft.x, minDescender, 0));
bottomRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, minDescender, 0));
topRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, maxAscender, 0));
// Draw Region
DrawRectangle(bottomLeft, topLeft, topRight, bottomRight, linkColor);
//Debug.Log("End Word Region at [" + currentCharInfo.character + "]");
}
}
// Last Character of Link
if (isBeginRegion && j == linkInfo.linkTextLength - 1)
{
isBeginRegion = false;
topLeft = m_Transform.TransformPoint(new Vector3(topLeft.x, maxAscender, 0));
bottomLeft = m_Transform.TransformPoint(new Vector3(bottomLeft.x, minDescender, 0));
bottomRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, minDescender, 0));
topRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, maxAscender, 0));
// Draw Region
DrawRectangle(bottomLeft, topLeft, topRight, bottomRight, linkColor);
//Debug.Log("End Word Region at [" + currentCharInfo.character + "]");
}
// If Link is split on more than one line.
else if (isBeginRegion && currentLine != textInfo.characterInfo[characterIndex + 1].lineNumber)
{
isBeginRegion = false;
topLeft = m_Transform.TransformPoint(new Vector3(topLeft.x, maxAscender, 0));
bottomLeft = m_Transform.TransformPoint(new Vector3(bottomLeft.x, minDescender, 0));
bottomRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, minDescender, 0));
topRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, maxAscender, 0));
// Draw Region
DrawRectangle(bottomLeft, topLeft, topRight, bottomRight, linkColor);
maxAscender = -Mathf.Infinity;
minDescender = Mathf.Infinity;
//Debug.Log("End Word Region at [" + currentCharInfo.character + "]");
}
}
//Debug.Log(wInfo.GetWord(m_TextMeshPro.textInfo.characterInfo));
}
}
/// <summary>
/// Draw Rectangles around each lines of the text.
/// </summary>
/// <param name="text"></param>
void DrawLineBounds()
{
int lineCount = m_TextInfo.lineCount;
for (int i = 0; i < lineCount; i++)
{
TMP_LineInfo lineInfo = m_TextInfo.lineInfo[i];
TMP_CharacterInfo firstCharacterInfo = m_TextInfo.characterInfo[lineInfo.firstCharacterIndex];
TMP_CharacterInfo lastCharacterInfo = m_TextInfo.characterInfo[lineInfo.lastCharacterIndex];
bool isLineVisible = (lineInfo.characterCount == 1 && (firstCharacterInfo.character == 10 || firstCharacterInfo.character == 11 || firstCharacterInfo.character == 0x2028 || firstCharacterInfo.character == 0x2029)) ||
i > m_TextComponent.maxVisibleLines ||
(m_TextComponent.overflowMode == TextOverflowModes.Page && firstCharacterInfo.pageNumber + 1 != m_TextComponent.pageToDisplay) ? false : true;
if (!isLineVisible) continue;
float lineBottomLeft = firstCharacterInfo.bottomLeft.x;
float lineTopRight = lastCharacterInfo.topRight.x;
float ascentline = lineInfo.ascender;
float baseline = lineInfo.baseline;
float descentline = lineInfo.descender;
float dottedLineSize = 12;
// Draw line extents
DrawDottedRectangle(m_Transform.TransformPoint(lineInfo.lineExtents.min), m_Transform.TransformPoint(lineInfo.lineExtents.max), Color.green, 4);
// Draw Ascent line
Vector3 ascentlineStart = m_Transform.TransformPoint(new Vector3(lineBottomLeft, ascentline, 0));
Vector3 ascentlineEnd = m_Transform.TransformPoint(new Vector3(lineTopRight, ascentline, 0));
Handles.color = Color.yellow;
Handles.DrawDottedLine(ascentlineStart, ascentlineEnd, dottedLineSize);
// Draw Base line
Vector3 baseLineStart = m_Transform.TransformPoint(new Vector3(lineBottomLeft, baseline, 0));
Vector3 baseLineEnd = m_Transform.TransformPoint(new Vector3(lineTopRight, baseline, 0));
Handles.color = Color.yellow;
Handles.DrawDottedLine(baseLineStart, baseLineEnd, dottedLineSize);
// Draw Descent line
Vector3 descentLineStart = m_Transform.TransformPoint(new Vector3(lineBottomLeft, descentline, 0));
Vector3 descentLineEnd = m_Transform.TransformPoint(new Vector3(lineTopRight, descentline, 0));
Handles.color = Color.yellow;
Handles.DrawDottedLine(descentLineStart, descentLineEnd, dottedLineSize);
// Draw text labels for metrics
if (m_HandleSize < 1.0f)
{
GUIStyle style = new GUIStyle();
style.normal.textColor = new Color(0.8f, 0.8f, 0.8f, 1.0f);
style.fontSize = 12;
style.fixedWidth = 200;
style.fixedHeight = 20;
Vector3 labelPosition;
// Ascent Line
labelPosition = m_Transform.TransformPoint(new Vector3(lineBottomLeft, ascentline, 0));
style.padding = new RectOffset(0, 10, 0, 5);
style.alignment = TextAnchor.MiddleRight;
Handles.Label(labelPosition, "Ascent Line", style);
// Base Line
labelPosition = m_Transform.TransformPoint(new Vector3(lineBottomLeft, baseline, 0));
Handles.Label(labelPosition, "Base Line", style);
// Descent line
labelPosition = m_Transform.TransformPoint(new Vector3(lineBottomLeft, descentline, 0));
Handles.Label(labelPosition, "Descent Line", style);
}
}
}
/// <summary>
/// Draw Rectangle around the bounds of the text object.
/// </summary>
void DrawBounds()
{
Bounds meshBounds = m_TextComponent.bounds;
// Get Bottom Left and Top Right position of each word
Vector3 bottomLeft = m_TextComponent.transform.position + meshBounds.min;
Vector3 topRight = m_TextComponent.transform.position + meshBounds.max;
DrawRectangle(bottomLeft, topRight, new Color(1, 0.5f, 0));
}
void DrawTextBounds()
{
Bounds textBounds = m_TextComponent.textBounds;
Vector3 bottomLeft = m_TextComponent.transform.position + (textBounds.center - textBounds.extents);
Vector3 topRight = m_TextComponent.transform.position + (textBounds.center + textBounds.extents);
DrawRectangle(bottomLeft, topRight, new Color(0f, 0.5f, 0.5f));
}
// Draw Rectangles
void DrawRectangle(Vector3 BL, Vector3 TR, Color color)
{
Gizmos.color = color;
Gizmos.DrawLine(new Vector3(BL.x, BL.y, 0), new Vector3(BL.x, TR.y, 0));
Gizmos.DrawLine(new Vector3(BL.x, TR.y, 0), new Vector3(TR.x, TR.y, 0));
Gizmos.DrawLine(new Vector3(TR.x, TR.y, 0), new Vector3(TR.x, BL.y, 0));
Gizmos.DrawLine(new Vector3(TR.x, BL.y, 0), new Vector3(BL.x, BL.y, 0));
}
void DrawDottedRectangle(Vector3 bottomLeft, Vector3 topRight, Color color, float size = 5.0f)
{
Handles.color = color;
Handles.DrawDottedLine(bottomLeft, new Vector3(bottomLeft.x, topRight.y, bottomLeft.z), size);
Handles.DrawDottedLine(new Vector3(bottomLeft.x, topRight.y, bottomLeft.z), topRight, size);
Handles.DrawDottedLine(topRight, new Vector3(topRight.x, bottomLeft.y, bottomLeft.z), size);
Handles.DrawDottedLine(new Vector3(topRight.x, bottomLeft.y, bottomLeft.z), bottomLeft, size);
}
void DrawSolidRectangle(Vector3 bottomLeft, Vector3 topRight, Color color, float size = 5.0f)
{
Handles.color = color;
Rect rect = new Rect(bottomLeft, topRight - bottomLeft);
Handles.DrawSolidRectangleWithOutline(rect, color, Color.black);
}
void DrawSquare(Vector3 position, float size, Color color)
{
Handles.color = color;
Vector3 bottomLeft = new Vector3(position.x - size, position.y - size, position.z);
Vector3 topLeft = new Vector3(position.x - size, position.y + size, position.z);
Vector3 topRight = new Vector3(position.x + size, position.y + size, position.z);
Vector3 bottomRight = new Vector3(position.x + size, position.y - size, position.z);
Handles.DrawLine(bottomLeft, topLeft);
Handles.DrawLine(topLeft, topRight);
Handles.DrawLine(topRight, bottomRight);
Handles.DrawLine(bottomRight, bottomLeft);
}
void DrawCrosshair(Vector3 position, float size, Color color)
{
Handles.color = color;
Handles.DrawLine(new Vector3(position.x - size, position.y, position.z), new Vector3(position.x + size, position.y, position.z));
Handles.DrawLine(new Vector3(position.x, position.y - size, position.z), new Vector3(position.x, position.y + size, position.z));
}
// Draw Rectangles
void DrawRectangle(Vector3 bl, Vector3 tl, Vector3 tr, Vector3 br, Color color)
{
Gizmos.color = color;
Gizmos.DrawLine(bl, tl);
Gizmos.DrawLine(tl, tr);
Gizmos.DrawLine(tr, br);
Gizmos.DrawLine(br, bl);
}
// Draw Rectangles
void DrawDottedRectangle(Vector3 bl, Vector3 tl, Vector3 tr, Vector3 br, Color color)
{
var cam = Camera.current;
float dotSpacing = (cam.WorldToScreenPoint(br).x - cam.WorldToScreenPoint(bl).x) / 75f;
UnityEditor.Handles.color = color;
UnityEditor.Handles.DrawDottedLine(bl, tl, dotSpacing);
UnityEditor.Handles.DrawDottedLine(tl, tr, dotSpacing);
UnityEditor.Handles.DrawDottedLine(tr, br, dotSpacing);
UnityEditor.Handles.DrawDottedLine(br, bl, dotSpacing);
}
#endif
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 21256c5b62f346f18640dad779911e20
timeCreated: 1430348781
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,157 @@
using UnityEngine;
using UnityEngine.EventSystems;
using System.Collections;
namespace TMPro.Examples
{
public class TMP_TextSelector_A : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
private TextMeshPro m_TextMeshPro;
private Camera m_Camera;
private bool m_isHoveringObject;
private int m_selectedLink = -1;
private int m_lastCharIndex = -1;
private int m_lastWordIndex = -1;
void Awake()
{
m_TextMeshPro = gameObject.GetComponent<TextMeshPro>();
m_Camera = Camera.main;
// Force generation of the text object so we have valid data to work with. This is needed since LateUpdate() will be called before the text object has a chance to generated when entering play mode.
m_TextMeshPro.ForceMeshUpdate();
}
void LateUpdate()
{
m_isHoveringObject = false;
if (TMP_TextUtilities.IsIntersectingRectTransform(m_TextMeshPro.rectTransform, Input.mousePosition, Camera.main))
{
m_isHoveringObject = true;
}
if (m_isHoveringObject)
{
#region Example of Character Selection
int charIndex = TMP_TextUtilities.FindIntersectingCharacter(m_TextMeshPro, Input.mousePosition, Camera.main, true);
if (charIndex != -1 && charIndex != m_lastCharIndex && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
{
//Debug.Log("[" + m_TextMeshPro.textInfo.characterInfo[charIndex].character + "] has been selected.");
m_lastCharIndex = charIndex;
int meshIndex = m_TextMeshPro.textInfo.characterInfo[charIndex].materialReferenceIndex;
int vertexIndex = m_TextMeshPro.textInfo.characterInfo[charIndex].vertexIndex;
Color32 c = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), 255);
Color32[] vertexColors = m_TextMeshPro.textInfo.meshInfo[meshIndex].colors32;
vertexColors[vertexIndex + 0] = c;
vertexColors[vertexIndex + 1] = c;
vertexColors[vertexIndex + 2] = c;
vertexColors[vertexIndex + 3] = c;
//m_TextMeshPro.mesh.colors32 = vertexColors;
m_TextMeshPro.textInfo.meshInfo[meshIndex].mesh.colors32 = vertexColors;
}
#endregion
#region Example of Link Handling
// Check if mouse intersects with any links.
int linkIndex = TMP_TextUtilities.FindIntersectingLink(m_TextMeshPro, Input.mousePosition, m_Camera);
// Clear previous link selection if one existed.
if ((linkIndex == -1 && m_selectedLink != -1) || linkIndex != m_selectedLink)
{
//m_TextPopup_RectTransform.gameObject.SetActive(false);
m_selectedLink = -1;
}
// Handle new Link selection.
if (linkIndex != -1 && linkIndex != m_selectedLink)
{
m_selectedLink = linkIndex;
TMP_LinkInfo linkInfo = m_TextMeshPro.textInfo.linkInfo[linkIndex];
// The following provides an example of how to access the link properties.
//Debug.Log("Link ID: \"" + linkInfo.GetLinkID() + "\" Link Text: \"" + linkInfo.GetLinkText() + "\""); // Example of how to retrieve the Link ID and Link Text.
Vector3 worldPointInRectangle;
RectTransformUtility.ScreenPointToWorldPointInRectangle(m_TextMeshPro.rectTransform, Input.mousePosition, m_Camera, out worldPointInRectangle);
switch (linkInfo.GetLinkID())
{
case "id_01": // 100041637: // id_01
//m_TextPopup_RectTransform.position = worldPointInRectangle;
//m_TextPopup_RectTransform.gameObject.SetActive(true);
//m_TextPopup_TMPComponent.text = k_LinkText + " ID 01";
break;
case "id_02": // 100041638: // id_02
//m_TextPopup_RectTransform.position = worldPointInRectangle;
//m_TextPopup_RectTransform.gameObject.SetActive(true);
//m_TextPopup_TMPComponent.text = k_LinkText + " ID 02";
break;
}
}
#endregion
#region Example of Word Selection
// Check if Mouse intersects any words and if so assign a random color to that word.
int wordIndex = TMP_TextUtilities.FindIntersectingWord(m_TextMeshPro, Input.mousePosition, Camera.main);
if (wordIndex != -1 && wordIndex != m_lastWordIndex)
{
m_lastWordIndex = wordIndex;
TMP_WordInfo wInfo = m_TextMeshPro.textInfo.wordInfo[wordIndex];
Vector3 wordPOS = m_TextMeshPro.transform.TransformPoint(m_TextMeshPro.textInfo.characterInfo[wInfo.firstCharacterIndex].bottomLeft);
wordPOS = Camera.main.WorldToScreenPoint(wordPOS);
//Debug.Log("Mouse Position: " + Input.mousePosition.ToString("f3") + " Word Position: " + wordPOS.ToString("f3"));
Color32[] vertexColors = m_TextMeshPro.textInfo.meshInfo[0].colors32;
Color32 c = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), 255);
for (int i = 0; i < wInfo.characterCount; i++)
{
int vertexIndex = m_TextMeshPro.textInfo.characterInfo[wInfo.firstCharacterIndex + i].vertexIndex;
vertexColors[vertexIndex + 0] = c;
vertexColors[vertexIndex + 1] = c;
vertexColors[vertexIndex + 2] = c;
vertexColors[vertexIndex + 3] = c;
}
m_TextMeshPro.mesh.colors32 = vertexColors;
}
#endregion
}
}
public void OnPointerEnter(PointerEventData eventData)
{
Debug.Log("OnPointerEnter()");
m_isHoveringObject = true;
}
public void OnPointerExit(PointerEventData eventData)
{
Debug.Log("OnPointerExit()");
m_isHoveringObject = false;
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 103e0a6a1d404693b9fb1a5173e0e979
timeCreated: 1452811039
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,547 @@
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using System.Collections;
using System.Collections.Generic;
#pragma warning disable 0618 // Disabled warning due to SetVertices being deprecated until new release with SetMesh() is available.
namespace TMPro.Examples
{
public class TMP_TextSelector_B : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler, IPointerUpHandler
{
public RectTransform TextPopup_Prefab_01;
private RectTransform m_TextPopup_RectTransform;
private TextMeshProUGUI m_TextPopup_TMPComponent;
private const string k_LinkText = "You have selected link <#ffff00>";
private const string k_WordText = "Word Index: <#ffff00>";
private TextMeshProUGUI m_TextMeshPro;
private Canvas m_Canvas;
private Camera m_Camera;
// Flags
private bool isHoveringObject;
private int m_selectedWord = -1;
private int m_selectedLink = -1;
private int m_lastIndex = -1;
private Matrix4x4 m_matrix;
private TMP_MeshInfo[] m_cachedMeshInfoVertexData;
void Awake()
{
m_TextMeshPro = gameObject.GetComponent<TextMeshProUGUI>();
m_Canvas = gameObject.GetComponentInParent<Canvas>();
// Get a reference to the camera if Canvas Render Mode is not ScreenSpace Overlay.
if (m_Canvas.renderMode == RenderMode.ScreenSpaceOverlay)
m_Camera = null;
else
m_Camera = m_Canvas.worldCamera;
// Create pop-up text object which is used to show the link information.
m_TextPopup_RectTransform = Instantiate(TextPopup_Prefab_01) as RectTransform;
m_TextPopup_RectTransform.SetParent(m_Canvas.transform, false);
m_TextPopup_TMPComponent = m_TextPopup_RectTransform.GetComponentInChildren<TextMeshProUGUI>();
m_TextPopup_RectTransform.gameObject.SetActive(false);
}
void OnEnable()
{
// Subscribe to event fired when text object has been regenerated.
TMPro_EventManager.TEXT_CHANGED_EVENT.Add(ON_TEXT_CHANGED);
}
void OnDisable()
{
// UnSubscribe to event fired when text object has been regenerated.
TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(ON_TEXT_CHANGED);
}
void ON_TEXT_CHANGED(Object obj)
{
if (obj == m_TextMeshPro)
{
// Update cached vertex data.
m_cachedMeshInfoVertexData = m_TextMeshPro.textInfo.CopyMeshInfoVertexData();
}
}
void LateUpdate()
{
if (isHoveringObject)
{
// Check if Mouse Intersects any of the characters. If so, assign a random color.
#region Handle Character Selection
int charIndex = TMP_TextUtilities.FindIntersectingCharacter(m_TextMeshPro, Input.mousePosition, m_Camera, true);
// Undo Swap and Vertex Attribute changes.
if (charIndex == -1 || charIndex != m_lastIndex)
{
RestoreCachedVertexAttributes(m_lastIndex);
m_lastIndex = -1;
}
if (charIndex != -1 && charIndex != m_lastIndex && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
{
m_lastIndex = charIndex;
// Get the index of the material / sub text object used by this character.
int materialIndex = m_TextMeshPro.textInfo.characterInfo[charIndex].materialReferenceIndex;
// Get the index of the first vertex of the selected character.
int vertexIndex = m_TextMeshPro.textInfo.characterInfo[charIndex].vertexIndex;
// Get a reference to the vertices array.
Vector3[] vertices = m_TextMeshPro.textInfo.meshInfo[materialIndex].vertices;
// Determine the center point of the character.
Vector2 charMidBasline = (vertices[vertexIndex + 0] + vertices[vertexIndex + 2]) / 2;
// Need to translate all 4 vertices of the character to aligned with middle of character / baseline.
// This is needed so the matrix TRS is applied at the origin for each character.
Vector3 offset = charMidBasline;
// Translate the character to the middle baseline.
vertices[vertexIndex + 0] = vertices[vertexIndex + 0] - offset;
vertices[vertexIndex + 1] = vertices[vertexIndex + 1] - offset;
vertices[vertexIndex + 2] = vertices[vertexIndex + 2] - offset;
vertices[vertexIndex + 3] = vertices[vertexIndex + 3] - offset;
float zoomFactor = 1.5f;
// Setup the Matrix for the scale change.
m_matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one * zoomFactor);
// Apply Matrix operation on the given character.
vertices[vertexIndex + 0] = m_matrix.MultiplyPoint3x4(vertices[vertexIndex + 0]);
vertices[vertexIndex + 1] = m_matrix.MultiplyPoint3x4(vertices[vertexIndex + 1]);
vertices[vertexIndex + 2] = m_matrix.MultiplyPoint3x4(vertices[vertexIndex + 2]);
vertices[vertexIndex + 3] = m_matrix.MultiplyPoint3x4(vertices[vertexIndex + 3]);
// Translate the character back to its original position.
vertices[vertexIndex + 0] = vertices[vertexIndex + 0] + offset;
vertices[vertexIndex + 1] = vertices[vertexIndex + 1] + offset;
vertices[vertexIndex + 2] = vertices[vertexIndex + 2] + offset;
vertices[vertexIndex + 3] = vertices[vertexIndex + 3] + offset;
// Change Vertex Colors of the highlighted character
Color32 c = new Color32(255, 255, 192, 255);
// Get a reference to the vertex color
Color32[] vertexColors = m_TextMeshPro.textInfo.meshInfo[materialIndex].colors32;
vertexColors[vertexIndex + 0] = c;
vertexColors[vertexIndex + 1] = c;
vertexColors[vertexIndex + 2] = c;
vertexColors[vertexIndex + 3] = c;
// Get a reference to the meshInfo of the selected character.
TMP_MeshInfo meshInfo = m_TextMeshPro.textInfo.meshInfo[materialIndex];
// Get the index of the last character's vertex attributes.
int lastVertexIndex = vertices.Length - 4;
// Swap the current character's vertex attributes with those of the last element in the vertex attribute arrays.
// We do this to make sure this character is rendered last and over other characters.
meshInfo.SwapVertexData(vertexIndex, lastVertexIndex);
// Need to update the appropriate
m_TextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
}
#endregion
#region Word Selection Handling
//Check if Mouse intersects any words and if so assign a random color to that word.
int wordIndex = TMP_TextUtilities.FindIntersectingWord(m_TextMeshPro, Input.mousePosition, m_Camera);
// Clear previous word selection.
if (m_TextPopup_RectTransform != null && m_selectedWord != -1 && (wordIndex == -1 || wordIndex != m_selectedWord))
{
TMP_WordInfo wInfo = m_TextMeshPro.textInfo.wordInfo[m_selectedWord];
// Iterate through each of the characters of the word.
for (int i = 0; i < wInfo.characterCount; i++)
{
int characterIndex = wInfo.firstCharacterIndex + i;
// Get the index of the material / sub text object used by this character.
int meshIndex = m_TextMeshPro.textInfo.characterInfo[characterIndex].materialReferenceIndex;
// Get the index of the first vertex of this character.
int vertexIndex = m_TextMeshPro.textInfo.characterInfo[characterIndex].vertexIndex;
// Get a reference to the vertex color
Color32[] vertexColors = m_TextMeshPro.textInfo.meshInfo[meshIndex].colors32;
Color32 c = vertexColors[vertexIndex + 0].Tint(1.33333f);
vertexColors[vertexIndex + 0] = c;
vertexColors[vertexIndex + 1] = c;
vertexColors[vertexIndex + 2] = c;
vertexColors[vertexIndex + 3] = c;
}
// Update Geometry
m_TextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
m_selectedWord = -1;
}
// Word Selection Handling
if (wordIndex != -1 && wordIndex != m_selectedWord && !(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
{
m_selectedWord = wordIndex;
TMP_WordInfo wInfo = m_TextMeshPro.textInfo.wordInfo[wordIndex];
// Iterate through each of the characters of the word.
for (int i = 0; i < wInfo.characterCount; i++)
{
int characterIndex = wInfo.firstCharacterIndex + i;
// Get the index of the material / sub text object used by this character.
int meshIndex = m_TextMeshPro.textInfo.characterInfo[characterIndex].materialReferenceIndex;
int vertexIndex = m_TextMeshPro.textInfo.characterInfo[characterIndex].vertexIndex;
// Get a reference to the vertex color
Color32[] vertexColors = m_TextMeshPro.textInfo.meshInfo[meshIndex].colors32;
Color32 c = vertexColors[vertexIndex + 0].Tint(0.75f);
vertexColors[vertexIndex + 0] = c;
vertexColors[vertexIndex + 1] = c;
vertexColors[vertexIndex + 2] = c;
vertexColors[vertexIndex + 3] = c;
}
// Update Geometry
m_TextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
}
#endregion
#region Example of Link Handling
// Check if mouse intersects with any links.
int linkIndex = TMP_TextUtilities.FindIntersectingLink(m_TextMeshPro, Input.mousePosition, m_Camera);
// Clear previous link selection if one existed.
if ((linkIndex == -1 && m_selectedLink != -1) || linkIndex != m_selectedLink)
{
m_TextPopup_RectTransform.gameObject.SetActive(false);
m_selectedLink = -1;
}
// Handle new Link selection.
if (linkIndex != -1 && linkIndex != m_selectedLink)
{
m_selectedLink = linkIndex;
TMP_LinkInfo linkInfo = m_TextMeshPro.textInfo.linkInfo[linkIndex];
// Debug.Log("Link ID: \"" + linkInfo.GetLinkID() + "\" Link Text: \"" + linkInfo.GetLinkText() + "\""); // Example of how to retrieve the Link ID and Link Text.
Vector3 worldPointInRectangle;
RectTransformUtility.ScreenPointToWorldPointInRectangle(m_TextMeshPro.rectTransform, Input.mousePosition, m_Camera, out worldPointInRectangle);
switch (linkInfo.GetLinkID())
{
case "id_01": // 100041637: // id_01
m_TextPopup_RectTransform.position = worldPointInRectangle;
m_TextPopup_RectTransform.gameObject.SetActive(true);
m_TextPopup_TMPComponent.text = k_LinkText + " ID 01";
break;
case "id_02": // 100041638: // id_02
m_TextPopup_RectTransform.position = worldPointInRectangle;
m_TextPopup_RectTransform.gameObject.SetActive(true);
m_TextPopup_TMPComponent.text = k_LinkText + " ID 02";
break;
}
}
#endregion
}
else
{
// Restore any character that may have been modified
if (m_lastIndex != -1)
{
RestoreCachedVertexAttributes(m_lastIndex);
m_lastIndex = -1;
}
}
}
public void OnPointerEnter(PointerEventData eventData)
{
//Debug.Log("OnPointerEnter()");
isHoveringObject = true;
}
public void OnPointerExit(PointerEventData eventData)
{
//Debug.Log("OnPointerExit()");
isHoveringObject = false;
}
public void OnPointerClick(PointerEventData eventData)
{
//Debug.Log("Click at POS: " + eventData.position + " World POS: " + eventData.worldPosition);
// Check if Mouse Intersects any of the characters. If so, assign a random color.
#region Character Selection Handling
/*
int charIndex = TMP_TextUtilities.FindIntersectingCharacter(m_TextMeshPro, Input.mousePosition, m_Camera, true);
if (charIndex != -1 && charIndex != m_lastIndex)
{
//Debug.Log("Character [" + m_TextMeshPro.textInfo.characterInfo[index].character + "] was selected at POS: " + eventData.position);
m_lastIndex = charIndex;
Color32 c = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), 255);
int vertexIndex = m_TextMeshPro.textInfo.characterInfo[charIndex].vertexIndex;
UIVertex[] uiVertices = m_TextMeshPro.textInfo.meshInfo.uiVertices;
uiVertices[vertexIndex + 0].color = c;
uiVertices[vertexIndex + 1].color = c;
uiVertices[vertexIndex + 2].color = c;
uiVertices[vertexIndex + 3].color = c;
m_TextMeshPro.canvasRenderer.SetVertices(uiVertices, uiVertices.Length);
}
*/
#endregion
#region Word Selection Handling
//Check if Mouse intersects any words and if so assign a random color to that word.
/*
int wordIndex = TMP_TextUtilities.FindIntersectingWord(m_TextMeshPro, Input.mousePosition, m_Camera);
// Clear previous word selection.
if (m_TextPopup_RectTransform != null && m_selectedWord != -1 && (wordIndex == -1 || wordIndex != m_selectedWord))
{
TMP_WordInfo wInfo = m_TextMeshPro.textInfo.wordInfo[m_selectedWord];
// Get a reference to the uiVertices array.
UIVertex[] uiVertices = m_TextMeshPro.textInfo.meshInfo.uiVertices;
// Iterate through each of the characters of the word.
for (int i = 0; i < wInfo.characterCount; i++)
{
int vertexIndex = m_TextMeshPro.textInfo.characterInfo[wInfo.firstCharacterIndex + i].vertexIndex;
Color32 c = uiVertices[vertexIndex + 0].color.Tint(1.33333f);
uiVertices[vertexIndex + 0].color = c;
uiVertices[vertexIndex + 1].color = c;
uiVertices[vertexIndex + 2].color = c;
uiVertices[vertexIndex + 3].color = c;
}
m_TextMeshPro.canvasRenderer.SetVertices(uiVertices, uiVertices.Length);
m_selectedWord = -1;
}
// Handle word selection
if (wordIndex != -1 && wordIndex != m_selectedWord)
{
m_selectedWord = wordIndex;
TMP_WordInfo wInfo = m_TextMeshPro.textInfo.wordInfo[wordIndex];
// Get a reference to the uiVertices array.
UIVertex[] uiVertices = m_TextMeshPro.textInfo.meshInfo.uiVertices;
// Iterate through each of the characters of the word.
for (int i = 0; i < wInfo.characterCount; i++)
{
int vertexIndex = m_TextMeshPro.textInfo.characterInfo[wInfo.firstCharacterIndex + i].vertexIndex;
Color32 c = uiVertices[vertexIndex + 0].color.Tint(0.75f);
uiVertices[vertexIndex + 0].color = c;
uiVertices[vertexIndex + 1].color = c;
uiVertices[vertexIndex + 2].color = c;
uiVertices[vertexIndex + 3].color = c;
}
m_TextMeshPro.canvasRenderer.SetVertices(uiVertices, uiVertices.Length);
}
*/
#endregion
#region Link Selection Handling
/*
// Check if Mouse intersects any words and if so assign a random color to that word.
int linkIndex = TMP_TextUtilities.FindIntersectingLink(m_TextMeshPro, Input.mousePosition, m_Camera);
if (linkIndex != -1)
{
TMP_LinkInfo linkInfo = m_TextMeshPro.textInfo.linkInfo[linkIndex];
int linkHashCode = linkInfo.hashCode;
//Debug.Log(TMP_TextUtilities.GetSimpleHashCode("id_02"));
switch (linkHashCode)
{
case 291445: // id_01
if (m_LinkObject01 == null)
m_LinkObject01 = Instantiate(Link_01_Prefab);
else
{
m_LinkObject01.gameObject.SetActive(true);
}
break;
case 291446: // id_02
break;
}
// Example of how to modify vertex attributes like colors
#region Vertex Attribute Modification Example
UIVertex[] uiVertices = m_TextMeshPro.textInfo.meshInfo.uiVertices;
Color32 c = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), 255);
for (int i = 0; i < linkInfo.characterCount; i++)
{
TMP_CharacterInfo cInfo = m_TextMeshPro.textInfo.characterInfo[linkInfo.firstCharacterIndex + i];
if (!cInfo.isVisible) continue; // Skip invisible characters.
int vertexIndex = cInfo.vertexIndex;
uiVertices[vertexIndex + 0].color = c;
uiVertices[vertexIndex + 1].color = c;
uiVertices[vertexIndex + 2].color = c;
uiVertices[vertexIndex + 3].color = c;
}
m_TextMeshPro.canvasRenderer.SetVertices(uiVertices, uiVertices.Length);
#endregion
}
*/
#endregion
}
public void OnPointerUp(PointerEventData eventData)
{
//Debug.Log("OnPointerUp()");
}
void RestoreCachedVertexAttributes(int index)
{
if (index == -1 || index > m_TextMeshPro.textInfo.characterCount - 1) return;
// Get the index of the material / sub text object used by this character.
int materialIndex = m_TextMeshPro.textInfo.characterInfo[index].materialReferenceIndex;
// Get the index of the first vertex of the selected character.
int vertexIndex = m_TextMeshPro.textInfo.characterInfo[index].vertexIndex;
// Restore Vertices
// Get a reference to the cached / original vertices.
Vector3[] src_vertices = m_cachedMeshInfoVertexData[materialIndex].vertices;
// Get a reference to the vertices that we need to replace.
Vector3[] dst_vertices = m_TextMeshPro.textInfo.meshInfo[materialIndex].vertices;
// Restore / Copy vertices from source to destination
dst_vertices[vertexIndex + 0] = src_vertices[vertexIndex + 0];
dst_vertices[vertexIndex + 1] = src_vertices[vertexIndex + 1];
dst_vertices[vertexIndex + 2] = src_vertices[vertexIndex + 2];
dst_vertices[vertexIndex + 3] = src_vertices[vertexIndex + 3];
// Restore Vertex Colors
// Get a reference to the vertex colors we need to replace.
Color32[] dst_colors = m_TextMeshPro.textInfo.meshInfo[materialIndex].colors32;
// Get a reference to the cached / original vertex colors.
Color32[] src_colors = m_cachedMeshInfoVertexData[materialIndex].colors32;
// Copy the vertex colors from source to destination.
dst_colors[vertexIndex + 0] = src_colors[vertexIndex + 0];
dst_colors[vertexIndex + 1] = src_colors[vertexIndex + 1];
dst_colors[vertexIndex + 2] = src_colors[vertexIndex + 2];
dst_colors[vertexIndex + 3] = src_colors[vertexIndex + 3];
// Restore UV0S
// UVS0
Vector2[] src_uv0s = m_cachedMeshInfoVertexData[materialIndex].uvs0;
Vector2[] dst_uv0s = m_TextMeshPro.textInfo.meshInfo[materialIndex].uvs0;
dst_uv0s[vertexIndex + 0] = src_uv0s[vertexIndex + 0];
dst_uv0s[vertexIndex + 1] = src_uv0s[vertexIndex + 1];
dst_uv0s[vertexIndex + 2] = src_uv0s[vertexIndex + 2];
dst_uv0s[vertexIndex + 3] = src_uv0s[vertexIndex + 3];
// UVS2
Vector2[] src_uv2s = m_cachedMeshInfoVertexData[materialIndex].uvs2;
Vector2[] dst_uv2s = m_TextMeshPro.textInfo.meshInfo[materialIndex].uvs2;
dst_uv2s[vertexIndex + 0] = src_uv2s[vertexIndex + 0];
dst_uv2s[vertexIndex + 1] = src_uv2s[vertexIndex + 1];
dst_uv2s[vertexIndex + 2] = src_uv2s[vertexIndex + 2];
dst_uv2s[vertexIndex + 3] = src_uv2s[vertexIndex + 3];
// Restore last vertex attribute as we swapped it as well
int lastIndex = (src_vertices.Length / 4 - 1) * 4;
// Vertices
dst_vertices[lastIndex + 0] = src_vertices[lastIndex + 0];
dst_vertices[lastIndex + 1] = src_vertices[lastIndex + 1];
dst_vertices[lastIndex + 2] = src_vertices[lastIndex + 2];
dst_vertices[lastIndex + 3] = src_vertices[lastIndex + 3];
// Vertex Colors
src_colors = m_cachedMeshInfoVertexData[materialIndex].colors32;
dst_colors = m_TextMeshPro.textInfo.meshInfo[materialIndex].colors32;
dst_colors[lastIndex + 0] = src_colors[lastIndex + 0];
dst_colors[lastIndex + 1] = src_colors[lastIndex + 1];
dst_colors[lastIndex + 2] = src_colors[lastIndex + 2];
dst_colors[lastIndex + 3] = src_colors[lastIndex + 3];
// UVS0
src_uv0s = m_cachedMeshInfoVertexData[materialIndex].uvs0;
dst_uv0s = m_TextMeshPro.textInfo.meshInfo[materialIndex].uvs0;
dst_uv0s[lastIndex + 0] = src_uv0s[lastIndex + 0];
dst_uv0s[lastIndex + 1] = src_uv0s[lastIndex + 1];
dst_uv0s[lastIndex + 2] = src_uv0s[lastIndex + 2];
dst_uv0s[lastIndex + 3] = src_uv0s[lastIndex + 3];
// UVS2
src_uv2s = m_cachedMeshInfoVertexData[materialIndex].uvs2;
dst_uv2s = m_TextMeshPro.textInfo.meshInfo[materialIndex].uvs2;
dst_uv2s[lastIndex + 0] = src_uv2s[lastIndex + 0];
dst_uv2s[lastIndex + 1] = src_uv2s[lastIndex + 1];
dst_uv2s[lastIndex + 2] = src_uv2s[lastIndex + 2];
dst_uv2s[lastIndex + 3] = src_uv2s[lastIndex + 3];
// Need to update the appropriate
m_TextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
}
}
}

View File

@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: a05dcd8be7ec4ccbb35c26219884aa37
timeCreated: 1435531209
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences:
- TextPopup_Prefab_01: {fileID: 22450954, guid: b06f0e6c1dfa4356ac918da1bb32c603,
type: 2}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,125 @@
using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class TMP_UiFrameRateCounter : MonoBehaviour
{
public float UpdateInterval = 5.0f;
private float m_LastInterval = 0;
private int m_Frames = 0;
public enum FpsCounterAnchorPositions { TopLeft, BottomLeft, TopRight, BottomRight };
public FpsCounterAnchorPositions AnchorPosition = FpsCounterAnchorPositions.TopRight;
private string htmlColorTag;
private const string fpsLabel = "{0:2}</color> <#8080ff>FPS \n<#FF8000>{1:2} <#8080ff>MS";
private TextMeshProUGUI m_TextMeshPro;
private RectTransform m_frameCounter_transform;
private FpsCounterAnchorPositions last_AnchorPosition;
void Awake()
{
if (!enabled)
return;
Application.targetFrameRate = 1000;
GameObject frameCounter = new GameObject("Frame Counter");
m_frameCounter_transform = frameCounter.AddComponent<RectTransform>();
m_frameCounter_transform.SetParent(this.transform, false);
m_TextMeshPro = frameCounter.AddComponent<TextMeshProUGUI>();
m_TextMeshPro.font = Resources.Load<TMP_FontAsset>("Fonts & Materials/LiberationSans SDF");
m_TextMeshPro.fontSharedMaterial = Resources.Load<Material>("Fonts & Materials/LiberationSans SDF - Overlay");
m_TextMeshPro.enableWordWrapping = false;
m_TextMeshPro.fontSize = 36;
m_TextMeshPro.isOverlay = true;
Set_FrameCounter_Position(AnchorPosition);
last_AnchorPosition = AnchorPosition;
}
void Start()
{
m_LastInterval = Time.realtimeSinceStartup;
m_Frames = 0;
}
void Update()
{
if (AnchorPosition != last_AnchorPosition)
Set_FrameCounter_Position(AnchorPosition);
last_AnchorPosition = AnchorPosition;
m_Frames += 1;
float timeNow = Time.realtimeSinceStartup;
if (timeNow > m_LastInterval + UpdateInterval)
{
// display two fractional digits (f2 format)
float fps = m_Frames / (timeNow - m_LastInterval);
float ms = 1000.0f / Mathf.Max(fps, 0.00001f);
if (fps < 30)
htmlColorTag = "<color=yellow>";
else if (fps < 10)
htmlColorTag = "<color=red>";
else
htmlColorTag = "<color=green>";
m_TextMeshPro.SetText(htmlColorTag + fpsLabel, fps, ms);
m_Frames = 0;
m_LastInterval = timeNow;
}
}
void Set_FrameCounter_Position(FpsCounterAnchorPositions anchor_position)
{
switch (anchor_position)
{
case FpsCounterAnchorPositions.TopLeft:
m_TextMeshPro.alignment = TextAlignmentOptions.TopLeft;
m_frameCounter_transform.pivot = new Vector2(0, 1);
m_frameCounter_transform.anchorMin = new Vector2(0.01f, 0.99f);
m_frameCounter_transform.anchorMax = new Vector2(0.01f, 0.99f);
m_frameCounter_transform.anchoredPosition = new Vector2(0, 1);
break;
case FpsCounterAnchorPositions.BottomLeft:
m_TextMeshPro.alignment = TextAlignmentOptions.BottomLeft;
m_frameCounter_transform.pivot = new Vector2(0, 0);
m_frameCounter_transform.anchorMin = new Vector2(0.01f, 0.01f);
m_frameCounter_transform.anchorMax = new Vector2(0.01f, 0.01f);
m_frameCounter_transform.anchoredPosition = new Vector2(0, 0);
break;
case FpsCounterAnchorPositions.TopRight:
m_TextMeshPro.alignment = TextAlignmentOptions.TopRight;
m_frameCounter_transform.pivot = new Vector2(1, 1);
m_frameCounter_transform.anchorMin = new Vector2(0.99f, 0.99f);
m_frameCounter_transform.anchorMax = new Vector2(0.99f, 0.99f);
m_frameCounter_transform.anchoredPosition = new Vector2(1, 1);
break;
case FpsCounterAnchorPositions.BottomRight:
m_TextMeshPro.alignment = TextAlignmentOptions.BottomRight;
m_frameCounter_transform.pivot = new Vector2(1, 0);
m_frameCounter_transform.anchorMin = new Vector2(0.99f, 0.01f);
m_frameCounter_transform.anchorMax = new Vector2(0.99f, 0.01f);
m_frameCounter_transform.anchoredPosition = new Vector2(1, 0);
break;
}
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 24b0dc2d1d494adbbec1f4db26b4cf83
timeCreated: 1448607572
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,84 @@
using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class TMPro_InstructionOverlay : MonoBehaviour
{
public enum FpsCounterAnchorPositions { TopLeft, BottomLeft, TopRight, BottomRight };
public FpsCounterAnchorPositions AnchorPosition = FpsCounterAnchorPositions.BottomLeft;
private const string instructions = "Camera Control - <#ffff00>Shift + RMB\n</color>Zoom - <#ffff00>Mouse wheel.";
private TextMeshPro m_TextMeshPro;
private TextContainer m_textContainer;
private Transform m_frameCounter_transform;
private Camera m_camera;
//private FpsCounterAnchorPositions last_AnchorPosition;
void Awake()
{
if (!enabled)
return;
m_camera = Camera.main;
GameObject frameCounter = new GameObject("Frame Counter");
m_frameCounter_transform = frameCounter.transform;
m_frameCounter_transform.parent = m_camera.transform;
m_frameCounter_transform.localRotation = Quaternion.identity;
m_TextMeshPro = frameCounter.AddComponent<TextMeshPro>();
m_TextMeshPro.font = Resources.Load<TMP_FontAsset>("Fonts & Materials/LiberationSans SDF");
m_TextMeshPro.fontSharedMaterial = Resources.Load<Material>("Fonts & Materials/LiberationSans SDF - Overlay");
m_TextMeshPro.fontSize = 30;
m_TextMeshPro.isOverlay = true;
m_textContainer = frameCounter.GetComponent<TextContainer>();
Set_FrameCounter_Position(AnchorPosition);
//last_AnchorPosition = AnchorPosition;
m_TextMeshPro.text = instructions;
}
void Set_FrameCounter_Position(FpsCounterAnchorPositions anchor_position)
{
switch (anchor_position)
{
case FpsCounterAnchorPositions.TopLeft:
//m_TextMeshPro.anchor = AnchorPositions.TopLeft;
m_textContainer.anchorPosition = TextContainerAnchors.TopLeft;
m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 1, 100.0f));
break;
case FpsCounterAnchorPositions.BottomLeft:
//m_TextMeshPro.anchor = AnchorPositions.BottomLeft;
m_textContainer.anchorPosition = TextContainerAnchors.BottomLeft;
m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 0, 100.0f));
break;
case FpsCounterAnchorPositions.TopRight:
//m_TextMeshPro.anchor = AnchorPositions.TopRight;
m_textContainer.anchorPosition = TextContainerAnchors.TopRight;
m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 1, 100.0f));
break;
case FpsCounterAnchorPositions.BottomRight:
//m_TextMeshPro.anchor = AnchorPositions.BottomRight;
m_textContainer.anchorPosition = TextContainerAnchors.BottomRight;
m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 0, 100.0f));
break;
}
}
}
}

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: c3c1afeda5e545e0b19add5373896d2e
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,83 @@
using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class TeleType : MonoBehaviour
{
//[Range(0, 100)]
//public int RevealSpeed = 50;
private string label01 = "Example <sprite=2> of using <sprite=7> <#ffa000>Graphics Inline</color> <sprite=5> with Text in <font=\"Bangers SDF\" material=\"Bangers SDF - Drop Shadow\">TextMesh<#40a0ff>Pro</color></font><sprite=0> and Unity<sprite=1>";
private string label02 = "Example <sprite=2> of using <sprite=7> <#ffa000>Graphics Inline</color> <sprite=5> with Text in <font=\"Bangers SDF\" material=\"Bangers SDF - Drop Shadow\">TextMesh<#40a0ff>Pro</color></font><sprite=0> and Unity<sprite=2>";
private TMP_Text m_textMeshPro;
void Awake()
{
// Get Reference to TextMeshPro Component
m_textMeshPro = GetComponent<TMP_Text>();
m_textMeshPro.text = label01;
m_textMeshPro.enableWordWrapping = true;
m_textMeshPro.alignment = TextAlignmentOptions.Top;
//if (GetComponentInParent(typeof(Canvas)) as Canvas == null)
//{
// GameObject canvas = new GameObject("Canvas", typeof(Canvas));
// gameObject.transform.SetParent(canvas.transform);
// canvas.GetComponent<Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
// // Set RectTransform Size
// gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(500, 300);
// m_textMeshPro.fontSize = 48;
//}
}
IEnumerator Start()
{
// Force and update of the mesh to get valid information.
m_textMeshPro.ForceMeshUpdate();
int totalVisibleCharacters = m_textMeshPro.textInfo.characterCount; // Get # of Visible Character in text object
int counter = 0;
int visibleCount = 0;
while (true)
{
visibleCount = counter % (totalVisibleCharacters + 1);
m_textMeshPro.maxVisibleCharacters = visibleCount; // How many characters should TextMeshPro display?
// Once the last character has been revealed, wait 1.0 second and start over.
if (visibleCount >= totalVisibleCharacters)
{
yield return new WaitForSeconds(1.0f);
m_textMeshPro.text = label02;
yield return new WaitForSeconds(1.0f);
m_textMeshPro.text = label01;
yield return new WaitForSeconds(1.0f);
}
counter += 1;
yield return new WaitForSeconds(0.05f);
}
//Debug.Log("Done revealing the text.");
}
}
}

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: e32c266ee6204b21a427753cb0694c81
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,121 @@
using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class TextConsoleSimulator : MonoBehaviour
{
private TMP_Text m_TextComponent;
private bool hasTextChanged;
void Awake()
{
m_TextComponent = gameObject.GetComponent<TMP_Text>();
}
void Start()
{
StartCoroutine(RevealCharacters(m_TextComponent));
//StartCoroutine(RevealWords(m_TextComponent));
}
void OnEnable()
{
// Subscribe to event fired when text object has been regenerated.
TMPro_EventManager.TEXT_CHANGED_EVENT.Add(ON_TEXT_CHANGED);
}
void OnDisable()
{
TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(ON_TEXT_CHANGED);
}
// Event received when the text object has changed.
void ON_TEXT_CHANGED(Object obj)
{
hasTextChanged = true;
}
/// <summary>
/// Method revealing the text one character at a time.
/// </summary>
/// <returns></returns>
IEnumerator RevealCharacters(TMP_Text textComponent)
{
textComponent.ForceMeshUpdate();
TMP_TextInfo textInfo = textComponent.textInfo;
int totalVisibleCharacters = textInfo.characterCount; // Get # of Visible Character in text object
int visibleCount = 0;
while (true)
{
if (hasTextChanged)
{
totalVisibleCharacters = textInfo.characterCount; // Update visible character count.
hasTextChanged = false;
}
if (visibleCount > totalVisibleCharacters)
{
yield return new WaitForSeconds(1.0f);
visibleCount = 0;
}
textComponent.maxVisibleCharacters = visibleCount; // How many characters should TextMeshPro display?
visibleCount += 1;
yield return null;
}
}
/// <summary>
/// Method revealing the text one word at a time.
/// </summary>
/// <returns></returns>
IEnumerator RevealWords(TMP_Text textComponent)
{
textComponent.ForceMeshUpdate();
int totalWordCount = textComponent.textInfo.wordCount;
int totalVisibleCharacters = textComponent.textInfo.characterCount; // Get # of Visible Character in text object
int counter = 0;
int currentWord = 0;
int visibleCount = 0;
while (true)
{
currentWord = counter % (totalWordCount + 1);
// Get last character index for the current word.
if (currentWord == 0) // Display no words.
visibleCount = 0;
else if (currentWord < totalWordCount) // Display all other words with the exception of the last one.
visibleCount = textComponent.textInfo.wordInfo[currentWord - 1].lastCharacterIndex + 1;
else if (currentWord == totalWordCount) // Display last word and all remaining characters.
visibleCount = totalVisibleCharacters;
textComponent.maxVisibleCharacters = visibleCount; // How many characters should TextMeshPro display?
// Once the last character has been revealed, wait 1.0 second and start over.
if (visibleCount >= totalVisibleCharacters)
{
yield return new WaitForSeconds(1.0f);
}
counter += 1;
yield return new WaitForSeconds(0.1f);
}
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 43bcd35a1c0c40ccb6d472893fe2093f
timeCreated: 1435298333
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,223 @@
using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class TextMeshProFloatingText : MonoBehaviour
{
public Font TheFont;
private GameObject m_floatingText;
private TextMeshPro m_textMeshPro;
private TextMesh m_textMesh;
private Transform m_transform;
private Transform m_floatingText_Transform;
private Transform m_cameraTransform;
Vector3 lastPOS = Vector3.zero;
Quaternion lastRotation = Quaternion.identity;
public int SpawnType;
// public bool IsTextObjectScaleStatic;
//private int m_frame = 0;
static WaitForEndOfFrame k_WaitForEndOfFrame = new WaitForEndOfFrame();
static WaitForSeconds[] k_WaitForSecondsRandom = new WaitForSeconds[]
{
new WaitForSeconds(0.05f), new WaitForSeconds(0.1f), new WaitForSeconds(0.15f), new WaitForSeconds(0.2f), new WaitForSeconds(0.25f),
new WaitForSeconds(0.3f), new WaitForSeconds(0.35f), new WaitForSeconds(0.4f), new WaitForSeconds(0.45f), new WaitForSeconds(0.5f),
new WaitForSeconds(0.55f), new WaitForSeconds(0.6f), new WaitForSeconds(0.65f), new WaitForSeconds(0.7f), new WaitForSeconds(0.75f),
new WaitForSeconds(0.8f), new WaitForSeconds(0.85f), new WaitForSeconds(0.9f), new WaitForSeconds(0.95f), new WaitForSeconds(1.0f),
};
void Awake()
{
m_transform = transform;
m_floatingText = new GameObject(this.name + " floating text");
// Reference to Transform is lost when TMP component is added since it replaces it by a RectTransform.
//m_floatingText_Transform = m_floatingText.transform;
//m_floatingText_Transform.position = m_transform.position + new Vector3(0, 15f, 0);
m_cameraTransform = Camera.main.transform;
}
void Start()
{
if (SpawnType == 0)
{
// TextMesh Pro Implementation
m_textMeshPro = m_floatingText.AddComponent<TextMeshPro>();
m_textMeshPro.rectTransform.sizeDelta = new Vector2(3, 3);
m_floatingText_Transform = m_floatingText.transform;
m_floatingText_Transform.position = m_transform.position + new Vector3(0, 15f, 0);
//m_textMeshPro.fontAsset = Resources.Load("Fonts & Materials/JOKERMAN SDF", typeof(TextMeshProFont)) as TextMeshProFont; // User should only provide a string to the resource.
//m_textMeshPro.fontSharedMaterial = Resources.Load("Fonts & Materials/LiberationSans SDF", typeof(Material)) as Material;
m_textMeshPro.alignment = TextAlignmentOptions.Center;
m_textMeshPro.color = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), 255);
m_textMeshPro.fontSize = 24;
//m_textMeshPro.enableExtraPadding = true;
//m_textMeshPro.enableShadows = false;
m_textMeshPro.enableKerning = false;
m_textMeshPro.text = string.Empty;
//m_textMeshPro.isTextObjectScaleStatic = IsTextObjectScaleStatic;
StartCoroutine(DisplayTextMeshProFloatingText());
}
else if (SpawnType == 1)
{
//Debug.Log("Spawning TextMesh Objects.");
m_floatingText_Transform = m_floatingText.transform;
m_floatingText_Transform.position = m_transform.position + new Vector3(0, 15f, 0);
m_textMesh = m_floatingText.AddComponent<TextMesh>();
m_textMesh.font = Resources.Load<Font>("Fonts/ARIAL");
m_textMesh.GetComponent<Renderer>().sharedMaterial = m_textMesh.font.material;
m_textMesh.color = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), 255);
m_textMesh.anchor = TextAnchor.LowerCenter;
m_textMesh.fontSize = 24;
StartCoroutine(DisplayTextMeshFloatingText());
}
else if (SpawnType == 2)
{
}
}
//void Update()
//{
// if (SpawnType == 0)
// {
// m_textMeshPro.SetText("{0}", m_frame);
// }
// else
// {
// m_textMesh.text = m_frame.ToString();
// }
// m_frame = (m_frame + 1) % 1000;
//}
public IEnumerator DisplayTextMeshProFloatingText()
{
float CountDuration = 2.0f; // How long is the countdown alive.
float starting_Count = Random.Range(5f, 20f); // At what number is the counter starting at.
float current_Count = starting_Count;
Vector3 start_pos = m_floatingText_Transform.position;
Color32 start_color = m_textMeshPro.color;
float alpha = 255;
int int_counter = 0;
float fadeDuration = 3 / starting_Count * CountDuration;
while (current_Count > 0)
{
current_Count -= (Time.deltaTime / CountDuration) * starting_Count;
if (current_Count <= 3)
{
//Debug.Log("Fading Counter ... " + current_Count.ToString("f2"));
alpha = Mathf.Clamp(alpha - (Time.deltaTime / fadeDuration) * 255, 0, 255);
}
int_counter = (int)current_Count;
m_textMeshPro.text = int_counter.ToString();
//m_textMeshPro.SetText("{0}", (int)current_Count);
m_textMeshPro.color = new Color32(start_color.r, start_color.g, start_color.b, (byte)alpha);
// Move the floating text upward each update
m_floatingText_Transform.position += new Vector3(0, starting_Count * Time.deltaTime, 0);
// Align floating text perpendicular to Camera.
if (!lastPOS.Compare(m_cameraTransform.position, 1000) || !lastRotation.Compare(m_cameraTransform.rotation, 1000))
{
lastPOS = m_cameraTransform.position;
lastRotation = m_cameraTransform.rotation;
m_floatingText_Transform.rotation = lastRotation;
Vector3 dir = m_transform.position - lastPOS;
m_transform.forward = new Vector3(dir.x, 0, dir.z);
}
yield return k_WaitForEndOfFrame;
}
//Debug.Log("Done Counting down.");
yield return k_WaitForSecondsRandom[Random.Range(0, 19)];
m_floatingText_Transform.position = start_pos;
StartCoroutine(DisplayTextMeshProFloatingText());
}
public IEnumerator DisplayTextMeshFloatingText()
{
float CountDuration = 2.0f; // How long is the countdown alive.
float starting_Count = Random.Range(5f, 20f); // At what number is the counter starting at.
float current_Count = starting_Count;
Vector3 start_pos = m_floatingText_Transform.position;
Color32 start_color = m_textMesh.color;
float alpha = 255;
int int_counter = 0;
float fadeDuration = 3 / starting_Count * CountDuration;
while (current_Count > 0)
{
current_Count -= (Time.deltaTime / CountDuration) * starting_Count;
if (current_Count <= 3)
{
//Debug.Log("Fading Counter ... " + current_Count.ToString("f2"));
alpha = Mathf.Clamp(alpha - (Time.deltaTime / fadeDuration) * 255, 0, 255);
}
int_counter = (int)current_Count;
m_textMesh.text = int_counter.ToString();
//Debug.Log("Current Count:" + current_Count.ToString("f2"));
m_textMesh.color = new Color32(start_color.r, start_color.g, start_color.b, (byte)alpha);
// Move the floating text upward each update
m_floatingText_Transform.position += new Vector3(0, starting_Count * Time.deltaTime, 0);
// Align floating text perpendicular to Camera.
if (!lastPOS.Compare(m_cameraTransform.position, 1000) || !lastRotation.Compare(m_cameraTransform.rotation, 1000))
{
lastPOS = m_cameraTransform.position;
lastRotation = m_cameraTransform.rotation;
m_floatingText_Transform.rotation = lastRotation;
Vector3 dir = m_transform.position - lastPOS;
m_transform.forward = new Vector3(dir.x, 0, dir.z);
}
yield return k_WaitForEndOfFrame;
}
//Debug.Log("Done Counting down.");
yield return k_WaitForSecondsRandom[Random.Range(0, 20)];
m_floatingText_Transform.position = start_pos;
StartCoroutine(DisplayTextMeshFloatingText());
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a4d4c76e63944cba8c7d00f56334b98c
MonoImporter:
serializedVersion: 2
defaultReferences:
- TheFont: {instanceID: 0}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,79 @@
using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class TextMeshSpawner : MonoBehaviour
{
public int SpawnType = 0;
public int NumberOfNPC = 12;
public Font TheFont;
private TextMeshProFloatingText floatingText_Script;
void Awake()
{
}
void Start()
{
for (int i = 0; i < NumberOfNPC; i++)
{
if (SpawnType == 0)
{
// TextMesh Pro Implementation
//go.transform.localScale = new Vector3(2, 2, 2);
GameObject go = new GameObject(); //"NPC " + i);
go.transform.position = new Vector3(Random.Range(-95f, 95f), 0.5f, Random.Range(-95f, 95f));
//go.transform.position = new Vector3(0, 1.01f, 0);
//go.renderer.castShadows = false;
//go.renderer.receiveShadows = false;
//go.transform.rotation = Quaternion.Euler(0, Random.Range(0, 360), 0);
TextMeshPro textMeshPro = go.AddComponent<TextMeshPro>();
//textMeshPro.FontAsset = Resources.Load("Fonts & Materials/LiberationSans SDF", typeof(TextMeshProFont)) as TextMeshProFont;
//textMeshPro.anchor = AnchorPositions.Bottom;
textMeshPro.fontSize = 96;
textMeshPro.text = "!";
textMeshPro.color = new Color32(255, 255, 0, 255);
//textMeshPro.Text = "!";
// Spawn Floating Text
floatingText_Script = go.AddComponent<TextMeshProFloatingText>();
floatingText_Script.SpawnType = 0;
}
else
{
// TextMesh Implementation
GameObject go = new GameObject(); //"NPC " + i);
go.transform.position = new Vector3(Random.Range(-95f, 95f), 0.5f, Random.Range(-95f, 95f));
//go.transform.position = new Vector3(0, 1.01f, 0);
TextMesh textMesh = go.AddComponent<TextMesh>();
textMesh.GetComponent<Renderer>().sharedMaterial = TheFont.material;
textMesh.font = TheFont;
textMesh.anchor = TextAnchor.LowerCenter;
textMesh.fontSize = 96;
textMesh.color = new Color32(255, 255, 0, 255);
textMesh.text = "!";
// Spawn Floating Text
floatingText_Script = go.AddComponent<TextMeshProFloatingText>();
floatingText_Script.SpawnType = 1;
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 76c11bbcfddf44e0ba17d6c2751c8d84
MonoImporter:
serializedVersion: 2
defaultReferences:
- TheFont: {instanceID: 0}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,84 @@
using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class VertexColorCycler : MonoBehaviour
{
private TMP_Text m_TextComponent;
void Awake()
{
m_TextComponent = GetComponent<TMP_Text>();
}
void Start()
{
StartCoroutine(AnimateVertexColors());
}
/// <summary>
/// Method to animate vertex colors of a TMP Text object.
/// </summary>
/// <returns></returns>
IEnumerator AnimateVertexColors()
{
// Force the text object to update right away so we can have geometry to modify right from the start.
m_TextComponent.ForceMeshUpdate();
TMP_TextInfo textInfo = m_TextComponent.textInfo;
int currentCharacter = 0;
Color32[] newVertexColors;
Color32 c0 = m_TextComponent.color;
while (true)
{
int characterCount = textInfo.characterCount;
// If No Characters then just yield and wait for some text to be added
if (characterCount == 0)
{
yield return new WaitForSeconds(0.25f);
continue;
}
// Get the index of the material used by the current character.
int materialIndex = textInfo.characterInfo[currentCharacter].materialReferenceIndex;
// Get the vertex colors of the mesh used by this text element (character or sprite).
newVertexColors = textInfo.meshInfo[materialIndex].colors32;
// Get the index of the first vertex used by this text element.
int vertexIndex = textInfo.characterInfo[currentCharacter].vertexIndex;
// Only change the vertex color if the text element is visible.
if (textInfo.characterInfo[currentCharacter].isVisible)
{
c0 = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), 255);
newVertexColors[vertexIndex + 0] = c0;
newVertexColors[vertexIndex + 1] = c0;
newVertexColors[vertexIndex + 2] = c0;
newVertexColors[vertexIndex + 3] = c0;
// New function which pushes (all) updated vertex data to the appropriate meshes when using either the Mesh Renderer or CanvasRenderer.
m_TextComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.Colors32);
// This last process could be done to only update the vertex data that has changed as opposed to all of the vertex data but it would require extra steps and knowing what type of renderer is used.
// These extra steps would be a performance optimization but it is unlikely that such optimization will be necessary.
}
currentCharacter = (currentCharacter + 1) % characterCount;
yield return new WaitForSeconds(0.05f);
}
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 91b8ba3d52e041fab2d0e0f169855539
timeCreated: 1457047157
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,175 @@
using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class VertexJitter : MonoBehaviour
{
public float AngleMultiplier = 1.0f;
public float SpeedMultiplier = 1.0f;
public float CurveScale = 1.0f;
private TMP_Text m_TextComponent;
private bool hasTextChanged;
/// <summary>
/// Structure to hold pre-computed animation data.
/// </summary>
private struct VertexAnim
{
public float angleRange;
public float angle;
public float speed;
}
void Awake()
{
m_TextComponent = GetComponent<TMP_Text>();
}
void OnEnable()
{
// Subscribe to event fired when text object has been regenerated.
TMPro_EventManager.TEXT_CHANGED_EVENT.Add(ON_TEXT_CHANGED);
}
void OnDisable()
{
TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(ON_TEXT_CHANGED);
}
void Start()
{
StartCoroutine(AnimateVertexColors());
}
void ON_TEXT_CHANGED(Object obj)
{
if (obj == m_TextComponent)
hasTextChanged = true;
}
/// <summary>
/// Method to animate vertex colors of a TMP Text object.
/// </summary>
/// <returns></returns>
IEnumerator AnimateVertexColors()
{
// We force an update of the text object since it would only be updated at the end of the frame. Ie. before this code is executed on the first frame.
// Alternatively, we could yield and wait until the end of the frame when the text object will be generated.
m_TextComponent.ForceMeshUpdate();
TMP_TextInfo textInfo = m_TextComponent.textInfo;
Matrix4x4 matrix;
int loopCount = 0;
hasTextChanged = true;
// Create an Array which contains pre-computed Angle Ranges and Speeds for a bunch of characters.
VertexAnim[] vertexAnim = new VertexAnim[1024];
for (int i = 0; i < 1024; i++)
{
vertexAnim[i].angleRange = Random.Range(10f, 25f);
vertexAnim[i].speed = Random.Range(1f, 3f);
}
// Cache the vertex data of the text object as the Jitter FX is applied to the original position of the characters.
TMP_MeshInfo[] cachedMeshInfo = textInfo.CopyMeshInfoVertexData();
while (true)
{
// Get new copy of vertex data if the text has changed.
if (hasTextChanged)
{
// Update the copy of the vertex data for the text object.
cachedMeshInfo = textInfo.CopyMeshInfoVertexData();
hasTextChanged = false;
}
int characterCount = textInfo.characterCount;
// If No Characters then just yield and wait for some text to be added
if (characterCount == 0)
{
yield return new WaitForSeconds(0.25f);
continue;
}
for (int i = 0; i < characterCount; i++)
{
TMP_CharacterInfo charInfo = textInfo.characterInfo[i];
// Skip characters that are not visible and thus have no geometry to manipulate.
if (!charInfo.isVisible)
continue;
// Retrieve the pre-computed animation data for the given character.
VertexAnim vertAnim = vertexAnim[i];
// Get the index of the material used by the current character.
int materialIndex = textInfo.characterInfo[i].materialReferenceIndex;
// Get the index of the first vertex used by this text element.
int vertexIndex = textInfo.characterInfo[i].vertexIndex;
// Get the cached vertices of the mesh used by this text element (character or sprite).
Vector3[] sourceVertices = cachedMeshInfo[materialIndex].vertices;
// Determine the center point of each character at the baseline.
//Vector2 charMidBasline = new Vector2((sourceVertices[vertexIndex + 0].x + sourceVertices[vertexIndex + 2].x) / 2, charInfo.baseLine);
// Determine the center point of each character.
Vector2 charMidBasline = (sourceVertices[vertexIndex + 0] + sourceVertices[vertexIndex + 2]) / 2;
// Need to translate all 4 vertices of each quad to aligned with middle of character / baseline.
// This is needed so the matrix TRS is applied at the origin for each character.
Vector3 offset = charMidBasline;
Vector3[] destinationVertices = textInfo.meshInfo[materialIndex].vertices;
destinationVertices[vertexIndex + 0] = sourceVertices[vertexIndex + 0] - offset;
destinationVertices[vertexIndex + 1] = sourceVertices[vertexIndex + 1] - offset;
destinationVertices[vertexIndex + 2] = sourceVertices[vertexIndex + 2] - offset;
destinationVertices[vertexIndex + 3] = sourceVertices[vertexIndex + 3] - offset;
vertAnim.angle = Mathf.SmoothStep(-vertAnim.angleRange, vertAnim.angleRange, Mathf.PingPong(loopCount / 25f * vertAnim.speed, 1f));
Vector3 jitterOffset = new Vector3(Random.Range(-.25f, .25f), Random.Range(-.25f, .25f), 0);
matrix = Matrix4x4.TRS(jitterOffset * CurveScale, Quaternion.Euler(0, 0, Random.Range(-5f, 5f) * AngleMultiplier), Vector3.one);
destinationVertices[vertexIndex + 0] = matrix.MultiplyPoint3x4(destinationVertices[vertexIndex + 0]);
destinationVertices[vertexIndex + 1] = matrix.MultiplyPoint3x4(destinationVertices[vertexIndex + 1]);
destinationVertices[vertexIndex + 2] = matrix.MultiplyPoint3x4(destinationVertices[vertexIndex + 2]);
destinationVertices[vertexIndex + 3] = matrix.MultiplyPoint3x4(destinationVertices[vertexIndex + 3]);
destinationVertices[vertexIndex + 0] += offset;
destinationVertices[vertexIndex + 1] += offset;
destinationVertices[vertexIndex + 2] += offset;
destinationVertices[vertexIndex + 3] += offset;
vertexAnim[i] = vertAnim;
}
// Push changes into meshes
for (int i = 0; i < textInfo.meshInfo.Length; i++)
{
textInfo.meshInfo[i].mesh.vertices = textInfo.meshInfo[i].vertices;
m_TextComponent.UpdateGeometry(textInfo.meshInfo[i].mesh, i);
}
loopCount += 1;
yield return new WaitForSeconds(0.1f);
}
}
}
}

View File

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

View File

@ -0,0 +1,161 @@
using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class VertexShakeA : MonoBehaviour
{
public float AngleMultiplier = 1.0f;
public float SpeedMultiplier = 1.0f;
public float ScaleMultiplier = 1.0f;
public float RotationMultiplier = 1.0f;
private TMP_Text m_TextComponent;
private bool hasTextChanged;
void Awake()
{
m_TextComponent = GetComponent<TMP_Text>();
}
void OnEnable()
{
// Subscribe to event fired when text object has been regenerated.
TMPro_EventManager.TEXT_CHANGED_EVENT.Add(ON_TEXT_CHANGED);
}
void OnDisable()
{
TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(ON_TEXT_CHANGED);
}
void Start()
{
StartCoroutine(AnimateVertexColors());
}
void ON_TEXT_CHANGED(Object obj)
{
if (obj = m_TextComponent)
hasTextChanged = true;
}
/// <summary>
/// Method to animate vertex colors of a TMP Text object.
/// </summary>
/// <returns></returns>
IEnumerator AnimateVertexColors()
{
// We force an update of the text object since it would only be updated at the end of the frame. Ie. before this code is executed on the first frame.
// Alternatively, we could yield and wait until the end of the frame when the text object will be generated.
m_TextComponent.ForceMeshUpdate();
TMP_TextInfo textInfo = m_TextComponent.textInfo;
Matrix4x4 matrix;
Vector3[][] copyOfVertices = new Vector3[0][];
hasTextChanged = true;
while (true)
{
// Allocate new vertices
if (hasTextChanged)
{
if (copyOfVertices.Length < textInfo.meshInfo.Length)
copyOfVertices = new Vector3[textInfo.meshInfo.Length][];
for (int i = 0; i < textInfo.meshInfo.Length; i++)
{
int length = textInfo.meshInfo[i].vertices.Length;
copyOfVertices[i] = new Vector3[length];
}
hasTextChanged = false;
}
int characterCount = textInfo.characterCount;
// If No Characters then just yield and wait for some text to be added
if (characterCount == 0)
{
yield return new WaitForSeconds(0.25f);
continue;
}
int lineCount = textInfo.lineCount;
// Iterate through each line of the text.
for (int i = 0; i < lineCount; i++)
{
int first = textInfo.lineInfo[i].firstCharacterIndex;
int last = textInfo.lineInfo[i].lastCharacterIndex;
// Determine the center of each line
Vector3 centerOfLine = (textInfo.characterInfo[first].bottomLeft + textInfo.characterInfo[last].topRight) / 2;
Quaternion rotation = Quaternion.Euler(0, 0, Random.Range(-0.25f, 0.25f) * RotationMultiplier);
// Iterate through each character of the line.
for (int j = first; j <= last; j++)
{
// Skip characters that are not visible and thus have no geometry to manipulate.
if (!textInfo.characterInfo[j].isVisible)
continue;
// Get the index of the material used by the current character.
int materialIndex = textInfo.characterInfo[j].materialReferenceIndex;
// Get the index of the first vertex used by this text element.
int vertexIndex = textInfo.characterInfo[j].vertexIndex;
// Get the vertices of the mesh used by this text element (character or sprite).
Vector3[] sourceVertices = textInfo.meshInfo[materialIndex].vertices;
// Need to translate all 4 vertices of each quad to aligned with center of character.
// This is needed so the matrix TRS is applied at the origin for each character.
copyOfVertices[materialIndex][vertexIndex + 0] = sourceVertices[vertexIndex + 0] - centerOfLine;
copyOfVertices[materialIndex][vertexIndex + 1] = sourceVertices[vertexIndex + 1] - centerOfLine;
copyOfVertices[materialIndex][vertexIndex + 2] = sourceVertices[vertexIndex + 2] - centerOfLine;
copyOfVertices[materialIndex][vertexIndex + 3] = sourceVertices[vertexIndex + 3] - centerOfLine;
// Determine the random scale change for each character.
float randomScale = Random.Range(0.995f - 0.001f * ScaleMultiplier, 1.005f + 0.001f * ScaleMultiplier);
// Setup the matrix rotation.
matrix = Matrix4x4.TRS(Vector3.one, rotation, Vector3.one * randomScale);
// Apply the matrix TRS to the individual characters relative to the center of the current line.
copyOfVertices[materialIndex][vertexIndex + 0] = matrix.MultiplyPoint3x4(copyOfVertices[materialIndex][vertexIndex + 0]);
copyOfVertices[materialIndex][vertexIndex + 1] = matrix.MultiplyPoint3x4(copyOfVertices[materialIndex][vertexIndex + 1]);
copyOfVertices[materialIndex][vertexIndex + 2] = matrix.MultiplyPoint3x4(copyOfVertices[materialIndex][vertexIndex + 2]);
copyOfVertices[materialIndex][vertexIndex + 3] = matrix.MultiplyPoint3x4(copyOfVertices[materialIndex][vertexIndex + 3]);
// Revert the translation change.
copyOfVertices[materialIndex][vertexIndex + 0] += centerOfLine;
copyOfVertices[materialIndex][vertexIndex + 1] += centerOfLine;
copyOfVertices[materialIndex][vertexIndex + 2] += centerOfLine;
copyOfVertices[materialIndex][vertexIndex + 3] += centerOfLine;
}
}
// Push changes into meshes
for (int i = 0; i < textInfo.meshInfo.Length; i++)
{
textInfo.meshInfo[i].mesh.vertices = copyOfVertices[i];
m_TextComponent.UpdateGeometry(textInfo.meshInfo[i].mesh, i);
}
yield return new WaitForSeconds(0.1f);
}
}
}
}

View File

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

View File

@ -0,0 +1,185 @@
using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class VertexShakeB : MonoBehaviour
{
public float AngleMultiplier = 1.0f;
public float SpeedMultiplier = 1.0f;
public float CurveScale = 1.0f;
private TMP_Text m_TextComponent;
private bool hasTextChanged;
void Awake()
{
m_TextComponent = GetComponent<TMP_Text>();
}
void OnEnable()
{
// Subscribe to event fired when text object has been regenerated.
TMPro_EventManager.TEXT_CHANGED_EVENT.Add(ON_TEXT_CHANGED);
}
void OnDisable()
{
TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(ON_TEXT_CHANGED);
}
void Start()
{
StartCoroutine(AnimateVertexColors());
}
void ON_TEXT_CHANGED(Object obj)
{
if (obj = m_TextComponent)
hasTextChanged = true;
}
/// <summary>
/// Method to animate vertex colors of a TMP Text object.
/// </summary>
/// <returns></returns>
IEnumerator AnimateVertexColors()
{
// We force an update of the text object since it would only be updated at the end of the frame. Ie. before this code is executed on the first frame.
// Alternatively, we could yield and wait until the end of the frame when the text object will be generated.
m_TextComponent.ForceMeshUpdate();
TMP_TextInfo textInfo = m_TextComponent.textInfo;
Matrix4x4 matrix;
Vector3[][] copyOfVertices = new Vector3[0][];
hasTextChanged = true;
while (true)
{
// Allocate new vertices
if (hasTextChanged)
{
if (copyOfVertices.Length < textInfo.meshInfo.Length)
copyOfVertices = new Vector3[textInfo.meshInfo.Length][];
for (int i = 0; i < textInfo.meshInfo.Length; i++)
{
int length = textInfo.meshInfo[i].vertices.Length;
copyOfVertices[i] = new Vector3[length];
}
hasTextChanged = false;
}
int characterCount = textInfo.characterCount;
// If No Characters then just yield and wait for some text to be added
if (characterCount == 0)
{
yield return new WaitForSeconds(0.25f);
continue;
}
int lineCount = textInfo.lineCount;
// Iterate through each line of the text.
for (int i = 0; i < lineCount; i++)
{
int first = textInfo.lineInfo[i].firstCharacterIndex;
int last = textInfo.lineInfo[i].lastCharacterIndex;
// Determine the center of each line
Vector3 centerOfLine = (textInfo.characterInfo[first].bottomLeft + textInfo.characterInfo[last].topRight) / 2;
Quaternion rotation = Quaternion.Euler(0, 0, Random.Range(-0.25f, 0.25f));
// Iterate through each character of the line.
for (int j = first; j <= last; j++)
{
// Skip characters that are not visible and thus have no geometry to manipulate.
if (!textInfo.characterInfo[j].isVisible)
continue;
// Get the index of the material used by the current character.
int materialIndex = textInfo.characterInfo[j].materialReferenceIndex;
// Get the index of the first vertex used by this text element.
int vertexIndex = textInfo.characterInfo[j].vertexIndex;
// Get the vertices of the mesh used by this text element (character or sprite).
Vector3[] sourceVertices = textInfo.meshInfo[materialIndex].vertices;
// Determine the center point of each character at the baseline.
Vector3 charCenter = (sourceVertices[vertexIndex + 0] + sourceVertices[vertexIndex + 2]) / 2;
// Need to translate all 4 vertices of each quad to aligned with center of character.
// This is needed so the matrix TRS is applied at the origin for each character.
copyOfVertices[materialIndex][vertexIndex + 0] = sourceVertices[vertexIndex + 0] - charCenter;
copyOfVertices[materialIndex][vertexIndex + 1] = sourceVertices[vertexIndex + 1] - charCenter;
copyOfVertices[materialIndex][vertexIndex + 2] = sourceVertices[vertexIndex + 2] - charCenter;
copyOfVertices[materialIndex][vertexIndex + 3] = sourceVertices[vertexIndex + 3] - charCenter;
// Determine the random scale change for each character.
float randomScale = Random.Range(0.95f, 1.05f);
// Setup the matrix for the scale change.
matrix = Matrix4x4.TRS(Vector3.one, Quaternion.identity, Vector3.one * randomScale);
// Apply the scale change relative to the center of each character.
copyOfVertices[materialIndex][vertexIndex + 0] = matrix.MultiplyPoint3x4(copyOfVertices[materialIndex][vertexIndex + 0]);
copyOfVertices[materialIndex][vertexIndex + 1] = matrix.MultiplyPoint3x4(copyOfVertices[materialIndex][vertexIndex + 1]);
copyOfVertices[materialIndex][vertexIndex + 2] = matrix.MultiplyPoint3x4(copyOfVertices[materialIndex][vertexIndex + 2]);
copyOfVertices[materialIndex][vertexIndex + 3] = matrix.MultiplyPoint3x4(copyOfVertices[materialIndex][vertexIndex + 3]);
// Revert the translation change.
copyOfVertices[materialIndex][vertexIndex + 0] += charCenter;
copyOfVertices[materialIndex][vertexIndex + 1] += charCenter;
copyOfVertices[materialIndex][vertexIndex + 2] += charCenter;
copyOfVertices[materialIndex][vertexIndex + 3] += charCenter;
// Need to translate all 4 vertices of each quad to aligned with the center of the line.
// This is needed so the matrix TRS is applied from the center of the line.
copyOfVertices[materialIndex][vertexIndex + 0] -= centerOfLine;
copyOfVertices[materialIndex][vertexIndex + 1] -= centerOfLine;
copyOfVertices[materialIndex][vertexIndex + 2] -= centerOfLine;
copyOfVertices[materialIndex][vertexIndex + 3] -= centerOfLine;
// Setup the matrix rotation.
matrix = Matrix4x4.TRS(Vector3.one, rotation, Vector3.one);
// Apply the matrix TRS to the individual characters relative to the center of the current line.
copyOfVertices[materialIndex][vertexIndex + 0] = matrix.MultiplyPoint3x4(copyOfVertices[materialIndex][vertexIndex + 0]);
copyOfVertices[materialIndex][vertexIndex + 1] = matrix.MultiplyPoint3x4(copyOfVertices[materialIndex][vertexIndex + 1]);
copyOfVertices[materialIndex][vertexIndex + 2] = matrix.MultiplyPoint3x4(copyOfVertices[materialIndex][vertexIndex + 2]);
copyOfVertices[materialIndex][vertexIndex + 3] = matrix.MultiplyPoint3x4(copyOfVertices[materialIndex][vertexIndex + 3]);
// Revert the translation change.
copyOfVertices[materialIndex][vertexIndex + 0] += centerOfLine;
copyOfVertices[materialIndex][vertexIndex + 1] += centerOfLine;
copyOfVertices[materialIndex][vertexIndex + 2] += centerOfLine;
copyOfVertices[materialIndex][vertexIndex + 3] += centerOfLine;
}
}
// Push changes into meshes
for (int i = 0; i < textInfo.meshInfo.Length; i++)
{
textInfo.meshInfo[i].mesh.vertices = copyOfVertices[i];
m_TextComponent.UpdateGeometry(textInfo.meshInfo[i].mesh, i);
}
yield return new WaitForSeconds(0.1f);
}
}
}
}

View File

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

View File

@ -0,0 +1,192 @@
using UnityEngine;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace TMPro.Examples
{
public class VertexZoom : MonoBehaviour
{
public float AngleMultiplier = 1.0f;
public float SpeedMultiplier = 1.0f;
public float CurveScale = 1.0f;
private TMP_Text m_TextComponent;
private bool hasTextChanged;
void Awake()
{
m_TextComponent = GetComponent<TMP_Text>();
}
void OnEnable()
{
// Subscribe to event fired when text object has been regenerated.
TMPro_EventManager.TEXT_CHANGED_EVENT.Add(ON_TEXT_CHANGED);
}
void OnDisable()
{
// UnSubscribe to event fired when text object has been regenerated.
TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(ON_TEXT_CHANGED);
}
void Start()
{
StartCoroutine(AnimateVertexColors());
}
void ON_TEXT_CHANGED(Object obj)
{
if (obj == m_TextComponent)
hasTextChanged = true;
}
/// <summary>
/// Method to animate vertex colors of a TMP Text object.
/// </summary>
/// <returns></returns>
IEnumerator AnimateVertexColors()
{
// We force an update of the text object since it would only be updated at the end of the frame. Ie. before this code is executed on the first frame.
// Alternatively, we could yield and wait until the end of the frame when the text object will be generated.
m_TextComponent.ForceMeshUpdate();
TMP_TextInfo textInfo = m_TextComponent.textInfo;
Matrix4x4 matrix;
TMP_MeshInfo[] cachedMeshInfoVertexData = textInfo.CopyMeshInfoVertexData();
// Allocations for sorting of the modified scales
List<float> modifiedCharScale = new List<float>();
List<int> scaleSortingOrder = new List<int>();
hasTextChanged = true;
while (true)
{
// Allocate new vertices
if (hasTextChanged)
{
// Get updated vertex data
cachedMeshInfoVertexData = textInfo.CopyMeshInfoVertexData();
hasTextChanged = false;
}
int characterCount = textInfo.characterCount;
// If No Characters then just yield and wait for some text to be added
if (characterCount == 0)
{
yield return new WaitForSeconds(0.25f);
continue;
}
// Clear list of character scales
modifiedCharScale.Clear();
scaleSortingOrder.Clear();
for (int i = 0; i < characterCount; i++)
{
TMP_CharacterInfo charInfo = textInfo.characterInfo[i];
// Skip characters that are not visible and thus have no geometry to manipulate.
if (!charInfo.isVisible)
continue;
// Get the index of the material used by the current character.
int materialIndex = textInfo.characterInfo[i].materialReferenceIndex;
// Get the index of the first vertex used by this text element.
int vertexIndex = textInfo.characterInfo[i].vertexIndex;
// Get the cached vertices of the mesh used by this text element (character or sprite).
Vector3[] sourceVertices = cachedMeshInfoVertexData[materialIndex].vertices;
// Determine the center point of each character at the baseline.
//Vector2 charMidBasline = new Vector2((sourceVertices[vertexIndex + 0].x + sourceVertices[vertexIndex + 2].x) / 2, charInfo.baseLine);
// Determine the center point of each character.
Vector2 charMidBasline = (sourceVertices[vertexIndex + 0] + sourceVertices[vertexIndex + 2]) / 2;
// Need to translate all 4 vertices of each quad to aligned with middle of character / baseline.
// This is needed so the matrix TRS is applied at the origin for each character.
Vector3 offset = charMidBasline;
Vector3[] destinationVertices = textInfo.meshInfo[materialIndex].vertices;
destinationVertices[vertexIndex + 0] = sourceVertices[vertexIndex + 0] - offset;
destinationVertices[vertexIndex + 1] = sourceVertices[vertexIndex + 1] - offset;
destinationVertices[vertexIndex + 2] = sourceVertices[vertexIndex + 2] - offset;
destinationVertices[vertexIndex + 3] = sourceVertices[vertexIndex + 3] - offset;
//Vector3 jitterOffset = new Vector3(Random.Range(-.25f, .25f), Random.Range(-.25f, .25f), 0);
// Determine the random scale change for each character.
float randomScale = Random.Range(1f, 1.5f);
// Add modified scale and index
modifiedCharScale.Add(randomScale);
scaleSortingOrder.Add(modifiedCharScale.Count - 1);
// Setup the matrix for the scale change.
//matrix = Matrix4x4.TRS(jitterOffset, Quaternion.Euler(0, 0, Random.Range(-5f, 5f)), Vector3.one * randomScale);
matrix = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, Vector3.one * randomScale);
destinationVertices[vertexIndex + 0] = matrix.MultiplyPoint3x4(destinationVertices[vertexIndex + 0]);
destinationVertices[vertexIndex + 1] = matrix.MultiplyPoint3x4(destinationVertices[vertexIndex + 1]);
destinationVertices[vertexIndex + 2] = matrix.MultiplyPoint3x4(destinationVertices[vertexIndex + 2]);
destinationVertices[vertexIndex + 3] = matrix.MultiplyPoint3x4(destinationVertices[vertexIndex + 3]);
destinationVertices[vertexIndex + 0] += offset;
destinationVertices[vertexIndex + 1] += offset;
destinationVertices[vertexIndex + 2] += offset;
destinationVertices[vertexIndex + 3] += offset;
// Restore Source UVS which have been modified by the sorting
Vector2[] sourceUVs0 = cachedMeshInfoVertexData[materialIndex].uvs0;
Vector2[] destinationUVs0 = textInfo.meshInfo[materialIndex].uvs0;
destinationUVs0[vertexIndex + 0] = sourceUVs0[vertexIndex + 0];
destinationUVs0[vertexIndex + 1] = sourceUVs0[vertexIndex + 1];
destinationUVs0[vertexIndex + 2] = sourceUVs0[vertexIndex + 2];
destinationUVs0[vertexIndex + 3] = sourceUVs0[vertexIndex + 3];
// Restore Source Vertex Colors
Color32[] sourceColors32 = cachedMeshInfoVertexData[materialIndex].colors32;
Color32[] destinationColors32 = textInfo.meshInfo[materialIndex].colors32;
destinationColors32[vertexIndex + 0] = sourceColors32[vertexIndex + 0];
destinationColors32[vertexIndex + 1] = sourceColors32[vertexIndex + 1];
destinationColors32[vertexIndex + 2] = sourceColors32[vertexIndex + 2];
destinationColors32[vertexIndex + 3] = sourceColors32[vertexIndex + 3];
}
// Push changes into meshes
for (int i = 0; i < textInfo.meshInfo.Length; i++)
{
//// Sort Quads based modified scale
scaleSortingOrder.Sort((a, b) => modifiedCharScale[a].CompareTo(modifiedCharScale[b]));
textInfo.meshInfo[i].SortGeometry(scaleSortingOrder);
// Updated modified vertex attributes
textInfo.meshInfo[i].mesh.vertices = textInfo.meshInfo[i].vertices;
textInfo.meshInfo[i].mesh.uv = textInfo.meshInfo[i].uvs0;
textInfo.meshInfo[i].mesh.colors32 = textInfo.meshInfo[i].colors32;
m_TextComponent.UpdateGeometry(textInfo.meshInfo[i].mesh, i);
}
yield return new WaitForSeconds(0.1f);
}
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 52ec835d14bd486f900952b77698b7eb
timeCreated: 1466280202
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,144 @@
using UnityEngine;
using System.Collections;
namespace TMPro.Examples
{
public class WarpTextExample : MonoBehaviour
{
private TMP_Text m_TextComponent;
public AnimationCurve VertexCurve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.25f, 2.0f), new Keyframe(0.5f, 0), new Keyframe(0.75f, 2.0f), new Keyframe(1, 0f));
public float AngleMultiplier = 1.0f;
public float SpeedMultiplier = 1.0f;
public float CurveScale = 1.0f;
void Awake()
{
m_TextComponent = gameObject.GetComponent<TMP_Text>();
}
void Start()
{
StartCoroutine(WarpText());
}
private AnimationCurve CopyAnimationCurve(AnimationCurve curve)
{
AnimationCurve newCurve = new AnimationCurve();
newCurve.keys = curve.keys;
return newCurve;
}
/// <summary>
/// Method to curve text along a Unity animation curve.
/// </summary>
/// <param name="textComponent"></param>
/// <returns></returns>
IEnumerator WarpText()
{
VertexCurve.preWrapMode = WrapMode.Clamp;
VertexCurve.postWrapMode = WrapMode.Clamp;
//Mesh mesh = m_TextComponent.textInfo.meshInfo[0].mesh;
Vector3[] vertices;
Matrix4x4 matrix;
m_TextComponent.havePropertiesChanged = true; // Need to force the TextMeshPro Object to be updated.
CurveScale *= 10;
float old_CurveScale = CurveScale;
AnimationCurve old_curve = CopyAnimationCurve(VertexCurve);
while (true)
{
if (!m_TextComponent.havePropertiesChanged && old_CurveScale == CurveScale && old_curve.keys[1].value == VertexCurve.keys[1].value)
{
yield return null;
continue;
}
old_CurveScale = CurveScale;
old_curve = CopyAnimationCurve(VertexCurve);
m_TextComponent.ForceMeshUpdate(); // Generate the mesh and populate the textInfo with data we can use and manipulate.
TMP_TextInfo textInfo = m_TextComponent.textInfo;
int characterCount = textInfo.characterCount;
if (characterCount == 0) continue;
//vertices = textInfo.meshInfo[0].vertices;
//int lastVertexIndex = textInfo.characterInfo[characterCount - 1].vertexIndex;
float boundsMinX = m_TextComponent.bounds.min.x; //textInfo.meshInfo[0].mesh.bounds.min.x;
float boundsMaxX = m_TextComponent.bounds.max.x; //textInfo.meshInfo[0].mesh.bounds.max.x;
for (int i = 0; i < characterCount; i++)
{
if (!textInfo.characterInfo[i].isVisible)
continue;
int vertexIndex = textInfo.characterInfo[i].vertexIndex;
// Get the index of the mesh used by this character.
int materialIndex = textInfo.characterInfo[i].materialReferenceIndex;
vertices = textInfo.meshInfo[materialIndex].vertices;
// Compute the baseline mid point for each character
Vector3 offsetToMidBaseline = new Vector2((vertices[vertexIndex + 0].x + vertices[vertexIndex + 2].x) / 2, textInfo.characterInfo[i].baseLine);
//float offsetY = VertexCurve.Evaluate((float)i / characterCount + loopCount / 50f); // Random.Range(-0.25f, 0.25f);
// Apply offset to adjust our pivot point.
vertices[vertexIndex + 0] += -offsetToMidBaseline;
vertices[vertexIndex + 1] += -offsetToMidBaseline;
vertices[vertexIndex + 2] += -offsetToMidBaseline;
vertices[vertexIndex + 3] += -offsetToMidBaseline;
// Compute the angle of rotation for each character based on the animation curve
float x0 = (offsetToMidBaseline.x - boundsMinX) / (boundsMaxX - boundsMinX); // Character's position relative to the bounds of the mesh.
float x1 = x0 + 0.0001f;
float y0 = VertexCurve.Evaluate(x0) * CurveScale;
float y1 = VertexCurve.Evaluate(x1) * CurveScale;
Vector3 horizontal = new Vector3(1, 0, 0);
//Vector3 normal = new Vector3(-(y1 - y0), (x1 * (boundsMaxX - boundsMinX) + boundsMinX) - offsetToMidBaseline.x, 0);
Vector3 tangent = new Vector3(x1 * (boundsMaxX - boundsMinX) + boundsMinX, y1) - new Vector3(offsetToMidBaseline.x, y0);
float dot = Mathf.Acos(Vector3.Dot(horizontal, tangent.normalized)) * 57.2957795f;
Vector3 cross = Vector3.Cross(horizontal, tangent);
float angle = cross.z > 0 ? dot : 360 - dot;
matrix = Matrix4x4.TRS(new Vector3(0, y0, 0), Quaternion.Euler(0, 0, angle), Vector3.one);
vertices[vertexIndex + 0] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 0]);
vertices[vertexIndex + 1] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 1]);
vertices[vertexIndex + 2] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 2]);
vertices[vertexIndex + 3] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 3]);
vertices[vertexIndex + 0] += offsetToMidBaseline;
vertices[vertexIndex + 1] += offsetToMidBaseline;
vertices[vertexIndex + 2] += offsetToMidBaseline;
vertices[vertexIndex + 3] += offsetToMidBaseline;
}
// Upload the mesh with the revised information
m_TextComponent.UpdateVertexData();
yield return new WaitForSeconds(0.025f);
}
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 790744c462254b7ba8038e6ed28b3db2
timeCreated: 1458801336
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6ba9720735f1b0d45b62426a89f65a99
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: e3265ab4bf004d28a9537516768c1c75
timeCreated: 1484171297
licenseType: Pro
TrueTypeFontImporter:
serializedVersion: 2
fontSize: 16
forceTextureCase: -2
characterSpacing: 1
characterPadding: 0
includeFontData: 1
use2xBehaviour: 0
fontNames: []
fallbackFontReferences: []
customCharacters:
fontRenderingMode: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e1e11eb08f01b264888724156c5aa5be
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 975583e06f8678e4db598aa11b6201bc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2e498d1c8094910479dc3e1b768306a4
timeCreated: 1484171803
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8f586378b4e144a9851e7b34d9b748ee
timeCreated: 1484171803
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 985e1363ef6272b4ab5562ff348d19ee
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,240 @@
// Simplified SDF shader:
// - No Shading Option (bevel / bump / env map)
// - No Glow Option
// - Softness is applied on both side of the outline
Shader "TextMeshPro/Mobile/Distance Field" {
Properties {
[HDR]_FaceColor ("Face Color", Color) = (1,1,1,1)
_FaceDilate ("Face Dilate", Range(-1,1)) = 0
[HDR]_OutlineColor ("Outline Color", Color) = (0,0,0,1)
_OutlineWidth ("Outline Thickness", Range(0,1)) = 0
_OutlineSoftness ("Outline Softness", Range(0,1)) = 0
[HDR]_UnderlayColor ("Border Color", Color) = (0,0,0,.5)
_UnderlayOffsetX ("Border OffsetX", Range(-1,1)) = 0
_UnderlayOffsetY ("Border OffsetY", Range(-1,1)) = 0
_UnderlayDilate ("Border Dilate", Range(-1,1)) = 0
_UnderlaySoftness ("Border Softness", Range(0,1)) = 0
_WeightNormal ("Weight Normal", float) = 0
_WeightBold ("Weight Bold", float) = .5
_ShaderFlags ("Flags", float) = 0
_ScaleRatioA ("Scale RatioA", float) = 1
_ScaleRatioB ("Scale RatioB", float) = 1
_ScaleRatioC ("Scale RatioC", float) = 1
_MainTex ("Font Atlas", 2D) = "white" {}
_TextureWidth ("Texture Width", float) = 512
_TextureHeight ("Texture Height", float) = 512
_GradientScale ("Gradient Scale", float) = 5
_ScaleX ("Scale X", float) = 1
_ScaleY ("Scale Y", float) = 1
_PerspectiveFilter ("Perspective Correction", Range(0, 1)) = 0.875
_Sharpness ("Sharpness", Range(-1,1)) = 0
_VertexOffsetX ("Vertex OffsetX", float) = 0
_VertexOffsetY ("Vertex OffsetY", float) = 0
_ClipRect ("Clip Rect", vector) = (-32767, -32767, 32767, 32767)
_MaskSoftnessX ("Mask SoftnessX", float) = 0
_MaskSoftnessY ("Mask SoftnessY", float) = 0
_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0
_StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255
_CullMode ("Cull Mode", Float) = 0
_ColorMask ("Color Mask", Float) = 15
}
SubShader {
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
}
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Cull [_CullMode]
ZWrite Off
Lighting Off
Fog { Mode Off }
ZTest [unity_GUIZTestMode]
Blend One OneMinusSrcAlpha
ColorMask [_ColorMask]
Pass {
CGPROGRAM
#pragma vertex VertShader
#pragma fragment PixShader
#pragma shader_feature __ OUTLINE_ON
#pragma shader_feature __ UNDERLAY_ON UNDERLAY_INNER
#pragma multi_compile __ UNITY_UI_CLIP_RECT
#pragma multi_compile __ UNITY_UI_ALPHACLIP
#include "UnityCG.cginc"
#include "UnityUI.cginc"
#include "TMPro_Properties.cginc"
struct vertex_t {
UNITY_VERTEX_INPUT_INSTANCE_ID
float4 vertex : POSITION;
float3 normal : NORMAL;
fixed4 color : COLOR;
float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
};
struct pixel_t {
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
float4 vertex : SV_POSITION;
fixed4 faceColor : COLOR;
fixed4 outlineColor : COLOR1;
float4 texcoord0 : TEXCOORD0; // Texture UV, Mask UV
half4 param : TEXCOORD1; // Scale(x), BiasIn(y), BiasOut(z), Bias(w)
half4 mask : TEXCOORD2; // Position in clip space(xy), Softness(zw)
#if (UNDERLAY_ON | UNDERLAY_INNER)
float4 texcoord1 : TEXCOORD3; // Texture UV, alpha, reserved
half2 underlayParam : TEXCOORD4; // Scale(x), Bias(y)
#endif
};
pixel_t VertShader(vertex_t input)
{
pixel_t output;
UNITY_INITIALIZE_OUTPUT(pixel_t, output);
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
float bold = step(input.texcoord1.y, 0);
float4 vert = input.vertex;
vert.x += _VertexOffsetX;
vert.y += _VertexOffsetY;
float4 vPosition = UnityObjectToClipPos(vert);
float2 pixelSize = vPosition.w;
pixelSize /= float2(_ScaleX, _ScaleY) * abs(mul((float2x2)UNITY_MATRIX_P, _ScreenParams.xy));
float scale = rsqrt(dot(pixelSize, pixelSize));
scale *= abs(input.texcoord1.y) * _GradientScale * (_Sharpness + 1);
if(UNITY_MATRIX_P[3][3] == 0) scale = lerp(abs(scale) * (1 - _PerspectiveFilter), scale, abs(dot(UnityObjectToWorldNormal(input.normal.xyz), normalize(WorldSpaceViewDir(vert)))));
float weight = lerp(_WeightNormal, _WeightBold, bold) / 4.0;
weight = (weight + _FaceDilate) * _ScaleRatioA * 0.5;
float layerScale = scale;
scale /= 1 + (_OutlineSoftness * _ScaleRatioA * scale);
float bias = (0.5 - weight) * scale - 0.5;
float outline = _OutlineWidth * _ScaleRatioA * 0.5 * scale;
float opacity = input.color.a;
#if (UNDERLAY_ON | UNDERLAY_INNER)
opacity = 1.0;
#endif
fixed4 faceColor = fixed4(input.color.rgb, opacity) * _FaceColor;
faceColor.rgb *= faceColor.a;
fixed4 outlineColor = _OutlineColor;
outlineColor.a *= opacity;
outlineColor.rgb *= outlineColor.a;
outlineColor = lerp(faceColor, outlineColor, sqrt(min(1.0, (outline * 2))));
#if (UNDERLAY_ON | UNDERLAY_INNER)
layerScale /= 1 + ((_UnderlaySoftness * _ScaleRatioC) * layerScale);
float layerBias = (.5 - weight) * layerScale - .5 - ((_UnderlayDilate * _ScaleRatioC) * .5 * layerScale);
float x = -(_UnderlayOffsetX * _ScaleRatioC) * _GradientScale / _TextureWidth;
float y = -(_UnderlayOffsetY * _ScaleRatioC) * _GradientScale / _TextureHeight;
float2 layerOffset = float2(x, y);
#endif
// Generate UV for the Masking Texture
float4 clampedRect = clamp(_ClipRect, -2e10, 2e10);
float2 maskUV = (vert.xy - clampedRect.xy) / (clampedRect.zw - clampedRect.xy);
// Populate structure for pixel shader
output.vertex = vPosition;
output.faceColor = faceColor;
output.outlineColor = outlineColor;
output.texcoord0 = float4(input.texcoord0.x, input.texcoord0.y, maskUV.x, maskUV.y);
output.param = half4(scale, bias - outline, bias + outline, bias);
output.mask = half4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * half2(_MaskSoftnessX, _MaskSoftnessY) + pixelSize.xy));
#if (UNDERLAY_ON || UNDERLAY_INNER)
output.texcoord1 = float4(input.texcoord0 + layerOffset, input.color.a, 0);
output.underlayParam = half2(layerScale, layerBias);
#endif
return output;
}
// PIXEL SHADER
fixed4 PixShader(pixel_t input) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(input);
half d = tex2D(_MainTex, input.texcoord0.xy).a * input.param.x;
half4 c = input.faceColor * saturate(d - input.param.w);
#ifdef OUTLINE_ON
c = lerp(input.outlineColor, input.faceColor, saturate(d - input.param.z));
c *= saturate(d - input.param.y);
#endif
#if UNDERLAY_ON
d = tex2D(_MainTex, input.texcoord1.xy).a * input.underlayParam.x;
c += float4(_UnderlayColor.rgb * _UnderlayColor.a, _UnderlayColor.a) * saturate(d - input.underlayParam.y) * (1 - c.a);
#endif
#if UNDERLAY_INNER
half sd = saturate(d - input.param.z);
d = tex2D(_MainTex, input.texcoord1.xy).a * input.underlayParam.x;
c += float4(_UnderlayColor.rgb * _UnderlayColor.a, _UnderlayColor.a) * (1 - saturate(d - input.underlayParam.y)) * sd * (1 - c.a);
#endif
// Alternative implementation to UnityGet2DClipping with support for softness.
#if UNITY_UI_CLIP_RECT
half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(input.mask.xy)) * input.mask.zw);
c *= m.x * m.y;
#endif
#if (UNDERLAY_ON | UNDERLAY_INNER)
c *= input.texcoord1.z;
#endif
#if UNITY_UI_ALPHACLIP
clip(c.a - 0.001);
#endif
return c;
}
ENDCG
}
}
CustomEditor "TMPro.EditorUtilities.TMP_SDFShaderGUI"
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: fe393ace9b354375a9cb14cdbbc28be4
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,85 @@
// UI Editable properties
uniform sampler2D _FaceTex; // Alpha : Signed Distance
uniform float _FaceUVSpeedX;
uniform float _FaceUVSpeedY;
uniform fixed4 _FaceColor; // RGBA : Color + Opacity
uniform float _FaceDilate; // v[ 0, 1]
uniform float _OutlineSoftness; // v[ 0, 1]
uniform sampler2D _OutlineTex; // RGBA : Color + Opacity
uniform float _OutlineUVSpeedX;
uniform float _OutlineUVSpeedY;
uniform fixed4 _OutlineColor; // RGBA : Color + Opacity
uniform float _OutlineWidth; // v[ 0, 1]
uniform float _Bevel; // v[ 0, 1]
uniform float _BevelOffset; // v[-1, 1]
uniform float _BevelWidth; // v[-1, 1]
uniform float _BevelClamp; // v[ 0, 1]
uniform float _BevelRoundness; // v[ 0, 1]
uniform sampler2D _BumpMap; // Normal map
uniform float _BumpOutline; // v[ 0, 1]
uniform float _BumpFace; // v[ 0, 1]
uniform samplerCUBE _Cube; // Cube / sphere map
uniform fixed4 _ReflectFaceColor; // RGB intensity
uniform fixed4 _ReflectOutlineColor;
//uniform float _EnvTiltX; // v[-1, 1]
//uniform float _EnvTiltY; // v[-1, 1]
uniform float3 _EnvMatrixRotation;
uniform float4x4 _EnvMatrix;
uniform fixed4 _SpecularColor; // RGB intensity
uniform float _LightAngle; // v[ 0,Tau]
uniform float _SpecularPower; // v[ 0, 1]
uniform float _Reflectivity; // v[ 5, 15]
uniform float _Diffuse; // v[ 0, 1]
uniform float _Ambient; // v[ 0, 1]
uniform fixed4 _UnderlayColor; // RGBA : Color + Opacity
uniform float _UnderlayOffsetX; // v[-1, 1]
uniform float _UnderlayOffsetY; // v[-1, 1]
uniform float _UnderlayDilate; // v[-1, 1]
uniform float _UnderlaySoftness; // v[ 0, 1]
uniform fixed4 _GlowColor; // RGBA : Color + Intesity
uniform float _GlowOffset; // v[-1, 1]
uniform float _GlowOuter; // v[ 0, 1]
uniform float _GlowInner; // v[ 0, 1]
uniform float _GlowPower; // v[ 1, 1/(1+4*4)]
// API Editable properties
uniform float _ShaderFlags;
uniform float _WeightNormal;
uniform float _WeightBold;
uniform float _ScaleRatioA;
uniform float _ScaleRatioB;
uniform float _ScaleRatioC;
uniform float _VertexOffsetX;
uniform float _VertexOffsetY;
//uniform float _UseClipRect;
uniform float _MaskID;
uniform sampler2D _MaskTex;
uniform float4 _MaskCoord;
uniform float4 _ClipRect; // bottom left(x,y) : top right(z,w)
//uniform float _MaskWipeControl;
//uniform float _MaskEdgeSoftness;
//uniform fixed4 _MaskEdgeColor;
//uniform bool _MaskInverse;
uniform float _MaskSoftnessX;
uniform float _MaskSoftnessY;
// Font Atlas properties
uniform sampler2D _MainTex;
uniform float _TextureWidth;
uniform float _TextureHeight;
uniform float _GradientScale;
uniform float _ScaleX;
uniform float _ScaleY;
uniform float _PerspectiveFilter;
uniform float _Sharpness;

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 3997e2241185407d80309a82f9148466
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4bd54315e7ed34f43a85cdebda0b2e51
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 19ae056e58cc5234f89f84768234a5db
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,57 @@
using System.Collections;
using UnityEngine;
public class ObjectDisplay : MonoBehaviour
{
public GameObject objectA;
public GameObject objectB;
public GameObject objectC;
public Material materialB;
public float delayForA = 1f;
public float delayForB = 10f;
public float delayForC = 15f;
public float delayForMaterialChange = 20f;
public void StartDisplaySequence()
{
StartCoroutine(DisplaySequence());
}
private IEnumerator DisplaySequence()
{
objectB.SetActive(false);
objectC.SetActive(false);
yield return new WaitForSeconds(delayForA);
objectA.SetActive(true);
yield return new WaitForSeconds(delayForB - delayForA);
objectA.SetActive(false);
objectB.SetActive(true);
yield return new WaitForSeconds(delayForC - delayForB);
objectB.SetActive(false);
objectC.SetActive(true);
yield return new WaitForSeconds(delayForMaterialChange - delayForC);
ChangeMaterial();
}
private void ChangeMaterial()
{
Renderer renderer = objectA.GetComponent<Renderer>();
if (renderer != null)
{
renderer.material = materialB;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3c23f798462cfa946b7bb3e2f86cd902
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -19,7 +19,7 @@
"dependencies": {
"com.unity.ugui": "1.0.0"
},
"url": "https://packages.unity.com"
"url": "https://packages.unity.cn"
},
"com.unity.analytics": {
"version": "3.3.5",
@ -28,37 +28,37 @@
"dependencies": {
"com.unity.ugui": "1.0.0"
},
"url": "https://packages.unity.com"
"url": "https://packages.unity.cn"
},
"com.unity.collab-proxy": {
"version": "1.2.16",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
"url": "https://packages.unity.cn"
},
"com.unity.ext.nunit": {
"version": "1.0.0",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
"url": "https://packages.unity.cn"
},
"com.unity.ide.rider": {
"version": "1.1.4",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.test-framework": "1.1.3"
"com.unity.test-framework": "1.1.1"
},
"url": "https://packages.unity.com"
"url": "https://packages.unity.cn"
},
"com.unity.ide.vscode": {
"version": "1.2.1",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
"url": "https://packages.unity.cn"
},
"com.unity.multiplayer-hlapi": {
"version": "1.0.6",
@ -67,14 +67,14 @@
"dependencies": {
"nuget.mono-cecil": "0.1.6-preview"
},
"url": "https://packages.unity.com"
"url": "https://packages.unity.cn"
},
"com.unity.purchasing": {
"version": "2.0.6",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
"url": "https://packages.unity.cn"
},
"com.unity.test-framework": {
"version": "1.1.16",
@ -85,7 +85,7 @@
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0"
},
"url": "https://packages.unity.com"
"url": "https://packages.unity.cn"
},
"com.unity.textmeshpro": {
"version": "2.0.1",
@ -94,14 +94,14 @@
"dependencies": {
"com.unity.ugui": "1.0.0"
},
"url": "https://packages.unity.com"
"url": "https://packages.unity.cn"
},
"com.unity.timeline": {
"version": "1.2.6",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
"url": "https://packages.unity.cn"
},
"com.unity.ugui": {
"version": "1.0.0",
@ -117,21 +117,21 @@
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
"url": "https://packages.unity.cn"
},
"com.unity.xr.openvr.standalone": {
"version": "2.0.5",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
"url": "https://packages.unity.cn"
},
"nuget.mono-cecil": {
"version": "0.1.6-preview",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
"url": "https://packages.unity.cn"
},
"com.unity.modules.ai": {
"version": "1.0.0",

View File

@ -1,2 +1,2 @@
m_EditorVersion: 2019.4.9f1
m_EditorVersionWithRevision: 2019.4.9f1 (50fe8a171dd9)
m_EditorVersionWithRevision: 2019.4.9f1 (ba291d946e84)