From 766cdff5ffa72b65d7f106658d1603f47739b2ba Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 27 Oct 2023 11:05:14 +0800 Subject: + init --- GameCode/SFSample.cs | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 GameCode/SFSample.cs (limited to 'GameCode/SFSample.cs') diff --git a/GameCode/SFSample.cs b/GameCode/SFSample.cs new file mode 100644 index 0000000..8a0d194 --- /dev/null +++ b/GameCode/SFSample.cs @@ -0,0 +1,73 @@ +using UnityEngine; + +[RequireComponent(typeof(Renderer))] +public class SFSample : MonoBehaviour +{ + private Material _material; + + public Vector2 _samplePosition = Vector2.zero; + + public bool _lineSample; + + public Vector2 samplePosition + { + get + { + return _samplePosition; + } + set + { + _samplePosition = value; + if ((bool)_material) + { + _material.SetVector("_SamplePosition", _samplePosition); + } + } + } + + public bool lineSample + { + get + { + return _lineSample; + } + set + { + _lineSample = value; + if ((bool)_material) + { + if (value) + { + _material.EnableKeyword("LINESAMPLE_ON"); + _material.DisableKeyword("FIXEDSAMPLEPOINT_ON"); + } + else + { + _material.DisableKeyword("LINESAMPLE_ON"); + _material.EnableKeyword("FIXEDSAMPLEPOINT_ON"); + } + } + } + } + + private void Start() + { + Renderer component = GetComponent(); + Material sharedMaterial = component.sharedMaterial; + if (sharedMaterial == null || sharedMaterial.shader.name != "Sprites/SFSoftShadow") + { + Debug.LogError("SFSample requires the attached renderer to be using the Sprites/SFSoftShadow shader."); + return; + } + _material = new Material(sharedMaterial); + component.material = _material; + _material.SetFloat("_SoftHardMix", sharedMaterial.GetFloat("_SoftHardMix")); + samplePosition = _samplePosition; + lineSample = _lineSample; + } + + private void OnDrawGizmosSelected() + { + Gizmos.DrawIcon(base.transform.TransformPoint(_samplePosition), "SFDotGizmo.psd"); + } +} -- cgit v1.1-26-g67d0