-
Notifications
You must be signed in to change notification settings - Fork 0
/
materialize.cs
50 lines (42 loc) · 1.06 KB
/
materialize.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class materialize : MonoBehaviour
{
public List<Material> materials;
public List<string> mapping;
// Use this for initialization
void Awake()
{
SearchOnMe();
}
// Update is called once per frame
void Update()
{
SearchOnMe();
}
void SearchOnMe()
{
Debug.Log("Searching....");
NameContains(this.transform);
Debug.Log("Done!");
}
void NameContains(Transform transf)
{
for (int i = 0; i < mapping.Count; i++) {
if ((mapping[i] != "") && transf.name.Contains(mapping[i])) {
// Apply
Renderer rend = transf.GetComponent<Renderer>();
if (rend != null) {
rend.material = materials[i];
}
}
}
// now search in its children, grandchildren etc.
foreach (Transform child in transf)
{
NameContains(child);
}
}
}