using ARLocation; using System.Collections; using System.Collections.Generic; using ARPlus; using UnityEngine; using Util; public class ARDataManager : MonoBehaviour { // Start is called before the first frame update private ARSceneManager arscenemgr_ = null; private GameObject goCL_; private GameObject[] goMax_; private GameObject[] goBW_; void Start() { var go = GameObject.Find("/ARSceneManager"); arscenemgr_ = go.GetComponent(); } public void AddClToScene() { if (goCL_ != null) return; double[][] rcdata = GetCLData(); LocationPath locPath = BuildCLLocationPath(rcdata); GameObject renderClGameObject = arscenemgr_.GetRenderCL(); goCL_ = new GameObject("RendCLInstance"); MoveAlongPath moveAlongPath = goCL_.AddComponent(); moveAlongPath.PathSettings = renderClGameObject.GetComponent().pathSettings; moveAlongPath.PathSettings.LineRenderer = renderClGameObject.GetComponent(); moveAlongPath.PlacementSettings = renderClGameObject.GetComponent().placementSettings; moveAlongPath.SetLocationPath(locPath); } public void AddBwToScene() { if (goBW_ != null) return; List bwdata = GetBWData(); goBW_ = new GameObject[bwdata.Count]; for (int i = 0; i < bwdata.Count; i++) { LocationPath locPath = BuildBWLocationPath(bwdata[i]); GameObject renderBwGameObject = arscenemgr_.GetRenderBW(); GameObject goBWItem_ = new GameObject("RendBWInstance-" + (i + 1).ToString()); goBW_[i] = goBWItem_; MoveAlongPath moveAlongPath = goBWItem_.AddComponent(); moveAlongPath.PathSettings = renderBwGameObject.GetComponent().pathSettings; moveAlongPath.PathSettings.LineRenderer = renderBwGameObject.GetComponent(); moveAlongPath.PathSettings.LineRenderer.loop = true; moveAlongPath.PlacementSettings = renderBwGameObject.GetComponent().placementSettings; moveAlongPath.SetLocationPath(locPath); } } public void AddMaxToScene() { if (goMax_ != null) return; // double[][] rcdata = GetMaxData(); var rcdata = GetGeoData("Max"); goMax_ = new GameObject[rcdata.Count]; for (int i = 0; i < rcdata.Count; i++) { LocationPath locPath = BuildLocationPath(rcdata[i]); GameObject renderMaxMaGameObject = arscenemgr_.GetRenderMax(); GameObject goMaxItem_ = new GameObject("RendMaxInstance-" + (i + 1).ToString()); goMax_[i] = goMaxItem_; MoveAlongPath moveAlongPath = goMaxItem_.AddComponent(); moveAlongPath.PathSettings = renderMaxMaGameObject.GetComponent().pathSettings; moveAlongPath.PathSettings.LineRenderer = renderMaxMaGameObject.GetComponent(); // 设置线段顶点数(如两点构成一条直线) moveAlongPath.PathSettings.LineRenderer.positionCount = 2; // // 设置宽度(起始和结束宽度) moveAlongPath.PathSettings.LineRenderer.startWidth = 0.1f; moveAlongPath.PathSettings.LineRenderer.endWidth = 0.1f; // // 设置颜色(支持渐变) moveAlongPath.PathSettings.LineRenderer.startColor = Color.red; moveAlongPath.PathSettings.LineRenderer.endColor = Color.blue; // // 设置材质(需指定Shader) moveAlongPath.PathSettings.LineRenderer.material = new Material(Shader.Find("Sprites/Default")); moveAlongPath.PlacementSettings = renderMaxMaGameObject.GetComponent().placementSettings; } // GameObject renderMaxMaGameObject = arscenemgr_.GetRenderMax(); // goMax_ = new GameObject("RendMaxInstance"); // MoveAlongPath moveAlongPath = goMax_.AddComponent(); // moveAlongPath.PathSettings = renderMaxMaGameObject.GetComponent().pathSettings; // moveAlongPath.PathSettings.LineRenderer = renderMaxMaGameObject.GetComponent(); // // 设置线段顶点数(如两点构成一条直线) // moveAlongPath.PathSettings.LineRenderer.positionCount = 2; // // // 设置宽度(起始和结束宽度) // moveAlongPath.PathSettings.LineRenderer.startWidth = 0.1f; // moveAlongPath.PathSettings.LineRenderer.endWidth = 0.1f; // // // 设置颜色(支持渐变) // moveAlongPath.PathSettings.LineRenderer.startColor = Color.red; // moveAlongPath.PathSettings.LineRenderer.endColor = Color.blue; // // // 设置材质(需指定Shader) // moveAlongPath.PathSettings.LineRenderer.material = new Material(Shader.Find("Sprites/Default")); // moveAlongPath.PlacementSettings = renderMaxMaGameObject.GetComponent().placementSettings; // moveAlongPath.SetLocationPath(locPath); } IReadOnlyList GetGeoData(string name) { var data = DataManager.geoDataDictionary[name]; return data; } List GetBWData() { List listCoords = new List(); double[][] lineCoords1 = new double[4][]; double[] coord11 = new double[3]; coord11[0] = 31.8494395; coord11[1] = 117.3096992; coord11[2] = 10; double[] coord12 = new double[3]; coord12[0] = 31.8493477; coord12[1] = 117.3099519; coord12[2] = 10; double[] coord13 = new double[3]; coord13[0] = 31.8492647; coord13[1] = 117.3099106; coord13[2] = 10; double[] coord14 = new double[3]; coord14[0] = 31.8493563; coord14[1] = 117.3096577; coord14[2] = 10; lineCoords1[0] = coord11; lineCoords1[1] = coord12; lineCoords1[2] = coord13; lineCoords1[3] = coord14; listCoords.Add(lineCoords1); double[][] lineCoords2 = new double[4][]; double[] coord21 = new double[3]; coord21[0] = 31.849531; coord21[1] = 117.3094462; coord21[2] = 10; double[] coord22 = new double[3]; coord22[0] = 31.8494394; coord22[1] = 117.309699; coord22[2] = 10; double[] coord23 = new double[3]; coord23[0] = 31.8493563; coord23[1] = 117.3096577; coord23[2] = 10; double[] coord24 = new double[3]; coord24[0] = 31.849448; coord24[1] = 117.3094049; coord24[2] = 10; lineCoords2[0] = coord21; lineCoords2[1] = coord22; lineCoords2[2] = coord23; lineCoords2[3] = coord24; listCoords.Add(lineCoords2); return listCoords; } LocationPath BuildBWLocationPath(double[][] data) { //MoveAlongPath.PathSettingsData psData = new MoveAlongPath.PathSettingsData(); LocationPath locPath = ScriptableObject.CreateInstance(); Location[] locs = new Location[4]; for (int i = 0; i < 4; i++) { locs[i] = new Location(data[i][0], data[i][1], data[i][2]) { AltitudeMode = AltitudeMode.Absolute }; } locPath.Locations = locs; locPath.SplineType = SplineType.LinearSpline; locPath.Alpha = 0.5f; locPath.SceneViewScale = 1.0f; //psData.LocationPath = locPath; return locPath; } double[][] GetCLData() //RiverCenterline { double[][] lineCoords = new double[6][]; double[] coord1 = new double[3]; coord1[0] = 31.8498255; coord1[1] = 117.306568; coord1[2] = 10; double[] coord2 = new double[3]; coord2[0] = 31.8493595; coord2[1] = 117.3083875; coord2[2] = 10; double[] coord3 = new double[3]; coord3[0] = 31.8490076; coord3[1] = 117.3097962; coord3[2] = 10; double[] coord4 = new double[3]; coord4[0] = 31.8489553; coord4[1] = 117.3100114; coord4[2] = 10; double[] coord5 = new double[3]; coord5[0] = 31.8479532; coord5[1] = 117.3123266; coord5[2] = 10; double[] coord6 = new double[3]; coord5[0] = 31.8474537; coord5[1] = 117.3130791; coord5[2] = 10; lineCoords[0] = coord1; lineCoords[1] = coord2; lineCoords[2] = coord3; lineCoords[3] = coord4; lineCoords[4] = coord5; lineCoords[5] = coord6; return lineCoords; } LocationPath BuildCLLocationPath(double[][] data) { //MoveAlongPath.PathSettingsData psData = new MoveAlongPath.PathSettingsData(); LocationPath locPath = ScriptableObject.CreateInstance(); Location[] locs = new Location[6]; for (int i = 0; i < 6; i++) { locs[i] = new Location(data[i][0], data[i][1], data[i][2]) { AltitudeMode = AltitudeMode.Absolute }; } locPath.Locations = locs; locPath.SplineType = SplineType.LinearSpline; locPath.Alpha = 0.5f; locPath.SceneViewScale = 1.0f; //psData.LocationPath = locPath; return locPath; } double[][] GetMaxData() //RiverCenterline { double[][] lineCoords = new double[2][]; double[] coord1 = new double[3]; coord1[0] = 31.8732576897494; coord1[1] = 117.13843113088807; coord1[2] = 10; double[] coord2 = new double[3]; coord2[0] = 31.873258780793716; coord2[1] = 117.1380031964643; coord2[2] = 10; lineCoords[0] = coord1; lineCoords[1] = coord2; return lineCoords; } LocationPath BuildLocationPath(Coords data) { // Debug.Log(data.coords.Count); var _data = data.coords; MoveAlongPath.PathSettingsData psData = new MoveAlongPath.PathSettingsData(); LocationPath locPath = ScriptableObject.CreateInstance(); Location[] locs = new Location[_data.Count]; for (int i = 0; i < _data.Count; i++) { locs[i] = new Location(_data[i].x, _data[i].y, _data[i].z) { AltitudeMode = AltitudeMode.Absolute }; } // locPath.Locations = locs; locPath.SplineType = SplineType.LinearSpline; locPath.Alpha = 0.5f; locPath.SceneViewScale = 1.0f; return locPath; } }