private void Start() { mirrorScript = GetComponentInParent <MirrorScript>(); cameraObject = GetComponent <Camera>(); //cameraObject.enabled = true; if (mirrorScript.AddFlareLayer) { cameraObject.gameObject.AddComponent <FlareLayer>(); } mirrorRenderer = MirrorObject.GetComponent <Renderer>(); if (Application.isPlaying) { foreach (Material m in mirrorRenderer.sharedMaterials) { if (m.name == "MirrorMaterial") { mirrorRenderer.sharedMaterial = m; break; } } } mirrorMaterial = mirrorRenderer.sharedMaterial; CreateRenderTexture(); }
public void ChangeMirrorRecursion() { foreach (GameObject o in Mirrors) { MirrorScript s = o.GetComponent <MirrorScript>(); s.MirrorRecursion = RecursionToggle.isOn; } }
private void undo() { // TODO: Record an undo with logging as an event if (dynamicStateStack.Count <= 1) { return; } try { dynamicStateStack.Pop(); DynamicState ds = dynamicStateStack.Peek(); LoggingManager.instance.RecordEvent(LoggingManager.EventCodes.UNDO, ds.toJson()); //int mimicIdx = 0; //int mirrorIdx = 0; List <coord> mimicCoords = ds.mimicPositions.ToList(); List <coord> mirrorCoords = ds.mirrorPositions.ToList(); while (moveables.Count > 0) { MoveableScript ms = moveables[0]; moveables.RemoveAt(0); if (ms is PlayerScript) { continue; } Destroy(ms.gameObject); } player.SetCoords(ds.playerPosition.col, ds.playerPosition.row); player.transform.position = new Vector3(player.GetCoords().col + mapOrigin.x, player.GetCoords().row + mapOrigin.y + player.yOffset); moveables.Add(player); foreach (coord c in mimicCoords) { MimicScript m = GameObject.Instantiate(mimic); m.SetCoords(c.col, c.row); m.transform.position = new Vector3(c.col + mapOrigin.x, c.row + mapOrigin.y + m.yOffset, -0.2f); moveables.Add(m); } foreach (coord c in mirrorCoords) { MirrorScript m = GameObject.Instantiate(mirror); m.SetCoords(c.col, c.row); m.transform.position = new Vector3(c.col + mapOrigin.x, c.row + mapOrigin.y + m.yOffset, -0.2f); moveables.Add(m); } foreach (coord c in buttonCoords.Keys) { if (buttonCoords[c].laser.data.isActive != ds.activeButtons.Contains(c)) { buttonCoords[c].TogglePressed(); } } } catch (InvalidOperationException) { //TODO: Actually display this to the user Debug.Log("Empty stack, no previous move to undo."); } }
private void CheckSwaps() { List <MoveableScript> toDelete = new List <MoveableScript> (); List <MoveableScript> toAdd = new List <MoveableScript> (); foreach (MoveableScript moveable in moveables) { Direction dr = moveable.direction; int row = moveable.GetCoords().row; int col = moveable.GetCoords().col; if (moveable.shouldSwap && moveable.type == BoardCodes.MIMIC) { inputReady = false; boardState.board [row, col] = 24; // Instantiate a Mirror MirrorScript m = GameObject.Instantiate(mirror); m.SetCoords(col, row); m.transform.Rotate(0f, -90f, 0f); m.startSpin(90, false); toAdd.Add(m); toDelete.Add(moveable); } else if (moveable.shouldSwap && moveable.type == BoardCodes.MIRROR) { inputReady = false; boardState.board [row, col] = 23; // Instantiate a Mimic MimicScript m = GameObject.Instantiate(mimic); m.SetCoords(col, row); m.transform.Rotate(0f, -90f, 0f); m.startSpin(90, false); toAdd.Add(m); toDelete.Add(moveable); } } foreach (MoveableScript moveable in toDelete) { this.moveables.Remove(moveable); GameObject.Destroy(moveable.gameObject); } foreach (MoveableScript m in toAdd) { int col = m.GetCoords().col; int row = m.GetCoords().row; m.transform.position = new Vector3(col + mapOrigin.x, row + mapOrigin.y + m.yOffset, 0); moveables.Add(m); } }
private void Start() { mirrorScript = GetComponentInParent<MirrorScript>(); cameraObject = GetComponent<Camera>(); //cameraObject.enabled = true; if (mirrorScript.AddFlareLayer) { cameraObject.gameObject.AddComponent<FlareLayer>(); } mirrorRenderer = MirrorObject.GetComponent<Renderer>(); if (Application.isPlaying) { mirrorRenderer.sharedMaterial = mirrorRenderer.material; } mirrorMaterial = mirrorRenderer.sharedMaterial; CreateRenderTexture(); }
private void PrepareNewMirror(GameObject newMirror, MirrorPositionInfo positionInfo) { Transform t = positionInfo.mirrorPos.transform; newMirror.transform.SetParent(mirrorParent.transform); newMirror.transform.position = t.position; newMirror.transform.rotation = t.rotation; newMirror.transform.localScale = t.localScale; newMirror.tag = positionInfo.mirrorPos.tag; for (int i = 0; i < newMirror.transform.childCount; i++) { newMirror.transform.GetChild(i).gameObject.tag = positionInfo.mirrorPos.tag; } MirrorScript mirrorScript = newMirror.GetComponent <MirrorScript>(); mirrorScript.ReflectLayers = positionInfo.reflectLayers; }
// Start is called before the first frame update void Start() { mirrorScript = MirrorPrefab.GetComponent <MirrorScript>(); }
Level boardState; //Row, Column // East col+, North row+ /* 0 = empty * 1 = wall * 2 = player * 3 = mimic * 4 = mirror * 10 = goal */ // Use this for initialization void Start() { firstStart = false; //load level using Melody's I/O boardState = IOScript.ParseLevel(levelName); // TODO: Below the way we get the index is DISGUSTING, this whole shitshow needs refactored levelNum = CreateLevelSelect.levelList.IndexOf(levelName); LoggingManager.instance.RecordLevelStart(levelNum, levelName); mapOrigin = new Vector2(-boardState.cols / 2.0f, -boardState.rows / 2.0f); mainCamera.orthographicSize = boardState.rows / 2.0f + 1; tutorial.text = boardState.tutorial; tutorial.enabled = true; if (levelNum == 0) { tutorial1.SetActive(true); } else if (levelNum == 5) { tutorial6.SetActive(true); } int buttonCount = 0; //instantiate lasers based on parsed lasers if (boardState.lasers != null) { foreach (Laser la in boardState.lasers) { LaserScript l = GameObject.Instantiate(laser); l.makeLaser(la, mapOrigin); laserList.Add(l); } } //instantiate items based on board for (int i = 0; i < boardState.rows; i++) { for (int j = 0; j < boardState.cols; j++) { if (boardState.board[i, j] == 1) { //wall GameObject w; if (i == 0 || boardState.board[i - 1, j] != 1) { w = GameObject.Instantiate(frontWall); } else { w = GameObject.Instantiate(wall); } w.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y, 0); } else if (boardState.board[i, j] >= 10 && boardState.board[i, j] < 20) { // goal GoalScript c = GameObject.Instantiate(goal); c.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y, 0); goalAtCoords.Add(new coord(i, j), c); goalCoords.Add(new coord(i, j)); } else if (boardState.board[i, j] >= 20 && boardState.board[i, j] < 30) { // swap GameObject c = GameObject.Instantiate(swap); c.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y, 0); swapCoords.Add(new coord(i, j)); } else if (boardState.board[i, j] >= 30 && boardState.board[i, j] < 40) { // button ButtonToggleScript c = GameObject.Instantiate(button); c.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y, 0); c.laser = laserList[boardState.buttons[buttonCount]]; c.InitButton(); buttonCoords.Add(new coord(i, j), c); buttonCount++; } else if (boardState.board[i, j] >= 50 && boardState.board[i, j] < 60) { // portal GameObject p = GameObject.Instantiate(portal); p.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y, 0); portalCoords.Add(new coord(i, j)); } else { // ground GameObject g = GameObject.Instantiate(ground); g.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y, 0); } if (boardState.board[i, j] % 10 == 2) { // player player = GameObject.Instantiate(player); player.SetCoords(j, i); player.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y + player.yOffset, -0.2f); moveables.Add(player); } else if (boardState.board[i, j] % 10 == 3) { // mimic MimicScript m = GameObject.Instantiate(mimic); m.SetCoords(j, i); m.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y + m.yOffset, -0.2f); moveables.Add(m); } else if (boardState.board[i, j] % 10 == 4) { // mirror MirrorScript m = GameObject.Instantiate(mirror); m.SetCoords(j, i); m.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y + m.yOffset, -0.2f); moveables.Add(m); } } } if (boardState.portals != null) { for (int i = 0; i < boardState.portals.Length; i++) { portalMap.Add(portalCoords[i], portalCoords[boardState.portals[i]]); } } }
void Update() { if (Input.GetMouseButtonDown (0)) { clickedGmObj = GetClickedGameObject (); if (clickedGmObj.tag == "Mirror" || clickedGmObj.tag == "StartMirror") { clickedGmObj.transform.Rotate (0, 120, 0);//rotate all mirrors mirrorScript = clickedGmObj.GetComponent<MirrorScript>(); mirrorScript.activated = true; if (mirrorScript.activated == true || clickedGmObj.tag == "StartMirror"){ targetGmObj = GetRaycastHit (clickedGmObj); Debug.Log("targetobj "+targetGmObj.name); } // print (targetGmObj); if (targetGmObj != null) { if (targetGmObj.tag == "Mirror") { rotationlight.eulerAngles = targetGmObj.transform.forward; // print (targetGmObj.name); targetGmObj.GetComponent<MirrorScript> ().ActivateMirrorScript (); step = targetGmObj; Debug.Log("step " + step.name); } } } if (targetGmObj.tag == "Bottle" && clickedGmObj != step) { // print (targetGmObj.name + step); Debug.Log("Hit wall, resetting mirrors"); step.GetComponent<MirrorScript> ().DeactivateMirrorScript (); } } }
// Update is called once per frame void Update() { if (showInfo) if (Input.GetMouseButtonDown(0)) { showInfo = false; } if (Input.GetMouseButtonDown (0)) { Debug.Log ("MouseClick"); clickedGmObj = GetClickedGameObject (); if (clickedGmObj != null) { if (clickedGmObj.tag == "Mirror" || clickedGmObj.tag == "StartMirror") { //make it rotate Debug.Log("helloworld"); clickedGmObj.transform.Rotate (0, 120, 0); _mirrorScript = clickedGmObj.GetComponent<MirrorScript>(); if(clickedGmObj.tag == "StartMirror" || _mirrorScript.activated) { targetGmObj = GetRaycastHit (clickedGmObj); //Debug.Log("finding target gameobj :" + targetGmObj); if(targetGmObj == null) Debug.Log("Clicked Game Object's Raycast Hits nothing"); //bucket if(targetGmObj.tag == "Mirror") { // Debug.Log(clickedGmObj.name + " is hitting " + targetGmObj.name); rotationlight.eulerAngles = targetGmObj.transform.forward; targetGmObj.GetComponent<MirrorScript> ().ActivateMirrorScript (); //Debug.Log("mirrors0 " + mirrors[0].name); mirrors.Add(targetGmObj); step = targetGmObj; Debug.Log("clickedgameobject :" + clickedGmObj + " Target gameobj :" + targetGmObj + "step : " + step.name); } if(targetGmObj.name == "EndCube") //If puzzle is finished! { Debug.Log("Sun Puzzle Finished"); finished = true; audioSound.PlayOneShot(PuzzleDone); this.enabled = false; } if(targetGmObj.tag == "Bottle" && clickedGmObj != step) { step.GetComponent<MirrorScript> ().DeactivateMirrorScript (); Debug.Log("resetting mirrors from " + step.name); } if(targetGmObj.tag == "StartMirror") { //hello } } } } } }