using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using Microsoft.CodeAnalysis; using Photon.Pun; using TMPro; using UnityEngine; using UnityEngine.Events; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("NanJu.LevelUnityScripts")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("0.1.0.0")] [assembly: AssemblyInformationalVersion("0.1.0")] [assembly: AssemblyProduct("MyStaff")] [assembly: AssemblyTitle("NanJu.LevelUnityScripts")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.1.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } public class CountdownTimer : MonoBehaviour { [CompilerGenerated] private sealed class d__15 : IEnumerator, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; public CountdownTimer <>4__this; private float 5__1; private float 5__2; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__15(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; 5__1 = 0f; break; case 1: <>1__state = -1; <>4__this.remainingTime -= 1f; <>4__this.每秒更新事件?.Invoke(<>4__this.remainingTime); break; } if (<>4__this.remainingTime > 0f) { 5__2 = Mathf.Ceil(<>4__this.remainingTime); if (Time.time >= 5__1) { GUIManager.instance.SetHeroTitle(<>4__this.标题文字 + "\n" + <>4__this.FormatTime(5__2), (AudioClip)null); 5__1 = Time.time + <>4__this.UI刷新间隔; } else { if ((Object)(object)GUIManager.instance.heroText != (Object)null) { ((TMP_Text)GUIManager.instance.heroText).text = <>4__this.标题文字 + "\n" + <>4__this.FormatTime(5__2); } if ((Object)(object)GUIManager.instance.heroDayText != (Object)null) { ((TMP_Text)GUIManager.instance.heroDayText).text = ""; } if ((Object)(object)GUIManager.instance.heroTimeOfDayText != (Object)null) { ((TMP_Text)GUIManager.instance.heroTimeOfDayText).text = ""; } } if (<>4__this.显示调试 && <>4__this.remainingTime % 10f < 1f) { Debug.Log((object)("[CountdownTimer] " + ((Object)((Component)<>4__this).gameObject).name + " 剩余: " + <>4__this.FormatTime(<>4__this.remainingTime))); } <>2__current = (object)new WaitForSeconds(1f); <>1__state = 1; return true; } <>4__this.isRunning = false; GUIManager.instance.SetHeroTitle(<>4__this.结束文字, (AudioClip)null); UnityEvent 结束事件 = <>4__this.结束事件; if (结束事件 != null) { 结束事件.Invoke(); } if (<>4__this.显示调试) { Debug.Log((object)("[CountdownTimer] " + ((Object)((Component)<>4__this).gameObject).name + " 倒计时结束")); } return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [Header("倒计时设置")] [Tooltip("倒计时总时长(秒)")] public float 总时间 = 300f; [Tooltip("初始显示的文字(会在前面显示)")] public string 标题文字 = "倒计时"; [Tooltip("倒计时结束时显示的文字")] public string 结束文字 = "时间到"; [Header("UI刷新")] [Tooltip("每隔多少秒重新调用SetHeroTitle刷新UI(防止动画淡出后文字消失)")] public float UI刷新间隔 = 4f; [Header("事件")] [Tooltip("倒计时开始时触发")] public UnityEvent 开始事件; [Tooltip("倒计时结束时触发")] public UnityEvent 结束事件; [Tooltip("每秒更新时触发,传递剩余秒数")] public UnityEvent 每秒更新事件; [Header("调试")] public bool 显示调试 = false; private float remainingTime; private bool isRunning = false; private Coroutine countdownCoroutine; private void OnDestroy() { Stop(); } public void 开始倒计时() { if (isRunning) { return; } if ((Object)(object)GUIManager.instance == (Object)null) { Debug.LogWarning((object)("[CountdownTimer] " + ((Object)((Component)this).gameObject).name + " GUIManager不可用")); return; } isRunning = true; remainingTime = 总时间; UnityEvent obj = 开始事件; if (obj != null) { obj.Invoke(); } if (显示调试) { Debug.Log((object)("[CountdownTimer] " + ((Object)((Component)this).gameObject).name + " 倒计时开始: " + FormatTime(remainingTime))); } countdownCoroutine = ((MonoBehaviour)this).StartCoroutine(CountdownRoutine()); } public void 停止倒计时() { if (isRunning) { Stop(); } } private void Stop() { if (countdownCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(countdownCoroutine); countdownCoroutine = null; } isRunning = false; } [IteratorStateMachine(typeof(d__15))] private IEnumerator CountdownRoutine() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__15(0) { <>4__this = this }; } private string FormatTime(float seconds) { int num = Mathf.Max(0, Mathf.FloorToInt(seconds)); int num2 = num / 60; int num3 = num % 60; return $"{num2:D2}:{num3:D2}"; } } public class FallingPlatform : MonoBehaviour { private enum State { Idle, Counting, Falling, Restoring } [Header("平台设置")] public Rigidbody 刚体; public Collider 感应碰撞体; public LayerMask 检测图层 = LayerMask.op_Implicit(-1); [Header("掉落设置")] public float 掉落延迟 = 1.5f; public bool 只触发一次 = true; [Header("复原设置")] public float 复原延迟 = 3f; [Header("事件")] public UnityEvent 掉落事件; public UnityEvent 复原事件; [Header("调试")] public bool 显示调试 = false; private Vector3 originalPosition; private Quaternion originalRotation; private State state = State.Idle; private float timer = 0f; private bool used = false; private void Awake() { if ((Object)(object)刚体 == (Object)null) { 刚体 = ((Component)this).GetComponent(); } if ((Object)(object)感应碰撞体 == (Object)null) { 感应碰撞体 = ((Component)this).GetComponent(); } if ((Object)(object)刚体 == (Object)null) { 刚体 = ((Component)this).gameObject.AddComponent(); } 刚体.isKinematic = true; 刚体.useGravity = false; } private void Start() { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) originalPosition = ((Component)this).transform.position; originalRotation = ((Component)this).transform.rotation; } private void Update() { if (state == State.Idle) { if (只触发一次 && used) { return; } DetectPlayer(); } if (state == State.Counting) { timer += Time.deltaTime; if (timer >= 掉落延迟) { DoFall(); } } if (state == State.Falling) { timer += Time.deltaTime; if (复原延迟 > 0f && timer >= 复原延迟) { DoRestore(); } } } private void DetectPlayer() { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) Collider detectCollider = GetDetectCollider(); if ((Object)(object)detectCollider == (Object)null) { return; } BoxCollider val = (BoxCollider)(object)((detectCollider is BoxCollider) ? detectCollider : null); Collider[] array; if (val != null) { Vector3 val2 = ((Component)val).transform.TransformPoint(val.center); Vector3 val3 = Vector3.Scale(val.size * 0.5f, ((Component)val).transform.lossyScale); array = Physics.OverlapBox(val2, val3, ((Component)val).transform.rotation, LayerMask.op_Implicit(检测图层)); } else { SphereCollider val4 = (SphereCollider)(object)((detectCollider is SphereCollider) ? detectCollider : null); if (val4 != null) { Vector3 val5 = ((Component)val4).transform.TransformPoint(val4.center); float num = val4.radius * Mathf.Max(new float[3] { ((Component)val4).transform.lossyScale.x, ((Component)val4).transform.lossyScale.y, ((Component)val4).transform.lossyScale.z }); array = Physics.OverlapSphere(val5, num, LayerMask.op_Implicit(检测图层)); } else { CapsuleCollider val6 = (CapsuleCollider)(object)((detectCollider is CapsuleCollider) ? detectCollider : null); if (val6 != null) { GetCapsulePoints(val6, out var p, out var p2, out var radius); array = Physics.OverlapCapsule(p, p2, radius, LayerMask.op_Implicit(检测图层)); } else { array = Physics.OverlapSphere(((Component)detectCollider).transform.position, 1f, LayerMask.op_Implicit(检测图层)); } } } Collider[] array2 = array; foreach (Collider other in array2) { if (IsValidTarget(other)) { state = State.Counting; timer = 0f; used = true; if (显示调试) { Debug.Log((object)("[FallingPlatform] " + ((Object)((Component)this).gameObject).name + " 感应到物体,开始计时")); } break; } } } private void DoFall() { state = State.Falling; timer = 0f; 刚体.isKinematic = false; 刚体.useGravity = true; UnityEvent obj = 掉落事件; if (obj != null) { obj.Invoke(); } if (显示调试) { Debug.Log((object)("[FallingPlatform] " + ((Object)((Component)this).gameObject).name + " 开始掉落")); } if (复原延迟 <= 0f) { DoRestore(); } } private void DoRestore() { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) state = State.Idle; timer = 0f; 刚体.isKinematic = true; 刚体.useGravity = false; 刚体.linearVelocity = Vector3.zero; 刚体.angularVelocity = Vector3.zero; ((Component)this).transform.position = originalPosition; ((Component)this).transform.rotation = originalRotation; UnityEvent obj = 复原事件; if (obj != null) { obj.Invoke(); } if (显示调试) { Debug.Log((object)("[FallingPlatform] " + ((Object)((Component)this).gameObject).name + " 已复原")); } } private Collider GetDetectCollider() { return ((Object)(object)感应碰撞体 != (Object)null) ? 感应碰撞体 : ((Component)this).GetComponent(); } private bool IsValidTarget(Collider other) { return (((LayerMask)(ref 检测图层)).value & (1 << ((Component)other).gameObject.layer)) != 0; } private void GetCapsulePoints(CapsuleCollider capsule, out Vector3 p1, out Vector3 p2, out float radius) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) Transform transform = ((Component)capsule).transform; Vector3 val = transform.TransformPoint(capsule.center); Vector3 lossyScale = transform.lossyScale; float num = capsule.direction; float radius2 = capsule.radius; float height = capsule.height; float num2; Vector3 val2; if (num == 0f) { num2 = Mathf.Max(lossyScale.y, lossyScale.z); val2 = transform.right; } else if (num == 1f) { num2 = Mathf.Max(lossyScale.x, lossyScale.z); val2 = transform.up; } else { num2 = Mathf.Max(lossyScale.x, lossyScale.y); val2 = transform.forward; } radius = radius2 * num2; float num3 = height * 0.5f * ((num == 0f) ? lossyScale.x : ((num == 1f) ? lossyScale.y : lossyScale.z)); num3 = Mathf.Max(num3 - radius, 0f); p1 = val + val2 * num3; p2 = val - val2 * num3; } public void ForceFall() { if (state == State.Idle) { state = State.Counting; timer = 0f; used = true; } } private void OnDrawGizmos() { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) Collider detectCollider = GetDetectCollider(); if ((Object)(object)detectCollider == (Object)null) { return; } Gizmos.color = ((state == State.Falling) ? new Color(1f, 0f, 0f, 0.3f) : new Color(0f, 1f, 1f, 0.3f)); Gizmos.matrix = ((Component)detectCollider).transform.localToWorldMatrix; BoxCollider val = (BoxCollider)(object)((detectCollider is BoxCollider) ? detectCollider : null); if (val != null) { Gizmos.DrawCube(val.center, val.size); Gizmos.DrawWireCube(val.center, val.size); return; } SphereCollider val2 = (SphereCollider)(object)((detectCollider is SphereCollider) ? detectCollider : null); if (val2 != null) { Gizmos.DrawSphere(val2.center, val2.radius); Gizmos.DrawWireSphere(val2.center, val2.radius); } } } public class InteractArea : MonoBehaviour, IInteractibleConstant, IInteractible { public enum TriggerMode { Interact, Trigger } [Header("模式设置")] [Tooltip("Interact=按E交互触发, Trigger=碰撞体接触即触发")] public TriggerMode 触发模式 = TriggerMode.Interact; [Header("显示设置")] [Tooltip("交互时显示的名称")] public string 显示名称 = "交互区域"; [Tooltip("交互提示文字(Interact模式显示在屏幕上的文字)")] public string 提示文字 = "交互"; [Header("交互设置(Interact模式)")] [Tooltip("按住交互所需时间(秒)")] public float 交互时间 = 2f; [Tooltip("交互完成后是否保持按住状态")] public bool 保持按住 = true; [Header("触发设置(Trigger模式)")] [Tooltip("检测的目标图层(只检测勾选的图层)")] public LayerMask 检测图层 = LayerMask.op_Implicit(-1); [Header("通用设置")] [Tooltip("是否只触发一次")] public bool 只触发一次 = true; [Header("事件")] [Tooltip("交互完成/触发时执行的事件")] public UnityEvent 触发事件; [Tooltip("交互完成/触发后,将触发者的GameObject作为参数传递")] public UnityEvent 触发事件_带参数; [Header("调试")] public bool 显示调试 = false; private bool triggered = false; private Collider detectCollider; public float interactTime => 交互时间; public bool holdOnFinish => 保持按住; private void Awake() { //IL_0035: Unknown result type (might be due to invalid IL or missing references) detectCollider = ((Component)this).GetComponent(); if ((Object)(object)detectCollider == (Object)null) { detectCollider = (Collider)(object)((Component)this).gameObject.AddComponent(); ((Collider)(BoxCollider)detectCollider).isTrigger = true; } else { detectCollider.isTrigger = true; } } private void OnTriggerEnter(Collider other) { if (触发模式 == TriggerMode.Trigger && (!只触发一次 || !triggered) && CheckLayer(((Component)other).gameObject)) { triggered = true; FireEvent(((Component)other).gameObject); if (显示调试) { Debug.Log((object)("[InteractArea] " + ((Object)((Component)this).gameObject).name + " Trigger触发,物体: " + ((Object)other).name)); } } } private void OnTriggerStay(Collider other) { if (触发模式 == TriggerMode.Trigger && (!只触发一次 || !triggered) && CheckLayer(((Component)other).gameObject)) { triggered = true; FireEvent(((Component)other).gameObject); if (显示调试) { Debug.Log((object)("[InteractArea] " + ((Object)((Component)this).gameObject).name + " Trigger持续触发: " + ((Object)other).name)); } } } private bool CheckLayer(GameObject obj) { return (((LayerMask)(ref 检测图层)).value & (1 << obj.layer)) != 0; } private void FireEvent(GameObject triggerObject) { UnityEvent obj = 触发事件; if (obj != null) { obj.Invoke(); } 触发事件_带参数?.Invoke(triggerObject); if (显示调试) { Debug.Log((object)("[InteractArea] " + ((Object)((Component)this).gameObject).name + " 触发事件已执行")); } } public void CancelCast(Character interactor) { } public Vector3 Center() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return ((Component)this).transform.position; } public string GetInteractionText() { if (触发模式 == TriggerMode.Trigger) { return ""; } if (只触发一次 && triggered) { return ""; } return 提示文字; } public float GetInteractTime(Character interactor) { return 交互时间; } public string GetName() { return 显示名称; } public Transform GetTransform() { return ((Component)this).transform; } public void HoverEnter() { } public void HoverExit() { } public void Interact(Character interactor) { } public void Interact_CastFinished(Character interactor) { if (触发模式 == TriggerMode.Interact && (!只触发一次 || !triggered)) { triggered = true; FireEvent(((Object)(object)interactor != (Object)null) ? ((Component)interactor).gameObject : null); if (显示调试) { Debug.Log((object)("[InteractArea] " + ((Object)((Component)this).gameObject).name + " 交互完成")); } } } public bool IsConstantlyInteractable(Character interactor) { return IsInteractible(interactor); } public bool IsInteractible(Character interactor) { if (触发模式 == TriggerMode.Trigger) { return false; } if (只触发一次 && triggered) { return false; } return true; } public void ReleaseInteract(Character interactor) { } public void ResetTrigger() { triggered = false; } } public class LayerEventSystem : MonoBehaviourPunCallbacks { public enum DetectionMode { Trigger, Raycast } [Header("图层检测设置")] [Tooltip("检测的目标图层(只检测勾选的图层)")] public LayerMask 检测图层 = LayerMask.op_Implicit(-1); [Tooltip("检测模式:Trigger=碰撞体体积检测, Raycast=射线检测")] public DetectionMode 检测模式 = DetectionMode.Trigger; [Tooltip("触发碰撞体(Trigger模式,用于定义检测体积的形状和位置,拖入其他物体的Collider也生效)")] public Collider 触发碰撞体; [Header("触发事件")] [Tooltip("物体进入检测区域时触发")] public UnityEvent 进入事件; [Tooltip("物体停留在检测区域时持续触发")] public UnityEvent 停留事件; [Tooltip("物体离开检测区域时触发")] public UnityEvent 离开事件; [Header("网络同步")] [Tooltip("是否启用Photon网络同步")] public bool 启用网络同步 = true; [Tooltip("是否由服务器(MasterClient)控制事件触发")] public bool 服务器控制 = false; [Tooltip("网络事件同步冷却(秒),防止频繁发送")] public float 网络同步冷却 = 0.3f; [Header("高级设置")] [Tooltip("是否只触发一次")] public bool 只触发一次 = false; [Tooltip("触发冷却时间(秒),0表示无冷却")] public float 触发冷却 = 0f; [Tooltip("射线检测起点方向")] public Vector3 射线方向 = Vector3.forward; [Tooltip("射线检测最大距离")] public float 射线距离 = 10f; [Tooltip("检测频率(秒),Trigger和Raycast模式都生效")] public float 检测间隔 = 0.1f; [Header("调试")] public bool 显示调试 = false; private PhotonView photonView; private bool hasTriggered = false; private float lastTriggerTime = -999f; private float lastNetworkSyncTime = -999f; private float lastDetectTime = -999f; private bool isInside = false; private GameObject lastDetectedObject = null; private HashSet previousInsideObjects = new HashSet(); private void Awake() { photonView = ((Component)this).GetComponent(); if ((Object)(object)photonView == (Object)null && 启用网络同步) { Debug.LogWarning((object)("[LayerEventSystem] " + ((Object)((Component)this).gameObject).name + " 缺少PhotonView组件,网络同步将不可用")); } if (检测模式 == DetectionMode.Trigger && (Object)(object)触发碰撞体 == (Object)null) { 触发碰撞体 = ((Component)this).GetComponent(); } } private void Update() { if (!(Time.time - lastDetectTime < 检测间隔)) { lastDetectTime = Time.time; if (检测模式 == DetectionMode.Trigger) { UpdateTriggerDetect(); } else if (检测模式 == DetectionMode.Raycast) { UpdateRaycastDetect(); } } } private Collider GetDetectCollider() { if ((Object)(object)触发碰撞体 != (Object)null) { return 触发碰撞体; } return ((Component)this).GetComponent(); } private void UpdateTriggerDetect() { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) Collider detectCollider = GetDetectCollider(); if ((Object)(object)detectCollider == (Object)null) { return; } HashSet hashSet = new HashSet(); BoxCollider val = (BoxCollider)(object)((detectCollider is BoxCollider) ? detectCollider : null); Collider[] array; if (val != null) { Vector3 val2 = ((Component)val).transform.TransformPoint(val.center); Vector3 val3 = Vector3.Scale(val.size * 0.5f, ((Component)val).transform.lossyScale); array = Physics.OverlapBox(val2, val3, ((Component)val).transform.rotation, LayerMask.op_Implicit(检测图层)); } else { SphereCollider val4 = (SphereCollider)(object)((detectCollider is SphereCollider) ? detectCollider : null); if (val4 != null) { Vector3 val5 = ((Component)val4).transform.TransformPoint(val4.center); float num = val4.radius * Mathf.Max(new float[3] { ((Component)val4).transform.lossyScale.x, ((Component)val4).transform.lossyScale.y, ((Component)val4).transform.lossyScale.z }); array = Physics.OverlapSphere(val5, num, LayerMask.op_Implicit(检测图层)); } else { CapsuleCollider val6 = (CapsuleCollider)(object)((detectCollider is CapsuleCollider) ? detectCollider : null); if (val6 != null) { GetCapsulePoints(val6, out var p, out var p2, out var radius); array = Physics.OverlapCapsule(p, p2, radius, LayerMask.op_Implicit(检测图层)); } else { array = Physics.OverlapSphere(((Component)detectCollider).transform.position, 1f, LayerMask.op_Implicit(检测图层)); } } } Collider[] array2 = array; foreach (Collider val7 in array2) { hashSet.Add(((Component)val7).gameObject); } foreach (GameObject item in hashSet) { if (!previousInsideObjects.Contains(item)) { if (CanProcess()) { isInside = true; lastDetectedObject = item; MarkTriggered(); FireEnterEvent(item); } } else if (!只触发一次 || !hasTriggered) { UnityEvent obj = 停留事件; if (obj != null) { obj.Invoke(); } } } foreach (GameObject previousInsideObject in previousInsideObjects) { if (!hashSet.Contains(previousInsideObject)) { isInside = false; lastDetectedObject = null; UnityEvent obj2 = 离开事件; if (obj2 != null) { obj2.Invoke(); } SyncNetworkEvent("Exit", previousInsideObject); if (显示调试) { Debug.Log((object)("[LayerEventSystem] " + ((Object)((Component)this).gameObject).name + " 物体离开: " + ((Object)previousInsideObject).name)); } } } if (hashSet.Count == 0) { isInside = false; } previousInsideObjects = hashSet; } private void UpdateRaycastDetect() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) Vector3 val = ((Component)this).transform.TransformDirection(((Vector3)(ref 射线方向)).normalized); RaycastHit val2 = default(RaycastHit); bool flag = Physics.Raycast(((Component)this).transform.position, val, ref val2, 射线距离, LayerMask.op_Implicit(检测图层)); if (flag && !isInside) { if (CanProcess()) { isInside = true; lastDetectedObject = ((Component)((RaycastHit)(ref val2)).collider).gameObject; MarkTriggered(); FireEnterEvent(((Component)((RaycastHit)(ref val2)).collider).gameObject); } } else if (flag && isInside) { if (!只触发一次 || !hasTriggered) { UnityEvent obj = 停留事件; if (obj != null) { obj.Invoke(); } } } else if (!flag && isInside) { isInside = false; UnityEvent obj2 = 离开事件; if (obj2 != null) { obj2.Invoke(); } SyncNetworkEvent("Exit", null); lastDetectedObject = null; if (显示调试) { Debug.Log((object)("[LayerEventSystem] " + ((Object)((Component)this).gameObject).name + " 射线检测物体离开")); } } } private void GetCapsulePoints(CapsuleCollider capsule, out Vector3 p1, out Vector3 p2, out float radius) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) Transform transform = ((Component)capsule).transform; Vector3 val = transform.TransformPoint(capsule.center); Vector3 lossyScale = transform.lossyScale; float num = capsule.direction; float radius2 = capsule.radius; float height = capsule.height; float num2; Vector3 val2; if (num == 0f) { num2 = Mathf.Max(lossyScale.y, lossyScale.z); val2 = transform.right; } else if (num == 1f) { num2 = Mathf.Max(lossyScale.x, lossyScale.z); val2 = transform.up; } else { num2 = Mathf.Max(lossyScale.x, lossyScale.y); val2 = transform.forward; } radius = radius2 * num2; float num3 = height * 0.5f * ((num == 0f) ? lossyScale.x : ((num == 1f) ? lossyScale.y : lossyScale.z)); num3 = Mathf.Max(num3 - radius, 0f); p1 = val + val2 * num3; p2 = val - val2 * num3; } private void FireEnterEvent(GameObject obj) { UnityEvent obj2 = 进入事件; if (obj2 != null) { obj2.Invoke(); } SyncNetworkEvent("Enter", obj); if (显示调试) { Debug.Log((object)("[LayerEventSystem] " + ((Object)((Component)this).gameObject).name + " 检测到图层物体: " + ((Object)obj).name + " (Layer: " + LayerMask.LayerToName(obj.layer) + ")")); } } private bool CanProcess() { if (只触发一次 && hasTriggered) { return false; } if (触发冷却 > 0f && Time.time - lastTriggerTime < 触发冷却) { return false; } return true; } private void MarkTriggered() { hasTriggered = true; lastTriggerTime = Time.time; } private void SyncNetworkEvent(string eventType, GameObject target) { if (!启用网络同步 || !PhotonNetwork.IsConnected || (Object)(object)photonView == (Object)null || (服务器控制 && !PhotonNetwork.IsMasterClient) || Time.time - lastNetworkSyncTime < 网络同步冷却) { return; } lastNetworkSyncTime = Time.time; int num = 0; if ((Object)(object)target != (Object)null) { PhotonView component = target.GetComponent(); if ((Object)(object)component != (Object)null) { num = component.ViewID; } } photonView.RPC("RPC_SyncLayerEvent", (RpcTarget)1, new object[2] { eventType, num }); if (显示调试) { Debug.Log((object)("[LayerEventSystem] 发送网络事件: " + eventType)); } } [PunRPC] private void RPC_SyncLayerEvent(string eventType, int targetViewID) { switch (eventType) { case "Enter": { UnityEvent obj2 = 进入事件; if (obj2 != null) { obj2.Invoke(); } break; } case "Stay": { UnityEvent obj3 = 停留事件; if (obj3 != null) { obj3.Invoke(); } break; } case "Exit": { UnityEvent obj = 离开事件; if (obj != null) { obj.Invoke(); } break; } } if (显示调试) { Debug.Log((object)("[LayerEventSystem] 收到网络事件: " + eventType)); } } [PunRPC] public void RPC_SetDetectionLayer(int layerMask) { ((LayerMask)(ref 检测图层)).value = layerMask; } [PunRPC] public void RPC_SetEnabled(bool enabled) { ((Behaviour)this).enabled = enabled; } [PunRPC] public void RPC_ResetTrigger() { hasTriggered = false; lastTriggerTime = -999f; isInside = false; previousInsideObjects.Clear(); } public void ResetTrigger() { if (启用网络同步 && PhotonNetwork.IsConnected && (Object)(object)photonView != (Object)null) { photonView.RPC("RPC_ResetTrigger", (RpcTarget)0, Array.Empty()); return; } hasTriggered = false; lastTriggerTime = -999f; isInside = false; previousInsideObjects.Clear(); } public void SetDetectionLayer(LayerMask newLayer) { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) if (启用网络同步 && PhotonNetwork.IsConnected && (Object)(object)photonView != (Object)null) { photonView.RPC("RPC_SetDetectionLayer", (RpcTarget)0, new object[1] { ((LayerMask)(ref newLayer)).value }); } else { 检测图层 = newLayer; } } public void SetEnabled(bool enabled) { if (启用网络同步 && PhotonNetwork.IsConnected && (Object)(object)photonView != (Object)null) { photonView.RPC("RPC_SetEnabled", (RpcTarget)0, new object[1] { enabled }); } else { ((Behaviour)this).enabled = enabled; } } public bool IsInside() { return isInside; } public GameObject GetLastDetectedObject() { return lastDetectedObject; } private void OnDrawGizmos() { //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) Collider detectCollider = GetDetectCollider(); if ((Object)(object)detectCollider == (Object)null) { return; } if (检测模式 == DetectionMode.Trigger) { Color color = (isInside ? new Color(0f, 1f, 0f, 0.3f) : new Color(1f, 0.5f, 0f, 0.2f)); Color val = (Color)(isInside ? Color.green : new Color(1f, 0.5f, 0f, 0.6f)); Gizmos.color = color; Gizmos.matrix = ((Component)detectCollider).transform.localToWorldMatrix; BoxCollider val2 = (BoxCollider)(object)((detectCollider is BoxCollider) ? detectCollider : null); if (val2 != null) { Gizmos.DrawCube(val2.center, val2.size); Gizmos.color = val; Gizmos.DrawWireCube(val2.center, val2.size); return; } SphereCollider val3 = (SphereCollider)(object)((detectCollider is SphereCollider) ? detectCollider : null); if (val3 != null) { Gizmos.DrawSphere(val3.center, val3.radius); Gizmos.color = val; Gizmos.DrawWireSphere(val3.center, val3.radius); return; } CapsuleCollider val4 = (CapsuleCollider)(object)((detectCollider is CapsuleCollider) ? detectCollider : null); if (val4 != null) { DrawCapsuleGizmo(val4, val); } } else if (检测模式 == DetectionMode.Raycast) { Vector3 val5 = ((Component)this).transform.TransformDirection(((Vector3)(ref 射线方向)).normalized); Gizmos.color = Color.red; Gizmos.DrawRay(((Component)this).transform.position, val5 * 射线距离); Gizmos.color = new Color(1f, 0f, 0f, 0.3f); Gizmos.DrawSphere(((Component)this).transform.position + val5 * 射线距离, 0.15f); } } private void DrawCapsuleGizmo(CapsuleCollider capsule, Color wireColor) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) Vector3 center = capsule.center; float radius = capsule.radius; float num = capsule.height * 0.5f - radius; Gizmos.matrix = ((Component)capsule).transform.localToWorldMatrix; Gizmos.color = wireColor; Gizmos.DrawWireSphere(center + Vector3.up * num, radius); Gizmos.DrawWireSphere(center - Vector3.up * num, radius); } } public class MovePlatformTwoPoint : MonoBehaviourPunCallbacks { [Header("移动设置")] [Tooltip("移动速度")] public float 移动速度 = 2f; [Tooltip("移动力度(物理模式下生效)")] public float 移动力度 = 5f; [Tooltip("是否使用物理引擎")] public bool 使用物理 = false; [Header("位置设置")] [Tooltip("起点位置物体(绑定后使用物体位置)")] public Transform 起点物体; [Tooltip("终点位置物体(绑定后使用物体位置)")] public Transform 终点物体; [Tooltip("起点坐标(当起点物体为空时使用)")] public Vector3 起点坐标 = Vector3.zero; [Tooltip("终点坐标(当终点物体为空时使用)")] public Vector3 终点坐标 = new Vector3(0f, 0f, 2f); [Header("网络同步")] [Tooltip("是否启用网络同步")] public bool 启用网络同步 = true; [Tooltip("是否由服务器控制")] public bool 服务器控制 = true; private Rigidbody rb; private bool isMovingToEnd = true; private float moveProgress = 0f; private void Awake() { rb = ((Component)this).GetComponent(); if (使用物理 && (Object)(object)rb == (Object)null) { rb = ((Component)this).gameObject.AddComponent(); } if ((Object)(object)rb != (Object)null) { rb.useGravity = false; rb.isKinematic = !使用物理; } } private void Start() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)起点物体 != (Object)null) { 起点坐标 = 起点物体.position; } if ((Object)(object)终点物体 != (Object)null) { 终点坐标 = 终点物体.position; } ((Component)this).transform.position = 起点坐标; } private void Update() { if ((!启用网络同步 || !PhotonNetwork.IsConnected || !服务器控制 || PhotonNetwork.IsMasterClient) && !使用物理) { MoveLerp(); } } private void FixedUpdate() { if ((!启用网络同步 || !PhotonNetwork.IsConnected || !服务器控制 || PhotonNetwork.IsMasterClient) && 使用物理 && (Object)(object)rb != (Object)null) { MovePhysics(); } } private void MoveLerp() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) Vector3 val = (isMovingToEnd ? 起点坐标 : 终点坐标); Vector3 val2 = (isMovingToEnd ? 终点坐标 : 起点坐标); float num = Vector3.Distance(val, val2); if (num < 0.01f) { isMovingToEnd = !isMovingToEnd; return; } float num2 = 移动速度 / num; moveProgress += Time.deltaTime * num2; ((Component)this).transform.position = Vector3.Lerp(val, val2, moveProgress); if (moveProgress >= 1f) { isMovingToEnd = !isMovingToEnd; moveProgress = 0f; if (启用网络同步 && PhotonNetwork.IsConnected && (Object)(object)((MonoBehaviourPun)this).photonView != (Object)null && ((MonoBehaviourPun)this).photonView.ViewID != 0) { ((MonoBehaviourPun)this).photonView.RPC("RPC_SyncDirection", (RpcTarget)1, new object[1] { isMovingToEnd }); } } } private void MovePhysics() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) Vector3 val = (isMovingToEnd ? 终点坐标 : 起点坐标); Vector3 val2 = val - ((Component)this).transform.position; Vector3 normalized = ((Vector3)(ref val2)).normalized; float num = Vector3.Distance(((Component)this).transform.position, val); if (num < 0.1f) { isMovingToEnd = !isMovingToEnd; val = (isMovingToEnd ? 终点坐标 : 起点坐标); val2 = val - ((Component)this).transform.position; normalized = ((Vector3)(ref val2)).normalized; if (启用网络同步 && PhotonNetwork.IsConnected && (Object)(object)((MonoBehaviourPun)this).photonView != (Object)null && ((MonoBehaviourPun)this).photonView.ViewID != 0) { ((MonoBehaviourPun)this).photonView.RPC("RPC_SyncDirection", (RpcTarget)1, new object[1] { isMovingToEnd }); } } rb.linearVelocity = normalized * 移动速度; } [PunRPC] private void RPC_SyncDirection(bool movingToEnd) { isMovingToEnd = movingToEnd; moveProgress = 0f; } [PunRPC] private void RPC_SyncPosition(Vector3 position) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) ((Component)this).transform.position = position; } private void OnDrawGizmos() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) Vector3 val = (((Object)(object)起点物体 != (Object)null) ? 起点物体.position : 起点坐标); Vector3 val2 = (((Object)(object)终点物体 != (Object)null) ? 终点物体.position : 终点坐标); Gizmos.color = Color.blue; Gizmos.DrawSphere(val, 0.15f); Gizmos.color = Color.red; Gizmos.DrawSphere(val2, 0.15f); Gizmos.color = Color.yellow; Gizmos.DrawLine(val, val2); } } public class RotatingObject_Clean : MonoBehaviour { [Header("旋转设置")] [Tooltip("旋转速度,正数顺时针,负数逆时针")] public Vector3 rotationSpeed = new Vector3(0f, 30f, 0f); [Tooltip("旋转力度/强度,影响旋转的幅度或力量")] public float rotationForce = 1f; [Tooltip("是否启用物理旋转")] public bool usePhysicsRotation = false; [Header("物理设置(仅在使用物理旋转时生效)")] public float physicsTorque = 10f; private Rigidbody rb; private void Start() { if (usePhysicsRotation) { rb = ((Component)this).GetComponent(); if ((Object)(object)rb == (Object)null) { rb = ((Component)this).gameObject.AddComponent(); } rb.freezeRotation = false; } } private void Update() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) if (!usePhysicsRotation) { ((Component)this).transform.Rotate(rotationSpeed * rotationForce * Time.deltaTime); } } private void FixedUpdate() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) if (usePhysicsRotation && (Object)(object)rb != (Object)null) { Vector3 val = rotationSpeed * rotationForce * physicsTorque; rb.AddTorque(val); } } } public class RotatingObject_Network : MonoBehaviour { [Header("旋转设置")] [Tooltip("旋转速度,正数顺时针,负数逆时针")] public Vector3 rotationSpeed = new Vector3(0f, 30f, 0f); [Tooltip("旋转力度/强度,影响旋转的幅度或力量")] public float rotationForce = 1f; [Tooltip("是否启用物理旋转")] public bool usePhysicsRotation = false; [Header("网络同步设置")] [Tooltip("是否由服务器控制旋转(适用于场景物体)")] public bool serverControlled = true; [Tooltip("同步频率(秒)")] public float syncInterval = 0.1f; private Rigidbody rb; private float lastSyncTime; private PhotonView photonView; private void Awake() { photonView = ((Component)this).GetComponent(); rb = ((Component)this).GetComponent(); if ((Object)(object)photonView == (Object)null) { Debug.LogWarning((object)"RotatingObject_Network: PhotonView component not found! Disabling network features."); } } private void Start() { if (!usePhysicsRotation && (Object)(object)rb != (Object)null) { rb.isKinematic = true; } } private void Update() { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) bool flag = true; if (PhotonNetwork.IsConnected && serverControlled && !PhotonNetwork.IsMasterClient) { flag = false; } if (flag) { if (!usePhysicsRotation) { ((Component)this).transform.Rotate(rotationSpeed * rotationForce * Time.deltaTime); } if (PhotonNetwork.IsConnected && (Object)(object)photonView != (Object)null) { SyncRotation(); } } } private void FixedUpdate() { //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) bool flag = true; if (PhotonNetwork.IsConnected && serverControlled && !PhotonNetwork.IsMasterClient) { flag = false; } if (flag && usePhysicsRotation && (Object)(object)rb != (Object)null) { rb.AddTorque(rotationSpeed * rotationForce * Time.fixedDeltaTime); } } private void SyncRotation() { //IL_0095: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)photonView == (Object)null) && (!serverControlled || PhotonNetwork.IsMasterClient) && !((Object)(object)photonView == (Object)null) && photonView.ViewID != 0 && Time.time - lastSyncTime >= syncInterval) { lastSyncTime = Time.time; photonView.RPC("RPC_SyncRotation", (RpcTarget)1, new object[1] { ((Component)this).transform.eulerAngles }); } } [PunRPC] public void RPC_SyncRotation(Vector3 rotation) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) if (serverControlled || !photonView.IsMine) { ((Component)this).transform.eulerAngles = rotation; } } [PunRPC] public void RPC_SetRotationSpeed(Vector3 speed) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) rotationSpeed = speed; } [PunRPC] public void RPC_SetRotationForce(float force) { rotationForce = force; } public void SetRotationSpeed(Vector3 speed) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) if (PhotonNetwork.IsConnected && (Object)(object)photonView != (Object)null) { photonView.RPC("RPC_SetRotationSpeed", (RpcTarget)0, new object[1] { speed }); } else { rotationSpeed = speed; } } public void SetRotationForce(float force) { if (PhotonNetwork.IsConnected && (Object)(object)photonView != (Object)null) { photonView.RPC("RPC_SetRotationForce", (RpcTarget)0, new object[1] { force }); } else { rotationForce = force; } } } public class Spawner : MonoBehaviour { [Header("生成设置")] public GameObject 预制体; [Tooltip("生成位置(为空则用自身位置)")] public Transform 生成位置; [Tooltip("生成后是否为Kinematic刚体")] public bool 固定刚体 = false; [Header("事件")] [Tooltip("物体生成后触发")] public UnityEvent 生成事件; [Tooltip("生成时传递生成的GameObject")] public UnityEvent 生成事件_带参数; [Header("防重复设置")] [Tooltip("两次生成之间的最短间隔(秒),防止一帧内多次调用导致生成多个")] public float 生成间隔 = 1f; [Header("调试")] public bool 显示调试 = false; private float lastSpawnTime = -999f; public void Spawn() { //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)预制体 == (Object)null) { Debug.LogWarning((object)("[Spawner] " + ((Object)((Component)this).gameObject).name + " 预制体为空")); } else { if (Time.time - lastSpawnTime < 生成间隔) { return; } lastSpawnTime = Time.time; Vector3 val = (((Object)(object)生成位置 != (Object)null) ? 生成位置.position : ((Component)this).transform.position); Quaternion val2 = (((Object)(object)生成位置 != (Object)null) ? 生成位置.rotation : ((Component)this).transform.rotation); GameObject val3 = ((!PhotonNetwork.IsConnected) ? Object.Instantiate(预制体, val, val2) : PhotonNetwork.InstantiateItemRoom(((Object)预制体).name, val, val2)); if ((Object)(object)val3 == (Object)null) { Debug.LogError((object)("[Spawner] " + ((Object)((Component)this).gameObject).name + " 生成失败")); return; } if (固定刚体) { PhotonView component = val3.GetComponent(); if ((Object)(object)component != (Object)null && PhotonNetwork.IsConnected) { component.RPC("SetKinematicRPC", (RpcTarget)3, new object[3] { true, val, val2 }); } else { Rigidbody component2 = val3.GetComponent(); if ((Object)(object)component2 != (Object)null) { component2.isKinematic = true; } } } UnityEvent obj = 生成事件; if (obj != null) { obj.Invoke(); } 生成事件_带参数?.Invoke(val3); if (显示调试) { Debug.Log((object)("[Spawner] " + ((Object)((Component)this).gameObject).name + " 已生成: " + ((Object)val3).name)); } } } private void OnDrawGizmos() { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)预制体 != (Object)null) { Vector3 val = (((Object)(object)生成位置 != (Object)null) ? 生成位置.position : ((Component)this).transform.position); Gizmos.color = Color.blue; Gizmos.DrawWireSphere(val, 0.25f); Gizmos.DrawLine(val, val + Vector3.up * 1f); } } } public class TriggerMover : MonoBehaviourPunCallbacks { [Header("感应设置")] [Tooltip("感应碰撞体(必须设置)")] public Collider 感应碰撞体; [Tooltip("是否只感应玩家(否则感应所有带刚体的物体)")] public bool 只感应玩家 = true; [Tooltip("目标移动物体")] public Transform 目标物体; [Tooltip("绑定目标位置物体(为空则使用下方坐标)")] public Transform 目标位置物体; [Tooltip("目标位置坐标(当目标位置物体为空时使用)")] public Vector3 目标位置 = Vector3.zero; [Header("移动设置")] [Tooltip("移动速度")] public float 移动速度 = 2f; [Tooltip("移动距离(仅方向模式)")] public float 移动距离 = 2f; [Tooltip("移动方向(仅方向模式)")] public Vector3 移动方向 = Vector3.forward; [Header("模式设置")] [Tooltip("移动模式:0=方向模式,1=目标位置模式")] public int 移动模式 = 0; [Tooltip("移动类型:0=单次移动,1=来回移动")] public int 移动类型 = 0; [Header("网络同步")] [Tooltip("是否启用网络同步")] public bool 启用网络同步 = true; [Tooltip("是否由服务器控制")] public bool 服务器控制 = true; private Vector3 originalPosition; private bool isMoving = false; private bool isReturning = false; private float moveProgress = 0f; private void Awake() { if ((Object)(object)((MonoBehaviourPun)this).photonView == (Object)null) { Debug.LogWarning((object)"TriggerMover: PhotonView component not found!"); } if ((Object)(object)感应碰撞体 == (Object)null) { 感应碰撞体 = ((Component)this).GetComponent(); if ((Object)(object)感应碰撞体 == (Object)null) { Debug.LogError((object)"TriggerMover: 未设置感应碰撞体!"); } } if ((Object)(object)感应碰撞体 != (Object)null) { 感应碰撞体.isTrigger = true; } } private void Start() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)目标物体 != (Object)null) { originalPosition = 目标物体.position; } } private void Update() { if ((!启用网络同步 || !PhotonNetwork.IsConnected || !服务器控制 || PhotonNetwork.IsMasterClient) && isMoving && (Object)(object)目标物体 != (Object)null) { MoveObject(); } } private void OnTriggerEnter(Collider other) { if (!CanTrigger()) { return; } bool flag = false; if (只感应玩家) { if (((Component)other).CompareTag("Player")) { flag = true; } } else { Rigidbody component = ((Component)other).GetComponent(); if ((Object)(object)component != (Object)null) { flag = true; } } if (flag && !isMoving) { StartMovement(); } } private bool CanTrigger() { if (启用网络同步 && PhotonNetwork.IsConnected && 服务器控制 && !PhotonNetwork.IsMasterClient) { return false; } return true; } private void StartMovement() { isMoving = true; isReturning = false; moveProgress = 0f; if (启用网络同步 && PhotonNetwork.IsConnected && (Object)(object)((MonoBehaviourPun)this).photonView != (Object)null) { ((MonoBehaviourPun)this).photonView.RPC("RPC_StartMovement", (RpcTarget)1, Array.Empty()); } } [PunRPC] private void RPC_StartMovement() { isMoving = true; isReturning = false; moveProgress = 0f; } private void MoveObject() { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) moveProgress += Time.deltaTime * 移动速度 / 移动距离; Vector3 val = originalPosition; Vector3 val2 = GetTargetPosition(); if (isReturning) { Vector3 val3 = val; val = val2; val2 = val3; } 目标物体.position = Vector3.Lerp(val, val2, moveProgress); if (moveProgress >= 1f) { if (移动类型 == 1) { isReturning = !isReturning; moveProgress = 0f; } else { CheckAndReturn(); } } } private Vector3 GetTargetPosition() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)目标位置物体 != (Object)null) { return 目标位置物体.position; } if (移动模式 == 0) { return originalPosition + ((Vector3)(ref 移动方向)).normalized * 移动距离; } return 目标位置; } private void CheckAndReturn() { if (!CheckTriggerHasObject()) { isReturning = true; moveProgress = 0f; } else { isMoving = false; } } private bool CheckTriggerHasObject() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)感应碰撞体 == (Object)null) { return false; } Bounds bounds = 感应碰撞体.bounds; Vector3 center = ((Bounds)(ref bounds)).center; bounds = 感应碰撞体.bounds; Collider[] array = Physics.OverlapBox(center, ((Bounds)(ref bounds)).extents); Collider[] array2 = array; foreach (Collider val in array2) { if ((Object)(object)val == (Object)(object)感应碰撞体) { continue; } if (只感应玩家) { if (((Component)val).CompareTag("Player")) { return true; } } else if ((Object)(object)((Component)val).GetComponent() != (Object)null) { return true; } } return false; } [PunRPC] private void RPC_StopMovement() { isMoving = false; isReturning = false; moveProgress = 0f; } [PunRPC] private void RPC_SetTargetPosition(Vector3 pos) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) 目标位置 = pos; } private void OnDrawGizmosSelected() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)目标物体 != (Object)null) { Gizmos.color = Color.blue; Gizmos.DrawSphere(originalPosition, 0.1f); Gizmos.color = Color.green; Gizmos.DrawSphere(GetTargetPosition(), 0.1f); Gizmos.color = Color.yellow; Gizmos.DrawLine(originalPosition, GetTargetPosition()); } } } [BepInPlugin("NanJu.LevelUnityScripts", "Unity脚本插件", "1.0.0")] public class UnityScriptsPlugin : BaseUnityPlugin { private void Awake() { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Unity脚本插件已加载"); } } public static class PluginInfo { public const string PLUGIN_GUID = "NanJu.LevelUnityScripts"; public const string PLUGIN_NAME = "Unity脚本插件"; public const string PLUGIN_VERSION = "1.0.0"; } namespace MyStaff { public static class MyPluginInfo { public const string PLUGIN_GUID = "NanJu.LevelUnityScripts"; public const string PLUGIN_NAME = "MyStaff"; public const string PLUGIN_VERSION = "0.1.0"; } }