1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- 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<string, Texture> texsMap = new Dictionary<string, Texture>();
- /// <summary>
- /// Awake is called when the script instance is being loaded.
- /// </summary>
- 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>().text = texs[i];
- go.GetComponent<Toggle>().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>().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>().text = child.name;
- go.GetComponent<Toggle>().onValueChanged.AddListener(onToggleValueChanged);
- }
- }
- void onToggleValueChanged(bool visible) {
- var go = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject;
- var toggle = go.GetComponent<Toggle>();
- root.Find(go.GetComponentInChildren<Text>().text).gameObject.SetActive(visible);
- }
- void onTextureTest(bool visible) {
- var go = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject;
- var toggle = go.GetComponent<Toggle>();
- var name = go.GetComponentInChildren<Text>().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);
- }
- }
|