Author Topic: Animator NGUI UI2D replace  (Read 4575 times)

AgOrisTWL

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Animator NGUI UI2D replace
« on: January 03, 2017, 03:14:04 PM »
Hello everyone,

I have worked a little with NGUI for some UI and enemies interaction, and have recently encountered with a little issue with UI2D sprite.

I made a tool to override animations in a Overridable animator, this animations contains the monster movement and sprites, and this overridable animator is in a Gameobject with a UI2D Sprite. I thought that with my animator i would be able to replace the texture in the UI2D script (Kind of like Unity commonly does), but it seems that its not possible,its kind of constant with the one I assigned at the editor, Am i right?

Now, I know that exists "UI Sprite" and "UI2D Sprite Animated", but the tool I made just works by overriding animations. Exists some way I can use animators in NGUI as is commonly used in Unity, like, by repleacing sprites every frame in the sprite class?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Animator NGUI UI2D replace
« Reply #1 on: January 04, 2017, 09:59:32 AM »
What your script (and Unity's animations) does, is changes a hidden, private property that should not be visible to Unity at all. The fact that it's able to see it and let you modify it is an ancient bug on Unity's side.

When working with NGUI and assigning something, you need to do it via an appropriate property. In your case, that's the mainTexture property. Simply changing a hidden private field's value won't do anything because NGUI won't know that you've changed it.

AgOrisTWL

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Animator NGUI UI2D replace
« Reply #2 on: January 04, 2017, 06:33:13 PM »
Oh, Thanks for the fast answer!!

Well... if its some kind of bug, then i can't do much about it.

Then, trying to find another solution, i want to adapt a Unity Canvas to the Size/Aspect Radio of NGUI's UI Root, kind of both styles of Canvas in one, is there anyway i can do that? When I try to do it, setting the Canvas Render Mode with the UI Root camera, shrinks my Canvas a lot compared to the UI Root Canvas.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Animator NGUI UI2D replace
« Reply #3 on: January 05, 2017, 09:58:46 AM »
The "bug" is only in Unity letting you see something that should be hidden.

If you want to animate via a property (which Unity does not support), you need to write an intermediate script that basically has a public field that you will animate, and an Update() function that will assign a sprite's property based on your field. Look for "Animated" series of scripts: AnimatedColor, AnimatedAlpha both do this.

I am not sure about the canvas. Although I helped kickstart Unity's UI back in the day, I haven't used it since I went back to Tasharen. You might need to ask on Unity's support forum.