public override VainDrawer CalculateNextPosition(Vain last, Vain next) { // Define some variables Vector3 position = this.obj.transform.position; Vector3 rotation = this.obj.transform.eulerAngles; // Check in what direction the vain is placed bool flip = this.obj.transform.GetChild(0).transform.forward.z != -1f; Vector3 origin = this.obj.transform.position; Vector3 far = origin + new Vector3(0f, 0f, this.obj.GetComponentInChildren<MeshFilter>().mesh.bounds.extents.z * 2) * scale; Vector3 exit0 = flip ? far : origin; Vector3 exit1 = flip ? origin : far; //Debug.Log(this.GetID() + " : e0 " + exit0 + " : e1 " + exit1); // Check from wich end we are leaving if (next == exits[0]) { // We are leaving from the bottom side // Set the position to continue on bottom and set the exit position to a calculation from the current vain //position = new Vector3(position.x, position.y, position.z - (size.z * this.scale)); position = exit0; } else { // We are leaving from the top side // Set the position to continue on top and set the exit position to a calculation from the current vain //position = new Vector3(position.x, position.y, position.z + (size.z * this.scale)); position = exit1; } // Return the information in the VainDrawer format return new VainDrawer(position, rotation); }
public override Vain GetStraight(Vain last) { if (exits[0] == last) return exits[1]; else return exits[0]; }
public override VainDrawer CalculateNextPosition(Vain last, Vain next) { // Get the vain we are moving towards //Vain v = GetStraight(last); // Define some variables Vector3 position = this.obj.transform.position; Vector3 rotation = this.obj.transform.eulerAngles; // Check from wich end we are leaving if (next == exits[0]) { // We are leaving from the bottom side // Set the position to continue on bottom and set the exit position to a calculation from the current vain position = new Vector3(position.x, position.y, position.z - (size.z * this.scale)); } else if(next == exits[1]) { // We are leaving from the top side // Set the position to continue on top and set the exit position to a calculation from the current vain position = new Vector3(position.x, position.y, position.z + (size.z * this.scale)); } else { // We are leaving from the small top side // Set the position to continue on small top and set the exit position to a calculation from the current vain position = new Vector3(position.x - (1.0525f * this.scale), position.y, position.z + (size.z * this.scale)); } // Return the information in the VainDrawer format return new VainDrawer(position, rotation); }
public override Vain GetSecond(Vain last) { // Find the end of the vain that is already drawn int found = -1; for (int i = 0; i < exits.Length; i++) { if (exits[i] == null) continue; if (exits[i].IsDrawn()) { // You found the vain that is drawn at the moment // End your quest found = i; break; } } // Return the opposite exit of the found one if (found == 0) { // Return the opposite exit from the 0-exit return this.exits[2]; } else if (found == 1) { // Return the opposite exit from the 1-exit return this.exits[2]; } else if (found == 2) { // Return the opposite exit from the 2-exit return this.exits[1]; } else { // There is no vain found that had to be drawn // This could mean that it is the first vain we are trying to draw // Return by default the exit that is not null return this.exits[0] == null ? this.exits[1] : this.exits[0]; } }
private void Update() { // Check if there is any vain drawn ever if (visible.Count == 0) { // There are no vains drawn yet. // Draw the first vain in the list if there is one if (vains.Count > 0) { // Draw the vain vains[0].DrawMe(this.transform, new VainDrawer()); // Set the vain as the last vain currentPlayerVain = vains[0]; lastPlayerVain = vains[0].GetExit(0); // Add the vain to the visible object visible.Add(vains[0]); // Return the method. We do not want to draw anything else at the moment return; } } else { // If the last vain is already set, set it to the current vain of the player Vain cv = GetVain(Player.Instance.currentVain); if (cv == null) return; if (cv != currentPlayerVain) { lastPlayerVain = currentPlayerVain; currentPlayerVain = cv; } } label.text = Distance.GetLocatie(currentPlayerVain.GetID()).ToString().Replace("_", " ") + "\n" + Distance.GetDistance(currentPlayerVain.GetID()).ToString(); List<Vain> currentVains = new List<Vain>(new Vain[] { currentPlayerVain }); List<Vain> lastVains = new List<Vain>(new Vain[] { lastPlayerVain }); // Continue here to see if there are more vains needed to be drawn for (int i = 0; i < renderDistance; i++) { List<Vain> newCurrents = new List<Vain>(); for (int j = 0; j < currentVains.Count; j++) { Vain currentVain = currentVains[j]; Vain lastVain = lastVains.Count == currentVains.Count ? lastVains[j] : lastVains[0]; // Get the next vain Vain next = currentVain.GetStraight(lastVain); // Check if the vain is not empty if (next == null) continue; // Get the information where the next object should be drawed VainDrawer drawinfo = currentVain.CalculateNextPosition(lastVain, next); // Get the exit to wich the last vain was connected int exit = next.GetExit(currentVain); // Check if the exit id not equals -1 if (exit == -1) { throw new Exception("Seriously?!?! How did you manage to trigger this exception?!?!"); } // Put the information into the drawinformation drawinfo.DestinationExit = exit; // Draw the next vain next.DrawMe(this.transform, drawinfo); next.AddDrawcall(); // Add the vain to the visible object if (!visible.Contains(next)) visible.Add(next); // Add the next vain to the new current list newCurrents.Add(next); // Check if a second vain needs to be drawn if (currentVain.HasSecondExit()) { // Get the second vain next = currentVain.GetSecond(lastVain); // Check if the vain is not empty if (next == null) continue; // Get the information where the next object should be drawed drawinfo = currentVain.CalculateNextPosition(lastVain, next); // Get the exit to wich the last vain was connected exit = next.GetExit(currentVain); // Check if the exit id not equals -1 if (exit == -1) { throw new Exception("Seriously?!?! How did you manage to trigger this exception?!?!"); } // Put the information into the drawinformation drawinfo.DestinationExit = exit; // Draw the next vain next.DrawMe(this.transform, drawinfo); next.AddDrawcall(); // Add the vain to the visible object if (!visible.Contains(next)) visible.Add(next); // Add the next vain to the new current list newCurrents.Add(next); } } // Set the next vain as the last lastVains = currentVains; currentVains = newCurrents; //lastVain = currentVain; //currentVain = next; } // Check if there are items that can be removed int index = 0; while (index < visible.Count) { if (visible[index].HasDrawcalls()) { visible[index].RemoveDrawcall(); } else { if (visible[index] == lastPlayerVain || visible[index] == currentPlayerVain) { index++; continue; } visible[index].DestroyMe(); visible.RemoveAt(index); continue; } index++; } if (currentPlayerVain.GetType().IsSubclassOf(typeof(Orgaan))) { if (currentPlayerVain.GetID() == -4 || currentPlayerVain.GetID() == -5) { VainMaterial.color = Color.Lerp(blueVain, redVain, betterColorChanger.Instance.celTimer); CellMaterial.color = Color.Lerp(blueVain, redVain, betterColorChanger.Instance.celTimer); particlesMaterial.color = Color.Lerp(blueVain, redVain, betterColorChanger.Instance.celTimer); Camera.main.backgroundColor = Color.Lerp(blueVain, redVain, betterColorChanger.Instance.celTimer); } else if (currentPlayerVain.GetID() < 0 && currentPlayerVain.GetID() != -1 && currentPlayerVain.GetID() != -2) { VainMaterial.color = Color.Lerp(blueVain, redVain, betterColorChanger.Instance.celTimer); CellMaterial.color = Color.Lerp(blueVain, redVain, betterColorChanger.Instance.celTimer); particlesMaterial.color = Color.Lerp(blueVain, redVain, betterColorChanger.Instance.celTimer); Camera.main.backgroundColor = Color.Lerp(blueVain, redVain, betterColorChanger.Instance.celTimer); } } }
public override Vain GetStraight(Vain last) { // Return the opposite exit of the found one if (exits[0] == last) { // Return the opposite exit from the 0-exit return this.exits[1]; } else if (exits[1] == last || exits[2] == last) { // Return the opposite exit from the 1-exit or 2-exit return this.exits[0]; } else { // There is no vain found that had to be drawn // This could mean that it is the first vain we are trying to draw // Return by default the exit that is not null return this.exits[0] == null ? this.exits[1] : this.exits[0]; } }
public override VainDrawer CalculateNextPosition(Vain last, Vain next) { // Define some variables Vector3 position = this.obj.transform.position; Vector3 rotation = this.obj.transform.eulerAngles; // Check in what direction the vain is placed bool flip = this.obj.transform.GetChild(0).transform.forward.z != -1f; Vector3 origin = this.obj.transform.position; Vector3 far = origin + new Vector3(0f, 0f, this.obj.GetComponentInChildren<MeshFilter>().mesh.bounds.extents.z * 2) * scale; Vector3 exit0 = flip ? far : origin; Vector3 exit1 = (flip ? origin : far) + new Vector3(-0.573125f * scale, 0f, 0f); Vector3 exit2 = (flip ? origin : far) + new Vector3(0.5825f * scale, 0f, 0f); //Debug.Log("0 : " + exit0); //Debug.Log("1 : " + exit1); //Debug.Log("2 : " + exit2); // Check from wich end we are leaving if (next == exits[0]) { // We are leaving from the bottom side // Set the position to continue on bottom and set the exit position to a calculation from the current vain //if (direction.z == -1f) //{ // position = new Vector3(position.x, position.y, position.z + (size.z * this.scale)); //} //else //{ // position = new Vector3(position.x, position.y, position.z); //} position = exit0; } else if(next == exits[1]) { // We are leaving from the left top side // Set the position to continue on left top and set the exit position to a calculation from the current vain //if (direction.z == -1f) //{ // position = new Vector3(position.x - (0.574f * this.scale), position.y, position.z + (size.z * this.scale)); //} //else //{ // position = new Vector3(position.x + (0.574f * this.scale), position.y, position.z); //} position = exit1; } else { // We are leaving from the right top side // Set the position to continue on right top and set the exit position to a calculation from the current vain //if (direction.z == -1f) //{ // position = new Vector3(position.x + (0.574f * this.scale), position.y, position.z + (size.z * this.scale)); //} //else //{ // position = new Vector3(position.x - (0.574f * this.scale), position.y, position.z); //} position = exit2; } // Return the information in the VainDrawer format return new VainDrawer(position, rotation); }
/// <summary> /// Calculate the position of the next vain according to the ideas of the current vain /// </summary> /// <returns>The new position information</returns> public virtual VainDrawer CalculateNextPosition(Vain last, Vain next) { Debug.LogError("No method defined for subtype of vain: " + this.GetType().ToString() + " method: CalculateNextPosition()"); return null; }
public void SetExit(int index, Vain vain) { if (index > exits.Length) { Debug.Log("Impossible id"); return; } //Debug.Log(this.id + "." + index + " - " + vain.id); if (exits[index] != null) { Debug.Log("Exit " + index + " of vain " + this.id + " cannot be set to " + vain.id); } exits[index] = vain; }
/// <summary> /// Get the next vain in the logic order /// </summary> /// <returns>The next vain from the current viewpoint</returns> public virtual Vain GetStraight(Vain last) { Debug.LogError("No method defined for subtype of vain: " + this.GetType().ToString() + " method: GetStraight()"); return null; }
public int GetExit(Vain vain) { for (int i = 0; i < exits.Length; i++) { if (exits[i] == vain) { return i; } } return -1; }