public override void OnTargetReached(Transform target) { base.OnTargetReached(target); if (InteractionTarget != null) { InteractionTarget.Interact(); } }
public YieldResult Interact(Interaction interaction) { if (InteractionTarget.Interact(interaction, human, InteractionInfo.issuedByAI)) { return(YieldResult.Continue); } else { return(YieldResult.Failed); } }
private void OnInteractionTargetChanged(InteractionTarget target) { if (target == null) { _useTextShown = false; } else { _textComponent.SetText($"(E) " + target.ActionDisplay); _useTextShown = true; } }
public IEnumerable <YieldResult> New_TendToFields() { Furniture furniture = InteractionTarget.GetPrimaryHolder <Furniture>(); SoilModule soilModule = furniture.GetModule <SoilModule>(); foreach (var interaction in soilModule.GetInteractions(human, InteractionInfo.issuedByAI, false)) { if (interaction.interaction == Interaction.RemoveInfestedPlants || interaction.interaction == Interaction.RemovePlant || interaction.interaction == Specialization.TendToFieldsInteraction) { continue; } if (interaction.interaction == Interaction.WaterPlant) { if (!soilModule.GetSeasons().Contains(SeasonManager.GetCurrentSeason())) { continue; } //InteractionRestrictionCanTakeResourceNearby cheat. we don't check the distance if (!WorldScripts.Instance.furnitureFactory.GetModules <InventoryReplenishmentModule>().Any(x => x.GetResource() == Resource.Water)) { continue; } //InteractionRestrictionEquipmentEffect cheat. we don't check the distance if (!human.equipmentSet.GetEffects().Any(x => x.first == EquipmentEffect.WateringPlants)) { continue; } } else if (!WorkInteractionControllerPatch.CheckInteraction(InteractionTarget, interaction, human)) { continue; } subTask = new YieldMicroInteraction(new InteractionInfo( interaction.interaction, InteractionTarget, interaction.restrictions, InteractionInfo.issuedByAI, InteractionInfo.priority, isContinuationOrSubtask: true), human); while (subTask != null) // WHILEPROTECTED { subTask = subTask.Handle(); yield return(YieldResult.WaitFrame); } StopCurrentSubtask(); } yield return(YieldResult.Completed); }
void SetupNearestBushAsTarget() { Bush nearestBush = VegetationGenerator.instance.GetReadyToInteractNearestBushWithFood(transform.position); if (!nearestBush) { return; } interactionTarget = nearestBush.GetComponent <InteractionTarget>(); interactionTarget.AddAnimal(this); targetPos = interactionTarget.transform.position; }
void SetupNearestTreeAsTarget() { Tree nearestTree = VegetationGenerator.instance.GetReadyToInteractNearestTree(transform.position); if (!nearestTree) { return; } interactionTarget = nearestTree.GetComponent <InteractionTarget>(); interactionTarget.AddAnimal(this); targetPos = interactionTarget.transform.position; }
void OnHoverBegin(InteractionTarget interactionTarget) { if (interactionTarget == null || interactionTarget.AttachTarget == null) { m_CompareDataModule.OnHoverChange(null); } else if (interactionTarget.AttachTarget.GetComponent <IDataVisual>() != null) { m_CompareDataModule.OnHoverChange(interactionTarget.AttachTarget.GetComponent <Proxy>()); } else { m_CompareDataModule.OnHoverEnd(); } }
public YieldResult New_LockInteraction(bool fromMod) { if (InteractionTarget.interactionLockID != 0 && Math.Abs(InteractionTarget.interactionLockID) != human.GetID() && InteractionTarget != human.GetInteractable()) { if (!fromMod && InteractionTarget.interactionLockID < 0) { return(YieldResult.Continue); } else { return(YieldResult.Failed); } } InteractionTarget.SetInteractionLockID(human.GetID()); return(YieldResult.Continue); }
void SceneViewHoverHandling(SceneView currentSceneView) { var currentEvent = Event.current; if (InteractionEnabled && !currentEvent.alt && EditorWindow.mouseOverWindow is SceneView) { if (EditorWindow.mouseOverWindow == currentSceneView) { RaycastInteractionTargets(currentSceneView.camera, HandleUtility.GUIPointToWorldRay(currentEvent.mousePosition)); } } else { m_CurrentHoverTarget = null; } CheckHoverChanges(); }
internal bool UpdateHover() { RaycastHit hit; Camera main = Camera.main; Ray ray = main.ScreenPointToRay(Input.mousePosition); // Hover Terrain if (Physics.Raycast(ray, out hit, 150f, 1 << LayerMask.NameToLayer("Terrain"))) { _hasTerrainPosition = true; _terrainPosition = hit.point; } else { _hasTerrainPosition = false; } //Hover Interactable if (Physics.Raycast(ray, out hit, 150f, 1 << LayerMask.NameToLayer("Interaction"))) { InteractionTarget target = hit.collider.GetComponent <InteractionTarget>(); AInteractable hovered = target.Interactable; if (hovered != null) { //Hovered success if (hovered != _hoveredObjet) { StopHover(); _hoveredObjet = hovered; StartHover(); } return(true); } } return(false); }
void CheckHoverChanges() { if (m_CurrentHoverTarget != m_PreviousHoverTarget) { if (m_PreviousHoverTarget != null) { EndHover(m_PreviousHoverTarget); } m_PreviousHoverTarget = m_CurrentHoverTarget; if (m_PreviousHoverTarget != null) { StartHover(m_PreviousHoverTarget); } } if (m_CurrentHoverTarget != null) { UpdateHover(m_PreviousHoverTarget, m_CurrentRaycastHit); } }
private Vector3 initialObjectRotation; // Cached rotation from before interaction // Use this for initialization void Start() { // Get FinalIK components interactionObject = GetComponent <InteractionObject>(); //handTarget = GetComponentInChildren<InteractionTarget>(); if (!handTarget) { // Get the left or right hand foreach (var target in GetComponentsInChildren <InteractionTarget>()) { if (target.effectorType == effectorType) { handTarget = target; break; } } } else { // Get the type from the selected target effectorType = handTarget.effectorType; } }
public void CanInteract(InteractionTarget newtar) { interact_target = newtar; }
[MenuItem("VoxSim/Hand Poses/Create Hand Pose %#r")] // it was available static void CreateSelectedHandPose() { /// <summary> /// Removes the person from the hand and creates an InteractionTarget /// /// Warning: make sure the hand you are turning into a pose is on a COPY of an agent. /// Whatever agent it is attached to will be deleted. /// /// IN: none /// OUT: none /// </summary> // get the selected game object GameObject obj = Selection.activeGameObject; // Check object is, in fact, a hand. if (obj.name != "lHand" && obj.name != "rHand") { Debug.Log("Currently selected object is not a hand."); return; } GameObject clone = Instantiate(obj); //Find parent (e.g. Diana) GameObject rootPerson = obj.transform.root.gameObject; Debug.Log(rootPerson); // Make sure new hand is in the same place as old one clone.transform.position = obj.transform.position; clone.transform.rotation = obj.transform.rotation; // Move hand wireframe to be a top-level object clone.transform.parent = null; // Delete extraneous components foreach (Component comp in clone.GetComponents <MonoBehaviour>()) { if (!(comp is InteractionTarget || comp is Transform)) { DestroyImmediate(comp); } } BoxCollider bc = clone.GetComponent <BoxCollider>(); // Only other component I've seen if (bc != null) { DestroyImmediate(bc); } // Set Interaction Target if it is not already there. InteractionTarget target = clone.GetComponent <InteractionTarget>(); if (target == null) // Only want to make one if it doesn't already exist. // Make a new one that says what hand to use and such { InteractionTarget newTarget = clone.AddComponent <InteractionTarget>() as InteractionTarget; if (clone.name.StartsWith("r")) { newTarget.effectorType = FullBodyBipedEffector.RightHand; } else if (clone.name.StartsWith("l")) { newTarget.effectorType = FullBodyBipedEffector.LeftHand; } newTarget.twistAxis = new Vector3(0, 0, 1); // specs say z axis, for wrist. } // remove "(Clone)" from name clone.name = clone.name.Replace("(Clone)", ""); // yeet the rest of the body // assumes agent is a clone deformed by the posing process anyway if (clone.transform.root != obj.transform.root) // edge case where you were already sans body { DestroyImmediate(rootPerson); } // Set new handpose as the new selection (since we deleted the old one) Selection.objects = new GameObject[] { clone }; }
static void MirrorSelectedHandPose() { // get the selected game object GameObject obj = Selection.activeGameObject; // if the pose already has a corresponding mirror, we don't need to do anything. if (obj.transform.parent.Find("l" + obj.name.Remove(0, 1)) && obj.transform.parent.Find("r" + obj.name.Remove(0, 1))) { Debug.Log("Preexisting Mirror Pose"); return; } // clone it, parent it to the same object as the original, and apply the requisite transformations GameObject clone = Instantiate(obj); clone.transform.parent = obj.transform.parent; //Find rotations Component[] rotations = clone.transform.parent.GetComponents(typeof(FixHandRotation)); bool rotRight = false; bool rotLeft = false; bool toMirrorRight = clone.name.StartsWith("r"); FixHandRotation newRot = null; // For if there is a corresponding rotation GameObject targetJoint = null; FullBodyBipedEffector targetHand = FullBodyBipedEffector.RightHand; Vector3 targetDir = new Vector3(0, 0, 0); InteractionSystem targetInteractionSystem = null; foreach (FixHandRotation rot in rotations) { // Check if rotations exist for both sides, and keep track of mirrored data if (rot.rootJoint.ToString().StartsWith("r")) { rotRight = true; string targetJointName = "l" + rot.rootJoint.name.ToString().Substring(1); targetInteractionSystem = rot.interactionSystem; // Interaction System targetJoint = GameObject.Find(targetJointName); // Root Joint targetHand = FullBodyBipedEffector.LeftHand; // Effector Type targetDir = new Vector3(-rot.localDirection.x, rot.localDirection.y, rot.localDirection.z); // Local Direction GameObject origJoint = rot.rootJoint; // The shoulder (or whatever else) we start with. if (targetJoint == null || targetJoint.transform.root != origJoint.transform.root) { Debug.Log("No mirror joint or wrong parent"); } } else if (rot.rootJoint.ToString().StartsWith("l")) { // See above block rotLeft = true; string targetJointName = "r" + rot.rootJoint.name.ToString().Substring(1); targetInteractionSystem = rot.interactionSystem; targetJoint = GameObject.Find(targetJointName); targetHand = FullBodyBipedEffector.RightHand; targetDir = new Vector3(-rot.localDirection.x, rot.localDirection.y, rot.localDirection.z); GameObject origJoint = rot.rootJoint; if (targetJoint == null || targetJoint.transform.root != origJoint.transform.root) { Debug.Log("No mirror joint or wrong parent"); } } } // Only need to make a new rotation if we're missing exactly one for the new function. // And only if old one matches with the one we're mirroring. if (rotRight ^ rotLeft && rotRight == toMirrorRight) { // Set parameters for new rotation that we now know we need. Debug.Log(targetJoint); newRot = clone.transform.parent.gameObject.AddComponent <FixHandRotation>(); newRot.rootJoint = targetJoint; newRot.effectorType = targetHand; newRot.localDirection = targetDir; newRot.interactionSystem = targetInteractionSystem; } // mirror along the X-axis clone.transform.localScale = new Vector3(-obj.transform.localScale.x, obj.transform.localScale.y, obj.transform.localScale.z); // mirror its local position across the YZ-plane (along the X-axis) clone.transform.localPosition = new Vector3(-obj.transform.localPosition.x, obj.transform.localPosition.y, obj.transform.localPosition.z); // reverse its rotation around the Y- and Z-axes clone.transform.localEulerAngles = Quaternion.Euler(new Vector3(0.0f, 180.0f, 180.0f)) * obj.transform.localEulerAngles; // remove "(Clone)" from name clone.name = clone.name.Replace("(Clone)", ""); // Get the InteractionTarget component and transforms of all children InteractionTarget interactionTarget = clone.GetComponent <InteractionTarget>(); Transform[] allChildren = clone.GetComponentsInChildren <Transform>(); if (clone.name.StartsWith("r")) { // replace right-hand labels with left-hand labels clone.name = "l" + clone.name.Remove(0, 1); foreach (Transform child in allChildren) { if (child.name.StartsWith("r")) { child.name = "l" + child.name.Remove(0, 1); } if (child.name.StartsWith("Right")) { child.name = "Left" + child.name.Remove(0, "Right".Length); } if (child.name.EndsWith("PointR")) { child.name = child.name.Replace("PointR", "PointL"); } } // switch handedness of effector type if (interactionTarget.effectorType == FullBodyBipedEffector.RightHand) { interactionTarget.effectorType = FullBodyBipedEffector.LeftHand; } else if (interactionTarget.effectorType == FullBodyBipedEffector.RightShoulder) { interactionTarget.effectorType = FullBodyBipedEffector.LeftShoulder; } // invert the twist axis if (Mathf.Abs(interactionTarget.twistAxis.x) > Constants.EPSILON) { interactionTarget.twistAxis = new Vector3(-interactionTarget.twistAxis.x, interactionTarget.twistAxis.y, interactionTarget.twistAxis.z); } } else if (clone.name.StartsWith("l")) { // replace left-hand labels with right-hand labels clone.name = "r" + clone.name.Remove(0, 1); foreach (Transform child in allChildren) { if (child.name.StartsWith("l")) { child.name = "r" + child.name.Remove(0, 1); } if (child.name.StartsWith("Left")) { child.name = "Right" + child.name.Remove(0, "Left".Length); } if (child.name.EndsWith("PointL")) { child.name = child.name.Replace("PointL", "PointR"); } } // switch handedness of effector type if (interactionTarget.effectorType == FullBodyBipedEffector.LeftHand) { interactionTarget.effectorType = FullBodyBipedEffector.RightHand; } else if (interactionTarget.effectorType == FullBodyBipedEffector.LeftShoulder) { interactionTarget.effectorType = FullBodyBipedEffector.RightShoulder; } // invert the twist axis if (Mathf.Abs(interactionTarget.twistAxis.x) > Constants.EPSILON) { interactionTarget.twistAxis = new Vector3(-interactionTarget.twistAxis.x, interactionTarget.twistAxis.y, interactionTarget.twistAxis.z); } } }
static void FlipLabelHandedness() { // get the selected game object, its InteractionTarget and transforms of all children GameObject obj = Selection.activeGameObject; InteractionTarget interactionTarget = obj.GetComponent <InteractionTarget>(); Transform[] allChildren = obj.GetComponentsInChildren <Transform>(); if (obj.name.StartsWith("r")) { // replace right-hand labels with left-hand labels obj.name = "l" + obj.name.Remove(0, 1); foreach (Transform child in allChildren) { if (child.name.StartsWith("r")) { child.name = "l" + child.name.Remove(0, 1); } if (child.name.StartsWith("Right")) { child.name = "Left" + child.name.Remove(0, "Right".Length); } if (child.name.EndsWith("PointR")) { child.name = child.name.Replace("PointR", "PointL"); } } // switch handedness of effector type if (interactionTarget.effectorType == FullBodyBipedEffector.RightHand) { interactionTarget.effectorType = FullBodyBipedEffector.LeftHand; } else if (interactionTarget.effectorType == FullBodyBipedEffector.RightShoulder) { interactionTarget.effectorType = FullBodyBipedEffector.LeftShoulder; } // invert the twist axis if (Mathf.Abs(interactionTarget.twistAxis.x) < Constants.EPSILON) { interactionTarget.twistAxis = new Vector3(-interactionTarget.twistAxis.x, interactionTarget.twistAxis.y, interactionTarget.twistAxis.z); } } else if (obj.name.StartsWith("l")) { // replace left-hand labels with right-hand labels obj.name = "r" + obj.name.Remove(0, 1); foreach (Transform child in allChildren) { if (child.name.StartsWith("l")) { child.name = "r" + child.name.Remove(0, 1); } if (child.name.StartsWith("Left")) { child.name = "Right" + child.name.Remove(0, "Left".Length); } if (child.name.EndsWith("PointL")) { child.name = child.name.Replace("PointL", "PointR"); } } // switch handedness of effector type if (interactionTarget.effectorType == FullBodyBipedEffector.LeftHand) { interactionTarget.effectorType = FullBodyBipedEffector.RightHand; } else if (interactionTarget.effectorType == FullBodyBipedEffector.LeftShoulder) { interactionTarget.effectorType = FullBodyBipedEffector.RightShoulder; } // invert the twist axis if (Mathf.Abs(interactionTarget.twistAxis.x) < Constants.EPSILON) { interactionTarget.twistAxis = new Vector3(-interactionTarget.twistAxis.x, interactionTarget.twistAxis.y, interactionTarget.twistAxis.z); } } }