Skip to content

Instantly share code, notes, and snippets.

@naojitaniguchi
Created May 25, 2016 05:06
Show Gist options
  • Select an option

  • Save naojitaniguchi/a9b2ce6b8ac19bf9197e031159d44214 to your computer and use it in GitHub Desktop.

Select an option

Save naojitaniguchi/a9b2ce6b8ac19bf9197e031159d44214 to your computer and use it in GitHub Desktop.
Set value to children under target node
using UnityEngine;
using System.Collections;
public class SetValueToChildren : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(SetValueToChildren))]
public class SetValueToChildrenEditor : Editor
{
void setValueToMaterial( GameObject go)
{
Debug.Log(go.name);
Renderer renderer = go.GetComponent<Renderer>();
if (renderer != null)
{
Debug.Log(go.name);
renderer.sharedMaterial.SetFloat("valueName", 0.0f);
}
for (int i = 0; i < go.transform.childCount; i++)
{
Transform t = go.transform.GetChild(i);
setLineWidthToMaterial(t.gameObject);
}
}
public override void OnInspectorGUI()
{
if (GUILayout.Button("SetValue", GUILayout.Width(100f)))
{
SetValueToChildren myTarget = (SetValueToChildrenEditor)target;
setValueToMaterial(myTarget.gameObject);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment