首次提交
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d9a58836214e4e58b41c998e14a4239
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,109 @@
|
||||
#if FAIRYGUI_DRAGONBONES
|
||||
|
||||
using UnityEngine;
|
||||
using DragonBones;
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public partial class GLoader3D : GObject
|
||||
{
|
||||
UnityArmatureComponent _armatureComponent;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public UnityArmatureComponent armatureComponent
|
||||
{
|
||||
get { return _armatureComponent; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="asset"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="anchor"></param>
|
||||
public void SetDragonBones(DragonBonesData asset, int width, int height, Vector2 anchor)
|
||||
{
|
||||
if (_armatureComponent != null)
|
||||
FreeDragonBones();
|
||||
|
||||
_armatureComponent = UnityFactory.factory.BuildArmatureComponent(asset.armatureNames[0], asset.name, null, asset.name);
|
||||
_armatureComponent.gameObject.transform.localScale = new Vector3(100, 100, 1);
|
||||
_armatureComponent.gameObject.transform.localPosition = new Vector3(anchor.x, -anchor.y, 0);
|
||||
SetWrapTarget(_armatureComponent.gameObject, true, width, height);
|
||||
|
||||
var ct = _armatureComponent.color;
|
||||
ct.redMultiplier = _color.r;
|
||||
ct.greenMultiplier = _color.g;
|
||||
ct.blueMultiplier = _color.b;
|
||||
_armatureComponent.color = ct;
|
||||
|
||||
OnChangeDragonBones(null);
|
||||
}
|
||||
|
||||
protected void LoadDragonBones()
|
||||
{
|
||||
DragonBonesData asset = (DragonBonesData)_contentItem.skeletonAsset;
|
||||
if (asset == null)
|
||||
return;
|
||||
|
||||
SetDragonBones(asset, _contentItem.width, _contentItem.height, _contentItem.skeletonAnchor);
|
||||
}
|
||||
|
||||
protected void OnChangeDragonBones(string propertyName)
|
||||
{
|
||||
if (_armatureComponent == null)
|
||||
return;
|
||||
|
||||
if (propertyName == "color")
|
||||
{
|
||||
var ct = _armatureComponent.color;
|
||||
ct.redMultiplier = _color.r;
|
||||
ct.greenMultiplier = _color.g;
|
||||
ct.blueMultiplier = _color.b;
|
||||
_armatureComponent.color = ct;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(_animationName))
|
||||
{
|
||||
if (_playing)
|
||||
_armatureComponent.animation.Play(_animationName, _loop ? 0 : 1);
|
||||
else
|
||||
_armatureComponent.animation.GotoAndStopByFrame(_animationName, (uint)_frame);
|
||||
}
|
||||
else
|
||||
_armatureComponent.animation.Reset();
|
||||
}
|
||||
|
||||
protected void FreeDragonBones()
|
||||
{
|
||||
if (_armatureComponent != null)
|
||||
{
|
||||
_armatureComponent.Dispose();
|
||||
if (Application.isPlaying)
|
||||
GameObject.Destroy(_armatureComponent.gameObject);
|
||||
else
|
||||
GameObject.DestroyImmediate(_armatureComponent.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnUpdateDragonBones(UpdateContext context)
|
||||
{
|
||||
if (_armatureComponent != null)
|
||||
{
|
||||
var ct = _armatureComponent.color;
|
||||
ct.alphaMultiplier = context.alpha * _content.alpha;
|
||||
_armatureComponent.color = ct;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d48ba38d2e2e420085e6c98407dc1fb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Plugins/FairyGUI/Scripts/Extensions/Spine.meta
Normal file
8
Assets/Plugins/FairyGUI/Scripts/Extensions/Spine.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d55093b745d3d452699bdfe7bd8ac88e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
188
Assets/Plugins/FairyGUI/Scripts/Extensions/Spine/SpineLoader.cs
Normal file
188
Assets/Plugins/FairyGUI/Scripts/Extensions/Spine/SpineLoader.cs
Normal file
@@ -0,0 +1,188 @@
|
||||
#if FAIRYGUI_SPINE
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Spine.Unity;
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public partial class GLoader3D : GObject
|
||||
{
|
||||
public static Action<SkeletonAnimation> CustomSpineDestroyMethod;
|
||||
|
||||
SkeletonAnimation _spineAnimation;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public SkeletonAnimation spineAnimation
|
||||
{
|
||||
get { return _spineAnimation; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="asset"></param>
|
||||
public void SetSpine(SkeletonDataAsset asset)
|
||||
{
|
||||
SetSpine(asset, _contentItem.width, _contentItem.height, _contentItem.skeletonAnchor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="asset"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="anchor"></param>
|
||||
public void SetSpine(SkeletonDataAsset asset, int width, int height, Vector2 anchor)
|
||||
{
|
||||
SetSpine(asset, width, height, anchor, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="asset"></param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
/// <param name="anchor"></param>
|
||||
/// <param name="cloneMaterial"></param>
|
||||
public void SetSpine(SkeletonDataAsset asset, int width, int height, Vector2 anchor, bool cloneMaterial)
|
||||
{
|
||||
if (_spineAnimation != null)
|
||||
FreeSpine();
|
||||
|
||||
_content.customCloneMaterials = MaterialOverride;
|
||||
_content.customRecoverMaterials = CleanMaterialOverride;
|
||||
|
||||
_spineAnimation = SkeletonRenderer.NewSpineGameObject<SkeletonAnimation>(asset);
|
||||
_spineAnimation.gameObject.name = asset.name;
|
||||
Spine.SkeletonData dat = asset.GetSkeletonData(false);
|
||||
_spineAnimation.gameObject.transform.localScale = new Vector3(1 / asset.scale, 1 / asset.scale, 1);
|
||||
_spineAnimation.gameObject.transform.localPosition = new Vector3(anchor.x, -anchor.y, 0);
|
||||
SetWrapTarget(_spineAnimation.gameObject, cloneMaterial, width, height);
|
||||
|
||||
_spineAnimation.skeleton.R = _color.r;
|
||||
_spineAnimation.skeleton.G = _color.g;
|
||||
_spineAnimation.skeleton.B = _color.b;
|
||||
|
||||
OnChangeSpine(null);
|
||||
}
|
||||
|
||||
protected void LoadSpine()
|
||||
{
|
||||
SkeletonDataAsset asset = (SkeletonDataAsset)_contentItem.skeletonAsset;
|
||||
if (asset == null)
|
||||
return;
|
||||
|
||||
SetSpine(asset, _contentItem.width, _contentItem.height, _contentItem.skeletonAnchor);
|
||||
}
|
||||
|
||||
protected void OnChangeSpine(string propertyName)
|
||||
{
|
||||
if (_spineAnimation == null)
|
||||
return;
|
||||
|
||||
if (propertyName == "color")
|
||||
{
|
||||
_spineAnimation.skeleton.R = _color.r;
|
||||
_spineAnimation.skeleton.G = _color.g;
|
||||
_spineAnimation.skeleton.B = _color.b;
|
||||
return;
|
||||
}
|
||||
|
||||
var skeletonData = _spineAnimation.skeleton.Data;
|
||||
|
||||
var state = _spineAnimation.AnimationState;
|
||||
Spine.Animation animationToUse = !string.IsNullOrEmpty(_animationName) ? skeletonData.FindAnimation(_animationName) : null;
|
||||
if (animationToUse != null)
|
||||
{
|
||||
var trackEntry = state.GetCurrent(0);
|
||||
if (trackEntry == null || trackEntry.Animation.Name != _animationName || trackEntry.IsComplete && !trackEntry.Loop)
|
||||
trackEntry = state.SetAnimation(0, animationToUse, _loop);
|
||||
else
|
||||
trackEntry.Loop = _loop;
|
||||
|
||||
if (_playing)
|
||||
trackEntry.TimeScale = 1;
|
||||
else
|
||||
{
|
||||
trackEntry.TimeScale = 0;
|
||||
trackEntry.TrackTime = Mathf.Lerp(0, trackEntry.AnimationEnd - trackEntry.AnimationStart, _frame / 100f);
|
||||
}
|
||||
}
|
||||
else
|
||||
state.ClearTrack(0);
|
||||
|
||||
var skin = !string.IsNullOrEmpty(skinName) ? skeletonData.FindSkin(skinName) : skeletonData.DefaultSkin;
|
||||
if (skin == null && skeletonData.Skins.Count > 0)
|
||||
skin = skeletonData.Skins.Items[0];
|
||||
if (_spineAnimation.skeleton.Skin != skin)
|
||||
{
|
||||
_spineAnimation.skeleton.SetSkin(skin);
|
||||
_spineAnimation.skeleton.SetSlotsToSetupPose();
|
||||
}
|
||||
}
|
||||
|
||||
protected void FreeSpine()
|
||||
{
|
||||
if (_spineAnimation != null)
|
||||
{
|
||||
if (CustomSpineDestroyMethod != null)
|
||||
{
|
||||
CustomSpineDestroyMethod(_spineAnimation);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
GameObject.Destroy(_spineAnimation.gameObject);
|
||||
else
|
||||
GameObject.DestroyImmediate(_spineAnimation.gameObject);
|
||||
}
|
||||
|
||||
_content.customCloneMaterials = null;
|
||||
_content.customRecoverMaterials = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnUpdateSpine(UpdateContext context)
|
||||
{
|
||||
if (_spineAnimation != null)
|
||||
_spineAnimation.skeleton.A = context.alpha * _content.alpha;
|
||||
}
|
||||
|
||||
private void MaterialOverride(Dictionary<Material, Material> materials)
|
||||
{
|
||||
if (_spineAnimation != null)
|
||||
{
|
||||
foreach (var kv in materials)
|
||||
{
|
||||
_spineAnimation.CustomMaterialOverride[kv.Key] = kv.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CleanMaterialOverride()
|
||||
{
|
||||
if (_spineAnimation != null)
|
||||
_spineAnimation.CustomMaterialOverride.Clear();
|
||||
}
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
static void InitializeOnLoad()
|
||||
{
|
||||
CustomSpineDestroyMethod = null;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3757a6f06ad143439bb00cd7190c6d1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1de100836593c444995397fa368017d5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e302db5f01fdb46b5b45f44c25164846
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,478 @@
|
||||
Shader "FairyGUI/TextMeshPro/Distance Field" {
|
||||
|
||||
Properties {
|
||||
_FaceTex ("Face Texture", 2D) = "white" {}
|
||||
_FaceUVSpeedX ("Face UV Speed X", Range(-5, 5)) = 0.0
|
||||
_FaceUVSpeedY ("Face UV Speed Y", Range(-5, 5)) = 0.0
|
||||
_FaceColor ("Face Color", Color) = (1,1,1,1)
|
||||
_FaceDilate ("Face Dilate", Range(-1,1)) = 0
|
||||
|
||||
_OutlineColor ("Outline Color", Color) = (0,0,0,1)
|
||||
_OutlineTex ("Outline Texture", 2D) = "white" {}
|
||||
_OutlineUVSpeedX ("Outline UV Speed X", Range(-5, 5)) = 0.0
|
||||
_OutlineUVSpeedY ("Outline UV Speed Y", Range(-5, 5)) = 0.0
|
||||
_OutlineWidth ("Outline Thickness", Range(0, 1)) = 0
|
||||
_OutlineSoftness ("Outline Softness", Range(0,1)) = 0
|
||||
|
||||
_Bevel ("Bevel", Range(0,1)) = 0.5
|
||||
_BevelOffset ("Bevel Offset", Range(-0.5,0.5)) = 0
|
||||
_BevelWidth ("Bevel Width", Range(-.5,0.5)) = 0
|
||||
_BevelClamp ("Bevel Clamp", Range(0,1)) = 0
|
||||
_BevelRoundness ("Bevel Roundness", Range(0,1)) = 0
|
||||
|
||||
_LightAngle ("Light Angle", Range(0.0, 6.2831853)) = 3.1416
|
||||
_SpecularColor ("Specular", Color) = (1,1,1,1)
|
||||
_SpecularPower ("Specular", Range(0,4)) = 2.0
|
||||
_Reflectivity ("Reflectivity", Range(5.0,15.0)) = 10
|
||||
_Diffuse ("Diffuse", Range(0,1)) = 0.5
|
||||
_Ambient ("Ambient", Range(1,0)) = 0.5
|
||||
|
||||
_BumpMap ("Normal map", 2D) = "bump" {}
|
||||
_BumpOutline ("Bump Outline", Range(0,1)) = 0
|
||||
_BumpFace ("Bump Face", Range(0,1)) = 0
|
||||
|
||||
_ReflectFaceColor ("Reflection Color", Color) = (0,0,0,1)
|
||||
_ReflectOutlineColor("Reflection Color", Color) = (0,0,0,1)
|
||||
_Cube ("Reflection Cubemap", Cube) = "black" { /* TexGen CubeReflect */ }
|
||||
_EnvMatrixRotation ("Texture Rotation", vector) = (0, 0, 0, 0)
|
||||
|
||||
|
||||
_UnderlayColor ("Border Color", Color) = (0,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
|
||||
|
||||
_GlowColor ("Color", Color) = (0, 1, 0, 0.5)
|
||||
_GlowOffset ("Offset", Range(-1,1)) = 0
|
||||
_GlowInner ("Inner", Range(0,1)) = 0.05
|
||||
_GlowOuter ("Outer", Range(0,1)) = 0.05
|
||||
_GlowPower ("Falloff", Range(1, 0)) = 0.75
|
||||
|
||||
_WeightNormal ("Weight Normal", float) = 0
|
||||
_WeightBold ("Weight Bold", float) = 0.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.0
|
||||
_ScaleX ("Scale X", float) = 1.0
|
||||
_ScaleY ("Scale Y", float) = 1.0
|
||||
_PerspectiveFilter ("Perspective Correction", Range(0, 1)) = 0.875
|
||||
_Sharpness ("Sharpness", Range(-1,1)) = 0
|
||||
|
||||
_VertexOffsetX ("Vertex OffsetX", float) = 0
|
||||
_VertexOffsetY ("Vertex OffsetY", float) = 0
|
||||
|
||||
_MaskCoord ("Mask Coordinates", vector) = (0, 0, 32767, 32767)
|
||||
_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
|
||||
|
||||
_ColorMask ("Color Mask", Float) = 15
|
||||
|
||||
_BlendSrcFactor ("Blend SrcFactor", Float) = 1
|
||||
_BlendDstFactor ("Blend DstFactor", Float) = 10
|
||||
}
|
||||
|
||||
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 [_BlendSrcFactor] [_BlendDstFactor]
|
||||
ColorMask [_ColorMask]
|
||||
|
||||
Pass {
|
||||
CGPROGRAM
|
||||
#pragma target 3.0
|
||||
#pragma vertex VertShader
|
||||
#pragma fragment PixShader
|
||||
//#pragma shader_feature __ BEVEL_ON
|
||||
#pragma shader_feature __ UNDERLAY_ON UNDERLAY_INNER
|
||||
//#pragma shader_feature __ GLOW_ON
|
||||
|
||||
//#pragma multi_compile __ UNITY_UI_CLIP_RECT
|
||||
//#pragma multi_compile __ UNITY_UI_ALPHACLIP
|
||||
#pragma multi_compile _ GRAYED
|
||||
#pragma multi_compile _ CLIPPED SOFT_CLIPPED
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityUI.cginc"
|
||||
|
||||
//begin copy
|
||||
//#include "Assets/TextMesh Pro/Shaders/TMPro_Properties.cginc"
|
||||
//#include "Assets/TextMesh Pro/Shaders/TMPro.cginc"
|
||||
|
||||
// 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;
|
||||
|
||||
float2 UnpackUV(float uv)
|
||||
{
|
||||
float2 output;
|
||||
output.x = floor(uv / 4096);
|
||||
output.y = uv - 4096 * output.x;
|
||||
|
||||
return output * 0.001953125;
|
||||
}
|
||||
|
||||
fixed4 GetColor(half d, fixed4 faceColor, fixed4 outlineColor, half outline, half softness)
|
||||
{
|
||||
half faceAlpha = 1-saturate((d - outline * 0.5 + softness * 0.5) / (1.0 + softness));
|
||||
half outlineAlpha = saturate((d + outline * 0.5)) * sqrt(min(1.0, outline));
|
||||
|
||||
faceColor.rgb *= faceColor.a;
|
||||
outlineColor.rgb *= outlineColor.a;
|
||||
|
||||
faceColor = lerp(faceColor, outlineColor, outlineAlpha);
|
||||
|
||||
faceColor *= faceAlpha;
|
||||
|
||||
return faceColor;
|
||||
}
|
||||
|
||||
//end copy
|
||||
|
||||
|
||||
struct vertex_t {
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
float4 position : 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 position : SV_POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 atlas : TEXCOORD0; // Atlas
|
||||
float4 param : TEXCOORD1; // alphaClip, scale, bias, weight
|
||||
float2 mask : TEXCOORD2; // Position in object space(xy), pixel Size(zw)
|
||||
float3 viewDir : TEXCOORD3;
|
||||
|
||||
#if (UNDERLAY_ON || UNDERLAY_INNER)
|
||||
float4 texcoord2 : TEXCOORD4; // u,v, scale, bias
|
||||
fixed4 underlayColor : COLOR1;
|
||||
#endif
|
||||
float4 textures : TEXCOORD5;
|
||||
};
|
||||
|
||||
// Used by Unity internally to handle Texture Tiling and Offset.
|
||||
float4 _FaceTex_ST;
|
||||
float4 _OutlineTex_ST;
|
||||
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
#ifdef CLIPPED
|
||||
float4 _ClipBox = float4(-2, -2, 0, 0);
|
||||
#endif
|
||||
|
||||
#ifdef SOFT_CLIPPED
|
||||
float4 _ClipBox = float4(-2, -2, 0, 0);
|
||||
float4 _ClipSoftness = float4(0, 0, 0, 0);
|
||||
#endif
|
||||
CBUFFER_END
|
||||
|
||||
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.position;
|
||||
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 bias =(.5 - weight) + (.5 / scale);
|
||||
|
||||
float alphaClip = (1.0 - _OutlineWidth * _ScaleRatioA - _OutlineSoftness * _ScaleRatioA);
|
||||
|
||||
// #if GLOW_ON
|
||||
// alphaClip = min(alphaClip, 1.0 - _GlowOffset * _ScaleRatioB - _GlowOuter * _ScaleRatioB);
|
||||
// #endif
|
||||
|
||||
alphaClip = alphaClip / 2.0 - ( .5 / scale) - weight;
|
||||
|
||||
#if (UNDERLAY_ON || UNDERLAY_INNER)
|
||||
float4 underlayColor = _UnderlayColor;
|
||||
underlayColor.rgb *= underlayColor.a;
|
||||
|
||||
float bScale = scale;
|
||||
bScale /= 1 + ((_UnderlaySoftness*_ScaleRatioC) * bScale);
|
||||
float bBias = (0.5 - weight) * bScale - 0.5 - ((_UnderlayDilate * _ScaleRatioC) * 0.5 * bScale);
|
||||
|
||||
float x = -(_UnderlayOffsetX * _ScaleRatioC) * _GradientScale / _TextureWidth;
|
||||
float y = -(_UnderlayOffsetY * _ScaleRatioC) * _GradientScale / _TextureHeight;
|
||||
float2 bOffset = 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);
|
||||
|
||||
// Support for texture tiling and offset
|
||||
float2 textureUV = UnpackUV(input.texcoord1.x);
|
||||
//float2 faceUV = TRANSFORM_TEX(textureUV, _FaceTex);
|
||||
//float2 outlineUV = TRANSFORM_TEX(textureUV, _OutlineTex);
|
||||
|
||||
output.position = vPosition;
|
||||
#if !defined(UNITY_COLORSPACE_GAMMA) && (UNITY_VERSION >= 550)
|
||||
output.color.rgb = GammaToLinearSpace(input.color.rgb);
|
||||
output.color.a = input.color.a;
|
||||
#else
|
||||
output.color = input.color;
|
||||
#endif
|
||||
output.atlas = input.texcoord0;
|
||||
output.param = float4(alphaClip, scale, bias, weight);
|
||||
//output.mask = half4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * half2(_MaskSoftnessX, _MaskSoftnessY) + pixelSize.xy));
|
||||
output.viewDir = mul((float3x3)_EnvMatrix, _WorldSpaceCameraPos.xyz - mul(unity_ObjectToWorld, vert).xyz);
|
||||
#if (UNDERLAY_ON || UNDERLAY_INNER)
|
||||
output.texcoord2 = float4(input.texcoord0 + bOffset, bScale, bBias);
|
||||
output.underlayColor = underlayColor;
|
||||
#endif
|
||||
//output.textures = float4(faceUV, outlineUV);
|
||||
|
||||
#ifdef CLIPPED
|
||||
output.mask = mul(unity_ObjectToWorld, input.position).xy * _ClipBox.zw + _ClipBox.xy;
|
||||
#endif
|
||||
|
||||
#ifdef SOFT_CLIPPED
|
||||
output.mask = mul(unity_ObjectToWorld, input.position).xy * _ClipBox.zw + _ClipBox.xy;
|
||||
#endif
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
fixed4 PixShader(pixel_t input) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
|
||||
float c = tex2D(_MainTex, input.atlas).a;
|
||||
|
||||
#ifndef UNDERLAY_ON
|
||||
clip(c - input.param.x);
|
||||
#endif
|
||||
|
||||
float scale = input.param.y;
|
||||
float bias = input.param.z;
|
||||
float weight = input.param.w;
|
||||
float sd = (bias - c) * scale;
|
||||
|
||||
float outline = (_OutlineWidth * _ScaleRatioA) * scale;
|
||||
float softness = (_OutlineSoftness * _ScaleRatioA) * scale;
|
||||
|
||||
half4 faceColor = _FaceColor;
|
||||
half4 outlineColor = _OutlineColor;
|
||||
|
||||
faceColor.rgb *= input.color.rgb;
|
||||
|
||||
//faceColor *= tex2D(_FaceTex, input.textures.xy + float2(_FaceUVSpeedX, _FaceUVSpeedY) * _Time.y);
|
||||
//outlineColor *= tex2D(_OutlineTex, input.textures.zw + float2(_OutlineUVSpeedX, _OutlineUVSpeedY) * _Time.y);
|
||||
|
||||
faceColor = GetColor(sd, faceColor, outlineColor, outline, softness);
|
||||
|
||||
// #if BEVEL_ON
|
||||
// float3 dxy = float3(0.5 / _TextureWidth, 0.5 / _TextureHeight, 0);
|
||||
// float3 n = GetSurfaceNormal(input.atlas, weight, dxy);
|
||||
|
||||
// float3 bump = UnpackNormal(tex2D(_BumpMap, input.textures.xy + float2(_FaceUVSpeedX, _FaceUVSpeedY) * _Time.y)).xyz;
|
||||
// bump *= lerp(_BumpFace, _BumpOutline, saturate(sd + outline * 0.5));
|
||||
// n = normalize(n- bump);
|
||||
|
||||
// float3 light = normalize(float3(sin(_LightAngle), cos(_LightAngle), -1.0));
|
||||
|
||||
// float3 col = GetSpecular(n, light);
|
||||
// faceColor.rgb += col*faceColor.a;
|
||||
// faceColor.rgb *= 1-(dot(n, light)*_Diffuse);
|
||||
// faceColor.rgb *= lerp(_Ambient, 1, n.z*n.z);
|
||||
|
||||
// fixed4 reflcol = texCUBE(_Cube, reflect(input.viewDir, -n));
|
||||
// faceColor.rgb += reflcol.rgb * lerp(_ReflectFaceColor.rgb, _ReflectOutlineColor.rgb, saturate(sd + outline * 0.5)) * faceColor.a;
|
||||
// #endif
|
||||
|
||||
#if UNDERLAY_ON
|
||||
float d = tex2D(_MainTex, input.texcoord2.xy).a * input.texcoord2.z;
|
||||
faceColor += input.underlayColor * saturate(d - input.texcoord2.w) * (1 - faceColor.a);
|
||||
#endif
|
||||
|
||||
#if UNDERLAY_INNER
|
||||
float d = tex2D(_MainTex, input.texcoord2.xy).a * input.texcoord2.z;
|
||||
faceColor += input.underlayColor * (1 - saturate(d - input.texcoord2.w)) * saturate(1 - sd) * (1 - faceColor.a);
|
||||
#endif
|
||||
|
||||
// #if GLOW_ON
|
||||
// float4 glowColor = GetGlowColor(sd, scale);
|
||||
// faceColor.rgb += glowColor.rgb * glowColor.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);
|
||||
// faceColor *= m.x * m.y;
|
||||
// #endif
|
||||
|
||||
// #if UNITY_UI_ALPHACLIP
|
||||
// clip(faceColor.a - 0.001);
|
||||
// #endif
|
||||
|
||||
#ifdef GRAYED
|
||||
fixed grey = dot(faceColor.rgb, fixed3(0.299, 0.587, 0.114));
|
||||
faceColor.rgb = fixed3(grey, grey, grey);
|
||||
#endif
|
||||
|
||||
#ifdef CLIPPED
|
||||
float2 factor = abs(input.mask);
|
||||
clip(1-max(factor.x, factor.y));
|
||||
#endif
|
||||
|
||||
#ifdef SOFT_CLIPPED
|
||||
float2 factor;
|
||||
float2 condition = step(input.mask.xy, 0);
|
||||
float4 clip_softness = _ClipSoftness * float4(condition, 1 - condition);
|
||||
factor.xy = (1.0 - abs(input.mask.xy)) * (clip_softness.xw + clip_softness.zy);
|
||||
faceColor.a *= clamp(min(factor.x, factor.y), 0.0, 1.0);
|
||||
clip(faceColor.a - 0.001);
|
||||
#endif
|
||||
return faceColor * input.color.a;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
//Fallback "TextMeshPro/Mobile/Distance Field"
|
||||
CustomEditor "TMPro.EditorUtilities.TMP_SDFShaderGUI"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de10f84640569464799f0e0bfa1ab7b0
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,807 @@
|
||||
#if FAIRYGUI_TMPRO
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TextCore;
|
||||
using TMPro;
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
/// TextMeshPro text adapter for FairyGUI. Most of codes were taken from TextMeshPro!
|
||||
/// Note that not all of TextMeshPro features are supported.
|
||||
/// </summary>
|
||||
public class TMPFont : BaseFont
|
||||
{
|
||||
protected TMP_FontAsset _fontAsset;
|
||||
|
||||
FontStyles _style;
|
||||
float _scale;
|
||||
float _padding;
|
||||
float _stylePadding;
|
||||
float _ascent;
|
||||
float _lineHeight;
|
||||
float _boldMultiplier;
|
||||
FontWeight _defaultFontWeight;
|
||||
FontWeight _fontWeight;
|
||||
TextFormat _topTextFormat;
|
||||
TextFormat _format;
|
||||
float _fontSizeScale;
|
||||
TMP_Character _char;
|
||||
NTexture[] _atlasTextures;
|
||||
|
||||
float _gradientScale;
|
||||
float _ratioA;
|
||||
float _ratioB;
|
||||
float _ratioC;
|
||||
|
||||
int _formatVersion;
|
||||
TMPFont _fallbackFont;
|
||||
List<TMPFont> _fallbackFonts;
|
||||
VertexBuffer[] _subMeshBuffers;
|
||||
bool _preparing;
|
||||
|
||||
public TMPFont()
|
||||
{
|
||||
this.canTint = true;
|
||||
this.shader = "FairyGUI/TextMeshPro/Distance Field";
|
||||
this.keepCrisp = true;
|
||||
|
||||
_defaultFontWeight = FontWeight.Medium;
|
||||
_fallbackFonts = new List<TMPFont>();
|
||||
_atlasTextures = new NTexture[0];
|
||||
_subMeshBuffers = new VertexBuffer[0];
|
||||
}
|
||||
|
||||
override public void Dispose()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
public TMP_FontAsset fontAsset
|
||||
{
|
||||
get { return _fontAsset; }
|
||||
set
|
||||
{
|
||||
_fontAsset = value;
|
||||
Init();
|
||||
}
|
||||
}
|
||||
|
||||
public FontWeight fontWeight
|
||||
{
|
||||
get { return _defaultFontWeight; }
|
||||
set { _defaultFontWeight = value; }
|
||||
}
|
||||
|
||||
void Release()
|
||||
{
|
||||
foreach (var tex in _atlasTextures)
|
||||
{
|
||||
if (tex != null)
|
||||
tex.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
Release();
|
||||
|
||||
mainTexture = WrapAtlasTexture(0);
|
||||
|
||||
// _ascent = _fontAsset.faceInfo.ascentLine;
|
||||
// _lineHeight = _fontAsset.faceInfo.lineHeight;
|
||||
_ascent = _fontAsset.faceInfo.pointSize;
|
||||
_lineHeight = _fontAsset.faceInfo.pointSize * 1.25f;
|
||||
_gradientScale = fontAsset.atlasPadding + 1;
|
||||
}
|
||||
|
||||
void OnCreateNewMaterial(Material mat)
|
||||
{
|
||||
mat.SetFloat(ShaderUtilities.ID_TextureWidth, mainTexture.width);
|
||||
mat.SetFloat(ShaderUtilities.ID_TextureHeight, mainTexture.height);
|
||||
mat.SetFloat(ShaderUtilities.ID_GradientScale, _gradientScale);
|
||||
mat.SetFloat(ShaderUtilities.ID_WeightNormal, fontAsset.normalStyle);
|
||||
mat.SetFloat(ShaderUtilities.ID_WeightBold, fontAsset.boldStyle);
|
||||
}
|
||||
|
||||
public override void Prepare(TextFormat format)
|
||||
{
|
||||
_preparing = true;
|
||||
_topTextFormat = _format = format;
|
||||
}
|
||||
|
||||
static List<NGraphics> subInstancesCopy = new List<NGraphics>();
|
||||
public override bool BuildGraphics(NGraphics graphics)
|
||||
{
|
||||
_preparing = false;
|
||||
_format = _topTextFormat;
|
||||
|
||||
if (graphics.subInstances != null)
|
||||
subInstancesCopy.AddRange(graphics.subInstances);
|
||||
|
||||
UpdatePaddings();
|
||||
UpdateGraphics(graphics);
|
||||
|
||||
bool changed = CreateSubGraphics(graphics, true);
|
||||
|
||||
for (int i = 0; i < _fallbackFonts.Count; i++)
|
||||
{
|
||||
_fallbackFonts[i]._format = _format;
|
||||
if (_fallbackFonts[i].CreateSubGraphics(graphics, false))
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (subInstancesCopy.Count > 0)
|
||||
{
|
||||
foreach (var g in subInstancesCopy)
|
||||
{
|
||||
if (g != null)
|
||||
{
|
||||
g.texture = null;
|
||||
g.enabled = false;
|
||||
}
|
||||
}
|
||||
subInstancesCopy.Clear();
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool CreateSubGraphics(NGraphics graphics, bool paddingsUpdated)
|
||||
{
|
||||
bool changed = false;
|
||||
for (int i = 0; i < _atlasTextures.Length; i++)
|
||||
{
|
||||
var texture = _atlasTextures[i];
|
||||
if (texture == null || texture.lastActive == 0)
|
||||
continue;
|
||||
|
||||
texture.lastActive = 0;
|
||||
|
||||
NGraphics sub = null;
|
||||
if (graphics.subInstances != null)
|
||||
{
|
||||
int index = graphics.subInstances.FindIndex(g => g.texture == texture);
|
||||
if (index == -1)
|
||||
index = graphics.subInstances.FindIndex(g => g.texture == null);
|
||||
if (index != -1)
|
||||
{
|
||||
sub = graphics.subInstances[index];
|
||||
subInstancesCopy[index] = null;
|
||||
}
|
||||
}
|
||||
if (sub == null)
|
||||
{
|
||||
sub = graphics.CreateSubInstance("SubTextField");
|
||||
sub.meshFactory = new TMPFont_SubMesh();
|
||||
sub.SetShaderAndTexture(shader, texture);
|
||||
graphics.subInstances.Add(sub);
|
||||
changed = true;
|
||||
}
|
||||
else if (sub.texture != texture)
|
||||
{
|
||||
sub.SetShaderAndTexture(shader, texture);
|
||||
sub.enabled = true;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (!paddingsUpdated)
|
||||
{
|
||||
paddingsUpdated = true;
|
||||
UpdatePaddings();
|
||||
}
|
||||
|
||||
UpdateGraphics(sub);
|
||||
((TMPFont_SubMesh)sub.meshFactory).font = this;
|
||||
((TMPFont_SubMesh)sub.meshFactory).atlasIndex = i;
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
void UpdateGraphics(NGraphics graphics)
|
||||
{
|
||||
graphics.userData.x = _padding;
|
||||
graphics.userData.y = _stylePadding;
|
||||
|
||||
MaterialPropertyBlock block = graphics.materialPropertyBlock;
|
||||
|
||||
block.SetFloat(ShaderUtilities.ID_ScaleRatio_A, _ratioA);
|
||||
block.SetFloat(ShaderUtilities.ID_ScaleRatio_B, _ratioB);
|
||||
block.SetFloat(ShaderUtilities.ID_ScaleRatio_C, _ratioC);
|
||||
|
||||
block.SetFloat(ShaderUtilities.ID_FaceDilate, _format.faceDilate);
|
||||
|
||||
if (_format.outline > 0)
|
||||
{
|
||||
graphics.ToggleKeyword("OUTLINE_ON", true);
|
||||
|
||||
block.SetFloat(ShaderUtilities.ID_OutlineWidth, _format.outline);
|
||||
block.SetColor(ShaderUtilities.ID_OutlineColor, _format.outlineColor);
|
||||
block.SetFloat(ShaderUtilities.ID_OutlineSoftness, _format.outlineSoftness);
|
||||
}
|
||||
else
|
||||
{
|
||||
graphics.ToggleKeyword("OUTLINE_ON", false);
|
||||
|
||||
block.SetFloat(ShaderUtilities.ID_OutlineWidth, 0);
|
||||
block.SetFloat(ShaderUtilities.ID_OutlineSoftness, 0);
|
||||
}
|
||||
|
||||
if (_format.shadowOffset.x != 0 || _format.shadowOffset.y != 0)
|
||||
{
|
||||
graphics.ToggleKeyword("UNDERLAY_ON", true);
|
||||
|
||||
block.SetColor(ShaderUtilities.ID_UnderlayColor, _format.shadowColor);
|
||||
block.SetFloat(ShaderUtilities.ID_UnderlayOffsetX, _format.shadowOffset.x);
|
||||
block.SetFloat(ShaderUtilities.ID_UnderlayOffsetY, -_format.shadowOffset.y);
|
||||
block.SetFloat(ShaderUtilities.ID_UnderlaySoftness, _format.underlaySoftness);
|
||||
}
|
||||
else
|
||||
{
|
||||
graphics.ToggleKeyword("UNDERLAY_ON", false);
|
||||
|
||||
block.SetFloat(ShaderUtilities.ID_UnderlayOffsetX, 0);
|
||||
block.SetFloat(ShaderUtilities.ID_UnderlayOffsetY, 0);
|
||||
block.SetFloat(ShaderUtilities.ID_UnderlaySoftness, 0);
|
||||
}
|
||||
}
|
||||
|
||||
override public void StartDraw(NGraphics graphics)
|
||||
{
|
||||
_padding = graphics.userData.x;
|
||||
_stylePadding = graphics.userData.y;
|
||||
|
||||
if (graphics.subInstances != null)
|
||||
{
|
||||
foreach (var g in graphics.subInstances)
|
||||
{
|
||||
if (g.texture == null)
|
||||
continue;
|
||||
|
||||
var mesh = g.meshFactory as TMPFont_SubMesh;
|
||||
if (mesh != null)
|
||||
{
|
||||
mesh.font._padding = g.userData.x;
|
||||
mesh.font._stylePadding = g.userData.y;
|
||||
mesh.font._subMeshBuffers[mesh.atlasIndex] = mesh.source = VertexBuffer.Begin();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NTexture WrapAtlasTexture(int index)
|
||||
{
|
||||
if (_atlasTextures.Length != fontAsset.atlasTextures.Length)
|
||||
{
|
||||
Array.Resize(ref _atlasTextures, fontAsset.atlasTextures.Length);
|
||||
Array.Resize(ref _subMeshBuffers, _atlasTextures.Length);
|
||||
}
|
||||
|
||||
var texture = _atlasTextures[index];
|
||||
if (texture == null)
|
||||
{
|
||||
texture = new NTexture(_fontAsset.atlasTextures[index]);
|
||||
texture.destroyMethod = DestroyMethod.None;
|
||||
_atlasTextures[index] = texture;
|
||||
|
||||
var manager = texture.GetMaterialManager(this.shader);
|
||||
manager.onCreateNewMaterial += OnCreateNewMaterial;
|
||||
}
|
||||
else if (texture.nativeTexture != _fontAsset.atlasTextures[index])
|
||||
{
|
||||
texture.Reload(_fontAsset.atlasTextures[index], null);
|
||||
}
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
override public void SetFormat(TextFormat format, float fontSizeScale)
|
||||
{
|
||||
_format = format;
|
||||
_formatVersion++;
|
||||
|
||||
_fontSizeScale = fontSizeScale;
|
||||
float size = _format.size * fontSizeScale;
|
||||
if (_format.specialStyle == TextFormat.SpecialStyle.Subscript || _format.specialStyle == TextFormat.SpecialStyle.Superscript)
|
||||
size *= SupScale;
|
||||
|
||||
_scale = size / _fontAsset.faceInfo.pointSize * _fontAsset.faceInfo.scale;
|
||||
_style = FontStyles.Normal;
|
||||
if (_format.bold)
|
||||
{
|
||||
_style |= FontStyles.Bold;
|
||||
_fontWeight = FontWeight.Bold;
|
||||
_boldMultiplier = 1 + _fontAsset.boldSpacing * 0.01f;
|
||||
}
|
||||
else
|
||||
{
|
||||
_fontWeight = _defaultFontWeight;
|
||||
_boldMultiplier = 1.0f;
|
||||
}
|
||||
if (_format.italic)
|
||||
_style |= FontStyles.Italic;
|
||||
|
||||
_format.FillVertexColors(vertexColors);
|
||||
}
|
||||
|
||||
override public bool GetGlyph(char ch, out float width, out float height, out float baseline)
|
||||
{
|
||||
if (!GetCharacterFromFontAsset(ch, _style, _fontWeight))
|
||||
{
|
||||
width = height = baseline = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
var font = _fallbackFont ?? this;
|
||||
|
||||
width = _char.glyph.metrics.horizontalAdvance * font._boldMultiplier * font._scale;
|
||||
height = font._lineHeight * font._scale;
|
||||
baseline = font._ascent * font._scale;
|
||||
|
||||
if (_format.specialStyle == TextFormat.SpecialStyle.Subscript)
|
||||
{
|
||||
height /= SupScale;
|
||||
baseline /= SupScale;
|
||||
}
|
||||
else if (_format.specialStyle == TextFormat.SpecialStyle.Superscript)
|
||||
{
|
||||
height = height / SupScale + baseline * SupOffset;
|
||||
baseline *= (SupOffset + 1 / SupScale);
|
||||
}
|
||||
|
||||
height = Mathf.RoundToInt(height);
|
||||
baseline = Mathf.RoundToInt(baseline);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GetCharacterFromFontAsset(uint unicode, FontStyles fontStyle, FontWeight fontWeight)
|
||||
{
|
||||
bool isAlternativeTypeface;
|
||||
|
||||
// #region OLD_TMP_VERION
|
||||
// TMP_FontAsset actualAsset;
|
||||
// _char = TMP_FontAssetUtilities.GetCharacterFromFontAsset(unicode, _fontAsset, true, fontStyle, fontWeight,
|
||||
// out isAlternativeTypeface, out actualAsset
|
||||
// );
|
||||
// if (_char == null)
|
||||
// return false;
|
||||
// #endregion
|
||||
|
||||
#region NEW_TMP_VERION
|
||||
_char = TMP_FontAssetUtilities.GetCharacterFromFontAsset(unicode, _fontAsset, true, fontStyle, fontWeight,
|
||||
out isAlternativeTypeface
|
||||
);
|
||||
if (_char == null)
|
||||
return false;
|
||||
|
||||
TMP_FontAsset actualAsset = _char.textAsset as TMP_FontAsset;
|
||||
#endregion
|
||||
|
||||
if (actualAsset != _fontAsset) //fallback
|
||||
{
|
||||
if (_fallbackFont == null || _fallbackFont._fontAsset != actualAsset)
|
||||
{
|
||||
_fallbackFont = _fallbackFonts.Find(x => x._fontAsset == actualAsset);
|
||||
if (_fallbackFont == null && _preparing)
|
||||
{
|
||||
_fallbackFont = new TMPFont();
|
||||
_fallbackFont.fontAsset = actualAsset;
|
||||
_fallbackFonts.Add(_fallbackFont);
|
||||
}
|
||||
}
|
||||
if (_fallbackFont != null)
|
||||
{
|
||||
if (_fallbackFont._formatVersion != _formatVersion)
|
||||
{
|
||||
_fallbackFont.SetFormat(_format, _fontSizeScale);
|
||||
_fallbackFont._formatVersion = _formatVersion;
|
||||
}
|
||||
|
||||
_fallbackFont._char = _char;
|
||||
}
|
||||
}
|
||||
else
|
||||
_fallbackFont = null;
|
||||
|
||||
if (_preparing)
|
||||
{
|
||||
if (_fallbackFont != null)
|
||||
{
|
||||
_fallbackFont.WrapAtlasTexture(_char.glyph.atlasIndex).lastActive = 1;
|
||||
}
|
||||
else if (_char.glyph.atlasIndex != 0)
|
||||
{
|
||||
WrapAtlasTexture(_char.glyph.atlasIndex).lastActive = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static Vector3 bottomLeft;
|
||||
static Vector3 topLeft;
|
||||
static Vector3 topRight;
|
||||
static Vector3 bottomRight;
|
||||
|
||||
static Vector4 uvBottomLeft;
|
||||
static Vector4 uvTopLeft;
|
||||
static Vector4 uvTopRight;
|
||||
static Vector4 uvBottomRight;
|
||||
|
||||
static Vector4 uv2BottomLeft;
|
||||
static Vector4 uv2TopLeft;
|
||||
static Vector4 uv2TopRight;
|
||||
static Vector4 uv2BottomRight;
|
||||
|
||||
static Color32[] vertexColors = new Color32[4];
|
||||
|
||||
override public void DrawGlyph(VertexBuffer vb, float x, float y)
|
||||
{
|
||||
if (_fallbackFont != null)
|
||||
{
|
||||
_fallbackFont.DrawGlyph(vb, x, y);
|
||||
return;
|
||||
}
|
||||
|
||||
vb = _subMeshBuffers[_char.glyph.atlasIndex] ?? vb;
|
||||
GlyphMetrics metrics = _char.glyph.metrics;
|
||||
GlyphRect rect = _char.glyph.glyphRect;
|
||||
|
||||
if (_format.specialStyle == TextFormat.SpecialStyle.Subscript)
|
||||
y = y - Mathf.RoundToInt(_ascent * _scale * SupOffset);
|
||||
else if (_format.specialStyle == TextFormat.SpecialStyle.Superscript)
|
||||
y = y + Mathf.RoundToInt(_ascent * _scale * (1 / SupScale - 1 + SupOffset));
|
||||
|
||||
topLeft.x = x + (metrics.horizontalBearingX - _padding - _stylePadding) * _scale;
|
||||
topLeft.y = y + (metrics.horizontalBearingY + _padding) * _scale;
|
||||
bottomRight.x = topLeft.x + (metrics.width + _padding * 2 + _stylePadding * 2) * _scale;
|
||||
bottomRight.y = topLeft.y - (metrics.height + _padding * 2) * _scale;
|
||||
|
||||
topRight.x = bottomRight.x;
|
||||
topRight.y = topLeft.y;
|
||||
bottomLeft.x = topLeft.x;
|
||||
bottomLeft.y = bottomRight.y;
|
||||
|
||||
#region Handle Italic & Shearing
|
||||
if (((_style & FontStyles.Italic) == FontStyles.Italic))
|
||||
{
|
||||
// Shift Top vertices forward by half (Shear Value * height of character) and Bottom vertices back by same amount.
|
||||
float shear_value = _fontAsset.italicStyle * 0.01f;
|
||||
Vector3 topShear = new Vector3(shear_value * ((metrics.horizontalBearingY + _padding + _stylePadding) * _scale), 0, 0);
|
||||
Vector3 bottomShear = new Vector3(shear_value * (((metrics.horizontalBearingY - metrics.height - _padding - _stylePadding)) * _scale), 0, 0);
|
||||
|
||||
topLeft += topShear;
|
||||
bottomLeft += bottomShear;
|
||||
topRight += topShear;
|
||||
bottomRight += bottomShear;
|
||||
}
|
||||
#endregion Handle Italics & Shearing
|
||||
|
||||
vb.vertices.Add(bottomLeft);
|
||||
vb.vertices.Add(topLeft);
|
||||
vb.vertices.Add(topRight);
|
||||
vb.vertices.Add(bottomRight);
|
||||
|
||||
float u = (rect.x - _padding - _stylePadding) / _fontAsset.atlasWidth;
|
||||
float v = (rect.y - _padding - _stylePadding) / _fontAsset.atlasHeight;
|
||||
float uw = rect.width > 0 ? (rect.width + _padding * 2 + _stylePadding * 2) / _fontAsset.atlasWidth : 0;
|
||||
float vw = rect.height > 0 ? (rect.height + _padding * 2 + _stylePadding * 2) / _fontAsset.atlasHeight : 0;
|
||||
|
||||
uvBottomLeft = new Vector2(u, v);
|
||||
uvTopLeft = new Vector2(u, v + vw);
|
||||
uvTopRight = new Vector2(u + uw, v + vw);
|
||||
uvBottomRight = new Vector2(u + uw, v);
|
||||
|
||||
float xScale = _scale * 0.01f;
|
||||
if (_format.bold)
|
||||
xScale *= -1;
|
||||
uv2BottomLeft = new Vector2(0, xScale);
|
||||
uv2TopLeft = new Vector2(511, xScale);
|
||||
uv2TopRight = new Vector2(2093567, xScale);
|
||||
uv2BottomRight = new Vector2(2093056, xScale);
|
||||
|
||||
vb.uvs.Add(uvBottomLeft);
|
||||
vb.uvs.Add(uvTopLeft);
|
||||
vb.uvs.Add(uvTopRight);
|
||||
vb.uvs.Add(uvBottomRight);
|
||||
|
||||
vb.uvs2.Add(uv2BottomLeft);
|
||||
vb.uvs2.Add(uv2TopLeft);
|
||||
vb.uvs2.Add(uv2TopRight);
|
||||
vb.uvs2.Add(uv2BottomRight);
|
||||
|
||||
vb.colors.Add(vertexColors[0]);
|
||||
vb.colors.Add(vertexColors[1]);
|
||||
vb.colors.Add(vertexColors[2]);
|
||||
vb.colors.Add(vertexColors[3]);
|
||||
}
|
||||
|
||||
override public void DrawLine(VertexBuffer vb, float x, float y, float width, int fontSize, int type)
|
||||
{
|
||||
if (!GetCharacterFromFontAsset('_', _style, FontWeight.Regular))
|
||||
return;
|
||||
|
||||
if (_fallbackFont != null)
|
||||
_fallbackFont.InternalDrawLine(vb, x, y, width, fontSize, type);
|
||||
else
|
||||
InternalDrawLine(vb, x, y, width, fontSize, type);
|
||||
}
|
||||
|
||||
void InternalDrawLine(VertexBuffer vb, float x, float y, float width, int fontSize, int type)
|
||||
{
|
||||
vb = _subMeshBuffers[_char.glyph.atlasIndex] ?? vb;
|
||||
|
||||
float thickness;
|
||||
float offset;
|
||||
|
||||
if (type == 0)
|
||||
{
|
||||
thickness = _fontAsset.faceInfo.underlineThickness;
|
||||
offset = _fontAsset.faceInfo.underlineOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
thickness = _fontAsset.faceInfo.strikethroughThickness;
|
||||
offset = _fontAsset.faceInfo.strikethroughOffset;
|
||||
}
|
||||
|
||||
GlyphRect rect = _char.glyph.glyphRect;
|
||||
float scale = (float)fontSize / _fontAsset.faceInfo.pointSize * _fontAsset.faceInfo.scale;
|
||||
float segmentWidth = _char.glyph.metrics.width / 2 * scale;
|
||||
width += _padding * 2;
|
||||
if (width < _char.glyph.metrics.width * scale)
|
||||
segmentWidth = width / 2f;
|
||||
|
||||
// UNDERLINE VERTICES FOR (3) LINE SEGMENTS
|
||||
#region UNDERLINE VERTICES
|
||||
|
||||
thickness = thickness * scale;
|
||||
if (thickness < 1)
|
||||
thickness = 1;
|
||||
offset = Mathf.RoundToInt(offset * scale);
|
||||
|
||||
x -= _padding;
|
||||
y += offset;
|
||||
|
||||
// Front Part of the Underline
|
||||
topLeft.x = x;
|
||||
topLeft.y = y + _padding * scale;
|
||||
bottomRight.x = x + segmentWidth;
|
||||
bottomRight.y = y - thickness - _padding * scale;
|
||||
|
||||
topRight.x = bottomRight.x;
|
||||
topRight.y = topLeft.y;
|
||||
bottomLeft.x = topLeft.x;
|
||||
bottomLeft.y = bottomRight.y;
|
||||
|
||||
vb.vertices.Add(bottomLeft);
|
||||
vb.vertices.Add(topLeft);
|
||||
vb.vertices.Add(topRight);
|
||||
vb.vertices.Add(bottomRight);
|
||||
|
||||
// Middle Part of the Underline
|
||||
topLeft = topRight;
|
||||
bottomLeft = bottomRight;
|
||||
|
||||
topRight.x = x + width - segmentWidth;
|
||||
bottomRight.x = topRight.x;
|
||||
|
||||
vb.vertices.Add(bottomLeft);
|
||||
vb.vertices.Add(topLeft);
|
||||
vb.vertices.Add(topRight);
|
||||
vb.vertices.Add(bottomRight);
|
||||
|
||||
// End Part of the Underline
|
||||
topLeft = topRight;
|
||||
bottomLeft = bottomRight;
|
||||
|
||||
topRight.x = x + width;
|
||||
bottomRight.x = topRight.x;
|
||||
|
||||
vb.vertices.Add(bottomLeft);
|
||||
vb.vertices.Add(topLeft);
|
||||
vb.vertices.Add(topRight);
|
||||
vb.vertices.Add(bottomRight);
|
||||
|
||||
#endregion
|
||||
|
||||
// UNDERLINE UV0
|
||||
#region HANDLE UV0
|
||||
|
||||
// Calculate UV required to setup the 3 Quads for the Underline.
|
||||
Vector2 uv0 = new Vector2((rect.x - _padding) / _fontAsset.atlasWidth, (rect.y - _padding) / _fontAsset.atlasHeight); // bottom left
|
||||
Vector2 uv1 = new Vector2(uv0.x, (rect.y + rect.height + _padding) / _fontAsset.atlasHeight); // top left
|
||||
Vector2 uv2 = new Vector2((rect.x - _padding + (float)rect.width / 2) / _fontAsset.atlasWidth, uv1.y); // Mid Top Left
|
||||
Vector2 uv3 = new Vector2(uv2.x, uv0.y); // Mid Bottom Left
|
||||
Vector2 uv4 = new Vector2((rect.x + _padding + (float)rect.width / 2) / _fontAsset.atlasWidth, uv1.y); // Mid Top Right
|
||||
Vector2 uv5 = new Vector2(uv4.x, uv0.y); // Mid Bottom right
|
||||
Vector2 uv6 = new Vector2((rect.x + _padding + rect.width) / _fontAsset.atlasWidth, uv1.y); // End Part - Bottom Right
|
||||
Vector2 uv7 = new Vector2(uv6.x, uv0.y); // End Part - Top Right
|
||||
|
||||
vb.uvs.Add(uv0);
|
||||
vb.uvs.Add(uv1);
|
||||
vb.uvs.Add(uv2);
|
||||
vb.uvs.Add(uv3);
|
||||
|
||||
// Middle Part of the Underline
|
||||
vb.uvs.Add(new Vector2(uv2.x - uv2.x * 0.001f, uv0.y));
|
||||
vb.uvs.Add(new Vector2(uv2.x - uv2.x * 0.001f, uv1.y));
|
||||
vb.uvs.Add(new Vector2(uv2.x + uv2.x * 0.001f, uv1.y));
|
||||
vb.uvs.Add(new Vector2(uv2.x + uv2.x * 0.001f, uv0.y));
|
||||
|
||||
// Right Part of the Underline
|
||||
|
||||
vb.uvs.Add(uv5);
|
||||
vb.uvs.Add(uv4);
|
||||
vb.uvs.Add(uv6);
|
||||
vb.uvs.Add(uv7);
|
||||
|
||||
#endregion
|
||||
|
||||
// UNDERLINE UV2
|
||||
#region HANDLE UV2 - SDF SCALE
|
||||
// UV1 contains Face / Border UV layout.
|
||||
float segUv1 = segmentWidth / width;
|
||||
float segUv2 = 1 - segUv1;
|
||||
|
||||
//Calculate the xScale or how much the UV's are getting stretched on the X axis for the middle section of the underline.
|
||||
float xScale = scale * 0.01f;
|
||||
|
||||
vb.uvs2.Add(PackUV(0, 0, xScale));
|
||||
vb.uvs2.Add(PackUV(0, 1, xScale));
|
||||
vb.uvs2.Add(PackUV(segUv1, 1, xScale));
|
||||
vb.uvs2.Add(PackUV(segUv1, 0, xScale));
|
||||
|
||||
vb.uvs2.Add(PackUV(segUv1, 0, xScale));
|
||||
vb.uvs2.Add(PackUV(segUv1, 1, xScale));
|
||||
vb.uvs2.Add(PackUV(segUv2, 1, xScale));
|
||||
vb.uvs2.Add(PackUV(segUv2, 0, xScale));
|
||||
|
||||
vb.uvs2.Add(PackUV(segUv2, 0, xScale));
|
||||
vb.uvs2.Add(PackUV(segUv2, 1, xScale));
|
||||
vb.uvs2.Add(PackUV(1, 1, xScale));
|
||||
vb.uvs2.Add(PackUV(1, 0, xScale));
|
||||
|
||||
#endregion
|
||||
|
||||
// UNDERLINE VERTEX COLORS
|
||||
#region
|
||||
// Alpha is the lower of the vertex color or tag color alpha used.
|
||||
|
||||
for (int i = 0; i < 12; i++)
|
||||
vb.colors.Add(vertexColors[0]);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Vector2 PackUV(float x, float y, float xScale)
|
||||
{
|
||||
double x0 = (int)(x * 511);
|
||||
double y0 = (int)(y * 511);
|
||||
|
||||
return new Vector2((float)((x0 * 4096) + y0), xScale);
|
||||
}
|
||||
|
||||
override public bool HasCharacter(char ch)
|
||||
{
|
||||
return _fontAsset.HasCharacter(ch, true);
|
||||
}
|
||||
|
||||
override public int GetLineHeight(int size)
|
||||
{
|
||||
return Mathf.RoundToInt(_lineHeight * ((float)size / _fontAsset.faceInfo.pointSize * _fontAsset.faceInfo.scale));
|
||||
}
|
||||
|
||||
void UpdatePaddings()
|
||||
{
|
||||
UpdateShaderRatios();
|
||||
|
||||
_padding = GetPadding();
|
||||
_stylePadding = (((_style & FontStyles.Bold) == FontStyles.Bold) ? _fontAsset.boldStyle : _fontAsset.normalStyle)
|
||||
/ 4.0f * _gradientScale * _ratioA;
|
||||
// Clamp overall padding to Gradient Scale size.
|
||||
if (_stylePadding + _padding > _gradientScale)
|
||||
_padding = _gradientScale - _stylePadding;
|
||||
}
|
||||
|
||||
float GetPadding()
|
||||
{
|
||||
Vector4 padding = Vector4.zero;
|
||||
Vector4 maxPadding = Vector4.zero;
|
||||
|
||||
float faceDilate = _format.faceDilate * _ratioA;
|
||||
float outlineSoftness = _format.outline > 0 ? _format.outlineSoftness : 0;
|
||||
float faceSoftness = outlineSoftness * _ratioA;
|
||||
float outlineThickness = _format.outline * _ratioA;
|
||||
|
||||
float uniformPadding = outlineThickness + faceSoftness + faceDilate;
|
||||
|
||||
// Underlay padding contribution
|
||||
if (_format.shadowOffset.x != 0 || _format.shadowOffset.y != 0)
|
||||
{
|
||||
float offsetX = _format.shadowOffset.x * _ratioC;
|
||||
float offsetY = -_format.shadowOffset.y * _ratioC;
|
||||
float dilate = _format.faceDilate * _ratioC;
|
||||
float softness = _format.underlaySoftness * _ratioC;
|
||||
|
||||
padding.x = Mathf.Max(padding.x, faceDilate + dilate + softness - offsetX);
|
||||
padding.y = Mathf.Max(padding.y, faceDilate + dilate + softness - offsetY);
|
||||
padding.z = Mathf.Max(padding.z, faceDilate + dilate + softness + offsetX);
|
||||
padding.w = Mathf.Max(padding.w, faceDilate + dilate + softness + offsetY);
|
||||
}
|
||||
|
||||
padding.x = Mathf.Max(padding.x, uniformPadding);
|
||||
padding.y = Mathf.Max(padding.y, uniformPadding);
|
||||
padding.z = Mathf.Max(padding.z, uniformPadding);
|
||||
padding.w = Mathf.Max(padding.w, uniformPadding);
|
||||
|
||||
padding.x = Mathf.Min(padding.x, 1);
|
||||
padding.y = Mathf.Min(padding.y, 1);
|
||||
padding.z = Mathf.Min(padding.z, 1);
|
||||
padding.w = Mathf.Min(padding.w, 1);
|
||||
|
||||
maxPadding.x = maxPadding.x < padding.x ? padding.x : maxPadding.x;
|
||||
maxPadding.y = maxPadding.y < padding.y ? padding.y : maxPadding.y;
|
||||
maxPadding.z = maxPadding.z < padding.z ? padding.z : maxPadding.z;
|
||||
maxPadding.w = maxPadding.w < padding.w ? padding.w : maxPadding.w;
|
||||
|
||||
padding *= _gradientScale;
|
||||
|
||||
// Set UniformPadding to the maximum value of any of its components.
|
||||
uniformPadding = Mathf.Max(padding.x, padding.y);
|
||||
uniformPadding = Mathf.Max(padding.z, uniformPadding);
|
||||
uniformPadding = Mathf.Max(padding.w, uniformPadding);
|
||||
|
||||
return uniformPadding + 1.25f;
|
||||
}
|
||||
|
||||
// Scale Ratios to ensure property ranges are optimum in Material Editor
|
||||
void UpdateShaderRatios()
|
||||
{
|
||||
_ratioA = _ratioB = _ratioC = 1;
|
||||
|
||||
float clamp = 1;
|
||||
|
||||
float weight = Mathf.Max(fontAsset.normalStyle, fontAsset.boldStyle) / 4.0f;
|
||||
float range = (weight + _format.faceDilate) * (_gradientScale - clamp);
|
||||
|
||||
// Compute Ratio A
|
||||
float outlineSoftness = _format.outline > 0 ? _format.outlineSoftness : 0;
|
||||
float t = Mathf.Max(1, weight + _format.faceDilate + _format.outline + outlineSoftness);
|
||||
_ratioA = (_gradientScale - clamp) / (_gradientScale * t);
|
||||
|
||||
// Compute Ratio B
|
||||
// no glow support yet
|
||||
|
||||
// Compute Ratio C
|
||||
if (_format.shadowOffset.x != 0 || _format.shadowOffset.y != 0)
|
||||
{
|
||||
t = Mathf.Max(1, Mathf.Max(Mathf.Abs(_format.shadowOffset.x), Mathf.Abs(-_format.shadowOffset.y)) + _format.faceDilate + _format.underlaySoftness);
|
||||
_ratioC = Mathf.Max(0, _gradientScale - clamp - range) / (_gradientScale * t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TMPFont_SubMesh : IMeshFactory
|
||||
{
|
||||
public TMPFont font;
|
||||
public int atlasIndex;
|
||||
public VertexBuffer source;
|
||||
|
||||
public void OnPopulateMesh(VertexBuffer vb)
|
||||
{
|
||||
if (source != null)
|
||||
{
|
||||
vb.Append(source);
|
||||
vb.AddTriangles();
|
||||
source = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7b7ade279883464288671135d22476f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
#if FAIRYGUI_TMPRO
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public partial class TextFormat
|
||||
{
|
||||
public float faceDilate;
|
||||
public float outlineSoftness;
|
||||
public float underlaySoftness;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6dd33b417fbb245f887d32166c8acc1d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75af914f7d92f454d9c7719275cf401c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,77 @@
|
||||
#if UNITY_WEBGL && FAIRYGUI_WEBGL_TEXT_INPUT
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using AOT;
|
||||
using FairyGUI;
|
||||
using UnityEngine;
|
||||
|
||||
public static class WebGLTextInput
|
||||
{
|
||||
static WebGLTextInput()
|
||||
{
|
||||
WebGLTextInputInit(OnInput, OnBlur);
|
||||
}
|
||||
|
||||
public static void Start(InputTextField target)
|
||||
{
|
||||
WebGLTextInputSetText(target.text,
|
||||
!target.textField.singleLine,
|
||||
ColorUtility.ToHtmlStringRGBA(target.textFormat.color),
|
||||
target.textFormat.size,
|
||||
target.textFormat.font,
|
||||
target.maxLength);
|
||||
|
||||
WebGLInput.captureAllKeyboardInput = false;
|
||||
|
||||
SyncTransform(target);
|
||||
}
|
||||
|
||||
public static void Stop()
|
||||
{
|
||||
WebGLTextInputHide();
|
||||
}
|
||||
|
||||
public static void SyncTransform(InputTextField target)
|
||||
{
|
||||
Rect rect = target.TransformRect(new Rect(0, 0, target.width, target.height), null);
|
||||
rect.min = StageCamera.main.WorldToScreenPoint(rect.min);
|
||||
rect.max = StageCamera.main.WorldToScreenPoint(rect.max);
|
||||
rect.y = Screen.height - rect.y - rect.height;
|
||||
|
||||
WebGLTextInputShow(rect.x, rect.y, target.width, target.height,
|
||||
rect.width / target.width, rect.height / target.height);
|
||||
}
|
||||
|
||||
[MonoPInvokeCallback(typeof(Action<string>))]
|
||||
static void OnInput(string value)
|
||||
{
|
||||
var focus = Stage.inst.focus as InputTextField;
|
||||
if (focus != null)
|
||||
focus.ReplaceText(value);
|
||||
}
|
||||
|
||||
[MonoPInvokeCallback(typeof(Action))]
|
||||
static void OnBlur()
|
||||
{
|
||||
WebGLInput.captureAllKeyboardInput = true;
|
||||
|
||||
var focus = Stage.inst.focus as InputTextField;
|
||||
if (focus != null)
|
||||
Stage.inst.SetFocus(null, true);
|
||||
}
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebGLTextInputInit(Action<string> onInputCallback, Action onBlurCallback);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebGLTextInputSetText(string text, bool multiline, string color, int fontSize, string fontFace, int maxLength);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebGLTextInputShow(float x, float y, float width, float height, float scaleX, float scaleY);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void WebGLTextInputHide();
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13531b8bb4ecf47a995ffa3e9c54ab0c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,107 @@
|
||||
var WebGLTextInput = {
|
||||
$canvasEle: null,
|
||||
$containerEle: null,
|
||||
$inputEle: null,
|
||||
$textareaEle: null,
|
||||
$callbacks: null,
|
||||
|
||||
WebGLTextInputInit: function (onInputCallback, onBlurCallback) {
|
||||
callbacks = { onInputCallback: onInputCallback, onBlurCallback: onBlurCallback };
|
||||
canvasEle = document.getElementById('unity-canvas');
|
||||
},
|
||||
|
||||
WebGLTextInputSetText: function (text, multiline, color, fontSize, fontFace, maxLength) {
|
||||
if (containerEle == null) {
|
||||
InitInput(inputEle = document.createElement("input"));
|
||||
InitInput(textareaEle = document.createElement("textarea"));
|
||||
|
||||
containerEle = document.createElement("div");
|
||||
containerEle.style.cssText = "transform-origin:0 0;-webkit-transform-origin:0 0;-moz-transform-origin:0 0;-o-transform-origin:0 0;";
|
||||
containerEle.style.position = "absolute";
|
||||
containerEle.style.zIndex = '1E5';
|
||||
containerEle.name = "WebGLTextInput";
|
||||
canvasEle.parentElement.appendChild(containerEle);
|
||||
}
|
||||
|
||||
inputEle.parentElement && (containerEle.removeChild(inputEle));
|
||||
textareaEle.parentElement && (containerEle.removeChild(textareaEle));
|
||||
|
||||
var current = multiline ? textareaEle : inputEle;
|
||||
containerEle.appendChild(current);
|
||||
containerEle.style.display = "";
|
||||
|
||||
current.maxLength = maxLength <= 0 ? 1E5 : maxLength;
|
||||
current.value = UTF8ToString(text);
|
||||
current.style.color = color;
|
||||
current.style.fontSize = fontSize + 'px';
|
||||
current.style.fontFamily = fontFace;
|
||||
current.focus();
|
||||
},
|
||||
|
||||
WebGLTextInputShow: function (x, y, width, height, scaleX, scaleY) {
|
||||
containerEle.style.top = y + "px";
|
||||
containerEle.style.left = x + "px";
|
||||
containerEle.style.width = width + "px";
|
||||
containerEle.style.height = height + "px";
|
||||
containerEle.style.transform = "scale(" + scaleX + "," + scaleY + ")";
|
||||
},
|
||||
|
||||
WebGLTextInputHide: function () {
|
||||
containerEle.style.display = "none";
|
||||
},
|
||||
|
||||
|
||||
$InitInput: function (input) {
|
||||
var style = input.style;
|
||||
style.position = "absolute";
|
||||
style.width = "100%";
|
||||
style.height = "100%";
|
||||
style.overflow = "hidden";
|
||||
style.resize = 'none';
|
||||
style.backgroundColor = 'transparent';
|
||||
style.border = 'none';
|
||||
style.outline = 'none';
|
||||
|
||||
var t = callbacks;
|
||||
input.addEventListener('input', function () {
|
||||
var returnStr = input.value;
|
||||
var bufferSize = lengthBytesUTF8(returnStr) + 1;
|
||||
var buffer = _malloc(bufferSize);
|
||||
stringToUTF8(returnStr, buffer, bufferSize);
|
||||
dynCall("vi", t.onInputCallback, [buffer]);
|
||||
});
|
||||
|
||||
input.addEventListener('blur', function () {
|
||||
if (input.parentElement)
|
||||
input.parentElement.style.display = "none";
|
||||
dynCall("v", t.onBlurCallback);
|
||||
});
|
||||
|
||||
if (input.tagName == "INPUT") {
|
||||
input.addEventListener('keydown', function (e) {
|
||||
if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) {
|
||||
e.preventDefault();
|
||||
input.blur();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var stopEvent = function (e) {
|
||||
if (e.type == 'touchmove')
|
||||
e.preventDefault();
|
||||
e.stopPropagation && e.stopPropagation();
|
||||
}
|
||||
|
||||
input.addEventListener('mousemove', stopEvent, { passive: false });
|
||||
input.addEventListener('mousedown', stopEvent, { passive: false });
|
||||
input.addEventListener('touchmove', stopEvent, { passive: false });
|
||||
},
|
||||
};
|
||||
|
||||
autoAddDeps(WebGLTextInput, '$canvasEle');
|
||||
autoAddDeps(WebGLTextInput, '$containerEle');
|
||||
autoAddDeps(WebGLTextInput, '$inputEle');
|
||||
autoAddDeps(WebGLTextInput, '$textareaEle');
|
||||
autoAddDeps(WebGLTextInput, "$callbacks");
|
||||
autoAddDeps(WebGLTextInput, '$InitInput');
|
||||
mergeInto(LibraryManager.library, WebGLTextInput);
|
||||
@@ -0,0 +1,36 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3613e6a08c3e07c47937410768813692
|
||||
timeCreated: 1565948029
|
||||
licenseType: Pro
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Facebook: WebGL
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
WebGL: WebGL
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user