x


Screen orientation change notification

Hello,

Is is possible for my script to be notified at the moment the device changes orientation? I'd rather not keep testing for device orientation on each frame... Maybe there's something like the delegate protocols in Obj-C, but no amount of searching or looking through the docs has helped.

Any help much appreciated!

more ▼

asked Jan 06 '12 at 09:02 PM

franklynw gravatar image

franklynw
81 2 4 6

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I figured it out using UnitySendMessage - in Xcode, in "AppController.mm", in -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation I added:

NSString *theOrientation = [NSString stringWithFormat:@"%i", interfaceOrientation];
UnitySendMessage("Game Manager", "DeviceRotated", [theOrientation UTF8String]);

and in Unity, in the script on my Game Manager gameObject I added -

public void DeviceRotated(string theMessage) {

    // do something here which needs to be done when device orientation changes

}

Being new to Unity I hadn't realised there could be 2-way communication between Unity & the Obj-c stuff. Probably elementary to most people here, but I thought I'd post it in case it helps someone avoid the troubles I had.

more ▼

answered Jan 09 '12 at 12:21 PM

franklynw gravatar image

franklynw
81 2 4 6

I guess I'm newer to Unity, because I don't understand that. You wrote "in Xcode...", but I thought you could only code in C# or unityscript. Where does that code go?

Oct 30 '12 at 01:44 AM B-rad

It goes into your XCode project when you build for iOS.

Oct 30 '12 at 08:53 PM bzgeb

ah, okay. Thanks.

Oct 30 '12 at 08:58 PM B-rad

Not the best solution, if you can avoid editing your xCode project you should, Because a new build won't have this included.

Dec 20 '12 at 06:21 PM J3 Gaming
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x485
x173
x124
x28

asked: Jan 06 '12 at 09:02 PM

Seen: 1634 times

Last Updated: Dec 20 '12 at 06:21 PM