CMaterialValueShow.cs 3.2 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. void Start()
  16. {
  17. listMaterialValue = new List<MaterialShow>();
  18. CreateMaterial();
  19. }
  20. /// <summary>
  21. /// 创建组合素材
  22. /// </summary>
  23. private void CreateMaterial()
  24. {
  25. switch ((MaterialType)cMValue.type)
  26. {
  27. case MaterialType.NULL:
  28. break;
  29. case MaterialType.Image:
  30. case MaterialType.Video:
  31. case MaterialType.Model:
  32. case MaterialType.Text:
  33. case MaterialType.ImageorViedoAndText:
  34. case MaterialType.ModelAndText:
  35. //UIKit.GetPanel<EditorPanel>().dicCMVOjbes.Add(cMValue.name, new List<GameObject>());
  36. //UIKit.GetPanel<EditorPanel>().dicCMVOjbes[cMValue.name].Add(gameObject);
  37. cMValue.materialList.ForEach(item =>
  38. {
  39. StartCoroutine(LoadMaterialObj(item));
  40. });
  41. break;
  42. default:
  43. break;
  44. }
  45. }
  46. private IEnumerator LoadMaterialObj(MaterialObjValue item)
  47. {
  48. GameObject obj = new GameObject(item.name);
  49. yield return new WaitForFixedUpdate();
  50. obj.transform.parent = transform;
  51. obj.transform.LocalIdentity();
  52. // SetObjMaterial(obj, item.ObjectTransform);
  53. Debug.Log(obj.name + " " + item.ObjectTransform);
  54. MaterialShow materialShow = obj.AddComponent<MaterialShow>();
  55. materialShow.value = item;
  56. materialShow.spoitName = spoitname;
  57. Debug.Log(item.name + " " + item.ObjectTransform.startPos.x);
  58. materialShow.type = cMValue.template;
  59. materialShow.updateTime = cMValue.updateTime;
  60. listMaterialValue.Add(materialShow);
  61. Debug.Log(item.name);
  62. UIKit.GetPanel<EditorPanel>().dicObjs[spoitname].Add(materialShow.gameObject);
  63. // UIKit.GetPanel<EditorPanel>().dicCMVOjbes[cMValue.name].Add(materialShow.gameObject);
  64. }
  65. /// <summary>
  66. /// 设置物体的初始位置
  67. /// </summary>
  68. /// <param name="obj"></param>
  69. /// <param name="objectData"></param>
  70. public void SetObjMaterial(GameObject obj, ObjectTransform objectData)
  71. {
  72. Debug.Log(objectData.startScale);
  73. if (objectData == null)
  74. return;
  75. if (objectData.nowScale == Vector3.zero)
  76. {
  77. obj.transform.localPosition = objectData.startPos;
  78. obj.transform.localEulerAngles = objectData.startRot;
  79. obj.transform.localScale = objectData.startScale;
  80. }
  81. else
  82. {
  83. obj.transform.localPosition = objectData.nowPos;
  84. obj.transform.localEulerAngles = objectData.nowRot;
  85. obj.transform.localScale = objectData.nowScale;
  86. }
  87. }
  88. }