public void UnRecordZoomZone(ZoomZone zoomZone) { if (recordedZoomZones.Count > 0 && recordedZoomZones[recordedZoomZones.Count - 1] == zoomZone) { recordedZoomZones.RemoveAt(recordedZoomZones.Count - 1); } }
public void RecordZoomZone(ZoomZone zoomZone) { // If a zoom zone has already been recorded or the zoom zone to be recorded is not the linked one if (zoomZone.recordZone && (recordedZoomZones.Count > 0 || zoomZone != linkedZoomZone)) { if (recordedZoomZones.Count == 0 || recordedZoomZones[recordedZoomZones.Count - 1] != zoomZone) { recordedZoomZones.Add(zoomZone); } } }
private void BeginRecursing() { for (int child = transform.childCount; child > 0; --child) { DestroyImmediate(transform.GetChild(0).gameObject); } totalRecursions = 0; recurseZoomZone = null; RecurseAtPoint(recurseIterations, transform); Debug.Log("Total recursions: " + totalRecursions); }
public ZoomZone GetLinkedZoomZone() { ZoomZone lastRecordedZoomZone = linkedZoomZone; if (linkedZoomZone) { // If any zoom zones have been recorded use the last one and clear it from the record if (recordedZoomZones.Count > 0) { lastRecordedZoomZone = recordedZoomZones[recordedZoomZones.Count - 1]; } } return(lastRecordedZoomZone); }
private void OnTriggerEnter2D(Collider2D other) { if (UtilityLibrary.Has <ZoomZone>(other.gameObject)) { ZoomZone zoom = other.GetComponent <ZoomZone>(); if (zoom.returnToDefault) { cam.ResetDefaults(zoom.lerpTime); } else { EnterZoomZone(zoom.zoomData, zoom.lerpTime); } } }
private void RecurseAtPoint(int currentIteration, Transform recurseParent) { if (totalRecursions > 5000) { Debug.Log("Total recursions greater than 1000, exited out"); } if (currentIteration <= 0) { return; } GameObject instantiatedObject = PrefabUtility.InstantiatePrefab(recursePrefab, recurseParent) as GameObject; // Remove zoom zones from children of the initial prefab if (totalRecursions > 0 && dontRemoveZoomZones == false) { foreach (ZoomZone zoomZone in instantiatedObject.GetComponentsInChildren <ZoomZone>()) { DestroyImmediate(zoomZone); } foreach (BoxCollider boxCollider in instantiatedObject.GetComponentsInChildren <BoxCollider>()) { DestroyImmediate(boxCollider); } foreach (Rigidbody rigidbody in instantiatedObject.GetComponentsInChildren <Rigidbody>()) { DestroyImmediate(rigidbody); } } totalRecursions += 1; if (recurseZoomZone == null) { recurseZoomZone = instantiatedObject.GetComponent <ZoomZone>(); } else { ZoomZone childZoomZone = instantiatedObject.GetComponent <ZoomZone>(); if (childZoomZone != null) { childZoomZone.linkedZoomZone = recurseZoomZone; childZoomZone.priority = recurseZoomZone.priority + (recurseIterations - currentIteration); } } foreach (SpriteRenderer spriteRenderer in instantiatedObject.GetComponentsInChildren <SpriteRenderer>()) { spriteRenderer.sortingOrder = spriteRenderer.sortingOrder + (recurseIterations - currentIteration); if (sortingLayer != "") { spriteRenderer.sortingLayerName = sortingLayer; } } for (int child = 0; child < instantiatedObject.transform.childCount; child++) { Transform childTransform = instantiatedObject.transform.GetChild(child); if (childTransform.name.ToLower().Contains(recursePointName.ToLower())) { RecurseAtPoint(currentIteration - 1, childTransform); } } }
//void FadeInOverlay() //{ // if (gameState == GameState.INTRO) // { // Vector3 distance = transform.position - fadePosition.position; // distance.z = 0.0f; // if (distance.magnitude < fadeDistance) // { // GetComponent<UnityStandardAssets.ImageEffects.ScreenOverlay>().intensity = Mathf.Lerp(GetComponent<UnityStandardAssets.ImageEffects.ScreenOverlay>().intensity, Mathf.Lerp(0.0f, 1.0f, 1.0f - Mathf.Clamp01((zoomSize - minFadeSize) / (maxFadeSize / minFadeSize))), Time.deltaTime * 2f); // } // else // { // GetComponent<UnityStandardAssets.ImageEffects.ScreenOverlay>().intensity = Mathf.Lerp(GetComponent<UnityStandardAssets.ImageEffects.ScreenOverlay>().intensity, 0.0f, Time.deltaTime * 10); // } // } // else // { // GetComponent<UnityStandardAssets.ImageEffects.ScreenOverlay>().intensity = Mathf.Lerp(GetComponent<UnityStandardAssets.ImageEffects.ScreenOverlay>().intensity, 1.0f, Time.deltaTime * 1.5f); // } //} public void CheckZoomZones() { ZoomZone highestPriorityZone = null; foreach (ZoomZone zoomZone in zoomZones) { if (zoomZone) { // Check if the zoom zone is linked and should jump float zoomJump = zoomZone.GetLinkedZoomJump(Camera.main.GetComponent <Collider>().bounds); if (zoomJump != 0.0f) { if (gameState == GameState.INTRO) { gameState = GameState.MAIN; SaveManager.Save_PassedIntro(); } ZoomZone linkedZoomZone = zoomZone.GetLinkedZoomZone(); Vector3 newCameraPosition = linkedZoomZone.transform.position + zoomZone.GetZoomZoneOffset(Camera.main.transform.position) * zoomJump; Debug.Log("Zoom Offset: " + zoomZone.GetZoomZoneOffset(Camera.main.transform.position), zoomZone); Debug.Log("Zoom Jump: " + zoomJump, zoomZone); Camera.main.transform.position = new Vector3(newCameraPosition.x, newCameraPosition.y, Camera.main.transform.position.z); zoomSize = zoomSize * zoomJump; if (Camera.main.orthographic) { Camera.main.orthographicSize = zoomSize; Camera.main.transform.localScale = Vector3.one * zoomSize; } else { Camera.main.fieldOfView = zoomSize; } zoomZone.UnRecordZoomZone(linkedZoomZone); linkedZoomZone.RecordZoomZone(zoomZone); //Ambient Audio if (linkedZoomZone.ambientSound != null && AmbientAudio.currentTrack != linkedZoomZone.ambientSound) { if (AmbientAudio.isFading) { StopCoroutine(AmbientAudio.GetFadeCoroutine()); } AmbientAudio.SetFadeCoroutine(StartCoroutine(AmbientAudio.FadeAudio(linkedZoomZone.ambientSound))); } //Music if (linkedZoomZone.musicTrack != null && Music.currentTrack != linkedZoomZone.musicTrack) { if (Music.isFading) { StopCoroutine(Music.GetFadeCoroutine()); } Music.SetFadeCoroutine(StartCoroutine(Music.FadeAudio(linkedZoomZone.musicTrack))); } } if (zoomZone.InsideZoomZone(Camera.main.transform.position) && (highestPriorityZone == null || zoomZone.priority > highestPriorityZone.priority)) { highestPriorityZone = zoomZone; } if (zoomJump != 0.0f) { break; } } } if (highestPriorityZone) { float minZoomSize = highestPriorityZone.GetMinZoomAtPoint(Camera.main.transform.position); if (minZoomSize > zoomSize) { zoomSize = Mathf.Lerp(zoomSize, minZoomSize, Time.deltaTime); } } }
public float GetLinkedZoomJump(Bounds viewBounds) { float zoomJump = 0.0f; ZoomZone lastRecordedZoomZone = GetLinkedZoomZone(); if (lastRecordedZoomZone || linkedToEvent) { Bounds zoneBounds = GetComponent <BoxCollider>().bounds; if (InsideZoomZone(viewBounds.center)) { if (linkedZoomDirection == 1) { if (zoneBounds.Contains(viewBounds.max) == true && zoneBounds.Contains(viewBounds.min) == true) { if (linkedToEvent && invokedEventZoomIn == false) { linkedZoomEventZoomIn.Invoke(); invokedEventZoomIn = true; invokedEventZoomOut = false; } if (lastRecordedZoomZone) { zoomJump = lastRecordedZoomZone.transform.localScale.magnitude / transform.localScale.magnitude; } } } else if (linkedZoomDirection == -1) { if (zoneBounds.Contains(viewBounds.center + Vector3.up * viewBounds.extents.y) == false || zoneBounds.Contains(viewBounds.center + Vector3.right * viewBounds.extents.x) == false || zoneBounds.Contains(viewBounds.center + Vector3.down * viewBounds.extents.y) == false || zoneBounds.Contains(viewBounds.center + Vector3.left * viewBounds.extents.x) == false) { if (linkedToEvent && invokedEventZoomOut == false) { linkedZoomEventZoomOut.Invoke(); invokedEventZoomOut = true; invokedEventZoomIn = false; } if (lastRecordedZoomZone) { zoomJump = lastRecordedZoomZone.transform.localScale.magnitude / transform.localScale.magnitude; } } } else //linked event only { if (zoneBounds.Contains(viewBounds.max) == true && zoneBounds.Contains(viewBounds.min) == true) //zooming in { if (linkedToEvent && invokedEventZoomIn == false) { linkedZoomEventZoomIn.Invoke(); invokedEventZoomIn = true; invokedEventZoomOut = false; } } if (zoneBounds.Contains(viewBounds.center + Vector3.up * viewBounds.extents.y) == false || zoneBounds.Contains(viewBounds.center + Vector3.right * viewBounds.extents.x) == false || zoneBounds.Contains(viewBounds.center + Vector3.down * viewBounds.extents.y) == false || zoneBounds.Contains(viewBounds.center + Vector3.left * viewBounds.extents.x) == false) //zooming out { if (linkedToEvent && invokedEventZoomOut == false) { linkedZoomEventZoomOut.Invoke(); invokedEventZoomOut = true; invokedEventZoomIn = false; } } } } } return(zoomJump); }
/*Animation BreakDown * 0 - Standing Still * 1 - Running * 2 - Squatting * 3 - Reverse Squatting * 4 - Squatting Still * 5 - Squat Running */ void Awake() { controller = GetComponent<Controller> (); getDamage = GetComponent<GetDamage> (); allKnow = GameObject.Find ("theOmniscient").GetComponent<GatherAllKnowledge> (); crouching = false; uncrouching = false; onMyKnees = false; Physics2D.IgnoreLayerCollision (8, 8); conAnchs = new Vector2[] { new Vector2 (0.025f,0.37f), new Vector2 (0.025f, 0.315f), new Vector2 (0.025f, 0.2605f), new Vector2 (0.025f, 0.2055f), new Vector2 (0.015f, 0.15f), }; if (GameObject.Find ("CheckPoints")) { checkPoint = GameObject.Find ("CheckPoints").GetComponent<CheckPoint>(); } char1 = false; char2 = false; teleHovering = false; copterHovering = false; recoRotoSpeed = 25f; angleTol = 3f; liftForce = 75f; jetSpeed = 300f; unitTimeFrame = .083f; platforms = new Collider2D[20]; minMoveRad = .4f; if (GameObject.Find("ZoomZone")){ zoomZone = GameObject.Find("ZoomZone").GetComponent<ZoomZone>(); } if (gameObject.name == "Hero1"){ char1 = true; hud = GameObject.Find("HUD1").GetComponent<HUD> (); healthBar = GameObject.Find ("HealthBar1").GetComponent<HealthBar> (); arm = GameObject.Find("Arm1"); shield = GameObject.Find("Shield1"); hammer = GameObject.Find("Hammer1"); tractorBeam = GameObject.Find("TractorBeam1"); weaponDetectorScript = GameObject.Find ("WeaponDetector1").GetComponent<WeaponDetectorScript> (); chargeDisplay = GameObject.Find ("ChargeBar1").GetComponent<ChargeDisplay> (); } else{ char2 = true; hud = GameObject.Find("HUD2").GetComponent<HUD> (); healthBar = GameObject.Find ("HealthBar2").GetComponent<HealthBar> (); arm = GameObject.Find("Arm2"); shield = GameObject.Find("Shield2"); hammer = GameObject.Find("Hammer2"); tractorBeam = GameObject.Find("TractorBeam2"); weaponDetectorScript = GameObject.Find ("WeaponDetector2").GetComponent<WeaponDetectorScript> (); chargeDisplay = GameObject.Find ("ChargeBar2").GetComponent<ChargeDisplay> (); } polyCols = GetComponents<PolygonCollider2D> (); cirCol = GetComponent<CircleCollider2D> (); hamCol = hammer.GetComponent<BoxCollider2D> (); shieldCol = shield.GetComponent<PolygonCollider2D> (); tractorBeamCol = tractorBeam.GetComponent<PolygonCollider2D> (); weaponCol = weaponDetectorScript.GetComponent<CircleCollider2D> (); spriteArm = arm.GetComponent<SpriteRenderer> (); spriteShield = shield.GetComponent<SpriteRenderer> (); spriteHero = GetComponent<SpriteRenderer> (); spriteHammer = hammer.GetComponent<SpriteRenderer> (); startingBounce = cirCol.sharedMaterial.bounciness; startingFriction = cirCol.sharedMaterial.friction; armRotateScript = arm.GetComponent<ArmRotate> (); armRot = arm.transform.rotation; armHinge = arm.GetComponent<HingeJoint2D>(); shieldHinge = shield.GetComponent<HingeJoint2D>(); hammerHinge = hammer.GetComponent<HingeJoint2D> (); alive = true; //transform.position = Vector3.zero; if (Application.loadedLevelName == "BattleArena"){ spawnSpots = new Vector3[6]; spawnSpots[0] = new Vector3 (0f,-2f,0f); spawnSpots [1] = new Vector3 (-2f,-1f,0f); spawnSpots [2] = new Vector3 (2f,-1f,0f); spawnSpots [3] = new Vector3 (0f,0f,0f); spawnSpots [4] = new Vector3 (0f,-2f,0f); spawnSpots [5] = new Vector3 (0f,-2f,0f); } else if (Application.loadedLevelName == "BattleShrine"){ spawnSpots = new Vector3[6]; spawnSpots [0] = new Vector3 (0f,2.5f,0f); spawnSpots [1] = new Vector3 (-1f,0f,0f); spawnSpots [2] = new Vector3 (1f,0f,0f); spawnSpots [3] = new Vector3 (0f,-2.5f,0f); spawnSpots [4] = new Vector3 (-3.5f,-.75f,0f); spawnSpots [5] = new Vector3 (3.5f,-.75f,0f); } else{ spawnSpots = new Vector3[6]; spawnSpots [0] = new Vector3 (0f,-2f,0f); spawnSpots [1] = new Vector3 (-2f,-1f,0f); spawnSpots [2] = new Vector3 (2f,-1f,0f); spawnSpots [3] = new Vector3 (0f,0f,0f); spawnSpots [4] = new Vector3 (0f,-2f,0f); spawnSpots [5] = new Vector3 (0f,-2f,0f); } wallJumpLagTime = .7f; runningVelThresh = .3f; runningCrouchVelThresh = .1f; wallDelay = false; heroAnimator = GetComponent<Animator>(); time2Respawn = 2f; startingHealth = 100; fallTimeDelay = 1f; runningSpeed = 7.5f; floatingSpeed = runningSpeed; jumpSpeed = 200f; fallSpeed = -50f; maxVelocity = new Vector2 (2f, 5f); maxFloatVelocity = new Vector2 (2.5f, 2.5f); floorDetectionBoxHeights = new Vector2 (0.023f,0.2f); forceX = 0; forceY = 0; i = 0; damage = 0; startingJumpSpeed = jumpSpeed; startingRunningSpeed = runningSpeed; startingFallSpeed = fallSpeed; startingMaxVelocity = maxVelocity.x; followP1 = true; }
/*Animation BreakDown * 0 - Standing Still * 1 - Running * 2 - Squatting * 3 - Reverse Squatting * 4 - Squatting Still * 5 - Squat Running */ void Awake() { controller = GetComponent <Controller> (); getDamage = GetComponent <GetDamage> (); allKnow = GameObject.Find("theOmniscient").GetComponent <GatherAllKnowledge> (); crouching = false; uncrouching = false; onMyKnees = false; Physics2D.IgnoreLayerCollision(8, 8); conAnchs = new Vector2[] { new Vector2(0.025f, 0.37f), new Vector2(0.025f, 0.315f), new Vector2(0.025f, 0.2605f), new Vector2(0.025f, 0.2055f), new Vector2(0.015f, 0.15f), }; if (GameObject.Find("CheckPoints")) { checkPoint = GameObject.Find("CheckPoints").GetComponent <CheckPoint>(); } char1 = false; char2 = false; teleHovering = false; copterHovering = false; recoRotoSpeed = 25f; angleTol = 3f; liftForce = 75f; jetSpeed = 300f; unitTimeFrame = .083f; platforms = new Collider2D[20]; minMoveRad = .4f; if (GameObject.Find("ZoomZone")) { zoomZone = GameObject.Find("ZoomZone").GetComponent <ZoomZone>(); } if (gameObject.name == "Hero1") { char1 = true; hud = GameObject.Find("HUD1").GetComponent <HUD> (); healthBar = GameObject.Find("HealthBar1").GetComponent <HealthBar> (); arm = GameObject.Find("Arm1"); shield = GameObject.Find("Shield1"); hammer = GameObject.Find("Hammer1"); tractorBeam = GameObject.Find("TractorBeam1"); weaponDetectorScript = GameObject.Find("WeaponDetector1").GetComponent <WeaponDetectorScript> (); chargeDisplay = GameObject.Find("ChargeBar1").GetComponent <ChargeDisplay> (); } else { char2 = true; hud = GameObject.Find("HUD2").GetComponent <HUD> (); healthBar = GameObject.Find("HealthBar2").GetComponent <HealthBar> (); arm = GameObject.Find("Arm2"); shield = GameObject.Find("Shield2"); hammer = GameObject.Find("Hammer2"); tractorBeam = GameObject.Find("TractorBeam2"); weaponDetectorScript = GameObject.Find("WeaponDetector2").GetComponent <WeaponDetectorScript> (); chargeDisplay = GameObject.Find("ChargeBar2").GetComponent <ChargeDisplay> (); } polyCols = GetComponents <PolygonCollider2D> (); cirCol = GetComponent <CircleCollider2D> (); hamCol = hammer.GetComponent <BoxCollider2D> (); shieldCol = shield.GetComponent <PolygonCollider2D> (); tractorBeamCol = tractorBeam.GetComponent <PolygonCollider2D> (); weaponCol = weaponDetectorScript.GetComponent <CircleCollider2D> (); spriteArm = arm.GetComponent <SpriteRenderer> (); spriteShield = shield.GetComponent <SpriteRenderer> (); spriteHero = GetComponent <SpriteRenderer> (); spriteHammer = hammer.GetComponent <SpriteRenderer> (); startingBounce = cirCol.sharedMaterial.bounciness; startingFriction = cirCol.sharedMaterial.friction; armRotateScript = arm.GetComponent <ArmRotate> (); armRot = arm.transform.rotation; armHinge = arm.GetComponent <HingeJoint2D>(); shieldHinge = shield.GetComponent <HingeJoint2D>(); hammerHinge = hammer.GetComponent <HingeJoint2D> (); alive = true; //transform.position = Vector3.zero; if (Application.loadedLevelName == "BattleArena") { spawnSpots = new Vector3[6]; spawnSpots[0] = new Vector3(0f, -2f, 0f); spawnSpots [1] = new Vector3(-2f, -1f, 0f); spawnSpots [2] = new Vector3(2f, -1f, 0f); spawnSpots [3] = new Vector3(0f, 0f, 0f); spawnSpots [4] = new Vector3(0f, -2f, 0f); spawnSpots [5] = new Vector3(0f, -2f, 0f); } else if (Application.loadedLevelName == "BattleShrine") { spawnSpots = new Vector3[6]; spawnSpots [0] = new Vector3(0f, 2.5f, 0f); spawnSpots [1] = new Vector3(-1f, 0f, 0f); spawnSpots [2] = new Vector3(1f, 0f, 0f); spawnSpots [3] = new Vector3(0f, -2.5f, 0f); spawnSpots [4] = new Vector3(-3.5f, -.75f, 0f); spawnSpots [5] = new Vector3(3.5f, -.75f, 0f); } else { spawnSpots = new Vector3[6]; spawnSpots [0] = new Vector3(0f, -2f, 0f); spawnSpots [1] = new Vector3(-2f, -1f, 0f); spawnSpots [2] = new Vector3(2f, -1f, 0f); spawnSpots [3] = new Vector3(0f, 0f, 0f); spawnSpots [4] = new Vector3(0f, -2f, 0f); spawnSpots [5] = new Vector3(0f, -2f, 0f); } wallJumpLagTime = .7f; runningVelThresh = .3f; runningCrouchVelThresh = .1f; wallDelay = false; heroAnimator = GetComponent <Animator>(); time2Respawn = 2f; startingHealth = 100; fallTimeDelay = 1f; runningSpeed = 7.5f; floatingSpeed = runningSpeed; jumpSpeed = 200f; fallSpeed = -50f; maxVelocity = new Vector2(2f, 5f); maxFloatVelocity = new Vector2(2.5f, 2.5f); floorDetectionBoxHeights = new Vector2(0.023f, 0.2f); forceX = 0; forceY = 0; i = 0; damage = 0; startingJumpSpeed = jumpSpeed; startingRunningSpeed = runningSpeed; startingFallSpeed = fallSpeed; startingMaxVelocity = maxVelocity.x; followP1 = true; }