Unity animation events - events

I have an animation and I want to show several time hints at certain points.
What is the best way of doing that?
I tried to make events in animation.. and call function which should notify the main GUI class, that something changed, but I am not sure if it is a good solution.
(actually I do not know how to do it effectively).
Or I can make a loop in my main GUI class, just reacting to time.. but I am not sure if the synchronization will be ok.

If it is a cutscene like animation, I would use these animation events. This way it is easy to edit it later, if something changes in the animation. If you calculate seconds in the code while playing the animation, it will be a maintenance hell.

Related

Is [NSWindow setFrame:display:] API asynchronous?

I have a strange UI behavior which made me think that this API might be asynchronous. Assuming it is (async), I've made some changes and now the UI works as expected. I didn't find the answer in Apple's documentation.
Is anyone familiar or had some experience with this? Is it really async? Thanks!
EDIT: All UI changes are being made from the main thread.
setFrame:display: updates the frame and tells the system to redraw the window (and possibly the subviews) during its next drawing cycle. Cocoa drawing is always done during its drawing cycle, not at the moment you call a drawing method. See What is the most robust way to force a UIView to redraw? for some more discussion on that.
This is better thought of as drawing being "consolidated" rather than "asynchronous." Unless there are animations, all drawing should generally be complete before the next event loop. It's possible that a view will somehow delay its drawing to a later event loop, but rare. Layer-backed views in 10.8+ can support actual async drawing, but this is not the default.
From you description, it's possible you're calling setFrame:display: from a thread other than the main thread. AppKit drawing is not thread safe. You cannot call drawing methods from anywhere but the main thread, or you'll get "strange UI behavior." (This isn't completely true. On OS X, you can use lockFocus to draw from other threads, but they still won't actually be applied until the next drawing cycle after you unlock focus. But normally it's best just to draw from the main thread in modern OS X since GCD makes this simple.)

Trying to add my animation to my idle state, but it just keeps saying "None(Motion)"

I have pulled the animation to the Motion tab both by dragging and trough the select motion search function but neither makes the animation stick to my idle state. Can someone give me a pointer to what im doing wrong?
One reason could be that the animations are marked as legacy.
Select one or many animation, in the inspector next to the lock, right click, then Debug. Untick the Legacy. No need to save or else.
The animation which you're trying to set is for another model!
You should use an animation that is for the model.
Or if you insist on using that animation select animation from assets and do a "Control + D" to duplicate it and use new one.
Use the Animator, not the animation controller. I made this mistake when I was following a tutorial. This is only relevant if you are animating .anim files within unity itself. Animation controller is the way to go if you import animations for your specific model.

Removing active animations from a DependencyProperty in WinRT

When you have an animated DependencyProperty, how do you remove all active animations? In WPF you could...
myDependencyObject.BeginAnimation(<propery path>, null);
... and that would remove all animations. Is there an equivalent in WinRT (aka Windows Store Apps)?
I have a solution I don't like: keep track of the storyboard to which the animation belongs and manually Stop() it when you want to replace it :/.
Hope this helps somebody.
Edit-
The reason this seems like a poor solution is that it requires the thing that starts the new animation to have some sort of connection to the thing that started the old animation. Ideally the animation target would be affected by different parts of the system at different times and those parts that do the animating would be completely decoupled.

Evaluate an If statement after dragging an image?

I'm dragging an imageView around the screen which is working great. At the moment, it is evaluating an if statement every time the image is moving, but I would like it to check it once the user has lifted their finger off the screen. How would I go about this? I thought maybe using touchesEnded:withEvent but it didn't look like it was being called when lifting the finger.
My code is a little complicated (well, it looks that way to me!) but if that is helpful, I will post it. Basically, in the handlePanGesture method, it is checking the co-ordinates against a dictionary and if it is true, will 'snap' to the correct position. The reason I want to check when the user has lifted is because, if they have dropped it in the wrong place, I'd like to animate it back to the original position.
Many thanks for reading this.
I think you need to check the state of the gesture recognizer in your action method, gestureRecognizer.state == UIGestureRecognizerStateEnded. It's my understanding that you only use touchesEnded:withEvent if you are subclassing the geture recognizer.

Where to put animation code?

Animations are a strange mix of view and control, and they sometimes need to be synchronized with delays between them, callback to code, etc.
So, without being specific to any particular GUI framework, where should I put my animation code in a MVC architecture?
This is such a general question, but I would be inclined to put this completely in the view if possible. You could think of it like jQuery animations which have a final value and a duration - you could think of this being handed off to the view, which could take care of everything at that point.

Resources