StatuimProfilerTest.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class StatuimProfilerTest : MonoBehaviour {
  6. public Transform root;
  7. public GameObject goToggle;
  8. public MeshRenderer groundRender;
  9. string [] texs = {
  10. "_MainTex",
  11. "_RTex",
  12. "_GTex",
  13. "_BTex",
  14. "_ATex",
  15. "_MaskTex",
  16. };
  17. Dictionary<string, Texture> texsMap = new Dictionary<string, Texture>();
  18. /// <summary>
  19. /// Awake is called when the script instance is being loaded.
  20. /// </summary>
  21. void Start()
  22. {
  23. StaticBatchingUtility.Combine(root.gameObject);
  24. goToggle.SetActive(false);
  25. GameObject go;
  26. for (int i = 0; i < texs.Length; i++)
  27. {
  28. var name = texs[i];
  29. go = Instantiate(goToggle, goToggle.transform.parent);
  30. go.SetActive(true);
  31. go.GetComponentInChildren<Text>().text = texs[i];
  32. go.GetComponent<Toggle>().onValueChanged.AddListener(onTextureTest);
  33. var tex = groundRender.material.GetTexture(name);
  34. texsMap.Add(name, tex);
  35. }
  36. go = Instantiate(goToggle, goToggle.transform.parent);
  37. go.SetActive(true);
  38. go.GetComponentInChildren<Text>().text = "=================";
  39. var count = root.childCount;
  40. for (int i = 0; i < count; i++)
  41. {
  42. var child = root.GetChild(i);
  43. go = Instantiate(goToggle, goToggle.transform.parent);
  44. go.SetActive(true);
  45. go.GetComponentInChildren<Text>().text = child.name;
  46. go.GetComponent<Toggle>().onValueChanged.AddListener(onToggleValueChanged);
  47. }
  48. }
  49. void onToggleValueChanged(bool visible) {
  50. var go = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject;
  51. var toggle = go.GetComponent<Toggle>();
  52. root.Find(go.GetComponentInChildren<Text>().text).gameObject.SetActive(visible);
  53. }
  54. void onTextureTest(bool visible) {
  55. var go = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject;
  56. var toggle = go.GetComponent<Toggle>();
  57. var name = go.GetComponentInChildren<Text>().text;
  58. Texture tex = null;
  59. if (visible)
  60. {
  61. texsMap.TryGetValue(name, out tex);
  62. }
  63. groundRender.material.SetTexture(name, tex);
  64. }
  65. void onAddBtnClick() {
  66. }
  67. void onDeleteBtnClick() {
  68. groundRender.material.SetTexture("_MainTex", null);
  69. }
  70. }