CMaterialValueShow.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using QFramework;
  5. using UniRx;
  6. using QFramework.MREditor;
  7. public class CMaterialValueShow : MonoBehaviour
  8. {
  9. public CompositeMaterialValue cMValue;
  10. public string spoitname;
  11. /// <summary>
  12. /// 当前组合素材内所有单个素材
  13. /// </summary>
  14. public List<MaterialShow> listMaterialValue;
  15. private ObjectTransform startObjTransform;
  16. void Start()
  17. {
  18. listMaterialValue = new List<MaterialShow>();
  19. startObjTransform = new ObjectTransform();
  20. startObjTransform.startPos = Vector3.zero;
  21. startObjTransform.startRot = Vector3.zero;
  22. startObjTransform.startScale = Vector3.one;
  23. startObjTransform.nowPos = Vector3.zero;
  24. startObjTransform.nowRot = Vector3.zero;
  25. startObjTransform.nowScale = Vector3.zero;
  26. CreateMaterial();
  27. }
  28. /// <summary>
  29. /// 创建组合素材
  30. /// </summary>
  31. private void CreateMaterial()
  32. {
  33. switch ((MaterialType)cMValue.type)
  34. {
  35. case MaterialType.NULL:
  36. break;
  37. case MaterialType.Image:
  38. case MaterialType.Video:
  39. case MaterialType.Model:
  40. case MaterialType.Text:
  41. case MaterialType.ImageorViedoAndText:
  42. case MaterialType.ModelAndText:
  43. //UIKit.GetPanel<EditorPanel>().dicCMVOjbes.Add(cMValue.name, new List<GameObject>());
  44. //UIKit.GetPanel<EditorPanel>().dicCMVOjbes[cMValue.name].Add(gameObject);
  45. cMValue.materialList.ForEach(item =>
  46. {
  47. GameObject obj = new GameObject(item.name);
  48. obj.transform.parent = transform;
  49. obj.transform.Identity();
  50. // SetObjMaterial(obj, item.ObjectTransform);
  51. MaterialShow materialShow = obj.AddComponent<MaterialShow>();
  52. materialShow.value = item;
  53. materialShow.type = cMValue.template;
  54. materialShow.spoitName = spoitname;
  55. materialShow.updateTime = cMValue.updateTime;
  56. listMaterialValue.Add(materialShow);
  57. Debug.Log(item.name);
  58. UIKit.GetPanel<EditorPanel>().dicObjs[spoitname].Add(materialShow.gameObject);
  59. // UIKit.GetPanel<EditorPanel>().dicCMVOjbes[cMValue.name].Add(materialShow.gameObject);
  60. });
  61. break;
  62. default:
  63. break;
  64. }
  65. }
  66. /// <summary>
  67. /// 设置物体的初始位置
  68. /// </summary>
  69. /// <param name="obj"></param>
  70. /// <param name="objectData"></param>
  71. public void SetObjMaterial(GameObject obj, ObjectTransform objectData)
  72. {
  73. Debug.Log(objectData.startScale);
  74. if (objectData == null)
  75. return;
  76. if (objectData.nowScale == Vector3.zero)
  77. {
  78. obj.transform.localPosition = objectData.startPos;
  79. obj.transform.localEulerAngles = objectData.startRot;
  80. obj.transform.localScale = objectData.startScale;
  81. }
  82. else
  83. {
  84. obj.transform.localPosition = objectData.nowPos;
  85. obj.transform.localEulerAngles = objectData.nowRot;
  86. obj.transform.localScale = objectData.nowScale;
  87. }
  88. }
  89. }