private static void SaveEnvironmentInfo(string taskMessage, string correctedTaskMessage, string environmentName, bool isEnvironmentNameSent, string graspingTargetName, string destinationName, Dictionary <RelocatableObjectInfo, GameObject> graspablesPositionMap, Dictionary <RelocatableObjectInfo, GameObject> destinationsPositionsMap) { EnvironmentInfo environmentInfo = new EnvironmentInfo(); environmentInfo.taskMessage = taskMessage; environmentInfo.correctedTaskMessage = correctedTaskMessage; environmentInfo.environmentName = environmentName; environmentInfo.isEnvironmentNameSent = isEnvironmentNameSent; environmentInfo.graspingTargetName = graspingTargetName; environmentInfo.destinationName = destinationName; List <RelocatableObjectInfo> graspablesPositions = new List <RelocatableObjectInfo>(); foreach (KeyValuePair <RelocatableObjectInfo, GameObject> graspablePositionPair in graspablesPositionMap) { RelocatableObjectInfo graspableInfo = new RelocatableObjectInfo(); graspableInfo.name = graspablePositionPair.Value.name; graspableInfo.position = graspablePositionPair.Key.position; graspableInfo.eulerAngles = graspablePositionPair.Key.eulerAngles; graspablesPositions.Add(graspableInfo); } environmentInfo.graspablesPositions = graspablesPositions; List <RelocatableObjectInfo> destinationsPositions = new List <RelocatableObjectInfo>(); foreach (KeyValuePair <RelocatableObjectInfo, GameObject> destinationPositionPair in destinationsPositionsMap) { RelocatableObjectInfo destinationInfo = new RelocatableObjectInfo(); destinationInfo.name = destinationPositionPair.Value.name; destinationInfo.position = destinationPositionPair.Key.position; destinationInfo.eulerAngles = destinationPositionPair.Key.eulerAngles; destinationsPositions.Add(destinationInfo); } environmentInfo.destinationsPositions = destinationsPositions; string filePath = String.Format(Application.dataPath + EnvironmentInfoFileNameFormat, HandymanConfig.Instance.numberOfTrials); StreamWriter streamWriter = new StreamWriter(filePath, false, Encoding.UTF8); SIGVerseLogger.Info("Save Environment info. path=" + filePath); streamWriter.WriteLine(JsonUtility.ToJson(environmentInfo, true)); streamWriter.Flush(); streamWriter.Close(); }
public Dictionary <RelocatableObjectInfo, GameObject> CreateDestinationsPositionsMap() { Dictionary <RelocatableObjectInfo, GameObject> destinationsPositionsMap = new Dictionary <RelocatableObjectInfo, GameObject>(); for (int i = 0; i < this.destinationCandidates.Count; i++) { RelocatableObjectInfo destinationPositionInfo = new RelocatableObjectInfo(); destinationPositionInfo.name = this.destinationCandidates[i].name; destinationPositionInfo.position = this.destinationCandidates[i].transform.position; destinationPositionInfo.eulerAngles = this.destinationCandidates[i].transform.eulerAngles; destinationsPositionsMap.Add(destinationPositionInfo, this.destinationCandidates[i]); } return(destinationsPositionsMap); }
public Dictionary <RelocatableObjectInfo, GameObject> CreateGraspablesPositionMap() { List <GameObject> graspingCandidatesPositionsInBedRoom = new List <GameObject>(); List <GameObject> graspingCandidatesPositionsInKitchen = new List <GameObject>(); List <GameObject> graspingCandidatesPositionsInLiving = new List <GameObject>(); List <GameObject> graspingCandidatesPositionsInLobby = new List <GameObject>(); this.DeactivateGraspingCandidatesPositions(); foreach (GameObject graspingCandidatesPosition in this.graspingCandidatesPositions) { Vector3 position = graspingCandidatesPosition.transform.position; if (this.IsTargetInArea(position, this.bedRoomArea)) { graspingCandidatesPositionsInBedRoom.Add(graspingCandidatesPosition); } if (this.IsTargetInArea(position, this.kitchenArea)) { graspingCandidatesPositionsInKitchen.Add(graspingCandidatesPosition); } if (this.IsTargetInArea(position, this.livingArea)) { graspingCandidatesPositionsInLiving.Add(graspingCandidatesPosition); } if (this.IsTargetInArea(position, this.lobbyArea)) { graspingCandidatesPositionsInLobby.Add(graspingCandidatesPosition); } } // Shuffle the grasping candidates list this.graspables = this.graspables.OrderBy(i => Guid.NewGuid()).ToList(); // Shuffle the grasping candidates position list graspingCandidatesPositionsInBedRoom = graspingCandidatesPositionsInBedRoom.OrderBy(i => Guid.NewGuid()).ToList(); graspingCandidatesPositionsInKitchen = graspingCandidatesPositionsInKitchen.OrderBy(i => Guid.NewGuid()).ToList(); graspingCandidatesPositionsInLiving = graspingCandidatesPositionsInLiving.OrderBy(i => Guid.NewGuid()).ToList(); graspingCandidatesPositionsInLobby = graspingCandidatesPositionsInLobby.OrderBy(i => Guid.NewGuid()).ToList(); List <GameObject> graspingCandidatesPositionsTmp = new List <GameObject>(); for (int i = 0; graspingCandidatesPositionsTmp.Count < this.graspables.Count; i++) { if (graspingCandidatesPositionsInBedRoom.Count > i) { graspingCandidatesPositionsTmp.Add(graspingCandidatesPositionsInBedRoom[i]); } if (graspingCandidatesPositionsInKitchen.Count > i) { graspingCandidatesPositionsTmp.Add(graspingCandidatesPositionsInKitchen[i]); } if (graspingCandidatesPositionsInLiving.Count > i) { graspingCandidatesPositionsTmp.Add(graspingCandidatesPositionsInLiving[i]); } if (graspingCandidatesPositionsInLobby.Count > i) { graspingCandidatesPositionsTmp.Add(graspingCandidatesPositionsInLobby[i]); } } Dictionary <RelocatableObjectInfo, GameObject> graspingCandidatesMap = new Dictionary <RelocatableObjectInfo, GameObject>(); for (int i = 0; i < this.graspables.Count; i++) { RelocatableObjectInfo graspablePositionInfo = new RelocatableObjectInfo(); graspablePositionInfo.name = this.graspables[i].name; graspablePositionInfo.position = graspingCandidatesPositionsTmp[i].transform.position - new Vector3(0, graspingCandidatesPositionsTmp[i].transform.localScale.y * 0.49f, 0); graspablePositionInfo.eulerAngles = graspingCandidatesPositionsTmp[i].transform.eulerAngles; graspingCandidatesMap.Add(graspablePositionInfo, this.graspables[i]); } return(graspingCandidatesMap); }