public Area(GameObject S) { A = S; AreaScript sk = S.GetComponent <AreaScript> (); width = sk.width; height = sk.height; Grid = sk.Grid; minX = A.GetComponent <Collider2D>().bounds.min.x; maxY = A.GetComponent <Collider2D>().bounds.max.y; minY = A.GetComponent <Collider2D>().bounds.min.y; maxX = A.GetComponent <Collider2D>().bounds.max.x; DoorCount = A.transform.GetChild(0).childCount - 2; OperableCount = A.transform.childCount - 1; Doors = new Door[DoorCount]; operables = new Operable[OperableCount]; for (int i = 0; i < DoorCount; i++) { Doors [i] = new Door(A.transform.GetChild(0).GetChild(i + 2).gameObject); } for (int i = 0; i < OperableCount; i++) { operables [i] = new Operable(A.transform.GetChild(i + 1).gameObject); } }
public override bool DoOperation(IEnumerable <KeyValuePair <string, string> > kvPairs) { Console.WriteLine("Doing some stuff in the Metrics Decorator"); var timer = new Stopwatch(); timer.Start(); var result = Operable.DoOperation(kvPairs); timer.Stop(); Console.WriteLine($"It took {timer.ElapsedMilliseconds} milliseconds to do the operation."); return(result); }
public override bool DoOperation(IEnumerable <KeyValuePair <string, string> > kvPairs) { try { Console.WriteLine("Doing some action before the operation inside of the ErrorHandlingDecorator"); var result = Operable.DoOperation(kvPairs); Console.WriteLine("Doing some action after the operation inside of the ErrorHandlingDecorator"); return(result); } catch (Exception e) { Console.WriteLine("Uh oh, something went wrong. Handling errors"); throw; } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { Menu.SetActive(true); Emeth.SendMessage("GiveCoordinates", new Stack <Vector2> ()); Inventory.SetActive(false); gameObject.SetActive(false); } if (Input.GetMouseButtonDown(0)) { Vector2 Position = Camera.main.ScreenToWorldPoint(Input.mousePosition); for (int i = 0; i < activeArea.CurrentArea().giveDoorCount(); i++) { if (activeArea.CurrentArea().GiveDoor(i).giveDoorObject().GetComponent <Collider2D> () != null && activeArea.CurrentArea().GiveDoor(i).giveDoorObject().GetComponent <Collider2D> ().OverlapPoint(Position)) { temporary.setClicked(false); activeArea.CurrentArea().GiveDoor(i).setClicked(true); temporary = activeArea.CurrentArea().GiveDoor(i); Emeth.SendMessage("GiveCoordinates", activeArea.CurrentArea().Pathfinder(Emeth.transform.position, activeArea.CurrentArea().GiveDoor(i).givePoint())); wasClicked = true; operateObject = ""; Inventory.SendMessage("CombItemNull"); break; } } for (int i = 0; i < activeArea.CurrentArea().giveOperablesCount(); i++) { if (activeArea.CurrentArea().GiveOperable(i).giveOperableObject() != null && activeArea.CurrentArea().GiveOperable(i).giveOperableObject().GetComponent <Collider2D> () != null && activeArea.CurrentArea().GiveOperable(i).giveOperableObject().GetComponent <Collider2D> ().OverlapPoint(Position)) { temporary.setClicked(false); activeArea.CurrentArea().GiveOperable(i).setClicked(true); temporary = activeArea.CurrentArea().GiveOperable(i); Emeth.SendMessage("GiveCoordinates", activeArea.CurrentArea().Pathfinder(Emeth.transform.position, activeArea.CurrentArea().GiveOperable(i).givePoint())); wasClicked = true; break; } } if (operateObject != "" && Emeth.GetComponent <Collider2D> ().OverlapPoint(Position)) { temporary.setClicked(false); Emeth.SendMessage("GiveCoordinates", new Stack <Vector2> ()); Emeth.SendMessage("Operate", operateObject); wasClicked = true; operateObject = ""; Inventory.SendMessage("CombItemNull"); } if (wasClicked == false) { Emeth.SendMessage("GiveCoordinates", activeArea.CurrentArea().Pathfinder(Emeth.transform.position, Position)); temporary.setClicked(false); operateObject = ""; Inventory.SendMessage("CombItemNull"); } wasClicked = false; } if (temporary.isNear(Emeth.transform.position)) { for (int i = 0; i < activeArea.CurrentArea().giveDoorCount(); i++) { Door tt = activeArea.CurrentArea().GiveDoor(i); if (tt.isNear(Emeth.transform.position)) { if (BoolsInts.boolies[tt.giveDoorObject().GetComponent <DoorScript> ().unlocked]) { Emeth.SendMessage("GiveCoordinates", new Stack <Vector2> ()); Vector2 teleport = tt.giveTargetPoint(); activeArea.setArea(tt.giveTargetArea()); Emeth.transform.position = teleport; if (Emeth.transform.position.x < tt.giveDoorObject().transform.position.x&& Emeth.transform.localScale.x < 0) { Emeth.transform.localScale = new Vector3(Emeth.transform.localScale.x * -1, Emeth.transform.localScale.y, Emeth.transform.localScale.z); } else if (Emeth.transform.position.x > tt.giveDoorObject().transform.position.x&& Emeth.transform.localScale.x > 0) { Emeth.transform.localScale = new Vector3(Emeth.transform.localScale.x * -1, Emeth.transform.localScale.y, Emeth.transform.localScale.z); } } else { CommentController.SetActive(true); CommentController.SendMessage("StartComment", "It's locked."); } break; } } for (int i = 0; i < activeArea.CurrentArea().giveOperablesCount(); i++) { Operable tt = activeArea.CurrentArea().GiveOperable(i); if (tt.isNear(Emeth.transform.position) && tt.giveOperableObject() != null) { Emeth.SendMessage("GiveCoordinates", new Stack <Vector2>()); if (Emeth.transform.position.x < tt.giveOperableObject().transform.position.x&& Emeth.transform.localScale.x > 0) { Emeth.transform.localScale = new Vector3(Emeth.transform.localScale.x * -1, Emeth.transform.localScale.y, Emeth.transform.localScale.z); } else if (Emeth.transform.position.x > tt.giveOperableObject().transform.position.x&& Emeth.transform.localScale.x < 0) { Emeth.transform.localScale = new Vector3(Emeth.transform.localScale.x * -1, Emeth.transform.localScale.y, Emeth.transform.localScale.z); } Inventory.SendMessage("CombItemNull"); tt.giveOperableObject().SendMessage("Operate", operateObject); operateObject = ""; break; } } temporary.setClicked(false); } // examining if (Input.GetMouseButtonDown(1)) { Vector2 Position = Camera.main.ScreenToWorldPoint(Input.mousePosition); for (int i = 0; i < activeArea.CurrentArea().giveDoorCount(); i++) { if (activeArea.CurrentArea().GiveDoor(i).giveDoorObject().GetComponent <Collider2D> ().OverlapPoint(Position)) { Emeth.SendMessage("GiveCoordinates", new Stack <Vector2>()); activeArea.CurrentArea().GiveDoor(i).giveDoorObject().SendMessage("Comment"); break; } } for (int i = 0; i < activeArea.CurrentArea().giveOperablesCount(); i++) { if (activeArea.CurrentArea().GiveOperable(i).giveOperableObject() != null && activeArea.CurrentArea().GiveOperable(i).giveOperableObject().GetComponent <Collider2D> ().OverlapPoint(Position)) { Emeth.SendMessage("GiveCoordinates", new Stack <Vector2>()); activeArea.CurrentArea().GiveOperable(i).giveOperableObject().SendMessage("Comment"); break; } } } // kamera Camera.main.transform.position = new Vector3(Emeth.transform.position.x, Emeth.transform.position.y + 2.5f, Camera.main.transform.position.z); if (Camera.main.transform.position.x + Camera.main.orthographicSize * Camera.main.aspect >= activeArea.CurrentArea().giveMaxX()) { Camera.main.transform.position = new Vector3(activeArea.CurrentArea().giveMaxX() - Camera.main.orthographicSize * Camera.main.aspect, Camera.main.transform.position.y, Camera.main.transform.position.z); } else if (Camera.main.transform.position.x - Camera.main.orthographicSize * Camera.main.aspect <= activeArea.CurrentArea().giveMinX()) { Camera.main.transform.position = new Vector3(activeArea.CurrentArea().giveMinX() + Camera.main.orthographicSize * Camera.main.aspect, Camera.main.transform.position.y, Camera.main.transform.position.z); } if (Camera.main.transform.position.y + Camera.main.orthographicSize >= activeArea.CurrentArea().giveMaxY()) { Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, activeArea.CurrentArea().giveMaxY() - Camera.main.orthographicSize, Camera.main.transform.position.z); } else if (Camera.main.transform.position.y - Camera.main.orthographicSize <= activeArea.CurrentArea().giveMinY()) { Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, activeArea.CurrentArea().giveMinY() + Camera.main.orthographicSize, Camera.main.transform.position.z); } }