/// <summary> /// Checks if it is a fork. If its a fork it will return the State. /// </summary> /// <returns>The State</returns> /// <param name="ID">Name of the object</param> public void SetCurrentCell(string ID, Vector3 pos) { //Check if not null if (ID != null && ID != "") { InstantiatedObject result; if (ID.Contains("DID") == true) { //If it is an dependency object check with parent ID = ID.Replace("DID", "ID"); } //Get the Cell by the ID property passed as an string result = list_instiated_object.Find(delegate(InstantiatedObject io){ return(io.ID == ID); }); if (result != null) { m_playerCell_previous = m_playerCell; m_playerCell = result; //Set the visited flag list_instiated_object[list_instiated_object.IndexOf(m_playerCell)].Visited = true; //Check if the last element was a fork Element CheckIfIsFork(pos); } } }
private void CreateCellModel(InstantiatedObject Element) { if (Element.CellModel != null) { //Place the Element with the correct Type, Position and Rotation AdjustPositionRotation(Element.CellModel, Element.MedianPoint, Element.Rotation, Element.ID); //Create a mirror Object //if(Element.Dependency != null && bool_place_dependency == true){ if (Element.Dependency != null && bool_place_dependency == true) { //Debug.Log("Dependency to solve"); //Element.Dependency.Type AdjustPositionRotation(Element.Dependency.CellModel, Element.Dependency.MedianPoint, Element.Dependency.Rotation, Element.Dependency.ID); } } }
/// <summary> /// Initial Build is called only once, it places the "Beginning Part" /// </summary> void InitialBuild() { // Setup Root Cell InstantiatedObject rootCell = new InstantiatedObject(Vector3.zero, Direction.Forward, Parts.Forward); rootCell.Type = Parts.Beginning; rootCell.CellModel = PlaceElement(rootCell.Type); //Set the three positions rootCell.MedianPoint = Vector3.zero; //Get the Position of the empty gameObject rootCell.EndPosition = rootCell.CellModel.gameObject.transform.GetChild(2).transform.position; //Set the rotation to default rootCell.Rotation = Quaternion.identity; rootCell.ID = UniqueID(); //Place the Element in the scene AdjustPositionRotation(rootCell.CellModel, rootCell.MedianPoint, rootCell.Rotation, rootCell.ID); //Set visited flag rootCell.Visited = true; list_instiated_object.Add(rootCell); //Start PlayerScript player.GetComponent <PlayerScript>().Initialization(list_instiated_object[0].ID); //Activate Build on the fly BuildOnTheFly(true); }
/// <summary> /// Plans the next element. /// </summary> /// <param name="previous">Previous.</param> /// <param name="cellCount">Cell count.</param> private void PlanNextElement(InstantiatedObject previous, int cellCount) { // Create an instance of the class Instantiated Object InstantiatedObject newCell = new InstantiatedObject(Vector3.zero, Direction.Forward, Parts.Forward); InstantiatedObject prevCell = previous; /*New local variables*/ Parts mypart; Direction mydirection; Quaternion myrotation; // Assign old Direction mydirection = prevCell.CellDirection; // Assign old Rotation myrotation = prevCell.Rotation; //Check if a straight part needs to be placed. This decission is made depending on the min and maximum amount set in the inspector. if (amount_of_elements[(int)Parts.Forward] < i_min_same_parts || amount_of_elements[(int)Parts.Forward] == null) { mypart = Parts.Forward; myrotation = GetRotationOfElement(mydirection, prevCell.CellDirection, mypart); } else { bool force; if (amount_of_elements[(int)Parts.Forward] >= i_max_same_parts) { force = true; } else { force = false; } //Choose Part randomly mypart = RandomlyChooseElement(force); //Choose if Direction needs to be changed mydirection = RandomlyChooseDirection(mypart, mydirection); //Change the rotation acording to the direction, necessary for corners and all the straight elements myrotation = GetRotationOfElement(mydirection, prevCell.CellDirection, mypart); //Reset the parts.Forward counter if (mypart != Parts.Forward) { amount_of_elements[(int)Parts.Forward] = 0; } } //Assign the type newCell.Type = mypart; //Overwrite default Direction newCell.CellDirection = mydirection; //Overwrite Rotation newCell.Rotation = myrotation; newCell.CellModel = PlaceElement(newCell.Type); //Assign the appropiate Position, depending on direction newCell.StartPosition = prevCell.EndPosition; Vector3 median; Vector3 end; Vector3 end2; GetPositionOfPoint(newCell.StartPosition, newCell.CellModel, newCell.Rotation, newCell.Type, newCell.CellDirection, prevCell.CellDirection, out median, out end, out end2); newCell.MedianPoint = median; newCell.EndPosition = end; newCell.EndPosition2 = end2; //Set Endpoint2 if (prevCell.Type == Parts.Fork) { CreateFork(newCell.CellDirection); } //Get the Name for the Ojbect newCell.ID = UniqueID(); CheckForCollision(newCell.StartPosition, newCell.EndPosition, newCell.CellDirection, newCell.ID); //Create the dependency if (create_fork == true) { //Create an Instance InstantiatedObject newCellFork = new InstantiatedObject(Vector3.zero, Direction.Forward, Parts.Forward); //Copy the type newCellFork.Type = newCell.Type; //Add to D to clearify that its a dependency object newCellFork.ID = "D" + newCell.ID; //Copy the Rotation from the main object newCellFork.Rotation = newCell.Rotation; if (newCell.CellDirection == direction_after_fork) { newCellFork.CellDirection = InverseDirection(newCell.CellDirection); } else { //Keep Direction newCellFork.CellDirection = newCell.CellDirection; } //Need to be reworked if ((newCell.Type == Parts.CornerLeft || newCell.Type == Parts.CornerRight)) { if (prevCell.CellDirection == direction_after_fork || newCell.CellDirection == direction_after_fork) { //Invert Type Parts type; if (newCell.Type == Parts.CornerRight) { type = Parts.CornerLeft; } else { type = Parts.CornerRight; } //Get new Rotation Quaternion rot; //Cell Model GameObject cm; //Recalculate Rotation mind the Dependency previous position rot = GetRotationOfElement(newCellFork.CellDirection, prevCell.Dependency.CellDirection, type); //Assign the type newCellFork.Type = type; //Assign the rotation newCellFork.Rotation = rot; } } if (newCellFork.Type == Parts.Stairway && newCell.CellDirection == direction_after_fork) { newCellFork.Rotation = GetRotationOfElement(newCellFork.CellDirection, prevCell.Dependency.CellDirection, newCellFork.Type); } Vector3 pos; Direction prevdir; prevdir = newCellFork.CellDirection; if (prevCell.Dependency != null) { //A dependency element was previously placed pos = prevCell.Dependency.EndPosition; if (newCell.Type == Parts.CornerLeft || newCell.Type == Parts.CornerRight) { //Corners always need the old direction as a reference to place prevdir = prevCell.Dependency.CellDirection; } } else { //Use the Position of the previous cell pos = prevCell.EndPosition2; } newCellFork.CellModel = PlaceElement(newCellFork.Type); median = Vector3.zero; end = Vector3.zero; end2 = Vector3.zero; GetPositionOfPoint(pos, newCellFork.CellModel, newCellFork.Rotation, newCellFork.Type, newCellFork.CellDirection, prevdir, out median, out end, out end2); newCellFork.MedianPoint = median; newCellFork.EndPosition = end; newCellFork.EndPosition2 = end2; //Set Endpoint2 //Set newCellFork as the dependency newCell.Dependency = newCellFork; } //Add the Element to the list list_instiated_object.Add(newCell); //Increase the counter for the Part amount_of_elements[(int)mypart] = amount_of_elements[(int)mypart] + 1; }
/// <summary> /// Plans the next element. /// </summary> /// <param name="previous">Previous.</param> /// <param name="cellCount">Cell count.</param> private void PlanNextElement(InstantiatedObject previous, int cellCount) { // Create an instance of the class Instantiated Object InstantiatedObject newCell = new InstantiatedObject(Vector3.zero, Direction.Forward, Parts.Forward); InstantiatedObject prevCell = previous; /*New local variables*/ Parts mypart; Direction mydirection; Quaternion myrotation; // Assign old Direction mydirection = prevCell.CellDirection; // Assign old Rotation myrotation = prevCell.Rotation; //Check if a straight part needs to be placed. This decission is made depending on the min and maximum amount set in the inspector. if(amount_of_elements[(int)Parts.Forward]<i_min_same_parts || amount_of_elements[(int)Parts.Forward] == null){ mypart = Parts.Forward; myrotation = GetRotationOfElement(mydirection, prevCell.CellDirection, mypart); } else{ bool force; if(amount_of_elements[(int)Parts.Forward]>= i_max_same_parts){ force = true; } else{ force = false; } //Choose Part randomly mypart = RandomlyChooseElement(force); //Choose if Direction needs to be changed mydirection = RandomlyChooseDirection(mypart, mydirection); //Change the rotation acording to the direction, necessary for corners and all the straight elements myrotation = GetRotationOfElement(mydirection, prevCell.CellDirection, mypart); //Reset the parts.Forward counter if(mypart != Parts.Forward){ amount_of_elements[(int)Parts.Forward] = 0; } } //Assign the type newCell.Type = mypart; //Overwrite default Direction newCell.CellDirection = mydirection; //Overwrite Rotation newCell.Rotation = myrotation; newCell.CellModel = PlaceElement(newCell.Type); //Assign the appropiate Position, depending on direction newCell.StartPosition = prevCell.EndPosition; Vector3 median; Vector3 end; Vector3 end2; GetPositionOfPoint(newCell.StartPosition, newCell.CellModel, newCell.Rotation, newCell.Type, newCell.CellDirection, prevCell.CellDirection, out median, out end, out end2); newCell.MedianPoint = median; newCell.EndPosition = end; newCell.EndPosition2 = end2; //Set Endpoint2 if(prevCell.Type == Parts.Fork){ CreateFork(newCell.CellDirection); } //Get the Name for the Ojbect newCell.ID = UniqueID(); CheckForCollision(newCell.StartPosition, newCell.EndPosition,newCell.CellDirection, newCell.ID); //Create the dependency if(create_fork == true){ //Create an Instance InstantiatedObject newCellFork = new InstantiatedObject(Vector3.zero, Direction.Forward, Parts.Forward); //Copy the type newCellFork.Type = newCell.Type; //Add to D to clearify that its a dependency object newCellFork.ID = "D"+newCell.ID; //Copy the Rotation from the main object newCellFork.Rotation = newCell.Rotation; if(newCell.CellDirection == direction_after_fork ){ newCellFork.CellDirection = InverseDirection(newCell.CellDirection); } else{ //Keep Direction newCellFork.CellDirection = newCell.CellDirection; } //Need to be reworked if((newCell.Type == Parts.CornerLeft || newCell.Type == Parts.CornerRight)){ if(prevCell.CellDirection == direction_after_fork || newCell.CellDirection == direction_after_fork){ //Invert Type Parts type; if(newCell.Type == Parts.CornerRight){ type = Parts.CornerLeft; } else { type = Parts.CornerRight; } //Get new Rotation Quaternion rot; //Cell Model GameObject cm; //Recalculate Rotation mind the Dependency previous position rot = GetRotationOfElement(newCellFork.CellDirection, prevCell.Dependency.CellDirection, type); //Assign the type newCellFork.Type = type; //Assign the rotation newCellFork.Rotation = rot; } } if(newCellFork.Type == Parts.Stairway && newCell.CellDirection == direction_after_fork){ newCellFork.Rotation =GetRotationOfElement(newCellFork.CellDirection, prevCell.Dependency.CellDirection, newCellFork.Type); } Vector3 pos; Direction prevdir; prevdir = newCellFork.CellDirection; if(prevCell.Dependency != null){ //A dependency element was previously placed pos = prevCell.Dependency.EndPosition; if(newCell.Type == Parts.CornerLeft || newCell.Type == Parts.CornerRight){ //Corners always need the old direction as a reference to place prevdir = prevCell.Dependency.CellDirection; } } else{ //Use the Position of the previous cell pos=prevCell.EndPosition2; } newCellFork.CellModel = PlaceElement(newCellFork.Type); median=Vector3.zero; end=Vector3.zero; end2=Vector3.zero; GetPositionOfPoint(pos, newCellFork.CellModel, newCellFork.Rotation, newCellFork.Type, newCellFork.CellDirection, prevdir, out median, out end, out end2); newCellFork.MedianPoint = median; newCellFork.EndPosition = end; newCellFork.EndPosition2 = end2; //Set Endpoint2 //Set newCellFork as the dependency newCell.Dependency = newCellFork; } //Add the Element to the list list_instiated_object.Add(newCell); //Increase the counter for the Part amount_of_elements[(int)mypart] = amount_of_elements[(int)mypart] + 1; }
/// <summary> /// Initial Build is called only once, it places the "Beginning Part" /// </summary> void InitialBuild(){ // Setup Root Cell InstantiatedObject rootCell = new InstantiatedObject(Vector3.zero, Direction.Forward, Parts.Forward); rootCell.Type = Parts.Beginning; rootCell.CellModel = PlaceElement(rootCell.Type); //Set the three positions rootCell.MedianPoint = Vector3.zero; //Get the Position of the empty gameObject rootCell.EndPosition = rootCell.CellModel.gameObject.transform.GetChild(2).transform.position; //Set the rotation to default rootCell.Rotation = Quaternion.identity; rootCell.ID = UniqueID(); //Place the Element in the scene AdjustPositionRotation(rootCell.CellModel, rootCell.MedianPoint, rootCell.Rotation, rootCell.ID); //Set visited flag rootCell.Visited = true; list_instiated_object.Add(rootCell); //Start PlayerScript player.GetComponent<PlayerScript>().Initialization(list_instiated_object[0].ID); //Activate Build on the fly BuildOnTheFly(true); }
/// <summary> /// Checks if it is a fork. If its a fork it will return the State. /// </summary> /// <returns>The State</returns> /// <param name="ID">Name of the object</param> public void SetCurrentCell(string ID, Vector3 pos){ //Check if not null if(ID != null && ID != ""){ InstantiatedObject result; if(ID.Contains("DID")== true){ //If it is an dependency object check with parent ID = ID.Replace("DID","ID"); } //Get the Cell by the ID property passed as an string result = list_instiated_object.Find(delegate(InstantiatedObject io){return io.ID == ID;}); if (result != null) { m_playerCell_previous = m_playerCell; m_playerCell = result; //Set the visited flag list_instiated_object[list_instiated_object.IndexOf(m_playerCell)].Visited = true; //Check if the last element was a fork Element CheckIfIsFork(pos); } } }
private void CreateCellModel(InstantiatedObject Element) { if (Element.CellModel != null) { //Place the Element with the correct Type, Position and Rotation AdjustPositionRotation(Element.CellModel,Element.MedianPoint,Element.Rotation,Element.ID); //Create a mirror Object //if(Element.Dependency != null && bool_place_dependency == true){ if(Element.Dependency != null && bool_place_dependency == true){ //Debug.Log("Dependency to solve"); //Element.Dependency.Type AdjustPositionRotation(Element.Dependency.CellModel, Element.Dependency.MedianPoint, Element.Dependency.Rotation, Element.Dependency.ID); } } }