blob: 8a0d194a898a6809b51f2985c272455500a8d0e0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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<Renderer>();
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");
}
}
|