Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Set Cursor Position

Discussion in 'Assets and Asset Store' started by NightmarexGR, Apr 26, 2014.

  1. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    Giveaway , the first person to post below me will get the asset for free !
    (can't participate in multiple assets of mine)
     
  2. awesomeface

    awesomeface

    Joined:
    Jul 30, 2012
    Posts:
    9
  3. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    Sending you a vouncher code in private , enjoy your free plugin :)
     
  4. AjZecrom

    AjZecrom

    Joined:
    Mar 24, 2017
    Posts:
    2
    Either make it free, or make a free no-support version. I can't afford to buy stuff from Unity, so I can do NOTHING.
     
  5. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    The plugin does exactly what it says it does, i don't remember not answering to a question ever made. Please describe me your problem or send me an email at DarknessBlade.original@gmail.com to assist you further.
     
  6. maxaud

    maxaud

    Joined:
    Feb 12, 2016
    Posts:
    177
    Hello! Interested in your plugin.

    I need to create a simulated cursor on the screen to interact with UI elements.

    I need to be able to move the cursor with a gamepad joystick. I'm sure I can code the gamepade to interact with your cursor functions but want to make sure that from what you can tell it would work for me.

    I'll also be trying it on PS4 so was curious if you knew if it supported that platform.

    Thank you.
     
  7. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    Hello maxaud , you will be able to click gui and move the mouse with a gamepad joystick but the plugin will only work on windows :/
    If you decide to buy and can't get it to work with the gamepad just pm me and i will help.
     
  8. maxaud

    maxaud

    Joined:
    Feb 12, 2016
    Posts:
    177
    Thanks for the prompt response. The PS4 compatibility is my biggest hurdle at the moment.
     
  9. MMarxDev

    MMarxDev

    Joined:
    Oct 28, 2016
    Posts:
    1
    Could you tell me a little more about the LocalPosition functions? Do they work on the position of the game window in the editor or the entire editor? Do they work on the entire window size in the windows player, or only the content area? are they normalized?
     
    NightmarexGR likes this.
  10. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    SetLocalPosition made to work flawlessly with unity-mouse-input.
    In the editor if for example you do HardwareCursor.SetLocalPosition(0,0) it will teleport the cursor to bottom left corner of Game view window. It ignores window borders.
    If you call HardwareCursor.SetLocalPosition(0,0) it ignores window borders again and sets cursor position to bottom left corner again. Moreover in the build : If you are in fullscreen mode, i have normalized the position so that it can work if you change the resolution of the screen !

    Warning Set Global position aka SetPosition to (0,0) will set cursor to Top Left corner , dont confuse the 2 coordinate systems are totally different !!

    P.S. remember to use GetPosition and GetLocalPosition to get mouse position if you need to.
     
  11. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    One last thing , remember regardless when you call SetLocalPosition and SetPosition (global) you can always set the position outside unity window you are not limited by any means.
     
  12. Daniel-Talis

    Daniel-Talis

    Joined:
    Dec 10, 2011
    Posts:
    425
    Does this plugin work with Unity 2017.1 and 2017.2 ?
     
  13. lofwyre

    lofwyre

    Joined:
    Apr 19, 2007
    Posts:
    166
    How are you going with Mac and Linux support?

    Cheers
     
  14. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    I have not tested but it should work fine. If not please send me a message with the issue.
     
  15. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    I start working for linux and mac this summer..
     
  16. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    Asset got deprecated, i contacted the unity asset store team to assist me reuploading it. Thanks for your patience
     
  17. Vecna

    Vecna

    Joined:
    Apr 2, 2014
    Posts:
    31
    Any update on it getting back on the Asset Store?
     
  18. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    We are back baby !! Finally my version was accepted and fast this time :O
     
  19. skinwalker

    skinwalker

    Joined:
    Apr 10, 2015
    Posts:
    505
    It says it only works on Windows but will it work if I build the game for Mac and Linux using my Windows PC?

    Does it work on Unity 2017.3.1 using (Experimental .Net 4.6) ?
     
  20. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    It works on (Windows Editor, Windows Build) only.
    It works 100% in Unity 2017.3.1

    EDIT: .Net 4.6 works 100% !!!
     
    Last edited: Aug 7, 2018
  21. uty6910

    uty6910

    Joined:
    Jun 22, 2018
    Posts:
    4
    Does this asset use the winapi function? I am looking for an asset that can control the cursor without using winapi.
     
  22. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    It does use Microsoft's WinForms, which will work only on windows OS. I am not completely sure if Forms are part of win api. I think they are different if you are referring to win32 api
     
  23. Wyvernn

    Wyvernn

    Joined:
    May 25, 2017
    Posts:
    3
    Hi,

    Does this still work with Unity 5?

    I'm using Unity 5.6.6f2 and your plugin works fine in the editor but when I do a Windows Standalone build I get this error:

    and

    I can confirm that System.Drawing.dll and System.Windows.Forms.dll are present in the Plugins folder and the player settings are set to .NET 2.0
     
  24. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    upload_2018-9-19_3-33-29.png
    If this is the only warning you are getting then it should work just fine.
    I just tested on unity 5.6.6f2 and it works as expected.

    If you have problems with your project just check the "output_log.txt" for clues where your error is.
    To confirm my plugin works, import it in an empty project and test build it.
     
  25. Wyvernn

    Wyvernn

    Joined:
    May 25, 2017
    Posts:
    3
    Thanks for the quick reply.
    I was mainly concerned I was using it incorrectly but if that error message is expected then that's a big weight off my mind.
    Cheers,
    Wyvernn
     
  26. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    Sure, this message is harmless you can ignore it or block it but i don't remember how.
     
  27. Bigpete591

    Bigpete591

    Joined:
    May 7, 2013
    Posts:
    59
    Does this work on the Latest Unity 2018.3?
     
  28. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    Yes it does, if you get any problems please contact me and i will fix them asap.
     
  29. lincode

    lincode

    Joined:
    May 2, 2019
    Posts:
    5
    Before buying this plugin. Could you help my to confirm if it's doable with this plugin.
    I'm working on a feature to synchronize the cursor between different players in a multiplayer game. I'm thinking to use this plugin to do that. My plan is to get the host's position of cursor and sync the position to other players in the room.
    We need to support iOS, Android, Mac and Windows. Thanks for your advice.
     
  30. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    It should be possible yes, but my plugin only works on windows OS..
     
  31. MoonwalkingBaz

    MoonwalkingBaz

    Joined:
    May 18, 2015
    Posts:
    9
    hi, did you get this working for mac?
     
  32. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    no, so far its windows only and i haven't had any opportunity to make it mac compatible since i don't own a mac yet...
     
  33. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    • got this in 2019.3.2f1
    Microsoft (R) Visual C# Compiler version 2.9.1.65535 (9d34608e)
    Copyright (C) Microsoft Corporation. All rights reserved.

    error CS1703: Multiple assemblies with equivalent identity have been imported: 'C:\2019\SkyHome\Assets\Plugins\System.Drawing.dll' and 'C:\Program Files\Unity2019.32f1\Editor\Data\NetStandard\compat\2.0.0\shims\netfx\System.Drawing.dll'. Remove one of the duplicate references.
     
  34. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    fixed in .net4X
     
    DarknessBlade likes this.
  35. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    Yes read the instructions and if you are using a unity version of 2018 and above instead of .NET 2.0 put .NET 4.x

    Thank you for posting this.
     
  36. AlienFreak

    AlienFreak

    Joined:
    Jul 2, 2012
    Posts:
    40
    For any who want to roll their own code...

    Lockstate doesn't work in Editor properly but will work in Standalone on Mac or PC builds just fine.

    For the Editor, I came up with a very legit way to move the mouse cursor and another to force a mouse click event because Unity is so annoying in not letting you do this when using Cursor.lockState. Now you can set Cursor.lockState and/or Cursor.visibility in Start() and call either of the following below to force the mouse to behave. (Verified working in macOS Big Sur, Unity 2021.1.17)

    Stupid easy way to force mouse cursor position to center of game window in editor only from code:
    Code (CSharp):
    1. using UnityEngine.InputSystem;
    2. using UnityEngine.InputSystem.LowLevel;
    3.  
    4. public static void ForceMousePositionToCenterOfGameWindow()
    5.     {
    6. #if UNITY_EDITOR
    7.         // Force the mouse to be in the middle of the game screen
    8.         var game = UnityEditor.EditorWindow.GetWindow(typeof(UnityEditor.EditorWindow).Assembly.GetType("UnityEditor.GameView"));
    9.         Vector2 warpPosition = game.rootVisualElement.contentRect.center;  // never let it move
    10.         Mouse.current.WarpCursorPosition(warpPosition);
    11.         InputState.Change(Mouse.current.position, warpPosition);
    12. #endif
    13.     }

    Stupid easy way to force click in game window in editor only from code:
    Code (CSharp):
    1. using UnityEngine.InputSystem;
    2. using UnityEngine.InputSystem.LowLevel;
    3.  
    4. public static void ForceClickMouseButtonInCenterOfGameWindow()
    5.     {
    6. #if UNITY_EDITOR
    7.         var game = UnityEditor.EditorWindow.GetWindow(typeof(UnityEditor.EditorWindow).Assembly.GetType("UnityEditor.GameView"));
    8.         Vector2 gameWindowCenter = game.rootVisualElement.contentRect.center;
    9.  
    10.         Event leftClickDown = new Event();
    11.         leftClickDown.button = 0;
    12.         leftClickDown.clickCount = 1;
    13.         leftClickDown.type = EventType.MouseDown;
    14.         leftClickDown.mousePosition = gameWindow;
    15.  
    16.         game.SendEvent(leftClickDown);
    17. #endif
    18.     }
     
  37. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    Nice, will do this in the next update.
     
  38. elaine_unity790

    elaine_unity790

    Joined:
    Mar 2, 2023
    Posts:
    1
    Hi, is the plugin support for Mac?
    I encounter an error message when I play the Example scene given

    EntryPointNotFoundException: InstallTrackingHandler assembly:<unknown assembly> type:<unknown type> member:(null)
    System.Windows.Forms.CarbonInternal.Dnd..cctor () (at <6528e4a6660e47ef95c4a290865951bf>:0)
    Rethrow as TypeInitializationException: The type initializer for 'System.Windows.Forms.CarbonInternal.Dnd' threw an exception.
    System.Windows.Forms.XplatUICarbon.Initialize () (at <6528e4a6660e47ef95c4a290865951bf>:0)
    System.Windows.Forms.XplatUICarbon..ctor () (at <6528e4a6660e47ef95c4a290865951bf>:0)
    System.Windows.Forms.XplatUICarbon.GetInstance () (at <6528e4a6660e47ef95c4a290865951bf>:0)
    System.Windows.Forms.XplatUI..cctor () (at <6528e4a6660e47ef95c4a290865951bf>:0)
    Rethrow as TypeInitializationException: The type initializer for 'System.Windows.Forms.XplatUI' threw an exception.
    System.Windows.Forms.SystemInformation.get_MouseSpeed () (at <6528e4a6660e47ef95c4a290865951bf>:0)
    SystemCursor.GetCurrentSensitivity () (at Assets/Plugins/Set Cursor Sensitivity v1.01/SystemCursor.cs:70)
    Csharp_Example.OnGUI () (at Assets/[Set Cursor Sensitivity]_ExampleScene (Deletable)/Example 1 Scene/Csharp_Example.cs:24)
    UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:189)

     
  39. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217
    Hello this asset only works for Windows OS, no mac or linux support sadly.
     
    elaine_unity790 likes this.