Example #1
0
    void UpdatePatternator()
    {
        int current_action_id = m_currentActionId;

        for (int i = 0; i < m_actions.Count; ++i)
        {
            SActionElement ae = m_actions[i];
            if (ae.time > m_playHead)
            {
                m_nextActionId = i;
                break;
            }
            else
            {
                current_action_id = i;
            }
        }
        if (current_action_id > m_currentActionId)
        {
            // Action happened: current_action_id
            SActionElement ae = m_actions[current_action_id];
            if (ae.type == EElement.Click)
            {
                Debug.Log("Summon: CLICK");
                GameObject go = Instantiate(m_clickElementPrefab, transform.position, Quaternion.identity);
                go.GetComponent <ClickElement>().Initialize(new Vector3(ae.x, ae.y, 0.0f), m_reactionTime);
            }
            else if (ae.type == EElement.Line)
            {
                Debug.Log("Summon: LINE");
                GameObject[] go =
                {
                    Instantiate(m_clickElementPrefab, transform.position, Quaternion.identity),
                    Instantiate(m_clickElementPrefab, transform.position, Quaternion.identity),
                    Instantiate(m_clickElementPrefab, transform.position, Quaternion.identity),
                    Instantiate(m_clickElementPrefab, transform.position, Quaternion.identity)
                };
                float w = m_boundary.size.x;
                float y = UnityEngine.Random.Range(m_boundary.min.y, m_boundary.max.y);
                for (int i = 0; i < 4; ++i)
                {
                    float delay = (float)m_bpmPeriod * (float)i;
                    float x     = m_boundary.min.x + (w * (float)i / 3.0f);
                    go[i].GetComponent <ClickElement>().Initialize(new Vector3(x, y, 0.0f), m_reactionTime, delay);
                }
            }
            else if (ae.type == EElement.ZigZag)
            {
                Debug.Log("Summon: ZIGZAG");
                GameObject[] go =
                {
                    Instantiate(m_clickElementPrefab, transform.position, Quaternion.identity),
                    Instantiate(m_clickElementPrefab, transform.position, Quaternion.identity),
                    Instantiate(m_clickElementPrefab, transform.position, Quaternion.identity),
                    Instantiate(m_clickElementPrefab, transform.position, Quaternion.identity)
                };
                GameObject line = Instantiate(m_connectorPrefab, new Vector3(0.0f, 0.0f, 2.5f), Quaternion.identity);
                line.transform.localPosition = new Vector3(0.0f, 0.0f, 15.0f);
                LineRenderer lrendr = line.GetComponent <LineRenderer>();
                lrendr.positionCount = 4;
                Assert.IsTrue(lrendr != null);
                float w = m_boundary.size.x - 1.0f;
                float h = m_boundary.size.y;
                for (int i = 0; i < 4; ++i)
                {
                    float   delay = (float)m_bpmPeriod * (float)i;
                    float   side  = i == 1 || i == 3? -1.0f : 1.0f;
                    float   x     = (side * (m_boundary.max.x - 1.0f)) - 0.5f;
                    float   y     = m_boundary.max.y - (h * (float)i / 3.0f) - 0.5f;
                    Vector3 pos   = new Vector3(x, y, 0.0f);
                    go[i].GetComponent <ClickElement>().Initialize(pos, m_reactionTime, delay);
                    lrendr.SetPosition(i, pos);
                }
                GameObject.Destroy(line, m_reactionTime + ((float)m_bpmPeriod * 4.0f));
            }
            else if (ae.type == EElement.Ladder)
            {
                Debug.Log("Summon: LADDER");
                GameObject[] go =
                {
                    Instantiate(m_clickElementPrefab, transform.position, Quaternion.identity),
                    Instantiate(m_clickElementPrefab, transform.position, Quaternion.identity),
                    Instantiate(m_clickElementPrefab, transform.position, Quaternion.identity),
                    Instantiate(m_clickElementPrefab, transform.position, Quaternion.identity)
                };
                GameObject line = Instantiate(m_connectorPrefab, new Vector3(0.0f, 0.0f, 2.5f), Quaternion.identity);
                line.transform.localPosition = new Vector3(0.0f, 0.0f, 15.0f);
                LineRenderer lrendr = line.GetComponent <LineRenderer>();
                lrendr.positionCount = 4;
                Assert.IsTrue(lrendr != null);
                float w = m_boundary.size.x;
                float h = m_boundary.size.y;
                for (int i = 0; i < 4; ++i)
                {
                    float   delay = (float)m_bpmPeriod * (float)i;
                    float   x     = m_boundary.min.x + (w * (float)i / 3.0f);
                    float   y     = m_boundary.min.y + (h * (float)i / 3.0f);
                    Vector3 pos   = new Vector3(x, y, 0.0f);
                    go[i].GetComponent <ClickElement>().Initialize(pos, m_reactionTime, delay);
                    lrendr.SetPosition(i, pos);
                }
                GameObject.Destroy(line, m_reactionTime + ((float)m_bpmPeriod * 4.0f));
            }
            else if (ae.type == EElement.UpDown)
            {
                GameObject[] go =
                {
                    Instantiate(m_clickElementPrefab, transform.position, Quaternion.identity),
                    Instantiate(m_clickElementPrefab, transform.position, Quaternion.identity),
                    Instantiate(m_clickElementPrefab, transform.position, Quaternion.identity),
                    Instantiate(m_clickElementPrefab, transform.position, Quaternion.identity)
                };
                GameObject line = Instantiate(m_connectorPrefab, new Vector3(0.0f, 0.0f, 2.5f), Quaternion.identity);
                line.transform.localPosition = new Vector3(0.0f, 0.0f, 15.0f);
                LineRenderer lrendr = line.GetComponent <LineRenderer>();
                lrendr.positionCount = 4;
                Assert.IsTrue(lrendr != null);
                float w = m_boundary.size.x - 1.0f;
                for (int i = 0; i < 4; ++i)
                {
                    float   delay = (float)m_bpmPeriod * (float)i;
                    float   x     = (m_boundary.max.x - 0.5f) - (w * (float)i / 3.0f);
                    float   side  = i == 1 || i == 3? -1.0f : 1.0f;
                    float   yy    = (side * (m_boundary.max.y - 1.0f)) - 0.5f;
                    Vector3 pos   = new Vector3(x, yy, 0.0f);
                    go[i].GetComponent <ClickElement>().Initialize(pos, m_reactionTime, delay);
                    lrendr.SetPosition(i, pos);
                }
                GameObject.Destroy(line, m_reactionTime + ((float)m_bpmPeriod * 4.0f));
            }
        }
        m_currentActionId = current_action_id;
    }
Example #2
0
    void InitPatternator()
    {
        Assert.IsTrue(m_patternList != null && m_patternList.Count > 0);
        m_actions          = new List <SActionElement>();
        m_reactionTime     = 4.0f;
        m_totalClicksCount = 0;
        int quadrant = 0;         // used to avoid randomly overlapping simple clicks

        foreach (SPatternEntry pe in m_patternList)
        {
            // Support for type 0 first
            Assert.IsTrue(pe.time > m_reactionTime);             // Just in case
            if (pe.time > m_reactionTime)
            {
                SActionElement ae = new SActionElement();
                ae.time = pe.time - m_reactionTime;
                // Simple Click
                if (pe.pattern == 0)
                {
                    m_totalClicksCount += 1;
                    ae.type             = EElement.Click;
                    int x_side = quadrant < 2? x_side = 1 : x_side = -1;
                    int y_side = quadrant == 1 || quadrant == 3? y_side = -1 : y_side = 1;
                    ae.x     = UnityEngine.Random.Range(0.5f * x_side, m_boundary.max.x * x_side);
                    ae.y     = UnityEngine.Random.Range(0.5f * y_side, m_boundary.max.y * y_side);
                    quadrant = (quadrant + 1) % 4;
                }
                else if (pe.pattern == 1)
                {
                    m_totalClicksCount += 4;
                    ae.type             = EElement.Line;
                    // Left
                    ae.x = m_boundary.min.x;
                    ae.y = m_boundary.center.y;
                }
                else if (pe.pattern == 2)
                {
                    m_totalClicksCount += 4;
                    ae.type             = EElement.ZigZag;
                    // Left-top
                    ae.x = m_boundary.min.x;
                    ae.y = m_boundary.max.y;
                }
                else if (pe.pattern == 3)
                {
                    m_totalClicksCount += 4;
                    ae.type             = EElement.Ladder;
                    // Left-bottom
                    ae.x = m_boundary.min.x;
                    ae.y = m_boundary.min.y;
                }
                else if (pe.pattern == 4)
                {
                    m_totalClicksCount += 4;
                    ae.type             = EElement.UpDown;
                    // Right-Top
                    ae.x = m_boundary.max.x;
                    ae.y = m_boundary.max.y;
                }
                else
                {
                    // Should never get here
                    Debug.LogError("Shouldn't be here");
                    continue;
                }
                m_actions.Add(ae);                 // TEMP: remove compare once all patterns implemented
            }
        }
    }