コード例 #1
0
 void Start()
 {
     foreach (var ctrl in Baroque.GetControllers())
     {
         StartCoroutine(_FollowJoystick(ctrl));
     }
     StartCoroutine(_BlinkCanvasInfo());
 }
コード例 #2
0
        protected ModelAction(Render render, Controller ctrl)
        {
            this.render = render;
            this.ctrl   = ctrl;

            Controller[] controllers = Baroque.GetControllers();
            other_ctrl = controllers[1 - ctrl.index];
        }
コード例 #3
0
    public IEnumerator SceneChange()
    {
        FindObjectOfType <PongBaseBuilder>().FadeOutSounds(0.2f);
        Baroque.FadeToColor(Color.black, 0.2f);
        yield return(new WaitForSeconds(0.2f));

        played_episode = episode;
        UnityEngine.SceneManagement.SceneManager.LoadScene(sceneName);
    }
コード例 #4
0
    void Update()
    {
        var ctrl0 = Baroque.GetControllers()[0];
        var ctrl1 = Baroque.GetControllers()[1];

        transform.rotation = Quaternion.Euler(ctrl0.triggerVariablePressure * 90, 0, ctrl1.triggerVariablePressure * 90);

        var rend = GetComponent <Renderer>();

        rend.material.color = new Color(ctrl0.triggerPressed ? 1f : 0f, ctrl1.triggerPressed ? 1f : 0f, 0);
    }
コード例 #5
0
 public static void RestartFollowingAll()
 {
     foreach (var ctrl in Baroque.GetControllers())
     {
         var pad = ctrl.GetComponentInChildren <PongPad>();
         if (pad != null)
         {
             pad.RestartFollowing();
         }
     }
 }
コード例 #6
0
        float[] RecordRenderModels()
        {
            List <float> tr = new List <float>(FlattenTransform(Baroque.GetHeadTransform()));

            foreach (var ctrl in Baroque.GetControllers())
            {
                if (ctrl.isActiveAndEnabled)
                {
                    tr.AddRange(FlattenTransform(ctrl.transform));
                }
            }
            return(tr.ToArray());
        }
コード例 #7
0
    protected override void RemovePointersOnPausedExplicit()
    {
        var old_expls = expls;

        expls = null;
        foreach (var ctrl in Baroque.GetControllers())
        {
            var expl = ctrl.GetAdditionalData(ref old_expls);
            if (expl.cylinder_tr != null)
            {
                Destroy((GameObject)expl.cylinder_tr.parent.gameObject);
            }
        }
    }
コード例 #8
0
 public void UpdateControllerHints()
 {
     foreach (var ctrl in Baroque.GetControllers())
     {
         if (clicked_trigger && clicked_touchpad)
         {
             ctrl.SetControllerHints(/*nothing*/);
         }
         else
         {
             ctrl.SetControllerHints(trigger: "open", touchpadPressed: "mark");
         }
     }
 }
コード例 #9
0
    IEnumerator _FadeOutPadsAndHeadset(bool[] stop_instruction)
    {
        var mat = new Material(PongPadBuilder.instance.padsAndHeadsetTransparencyMaterial);

        void FixMat(Transform toplevel)
        {
            foreach (var rend in toplevel.GetComponentsInChildren <MeshRenderer>())
            {
                rend.sharedMaterial = mat;
            }
        }

        var headset = Instantiate(PongPadBuilder.instance.headsetPrefab);
        var head_tr = Baroque.GetHeadTransform();

        headset.SetPositionAndRotation(head_tr.position, head_tr.rotation);
        FixMat(headset);

        foreach (var ctrl in Baroque.GetControllers())
        {
            var pad = ctrl.GetComponentInChildren <PongPad>();
            if (pad != null)
            {
                pad = Instantiate(pad, headset, worldPositionStays: true);
                Destroy((PongPad)pad.GetComponent <PongPad>());
                FixMat(pad.transform);
            }
        }

        while (!stop_instruction[0])
        {
            yield return(null);

            var col = mat.color;
            col.a -= Time.deltaTime * 0.75f;
            if (col.a <= 0f)
            {
                break;
            }
            mat.color = col;
        }

        Destroy((GameObject)headset.gameObject);
        Destroy(mat);
    }
コード例 #10
0
    private IEnumerator Start()
    {
        cells = new Dictionary <Vector3Int, Transform>();

        Vector2 size;

        while (!Baroque.TryGetPlayAreaSize(out size))
        {
            yield return(null);
        }

#if false
        /* for testing various play area sizes */
        Vector3 size3 = playArea.transform.GetChild(0).localScale;
        size.x = size3.x;
        size.y = size3.z;
        for (int z = 0; z < nz; z++)
        {
            for (int y = 0; y < ny; y++)
            {
                for (int x = 0; x < nx; x++)
                {
                    SetCell(new Vector3Int(x, y, z), 10);
                }
            }
        }
#endif

        Vector2 current_size = new Vector2(transform.localScale.x * (nx + 0.7f), transform.localScale.z * (nz + 1));
        float   factor       = Mathf.Min(size.x / current_size.x, size.y / current_size.y);
        factor *= 0.8f;
        if (factor < 1)
        {
            transform.localScale *= factor;
        }

        Vector3 center = transform.TransformPoint(new Vector3((nx - 1) * 0.5f, 0, nz * 0.5f));
        center.y            = 0;
        transform.position -= center;

        yield return(null);
        //Shader.WarmupAllShaders();
    }
コード例 #11
0
    void SelectedLevel(LevelBox level_box, Vector3 hitpoint)
    {
        gameObject.SetActive(false);
        foreach (var ctrl in Baroque.GetControllers())
        {
            ctrl.SetControllerHints(/*nothing*/);
        }

        foreach (var mines1 in FindObjectsOfType <Mines>())
        {
            mines1.Unpopulate();
        }

        var mines = level_box.correspondingMines;

        for (int z = 0; z < mines.nz; z++)
        {
            for (int y = 0; y < mines.ny; y++)
            {
                for (int x = 0; x < mines.nx; x++)
                {
                    var sgt = Instantiate(sgtPrefab);
                    sgt.mines     = mines;
                    sgt.targetInt = new Vector3Int(x, y, z);

                    sgt.GetComponent <MeshRenderer>().sharedMaterial = level_box.correspondingMines.defaultMat;

                    sgt.transform.localScale    = level_box.particleSys.main.startSize.constant * Vector3.one;
                    sgt.transform.localPosition = hitpoint + Random.insideUnitSphere * 0.5f;
                }
            }
        }

        foreach (var laser in lasers)
        {
            if (laser != null && laser.tr != null)
            {
                Destroy(laser.tr.gameObject);
            }
        }
        lasers = null;
    }
コード例 #12
0
    public static void AddPoints(Vector3 position, Color color, int count, float points_size = 0f)
    {
        Quaternion rot = Quaternion.LookRotation(position - Baroque.GetHeadTransform().position);

        rot.eulerAngles += Random.insideUnitSphere * 10f;

        var b = PongPadBuilder.instance;
        var p = Instantiate(b.canvasPointsPrefab, position, rot);

        p.text.text  = count.ToString();
        p.text.color = color;
        if (points_size > 1f)
        {
            p.transform.localScale *= points_size;
        }

        if (total_points_color == new Color())
        {
            total_points_color = b.totalPointsText.color;
        }

        UpdateTotalPoints(count);
        b.StartCoroutine(_Blink());

        IEnumerator _Blink()
        {
            float fraction = 0.75f;

            while (true)
            {
                b.totalPointsText.color = Color.Lerp(total_points_color, color, fraction);
                if (fraction <= 0f)
                {
                    break;
                }
                yield return(null);

                fraction -= Time.deltaTime;
            }
        }
    }
コード例 #13
0
    // Update is called once per frame
    void OnTriggerDown(Controller controller)
    {
        if (!popup.enabled)
        {
            // determine direction
            Vector3 head_forward = controller.position - Baroque.GetHeadTransform().position;
            Vector3 fw           = controller.forward + head_forward.normalized;
            fw.y = 0;
            Vector3 handposition = controller.position + (0.05f * fw);

            // move numpad
            popup.transform.position = handposition;
            popup.transform.rotation = Quaternion.LookRotation(fw);
        }

        // flip enable
        popup.enabled = !popup.enabled;

        // flip visibility
        var popupRenderer = popup.GetComponent <Canvas>();

        popupRenderer.enabled = !popupRenderer.enabled;
    }
コード例 #14
0
    IEnumerator EndGame()
    {
        FadeOutSounds(0.8f);
        //levelEndSound.Play();

        Scores.NewScore(episodeNumber, _total_points);

        float f          = 0f;
        float t0         = Time.time;
        int   total_emit = 250;

        while (total_emit > 0)
        {
            yield return(null);

            f += Time.deltaTime * 100f;
            while (f >= 1f)
            {
                var emit_params = new ParticleSystem.EmitParams
                {
                    position      = new Vector3(0, 1.5f, 3f) + 1.5f * Random.insideUnitSphere,
                    velocity      = new Vector3(0, 1, 0) + (Random.onUnitSphere * 0.5f),
                    startSize     = 0.1f,
                    startLifetime = Random.Range(0.2f, 0.5f),
                    startColor    = Color.white,
                };
                hitPS.Emit(emit_params, 1);
                total_emit--;
                f -= 1f;
            }
        }
        Baroque.FadeToColor(Color.black, 2f);
        yield return(new WaitForSeconds(2f));

        UnityEngine.SceneManagement.SceneManager.LoadScene("Intro");
    }
コード例 #15
0
    IEnumerator _FollowJoystick(Controller ctrl)
    {
        while (!_JoystickReleased(ctrl))
        {
            yield return(null);
        }

        while (true)
        {
            yield return(null);

            if (!ctrl.isReady)
            {
                continue;
            }

            Vector2 pos = ctrl.touchpadPosition;
            if (pos.sqrMagnitude < 0.6f * 0.6f || Mathf.Abs(pos.x) < 0.3f)
            {
                continue;
            }

            if (PongPadBuilder.paused)
            {
                continue;
            }

            /* moving the joystick! */
            if (canvasInfo != null)
            {
                Destroy((GameObject)canvasInfo);
                canvasInfo = null;
            }
            if (stop_instruction != null)
            {
                stop_instruction[0] = true;
            }
            stop_instruction = new bool[1];
            StartCoroutine(_FadeOutPadsAndHeadset(stop_instruction));

            float dir = Mathf.Sign(pos.x);
            current_angle += dir * 120f;
            if (current_angle >= 360f)
            {
                current_angle -= 360f;
            }
            else if (current_angle < 0f)
            {
                current_angle += 360f;
            }

            transform.rotation = Quaternion.Euler(0, -current_angle, 0);
            PongPadBuilder.instance.UpdateTrackingSpacePosition();
            PongPad.RestartFollowingAll();

            Baroque.FadeToColor(new Color(0.5f, 0.5f, 0.5f), 0.05f);
            yield return(new WaitForSeconds(0.05f));

            Baroque.FadeToColor(Color.clear, 0.05f);

            /* wait until we release the joystick */
            while (!_JoystickReleased(ctrl))
            {
                yield return(null);
            }
        }
    }
コード例 #16
0
    private void Update()
    {
        Vector3 direction = Baroque.GetHeadTransform().position - transform.position;

        transform.rotation = Quaternion.LookRotation(direction);
    }
コード例 #17
0
    IEnumerator _BombExplode(Vector3Int pos, Transform explosion)
    {
        Vector3 p0 = transform.TransformPoint(pos);

        playArea.smokeParticleSys.transform.position = p0;
        playArea.smokeParticleSys.Play();

        const int NUM = 1000;

        var draw_matrices   = new Matrix4x4[NUM];
        var rotate_matrices = new Matrix4x4[NUM];

        float start_time = Time.time;

        for (int i = 0; i < NUM; i++)
        {
            Quaternion q  = Random.rotationUniform;
            float      s1 = Random.Range(0.25f, 1f);
            Vector3    s  = Vector3.one * s1 * s1 * 0.3f;
            draw_matrices[i] = Matrix4x4.TRS(p0, q, s);

            q = Quaternion.LookRotation(Vector3.forward + Random.insideUnitSphere * 0.03f);
            rotate_matrices[i] = Matrix4x4.Rotate(q);

            float t = Mathf.Lerp(start_time, start_time + 0.5f, (i + 1) / (float)NUM);
            while (Time.time < t)
            {
                yield return(null);
            }
        }

        start_time = Time.time;
        Baroque.FadeToColor(Color.clear, TIME_ANIMATION);

        var mesh = new Mesh();

        mesh.vertices = new Vector3[] { new Vector3(-1, -1, -1), new Vector3(1, 1, 1) };
        mesh.SetIndices(new int[] { 0, 1 }, MeshTopology.Lines, submesh: 0, calculateBounds: true);
        var material = new Material(playArea.instanciatedColorMaterial);

        material.SetColor("_ColorMin", Color.Lerp(activeMat.color, Color.white, 0.5f));

        var t_next = Time.time;
        var a_prev = 1f;

        while (true)
        {
            float a = (Time.time - start_time) / TIME_ANIMATION;
            if (a >= 1f)
            {
                break;
            }
            a = 1 - a * a;

            Graphics.DrawMeshInstanced(mesh, 0, material, draw_matrices, NUM,
                                       null, UnityEngine.Rendering.ShadowCastingMode.Off, false);

            while (Time.time >= t_next)
            {
                float a_ratio = a / a_prev;
                a_prev = a;
                Matrix4x4 scale = Matrix4x4.Scale(Vector3.one * a_ratio);
                for (int i = 0; i < NUM; i++)
                {
                    draw_matrices[i] *= rotate_matrices[i] * scale;
                }
                t_next += 1f / 45f;
            }
            yield return(null);
        }
コード例 #18
0
    IEnumerator BombExplodeOrGameSucceeded(Vector3Int?bomb_pos = null)
    {
        interactions    = false;
        click_neighbors = null;
        foreach (var ctrl in Baroque.GetControllers())
        {
            if (ctrl.isActiveAndEnabled)
            {
                ctrl.HapticPulse();
            }
            ctrl.SetControllerHints(/*nothing*/);
        }

        playArea.clock.StopTicking();
        if (bomb_pos != null)
        {
            SetCell(bomb_pos.Value, 0);
        }

        remove_me = new List <GameObject>();

        if (bomb_pos != null)
        {
            Vector3 p0        = transform.TransformPoint(bomb_pos.Value);
            var     explosion = Instantiate(playArea.explosionPrefab);
            explosion.rotation = Quaternion.LookRotation(Baroque.GetHeadTransform().position - p0);
            explosion.position = p0 + explosion.forward * 0.05f;

            yield return(new WaitForSeconds(0.1f));

            Destroy(explosion.gameObject);

            var bomb = Instantiate(playArea.explodedBombPrefab, transform);
            bomb.position   = p0;
            bomb.localScale = Vector3.one;
            remove_me.Add(bomb.gameObject);

            yield return(new WaitForSeconds(0.3f));

            playArea.smokeParticleSys.transform.position = p0;
            playArea.smokeParticleSys.Play();

            yield return(new WaitForSeconds(0.6f));
        }
        else
        {
            yield return(new WaitForSeconds(0.5f));

            var main = playArea.successParticleSys.main;
            main.startColor = activeMat.color;

            /* ^^^ XXX waaaat "main" is a struct, but it's still how you change parameters.  You
             * assign a value to the struct.  There's a magic setter property that will actually
             * have an effect on the original particle system.  Because if it was a normal struct,
             * such a field assignment would be lost after we forget about the 'main' local variable.
             */
            playArea.successParticleSys.Play();
        }
        playArea.selectLevel.SetActive(true);
        if (bomb_pos == null && playArea.clock.seconds > 0)
        {
            playArea.selectLevel.GetComponent <SelectLevel>().WriteNewScore(this, playArea.clock.seconds);
        }

        foreach (var ub in GetUnknownBoxes())
        {
            if (bombs.Contains(ub.position))
            {
                var bomb = Instantiate(playArea.bombPrefab, transform);
                bomb.localPosition = ub.position;
                bomb.localScale    = Vector3.one;
                remove_me.Add(bomb.gameObject);

                if (bomb_pos == null)
                {
                    bomb.localScale *= 0.45f;
                    ub.WinkOut();
                }
            }
            else
            if (bomb_pos != null && ub.probablyBomb)
            {
                ub.WinkOut(show_empty: true);
            }
        }
    }
コード例 #19
0
    protected override void AddPointersOnPausedExplicit()
    {
        foreach (var coll in pausedCanvasGobj.GetComponentsInChildren <BoxCollider>())
        {
            coll.GetComponent <UnityEngine.UI.Text>().color = new Color(0.9f, 0.9f, 0.9f);
        }

        foreach (var ctrl in Baroque.GetControllers())
        {
            if (ctrl.isReady)
            {
                var expl = ctrl.GetAdditionalData(ref expls);
                if (expl.cylinder_tr == null)
                {
                    var gobj = Instantiate(pausedPointerPrefab, ctrl.transform);
                    expl.cylinder_tr = gobj.transform.GetChild(0);
                }

                const float Z_MAX = 0.75f;
                float       z     = Z_MAX;

                Collider click = null;
                if (Physics.Raycast(ctrl.transform.position, ctrl.transform.forward, out var hitInfo, 2 * Z_MAX,
                                    layerMask: 1 << IntroPointer.LAYER_SELECTION))
                {
                    click = hitInfo.collider;
                }

                if (click != null && (expl.clicking_button == null || expl.clicking_button == click))
                {
                    var text = hitInfo.collider.GetComponent <UnityEngine.UI.Text>();
                    if (expl.clicking_button == null)
                    {
                        text.color = new Color(1f, 0.7f, 0.7f);
                    }
                    else
                    {
                        text.color = new Color(1f, 0.45f, 0.45f);
                    }

                    z = hitInfo.distance * 0.5f;
                }
                var cylinder_tr = expl.cylinder_tr;
                var v           = cylinder_tr.localScale; v.y = z; cylinder_tr.localScale = v;
                v = cylinder_tr.localPosition; v.z = z; cylinder_tr.localPosition = v;

                if (ctrl.triggerPressed)
                {
                    if (expl.clicking_button == null)
                    {
                        expl.clicking_button = click;
                    }
                    //expl.menu_press = 0;
                }
                else if (expl.clicking_button != null && expl.clicking_button == click)
                {
                    SetPausedExplicit(false);
                    if (click.gameObject.name == "EXIT")
                    {
                        Scores.NewScore(episodeNumber, _total_points);
                        UnityEngine.SceneManagement.SceneManager.LoadScene("Intro");
                    }
                    break;
                }
                else
                {
                    expl.clicking_button = null;

                    /*if (ctrl.touchpadPressed || ctrl.menuPressed)
                     * {
                     *  if (expl.menu_press == 1)
                     *      expl.menu_press = 2;
                     * }
                     * else if (expl.menu_press == 2)
                     * {
                     *  SetPausedExplicit(false);
                     *  break;
                     * }
                     * else
                     *  expl.menu_press = 1;*/
                }
            }
        }
    }
コード例 #20
0
    private void Gt_onControllersUpdate(Controller[] controllers)
    {
        foreach (var level_box in GetComponentsInChildren <LevelBox>())
        {
            level_box.SetHighlight(0);
        }

        foreach (var ctrl in Baroque.GetControllers())    /* includes inactive ones */
        {
            var laser = ctrl.GetAdditionalData(ref lasers);

            if (!ctrl.isActiveAndEnabled)
            {
                if (laser.tr != null)
                {
                    Destroy(laser.tr.gameObject);
                    laser.tr = null;
                }
            }
            else
            {
                if (laser.tr == null)
                {
                    laser.tr = Instantiate(laserPrefab);
                    laser.q  = ctrl.rotation;
                    successParticleSys.trigger.SetCollider(ctrl.index, laser.tr.GetComponentInChildren <Collider>());
                }
                laser.q = Quaternion.Lerp(ctrl.rotation, laser.q, Mathf.Exp(-Time.deltaTime * 50));

                laser.tr.position = ctrl.position;
                laser.tr.rotation = laser.q;

                RaycastHit hitinfo;
                LevelBox   level_box = null;
                float      distance  = 5f;
                if (Physics.SphereCast(laser.tr.position, 0.01f, laser.tr.forward, out hitinfo, 10f,
                                       1 << LevelBox.LAYER, QueryTriggerInteraction.Ignore))
                {
                    level_box = hitinfo.collider.GetComponentInParent <LevelBox>();
                    distance  = Vector3.Distance(ctrl.position, hitinfo.point);
                }
                var     tr0 = laser.tr.GetChild(0);
                Vector3 p   = tr0.localScale;
                p.y            = distance * 0.5f;
                tr0.localScale = p;
                p   = tr0.localPosition;
                p.z = distance * 0.5f + 0.07f;
                tr0.localPosition = p;

                Color c = level_box == null ? new Color(0.3f, 0.3f, 0.3f) :
                          ctrl.triggerPressed ? new Color(1f, 1f, 1f) : level_box.laserColor;
                laser.tr.GetComponentInChildren <Renderer>().material.color = c;

                if (level_box != null)
                {
                    level_box.SetHighlight((ctrl.triggerPressed | laser.trigger_pressed) ? 2 : 1);

                    if (laser.trigger_pressed && !ctrl.triggerPressed)
                    {
                        SelectedLevel(level_box, hitinfo.point);
                        ctrl.HapticPulse();
                        break;
                    }

                    float cur_time  = Time.time;
                    float prev_time = cur_time - Time.deltaTime;

                    int n1 = (int)(prev_time * particlesPerSecond);
                    int n2 = (int)(cur_time * particlesPerSecond);

                    if (n2 > n1)
                    {
                        ParticleSystem.EmitParams emit_params = new ParticleSystem.EmitParams
                        {
                            position             = hitinfo.point,
                            applyShapeToPosition = true,
                            startColor           = level_box.laserColor,
                        };
                        level_box.particleSys.Emit(emit_params, n2 - n1);
                    }
                    if (laser.level_box != level_box)
                    {
                        ctrl.HapticPulse();
                    }
                }
                laser.level_box       = level_box;
                laser.trigger_pressed = ctrl.triggerPressed;

                ctrl.SetControllerHints(trigger: "choose level");
            }
        }
    }