Tuple<GraspableObject, Grasp> GetOptimalTargetAndGrasp() { var targets = FindObjectsOfType<GraspableObject>(); if (targets.Length == 0) { return null; } var shortest_distance = float.MaxValue; GraspableObject optimal_target = null; Grasp optimal_grasp = null; foreach (var target in targets) { var pair = target.GetOptimalGrasp(this); if (pair == null || pair.Item1 == null || pair.Item1.IsObstructed()) { continue; } var target_grasp = pair.Item1; var distance = pair.Item2; if (distance < shortest_distance) { shortest_distance = distance; optimal_grasp = target_grasp; optimal_target = target; } } return new Tuple<GraspableObject, Grasp>(optimal_target, optimal_grasp); }
void Ab(GameObject child_game_object, GraspableObject other_maybe_graspable) { if (other_maybe_graspable) { if (child_game_object == this._grab_region.gameObject && other_maybe_graspable.gameObject == this._target_game_object.gameObject) { if (this._debugging) { Debug.Log(message: $"Target {other_maybe_graspable.name} is inside region"); } this._state.TargetIsInsideRegion(); } if (child_game_object == this._begin_grab_region.gameObject && other_maybe_graspable.gameObject == this._target_game_object.gameObject && !this._state.IsTargetGrabbed()) { if (this._debugging) { Debug.Log(message: $"Picking up target {other_maybe_graspable.name}"); } this._state.PickUpTarget(); } } }
public void FindTargetAndUpdatePath() { var pair = this.GetOptimalTargetAndGrasp(); if (pair == null || pair.Item1 == null || pair.Item2 == null) { this._state.PathFindingState = PathFindingState.Returning_; this._path = this.FindPath(this.transform.position, this._reset_position); return; } this._target_game_object = pair.Item1; this._target_grasp = pair.Item2; this._approach_position = this._target_grasp.transform.position - this._target_grasp.transform.forward * this._approach_distance; if (Vector3.Distance(this.transform.position, this._approach_position) > this._search_boundary) { return; } this._path = this.FindPath(this.transform.position, this._approach_position); this._intermediate_target = this._path.Next(this._step_size); }