feat(Emmit): 实现发射器
This commit is contained in:
@@ -53,7 +53,7 @@ namespace Script.Gameplay.Facility
|
||||
|
||||
[SerializeField] private bool isActive = true;
|
||||
|
||||
public bool IsActive
|
||||
public bool IsEditableActive
|
||||
{
|
||||
get => isActive;
|
||||
set
|
||||
|
@@ -8,7 +8,7 @@ namespace Script.Gameplay.Facility
|
||||
{
|
||||
[SerializeField] private bool isActive = true;
|
||||
|
||||
public bool IsActive
|
||||
public bool IsEditableActive
|
||||
{
|
||||
get => isActive;
|
||||
set
|
||||
|
@@ -62,9 +62,9 @@ namespace Script.Gameplay.Facility
|
||||
|
||||
#region EditableComponent
|
||||
|
||||
[SerializeField] private bool isActive = true;
|
||||
private bool isActive = true;
|
||||
|
||||
public bool IsActive
|
||||
public bool IsEditableActive
|
||||
{
|
||||
get => isActive;
|
||||
set
|
||||
|
77
Assets/Script/Gameplay/Facility/EmitterController.cs
Normal file
77
Assets/Script/Gameplay/Facility/EmitterController.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Script.Gameplay.Connect;
|
||||
using Script.Gameplay.Interface;
|
||||
|
||||
namespace Script.Gameplay.Facility
|
||||
{
|
||||
public class EmitterController : MonoBehaviour, IEditableComponent, IConnectable
|
||||
{
|
||||
[Header("发射器设置")]
|
||||
[SerializeField] private GameObject prefabToEmit;
|
||||
[SerializeField] private Transform emitPoint;
|
||||
[SerializeField] private Vector3 emitDirection = Vector3.forward;
|
||||
[SerializeField] private float emitForce = 10f;
|
||||
[SerializeField] private float emitInterval = 1f;
|
||||
[Header("生成对象销毁时间")]
|
||||
[SerializeField] private float destroyDelay = 5f; // 生成对象多少秒后销毁
|
||||
|
||||
private Coroutine emitCoroutine;
|
||||
|
||||
// 不可交互
|
||||
// 可编辑
|
||||
public bool IsEditableActive { get; set; } = true;
|
||||
public string ComponentName { get; set; } = "Emitter";
|
||||
public LockLevel LockLevel => LockLevel.Red;
|
||||
|
||||
// 可连线
|
||||
public List<ConnectionLine> ConnectionLines { get; set; } = new List<ConnectionLine>();
|
||||
public void OnGazeEnter() { }
|
||||
public void OnGazeExit() { }
|
||||
public Vector3 GetPosition() => transform.position;
|
||||
public GameObject GetGameObject() => gameObject;
|
||||
public string GetConnectableName() => gameObject.name;
|
||||
|
||||
// 接收信号
|
||||
public void SignalActive(bool active, GameObject sender)
|
||||
{
|
||||
if(!IsEditableActive) return;
|
||||
if (active)
|
||||
{
|
||||
if (emitCoroutine == null)
|
||||
emitCoroutine = StartCoroutine(EmitRoutine());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (emitCoroutine != null)
|
||||
{
|
||||
StopCoroutine(emitCoroutine);
|
||||
emitCoroutine = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator EmitRoutine()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Emit();
|
||||
yield return new WaitForSeconds(emitInterval);
|
||||
}
|
||||
}
|
||||
|
||||
private void Emit()
|
||||
{
|
||||
if (prefabToEmit == null || emitPoint == null) return;
|
||||
var obj = Instantiate(prefabToEmit, emitPoint.position, emitPoint.rotation);
|
||||
var rb = obj.GetComponent<Rigidbody>();
|
||||
if (rb != null)
|
||||
{
|
||||
rb.AddForce(emitPoint.TransformDirection(emitDirection.normalized) * emitForce, ForceMode.Impulse);
|
||||
}
|
||||
// 添加销毁逻辑
|
||||
Destroy(obj, destroyDelay);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a5a563132c84e50b983b557eb3da442
|
||||
timeCreated: 1761028056
|
@@ -42,7 +42,7 @@ namespace Script.Gameplay.Facility
|
||||
|
||||
[SerializeField] private bool isActive = true;
|
||||
|
||||
public bool IsActive
|
||||
public bool IsEditableActive
|
||||
{
|
||||
get => isActive;
|
||||
set
|
||||
|
@@ -28,7 +28,7 @@ namespace Script.Gameplay.Facility
|
||||
|
||||
#region EditableComponent
|
||||
|
||||
public bool IsActive
|
||||
public bool IsEditableActive
|
||||
{
|
||||
get => isActive;
|
||||
set => isActive = value;
|
||||
|
@@ -8,7 +8,7 @@ namespace Script.Gameplay.Facility
|
||||
{
|
||||
[SerializeField] private bool isActive = true;
|
||||
|
||||
public bool IsActive
|
||||
public bool IsEditableActive
|
||||
{
|
||||
get => isActive;
|
||||
set
|
||||
|
@@ -9,7 +9,7 @@ namespace Script.Gameplay.Interface
|
||||
|
||||
public interface IEditableComponent
|
||||
{
|
||||
public bool IsActive { get; set; }
|
||||
public bool IsEditableActive { get; set; }
|
||||
public string ComponentName { get; set; }
|
||||
public LockLevel LockLevel { get; }
|
||||
}
|
||||
|
@@ -81,7 +81,7 @@ namespace Script.Gameplay.Player
|
||||
{
|
||||
hitInteractable.OnGazeEnter(this.gameObject);
|
||||
// 这里可以显示交互提示UI,例如 “E - 开门”
|
||||
Debug.Log(hitInteractable.GetInteractPrompt());
|
||||
//Debug.Log(hitInteractable.GetInteractPrompt());
|
||||
}
|
||||
|
||||
previousGazedTarget = hitInteractable;
|
||||
|
@@ -24,7 +24,7 @@ namespace UI
|
||||
|
||||
private void OnClickButton()
|
||||
{
|
||||
_component.IsActive = !_component.IsActive;
|
||||
_component.IsEditableActive = !_component.IsEditableActive;
|
||||
RefreshUI();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace UI
|
||||
if (_component != null)
|
||||
{
|
||||
componentName.text = _component.ComponentName;
|
||||
componentState.text = _component.IsActive ? "Active" : "Inactive";
|
||||
componentState.text = _component.IsEditableActive ? "Active" : "Inactive";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user