Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Soft shadows - my custom component

Discussion in 'UI Toolkit' started by tattyd, Jun 26, 2022.

  1. tattyd

    tattyd

    Joined:
    Feb 17, 2020
    Posts:
    14
    Hey all,

    Like many others, I was in need of a soft shadow for some of my elements in UI Toolkit. I decided this was a good time to learn about OnGenerateVisualContent :)

    Here's my Soft Shadows component:

    https://gist.github.com/tattyd/6807d6be9e550a1f24ad17f21d69177e

    Usage:

    Wrap whatever VisualElement should be shadowed with a <Shadow></Shadow> component.

    Control shadow colour using the USS color style property (shows as 'text color' in the editor). This allows you to do fun mouseover effects, as well as transitions:

    Code (CSharp):
    1. Shadow {
    2.     transition: 250ms;
    3. }
    4. Shadow:hover {
    5.     color: white;
    6. }
    Attributes:
    • shadow-corner-radius controls the corner radius, although in practice it feels more like controlling the blurryness.
    • shadow-scale allows you to scale the shadow up/down to alter how far it renders from the contents.
    • shadow-offset-x and shadow-offset-y allow you to move the shadow around, e.g. to simulate light coming from a specific direction.
    Hope it's useful to somebody!

    Sample:

    upload_2022-6-25_21-53-34.png
     
  2. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,847
    very nice
     
  3. Neiyra

    Neiyra

    Joined:
    Apr 19, 2016
    Posts:
    28
    Thanks, that great! I´m gonna test it immediately.
     
  4. lofell

    lofell

    Joined:
    Nov 4, 2020
    Posts:
    7
    nice!
     
  5. AgelessFrost

    AgelessFrost

    Joined:
    Jan 26, 2019
    Posts:
    5
    This does work well, though for anyone looking at this, it does not conform to the shape of the texture, so if you just want a circular or squared background effect, this can work very well!
     
  6. Tariq-11

    Tariq-11

    Joined:
    Jan 5, 2017
    Posts:
    5
    That is really nice amaizing
    but i am not able to controll attributes in uss but i can in the inspector
    i tryied using class id and dirrect element but it didn't work in uss
     
  7. Muneeb0210

    Muneeb0210

    Joined:
    Oct 1, 2022
    Posts:
    1
    I am new to unity and ui toolkit is like an alien to me. what does this mean? "wrap around" do i have to go in uxml file or some other thing