protected virtual void OnSceneGUI() { RadarMesh vmRadarMesh = (RadarMesh)target; if (vmRadarMesh.LocalPositions.Count < 3) { vmRadarMesh.ClearMesh(); return; } if (vmRadarMesh.DisplayHandles) { for (int i = 0; i < vmRadarMesh.LocalPositions.Count; i++) { EditorGUI.BeginChangeCheck(); Vector3 newTargetPosition = Handles.PositionHandle(vmRadarMesh.transform.TransformPoint(vmRadarMesh.LocalPositions[i]), vmRadarMesh.transform.rotation); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(vmRadarMesh, "mesh change"); vmRadarMesh.LocalPositions[i] = vmRadarMesh.transform.InverseTransformPoint(newTargetPosition); } } vmRadarMesh.RefreshMesh(); } }
void OnExitRange(Collider other, RadarMesh radar) { if (Detected.ContainsKey(other)) { Detected.Remove(other); } if (Visualized.ContainsKey(other)) { Visualized.Remove(other); } }
public override void OnInspectorGUI() { DrawDefaultInspector(); RadarMesh radarMesh = (RadarMesh)target; EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); if (GUILayout.Button("Edit Radar Mesh : " + radarMesh.DisplayHandles)) { Undo.RecordObject(radarMesh, "Edit Mesh"); radarMesh.DisplayHandles = !radarMesh.DisplayHandles; } }
void WhileInRange(Collider other, RadarMesh radar) { if (other.isTrigger) { return; } if (!other.enabled) { return; } if (CheckBlocked(other)) { if (Detected.ContainsKey(other)) { Detected.Remove(other); } if (Visualized.ContainsKey(other)) { Visualized.Remove(other); } return; } if (Detected.ContainsKey(other)) // update existing data { Detected[other].SensorPosition = transform.position; Detected[other].SensorAim = transform.forward; Detected[other].SensorRight = transform.right; Detected[other].SensorVelocity = GetSensorVelocity(); Detected[other].SensorAngle = GetSensorAngle(other); Detected[other].Position = other.bounds.center; Detected[other].Velocity = GetObjectVelocity(other); Detected[other].RelativePosition = other.bounds.center - transform.position; Detected[other].RelativeVelocity = GetSensorVelocity() - GetObjectVelocity(other); Detected[other].ColliderSize = other.bounds.size; Detected[other].State = GetAgentState(other); Detected[other].NewDetection = false; } else { Box box = GetVisualizationBox(other); if (box.Size != Vector3.zero) // Empty box returned if tag is not right { Visualized.Add(other, box); Detected.Add(other, new DetectedRadarObject() { Id = other.gameObject.GetInstanceID(), SensorPosition = transform.position, SensorAim = transform.forward, SensorRight = transform.right, SensorVelocity = GetSensorVelocity(), SensorAngle = GetSensorAngle(other), Position = other.bounds.center, Velocity = GetObjectVelocity(other), RelativePosition = other.bounds.center - transform.position, RelativeVelocity = GetSensorVelocity() - GetObjectVelocity(other), ColliderSize = other.bounds.size, State = GetAgentState(other), NewDetection = true, }); } } }
void OnExitRange(Collider other, RadarMesh radar) { OnExitRange(other); }