private void Initialize(EnvironmentInfo environmentInfo, HandymanScoreManager scoreManager, AudioSource objectCollisionAudioSource) { List <GameObject> objectCollisionDestinations = new List <GameObject>(); objectCollisionDestinations.Add(scoreManager.gameObject); objectCollisionDestinations.Add(this.playbackRecorder.gameObject); foreach (GameObject graspable in this.graspables) { CollisionTransferer collisionTransferer = graspable.AddComponent <CollisionTransferer>(); collisionTransferer.Initialize(objectCollisionDestinations, Score.GetObjectCollisionVeloticyThreshold(), 0.1f, objectCollisionAudioSource); } Dictionary <RelocatableObjectInfo, GameObject> graspablesPositionMap = null; //key:GraspablePositionInfo, value:Graspables Dictionary <RelocatableObjectInfo, GameObject> destinationsPositionsMap = null; //key:DestinationPositionInfo, value:DestinationCandidate if (HandymanConfig.Instance.configFileInfo.isGraspableObjectsPositionRandom) { this.graspingTarget = this.DecideGraspingTarget(); this.destination = this.DecideDestination(); graspablesPositionMap = this.CreateGraspablesPositionMap(); destinationsPositionsMap = this.CreateDestinationsPositionsMap(); } else { this.DeactivateGraspingCandidatesPositions(); this.graspingTarget = (from graspable in this.graspables where graspable.name == environmentInfo.graspingTargetName select graspable).First(); if (this.graspingTarget == null) { throw new Exception("Grasping target not found. name=" + environmentInfo.graspingTargetName); } graspablesPositionMap = new Dictionary <RelocatableObjectInfo, GameObject>(); foreach (RelocatableObjectInfo graspablePositionInfo in environmentInfo.graspablesPositions) { GameObject graspableObj = (from graspable in this.graspables where graspable.name == graspablePositionInfo.name select graspable).First(); if (graspableObj == null) { throw new Exception("Graspable object not found. name=" + graspablePositionInfo.name); } graspablesPositionMap.Add(graspablePositionInfo, graspableObj); } // Destination object this.destination = (from destinationCandidate in this.destinationCandidates where destinationCandidate.name == environmentInfo.destinationName select destinationCandidate).First(); if (this.destination == null) { throw new Exception("Destination not found. name=" + environmentInfo.destinationName); } // Destination candidates position map destinationsPositionsMap = new Dictionary <RelocatableObjectInfo, GameObject>(); foreach (RelocatableObjectInfo destinationPositionInfo in environmentInfo.destinationsPositions) { GameObject destinationObj = (from destinationCandidate in this.destinationCandidates where destinationCandidate.name == destinationPositionInfo.name select destinationCandidate).First(); if (destinationObj == null) { throw new Exception("Destination candidate not found. name=" + destinationPositionInfo.name); } destinationsPositionsMap.Add(destinationPositionInfo, destinationObj); } } if (this.destination.tag != TagModerator) { // Add Placement checker to triggers Transform judgeTriggerOn = this.destination.transform.Find(JudgeTriggerNameOn); Transform judgeTriggerIn = this.destination.transform.Find(JudgeTriggerNameIn); if (judgeTriggerOn == null && judgeTriggerIn == null) { throw new Exception("No JudgeTrigger. name=" + this.destination.name); } if (judgeTriggerOn != null && judgeTriggerIn != null) { throw new Exception("Too many JudgeTrigger. name=" + this.destination.name); } if (judgeTriggerOn != null) { PlacementChecker placementChecker = judgeTriggerOn.gameObject.AddComponent <PlacementChecker>(); placementChecker.Initialize(PlacementChecker.JudgeType.On); } if (judgeTriggerIn != null) { PlacementChecker placementChecker = judgeTriggerIn.gameObject.AddComponent <PlacementChecker>(); placementChecker.Initialize(PlacementChecker.JudgeType.In); } } foreach (KeyValuePair <RelocatableObjectInfo, GameObject> pair in graspablesPositionMap) { pair.Value.transform.position = pair.Key.position; pair.Value.transform.eulerAngles = pair.Key.eulerAngles; // Debug.Log(pair.Key.name + " : " + pair.Value.name); } foreach (KeyValuePair <RelocatableObjectInfo, GameObject> pair in destinationsPositionsMap) { pair.Value.transform.position = pair.Key.position; pair.Value.transform.eulerAngles = pair.Key.eulerAngles; // Debug.Log(pair.Key.name + " : " + pair.Value.name); } this.targetRoom = this.GetTargetRoom(); if (HandymanConfig.Instance.configFileInfo.isGraspableObjectsPositionRandom) { this.taskMessage = this.CreateTaskMessage(); this.correctedTaskMessage = string.Empty; this.isEnvironmentNameSent = true; } else { this.taskMessage = environmentInfo.taskMessage; this.correctedTaskMessage = environmentInfo.correctedTaskMessage; this.isEnvironmentNameSent = environmentInfo.isEnvironmentNameSent; } if (HandymanConfig.Instance.configFileInfo.isGraspableObjectsPositionRandom) { SaveEnvironmentInfo(this.taskMessage, this.correctedTaskMessage, this.environmentName, this.isEnvironmentNameSent, this.graspingTarget.name, this.destination.name, graspablesPositionMap, destinationsPositionsMap); } this.rosConnections = SIGVerseUtils.FindObjectsOfInterface <IRosConnection>(); SIGVerseLogger.Info("ROS connection : count=" + this.rosConnections.Length); // Set up the voice (Using External executable file) this.speechProcess = new System.Diagnostics.Process(); this.speechProcess.StartInfo.FileName = Application.dataPath + "/" + SpeechExePath; this.speechProcess.StartInfo.CreateNoWindow = true; this.speechProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; this.isSpeechUsed = System.IO.File.Exists(this.speechProcess.StartInfo.FileName); this.speechInfoQue = new Queue <SpeechInfo>(); SIGVerseLogger.Info("Text-To-Speech: " + Application.dataPath + "/" + SpeechExePath); this.isPlacementSucceeded = null; }
private void GetGameObjects(EnvironmentInfo environmentInfo, GameObject avatarMotionPlayback, GameObject worldPlayback) { this.robot = GameObject.FindGameObjectWithTag(TagRobot); this.hsrBaseFootPrint = SIGVerseUtils.FindTransformFromChild(this.robot.transform, HSRCommon.Link.base_footprint.ToString()); this.hsrGraspingDetector = this.robot.GetComponentInChildren <GraspingDetector>(); GameObject moderatorObj = GameObject.FindGameObjectWithTag(TagModerator); // Get grasping candidates this.graspingCandidates = this.ExtractGraspingCandidates(environmentInfo); // List<GameObject> dummyGraspingCandidates = GameObject.FindGameObjectsWithTag(TagDummyGraspingCandidates).ToList<GameObject>(); this.graspables = new List <GameObject>(); this.graspables.AddRange(this.graspingCandidates); // this.graspables.AddRange(dummyGraspingCandidates); // Check the name conflict of graspables. if (this.graspables.Count != (from graspable in this.graspables select graspable.name).Distinct().Count()) { throw new Exception("There is the name conflict of graspable objects."); } SIGVerseLogger.Info("Count of Graspables = " + this.graspables.Count); this.bedRoomArea = GameObject.Find(this.environmentName + "/RoomArea/" + AreaNameBedRoom); this.kitchenArea = GameObject.Find(this.environmentName + "/RoomArea/" + AreaNameKitchen); this.livingArea = GameObject.Find(this.environmentName + "/RoomArea/" + AreaNameLiving); this.lobbyArea = GameObject.Find(this.environmentName + "/RoomArea/" + AreaNameLobby); // Get grasping candidates positions this.graspingCandidatesPositions = GameObject.FindGameObjectsWithTag(TagGraspingCandidatesPosition).ToList <GameObject>(); if (this.graspables.Count > this.graspingCandidatesPositions.Count) { throw new Exception("graspables.Count(" + this.graspables.Count + ") > graspingCandidatesPositions.Count(" + this.graspingCandidatesPositions.Count + "). Layout=" + this.environmentName); } else { SIGVerseLogger.Info("Count of GraspingCandidatesPosition = " + this.graspingCandidatesPositions.Count); } this.destinationCandidates = GameObject.FindGameObjectsWithTag(TagDestinationCandidates).ToList <GameObject>(); this.destinationCandidates.Add(moderatorObj); // Treat moderator as a destination candidate if (this.destinationCandidates.Count == 0) { throw new Exception("Count of DestinationCandidates is zero."); } // Check the name conflict of destination candidates. if (this.destinationCandidates.Count != (from destinations in this.destinationCandidates select destinations.name).Distinct().Count()) { throw new Exception("There is the name conflict of destination candidates objects."); } SIGVerseLogger.Info("Count of Destinations = " + this.destinationCandidates.Count); this.avatarMotionPlayer = avatarMotionPlayback.GetComponent <HandymanAvatarMotionPlayer>(); this.avatarMotionRecorder = avatarMotionPlayback.GetComponent <HandymanAvatarMotionRecorder>(); this.playbackRecorder = worldPlayback.GetComponent <HandymanPlaybackRecorder>(); this.playbackRecorder.SetEnvironmentName(this.environmentName); }