Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Genhain

Pages: [1] 2 3
1
As the title says i am using NGUITools.Destroy(); to destroy a game object and unity standard one, either way i get the following exception...

Quote
MissingReferenceException: The object of type 'UILabel' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UIPanel.UpdateWidgets () (at Assets/Imported/NGUI/Scripts/UI/UIPanel.cs:1519)
UIPanel.UpdateSelf () (at Assets/Imported/NGUI/Scripts/UI/UIPanel.cs:1222)
UIPanel.LateUpdate () (at Assets/Imported/NGUI/Scripts/UI/UIPanel.cs:1181)

This never happened before i started using my own font's, dynamic i believe. I also did some research into it and people seem to suggest you do the following in UIWidget

  1. public virtual void MarkAsChanged ()
  2.         {
  3.                 if (NGUITools.GetActive(this))
  4.                 {
  5.                         mChanged = true;
  6. #if UNITY_EDITOR
  7.             if(this != null)<--ADD THIS CHECK HERE
  8.             {
  9.                             NGUITools.SetDirty(this);
  10.             }
  11. #endif
  12.                         // If we're in the editor, update the panel right away so its geometry gets updated.
  13.                         if (panel != null && enabled && NGUITools.GetActive(gameObject) && !mPlayMode)
  14.                         {
  15.                                 SetDirty();
  16.                                 CheckLayer();
  17. #if UNITY_EDITOR
  18.                                 // Mark the panel as dirty so it gets updated
  19.                                 if (material != null) NGUITools.SetDirty(panel.gameObject);
  20. #endif
  21.                         }
  22.                 }
  23.         }
  24.  

but to no avail. Does anyone have any idea how to fix this?

UPDATE:

So i discovered...If you spawn a prefab with a UILabel that starts of as inactive...destroying it will cause the crash, they needed to be active at some point during the lifetime of the object before you destroy it, so it is initialisations being ignored based on an inactive state. I don't know if this only applies to UILabels or other NGUI elements.

On a slightly related note i had to change certain code in NGUI to take into account inactive elements also on the NGUITools.BringForward() as it would ignore inactive elements in and under the object you are trying to bring forward and would mess up the visual hierarchy of the object. Whether or not this was intended i do not know, but if you are experiencing a similar malady, with NGUI it seems better to have all elements active until the components Start() get's called at which point you can set it too invisible or inactive.

Good luck.

2
NGUI 3 Support / Re: [HOTFIX]Other Tween engines and NGUI
« on: November 13, 2014, 02:45:05 AM »
So i stumbled upon this by pure accident but i found a way for other tween engines(DOTween at least) and NGUI's anchoring system to coexist peacefully.

if you set the anchor update to OnEnable...there seems to be no more issues...I can't say why i am just ecstatic it seems to have solved me of the issue, but i would only call this a hotfix as i do not know if it might cause undue behaviours elsewhere.

anyway i will post the code for others to use if you are interested. Apologies if it is a tad utterly unreadable. But essentially DOLocalMoveWidget checks to see if it has a UIRect which any visual component with NGUI does, stores the previous updateFlag and sets it to onEnable and onCompleting sets it back to it's previous value.

  1. public static Tweener DOLocalMoveWidget (this Transform target, Vector3 endValue, float duration, DG.Tweening.Core.TweenCallback callback = null, bool snapping = false)
  2. {
  3.     UIRect rect = target.GetComponent<UIRect>();
  4.     UIRect.AnchorUpdate defaultUpdateFlag = UIRect.AnchorUpdate.OnUpdate;
  5.  
  6.     if(rect != null)
  7.     {
  8.         defaultUpdateFlag = rect.updateAnchors;
  9.         rect.updateAnchors = UIRect.AnchorUpdate.OnEnable;
  10.     }
  11.  
  12.     return DOTween.To(()=>target.localPosition,x=> target.localPosition = x,endValue,duration)
  13.         .OnComplete(()=>
  14.        {
  15.            TweenPosition.Begin(target.gameObject,0,endValue).PlayForward();
  16.            rect.updateAnchors = defaultUpdateFlag;
  17.            if(callback!= null)callback();
  18.        });
  19. }
  20.  
  21. public static Tweener DOLocalMoveXWidget(this Transform target, float endValue, float duration, DG.Tweening.Core.TweenCallback callback = null, bool snapping = false)
  22. {
  23.     Vector3 endPosition = target.localPosition;
  24.     endPosition.x = endValue;
  25.  
  26.     return target.DOLocalMoveWidget(endPosition,duration,callback,snapping);
  27. }
  28.  
  29. public static Tweener DOLocalMoveYWidget(this Transform target, float endValue, float duration, DG.Tweening.Core.TweenCallback callback = null, bool snapping = false)
  30. {
  31.     Vector3 endPosition = target.localPosition;
  32.     endPosition.y = endValue;
  33.  
  34.     return target.DOLocalMoveWidget(endPosition,duration,callback,snapping);
  35. }
  36.  
  37. public static Tweener DOLocalMoveZWidget(this Transform target, float endValue, float duration, DG.Tweening.Core.TweenCallback callback = null, bool snapping = false)
  38. {
  39.     Vector3 endPosition = target.localPosition;
  40.     endPosition.z = endValue;
  41.  
  42.     return target.DOLocalMoveWidget(endPosition,duration,callback,snapping);
  43. }
  44.  

3
So the previous code i had, worked for pixel perfect but not fixedSize or constrained...this however works on both for getting the docks top position on screen that scales properly.

  1. void CalculateDisplacementFromCrossOver ()
  2. {
  3.         cardHandWidget = objectToBeginScrollingFrom.GetComponent<UIWidget>();
  4.     Vector3 pos = cardHandWidget.transform.localPosition;
  5.     pos.y += cardHandWidget.localSize.y/2;
  6.  
  7.     var docksMaxY = UICamera.currentCamera.WorldToScreenPoint(cardHandWidget.transform.parent.TransformPoint(pos)).y;
  8.     var touchPointInStandardScreenSpace = UICamera.currentTouch.pos.y;
  9.  
  10.         displacementFromCrossover = touchPointInStandardScreenSpace - docksMaxY;
  11. }
  12.  

4
So i have an widget that is about 466 in height as the widget indicates and it is anchored to the bottom, so this to me would indicate it is 466 pixels up the screen yes?

I am then getting the mouse position and finding out how far from the top of the widget it is...wether it is under the height of 466 or more. However the "UICamera.currentTouch.pos" code seems to return a position that is affected by screen scaling where as the height im currently getting from the UIWidget is not...soIi have to scale one or the other by something, and i am not certain what. I have tried "UIRoot.GetPixelSizeAdjustment" but that scaling value is still a bit off it seems. here is my current code.

  1. void CalculateDisplacementFromCrossOver ()
  2. {
  3.     cardHandWidget = objectToBeginScrollingFrom.GetComponent<UIWidget>();
  4.     var docksMaxY = cardHandWidget.localSize.y;
  5.     var touchPointInStandardScreenSpace = UICamera.currentTouch.pos.y;//in pixels
  6.     displacementFromCrossover = touchPointInStandardScreenSpace - docksMaxY;
  7.  
  8.     Debug.Log("pixel size adjustment:"+UIRoot.GetPixelSizeAdjustment(cardHandWidget.gameObject));
  9.     Debug.Log("touch Height:"+touchPointInStandardScreenSpace);
  10. }
  11.  

5
NGUI 3 Support / Re: Other Tween engines and NGUI
« on: November 11, 2014, 01:37:49 AM »
Despite some experimentation i can not get it to work, i have opted to stop using the DOTween Tweening system in the mean time as i do not have time to get it working over other milestones. If i however come across any revelations i will post them here.

6
NGUI 3 Support / Re: Other Tween engines and NGUI
« on: November 06, 2014, 06:03:32 AM »
Okay is there a way for me to perhaps clear the anchors for the duration of the tween, keeping references of them...then once finished, put them back in and update them? i have managed to get as far as clearing the anchors...but trying to add them back in is proving difficult.

so somthing like
  1. UIWidget previousWidget = target.GetComponent<UIWidget>();
  2. //start tween
  3. UIRect.AnchorPoint oldLeftAnchor = previousWidget.leftAnchor;
  4. UIRect.AnchorPoint oldRightAnchor = previousWidget.rightAnchor;
  5. UIRect.AnchorPoint oldBottomAnchor = previousWidget.bottomAnchor;
  6. UIRect.AnchorPoint oldTopAnchor = previousWidget.topAnchor;
  7.  
  8. previousWidget.ClearAnchors();
  9.  
  10. //On tween finished
  11. previousWidget.leftAnchor = oldLeftAnchor;
  12. previousWidget.rightAnchor = oldRightAnchor;
  13. previousWidget.bottomAnchor = oldBottomAnchor;
  14. previousWidget.topAnchor = oldTopAnchor;
  15.  
  16. previousWidget.ResetAndUpdateAnchors();
  17.  

7
NGUI 3 Support / Re: Other Tween engines and NGUI
« on: November 06, 2014, 03:41:46 AM »
I have to say your code is utterly unreadable. There is not much I can do to help you with some third party tween system in any case.

well i am using lambda statements so it can get a little cluttered. i'll expand one out

  1. public static Tweener DOLocalMoveXWidget(this Transform target, float endValue, float duration, DG.Tweening.Core.TweenCallback callback = null, bool snapping = false)
  2. {
  3.     return target.DOLocalMoveX(endValue,duration,snapping)
  4.      .OnComplete(()=>
  5.     {
  6.         TweenPosition.Begin(target.gameObject,0,new Vector3(endValue,target.localPosition.y)).PlayForward();
  7.         if(callback!= null)callback();
  8.     });
  9. }
  10.  

Hopefully that is more readable.

Essentially i am using the tween engine to move something visually and then in the onComplete lambda call TweenPosition at a duration of 0 seconds to make it happen instantly which will account for the anchors and such

I'm not expecting you to know how a third party system will work, but as i have said i have been ruling out what the causes are and as stated it's the activation of anchors that is causing the symptom i describe and looking at your code during your position tweens you use "NGUIMath.MoveRect(mRect, value.x, value.y);" to accommodate the anchors i was just enquiring as if you possibly have any insight as to why anchors along with deactivating and activating an object would cause it to be unable to interpolate any longer since you developed them and probably ran into one or two gotcha moments that would help explain the behaviour i am experiencing?

8
NGUI 3 Support / Re: Other Tween engines and NGUI
« on: November 05, 2014, 11:38:31 PM »
UPDATE

So i came up with this little ditty

  1. Sequence mySequence = DOTween.Sequence();
  2.  
  3. mySequence
  4.                 .Append(testTween.DOLocalAxisRotate(new Vector3(0,0,90),1))
  5.                 .Append(testTween.DOLocalMoveWidget(new Vector3(30,30,0),1))
  6.                 .Append(testTween.DOLocalMoveXWidget(60,1))
  7.                 .Append(testTween.DOLocalMoveYWidget(60,1))
  8.                 .Append(testTween.DOLocalMoveWidget(new Vector3(0,0,0),1))
  9.                 .Append(testTween.DOLocalRotate(new Vector3(0,0,180),1))
  10.                 .Append(testTween.DOPunchScale(new Vector3(2,2,1),1))
  11.                 .Append(testTween.DORotate(new Vector3(0,0,-180),1))
  12.                 .Append(testTween.DOScale(new Vector3(1.5f,1.5f,1),1))
  13.                 .Append(testTween.DOLocalMoveWidget(new Vector3(0,-50,0),1))
  14.                 .AppendCallback(()=>{NGUITools.SetActive(testTween.gameObject,false);})
  15.                 .AppendInterval(1)
  16.                 .AppendCallback(()=>{NGUITools.SetActive(testTween.gameObject,true);});
  17.  

and it essentially plays through once fine...And then once it hits mySequence.Restart(); after deactivating and reactivating them is when the movement tweens stop interpolating. without setting them inactive and active again it works fine, and again this is only if anchors are present and seems to only affect positional Tweens...the rotates and scale ones do not seem affected at all.

9
NGUI 3 Support / [HOTFIX]Other Tween engines and NGUI
« on: November 05, 2014, 11:09:58 PM »
Not that there is anything wrong With NGUI tweening method, but i wanted something with a few more options and intricacy, so i tried to give HOTweens successor DOTween a go. And it seemed to work, until anchors got involved.

if you tried tweening anything with DOTween that had an anchor...it would move, and then snap back to it's from. So i discovered that NGUI movement tweening does a little thing in the background which updates the anchors rect as you tween which caused me to come up with this.

  1. public static Tweener DOLocalMoveWidget (this Transform target, Vector3 endValue, float duration, DG.Tweening.Core.TweenCallback callback = null, bool snapping = false)
  2. {
  3.         return DOTween.To(()=>target.localPosition,x=> target.localPosition = x,endValue,duration).OnComplete(()=>{TweenPosition.Begin(target.gameObject,0,endValue).PlayForward();if(callback!= null)callback();});
  4. }
  5.  
  6. public static Tweener DOLocalMoveXWidget(this Transform target, float endValue, float duration, DG.Tweening.Core.TweenCallback callback = null, bool snapping = false)
  7. {
  8.         return target.DOLocalMoveX(endValue,duration,snapping).OnComplete(()=>{TweenPosition.Begin(target.gameObject,0,new Vector3(endValue,target.localPosition.y)).PlayForward();if(callback!= null)callback();});
  9. }
  10.  
  11. public static Tweener DOLocalMoveYWidget(this Transform target, float endValue, float duration, DG.Tweening.Core.TweenCallback callback = null, bool snapping = false)
  12. {
  13.         return target.DOLocalMoveY(endValue,duration,snapping).OnComplete(()=>{TweenPosition.Begin(target.gameObject,0,new Vector3(target.localPosition.x,endValue)).PlayForward();if(callback!= null)callback();});
  14. }
  15.  
  16. public static Tweener DOLocalMoveZWidget(this Transform target, float endValue, float duration, DG.Tweening.Core.TweenCallback callback = null, bool snapping = false)
  17. {
  18.         return target.DOLocalMoveZ(endValue,duration,snapping).OnComplete(()=>{TweenPosition.Begin(target.gameObject,0,new Vector3(target.localPosition.x,target.localPosition.y,endValue)).PlayForward();if(callback!= null)callback();});
  19. }
  20.  

And it all seems to work, with now what seems to be one small exception if after deactivating the view these tweens were in and returning to it, the DOTweens now no longer show any visible sign of interpolation..but after their duration is up the oncomplete is called and they snap to their target "to" which indicates that the onComplete is being called and NGUI UITweens are being called...So my question is is there something that UITween does that is causing this? or does anyone have any suggestions about the code above to fix this?

I will keep experimenting and update with progress or discoveries as to the exact cause of the issue if i can.

10
Fixed it.

  1. int count = GetChildList().Count;
  2.  
  3. //Grids local position
  4. Vector3 lastElementInGridPos = transform.localPosition;
  5. lastElementInGridPos.x += (count*cellWidth);//add x equal to amount of elements * set cellwidth
  6. lastElementInGridPos.x -= (transform.localPosition.x+416);//adjust for scroll view offset
  7.  
  8. Vector3 EndValue = transform.TransformPoint(lastElementInGridPos);
  9.  

11
So i have extended UIGrid to give me a bit more control of the visual look of the reparenting tween. The code below is called when the item is dropped into a UIDragDropContainer which points to this as its reparent target. The general idea is create a copy of the element hide the original set the copy to be at the highest level of depth (UIDragDropRoot), find out the originals position in world coordinates. then convert it to local of the parent of the original, and then tween the movement and a callback to cleanup. That is how i assumed you convert between local and world coordinates, because i have done something similar in other areas with success yet here it does not seem to be the case...is there edge cases with scrollviews i am wondering? or am i doing it wrong?

my hierarchy is as follows

DragDropRootPanel
widget
-collider
-ScrollView
  -widget
    -widget
      -ScrollView(with uigrid extension script attached)
        -card
        -card
        -card

it is an odd hierarchy i am aware but i required a vertical scroll and then a horizontal scroll within that and the extra widget is so the inner scrollview is slightly offcenter as the top level scrollview has UICenterOnChild on it.

  1. public override void CardDroppedIntoGrid(WCCard card)
  2. {
  3.         base.CardDroppedIntoGrid(card);
  4.         //create display copy
  5.         GameObject cardDisplayCopy = card.CreateDisplayCopy();
  6.  
  7.         card.GetComponent<UIWidget>().SetVisible(false);
  8.  
  9.         cardDisplayCopy.transform.position = card.transform.position;
  10.  
  11.         // Re-parent the item
  12.         if (UIDragDropRoot.root != null)
  13.                 cardDisplayCopy.transform.parent = UIDragDropRoot.root;
  14.  
  15.         NGUITools.MarkParentAsChanged(cardDisplayCopy);
  16.  
  17.         Vector3 lastElementInGridPos = GetChildList().Last().transform.position;
  18.  
  19.         Vector3 EndValue = transform.InverseTransformPoint(lastElementInGridPos);
  20.  
  21.         cardDisplayCopy.transform.DOLocalMove(EndValue,2,false)
  22.                 .OnComplete(()=>
  23.                 {
  24.                         card.GetComponent<UIWidget>().SetVisible(true);
  25.                         if(!Application.isPlaying)
  26.                                 GameObject.DestroyImmediate(cardDisplayCopy);
  27.                         else
  28.                                 GameObject.Destroy(cardDisplayCopy);
  29.                 }).SetEase(Ease.InCirc);
  30. }
  31.  

12
Yes and it has a UIDragDropItem script attached which disables UIDragScrollView on start and re-enables it on release. so FindScrollView was being called but once it got into FindScrollView there is checks for null and equality, but not if the current parent scrollview is different from the last, hence it just keeps the scrollview reference to it's previous parent. I am not sure if this is intended...but if not, here is how i fixed it.

  1. void FindScrollView ()
  2. {
  3.         // If the scroll view is on a parent, don't try to remember it (as we want it to be dynamic in case of re-parenting)
  4.         UIScrollView sv = NGUITools.FindInParents<UIScrollView>(mTrans);
  5.  
  6.                                            //-->EXTRA CHECK HERE<--
  7.         if (scrollView == null || ( mAutoFind && scrollView != sv ))
  8.         {
  9.                 scrollView = sv;
  10.                 mAutoFind = true;
  11.         }
  12.         else if (scrollView == sv)
  13.         {
  14.                 mAutoFind = true;
  15.         }
  16.         mScroll = scrollView;
  17. }
  18.  

13
NGUI 3 Support / Re: UICenterOnChild with offset?
« on: November 02, 2014, 09:43:51 PM »
I imagined there would be a way to achieve this through how you parented certain elements...and now that you say it. It makes perfect and simple sense, i must have been tired. Cheers Aren

14
  1. void FindScrollView ()
  2. {
  3.         // If the scroll view is on a parent, don't try to remember it (as we want it to be dynamic in case of re-parenting)
  4.         UIScrollView sv = NGUITools.FindInParents<UIScrollView>(mTrans);
  5.  
  6.         if (scrollView == null)
  7.         {
  8.                 scrollView = sv;
  9.                 mAutoFind = true;
  10.         }
  11.         else if (scrollView == sv)
  12.         {
  13.                 mAutoFind = true;
  14.         }
  15.         mScroll = scrollView;
  16. }
  17.  

so with this currently as is, if i drag from one scrollview to another, it will not reparent to the new scrollview...unless we either clear the reference or the previous scrollview get's destroyed or you press and release first where it will set the new scrollview anyway. Unless i am using UIDragscrollView & UIDragDropItem with scrollviews wrong? But i do not think so as this worked before i upgraded.

15
NGUI 3 Support / [SOLVED]UICenterOnChild with offset?
« on: October 30, 2014, 10:45:47 PM »
I was just going to make a child class and override any virtual functions to find this is a rather black boxed class. I cant immediately think of any way of having the scroll center On a child except with an offset in either x or y, while keeping the clipping regions exactly as is and where you want them, without modifying the existing class.

Pages: [1] 2 3