ProjectConfiguration.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. /// <summary>
  7. /// 场景的设置
  8. /// </summary>
  9. public class ProjectConfiguration : MonoBehaviour
  10. {
  11. public int cubeLength;
  12. public CubeItem item;
  13. public Transform trackingTarget;
  14. public Camera camera;
  15. private TestData data;
  16. void Start()
  17. {
  18. data = new TestData();
  19. data.Length = 40;
  20. data.UIInterval = 1;
  21. //data.EulerAngleX = false;
  22. //data.EulerAngleY = true;
  23. //data.EulerAngleZ = false;
  24. data.EulerAxle = 2;
  25. data.CameraFar = 2;
  26. data.isShowMeasure = false;
  27. data.FadeDis = 1;
  28. data.ShowDis = 0.4f;
  29. }
  30. private void Init()
  31. {
  32. //camera.farClipPlane = data.CameraFar;
  33. BladeServerManager.Instance.showDis = data.ShowDis;
  34. BladeServerManager.Instance.fadeDis = data.FadeDis;
  35. if (!data.isShowMeasure)
  36. return;
  37. for (float i = 0; i < data.Length+1; i+=data.UIInterval)
  38. {
  39. GameObject obj = GameObject.Instantiate(item.gameObject, transform);
  40. obj.name = i.ToString();
  41. obj.transform.localPosition = new Vector3(0, 0.1f, -i);
  42. obj.GetComponent<CubeItem>().text.text = i.ToString() + " M";
  43. obj.SetActive(true);
  44. }
  45. }
  46. // Update is called once per frame
  47. void Update()
  48. {
  49. if(trackingTarget!=null)
  50. {
  51. switch (data.EulerAxle)
  52. {
  53. case 1:
  54. transform.eulerAngles = new Vector3(0, trackingTarget.eulerAngles.x, 0);
  55. break;
  56. case 2:
  57. transform.eulerAngles = new Vector3(0, trackingTarget.eulerAngles.y, 0);
  58. break;
  59. case 3:
  60. transform.eulerAngles = new Vector3(0, trackingTarget.eulerAngles.z, 0);
  61. break;
  62. default:
  63. break;
  64. }
  65. transform.position = trackingTarget.position;
  66. }
  67. }
  68. public void Test()
  69. {
  70. }
  71. }
  72. public class TestData
  73. {
  74. public int Length { get; set; }// 需要显示的长度
  75. public float CameraFar { get; set; } // Camera的可见距离
  76. public float UIInterval { get; set; } // 间隔多少米显示距离UI 0.5m/1m/....
  77. //public bool EulerAngleX { get; set; } // 是否同步Tag X轴旋转
  78. //public bool EulerAngleY { get; set; } // 是否同步Tag Y轴旋转
  79. //public bool EulerAngleZ { get; set; } // 是否同步Tag Z轴旋转
  80. public int EulerAxle { get; set; } // 跟随哪个轴旋转 1 X轴 2 Y轴 3 Z轴
  81. public float ShowDis { get; set; } // 机柜详细信息 显示的距离
  82. public float FadeDis { get; set; } // 机柜详细信息 消失的距离
  83. public bool isShowMeasure { get; set; } // 是否显示测量长度的Demo
  84. }