Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        Vector3 t = transform.position;

        t.x = ParamCalculator.VanillaPositionToUnityX(NoteData.Position + NoteData.Width / 2);
        t.y = ParamCalculator.TimeToPositionY(NoteData.Time);

        if (NoteData.Direction == -1)
        {
            Vector3 pos = t;
            pos.x = t.y + 2f - 4.25f;
            pos.y = t.x * 9f / 16f * 0.8f;
            transform.localRotation = Quaternion.Euler(0f, 0f, -90f);
            transform.position      = pos;
        }
        else if (NoteData.Direction == 1)
        {
            Vector3 pos = t;
            pos.x = -t.y - 2f + 4.255f;
            pos.y = t.x * 9f / 16f * 0.8f;
            transform.localRotation = Quaternion.Euler(0f, 0f, 90f);
            transform.position      = pos;
        }
        else
        {
            transform.position      = t;
            transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
        }
    }
Ejemplo n.º 2
0
    public static GameObject NewNote(string path, int timedelta = 0, bool regundo = false)
    {
        GameObject go = GameObject.Instantiate(Resources.Load <GameObject> (path));
        NoteData   nd = go.GetComponent <NoteData> ();

        nd.Direction          = GridManager.Instance.GridDir;
        go.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector3 tmp = go.transform.position;

        tmp.z = 0;
        if (GridManager.Instance.GridDir == 1)
        {
            tmp.x = go.transform.position.y / 9f * 16f / 0.8f;
            tmp.y = -go.transform.position.x + 4.255f - 2f;
        }
        else if (GridManager.Instance.GridDir == -1)
        {
            tmp.x = go.transform.position.y / 9f * 16f / 0.8f;
            tmp.y = go.transform.position.x + 4.25f - 2f;
        }
        go.transform.position = tmp;
        nd.Position           = ParamCalculator.UnityXToVanillaPosition(tmp.x) - nd.Width / 2;
        nd.Time        = ParamCalculator.PositionYToTime(tmp.y) + timedelta;
        nd.Width       = WidthStore [WidthStoreN];
        nd.InnerID     = ++AtomicCounter;
        nd.NotifyWidth = true;
        go.GetComponent <NoteSelection> ().ShouldAttachGridY = true;
        if (regundo)
        {
            UndoSystem.RegisterUndo(new UndoSystem.CreateNoteUndoAction(nd, path));
        }
        return(go);
    }
Ejemplo n.º 3
0
    public static void AddNotes(XmlElement element, List <NoteData> notes)
    {
        for (var i = 0; i < notes.Count; i++)
        {
            NoteData note = notes [i];

            XmlElement e = element.OwnerDocument.CreateElement("CMapNoteAsset");

            XmlElement id = element.OwnerDocument.CreateElement("m_id");
            id.InnerText = i.ToString();
            e.AppendChild(id);

            XmlElement ty = element.OwnerDocument.CreateElement("m_type");
            ty.InnerText = note.NoteType;
            e.AppendChild(ty);

            XmlElement ti = element.OwnerDocument.CreateElement("m_time");
            ti.InnerText = ParamCalculator.TimeToBar(note.Time).ToString("0.00000");
            e.AppendChild(ti);

            XmlElement po = element.OwnerDocument.CreateElement("m_position");
            po.InnerText = note.Position.ToString("0.00000");
            e.AppendChild(po);

            XmlElement wi = element.OwnerDocument.CreateElement("m_width");
            wi.InnerText = note.Width.ToString("0.00000");
            e.AppendChild(wi);

            XmlElement su = element.OwnerDocument.CreateElement("m_subId");
            su.InnerText = note.Sub ? notes.IndexOf(note.Sub).ToString() : "-1";
            e.AppendChild(su);

            element.AppendChild(e);
        }
    }
Ejemplo n.º 4
0
    public static GameObject ReadNote2(XmlNodeList list, XmlNode node)
    {
        GameObject go = null;
        NoteData   nd = null;

        Debug.Log(node.OuterXml);
        switch (node.SelectSingleNode("m_type").InnerText)
        {
        case "SUB":
        case "3":
            go = GameObject.Instantiate(Resources.Load <GameObject> ("NoteHoldSub"));
            int id = int.Parse(node.SelectSingleNode("m_id").InnerText);
            SubsToRefer [id].Sub = go.GetComponent <NoteData> ();

            GameObject render = GameObject.Instantiate(Resources.Load <GameObject> ("NoteHold"));
            render.GetComponent <HoldScaling> ().Begin = SubsToRefer [id].transform;
            render.GetComponent <HoldScaling> ().End   = SubsToRefer [id].Sub.transform;

            SubsToRefer.Remove(id);
            break;

        default:
            return(null);
        }
        nd             = go.GetComponent <NoteData> ();
        nd.Position    = float.Parse(node.SelectSingleNode("m_position").InnerText);
        nd.Width       = float.Parse(node.SelectSingleNode("m_width").InnerText);
        nd.Time        = ParamCalculator.BarToTime(float.Parse(node.SelectSingleNode("m_time").InnerText));
        nd.InnerID     = ++HotkeySystem.AtomicCounter;
        nd.NotifyWidth = true;
        return(go);
    }
Ejemplo n.º 5
0
    void Judge()
    {
        foreach (var sr in GetComponentsInChildren <SpriteRenderer> ())
        {
            sr.enabled = false;
        }
        GameObject pf = Instantiate(Resources.Load <GameObject> ("EffectPerfect"));
        Vector3    v;

        switch (mData.Direction)
        {
        case 0:
            v   = transform.position;
            v.y = -0.52f;
            pf.transform.position = v;
            break;

        case -1:
        case 1:
            v   = transform.position;
            v.x = 2.79f * mData.Direction;
            pf.transform.position = v;
            break;
        }
        pf.transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles);
        Vector3 pls = transform.localScale;

        pls.y = 1;
        pls.x = 1.25f * ParamCalculator.VanillaWidthToScaleX(mData.Width) * 0.5f * (mData.Direction != 0 ? 9f / 16f * 0.8f : 1f);
        pf.transform.localScale = pls;
        Judged = true;
    }
Ejemplo n.º 6
0
    public void AttachToGridX()
    {
        if (GridManager.Instance.NumRows <= 0)
        {
            return;
        }
        dataBefore = new UndoSystem.NoteDataBefore(mData);
        float minabs = int.MaxValue;
        float pos    = mData.Position;

        for (int i = 0; i < GridManager.GridCols.Count; i++)
        {
            float curtime = GridManager.GridCols [i].Time;
            curtime /= 1000f;
            curtime  = ParamCalculator.UnityXToVanillaPosition(curtime);
            if (mData.Direction != 0)
            {
                curtime = curtime * 1.25f - 0.625f;
            }
            curtime -= mData.Width / 2f;
            if (Mathf.Abs(curtime - mData.Position) < minabs)
            {
                minabs = Mathf.Abs(curtime - mData.Position);
                pos    = curtime;
            }
        }
        mData.Position = pos;
        UndoSystem.RegisterUndo(new UndoSystem.NoteDataChangeUndoAction(mData, dataBefore, new UndoSystem.NoteDataBefore(mData)));
    }
Ejemplo n.º 7
0
    void INoteScaling.NoteChanged(float position, float width, int direction)
    {
        Vector3 t;

        t   = transform.localScale;
        t.x = ParamCalculator.VanillaWidthToScaleX(width) * 0.5f * (direction != 0 ? 9f / 16f : 1f);
        transform.localScale = t;
    }
Ejemplo n.º 8
0
    void UpdateHorizons()
    {
        if (Mathf.Abs(GridDir) > 1)
        {
            foreach (var line in GridLines)
            {
                line.Time = int.MinValue;
                line.Transform.position = new Vector3(-100, -100, -1);
            }
            return;
        }
        double STEP    = (ParamCalculator.BarToTime(1000f) - ParamCalculator.BarToTime(0f)) * BeatPerRow / 4000f;
        double MAXTIME = (int)((TimeControlSystem.CurrentTimeMillis + 1000) / STEP) * STEP;
        double MINTIME = (int)((TimeControlSystem.CurrentTimeMillis - 700) / STEP) * STEP;
        IEnumerator <TimeTransformPair> horis;

        int c = 0;

        for (double i = MINTIME; i < MAXTIME; i += STEP)
        {
            c++;
        }
        for (int i = GridLines.Count; i < c; i++)
        {
            Transform n = Instantiate(Resources.Load <GameObject> ("UI/GridLineHorizon"), transform).transform;
            GridLines.Add(new TimeTransformPair(0, n));
        }

        horis = GridLines.GetEnumerator();
        for (double i = MINTIME; i < MAXTIME; i += STEP)
        {
            if (!horis.MoveNext())
            {
                continue;
            }
            horis.Current.Time = (int)i;
            horis.Current.Transform.position = new Vector3(0, ParamCalculator.TimeToPositionY((int)i), -1);
            horis.Current.Transform.rotation = Quaternion.Euler(0, 0, 0);
            horis.Current.Transform.GetComponent <LineRenderer> ().startColor = DirColors [GridDir + 1];
            horis.Current.Transform.GetComponent <LineRenderer> ().endColor   = DirColors [GridDir + 1];
            if (GridDir != 0)
            {
                horis.Current.Transform.rotation = Quaternion.Euler(0, 0, 90);
                Vector3 v   = horis.Current.Transform.position;
                Vector3 pos = horis.Current.Transform.position;
                pos.x  = -v.y - 2f + 4.25f;
                pos.x *= GridDir;
                pos.y  = 0;
                horis.Current.Transform.position = pos;
            }
        }
        while (horis.MoveNext())
        {
            horis.Current.Time = int.MinValue;
            horis.Current.Transform.position = new Vector3(-100, -100, -1);
        }
    }
Ejemplo n.º 9
0
    void INoteScaling.NoteChanged(float position, float width, int direction)
    {
        Vector3 t;

        t                = Left.localScale;
        t.x              = ParamCalculator.VanillaWidthToScaleX(width) * 50f / 29f - 21f / 29f;
        Left.localScale  = t;
        Right.localScale = t;

        t   = Left.localPosition;
        t.x = -0.445f - 0.22f * Left.localScale.x;
        Left.localPosition = t;

        t   = Right.localPosition;
        t.x = 0.445f + 0.22f * Right.localScale.x;
        Right.localPosition = t;

        t   = transform.localScale;
        t.x = t.y = 0.57f * (direction != 0 ? 9f / 16f * 0.8f : 1f);
        transform.localScale = t;
    }
Ejemplo n.º 10
0
    public static GameObject ReadNote1(XmlNodeList list, XmlNode node)
    {
        GameObject go = null;
        NoteData   nd = null;

        Debug.Log(node.OuterXml);
        switch (node.SelectSingleNode("m_type").InnerText)
        {
        case "NORMAL":
        case "0":
            go = GameObject.Instantiate(Resources.Load <GameObject> ("NoteNormal"));
            break;

        case "CHAIN":
        case "1":
            go = GameObject.Instantiate(Resources.Load <GameObject> ("NoteChain"));
            break;

        case "HOLD":
        case "2":
            go = GameObject.Instantiate(Resources.Load <GameObject> ("NoteHoldHold"));
            int sub = int.Parse(node.SelectSingleNode("m_subId").InnerText);
            SubsToRefer.Add(sub, go.GetComponent <NoteData> ());
            break;

        case "SUB":
        case "3":
            return(null);
        }
        nd             = go.GetComponent <NoteData> ();
        nd.Position    = float.Parse(node.SelectSingleNode("m_position").InnerText);
        nd.Width       = float.Parse(node.SelectSingleNode("m_width").InnerText);
        nd.Time        = ParamCalculator.BarToTime(float.Parse(node.SelectSingleNode("m_time").InnerText));
        nd.InnerID     = ++HotkeySystem.AtomicCounter;
        nd.NotifyWidth = true;
        return(go);
    }
Ejemplo n.º 11
0
    IEnumerator do_Update()
    {
        if (ShouldAttachGridX)
        {
            ShouldAttachGridX = false;
            AttachToGridX();
        }
        if (ShouldAttachGridY)
        {
            ShouldAttachGridY = false;
            AttachToGridY();
        }
        if (mData.Direction == 0)
        {
            Hitbox = new Rect(transform.position.x - transform.localScale.x, transform.position.y - transform.localScale.y * 0.32f, transform.localScale.x * 2, transform.localScale.y * 2 * 0.32f);
        }
        else
        {
            Hitbox = new Rect(transform.position.x - transform.localScale.y * 0.32f, transform.position.y - transform.localScale.x, transform.localScale.y * 2 * 0.32f, transform.localScale.x * 2);
        }

        if ((Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt)))
        {
            if (JudgeContain())
            {
                if (Input.GetMouseButton(0))
                {
                    AttachToGridX();
                }
                if (Input.GetMouseButton(1))
                {
                    AttachToGridY();
                }
            }
            yield break;
        }
        lastClick += Time.deltaTime;

        if (MouseInterfaceID == -1 && Input.GetMouseButton(0) && GridManager.Instance.GridDir == mData.Direction && JudgeContain() && !TimeControlSystem.isPlaying)
        {
            if (lastClick < 0.33f)
            {
                Debug.Log(1);
                Instantiate(Resources.Load <GameObject> ("UI/NoteDataEdit"), HotkeySystem.Instance.Canvas.transform).GetComponent <NoteDataEdit> ().Editing = mData;
                MouseInterfaceID = -2;
            }
            else
            {
                MouseInterfaceID = Mathf.Abs(GetHashCode());
                IsSelected       = true;
                dataBefore       = new UndoSystem.NoteDataBefore(mData);

                mIndicator           = Instantiate(Resources.Load <GameObject> ("RectLines")).GetComponent <RectLines> ();
                mIndicator.Rectangle = Hitbox;
                mIndicator.LineWidth = 0.05f;
            }
            lastClick = 0;
        }
        if (MouseInterfaceID == Mathf.Abs(GetHashCode()))
        {
            mIndicator.Rectangle = Hitbox;
            if (!Input.GetMouseButton(0) || GridManager.Instance.GridDir != mData.Direction)
            {
                MouseInterfaceID = -1;
                IsSelected       = false;

                mIndicator.NeedsDestroy = true;
                AttachToGridY();
                UndoSystem.RegisterUndo(new UndoSystem.NoteDataChangeUndoAction(mData, dataBefore, new UndoSystem.NoteDataBefore(mData)));
            }
        }
        if (MouseInterfaceID == -1 && Input.GetMouseButtonDown(1) && JudgeContain())
        {
            MouseInterfaceID = Mathf.Abs(GetHashCode());

            yield return(new WaitForEndOfFrame());

            Destroy(gameObject);
            if (mData.NoteType != "HOLD" && mData.NoteType != "SUB")
            {
                UndoSystem.RegisterUndo(new UndoSystem.CreateNoteUndoAction(mData, name.Split('(') [0], false));
            }
            else if (mData.Sub != null)
            {
                UndoSystem.RegisterUndo(new UndoSystem.HoldCreateUndoAction(mData, mData.Sub, false));
            }
        }
        if (IsSelected)
        {
            if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
            {
                mData.Width += Input.GetAxis("Mouse Y") * 0.8f;
                if (mData.Width < 0.05f)
                {
                    mData.Width = 0.05f;
                }
                else
                {
                    mData.Position -= Input.GetAxis("Mouse Y") * 0.4f;
                }
            }
            else
            {
                float UNX;
                float UNY;
                if (mData.Direction == 0)
                {
                    UNX = transform.position.x + Input.GetAxis("Mouse X");
                    UNY = transform.position.y + Input.GetAxis("Mouse Y");
                }
                else if (mData.Direction == 1)
                {
                    UNX = (transform.position.y + Input.GetAxis("Mouse Y")) / 9f * 16f / 0.8f;
                    UNY = -(transform.position.x + Input.GetAxis("Mouse X")) + 4.255f - 2f;
                }
                else
                {
                    UNX = (transform.position.y + Input.GetAxis("Mouse Y")) / 9f * 16f / 0.8f;
                    UNY = (transform.position.x + Input.GetAxis("Mouse X")) + 4.25f - 2f;
                }
                mData.Position = ParamCalculator.UnityXToVanillaPosition(UNX) - mData.Width / 2;
                mData.Time     = ParamCalculator.PositionYToTime(UNY);
            }
        }
    }