From f1a163746808b15db4eefba6d16b17a09089dd6a Mon Sep 17 00:00:00 2001 From: lucaw Date: Thu, 9 Jun 2022 10:09:56 -0700 Subject: [PATCH 1/4] Attempting a fix to call to addAgents. --- unity/Assets/Scripts/AgentManager.cs | 48 +++++++++++++++------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/unity/Assets/Scripts/AgentManager.cs b/unity/Assets/Scripts/AgentManager.cs index a08f66df6d..5bf449ccce 100644 --- a/unity/Assets/Scripts/AgentManager.cs +++ b/unity/Assets/Scripts/AgentManager.cs @@ -283,9 +283,15 @@ public void Initialize(ServerAction action) { //this will need a rework to make multi agent work as GetReachablePositions is used to position additional //agents, which won't work if we initialize the agent(s) before the scene exists string sceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; - if (!sceneName.StartsWith("Procedural")) { - StartCoroutine(addAgents(action)); + + addAgents(action); + this.agents[0].m_Camera.depth = 9999; + if (action.startAgentsRotatedBy != 0f) { + RotateAgentsByRotatingUniverse(action.startAgentsRotatedBy); + } else { + ResetSceneBounds(); } + this.agentManagerState = AgentState.ActionComplete; } private void SetUpLocobotController(ServerAction action) { @@ -348,28 +354,24 @@ public BaseFPSAgentController PrimaryAgent { get => this.primaryAgent; } - private IEnumerator addAgents(ServerAction action) { - yield return null; - Vector3[] reachablePositions = primaryAgent.getReachablePositions(2.0f); - for (int i = 1; i < action.agentCount && this.agents.Count < Math.Min(agentColors.Length, action.agentCount); i++) { - action.x = reachablePositions[i + 4].x; - action.y = reachablePositions[i + 4].y; - action.z = reachablePositions[i + 4].z; - addAgent(action); - yield return null; // must do this so we wait a frame so that when we CapsuleCast we see the most recently added agent - } - for (int i = 0; i < this.agents.Count; i++) { - this.agents[i].m_Camera.depth = 1; - } - this.agents[0].m_Camera.depth = 9999; - - if (action.startAgentsRotatedBy != 0f) { - RotateAgentsByRotatingUniverse(action.startAgentsRotatedBy); - } else { - ResetSceneBounds(); + private void addAgents(ServerAction action) { + if (action.agentCount > 1) { + if (sceneName.StartsWith("Procedural")) { + throw new NotImplementedException($"Procedural scenes only support a single agent currently."); + } + Physics.SyncTransforms(); + Vector3[] reachablePositions = primaryAgent.getReachablePositions(2.0f); + for (int i = 1; i < action.agentCount && this.agents.Count < Math.Min(agentColors.Length, action.agentCount); i++) { + action.x = reachablePositions[i + 4].x; + action.y = reachablePositions[i + 4].y; + action.z = reachablePositions[i + 4].z; + addAgent(action); + Physics.SyncTransforms(); // must do this so that when we CapsuleCast we see the most recently added agent + } + for (int i = 1; i < this.agents.Count; i++) { + this.agents[i].m_Camera.depth = 1; + } } - - this.agentManagerState = AgentState.ActionComplete; } public void ResetSceneBounds() { From 5e88b7320124823106b25503226e06b1968a3f49 Mon Sep 17 00:00:00 2001 From: lucaw Date: Thu, 9 Jun 2022 10:30:09 -0700 Subject: [PATCH 2/4] Typo. --- unity/Assets/Scripts/AgentManager.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/unity/Assets/Scripts/AgentManager.cs b/unity/Assets/Scripts/AgentManager.cs index 5bf449ccce..26a27c89ca 100644 --- a/unity/Assets/Scripts/AgentManager.cs +++ b/unity/Assets/Scripts/AgentManager.cs @@ -276,14 +276,8 @@ public void Initialize(ServerAction action) { if (action.alwaysReturnVisibleRange) { ((PhysicsRemoteFPSAgentController)primaryAgent).alwaysReturnVisibleRange = action.alwaysReturnVisibleRange; } - //if multi agent requested, add duplicates of primary agent now - //note: for Houses, adding multiple agents in will need to be done differently as currently - //initializing additional agents assumes the scene is already setup, and Houses initialize the - //primary agent floating in space, then generates the house, then teleports the primary agent. - //this will need a rework to make multi agent work as GetReachablePositions is used to position additional - //agents, which won't work if we initialize the agent(s) before the scene exists - string sceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; + //if multi agent requested, add duplicates of primary agent now addAgents(action); this.agents[0].m_Camera.depth = 9999; if (action.startAgentsRotatedBy != 0f) { @@ -356,9 +350,15 @@ public BaseFPSAgentController PrimaryAgent { private void addAgents(ServerAction action) { if (action.agentCount > 1) { - if (sceneName.StartsWith("Procedural")) { + // note: for procedural scenes, adding multiple agents in will need to be done differently as currently + // initializing additional agents assumes the scene is already setup, and Houses initialize the + // primary agent floating in space, then generates the house, then teleports the primary agent. + // this will need a rework to make multi agent work as GetReachablePositions is used to position additional + // agents, which won't work if we initialize the agent(s) before the scene exists + if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.StartsWith("Procedural")) { throw new NotImplementedException($"Procedural scenes only support a single agent currently."); } + Physics.SyncTransforms(); Vector3[] reachablePositions = primaryAgent.getReachablePositions(2.0f); for (int i = 1; i < action.agentCount && this.agents.Count < Math.Min(agentColors.Length, action.agentCount); i++) { From c625abe878effa529b391b9d015960a2c245701d Mon Sep 17 00:00:00 2001 From: lucaw Date: Thu, 9 Jun 2022 11:23:31 -0700 Subject: [PATCH 3/4] Not including all scenes. --- unity/Assets/Editor/Build.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unity/Assets/Editor/Build.cs b/unity/Assets/Editor/Build.cs index 30dc4c8c43..5be702f26e 100644 --- a/unity/Assets/Editor/Build.cs +++ b/unity/Assets/Editor/Build.cs @@ -121,7 +121,7 @@ private static List GetAllScenePaths() { } // uncomment for faster builds for testing - return scenes; //.Where(x => x.Contains("FloorPlan1_") || x.Contains("Procedural")).ToList(); + return scenes.Where(x => x.Contains("FloorPlan") || x.Contains("Procedural.unity")).ToList(); //.Where(x => x.Contains("FloorPlan1_") || x.Contains("Procedural")).ToList(); } private static List GetScenesFromEnv() { From 2c5a5c6fa78ef769be4fff2b46e6e93e00a60915 Mon Sep 17 00:00:00 2001 From: lucaw Date: Thu, 9 Jun 2022 14:15:11 -0700 Subject: [PATCH 4/4] Reverting to include all scenes. --- unity/Assets/Editor/Build.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unity/Assets/Editor/Build.cs b/unity/Assets/Editor/Build.cs index 5be702f26e..f3e63fb0b6 100644 --- a/unity/Assets/Editor/Build.cs +++ b/unity/Assets/Editor/Build.cs @@ -121,7 +121,7 @@ private static List GetAllScenePaths() { } // uncomment for faster builds for testing - return scenes.Where(x => x.Contains("FloorPlan") || x.Contains("Procedural.unity")).ToList(); //.Where(x => x.Contains("FloorPlan1_") || x.Contains("Procedural")).ToList(); + return scenes; //.Where(x => x.Contains("FloorPlan") || x.Contains("Procedural.unity")).ToList(); //.Where(x => x.Contains("FloorPlan1_") || x.Contains("Procedural")).ToList(); } private static List GetScenesFromEnv() {