Author Topic: Turning off UISprite's "Fill Center" via code?  (Read 1888 times)

pradafang

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Turning off UISprite's "Fill Center" via code?
« on: March 12, 2014, 08:56:31 AM »
Hello everyone,

Currently I'm working on a script that creates a sliced sprite and adds it to my scene. However, I haven't been able to turn off the "Fill Center" check box via code. I need to turn it off for many sprites, so turning it off manually each time isn't the best idea.

Can someone tell me which property I must modify in order for the "Fill Center" to appear off?

Basically what I'm doing is something like:

  1. UISprite outline = go.AddComponent<UISprite>();
  2. //Then I do stuff related to sprite size, name, and other properties
  3.  
  4. outline.type = UISprite.Type.Sliced;
  5. //Turn off "Fill Center" here somehow
  6.  

If you could help me out, I would really appreciate it!

jamjardavies

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Turning off UISprite's "Fill Center" via code?
« Reply #1 on: March 12, 2014, 10:31:53 AM »
Hi,

Not sure if this helps but looking into the inspector, it looks like it's done like so:

  1. sp = serializedObject.FindProperty("centerType");
  2. bool val = (sp.intValue != (int)UISprite.AdvancedType.Invisible);
  3.  
  4. if (val != EditorGUILayout.Toggle("Fill Center", val))
  5. {
  6.         sp.intValue = val ? (int)UISprite.AdvancedType.Invisible : (int)UISprite.AdvancedType.Sliced;
  7. }
  8.  

So I assume, sprite.centerType.intValue?

Regards

James
« Last Edit: March 12, 2014, 10:37:36 AM by jamjardavies »

pradafang

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Turning off UISprite's "Fill Center" via code?
« Reply #2 on: March 12, 2014, 02:57:49 PM »
You're right!

Setting my sprite's centerType to UISprite.AdvancedType.Invisible made it work.

Thanks!