MarshMello0 / Editor-Rich-Presence

Show off what you're working on in unity with Editor Rich Presence on discord.
https://assetstore.unity.com/packages/tools/utilities/editor-rich-presence-178736#description
MIT License
61 stars 10 forks source link

Over 6 hours elapsed even though just opened #3

Closed BigAtomikku closed 4 years ago

hazeliscoding commented 4 years ago

I'm having the same issue too, I added it to a fresh project and it says over 22 hours elapsed.

ghost commented 4 years ago

Couldn't find the UpdatePresence method in this repo, but found it through the zip on the releases. You should probably use something like the following so that it goes based on the Unity process:

DateTime processStartTime = System.Diagnostics.Process.GetCurrentProcess().StartTime.ToUniversalTime();
discordPresence.startTimestamp = (int)(processStartTime.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
BigAtomikku commented 4 years ago

Couldn't find the UpdatePresence method in this repo, but found it through the zip on the releases. You should probably use something like the following so that it goes based on the Unity process:

DateTime processStartTime = System.Diagnostics.Process.GetCurrentProcess().StartTime.ToUniversalTime();
discordPresence.startTimestamp = (int)(processStartTime.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

where should we put this code in the cs? Am not very good with cs yet

hazeliscoding commented 4 years ago

Couldn't find the UpdatePresence method in this repo, but found it through the zip on the releases. You should probably use something like the following so that it goes based on the Unity process:

DateTime processStartTime = System.Diagnostics.Process.GetCurrentProcess().StartTime.ToUniversalTime();
discordPresence.startTimestamp = (int)(processStartTime.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

where should we put this code in the cs? Am not very good with cs yet

I think it would be in the GetTimeStamp() method in UREP.cs. I adapted the code above into this.

DateTime processStartTime = System.Diagnostics.Process.GetCurrentProcess().StartTime.ToUniversalTime();
long timeStamp = (int)(processStartTime.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
return timeStamp.ToString();

But now if we have the resetOnSceneChange = true, then the timestamp isn't reset like before.

ghost commented 4 years ago

Sorry, yes that would be in UERP.cs. I set my folder structure to the following since I didn't want to build an independent dll (easier to change for me, and don't know if I really need the x86 but doesn't hurt to keep it for other devs):

/Assets/Editor/UERP.cs
/Assets/Editor/DiscordRpc.cs
/Assets/Editor/UERP/Plugins/x86/discord-rpc.dll
/Assets/Editor/UERP/Plugins/x86_64/discord-rpc.dll

For me personally, I didn't want it resetting on the scene change so this was the change I needed, but yes if you wanted it to reset on the scene change then that would not work the way you want. In that case, I'm not 100% sure of an easy way, because if you were to set the timestamp subtract from the current timestamp, then you will have it reset each build. Unfortunately, a rebuild means static values don't really work.

I can think of an extreme method, where you create a new file with some process info and then check the file to see if it matches the current process info as well as some timestamp to indicate when the scene was opened. If the process info matches, use the scene timestamp in there. Otherwise if it doesn't, re-create it and update accordingly (and then just re-create the file on scene changes, too). Again, a little extreme, but because builds re-set all the variables, you'll need to find an external source to depend on (which is why I chose the timestamp of the process itself). Maybe Unity has some kind of API or information for the scene you can use in EditorSceneManager.GetActiveScene()? I haven't dug into that much, but I'm wondering if that manager would have something in it to say when a scene was opened.

MarshMello0 commented 4 years ago

Apologies somehow missed all these old issues. I have just fixed (to my knowledge) the elapsed issue in update 3.0.0.

Feel free to reopen this issue if it isn't.