Search Unity

'Driven by' - is there a way to do this from our own scripts?

Discussion in 'UGUI & TextMesh Pro' started by StarManta, Sep 2, 2014.

  1. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Would it be possible to, for a component I write that controls the position of a RectTransform, have the controls grayed out just like when they are 'driven' by other builtin components?

    Better yet, could we also do this with regular Transforms? It'd be a really nice improvement to the workflow.
     
  2. secondbreakfast

    secondbreakfast

    Joined:
    Jan 5, 2013
    Posts:
    98
    It looks like there is a DrivenRectTransformTracker that you can add your RectTransforms to to disable. It looks like that's RectTransform specific though.
     
  3. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Yes, use the DrivenRectTransformTracker to drive RectTransforms.

    Every time the layout is updated, you should first call Clear on it, and then add the RectTransforms you want to drive, one by one. Then you can set the properties on the RectTransforms you've set as driven.

    Make sure to also call Clear in OnDisable of your component.

    The ability to set properties as driven is specific to RectTransform and can't be used for anything else in Unity.
     
    UnityKristy and rakkarage like this.