示例#1
0
        Pair <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.First == null || pair.First.IsObstructed())
                {
                    continue;
                }
                var target_grasp = pair.First;
                var distance     = pair.Second;
                if (distance < shortest_distance)
                {
                    shortest_distance = distance;
                    optimal_grasp     = target_grasp;
                    optimal_target    = target;
                }
            }

            return(new Pair <GraspableObject, Grasp>(optimal_target, optimal_grasp));
        }
示例#2
0
        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)
                    {
                        print(string.Format("Target {0} is inside region", other_maybe_graspable.name));
                    }
                    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)
                    {
                        print(string.Format("Picking up target {0}", other_maybe_graspable.name));
                    }
                    this._state.PickUpTarget();
                }
            }
        }
示例#3
0
        public void FindTargetAndUpdatePath()
        {
            var pair = this.GetOptimalTargetAndGrasp();

            if (pair == null || pair.First == null || pair.Second == null)
            {
                this._state.PathFindingState = PathFindingState.Returning;
                this._path = this.FindPath(this.transform.position, this._reset_position);
                return;
            }

            this._target_game_object = pair.First;
            this._target_grasp       = pair.Second;
            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);
        }