Search Unity

Gradient Editor as an inspector variable I can access through script?

Discussion in 'Editor & General Support' started by J_P_, Mar 1, 2012.

  1. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    I'm referring to the nice Gradient Editor available on the new shuriken particle system. Is it possible to use that as a variable I can have in the inspector for my own scripts? I could see it working similar to the existing AnimationCurve variable.

    currentColor = colorGradient.Evaluate(0.5f);
    (this would grab whatever color is at the halfway point in the gradient)

    edit: I guess it might be possible for me to set up a dummy particle with the gradient I want and just read the color of the particle.
     
    Last edited: Mar 1, 2012
  2. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    Well that looks like a dead end... ParticleSystem.Particle.color doesn't give me the actual color of the particle (which is controlled by color over lifetime), it only gives me the starting color. Is that intended..? Doesn't seem very useful.

    edit: to get around it, I'm creating/destroying particles as close to 30fps as I can get so that they get a new starting color over time that I can read. Still has a flickering problem though. So many hoops to jump through to do what I want -_-
     
    Last edited: Mar 28, 2012
  3. Patapouffe

    Patapouffe

    Joined:
    Apr 3, 2010
    Posts:
    88
    Well it is useful if you have one prefab of your effect but need the effect to be a different color sometimes without having to make a prefab for each color you are using.

    However, I agree with you, having access to the gradient would be great as it would allow more options.
     
  4. deram_scholzara

    deram_scholzara

    Joined:
    Aug 26, 2005
    Posts:
    1,043
    Man, I would totally love to have access to Shuriken's gradient class. I wouldn't even be using it for shuriken most of the time. I'd most likely use it in place of Color.Lerp() (or a series of them).
     
  5. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    For what it's worth, my workaround eventually worked out decently -- just feels sloppy.
     
    Last edited: Mar 29, 2012
  6. shallwaycn

    shallwaycn

    Joined:
    Apr 3, 2012
    Posts:
    202
    bump.

    can unity provide the gradient editor script? I'm dying to use this editor tool for my own package.
     
  7. Critical

    Critical

    Joined:
    Aug 7, 2012
    Posts:
    5
    indeed, that would be a great feature, I was looking for the same.
     
  8. Alf203

    Alf203

    Joined:
    Dec 7, 2012
    Posts:
    461
    +1 This would be a very useful feature.
     
  9. hklown

    hklown

    Joined:
    Oct 4, 2012
    Posts:
    2
    It seems like there's an undocumented class UnityEngine.Gradient that uses the gradient inspector if declared as a public member of a MonoBehaviour. It has an Evaluate(float) method and steps can be added programmatically.
     
    Psyco92 likes this.
  10. Psyco92

    Psyco92

    Joined:
    Nov 15, 2013
    Posts:
    22
    This just saved me a lot of time. Many thanks great sir!