Beispiel #1
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);
    }
Beispiel #2
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);
            }
        }
    }