Ejemplo n.º 1
0
    /*
     * Another behemoth, does frame-by-frame updates to state, appearances, transforms, etc.
     * Includes calls to TryHand, UpdateGrabVis, etc. as well as calls to ThermoState functions.
     * Basically, wraps calls to a bunch of other functions, and a hodgepodge of other random tasks,
     * as far as I can tell.
     */
    void Update()
    {
        //hands keep trying to run away- no idea why (this is a silly way to keep them still)
        lactualhand.transform.localPosition    = new Vector3(0f, 0f, 0f);
        lactualhand.transform.localEulerAngles = new Vector3(0f, 0f, 90f);
        ractualhand.transform.localPosition    = new Vector3(0f, 0f, 0f);
        ractualhand.transform.localEulerAngles = new Vector3(0f, 0f, -90f);

        //apply thermo
        if (!tool_clamp.engaged)
        {
            double psi_to_pascal    = 6894.76;
            double neutral_pressure = 14.6959;                                   //~1atm in psi
            double weight_pressure  = applied_weight / thermo.surfacearea_insqr; //psi
            weight_pressure += neutral_pressure;
            weight_pressure *= psi_to_pascal;                                    //conversion from psi to pascal

            //treat "applied_weight" as target, and iterate toward it, rather than applying it additively
            //(technically, "should" add_pressure(...) with every delta of weight on the piston, but that would result in very jumpy nonsense movements. iterating toward a target smooths it out)
            double delta_pressure = (weight_pressure - thermo.pressure) * 0.01; //1% of difference
            if (System.Math.Abs(delta_pressure) > 1)
            {
                // we only are applying pressure added/released if we are in gas region.
                // if this ever changes, adapt this "if" check as needed.
                if (thermo.region == 2)
                {
                    arrows.Go(delta_pressure > 0.0f);
                    arrows.SetFlow(delta_pressure);
                }
                if (tool_insulator.engaged)
                {
                    thermo.add_pressure_insulated(delta_pressure);
                }
                else
                {
                    thermo.add_pressure_uninsulated(delta_pressure);
                }
            }
            else if (arrows.running)
            {
                arrows.Stop();
            }
        }
        //if(tool_insulator.engaged && applied_heat != 0) //yes, "engaged" is correct. if insulator NOT engaged, then any heat added IMMEDIATELY dissipates
        if (applied_heat != 0)
        {
            double insulation_coefficient = tool_insulator.engaged ? 1.0f : CONTAINER_INSULATION_COEFFICIENT;
            double heat_joules            = insulation_coefficient * applied_heat * (double)Time.deltaTime;
            if (tool_clamp.engaged)
            {
                thermo.add_heat_constant_v(heat_joules);
            }
            else
            {
                thermo.add_heat_constant_p(heat_joules);
            }
        }

        //running blended average of hand velocity (transfers this velocity on "release object" for consistent "throwing")
        lhand_vel += (lhand.transform.position - lhand_pos) / Time.deltaTime;
        lhand_vel *= 0.5f;
        lhand_pos  = lhand.transform.position;

        rhand_vel += (rhand.transform.position - rhand_pos) / Time.deltaTime;
        rhand_vel *= 0.5f;
        rhand_pos  = rhand.transform.position;

        //input
        //float lhandt  = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger);
        //float lindext = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger);
        //float rhandt  = OVRInput.Get(OVRInput.Axis1D.SecondaryHandTrigger);
        //float rindext = OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger);
        float lhandt  = OVRInput.Get(OVRInput.RawAxis1D.LHandTrigger);
        float lindext = OVRInput.Get(OVRInput.RawAxis1D.LIndexTrigger);
        float rhandt  = OVRInput.Get(OVRInput.RawAxis1D.RHandTrigger);
        float rindext = OVRInput.Get(OVRInput.RawAxis1D.RIndexTrigger);

        //index compatibility
        if (OVRInput.Get(OVRInput.Button.One, OVRInput.Controller.LTouch))
        {
            lhandt = 1.0f;
        }
        if (OVRInput.Get(OVRInput.Button.One, OVRInput.Controller.RTouch))
        {
            rhandt = 1.0f;
        }
        lhandt += lindext;
        rhandt += rindext;
        if (lindext > 0.0f || rindext > 0.0f)
        {
            ;
        }
        //test effect of hands one at a time ("true" == "left hand", "false" == "right hand")
        TryHand(true, lhandt, lindext, lhand.transform.position.x, lhand.transform.position.y, lhand_vel, ref lhtrigger, ref litrigger, ref lhtrigger_delta, ref litrigger_delta, ref lz, ref ly, ref lhand, ref lgrabbed, ref rhand, ref rgrabbed);  //left hand
        TryHand(false, rhandt, rindext, rhand.transform.position.x, rhand.transform.position.y, rhand_vel, ref rhtrigger, ref ritrigger, ref rhtrigger_delta, ref ritrigger_delta, ref rz, ref ry, ref rhand, ref rgrabbed, ref lhand, ref lgrabbed); //right hand

        UpdateGrabVis();

        //clipboard
        int old_board_mode = board_mode;

        board_mode = reconcileDependentSelectables(board_mode, mode_tabs);
        if (board_mode == -1)
        {
            board_mode = old_board_mode;
        }
        updateSelectableVis(board_mode, mode_tabs);

        switch (board_mode)
        {
        case 0: //instructions
            if (!instructions_parent.activeSelf)
            {
                instructions_parent.SetActive(true);
            }
            if (challenge_parent.activeSelf)
            {
                challenge_parent.SetActive(false);
            }
            if (quiz_parent.activeSelf)
            {
                quiz_parent.SetActive(false);
            }
            break;

        case 1: //challenge
            if (instructions_parent.activeSelf)
            {
                instructions_parent.SetActive(false);
            }
            if (!challenge_parent.activeSelf)
            {
                challenge_parent.SetActive(true);
            }
            if (quiz_parent.activeSelf)
            {
                quiz_parent.SetActive(false);
            }

            if (challenge_ball_collide.win)
            {
                challenge_ball_collide.win = false;
                SetChallengeBall();
            }
            break;

        case 2: //quiz
            if (instructions_parent.activeSelf)
            {
                instructions_parent.SetActive(false);
            }
            if (challenge_parent.activeSelf)
            {
                challenge_parent.SetActive(false);
            }
            if (!quiz_parent.activeSelf)
            {
                quiz_parent.SetActive(true);
            }
            qselected = reconcileDependentSelectables(qselected, option_tabs);
            updateSelectableVis(qselected, option_tabs);
            if (qselected != -1) //answer selected, can be confirmed
            {
                if (qconfirm_tab.fingertoggleable.finger)
                {
                    qconfirm_tab.backing_meshrenderer.material = tab_hisel;                                //touching
                }
                else
                {
                    qconfirm_tab.backing_meshrenderer.material = tab_sel; //not touching
                }
                if (!qconfirmed && qconfirm_tab.fingertoggleable.finger)  //newly hit
                {
                    qconfirmed = true;
                    if (qselected == answers[question])
                    {
                        ; //correct
                    }
                    else
                    {
                        ; //incorrect
                    }
                    givens[question] = qselected;
                    question++;
                    SetQuizText();
                }
            }
            else //no answer selected- can't confirm
            {
                if (qconfirm_tab.fingertoggleable.finger)
                {
                    qconfirm_tab.backing_meshrenderer.material = tab_hi;                                     //touching
                }
                else
                {
                    qconfirm_tab.backing_meshrenderer.material = tab_default;                                //not touching
                }
                qconfirmed = false;
            }
            break;

        case 3:             //congratulations
            board_mode = 2; //immediately return back to quiz until this section is actually implemented
            break;
        }

        //tooltext
        Tool t;

        for (int i = 0; i < tools.Count; i++)
        {
            t = tools[i];
            t.dial_dial.examined = false;
            if (t.dial == lgrabbed || t.dial == rgrabbed)
            {
                t.dial_dial.examined = true;
            }
            if (t.dial_dial.val != t.dial_dial.prev_val)
            {
                t.textv_tmpro.SetText("{0:3}" + t.dial_dial.unit, (float)t.dial_dial.map);
                t.dial_dial.examined = true;
            }
            t.dial_dial.prev_val = t.dial_dial.val;
        }

        // we did tool text above, so here I'll drop in the bit to check whether to show phase warning for balloon and weight.
        switch (thermo.region)
        {
        case 0:
        case 1:
            tool_weight.textn.GetComponent <MeshRenderer>().enabled = true;
            tool_weight.disabled = true;
            tool_balloon.textn.GetComponent <MeshRenderer>().enabled = true;
            tool_balloon.disabled = true;
            break;

        case 2:
            tool_weight.textn.GetComponent <MeshRenderer>().enabled = false;
            tool_weight.disabled = false;
            tool_balloon.textn.GetComponent <MeshRenderer>().enabled = false;
            tool_balloon.disabled = false;
            break;
        }

        for (int i = 0; i < tools.Count; i++)
        {
            t = tools[i];
            if (!t.text_fadable.stale)
            {
                if (t.text_fadable.alpha == 0f)
                {
                    t.textv_meshrenderer.enabled = false;
                    t.textl_meshrenderer.enabled = false;
                }
                else
                {
                    t.textv_meshrenderer.enabled = true;
                    t.textl_meshrenderer.enabled = true;
                    Color32 c = t.disabled ? new Color32(70, 70, 70, (byte)(t.text_fadable.alpha * 255)) : new Color32(0, 0, 0, (byte)(t.text_fadable.alpha * 255));
                    t.textv_tmpro.faceColor = c;
                    t.textl_tmpro.faceColor = c;
                }
            }
        }
        thermo.UpdateErrorState();
    }