Skip to content

Commit

Permalink
Merge pull request #786 from allenai/RemoveFromScene_Update
Browse files Browse the repository at this point in the history
Fix to RemoveFromScene objectId assignment
  • Loading branch information
mattdeitke authored Jun 17, 2021
2 parents 53ff17a + 25f6a5d commit 16d3007
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
24 changes: 23 additions & 1 deletion unity/Assets/Scripts/BaseFPSAgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,8 @@ public bool CheckIfAgentCanMove(
return true;
}

//TODO: May need to track enabled/disabled objecst separately since some
//actions loop through the ObjectIdTOSimObjPhysics dict and this may have adverse effects
public void DisableObject(string objectId) {
if (physicsSceneManager.ObjectIdToSimObjPhysics.ContainsKey(objectId)) {
physicsSceneManager.ObjectIdToSimObjPhysics[objectId].gameObject.SetActive(false);
Expand All @@ -1235,6 +1237,24 @@ public void DisableObject(string objectId) {
}
}

//TODO: May need to track enabled/disabled objecst separately since some
//actions loop through the ObjectIdTOSimObjPhysics dict and this may have adverse effects
public void DisableAllObjectsOfType(ServerAction action) {
string type = action.objectType;
if (type == "") {
type = action.objectId;
}

foreach (SimObjPhysics so in GameObject.FindObjectsOfType<SimObjPhysics>()) {
if (Enum.GetName(typeof(SimObjType), so.Type) == type) {
so.gameObject.SetActive(false);
}
}
actionFinished(true);
}

//TODO: May need to track enabled/disabled objecst separately since some
//actions loop through the ObjectIdTOSimObjPhysics dict and this may have adverse effects
public void EnableObject(string objectId) {
if (physicsSceneManager.ObjectIdToSimObjPhysics.ContainsKey(objectId)) {
physicsSceneManager.ObjectIdToSimObjPhysics[objectId].gameObject.SetActive(true);
Expand All @@ -1256,7 +1276,9 @@ public void RemoveFromScene(string objectId) {
// see if the object exists in this scene
if (physicsSceneManager.ObjectIdToSimObjPhysics.ContainsKey(objectId)) {
physicsSceneManager.ObjectIdToSimObjPhysics[objectId].transform.gameObject.SetActive(false);
physicsSceneManager.SetupScene();
//don't do a full scene setup to prevent overwriting already assigned objectIds
//TODO: More robust objectId system
physicsSceneManager.RemoveFromObjectsInScene(physicsSceneManager.ObjectIdToSimObjPhysics[objectId]);
actionFinished(true);
return;
}
Expand Down
16 changes: 1 addition & 15 deletions unity/Assets/Scripts/PhysicsRemoteFPSAgentController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright Allen Institute for Artificial Intelligence 2017
// Copyright Allen Institute for Artificial Intelligence 2017

using System;
using System.Collections;
Expand Down Expand Up @@ -7277,20 +7277,6 @@ public void ObjectsVisibleFromPositions(ServerAction action) {
actionFinished(true, objectIdToVisiblePositions);
}

public void DisableAllObjectsOfType(ServerAction action) {
string type = action.objectType;
if (type == "") {
type = action.objectId;
}

foreach (SimObjPhysics so in GameObject.FindObjectsOfType<SimObjPhysics>()) {
if (Enum.GetName(typeof(SimObjType), so.Type) == type) {
so.gameObject.SetActive(false);
}
}
actionFinished(true);
}

public void StackBooks() {
GameObject topLevelObject = GameObject.Find("HideAndSeek");
SimObjPhysics[] hideSeekObjects = topLevelObject.GetComponentsInChildren<SimObjPhysics>();
Expand Down

0 comments on commit 16d3007

Please sign in to comment.