Пример #1
0
 // Use this for initialization
 void Start()
 {
     if (smellSensor == null)
     {
         Debug.Log("RHS>>> ERROR! Smell Sensor is missing!");
     }
     else
     {
         captureSmell = smellSensor.GetComponent <CaptureSmell>();
     }
     count                 = 0;
     knowObjects           = new HashSet <GameObject>();
     updKnowElementsList   = new HashSet <GameObject>();
     unknowObjects         = new HashSet <GameObject>();
     updUnknowElementsList = new HashSet <GameObject>();
     Debug.Log("RHS>>> " + this.name + " smell was configured with success.");
 }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        updateSpineRotation();
        for (int i = 0; i < agentHands.Length; i++)
        {
            if (agentHands[i].getCommand() != null)
            {
                switch (agentHands[i].getCommand().getAction())
                {
                case Action.Take:
                    updateFocusPosition(agentHands[i]);
                    switch (agentHands[i].getCommand().getActionStateID())
                    {
                    case (int)Take.Start:
                        Debug.Log("Command>>> " + this.name + " command " + agentHands[i].getCommand().getId() + " Started!");
                        agentHands[i].getCommand().next();
                        break;

                    case (int)Take.Position:
                        velocityFocus    = Constants.NATURALSPD * 2;
                        agentHands[i].ik = true;
                        configureCrouchAndSpineInclination(agentHands[i]);
                        //O foco está na posição
                        if (isInPosition(agentHands[i].focus.position, agentHands[i].getCommand().getNearestDesiredPosition(transform.position)))
                        {
                            //A mão está posicionada no foco? O IK já terminou de executar?
                            if (isInPosition(agentHands[i].hand.position, agentHands[i].focus.position) && animator.GetFloat(agentHands[i].getAnimatorParam()) > 0.9)
                            {
                                agentHands[i].getCommand().next();
                            }
                            else
                            if (!isReachable(agentHands[i]))
                            {
                                Debug.Log("Command>>> " + this.name + " command " + agentHands[i].getCommand().getId() + " Failed! Object not reachable.");
                                agentHands[i].getCommand().fail();
                            }
                        }
                        break;

                    case (int)Take.Grab:
                        bool success = agentHands[i].hold(agentHands[i].getCommand().getReference());
                        if (success)
                        {
                            agentHands[i].getCommand().next();
                        }
                        else
                        {
                            agentHands[i].getCommand().fail();
                        }
                        Debug.Log("Command>>> " + this.name + " command " + agentHands[i].getCommand().getId() + " Failed! Could not grab the object!");
                        break;

                    case (int)Take.Approximate:
                        if (agentHands[i].getCommand().isToResetHand())
                        {
                            resetCrouchValue();
                            resetSpineRotation();
                        }
                        velocityFocus = Constants.NATURALSPD;
                        agentHands[i].getCommand().setLocation(agentHands[i].getRestPosition());
                        //O foco está na posição?
                        if (isInPosition(agentHands[i].focus.position, agentHands[i].getRestPosition().position))
                        {
                            agentHands[i].getCommand().success();
                            Debug.Log("Command>>> " + this.name + " command " + agentHands[i].getCommand().getId() + " Success!");
                        }
                        break;

                    case (int)Take.End:
                        //Continua atualizando o IK

                        //Verifica houve falha
                        if (agentHands[i].isHandFree())
                        {
                            agentHands[i].ik = false;
                        }
                        break;

                    default:
                        break;
                    }
                    break;

                case Action.Activate:
                case Action.Deactivate:
                    velocityFocus = Constants.NATURALSPD * 3;
                    updateFocusPosition(agentHands[i]);
                    switch (agentHands[i].getCommand().getActionStateID())
                    {
                    case (int)Activate.Start:
                        Debug.Log("Command>>> " + this.name + " command " + agentHands[i].getCommand().getId() + " Started!");
                        agentHands[i].getCommand().next();
                        break;

                    case (int)Activate.Position:
                        manageHandPosition(agentHands[i]);
                        break;

                    case (int)Activate.Trigger:
                        bool success = agentHands[i].setActivate(agentHands[i].getCommand().getReference(), agentHands[i].getCommand().getAction() == Action.Activate);
                        if (success)
                        {
                            agentHands[i].getCommand().success();
                            Debug.Log("Command>>> " + this.name + " command " + agentHands[i].getCommand().getId() + " Success!");
                        }
                        else
                        {
                            Debug.Log("Command>>> " + this.name + " command " + agentHands[i].getCommand().getId() + " Failed! ERROR!");
                            agentHands[i].getCommand().fail();
                        }
                        break;

                    case (int)Activate.End:
                        manageEndOfActivate(agentHands[i]);
                        break;

                    default:
                        Debug.Log("Command>>> " + this.name + " command " + agentHands[i].getCommand().getId() + " Failed! Object not reachable.");
                        agentHands[i].getCommand().fail();
                        break;
                    }
                    break;

                case Action.Release:
                    velocityFocus = Constants.NATURALSPD * 3;
                    switch (agentHands[i].getCommand().getActionStateID())
                    {
                    case (int)Release.Start:
                        Debug.Log("Command>>> " + this.name + " command " + agentHands[i].getCommand().getId() + " Started!");
                        agentHands[i].getCommand().next();
                        break;

                    case (int)Release.Position:
                        if (isLocationReachable(agentHands[i]))
                        {
                            updateFocusToOtherPosition(agentHands[i], agentHands[i].getCommand().getNearestDesiredContainer(transform.position));
                            configureCrouchAndSpineInclination(agentHands[i]);
                        }
                        else
                        {
                            updateFocusToOtherPosition(agentHands[i], agentHands[i].getRestPosition().position);
                            Debug.Log("Command>>> " + this.name + " command " + agentHands[i].getCommand().getId() + " Failed! Location is not reachable.");
                            agentHands[i].getCommand().fail();
                        }
                        //O Foco está na posição?
                        if (isInPosition(agentHands[i].focus.position, agentHands[i].getCommand().getNearestDesiredContainer(transform.position)) && isInPosition(agentHands[i].focus.position, agentHands[i].hand.position))
                        {
                            agentHands[i].getCommand().next();
                        }
                        break;

                    case (int)Release.Leave:
                        velocityFocus = Constants.NATURALSPD;
                        bool success = agentHands[i].drop(agentHands[i].getCommand().getNearestDesiredContainer(transform.position));
                        if (success)
                        {
                            Debug.Log("Command>>> " + this.name + " command " + agentHands[i].getCommand().getId() + " Success!");
                            agentHands[i].getCommand().success();
                        }
                        else
                        {
                            Debug.Log("Command>>> " + this.name + " command " + agentHands[i].getCommand().getId() + " Failed! ERROR!");
                            agentHands[i].getCommand().fail();
                        }
                        break;

                    case (int)Release.End:
                        if (agentHands[i].getCommand().isToResetHand())
                        {
                            resetCrouchValue();
                            resetSpineRotation();
                        }
                        if (agentHands[i].getCommand().isFail())
                        {
                            updateFocusToOtherPosition(agentHands[i], agentHands[i].getRestPosition().position);
                        }
                        else
                        {
                            agentHands[i].ik = false;
                        }
                        if (agentHands[i].isHandFree())
                        {
                            agentHands[i].ik = false;
                        }
                        break;
                    }
                    break;

                case Action.Taste:
                    velocityFocus = Constants.NATURALSPD * 3;
                    switch (agentHands[i].getCommand().getActionStateID())
                    {
                    case (int)Taste.Start:
                        Debug.Log("Command>>> " + this.name + " command " + agentHands[i].getCommand().getId() + " Started!");
                        auxCommand = GetComponent <AgentHeadMovement>().getCurrentCommand();
                        GetComponent <AgentHeadMovement>().sendCommand(new Command("", Action.HeadReset));
                        agentHands[i].getCommand().next();
                        break;

                    case (int)Taste.Position:
                        if (!agentHands[i].isHandFree())
                        {
                            updateFocusToOtherPosition(agentHands[i], agentHands[i].getCommand().getNearestDesiredPosition(agentHands[i].hand.position));
                            int auxFlag = 1;
                            if (agentHands[i].getActHand() == Hands.Right)
                            {
                                auxFlag = -1;
                            }
                            rotateFocus(agentHands[i], (handTasteYAngle * auxFlag));
                            //O Foco está na posição?
                            CaptureTaste captureTaste = agentTasteSensor.GetComponent <CaptureTaste>();
                            captureTaste.capture();
                            if (captureTaste.isObjectInTasteSensor() && captureTaste.getActTaste() == agentHands[i].objInHand.gameObject)
                            {
                                agentHands[i].getCommand().next();
                            }
                        }
                        else
                        {
                            Debug.Log("Command>>> " + this.name + " command " + agentHands[i].getCommand().getId() + " Failed! Hand is empty. ");
                            agentHands[i].getCommand().fail();
                        }
                        break;

                    case (int)Taste.Taste:

                        timer += Time.deltaTime;
                        float seconds = timer % 60;
                        velocityFocus = Constants.NATURALSPD;
                        if (seconds > timeToTaste)
                        {
                            CaptureTaste captureTaste = agentTasteSensor.GetComponent <CaptureTaste>();
                            captureTaste.stopCature();
                            agentHands[i].getCommand().next();
                        }
                        break;

                    case (int)Taste.ReturnHeadTask:
                        if (auxCommand != null)
                        {
                            auxCommand.resetState();
                            GetComponent <AgentHeadMovement>().sendCommand(auxCommand);
                        }
                        Debug.Log("Command>>> " + this.name + " command " + agentHands[i].getCommand().getId() + " Success!");
                        agentHands[i].getCommand().success();
                        break;

                    case (int)Taste.End:
                        if (agentHands[i].getCommand().isToResetHand())
                        {
                            resetCrouchValue();
                            resetSpineRotation();
                        }
                        resetRotationFocus(agentHands[i]);
                        timer = 0f;
                        updateFocusToOtherPosition(agentHands[i], agentHands[i].getRestPosition().position);
                        if (agentHands[i].isHandFree())
                        {
                            agentHands[i].ik = false;
                        }
                        break;
                    }
                    break;

                case Action.Smell:
                    velocityFocus = Constants.NATURALSPD * 3;
                    switch (agentHands[i].getCommand().getActionStateID())
                    {
                    case (int)Smell.Start:
                        Debug.Log("Command>>> " + this.name + " command " + agentHands[i].getCommand().getId() + " Started!");
                        auxCommand = GetComponent <AgentHeadMovement>().getCurrentCommand();
                        GetComponent <AgentHeadMovement>().sendCommand(new Command("", Action.HeadReset));
                        agentHands[i].getCommand().next();
                        break;

                    case (int)Smell.Position:
                        if (!agentHands[i].isHandFree())
                        {
                            updateFocusToOtherPosition(agentHands[i], agentHands[i].getCommand().getNearestDesiredPosition(agentHands[i].hand.position));
                            int auxFlag = 1;
                            if (agentHands[i].getActHand() == Hands.Right)
                            {
                                auxFlag = -1;
                            }
                            rotateFocus(agentHands[i], (handTasteYAngle * auxFlag));
                            //O Foco está na posição?
                            CaptureSmell captureSmell = agentSmellSensor.GetComponent <CaptureSmell>();
                            if (agentHands[i].objInHand.gameObject.GetComponentInChildren <ParticleSystem>() == null)
                            {
                                captureSmell.putObjInSmell(agentHands[i].objInHand.gameObject);
                            }
                            if (captureSmell.isObjectInSmellInSensor() && captureSmell.getActSmell() == agentHands[i].objInHand.gameObject)
                            {
                                agentHands[i].getCommand().next();
                            }
                        }
                        else
                        {
                            Debug.Log("Command>>> " + this.name + " command " + agentHands[i].getCommand().getId() + " Failed! Hand is empty. ");
                            agentHands[i].getCommand().fail();
                        }
                        break;

                    case (int)Smell.Smell:

                        timer += Time.deltaTime;
                        float seconds = timer % 60;
                        velocityFocus = Constants.NATURALSPD;
                        if (seconds > timeToTaste)
                        {
                            agentHands[i].getCommand().next();
                        }
                        break;

                    case (int)Smell.ReturnHeadTask:
                        if (auxCommand != null)
                        {
                            auxCommand.resetState();
                            GetComponent <AgentHeadMovement>().sendCommand(auxCommand);
                        }
                        Debug.Log("Command>>> " + this.name + " command " + agentHands[i].getCommand().getId() + " Success!");
                        agentHands[i].getCommand().success();
                        break;

                    case (int)Smell.End:
                        if (agentHands[i].getCommand().isToResetHand())
                        {
                            resetCrouchValue();
                            resetSpineRotation();
                        }
                        resetRotationFocus(agentHands[i]);
                        timer = 0f;
                        updateFocusToOtherPosition(agentHands[i], agentHands[i].getRestPosition().position);
                        if (agentHands[i].isHandFree())
                        {
                            agentHands[i].ik = false;
                        }
                        break;
                    }
                    break;

                default:
                    break;
                }
            }
        }
    }