using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class StatuimProfilerTest : MonoBehaviour { public Transform root; public GameObject goToggle; public MeshRenderer groundRender; string [] texs = { "_MainTex", "_RTex", "_GTex", "_BTex", "_ATex", "_MaskTex", }; Dictionary texsMap = new Dictionary(); /// /// Awake is called when the script instance is being loaded. /// void Start() { StaticBatchingUtility.Combine(root.gameObject); goToggle.SetActive(false); GameObject go; for (int i = 0; i < texs.Length; i++) { var name = texs[i]; go = Instantiate(goToggle, goToggle.transform.parent); go.SetActive(true); go.GetComponentInChildren().text = texs[i]; go.GetComponent().onValueChanged.AddListener(onTextureTest); var tex = groundRender.material.GetTexture(name); texsMap.Add(name, tex); } go = Instantiate(goToggle, goToggle.transform.parent); go.SetActive(true); go.GetComponentInChildren().text = "================="; var count = root.childCount; for (int i = 0; i < count; i++) { var child = root.GetChild(i); go = Instantiate(goToggle, goToggle.transform.parent); go.SetActive(true); go.GetComponentInChildren().text = child.name; go.GetComponent().onValueChanged.AddListener(onToggleValueChanged); } } void onToggleValueChanged(bool visible) { var go = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject; var toggle = go.GetComponent(); root.Find(go.GetComponentInChildren().text).gameObject.SetActive(visible); } void onTextureTest(bool visible) { var go = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject; var toggle = go.GetComponent(); var name = go.GetComponentInChildren().text; Texture tex = null; if (visible) { texsMap.TryGetValue(name, out tex); } groundRender.material.SetTexture(name, tex); } void onAddBtnClick() { } void onDeleteBtnClick() { groundRender.material.SetTexture("_MainTex", null); } }