protected bool CheckVisibility(StoryboardData data, StoryboardNode currentnode, Vector3 finalPosition, Quaternion finalRotation, SimulationTargetData targetData) { ProxySet proxySet = data.m_proxySets[currentnode.m_index]; if (proxySet.CheckIfContains(finalPosition)) { return(false); } RaycastHit hit; Vector3 dir = (targetData.m_targetPosition - finalPosition); if (Physics.SphereCast(finalPosition, data.m_visibilityCapsuleRadius, dir.normalized, out hit, dir.magnitude)) { if (targetData.m_target != null && hit.transform == targetData.m_target) { return(true); } else if (targetData.m_target != null && hit.transform != targetData.m_target) { return(Vector3.Distance(hit.point, targetData.m_target.position) < data.m_visibilityContactThreshold); } else if (targetData.m_target == null) { return(Vector3.Distance(hit.point, targetData.m_targetPosition) < data.m_visibilityContactThreshold); } else { return(false); } } return(true); }
public IEnumerator CalculateSceneProxies(StoryboardWindow window, StoryboardData data, TimelineAsset timeline, PlayableDirector playable, Vector3 position, Vector3 sceneProxyBounds) { data.m_proxySets.Clear(); IEnumerable <IMarker> markers = timeline.markerTrack.GetMarkers(); markers = markers.OrderBy(a => a.time); IEnumerator markersIt = markers.GetEnumerator(); while (markersIt.MoveNext()) { if (markersIt.Current is StoryboardMarker marker) { playable.time = marker.m_jumpsToTime ? marker.m_jumpTime : marker.time; playable.Evaluate(); yield return(null); ProxySet set = new ProxySet(); set.m_proxies = new List <Proxy>(); Collider[] colliders = Physics.OverlapBox(position, sceneProxyBounds / 2.0f); for (int i = 0; i < colliders.Length; i++) { Proxy proxy = new Proxy(); Collider col = colliders[i]; proxy.m_collider = colliders[i]; proxy.m_gameObjectID = proxy.m_collider.gameObject.GetInstanceID().ToString(); set.m_proxies.Add(proxy); } yield return(null); set.m_marker = marker; data.m_proxySets.Add(set); } } playable.time = 0.0; playable.Evaluate(); window.OnProxyCalculationEnd(); }
private void DrawSceneProxyProperties() { EditorGUILayout.BeginVertical("GroupBox"); EditorGUILayout.LabelField("Scene Proxy", m_resources.m_smallLabel); EditorGUILayout.Space(5); EditorGUILayout.HelpBox("Proxy set calculations are session based, meaning they won't be serialized and will not survive scene changes or editor restarts.", MessageType.Info); m_proxyBounds = EditorGUILayout.Vector3Field("Bounds", m_proxyBounds); EditorGUILayout.BeginHorizontal(); if (m_shouldDisableButtons) { GUI.enabled = false; } if (GUILayout.Button("Calculate Proxy")) { if (Progress.Exists(m_proxyProgressID)) { Progress.Cancel(m_proxyProgressID); EditorCoroutineUtility.StopCoroutine(m_proxyCalculationRoutine); } m_proxyCalculationRoutine = EditorCoroutineUtility.StartCoroutineOwnerless(m_simulator.CalculateSceneProxies(this, m_storyboardData, m_timeline, m_playableDirector, m_sceneProxy.transform.position, m_proxyBounds)); m_displayProxyProgressBar = true; m_proxyProgressID = Progress.Start("Calculating proxy sets...", "proxy"); } if (m_shouldDisableButtons) { GUI.enabled = true; } if (GUILayout.Button("Clear Proxy Sets")) { m_proxySetToDraw = 0; if (Progress.Exists(m_proxyProgressID)) { Progress.Cancel(m_proxyProgressID); EditorCoroutineUtility.StopCoroutine(m_proxyCalculationRoutine); } m_storyboardData.m_proxySets.Clear(); m_playableDirector.time = 0; m_playableDirector.Evaluate(); } m_markerCount = m_simulator.GetTimelineMarkerCount(m_timeline); m_proxiesValid = m_storyboardData.m_proxySets.Count == m_markerCount; if (m_displayProxyProgressBar) { Progress.Report(m_proxyProgressID, (float)m_storyboardData.m_proxySets.Count / (float)m_markerCount, "Calculating proxy sets..."); } EditorGUILayout.EndHorizontal(); Handles.color = Color.white; Handles.DrawWireCube(m_sceneProxy.transform.position, m_proxyBounds); // Invalidate sets if colliders are not found. for (int i = 0; i < m_storyboardData.m_proxySets.Count; i++) { ProxySet set = m_storyboardData.m_proxySets[i]; for (int j = 0; j < set.m_proxies.Count; j++) { Proxy proxy = set.m_proxies[j]; if (proxy.m_collider == null) { set.m_proxies.RemoveAt(j); } } if (set.m_proxies.Count == 0) { m_storyboardData.m_proxySets.RemoveAt(i); } } m_visualizeProxyBoundaries = EditorGUILayout.Toggle("Visualize Boundaries", m_visualizeProxyBoundaries); if (m_storyboardData.m_proxySets.Count > 0) { m_visualizeProxyCollisions = EditorGUILayout.Toggle("Visualize Collisions", m_visualizeProxyCollisions); if (m_visualizeProxyCollisions) { m_proxySetToDraw = EditorGUILayout.IntSlider("Set to Draw", m_proxySetToDraw, 0, m_storyboardData.m_proxySets.Count - 1); m_visualizeEvaluateTimeline = EditorGUILayout.Toggle("Evaluate Timeline", m_visualizeEvaluateTimeline); if (m_visualizeEvaluateTimeline) { StoryboardMarker marker = m_storyboardData.m_proxySets[m_proxySetToDraw].m_marker; m_playableDirector.time = marker.m_jumpsToTime ? marker.m_jumpTime : marker.time; m_playableDirector.Evaluate(); } } } GUIStyle labelStyle = new GUIStyle(); if (m_storyboardData.m_proxySets.Count != m_markerCount) { labelStyle.normal.textColor = Color.yellow; } else { labelStyle.normal.textColor = Color.green; } GUILayout.Label(m_storyboardData.m_proxySets.Count + " proxy sets are calculated out of " + m_markerCount + " markers.", labelStyle); EditorGUILayout.EndVertical(); }