feat: 全面重写—shader模型描边+Shose→ping→chanraotuibu→ping第二轮
- ShoseClickHandler: shader描边,点击移动Shose到ShosePoint+激活ping.004 - PingClickHandler: shader描边两阶段,第一轮完激活chanraotuibu - ChanraoTuibuHandler: shader描边,点击后亮起ping第二轮边框 - TouchPositionHandler: point1激活Shose而非chanraotuibu - 所有Handler用Custom/OutlineUnlit shader(_MainColor.a=0)实现模型精准描边
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Shose 鞋子交互:shader 模型描边闪烁,点击后显示模型+移动到ShosePoint
|
||||
/// </summary>
|
||||
public class ShoseClickHandler : MonoBehaviour
|
||||
{
|
||||
public GameObject nextObject;
|
||||
public Transform targetPoint;
|
||||
|
||||
private MeshRenderer _modelRenderer;
|
||||
private MeshRenderer _outlineMesh;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
_modelRenderer = GetComponent<MeshRenderer>();
|
||||
if (_modelRenderer != null) _modelRenderer.enabled = false;
|
||||
|
||||
CreateOutlineMesh();
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(BlinkOutline());
|
||||
}
|
||||
|
||||
void CreateOutlineMesh()
|
||||
{
|
||||
if (_outlineMesh != null) return;
|
||||
var mf = GetComponent<MeshFilter>();
|
||||
if (mf == null || mf.sharedMesh == null) return;
|
||||
|
||||
var mat = new Material(Shader.Find("Custom/OutlineUnlit"));
|
||||
mat.SetColor("_OutlineColor", new Color(0.2f, 0.5f, 1f, 1f));
|
||||
mat.SetColor("_MainColor", new Color(0, 0, 0, 0));
|
||||
mat.SetFloat("_OutlineWidth", 0.03f);
|
||||
|
||||
var go = new GameObject("Outline");
|
||||
go.transform.SetParent(transform, false);
|
||||
var omf = go.AddComponent<MeshFilter>();
|
||||
omf.sharedMesh = mf.sharedMesh;
|
||||
_outlineMesh = go.AddComponent<MeshRenderer>();
|
||||
_outlineMesh.material = mat;
|
||||
}
|
||||
|
||||
System.Collections.IEnumerator BlinkOutline()
|
||||
{
|
||||
if (_outlineMesh != null) _outlineMesh.enabled = true;
|
||||
yield return new WaitForSeconds(0.4f);
|
||||
while (true)
|
||||
{
|
||||
if (_outlineMesh != null) _outlineMesh.enabled = !_outlineMesh.enabled;
|
||||
yield return new WaitForSeconds(0.4f);
|
||||
}
|
||||
}
|
||||
|
||||
void OnMouseDown()
|
||||
{
|
||||
StopAllCoroutines();
|
||||
if (_modelRenderer != null) _modelRenderer.enabled = true;
|
||||
if (_outlineMesh != null) _outlineMesh.enabled = false;
|
||||
|
||||
if (targetPoint != null)
|
||||
{
|
||||
transform.position = targetPoint.position;
|
||||
transform.rotation = targetPoint.rotation;
|
||||
}
|
||||
|
||||
if (nextObject != null) nextObject.SetActive(true);
|
||||
Debug.Log($"[ShoseClick] 已移动到{targetPoint?.name}, {nextObject?.name} 已激活");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user