예제 #1
0
    // Update is called once per frame
    public void UpdateEvent()
    {
        // Get the interpreter if it's null
        if (interpreter == null)
        {
            if (GameObject.FindGameObjectWithTag("SceneInterpreter"))
            {
                return;
            }
            interpreter = GameObject.FindGameObjectWithTag("SceneInterpreter").GetComponent <SceneInterpreter>();
        }
        // Return if the interpreter is running
        if (interpreter.InterpreterActive())
        {
            return;
        }

        // Check our pages and process if appropriate
        int pid          = pages.Count;
        int previousPage = currentPage;

        currentPage = -1;
        for (int i = pid - 1; i >= 0; i--)
        {
            // Check each criteria, if they all pass, this is the current page
            bool c1 = pages[i].variable1Name == "" || pages[i].variable1Value <= interpreter.GetVariable(pages[i].variable1Name);
            bool c2 = pages[i].variable2Name == "" || pages[i].variable2Value <= interpreter.GetVariable(pages[i].variable2Name);
            bool c3 = pages[i].switch1Name == "" || pages[i].switch1Value == interpreter.GetSwitch(pages[i].switch1Name);
            bool c4 = pages[i].switch2Name == "" || pages[i].switch2Value == interpreter.GetSwitch(pages[i].switch2Name);
            // If all 4 criteria match, that's our page
            if (c1 && c2 && c3 && c4)
            {
                if (previousPage != i)
                {
                    thisPageRun = false;
                }
                currentPage = i;
                break;
            }
        }

        // If our page trigger is auto and we're not running, run us!
        if (currentPage >= 0 && pages[currentPage].trigger == eEventTrigger.Auto && !thisPageRun)
        {
            Debug.Log(pages[currentPage].pageName + ": " + currentPage);
            // Add each event to the scene interpreter
            foreach (d_Event e in pages[currentPage].events)
            {
                interpreter.AddEvent(e, gameObject);
            }
            thisPageRun = true;
        }
    }
예제 #2
0
    // Updates the basic character functions
    void UpdatePlayers()
    {
        // Update all appropriate player objects
        foreach (GameObject player in Players)
        {
            // Set the animator speed
            //AIPath aiPath = player.GetComponent<AIPath>();

            /*if(aiPath.velocity != null)
             * {
             *      anim.SetFloat("Speed", aiPath.velocity / aiPath.speed);
             *      anim.SetFloat("Speed", seek.GetCurrentPath().speed);
             *      //print (seek.GetCurrentPath().speed);
             * }*/
            //animation.SetFloat("Speed", h*h+v*v);

            // Change our control to if the Interpreter is active or not
            if (interpreter != null)
            {
                // If the interpreter is working actively, we can't control our character
                CharacterMotor motor = player.GetComponent <CharacterMotor>();
                if (interpreter.InterpreterActive())
                {
                    motor.SetControllable(false);
                }
                else if (cameraActive)
                {
                    motor.SetControllable(false);
                }
                else
                {
                    motor.SetControllable(true);
                }
            }

            // Get the Animator
            Animator anim = player.GetComponent <Animator>();

            // Create and calculate our variables for animation
            Vector3 velocity;
            float   cSpeed;
            velocity = player.GetComponent <CharacterController>().velocity;
            if (player.GetComponent <CharacterMotor>().MaxSpeedInDirection(velocity) > 0f)
            {
                cSpeed = velocity.magnitude / player.GetComponent <CharacterMotor>().MaxSpeedInDirection(velocity);
            }
            else
            {
                cSpeed = 0f;
            }

            // Set the variables needed for animation
            anim.SetFloat("Speed", cSpeed);
            anim.SetFloat("VSpeed", velocity.y);
            anim.SetBool("OnGround", player.GetComponent <CharacterMotor>().IsGrounded());
            anim.SetBool("Jumping", Player.GetComponent <CharacterMotor>().IsJumping());

            // Fix the weight on the Additional layers
            anim.SetLayerWeight(1, 1.0f);

            // Ensure the player has us set as their player controller
            //PlayerActionAI pAI = player.GetComponent<PlayerActionAI>();
            //pAI.pController = this;
            //pAI.UpdateSpeed();

            // If it's not the active player...

            /*
             * if (player != Player)
             * {
             *      // Call the player to update their own logic
             *      pAI.UpdateCombatAI();
             *      pAI.UpdatePathAI();
             * }
             * else
             * {
             *      // Call the active player AI
             *      pAI.UpdateActiveAI();
             * }
             */
        }
    }