/// <summary> /// Place selected object /// </summary> public void MoveObject() { GameObject obj; try { //Get selected object obj = selectObject.GetObject(); } catch (NullReferenceException) { SSTools.ShowMessage("No object selected", SSTools.Position.bottom, SSTools.Time.twoSecond); return; } //If move target is selected, switch to parent if (MoveTargetChecker.IsMoveTarget(obj)) { obj = obj.transform.parent.gameObject; } if (!HandChecker.HasHands(obj)) { SSTools.ShowMessage("No hands placed", SSTools.Position.bottom, SSTools.Time.twoSecond); return; } GameObject positionTarget; try { //Get move target positionTarget = obj.transform.Find("moveTarget").gameObject; } catch (NullReferenceException) { SSTools.ShowMessage("No move target defined", SSTools.Position.bottom, SSTools.Time.twoSecond); return; } //List for instructions List <MInstruction> list = new List <MInstruction>(); //Get IDs of objects String objectID = obj.GetComponent <MMISceneObject>().MSceneObject.ID; String targetPositionID = positionTarget.GetComponent <MMISceneObject>().MSceneObject.ID; //Instruction if both hands are present on object if (HandChecker.HasBothHands(obj)) { MInstruction moveObject = new MInstruction(MInstructionFactory.GenerateID(), "move object", "Object/Move") { Properties = PropertiesCreator.Create("SubjectID", objectID, "Hand", "Both", "TargetID", targetPositionID, CoSimTopic.OnStart, _carryIDManager.CurrentCarryIdBoth + ":" + CoSimAction.EndInstruction) }; list.Add(moveObject); } //Instruction if only right hand is present on object else if (HandChecker.HasRightHand(obj)) { MInstruction moveObject = new MInstruction(MInstructionFactory.GenerateID(), "move object", "Object/Move") { Properties = PropertiesCreator.Create("SubjectID", objectID, "Hand", "Right", "TargetID", targetPositionID, CoSimTopic.OnStart, _carryIDManager.CurrentCarryIdRight + ":" + CoSimAction.EndInstruction) }; list.Add(moveObject); } //Instruction if only left hand is present on object else if (HandChecker.HasLeftHand(obj)) { MInstruction moveObject = new MInstruction(MInstructionFactory.GenerateID(), "move object", "Object/Move") { Properties = PropertiesCreator.Create("SubjectID", objectID, "Hand", "Left", "TargetID", targetPositionID, CoSimTopic.OnStart, _carryIDManager.CurrentCarryIdLeft + ":" + CoSimAction.EndInstruction) }; list.Add(moveObject); } //Indicates that an object has been moved and thus the Carry Instruction is finished pickedUp = false; //Add instructions to queue queueController.AddItem(list, "Place " + obj.name); }
/// <summary> /// Pick up selected object /// </summary> public void PickUp() { GameObject obj; try { //Get selected object obj = selectObject.GetObject(); } catch (NullReferenceException) { SSTools.ShowMessage("No object selected", SSTools.Position.bottom, SSTools.Time.twoSecond); return; } //If move target is selected, switch to parent if (MoveTargetChecker.IsMoveTarget(obj)) { obj = obj.transform.parent.gameObject; } if (!HandChecker.HasHands(obj)) { SSTools.ShowMessage("No hands placed", SSTools.Position.bottom, SSTools.Time.twoSecond); return; } List <MInstruction> list = new List <MInstruction>(); //Get IDs of object String objID = obj.GetComponent <MMISceneObject>().MSceneObject.ID; //Instructions if both hands are present on object if (HandChecker.HasBothHands(obj)) { _carryIDManager.CurrentCarryIdBoth = MInstructionFactory.GenerateID(); MInstruction carryInstruction = new MInstruction(_carryIDManager.CurrentCarryIdBoth, "carry object", "Object/Carry") { Properties = PropertiesCreator.Create("TargetID", objID, "Hand", "Both") }; list.Add(carryInstruction); } //Instructions if only right hand is present on object else if (HandChecker.HasRightHand(obj)) { _carryIDManager.CurrentCarryIdRight = MInstructionFactory.GenerateID(); MInstruction carryInstruction = new MInstruction(_carryIDManager.CurrentCarryIdRight, "carry object", "Object/Carry") { Properties = PropertiesCreator.Create("TargetID", objID, "Hand", "Right"), }; list.Add(carryInstruction); } //Instructions if only left hand is present on object else if (HandChecker.HasLeftHand(obj)) { _carryIDManager.CurrentCarryIdLeft = MInstructionFactory.GenerateID(); MInstruction carryInstruction = new MInstruction(_carryIDManager.CurrentCarryIdLeft, "carry object", "Object/Carry") { Properties = PropertiesCreator.Create("TargetID", objID, "Hand", "Left"), }; list.Add(carryInstruction); } //Indicates that an object has been picked up, so it cannot be released pickedUp = true; //Add instructions to queue queueController.AddItem(list, "Pick up " + obj.name); }
/// <summary> /// Reach selected object /// </summary> public void ReachObject() { GameObject go; try { //Get selected object go = selectObject.GetObject(); } catch (NullReferenceException) { SSTools.ShowMessage("No object selected", SSTools.Position.bottom, SSTools.Time.twoSecond); return; } //If move target is selected, switch to parent if (MoveTargetChecker.IsMoveTarget(go)) { go = go.transform.parent.gameObject; } //Check for hands if (!HandChecker.HasHands(go)) { SSTools.ShowMessage("No hands placed", SSTools.Position.bottom, SSTools.Time.twoSecond); return; } //List of instructions List <MInstruction> list = new List <MInstruction>(); if (HandChecker.HasLeftHand(go)) { //Get UnitySceneAccess ID of hand //GameObject hand = go.transform.Find("LeftHand(Clone)").gameObject; GameObject hand = HandChecker.GetLeftHand(go); String objectID = hand.GetComponent <MMISceneObject>().MSceneObject.ID; //Now create a specific instruction to reach with the right hand MInstruction reachLeft = new MInstruction(MInstructionFactory.GenerateID(), "reach left", "Pose/Reach") { Properties = PropertiesCreator.Create("TargetID", objectID, "Hand", "Left") }; //Add instructions to list list.Add(reachLeft); list.AddRange(MakeHandPose(go, "Left")); } if (HandChecker.HasRightHand(go)) { //Get UnitySceneAccess ID of hand //GameObject hand = go.transform.Find("RightHand(Clone)").gameObject; GameObject hand = HandChecker.GetRightHand(go); String objectID = hand.GetComponent <MMISceneObject>().MSceneObject.ID; //Now create a specific instruction to reach with the right hand MInstruction reachRight = new MInstruction(MInstructionFactory.GenerateID(), "reach right", "Pose/Reach") { Properties = PropertiesCreator.Create("TargetID", objectID, "Hand", "Right") }; //Add instructions to list list.Add(reachRight); list.AddRange(MakeHandPose(go, "Right")); } //Add instruction to queue queueController.AddItem(list, "Reach " + go.name); }