/// <summary> /// Remove all default Actors that doesn't exist in data /// </summary> private void ClearUnusedDefaultInputs(LiveFrame_v4 frame) { if (actors != null) { foreach (Actor actor in new List <Actor>((IEnumerable <Actor>)actors.Values)) { // Don't remove idle demo if (actor.profileName == ACTOR_DEMO_IDLE_NAME) { continue; } if (!frame.HasProfile(actor.profileName)) { actors.Remove(actor.profileName); } } } if (props != null) { foreach (Prop prop in new List <Prop>((IEnumerable <Prop>)props.Values)) { if (!frame.HasProp(prop.propName)) { props.Remove(prop.propName); } } } }
private void StudioReceiver_onStudioDataReceived(object sender, LiveFrame_v4 e) { // Process in Unity thread RunOnMainThread(() => { ProcessLiveFrame(e); }); }
/// <summary> /// Remove all rows that no longer exists in live data /// </summary> private void ClearUnusedInputRows(LiveFrame_v4 frame) { foreach (InputHierarchyRow row in new List <InputHierarchyRow>((IEnumerable <InputHierarchyRow>)rows.Values)) { if (!frame.HasProfile(row.profileName) && !frame.HasProp(row.profileName)) { rows.Remove(row.profileName); } } }
/// <summary> /// Check if prop name is present in live data /// </summary> public static bool HasProp(this LiveFrame_v4 frame, string propName) { for (int i = 0; i < frame.scene.props.Length; i++) { if (frame.scene.props[i].name == propName) { return(true); } } return(false); }
/// <summary> /// Main process logic of live data /// </summary> private void ProcessLiveFrame(LiveFrame_v4 frame) { // Update each actor from live data for (int i = 0; i < frame.scene.actors.Length; i++) { ActorFrame actorFrame = frame.scene.actors[i]; List <Actor> actorOverrides = GetActorOverride(actorFrame.name); // Update custom actors if any if (actorOverrides.Count > 0) { for (int a = 0; a < actorOverrides.Count; a++) { actorOverrides[a].UpdateActor(actorFrame); } } // Update default actor else if (autoGenerateInputsWhenNoOverridesFound && actors != null) { actors[actorFrame.name].UpdateActor(actorFrame); } } // Update each prop from live data for (int i = 0; i < frame.scene.props.Length; i++) { PropFrame propFrame = frame.scene.props[i]; List <Prop> propOverrides = GetPropOverride(propFrame.name); // Update custom props if any if (propOverrides.Count > 0) { for (int a = 0; a < propOverrides.Count; a++) { propOverrides[a].UpdateProp(propFrame); } } // Update default prop else if (autoGenerateInputsWhenNoOverridesFound && props != null) { props[propFrame.name].UpdateProp(propFrame); } } // Remove all default Actors that doesn't exist in data ClearUnusedDefaultInputs(frame); // Show default character UpdateDefaultActorWhenIdle(); // Update Hierarchy UI uiManager?.UpdateHierarchy(frame); }
public void UpdateHierarchy(LiveFrame_v4 dataFrame) { // Check if UI needs rebuild bool forceLayoutUpdate = false; // Update each actor from live data for (int i = 0; i < dataFrame.scene.actors.Length; i++) { ActorFrame actorFrame = dataFrame.scene.actors[i]; string profileName = actorFrame.name; // If profile doesn't exist, mark for rebuild if (forceLayoutUpdate == false && !rows.ContainsKey(profileName)) { forceLayoutUpdate = true; } rows[profileName].UpdateRow(actorFrame); } // Update each prop from live data for (int i = 0; i < dataFrame.scene.props.Length; i++) { PropFrame propFrame = dataFrame.scene.props[i]; string profileName = propFrame.name; // If profile doesn't exist, mark for rebuild if (forceLayoutUpdate == false && !rows.ContainsKey(profileName)) { forceLayoutUpdate = true; } rows[profileName].UpdateRow(propFrame); } ClearUnusedInputRows(dataFrame); if (forceLayoutUpdate) { LayoutRebuilder.ForceRebuildLayoutImmediate(prefabContainer as RectTransform); } }