public static LumarcaLine LoadFromJSON(JObject jLine) { LumarcaLine ll = new LumarcaLine( UtilScript.JsonToVector3(jLine[JSON_TOP]), UtilScript.JsonToVector3(jLine[JSON_BOTTOM]), jLine[JSON_MATERIAL].ToString(), (bool)jLine[JSON_HAS_DOT]); return(ll); }
// Use this for initialization void Start() { Cursor.visible = false; SetMaterial(); pool = new List <Vector3>(); for (int i = 0; i < 10000; i++) { pool.Add(new Vector3()); } result = new List <float>(); TextAsset asset = Resources.Load("positions") as TextAsset; Stream s = new MemoryStream(asset.bytes); BinaryReader reader = new BinaryReader(s); // BinaryReader reader = new BinaryReader(File.Open("positions.json", FileMode.Open)); JSONNode ja = SimpleJSON.JSONNode.Deserialize(reader); for (int i = 0; i < ja.Count; i++) { Vector3 vec = UtilScript.JsonToVector3(ja[i]); posList.Add(vec); } pos = posList.ToArray(); Debug.Log("Num Lines: " + pos.Length); CameraFrustumScript cfs = Camera.main.GetComponent <CameraFrustumScript>(); front = cfs.GetFrontPlane(); back = new Vector3[4]; for (int i = 0; i < front.Length; i++) { back[i] = UtilScript.CloneVec3(front[i]); back[i].z = Camera.main.farClipPlane - Camera.main.nearClipPlane; } }
// Use this for initialization void Start() { Cursor.visible = false; ray = new Ray(); BinaryReader reader = new BinaryReader(File.Open("DotPositions.json", FileMode.Open)); // JSONNode ja = SimpleJSON.JSONNode.Deserialize(reader); string jsonStr = reader.ReadString(); JObject ja = JsonConvert.DeserializeObject(jsonStr) as JObject; for (int i = 0; i < ja.Count; i++) { Vector3 vec = UtilScript.JsonToVector3(ja[i]); posList.Add(vec); } Dictionary <int, List <Vector3> > sameDepth = new Dictionary <int, List <Vector3> >(); dotsByZY = new Dictionary <int, Dictionary <int, List <Vector3> > >(); quadsByZY = new Dictionary <int, Dictionary <int, List <GameObject> > >(); //Sort all the dots at the same depth into a temporary Dictionary foreach (Vector3 dPos in posList) { if (!sameDepth.ContainsKey((int)dPos.z)) { sameDepth.Add((int)dPos.z, new List <Vector3>()); } sameDepth[(int)dPos.z].Add(dPos); } //Sort all the dots into a Dictionary of Dictionarys, sorted by Z and Y //This makes rows of dots, or lines, which we can then use to check intersections foreach (int z in sameDepth.Keys) { dotsByZY.Add(z, new Dictionary <int, List <Vector3> >()); List <Vector3> list = sameDepth[z]; foreach (Vector3 zPos in list) { if (!dotsByZY[z].ContainsKey((int)zPos.y)) { dotsByZY[z].Add((int)zPos.y, new List <Vector3>()); } dotsByZY[z][(int)zPos.y].Add(zPos); } } int totalLines = 0; //Count up all the lines, create a Quad for each position foreach (int zVal in dotsByZY.Keys) { Dictionary <int, List <Vector3> > dict = dotsByZY[zVal]; if (debugMessages) { Debug.Log("->" + zVal + ": " + dict.Count); } quadsByZY.Add(zVal, new Dictionary <int, List <GameObject> >()); foreach (int yVal in dict.Keys) { List <Vector3> line = dict[yVal]; if (debugMessages) { Debug.Log("---->" + yVal + ": " + line.Count); } quadsByZY[zVal].Add(yVal, new List <GameObject>()); foreach (Vector3 vec in line) { GameObject q = Instantiate(Resources.Load("Quad")) as GameObject; q.transform.localScale = new Vector3(dotSize / 2, dotSize / 2, dotSize / 2); q.transform.position = vec; q.SetActive(false); quadsByZY[zVal][yVal].Add(q); } totalLines++; } } if (debugMessages) { Debug.Log("totalLines: " + totalLines); } int posCount = 0; CameraFrustrumScript cfs = Camera.main.GetComponent <CameraFrustrumScript>(); front = cfs.GetFrontPlane(); back = new Vector3[4]; for (int i = 0; i < front.Length; i++) { back[i] = UtilScript.CloneVec3(front[i]); back[i].z = Camera.main.farClipPlane - Camera.main.nearClipPlane; } }
// Use this for initialization void Setup() { if (!init) { PlayerPrefs.SetString(PP_KILL_STRING, ""); foreach (int i in killStrings) { killStringsList.Add(i); } print("killStringsList:" + killStringsList.Count); string text = PlayerPrefs.GetString(PP_KILL_STRING, ""); string[] splitKill = text.Split(','); print("text: " + text); for (int i = 0; i < splitKill.Length; i++) { int num = 0; System.Int32.TryParse(splitKill[i], out num); //KILL STRING MIGHT ALWAYS INCLUDE 0, BECAUSE OF TryParse if (!killStringsList.Contains(num)) { killStringsList.Add(num); } else { print("Killer"); } } for (int i = 0; i < killStringsList.Count; i++) { int num = killStringsList[i]; while (killStringsList.Contains(num)) { killStringsList.Remove(num); } killStringsList.Add(num); } print("killStringsList count: " + killStringsList.Count); init = true; Cursor.visible = !Application.isEditor; SetMaterial(); pool = new List <Vector3>(); for (int i = 0; i < 10000; i++) { pool.Add(new Vector3()); } result = new List <float>(); TextAsset asset = Resources.Load <TextAsset>(jsonLineFile); JObject j1 = JObject.Parse(asset.text); cfs = Camera.main.GetComponent <CameraFrustrumScript>(); Vector3 projPos = new Vector3( (float)j1[LumarcaGenerator.PROP_PROJ_POS]["x"], (float)j1[LumarcaGenerator.PROP_PROJ_POS]["y"], (float)j1[LumarcaGenerator.PROP_PROJ_POS]["z"]); cfs.SetupCamera( (float)j1[LumarcaGenerator.PROP_PHYSICAL_WIDTH], projPos, (float)j1[LumarcaGenerator.PROP_THROW_RATIO], (bool)j1[LumarcaGenerator.PROP_CEILING_MOUNT]); front = cfs.GetFrontPlane(); back = new Vector3[4]; back[0] = LumarcaGenerator.GetFarClippingPlane(front[0]); back[1] = LumarcaGenerator.GetFarClippingPlane(front[1]); back[2] = LumarcaGenerator.GetFarClippingPlane(front[2]); back[3] = LumarcaGenerator.GetFarClippingPlane(front[3]); frontHeight = front[2].y - front[0].y; backHeight = back[2].y - back[0].y; JArray ja = j1["positions"] as JArray; for (int i = 0; i < ja.Count; i++) { Vector3 vec = UtilScript.JsonToVector3(ja[i]); if (flipX) { vec.x = -vec.x; } float lerpPer = (vec.z - front[0].z) / (back[0].z - front[0].z); float lineHeight = Mathf.Lerp(frontHeight, backHeight, lerpPer); if (cfs.ceilingMounted) { vec.y = (front[2].y + (front[2].y - lineHeight)) / 2f; } else { vec.y = (front[0].y + (front[0].y + lineHeight)) / 2f; } posList.Add(vec); } pos = posList.ToArray(); Debug.Log("Num Lines: " + pos.Length); foreach (LumarcaAnimation la in lumarcaAnimations) { la.LoadFromJSON(); } GetComponent <LumarcaAnimation>(); if (recordName) { recordAnimation = GetComponent <LumarcaAnimation>(); if (recordAnimation == null) { recordAnimation = gameObject.AddComponent <LumarcaAnimation>(); } } VectorManager.useDraw3D = true; // 0.6424695 // VectorLine.SetRay3D (Color.green, transform.position, transform.forward * 5.0f); // VectorLine line = VectorLine.SetLine(Color.green, new Vector3[]{Vector3.left, Vector3.down}); // line.SetColor(Color.yellow); // line.Draw3D(); // VectorLine.SetLine(Color.red, new Vector3[]{Vector3.left, Vector3.down}); // // vectorLinePool = new ObjectPool<VectorLine>(new ObjectGenerator<VectorLine>()); // // VectorLine myLine = vectorLinePool.GetObject(); // // myLine.SetColor(Color.blue); // myLine.points3[0] = new Vector3(0,0,0); // myLine.points3[1] = new Vector3(0,1,0); // // List<int> myWidths = new List<int>(){1}; // C# // myLine.SetWidths (myWidths); } }
// Use this for initialization void Start() { Cursor.visible = false; SetMaterial(); pool = new List <Vector3>(); for (int i = 0; i < 10000; i++) { pool.Add(new Vector3()); } result = new List <float>(); TextAsset asset = Resources.Load(jsonLineFile) as TextAsset; JObject j1 = JObject.Parse(asset.text); JArray ja = j1["positions"] as JArray; for (int i = 0; i < ja.Count; i++) { Vector3 vec = UtilScript.JsonToVector3(ja[i]); posList.Add(vec); } pos = posList.ToArray(); Debug.Log("Num Lines: " + pos.Length); cfs = Camera.main.GetComponent <CameraFrustrumScript>(); // jObject["lumarcaSize"] = cfs.physicalWidth; // jObject["ProjPos"] = UtilScript.Vector3ToJson(cfs.transform.position); // jObject["ThrowRatio"] = cfs.throwRatio; // jObject["PhysicalWidth"] = cfs.physicalWidth; // jObject["CeilingMount"] = cfs.ceilingMounted; // JArray jPositions = new JArray(); // jObject["positions"] = jPositions; Vector3 projPos = new Vector3( (float)j1[LumarcaGenerator.PROP_PROJ_POS]["x"], (float)j1[LumarcaGenerator.PROP_PROJ_POS]["y"], (float)j1[LumarcaGenerator.PROP_PROJ_POS]["z"]); cfs.SetupCamera( (float)j1[LumarcaGenerator.PROP_PHYSICAL_WIDTH], projPos, (float)j1[LumarcaGenerator.PROP_THROW_RATIO], (bool)j1[LumarcaGenerator.PROP_CEILING_MOUNT]); front = cfs.GetFrontPlane(); back = new Vector3[4]; for (int i = 0; i < front.Length; i++) { back[i] = UtilScript.CloneVec3(front[i]); back[i].z = front[0].z + Camera.main.farClipPlane - Camera.main.nearClipPlane; } foreach (LumarcaAnimation la in lumarcaAnimations) { la.LoadFromJSON(); } GetComponent <LumarcaAnimation>(); if (recordName) { recordAnimation = gameObject.AddComponent <LumarcaAnimation>(); } }