Jump to content

Need some help with key binding for new modder


Recommended Posts

Hi,

While I would appreciate some help with the actual answer for the following questions, I would also appreciate pointers on where to find the answers myself:

I'm using Xamarin Studio on Windows 7, if that is relevant.

I am trying to write a mod which will take screenshots at specific events during a game. I am trying to find out the following:

1. I have looked in the references for UnityEngine, and while I found a Screen class, I don't see anything which would be something like screenshot, screencapture, etc.

2. Alternatively, I am also looking if there is a way to inject a keystroke into the stream.

I'd prefer #1, since there are a number of things which I'd like to do and that is a better way.

Thanks in advance

Link to comment
Share on other sites

While I don't know how to trigger a screenshot, I can confirm that injecting a keystroke via code is a no-go.

I looked for this myself a while back and my best guess is that Unity only accepts keystrokes from the hardware input layer and has no way of writing to that function itself.

D.

edit: bah, ninja!

Link to comment
Share on other sites


Application.CaptureScreenshot(string filename);

is what you are looking for. :)

Is this done asynchronously? I'm asking because I first call it, and then the next line I try to convert it to a jpg, and I'm getting an error that the file doesn't exist.

Thanks

Link to comment
Share on other sites

Does the file exist by the time you can move to the folder and check?

If this is on the same "update frame", the next line of code pretty much runs instantly and while making a screenshot is fast, it's not that fast. (a.k.a. runs asynchronously)

If this is the case you'll have to delay until the file exists some how.

D.

Link to comment
Share on other sites

Does the file exist by the time you can move to the folder and check?

If this is on the same "update frame", the next line of code pretty much runs instantly and while making a screenshot is fast, it's not that fast. (a.k.a. runs asynchronously)

If this is the case you'll have to delay until the file exists some how.

D.

That's what I thought. Thanks.

- - - Updated - - -

Start a coroutine to wait a few frames, then try the conversion? Shout if you need some pointers.

If you could point me to an example, that would be a big help. I'm just getting started in this kind of programming, and, while I know threading very well, i don't know how to do it in Unity yet.

Thanks.

Link to comment
Share on other sites

Documentation

Simple wait while null function

public System.Collections.IEnumerator waitWhileNull()
{
while(image == null)
yield return null; // null == wait till the next Update cycle, new WaitForFixedUpdate() == wait till next FixedUpdate cycle, break == exit this coroutine instance here, new WaitForSeconds(1) == Wait till one second has passed
// do something
}

KSP usage (two stages of waiting for a certain value, and three stages where it's just waiting a set number of frames)

Coroutines let you execute a single function with all its local variables through multiple timesteps

Edited by Crzyrndm
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...