示例#1
0
    void Update()
    {
        synchronizedInvoke.ProcessQueue();

        if (!SceneHandler.Instance.Active)
        {
            return;
        }

        if (selectedScript != null && selectedScript.codeUI != null && selectedScript.caret != null)
        {
            HandleTextInput();
            HandleSpecialInput();

            BlinkCaret();
            setCaret();

            UpdateEditor();
        }

        if (Input.GetKeyDown(KeyCode.S) && SceneHandler.ControlOperatorDown())
        {
            SaveAndClose();
        }
    }
示例#2
0
    void Update()
    {
        if (!SceneHandler.Instance.Active)
        {
            return;
        }

        synchronizedInvoke.ProcessQueue();

        if (Input.GetKeyDown(KeyCode.S) && SceneHandler.ControlOperatorDown())
        {
            SaveAndClose();
        }
    }
 void Update()
 {
     synchronizedInvoke.ProcessQueue();
 }
示例#4
0
    void Update()
    {
        m_synchronizeInvoke.ProcessQueue();


        if (m_exitScheduled)
        {
            ApplicationQuit();
        }


        if (Input.GetKeyDown(KeyCode.Escape))
        {
        }
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            Debug.Log("Mame Update()");
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
        }
        if (Input.GetKeyDown(KeyCode.C))
        {
            m_showController = !m_showController;
        }
        if (Input.GetKeyDown(KeyCode.Z))
        {
        }
        if (Input.GetMouseButtonDown(0))
        {
        }

        //foreach (KeyCode c in Enum.GetValues(typeof(KeyCode)).Cast<KeyCode>())
        foreach (KeyCode c in Enum.GetValues(typeof(KeyCode)))
        {
            if (Input.GetKeyDown(c))
            {
            }
            if (Input.GetKeyUp(c))
            {
            }
        }


        {
            var instance = mame.mame_machine_manager.instance();
            var osd      = instance != null ? (mcsUnity.osd_interface_Unity)instance.osd() : null;

            if (osd != null && osd.keyboard_state != null)
            {
                if (!m_keyManualOverride)
                {
                    foreach (var key in mcsUnity.osd_interface_Unity.keymap)
                    {
                        bool keyStatus = Input.GetKey(key.Key);
                        osd.keyboard_state[(int)key.Value].i = keyStatus ? 1 : 0;
                    }
                }
            }


            if (osd != null && osd.mouse_axis_state != null)
            {
                // Input.mousePosition
                // The bottom-left of the screen or window is at (0, 0). The top-right of the screen or window is at (Screen.width, Screen.height).
                // Note: Input.mousePosition reports the position of the mouse even when it is not inside the Game View

                float mouseX = Input.mousePosition.x;
                float mouseY = Input.mousePosition.y;

                mouseY = Screen.height - mouseY;

                if (mouseX >= 0 && mouseX <= Screen.width &&
                    mouseY >= 0 && mouseY <= Screen.height)
                {
                    // using ScaleAndCrop here, because I think there's a bug in the function.  It should be ScaleToFit, just like the DrawTexture() call.
                    Vector2 result = ScaleFromTo(new Vector2(Screen.width, Screen.height), new Vector2(m_win_video_window_unity.width, m_win_video_window_unity.height), ScaleMode.ScaleAndCrop);

                    float mouseXscaled = mouseX * result.x;
                    float mouseYscaled = mouseY * result.y;
                    float widthScaled  = Screen.width * result.x;
                    float heightScaled = Screen.height * result.y;

                    float emptyRegionWidth  = (widthScaled - m_win_video_window_unity.width) / 2;
                    float emptyRegionHeight = (heightScaled - m_win_video_window_unity.height) / 2;

                    //Debug.LogFormat("{0}x{1} - {2}", mouseX, mouseY, result);
                    //Debug.LogFormat("Mouse: {0}x{1} - {2} - {3} - {4} - {5} - {6}", result.x, result.y, mouseXscaled, Screen.width, m_win_video_window_unity.width, widthScaled, emptyRegionWidth);

                    bool outside = false;
                    if (mouseXscaled < emptyRegionWidth || mouseXscaled > (m_win_video_window_unity.width + emptyRegionWidth))
                    {
                        outside = true;
                        //Debug.LogFormat("Mouse outside region: {0}", mouseXscaled);
                    }

                    if (mouseYscaled < emptyRegionHeight || mouseYscaled > (m_win_video_window_unity.height + emptyRegionHeight))
                    {
                        outside = true;
                        //Debug.LogFormat("Mouse outside region: {0}", mouseYscaled);
                    }

                    if (!outside)
                    {
                        int mouseXint = (int)(mouseXscaled - emptyRegionWidth);
                        int mouseYint = (int)(mouseYscaled - emptyRegionHeight);

                        //Console.WriteLine("Form1_MouseMove() - '{0}' - '{1}' - '{2}' - '{3}'", mouseX, mouseY, dpiX, scaleX);

                        osd.mouse_axis_state[0].i = mouseXint;
                        osd.mouse_axis_state[1].i = mouseYint;

                        osd.ui_input_push_mouse_move_event(mouseXint, mouseYint);

                        if (osd.mouse_button_state != null)
                        {
                            for (int i = 0; i < 3; i++)
                            {
                                bool mouseButton = Input.GetMouseButton(i);
                                osd.mouse_button_state[i].i = mouseButton ? 1 : 0;

                                if (i == 0)
                                {
                                    if (mouseButton)
                                    {
                                        osd.ui_input_push_mouse_down_event(mouseXint, mouseYint);
                                    }
                                    else
                                    {
                                        osd.ui_input_push_mouse_up_event(mouseXint, mouseYint);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }


        {
            var instance     = mame.mame_machine_manager.instance();
            var osd          = instance != null ? (mcsUnity.osd_interface_Unity)instance.osd() : null;
            var screenbuffer = osd != null ? osd.screenbufferptr : null;
            if (screenbuffer != null)
            {
                lock (osd.osdlock)
                {
                    if (osd.osdlock_screen_buffer_updated)
                    {
                        // https://docs.unity3d.com/ScriptReference/Texture2D.GetPixels.html

                        var pixels = m_win_video_window_unity.GetPixels32();
                        int texw   = m_win_video_window_unity.width;
                        int texh   = m_win_video_window_unity.height;

                        int stride = 400;


                        System.Random r = new System.Random();
                        for (int i = 0; i < 10; i++)
                        {
                            screenbuffer.SetUInt32(i + 200 + 100 * stride, (UInt32)(r.Next() % 16000000));
                        }

                        for (int i = 0; i < 10; i++)
                        {
                            screenbuffer.SetUInt32(i + 200 + 110 * stride, mame.rgb_t.white());
                        }


                        for (int y = 0; y < 400; y++)
                        {
                            int sourceArrayIndex = y * stride;
                            int destArrayIndex   = (texh - (y + 1)) * texw;

                            for (int x = 0; x < 400; x++)
                            {
                                UInt32 color = screenbuffer.GetUInt32(sourceArrayIndex + x);
                                pixels[destArrayIndex + x] = ToColor32((int)color);
                            }
                        }


                        m_win_video_window_unity.SetPixels32(pixels);

                        m_win_video_window_unity.Apply();

                        osd.osdlock_screen_buffer_updated = false;
                    }
                }
            }
        }
    }