public void echoObjArrRemove(meshEchoType echoType, string name) { if (echoObjArr.ContainsKey(echoType)) { echoObjArrType = echoObjArr[echoType]; if (echoObjArrType.Count > 0) { var key = echoObjArrType.First(kvp => kvp.Value == name).Key; if (echoObjArrType.ContainsKey(key)) { echoObjArrType.Remove(key); } } } }
void Update() { if (!initialized) { return; } if (meshEcho == meshEchoType.noClearTime) { if (!parentMesh.noClearTime) { if (parentMesh.clearTime == 0.0f) { Destroy(gameObject); return; } else { // switch to clearTime meshEcho = meshEchoType.clearTime; clearTime = parentMesh.clearTime; } } } else if (meshEcho == meshEchoType.clearTime) { Destroy(gameObject, clearTime); } else if (meshEcho == meshEchoType.traceTime) { if (currentAlpha == 0.0f) { Destroy(gameObject); return; } t = (MainSettingsVars.time - startTime) / traceTime; currentAlpha = Mathf.SmoothStep(initialAlpha, 0.0f, t); currentColor.a = currentAlpha; material.color = currentColor; GetComponent <MeshRenderer>().material = material; } else { Destroy(gameObject); return; } }
void echoObjArrAdd(meshEchoType echoType, GameObject val) { if (transform.childCount == 0 && echoObjArr.Count > 0) { echoObjArr.Clear(); } int key = 0; if (echoObjArr.ContainsKey(echoType)) { echoObjArrType = echoObjArr[echoType]; if (echoObjArrType.Count > 0) { if (echoObjArrType.Count >= MainSettingsVars.data.maxSizeChildren) { Transform testTransform = transform.Find(echoObjArrType[echoObjArrType.Keys.First()]); if (testTransform != null) { Destroy(testTransform.gameObject); } echoObjArrType.Remove(echoObjArrType.Keys.First()); } key = echoObjArrType.Keys.Max() + 1; } val.name = val.name + key; echoObjArrType.Add(key, val.name); echoObjArr[echoType] = echoObjArrType; } else { val.name = val.name + key; echoObjArrType = new SortedDictionary <int, string>() { { key, val.name } }; echoObjArr.Add(echoType, echoObjArrType); } }
public void Initialize(meshEchoType echoType) { // checks if (!GetComponent <MeshFilter>()) { Destroy(gameObject); return; } if (!GetComponent <MeshRenderer>()) { Destroy(gameObject); return; } parentMesh = (OSC_Mesh)this.GetComponentInParent(typeof(OSC_Mesh)); if (parentMesh == null) { Destroy(gameObject); return; } if (!parentMesh.noClearTime && parentMesh.clearTime == 0.0f && parentMesh.traceTime == 0.0f) { Destroy(gameObject); return; } if (parentMesh.mesh == null) { Destroy(gameObject); return; } if (parentMesh.mesh.vertices.Length == 0) { Destroy(gameObject); return; } if (parentMesh.material == null) { Destroy(gameObject); return; } // setup mesh = new Mesh(); mesh.vertices = parentMesh.mesh.vertices; mesh.SetIndices(parentMesh.mesh.GetIndices(0), parentMesh.mesh.GetTopology(0), 0, false); GetComponent <MeshFilter>().mesh = mesh; material = new Material(parentMesh.material.shader); material.color = parentMesh.material.color; GetComponent <MeshRenderer>().material = material; transform.position = parentMesh.transform.position; transform.rotation = parentMesh.transform.rotation; // setup specific types meshEcho = echoType; if (meshEcho == meshEchoType.noClearTime) { mesh.UploadMeshData(true); } else if (meshEcho == meshEchoType.clearTime) { mesh.UploadMeshData(true); clearTime = parentMesh.clearTime; } else if (meshEcho == meshEchoType.traceTime) { mesh.MarkDynamic(); traceTime = parentMesh.traceTime; initialAlpha = parentMesh.alpha; currentColor = material.color; material = new Material(Shader.Find("Transparent/Diffuse")); material.color = currentColor; GetComponent <MeshRenderer>().material = material; startTime = MainSettingsVars.time; } else { Destroy(gameObject); return; } initialized = true; }