添加指引系统,退出APP功能,安徽宿州砀山古城商业街苏州场景
This commit is contained in:
8
Assets/_Valheim/Scripts/Player.meta
Normal file
8
Assets/_Valheim/Scripts/Player.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab89cc5a9acefa34db85ad4749b51af8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
102
Assets/_Valheim/Scripts/Player/GuideArrowPath.cs
Normal file
102
Assets/_Valheim/Scripts/Player/GuideArrowPath.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GuideArrowPath : MonoBehaviour
|
||||
{
|
||||
public LayerMask obstacleMask;
|
||||
public float pathHeight = 0.5f;
|
||||
|
||||
private LineRenderer lineRenderer;
|
||||
private bool isPathVisible = false;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
// 从预制体上获取已存在的LineRenderer组件
|
||||
lineRenderer = GetComponent<LineRenderer>();
|
||||
if (lineRenderer == null)
|
||||
{
|
||||
Debug.LogError("LineRenderer组件未找到!请确保预制体上已挂载LineRenderer组件");
|
||||
return;
|
||||
}
|
||||
|
||||
// 预制体上已预设LineRenderer属性,这里不再动态设置
|
||||
// 如果需要在代码中覆盖预制体设置,可以取消注释以下代码
|
||||
/*
|
||||
lineRenderer.startWidth = 0.1f;
|
||||
lineRenderer.endWidth = 0.1f;
|
||||
lineRenderer.material = new Material(Shader.Find("Sprites/Default"));
|
||||
lineRenderer.startColor = Color.yellow;
|
||||
lineRenderer.endColor = Color.red;
|
||||
*/
|
||||
|
||||
lineRenderer.positionCount = 0;
|
||||
lineRenderer.enabled = false; // 初始禁用
|
||||
|
||||
Debug.Log("GuideArrowPath 初始化完成,LineRenderer: " + (lineRenderer != null));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置路径
|
||||
/// </summary>
|
||||
public void SetPath(List<Vector3> pathPoints)
|
||||
{
|
||||
if (lineRenderer == null)
|
||||
{
|
||||
Debug.LogError("LineRenderer 未找到!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (pathPoints == null || pathPoints.Count < 2)
|
||||
{
|
||||
lineRenderer.positionCount = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// 调整路径点高度
|
||||
for (int i = 0; i < pathPoints.Count; i++)
|
||||
{
|
||||
pathPoints[i] = new Vector3(pathPoints[i].x, pathHeight, pathPoints[i].z);
|
||||
}
|
||||
|
||||
lineRenderer.positionCount = pathPoints.Count;
|
||||
lineRenderer.SetPositions(pathPoints.ToArray());
|
||||
|
||||
Debug.Log("设置路径,点数: " + pathPoints.Count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显示路径
|
||||
/// </summary>
|
||||
public void ShowPath()
|
||||
{
|
||||
if (lineRenderer != null)
|
||||
{
|
||||
lineRenderer.enabled = true;
|
||||
isPathVisible = true;
|
||||
Debug.Log("显示路径,LineRenderer enabled: " + lineRenderer.enabled);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭路径
|
||||
/// </summary>
|
||||
public void ClosePath()
|
||||
{
|
||||
if (lineRenderer != null)
|
||||
{
|
||||
lineRenderer.enabled = false;
|
||||
isPathVisible = false;
|
||||
lineRenderer.positionCount = 0;
|
||||
Debug.Log("关闭路径");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查路径是否可见
|
||||
/// </summary>
|
||||
public bool IsPathVisible()
|
||||
{
|
||||
return isPathVisible && lineRenderer != null && lineRenderer.enabled;
|
||||
}
|
||||
}
|
||||
11
Assets/_Valheim/Scripts/Player/GuideArrowPath.cs.meta
Normal file
11
Assets/_Valheim/Scripts/Player/GuideArrowPath.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8cdda35296b966646ada44468a5c40c5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user