playMaker

Author Topic: Set Material Color to affect parent and all children [SOLVED]  (Read 10766 times)

elvis75k

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 97
    • nRender
Set Material Color to affect parent and all children [SOLVED]
« on: January 19, 2012, 07:58:19 AM »
The thing i'm looking for is like the unity editor scene viewport effect: when you match the name in the search filter toolbar, all the object become progressively white, except the one you're looking for.
Here the question that i have right now:

How to add to SetMaterialColor the ability to iterate through the childrens of a group of object?
I need to dissolve some grouped models to make il look half transparent (NOT ONLY WHITE), i don't want to do this for every single mesh or it will result in a total messy workflow. I'm aware of the fact that object must have renderer and transparent shader..

It will be also a dream if i can handle somewhere the hue/saturation of textures with animations or iTweens.

edit: do i need a custom SetMaterialColor or this can be done already with a combo of other available actions? I can't find a way to do this and it is so frustrating.
« Last Edit: January 31, 2012, 09:12:34 AM by elvis75k »

elvis75k

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 97
    • nRender
Re: Set Material Color to affect parent and all children
« Reply #1 on: January 21, 2012, 11:21:16 AM »
Here is a script that change color to all hierarchy (if the root is just a game object, one should add a mesh renderer component to it or you end with an error). This is quite good for my needs.
I need to add this [affect child] to the SetMaterialColor action.
A selection set like in maya will be very usefull now.
here is the script:

Code: [Select]
using UnityEngine;
using System.Collections;

public class FadeTest : MonoBehaviour
{
Color startColor;
Color currentColor;
Color endColor;
bool shouldFade = false;
float startTime;
float endTime;
public float seconds = 5.0f;
float t;

// Use this for initialization
void Start ()
{
startColor = gameObject.renderer.material.color;
endColor = new Color(startColor.r, startColor.g, startColor.b, 0.0f);

for ( int childIndex = 0; childIndex < gameObject.transform.GetChildCount(); childIndex++)
{
Transform child = gameObject.transform.GetChild(childIndex);

child.gameObject.AddComponent<FadeTest>();
}
}

// Update is called once per frame
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
shouldFade = true;

startTime = Time.time;

endTime = startTime + seconds;
}

Fade();
}

void Fade()
{
if ( shouldFade )
{
t = Time.time / endTime;

currentColor = Color.Lerp(startColor, endColor, t);

gameObject.renderer.material.SetColor("_Color", currentColor);

if ( currentColor == endColor )
{
shouldFade = false;
startTime = 0.0f;
endTime = 0.0f;
t= 0.0f;
}
}
}
}

http://forum.unity3d.com/threads/113039-Fade-Object-and-Children?p=751029&viewfull=1#post751029

elvis75k

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 97
    • nRender
Re: Set Material Color to affect parent and all children
« Reply #2 on: January 27, 2012, 09:12:16 AM »
bump?
While learning that transparent shaders is not so good for what i'm doing now..
i only need to change material color for all child in a "group" to affect them all with one simlpe action (every child has it own material). I can't do it by myself, i don't have yet the skills to hack/compare/edit official actions :(
i'll appreciate some help or hints!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Set Material Color to affect parent and all children
« Reply #3 on: January 31, 2012, 05:04:43 AM »
Hi,

 Here we go:)

http://hutonggames.com/playmakerforum/index.php?topic=1053.0

If this is not exactly what you want, please clarify, but that should do.

Bye,

 Jean

elvis75k

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 97
    • nRender
Re: Set Material Color to affect parent and all children
« Reply #4 on: January 31, 2012, 08:57:12 AM »
Splendid! It is possible to have a reset on exit?
Thank you very much :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Set Material Color to affect parent and all children [SOLVED]
« Reply #5 on: January 31, 2012, 02:16:11 PM »
Hi,

 Yes, it's possible. I have edited the post. Now there is a "revertOnExit" option.

 Bye,

 Jean