1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
| public class MovementUtility { private static Dictionary<GameObject, AudioSource[]> transformAudioSourceMap;
public static void DrawLineOfSight(Transform transform, Vector3 positionOffset, float fieldOfViewAngle, float angleOffset, float viewDistance, bool usePhysics2D) { }
private static AudioSource[] GetAudioSources(GameObject target) { bool flag = MovementUtility.transformAudioSourceMap == null; if (flag) { MovementUtility.transformAudioSourceMap = new Dictionary<GameObject, AudioSource[]>(); } AudioSource[] componentsInChildren; bool flag2 = MovementUtility.transformAudioSourceMap.TryGetValue(target, out componentsInChildren); AudioSource[] result; if (flag2) { result = componentsInChildren; } else { componentsInChildren = target.GetComponentsInChildren<AudioSource>(); MovementUtility.transformAudioSourceMap.Add(target, componentsInChildren); result = componentsInChildren; } return result; }
public static GameObject LineOfSight(Transform transform, Vector3 positionOffset, GameObject targetObject, Vector3 targetOffset, bool usePhysics2D, int ignoreLayerMask) { GameObject result; if (usePhysics2D) { RaycastHit2D raycastHit2D; bool flag = raycastHit2D = Physics2D.Linecast(transform.TransformPoint(positionOffset), targetObject.transform.TransformPoint(targetOffset), ~ignoreLayerMask); if (flag) { bool flag2 = raycastHit2D.transform.IsChildOf(targetObject.transform) || targetObject.transform.IsChildOf(raycastHit2D.transform); if (flag2) { result = targetObject; return result; } } } else { RaycastHit raycastHit;
bool flag3 = Physics.Linecast(transform.TransformPoint(positionOffset), targetObject.transform.TransformPoint(targetOffset), out raycastHit, ~ignoreLayerMask); if (flag3) { bool flag4 = raycastHit.transform.IsChildOf(targetObject.transform) || targetObject.transform.IsChildOf(raycastHit.transform); if (flag4) { result = targetObject; return result; } } } result = null; return result; }
public static GameObject WithinHearingRange2D(Transform transform, Vector3 positionOffset, float audibilityThreshold, float hearingRadius, LayerMask objectLayerMask) { GameObject result = null; Collider2D[] array = Physics2D.OverlapCircleAll(transform.TransformPoint(positionOffset), hearingRadius, objectLayerMask); bool flag = array != null; if (flag) { float num = 0f; for (int i = 0; i < array.Length; i++) { float num2 = 0f; GameObject gameObject; bool flag2 = (gameObject = MovementUtility.WithinHearingRange(transform, positionOffset, audibilityThreshold, array[i].gameObject, ref num2)) != null; if (flag2) { bool flag3 = num2 > num; if (flag3) { num = num2; result = gameObject; } } } } return result; }
public static GameObject WithinSight(Transform transform, Vector3 positionOffset, float fieldOfViewAngle, float viewDistance, LayerMask objectLayerMask, Vector3 targetOffset, LayerMask ignoreLayerMask) { GameObject result = null; Collider[] array = Physics.OverlapSphere(transform.position, viewDistance, objectLayerMask); bool flag = array != null; if (flag) { float num = float.PositiveInfinity; for (int i = 0; i < array.Length; i++) { float num2; GameObject gameObject; bool flag2 = (gameObject = MovementUtility.WithinSight(transform, positionOffset, fieldOfViewAngle, viewDistance, array[i].gameObject, targetOffset, false, 0f, out num2, ignoreLayerMask)) != null; if (flag2) { bool flag3 = num2 < num; if (flag3) { num = num2; result = gameObject; } } } } return result; }
public static GameObject WithinSight(Transform transform, Vector3 positionOffset, float fieldOfViewAngle, float viewDistance, GameObject targetObject, Vector3 targetOffset, LayerMask ignoreLayerMask) { float num; return MovementUtility.WithinSight(transform, positionOffset, fieldOfViewAngle, viewDistance, targetObject, targetOffset, false, 0f, out num, ignoreLayerMask); }
private static GameObject WithinSight(Transform transform, Vector3 positionOffset, float fieldOfViewAngle, float viewDistance, GameObject targetObject, Vector3 targetOffset, bool usePhysics2D, float angleOffset2D, out float angle, int ignoreLayerMask) { Vector3 vector = targetObject.transform.position - transform.TransformPoint(positionOffset); if (usePhysics2D) { angle = Vector3.Angle(vector, transform.up) + angleOffset2D; vector.z = 0f; } else { angle = Vector3.Angle(vector, transform.forward); vector.y = 0f; } bool flag = vector.magnitude < viewDistance && angle < fieldOfViewAngle * 0.5f; GameObject result; if (flag) { bool flag2 = MovementUtility.LineOfSight(transform, positionOffset, targetObject, targetOffset, usePhysics2D, ignoreLayerMask) != null; if (flag2) { result = targetObject; return result; } bool flag3 = targetObject.GetComponent<Collider>() == null && targetObject.GetComponent<Collider2D>() == null; if (flag3) { bool activeSelf = targetObject.gameObject.activeSelf; if (activeSelf) { result = targetObject; return result; } } } result = null; return result; }
public static GameObject WithinSight2D(Transform transform, Vector3 positionOffset, float fieldOfViewAngle, float viewDistance, LayerMask objectLayerMask, Vector3 targetOffset, float angleOffset2D, LayerMask ignoreLayerMask) { GameObject result = null; Collider2D[] array = Physics2D.OverlapCircleAll(transform.position, viewDistance, objectLayerMask); bool flag = array != null; if (flag) { float num = float.PositiveInfinity; for (int i = 0; i < array.Length; i++) { float num2; GameObject gameObject; bool flag2 = (gameObject = MovementUtility.WithinSight(transform, positionOffset, fieldOfViewAngle, viewDistance, array[i].gameObject, targetOffset, true, angleOffset2D, out num2, ignoreLayerMask)) != null; if (flag2) { bool flag3 = num2 < num; if (flag3) { num = num2; result = gameObject; } } } } return result; }
public static GameObject WithinSight2D(Transform transform, Vector3 positionOffset, float fieldOfViewAngle, float viewDistance, GameObject targetObject, Vector3 targetOffset, float angleOffset2D, LayerMask ignoreLayerMask) { float num; return MovementUtility.WithinSight(transform, positionOffset, fieldOfViewAngle, viewDistance, targetObject, targetOffset, true, angleOffset2D, out num, ignoreLayerMask); } }
|