News: Enjoy our Christmas offer 30% off on our latest package Tower Defense Level Kit http://u3d.as/m7h

  • September 24, 2018, 03:11:43 PM

Login with username, password and session length

Author Topic: onCloseEnd callback - moving it makes code cleaner?  (Read 1416 times)

Offline xyzDave

  • Newbie
  • *
  • Posts: 9
onCloseEnd callback - moving it makes code cleaner?
« on: December 11, 2015, 04:35:21 PM »
Hi,
I've just been adding callback code when some panel finish moving, and I was having to add a co-routine if I trigger the opening of a panel that triggered the callback in the callback.
E.g.
PanelB.Close()

If PanelB has an OnCloseEnd callback as
void Callback()
{
    PanelB.Open()
}

PanelB will not open as the motionState is not MotionState.Closed when Open() is called.
To make it work I added a co-routine containing the Open to delay the call by 1 frame.

But... I then realised if you changed the code to that shown below, the Co-routine is nolonger required as motionState is set to MotionState.Closed prior to the callback.

Code: [Select]
protected override void On_EndMotion (string id){

if (id == motionId){

currentPropertiesCounter++;

if (currentPropertiesCounter >= propertiesCounter){
if (currentProp.motionType == EMMotionProperties.MotionType.Open){
onOpenEnd.Invoke(motionName);
motionState = MotionState.Open;
if (currentProp.autoClose){
StartCoroutine( WaitToAutoClose(currentProp.autoCloseDelayTime));
}
}
else{
 // MOVE TO BELOW>>>                onCloseEnd.Invoke( motionName);
motionState = MotionState.Closed;
GetTransformFromProperties( openProp,false).ApplyAllToRectTransform( cachedTransform, cachedCanvasGroup );
HideUIElement();
                                        onCloseEnd.Invoke( motionName);  // moved from above
}
}

}
}

what do you think?  Does this make sense?  Is it worth adding this the next library release?  I can't see how it would break any existing code.

Thanks
Dave

Offline Nicolas

  • Administrator
  • Hero Member
  • *****
  • Posts: 792
Re: onCloseEnd callback - moving it makes code cleaner?
« Reply #1 on: December 12, 2015, 10:21:57 AM »
Hi,

 Yes, I had forbidden the opening if was not "closed" to avoid for example :
 A click on a button launches a movement then at the end of the loading or otherwise, authorizing the opening even if the state is not closed, if the user click again on the button, it re opening the motion.

But you have the choice, the Open method has an optional parameter to force the opening event if the state is not closed

Version 1.2.0
==============
- Open method has now an optional parameter that allow to force the opening, even if the element isn't close.

Code: [Select]
public void Open(bool force=false)

So you can already do that without any modificaiton


Remember that you have at your disposal  the classe EMMotionManager that allow you to launch motion without to do a reference in a public variable (doc page 20). May be this class need to be expand to add more feature.
« Last Edit: December 12, 2015, 10:48:56 AM by Nicolas »

Offline xyzDave

  • Newbie
  • *
  • Posts: 9
Re: onCloseEnd callback - moving it makes code cleaner?
« Reply #2 on: December 13, 2015, 06:30:12 PM »
Hi Nicholas,
 Open(bool force=false) would be very handy.

When is version 1.2.0 due to be released?

Unity Asset store is currently on version 1.1.0

Thanks,
Dave


Offline Nicolas

  • Administrator
  • Hero Member
  • *****
  • Posts: 792
Re: onCloseEnd callback - moving it makes code cleaner?
« Reply #3 on: December 13, 2015, 08:41:19 PM »
I kept it because I only had this little evolution. Despite a good rating, and regular purchases you're the first to post in this section.
So I can upload it to the AssetStore tomorrow, but there will be more than that