Commit c141e353 authored by gaorui's avatar gaorui
Browse files

Merge branch 'feat-dev3' into 'main'

Feat dev3

See merge request unity-cross/UnityDemo!1
parents 2ce8d1c7 b31b4ba9
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;
*/
}
}
}
}
}
fileFormatVersion: 2
guid: dc20866c0d5e413ab7559440e15333ae
MonoImporter:
serializedVersion: 2
defaultReferences:
- TheFont: {instanceID: 0}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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);
}
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 2d687537154440a3913a9a3c7977978c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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;
}
}
fileFormatVersion: 2
guid: 53d91f98a2664f5cb9af11de72ac54ec
timeCreated: 1487197841
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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";
}
}
fileFormatVersion: 2
guid: ac1eb05af6d391b4eb0f4c070a99f1d0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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;
}
}
}
fileFormatVersion: 2
guid: a4b6f99e8bc54541bbd149b014ff441c
timeCreated: 1449025325
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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;
}
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 4f19c7f94c794c5097d8bd11e39c750d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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();
}
}
}
}
fileFormatVersion: 2
guid: 2787a46a4dc848c1b4b7b9307b614bfd
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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;
}
}
}
fileFormatVersion: 2
guid: 9eff140b25d64601aabc6ba32245d099
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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);
}
}
}
}
fileFormatVersion: 2
guid: d412675cfb3441efa3bf8dcd9b7624dc
timeCreated: 1458801336
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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;
}
}
}
fileFormatVersion: 2
guid: 1a7eb92a01ed499a987bde9def05fbce
timeCreated: 1473112765
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment