Author Topic: Scripting clipping  (Read 6716 times)

tgraupmann

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Scripting clipping
« on: January 14, 2013, 03:20:47 PM »
How can I set the Clipping Center and Size for a UIPanel through script?

I thought maybe something like this:
               item.panel.clipping = UIDrawCall.Clipping.HardClip;
               item.panel.clipRange.Set(-x, 0, 0, 930);
               item.panel.UpdateDrawcalls();

I want Hard Clip, X=136, Size.X=930.

If I change the clip in the update loop, do I need to update the draw calls or something for it to update?

Thanks,

~Tim

tgraupmann

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: Scripting clipping
« Reply #1 on: January 14, 2013, 03:24:20 PM »
item.panel.clipping = UIDrawCall.Clipping.HardClip;

Was able to change the clipping.

But now I need the script to change the center and size...

tgraupmann

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: Scripting clipping
« Reply #2 on: January 14, 2013, 03:34:01 PM »
Found it:

               var range : Vector4 = new Vector4(x, 0, 930, 0);
               item.panel.clipping = UIDrawCall.Clipping.HardClip;
               item.panel.clipRange = range;

JavaScript and intellisense is a pain...

tgraupmann

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: Scripting clipping
« Reply #3 on: January 14, 2013, 03:41:06 PM »
The UIPanelInspector marks the UIPanel as dirty when the clip range is changed. How would I do that from the game code at runtime?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scripting clipping
« Reply #4 on: January 15, 2013, 07:08:09 AM »
What for? The inspector marks the script / game object as dirty so Unity knows that it should be saved. Not sure why you would want to mess with that yourself?

tgraupmann

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: Scripting clipping
« Reply #5 on: January 15, 2013, 11:58:47 AM »
I just wanted to know if there's anything extra I need to do if I change the clip range during an update frame to get Unity to use that?

Instead I put the child objects into a child containter "ClipContainer" and move that which respects the clip range.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scripting clipping
« Reply #6 on: January 15, 2013, 11:12:57 PM »
Assuming the panel has clipping enabled, adjusting clip range should work just fine.