Compare commits

...

3 Commits

13 changed files with 340 additions and 62 deletions

View File

@@ -221,9 +221,11 @@ MonoBehaviour:
isEnableInteract: 1 isEnableInteract: 1
isEnableEdit: 1 isEnableEdit: 1
isEnableConnect: 1 isEnableConnect: 1
componentName:
needSignalCount: 2
isOpenInEditor: 1 isOpenInEditor: 1
needSignalCount: 2
currentSignalCount: 0
componentName:
isEnableSendSignal: 1
sendSignalMode: 1 sendSignalMode: 1
controlTarget: controlTarget:
- {fileID: 0} - {fileID: 0}

View File

@@ -123,9 +123,11 @@ MonoBehaviour:
isEnableInteract: 1 isEnableInteract: 1
isEnableEdit: 1 isEnableEdit: 1
isEnableConnect: 1 isEnableConnect: 1
componentName:
needSignalCount: 1
isOpenInEditor: 1 isOpenInEditor: 1
needSignalCount: 1
currentSignalCount: 0
componentName:
isEnableSendSignal: 1
--- !u!114 &6634784627554641663 --- !u!114 &6634784627554641663
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@@ -169,9 +169,12 @@ MonoBehaviour:
isEnableInteract: 1 isEnableInteract: 1
isEnableEdit: 1 isEnableEdit: 1
isEnableConnect: 1 isEnableConnect: 1
componentName:
needSignalCount: 1
isOpenInEditor: 1 isOpenInEditor: 1
needSignalCount: 1
currentSignalCount: 0
componentName:
isEnableSendSignal: 1
isEmittingOnStart: 0
prefabToEmit: {fileID: 7979385610396712053, guid: 9fc63211af583b946b1f381e4bf38ddf, prefabToEmit: {fileID: 7979385610396712053, guid: 9fc63211af583b946b1f381e4bf38ddf,
type: 3} type: 3}
emitPoint: {fileID: 119873216418816890} emitPoint: {fileID: 119873216418816890}
@@ -179,6 +182,11 @@ MonoBehaviour:
emitForce: 10 emitForce: 10
emitInterval: 1 emitInterval: 1
destroyDelay: 5 destroyDelay: 5
overridePrefabScale: 0
fixedScale: {x: 1, y: 1, z: 1}
randomizeScale: 0
minScale: {x: 1, y: 1, z: 1}
maxScale: {x: 1, y: 1, z: 1}
--- !u!114 &8359041934045797068 --- !u!114 &8359041934045797068
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@@ -184,9 +184,11 @@ MonoBehaviour:
isEnableInteract: 1 isEnableInteract: 1
isEnableEdit: 1 isEnableEdit: 1
isEnableConnect: 1 isEnableConnect: 1
componentName:
needSignalCount: 1
isOpenInEditor: 1 isOpenInEditor: 1
needSignalCount: 1
currentSignalCount: 0
componentName:
isEnableSendSignal: 1
disappearType: 0 disappearType: 0
--- !u!1 &8796126894100698369 --- !u!1 &8796126894100698369
GameObject: GameObject:

View File

@@ -233,6 +233,7 @@ MonoBehaviour:
needSignalCount: 1 needSignalCount: 1
currentSignalCount: 0 currentSignalCount: 0
componentName: componentName:
isEnableSendSignal: 1
startPositionObject: {fileID: 3154147150921727065} startPositionObject: {fileID: 3154147150921727065}
targetPositionObject: {fileID: 2516956888757501734} targetPositionObject: {fileID: 2516956888757501734}
moveSpeed: 2 moveSpeed: 2

View File

@@ -137,9 +137,11 @@ MonoBehaviour:
isEnableInteract: 1 isEnableInteract: 1
isEnableEdit: 1 isEnableEdit: 1
isEnableConnect: 1 isEnableConnect: 1
componentName:
needSignalCount: 1
isOpenInEditor: 1 isOpenInEditor: 1
needSignalCount: 1
currentSignalCount: 0
componentName:
isEnableSendSignal: 1
currentNumber: 0 currentNumber: 0
correctNumber: 1 correctNumber: 1
--- !u!114 &1413885433821236986 --- !u!114 &1413885433821236986

View File

@@ -173,7 +173,7 @@ MonoBehaviour:
needSignalCount: 1 needSignalCount: 1
currentSignalCount: 0 currentSignalCount: 0
componentName: componentName:
isEnableSendSignal: 0 isEnableSendSignal: 1
destinationPoint: {fileID: 8009085288281141996} destinationPoint: {fileID: 8009085288281141996}
playerTag: Player playerTag: Player
transportDelay: 0.1 transportDelay: 0.1

View File

@@ -1114,6 +1114,74 @@ PrefabInstance:
m_AddedGameObjects: [] m_AddedGameObjects: []
m_AddedComponents: [] m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: be07db3098b709a40a6965f50f8c9640, type: 3} m_SourcePrefab: {fileID: 100100000, guid: be07db3098b709a40a6965f50f8c9640, type: 3}
--- !u!1001 &830739288
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalPosition.x
value: -20
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalPosition.y
value: 3
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7524217001864027819, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_Name
value: HidePlatform (2)
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: fff496640cf3cc748b6a608893c657ba, type: 3}
--- !u!1001 &865274353 --- !u!1001 &865274353
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -1572,6 +1640,79 @@ PrefabInstance:
m_AddedGameObjects: [] m_AddedGameObjects: []
m_AddedComponents: [] m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: be07db3098b709a40a6965f50f8c9640, type: 3} m_SourcePrefab: {fileID: 100100000, guid: be07db3098b709a40a6965f50f8c9640, type: 3}
--- !u!1001 &1707098865
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 5795370598927137930, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: disappearType
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalPosition.x
value: -20
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalPosition.y
value: 6.56
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7524217001864027819, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_Name
value: HidePlatform (4)
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: fff496640cf3cc748b6a608893c657ba, type: 3}
--- !u!1001 &1751629950 --- !u!1001 &1751629950
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -1769,6 +1910,79 @@ Transform:
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1891511232
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 5795370598927137930, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: disappearType
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalPosition.x
value: -20
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalPosition.y
value: 4.76
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6191493531679122464, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7524217001864027819, guid: fff496640cf3cc748b6a608893c657ba,
type: 3}
propertyPath: m_Name
value: HidePlatform (3)
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: fff496640cf3cc748b6a608893c657ba, type: 3}
--- !u!1001 &1948851238 --- !u!1001 &1948851238
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -3433,6 +3647,9 @@ SceneRoots:
- {fileID: 6865129841946316189} - {fileID: 6865129841946316189}
- {fileID: 2578337202726380610} - {fileID: 2578337202726380610}
- {fileID: 4318083913684650404} - {fileID: 4318083913684650404}
- {fileID: 1891511232}
- {fileID: 1707098865}
- {fileID: 830739288}
- {fileID: 761528196} - {fileID: 761528196}
- {fileID: 1781028406820323425} - {fileID: 1781028406820323425}
- {fileID: 7779342506646282638} - {fileID: 7779342506646282638}

View File

@@ -93,24 +93,23 @@ namespace Script.Gameplay.Connect
public void OnSignalReceived(bool active, GameObject sender) public void OnSignalReceived(bool active, GameObject sender)
{ {
SendSignal(active, this.gameObject); SendSignal(active, sender);
} }
public bool IsEnableSendSignal { get; set; } = true; public bool IsEnableSendSignal { get; set; } = true;
public void SendSignal(bool active, GameObject sender) public void SendSignal(bool active, GameObject sender)
{ {
var a = _pointA as ISignalReceiver; if (_pointA.GetGameObject() != sender)
var b = _pointB as ISignalReceiver;
ISignalReceiver senderR = sender.GetComponent<ISignalReceiver>();
if (a != senderR)
{ {
a.OnSignalReceived(active, this.gameObject); var pointA = _pointA as ISignalReceiver;
pointA?.OnSignalReceived(active, this.gameObject);
} }
if (b != senderR) if (_pointB.GetGameObject() != sender)
{ {
b.OnSignalReceived(active, this.gameObject); var pointB = _pointB as ISignalReceiver;
pointB?.OnSignalReceived(active, this.gameObject);
} }
} }
} }

View File

@@ -3,6 +3,7 @@ using Script.Gameplay.Connect;
using Script.Gameplay.Global; using Script.Gameplay.Global;
using Script.Gameplay.Interface; using Script.Gameplay.Interface;
using UnityEngine; using UnityEngine;
using UnityEngine.Experimental.GlobalIllumination;
namespace Script.Gameplay.Facility namespace Script.Gameplay.Facility
{ {
@@ -108,6 +109,11 @@ namespace Script.Gameplay.Facility
public virtual void OnSignalReceived(bool active, GameObject sender) public virtual void OnSignalReceived(bool active, GameObject sender)
{ {
if (isEnableSendSignal)
{
SendSignal(active, sender);
}
if (active) if (active)
{ {
CurrentNeedSignalCount++; CurrentNeedSignalCount++;
@@ -130,23 +136,87 @@ namespace Script.Gameplay.Facility
set => isEnableSendSignal = value; set => isEnableSendSignal = value;
} }
/// <summary>
///
/// </summary>
/// <param name="active">发送true or false</param>
/// <param name="sender">让此物体触发发送的来源者</param>
public virtual void SendSignal(bool active, GameObject sender) public virtual void SendSignal(bool active, GameObject sender)
{ {
if(!IsEnableSendSignal) return; if (!IsEnableSendSignal) return;
if (ConnectionLines != null) if (ConnectionLines != null)
{ {
if (ISignalSender.IsSendToSignalSender(sender)) // 利用DFS检测是否存在连接环
if (DfsCheckConnectionRing(this.gameObject))
{ {
// 防止信号回传给发送者自己 StartCoroutine(GameManager.Instance.ReStartGame());
BUGManager.Instance.LogStackOverflowBUG(this.transform);
return; return;
} }
foreach (var line in ConnectionLines) foreach (var line in ConnectionLines)
{ {
// 排除掉为sender的连接线
if (line.gameObject == sender)
{
continue;
}
line.OnSignalReceived(active, this.gameObject); line.OnSignalReceived(active, this.gameObject);
} }
} }
} }
public static bool DfsCheckConnectionRing(GameObject root)
{
if (root == null) return false;
var rootConnect = root.GetComponent<IConnectable>();
if (rootConnect == null) return false;
var visited = new HashSet<GameObject>();
// 内部递归 DFSparent 用于避免把返回到父节点误判为环
bool Dfs(GameObject current, GameObject parent)
{
if (current == null) return false;
visited.Add(current);
var conn = current.GetComponent<IConnectable>();
if (conn == null) return false;
foreach (var line in conn.ConnectionLines)
{
if (line == null) continue;
GameObject a = line.PointA?.GetGameObject();
GameObject b = line.PointB?.GetGameObject();
GameObject neighbor = null;
if (a == current) neighbor = b;
else if (b == current) neighbor = a;
else continue; // 如果这条线并未连接到 current跳过
if (neighbor == null) continue;
// 如果邻居是父节点,跳过(因为这是无向边回到父)
if (neighbor == parent) continue;
// 已访问到其他非父节点,说明存在环
if (visited.Contains(neighbor))
{
return true;
}
if (Dfs(neighbor, current))
{
return true;
}
}
return false;
}
return Dfs(root, null);
}
} }
} }

View File

@@ -17,19 +17,13 @@ namespace Script.Gameplay.Facility
public override void Interact(GameObject interactor) public override void Interact(GameObject interactor)
{ {
if (!IsEnableInteract) return; if (!IsEnableInteract) return;
PullLever(); PullLever(this.gameObject);
} }
public override void OnSignalReceived(bool active, GameObject sender) private void PullLever(GameObject sender = null)
{
base.OnSignalReceived(active, sender);
//PullLever();
}
private void PullLever()
{ {
isPulled = !isPulled; isPulled = !isPulled;
SendSignal(isPulled, this.gameObject); SendSignal(isPulled, sender);
// 可选:拉杆动画 // 可选:拉杆动画
if (isPulled) if (isPulled)
{ {
@@ -42,6 +36,5 @@ namespace Script.Gameplay.Facility
transform.rotation = Quaternion.Euler(0f, 0f, 0f); transform.rotation = Quaternion.Euler(0f, 0f, 0f);
} }
} }
} }
} }

View File

@@ -11,19 +11,27 @@ namespace Script.Gameplay.Facility
[SerializeField] private Vector3 plateOffset = Vector3.up * 0.1f; [SerializeField] private Vector3 plateOffset = Vector3.up * 0.1f;
private bool lastState = false; private bool lastState = false;
private bool hasObject = false;
private void FixedUpdate() private void FixedUpdate()
{ {
if (!isOpenInEditor) return; if (!isOpenInEditor) return;
bool hasObject = Physics.CheckBox(transform.position + plateOffset, plateSize * 0.5f, Quaternion.identity, detectLayer); hasObject = Physics.CheckBox(transform.position + plateOffset, plateSize * 0.5f, Quaternion.identity, detectLayer);
if (hasObject != lastState) if (hasObject != lastState)
{ {
SendSignal(hasObject, this.gameObject); SendSignal(hasObject, this.gameObject);
lastState = hasObject; lastState = hasObject;
if (hasObject)
{
// 被压下动画
}
else
{
// 弹起动画
}
} }
} }
#if UNITY_EDITOR #if UNITY_EDITOR
private void OnDrawGizmosSelected() private void OnDrawGizmosSelected()
{ {

View File

@@ -11,31 +11,5 @@ namespace Script.Gameplay.Interface
GameObject GetGameObject(); // 获取连接点物体 GameObject GetGameObject(); // 获取连接点物体
string GetConnectableName(); // 获取连接点名称 string GetConnectableName(); // 获取连接点名称
public List<ConnectionLine> ConnectionLines { get; set; } public List<ConnectionLine> ConnectionLines { get; set; }
// public static List<GameObject> GetConnectedGameObjects(GameObject sender)
// {
// IConnectable connectable = sender.GetComponent<IConnectable>();
// List<GameObject> connectedObjects = new List<GameObject>();
// if (connectable != null)
// {
// foreach (var target in connectable.ConnectionLines)
// {
// if (target != null && target.PointA != null && target.PointB != null)
// {
// // 排除掉AB点中与sender相同的点
// if (target.PointA.GetGameObject() != sender)
// {
// connectedObjects.Add(target.PointA.GetGameObject());
// }
//
// if (target.PointB.GetGameObject() != sender)
// {
// connectedObjects.Add(target.PointB.GetGameObject());
// }
// }
// }
// }
// return connectedObjects;
// }
} }
} }