// Use this for initialization public void initPos() { Bounds bounds = GetComponent <SpriteRenderer>().bounds; max = CameraExtensions.OrthographicBounds(Camera.main).max - bounds.extents; min = CameraExtensions.OrthographicBounds(Camera.main).min + bounds.extents; //min.x += bounds.size.x; if (isPlayerRight) { UpKey = KeyCode.UpArrow; downKey = KeyCode.DownArrow; LeftKey = KeyCode.LeftArrow; RightKey = KeyCode.RightArrow; transform.position = new Vector3(max.x, 0, 0); } else { UpKey = KeyCode.W; downKey = KeyCode.S; LeftKey = KeyCode.A; RightKey = KeyCode.D; transform.position = new Vector3(min.x, 0, 0); } }
void Awake() { connectedPortals = new List <Portal> (); layer = LayerManager.Instance().CreateLayer(gameObject.name); gameObject.layer = layer; Transform[] childrenTransforms = gameObject.GetComponentsInChildren <Transform>(); foreach (Transform t in childrenTransforms) { t.gameObject.layer = layer; } foreach (Camera camera in Camera.allCameras) { if (this.initialWorld) { CameraExtensions.LayerCullingShow(camera, layer); if (camera.GetComponent <Skybox>()) { camera.GetComponent <Skybox>().material = customSkybox; } } else { CameraExtensions.LayerCullingHide(camera, layer); } } }
// Use this for initialization void Start() { txtInstruction.DOFade(0.2f, 1f).SetLoops(-1, LoopType.Yoyo); //walls = transform.chi Bounds bounds = CameraExtensions.OrthographicBounds(Camera.main); //Transform[] children = transform.GetComponentsInChildren<Transform>(); walls[0].position = bounds.center + new Vector3(bounds.extents.x, -bounds.center.y, 0); walls[0].localScale = new Vector3(2, 2, bounds.size.y); walls[1].position = bounds.center + new Vector3(-bounds.extents.x, -bounds.center.y, 0); walls[1].localScale = new Vector3(2, 2, bounds.size.y); maxX = walls[0].position.x - 2; minX = walls[1].position.x + 2; walls[2].position = bounds.center + new Vector3(0, -bounds.center.y, bounds.extents.y); walls[2].localScale = new Vector3(bounds.size.x, 2, 2); walls[3].position = bounds.center + new Vector3(0, -bounds.center.y, -bounds.extents.y); walls[3].localScale = new Vector3(bounds.size.x, 2, 2); maxY = walls[2].position.z - 2; minY = walls[3].position.z + 2; float width = 0; bar.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0f); // = new Vector3(maxX-minX,1,1); }
private void UpdateZoomThing() { int state = 0; if (m_GameManager.Players[m_PlayerIndex].Player != null) { state = m_GameManager.Players[m_PlayerIndex].Player.PInput.Zoom ? 1 : -1; } m_CameraMode += state * Time.deltaTime * 3.0f; m_CameraMode = Mathf.Clamp01(m_CameraMode); // Set the layer masks string mask = "P" + (m_PlayerIndex + 1).ToString() + "FPHidden"; if (m_CameraMode > 0.6f) { CameraExtensions.LayerCullingHide(m_Camera, mask); } else { CameraExtensions.LayerCullingShow(m_Camera, mask); } }
// Use this for initialization void Start() { Messenger.AddListener <GameObject> ("exitObstacle", exitedCollider); Messenger.AddListener <GameObject> ("disappear", disappearObstacle); Messenger.AddListener <GameObject> ("enteredObstacle", enteredCollider); Messenger.AddListener("clearOutLane", clearOutLane); Messenger.AddListener("ranOutOfHealth", ranOutOfHealth); Messenger.AddListener("landed", landed); Messenger.AddListener("jumped", jumped); Messenger.AddListener <bool> ("isLaneEnabled", laneEnabled); Messenger.AddListener("hitPowerBox", hitPowerBox); cam = Camera.main; scoreController = new ScoreController(); timerController = new TimerController(() => TimesUp()); cameraScript = cam.GetComponent <CameraScript> (); bounds = CameraExtensions.OrthographicBounds(cam); audioScript = GameObject.FindGameObjectWithTag("AudioController").GetComponent <AudioScript> (); soundEffectScript = GameObject.FindGameObjectWithTag("SoundEffectsController").GetComponent <SoundEffectsScript> (); currentGameLevel = LevelManager.Instance.getCurrentLevelDetail(); timerController.beginTimer(currentGameLevel.lengthInSeconds * 1000); #if UNITY_ANDROID touch = new TouchGesture(this.gestureSetting); StartCoroutine(touch.CheckHorizontalSwipes( onLeftSwipe: () => { moveRight(); }, onRightSwipe: () => { moveLeft(); } )); #endif }
// Update is called once per frame void FixedUpdate() { Bounds bounds = CameraExtensions.OrthographicBounds(Camera.main); if (transform.position.x > bounds.max.x - sr.bounds.extents.x || transform.position.x < bounds.min.x + sr.bounds.extents.x) { Debug.Log("ball goes out of view"); bool isRightPlayerLose; if (transform.position.x > 0) { isRightPlayerLose = true; } else { isRightPlayerLose = false; } scoreCounter.UpdateScore(isRightPlayerLose); } else if (transform.position.y >= bounds.max.y || transform.position.y <= bounds.min.y) { rb.velocity = new Vector2(rb.velocity.x, -rb.velocity.y); } }
// Update is called once per frame void Update() { if (nextY < CameraExtensions.GetEdges(Camera.main)[1]) { GenerateRows(1); } }
// Update is called once per frame void Update() { if (transform.position.y + 1 < CameraExtensions.GetEdges(Camera.main)[3]) { Destroy(gameObject); } }
void GenerateRows(int count) { // left and right edges are constant in our case so maybe not necessary to call this every loop? // not too taxing so can be left for now List <float> cameraEdges = CameraExtensions.GetEdges(Camera.main); for (int c = 0; c < count; c++) { nextY += intervalY; List <GameObject> row = new List <GameObject>(); for (int x = 0; x < cols; x++) { float xStep = (ScreenDims.x / cols); float px = (x * xStep) - (HalfDims.x) + .6f; row.Add(Instantiate(PlatformPrefab, new Vector3(px, nextY, 0), Quaternion.identity)); } int rand = Random.Range(cols / 2, cols); for (int i = 0; i < rand; i++) // remove between 1 and col minus 1 platforms per row { int index = Random.Range(0, row.Count); Destroy(row[index]); row.RemoveAt(index); } if (Random.value < CoinChance && GenerateCoins) { // spawn coin based on random chance per row generated Instantiate(CoinPrefab, new Vector3(Random.Range(cameraEdges[0], cameraEdges[2]), nextY + 0.5f, 0), Quaternion.identity); } row.Clear(); } }
// Update is called once per frame void Update() { if (!CameraExtensions.ContainBounds(bounds)) { ShiftTerrain(); } }
// Use this for initialization void Start() { Bounds cameraBounds = CameraExtensions.OrthographicBounds(); cameraBounds = CameraExtensions.OrthographicBoundsWorld(); Vector3 tileSize = terrain.GetComponent <Terrain>().terrainData.size; //new Vector3 (2f, 1f, 2f); int xCount = 1, //Mathf.Abs((int)((cameraBounds.max.x - cameraBounds.min.x) / tileSize.x)), // TODO rename width and make class variable yCount = 1, zCount = 1; //= Mathf.Abs((int)((cameraBounds.max.z - cameraBounds.min.z) / tileSize.z)); terrains = new Tile[xCount * yCount * zCount]; // terrains = new Tile[xCount, 1, zCount]; // bounds = CameraExtensions.OrthographicBounds ().min; for (int tile = 0, x = 0; x < xCount; x++) { for (int y = 0; y < yCount; y++) { for (int z = 0; z < zCount; z++, tile++) { terrains [tile] = Instantiate(terrain).GetComponent <Tile> (); terrains [tile].transform.localPosition = new Vector3( cameraBounds.min.x + ((float)x) * tileSize.x, 0f, cameraBounds.min.z + ((float)z) * tileSize.z ); } } } // while(!CameraExtensions.ContainBounds(bounds)) { // terrains[i]Instantiate(terrain).transform.position // } }
private GameObject GetBlockUnderMouse() { Camera camera = CameraExtensions.FindCameraUnderMouse(); if (camera == null) { return(null); } Ray ray = camera.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (!Physics.Raycast(ray, out hitInfo)) { return(null); } GameObject gameObject = RootGameObject.GetRoot(hitInfo.collider.gameObject); if (Tags.PALETTE_BLOCK.HasTag(gameObject)) { return(gameObject); } return(null); }
protected void RenderPlane(Camera portalCamera, RenderTexture targetTexture, Vector3 camPosition, Quaternion camRotation, Matrix4x4 camProjectionMatrix) { // Copy camera position/rotation/projection data into the reflectionCamera portalCamera.transform.position = camPosition; portalCamera.transform.rotation = camRotation; portalCamera.targetTexture = targetTexture; portalCamera.ResetWorldToCameraMatrix(); // Change the project matrix to use oblique culling (only show things BEHIND the portal) Vector3 pos = transform.position; Vector3 normal = transform.forward; bool isForward = transform.InverseTransformPoint(portalCamera.transform.position).z < 0; Vector4 clipPlane = CameraSpacePlane(portalCamera, pos, normal, isForward ? 1.0f : -1.0f); Matrix4x4 projection = camProjectionMatrix; if (this.enableObliqueProjection) { CalculateObliqueMatrix(ref projection, clipPlane); } portalCamera.projectionMatrix = projection; // Hide the other dimensions portalCamera.enabled = false; portalCamera.cullingMask = 0; CameraExtensions.LayerCullingShow(portalCamera, ToDimension().layer); CameraExtensions.LayerCullingShowMask(portalCamera, alwaysVisibleMask); portalCamera.Render(); }
// Update is called once per frame void Update() { /* This is used to enable VRTK kit builds*/ if (mainCameraNeedsSetup) { if (Camera.main == null) { return; } if (this.initialWorld) { CameraExtensions.LayerCullingShow(Camera.main, layer); Camera.main.gameObject.layer = layer; if (Camera.main.GetComponent <Skybox>()) { Camera.main.GetComponent <Skybox>().material = customSkybox; } } else { CameraExtensions.LayerCullingHide(Camera.main, layer); } this.mainCameraNeedsSetup = false; } }
/// <summary> /// Rotates a target towards the mouse at a constant rate /// </summary> /// <param name="target">Target GameObject</param> /// <param name="camera">Rendering camera</param> /// <param name="turningRate">Speed at which the object should turn to any side</param> public static Quaternion MouseLookAtRotation(Transform target, float turningRate, Camera camera = null) { camera = camera ?? CameraExtensions.GetMainOrthgraphicCamera(); Quaternion q = GetMouseWorldPos(target, camera); var zStep = CalculateZStep(target.rotation.eulerAngles, q.eulerAngles, turningRate); return(Quaternion.Euler(target.rotation.eulerAngles + new Vector3(0f, 0f, zStep))); }
// Update is called once per frame void Update() { // remove from game if off screen if (transform.position.y + 1 < CameraExtensions.GetEdges(Camera.main)[3]) { Destroy(gameObject); } }
// Use this for initialization void Start() { InstantiatePlayerReflection(); cameraBounds = CameraExtensions.OrthographicBounds(Camera.main); playerSprite = GetComponent <SpriteRenderer>(); spriteWidth = playerSprite.sprite.bounds.size.x; }
/// <summary> /// Called once the map is generated. /// </summary> /// <remarks> /// This fixes an issue where /// all those extensions that /// require calling the central /// property of the Map class in /// the API were corrupted due to /// a missed call, such as before /// getting the elevator type. /// </remarks> public static void OnMapGenerated() { API.Features.Map.ClearCache(); GenerateCache(); LiftTypeExtension.RegisterElevatorTypesOnLevelLoad(); CameraExtensions.RegisterCameraInfoOnLevelLoad(); DoorExtensions.RegisterDoorTypesOnLevelLoad(); }
public void Update() { if (Backgrounds[0].transform.position.y + BackgroundHeight < CameraExtensions.GetEdges(Camera.main)[3]) { Destroy(Backgrounds[0]); Backgrounds.RemoveAt(0); NextBackground(); } }
void FixedUpdate() { _transform.position += Vector3.down * Speed; if (_transform.position.y < CameraExtensions.OrthographicBounds(Camera.main).min.y) { Destroy(gameObject); } }
/* Rendering and Display */ void OnWillRenderObject() { // Create the textures and camera if they don't exist. if (!leftTexture) { Vector2 texSize = new Vector2(mainCamera.pixelWidth, mainCamera.pixelHeight); leftTexture = new RenderTexture((int)(texSize.x * renderQuality), (int)(texSize.y * renderQuality), 16); #if USES_STEAM_VR || USES_OPEN_VR rightTexture = new RenderTexture((int)(texSize.x * renderQuality), (int)(texSize.y * renderQuality), 16); #endif renderCam = new GameObject(gameObject.name + " render camera", typeof(Camera), typeof(Skybox)).GetComponent <Camera> (); #if USES_AR_KIT if (mainCamera.GetComponent <UnityARVideo> ()) { renderCam.clearFlags = CameraClearFlags.SolidColor; ARKitCameraRender component = renderCam.gameObject.AddComponent <ARKitCameraRender> (); component.m_ClearMaterial = mainCamera.GetComponent <UnityARVideo> ().m_ClearMaterial; } #endif renderCam.name = gameObject.name + " render camera"; renderCam.tag = "Untagged"; if (renderCam.GetComponent <Skybox> ()) { camSkybox = renderCam.GetComponent <Skybox> (); } else { renderCam.gameObject.AddComponent <Skybox> (); camSkybox = renderCam.GetComponent <Skybox> (); } CameraExtensions.ClearCameraComponents(renderCam.GetComponent <Camera>()); // remove child objects to better support VRTKKit /*foreach(Transform child in renderCam.transform) * { * Destroy(child.gameObject); * } */ renderCam.hideFlags = HideFlags.HideInHierarchy; renderCam.enabled = false; } if (ToDimension().customSkybox) { camSkybox.material = ToDimension().customSkybox; } meshRenderer.material.SetFloat("_RecursiveRender", (gameObject.layer != Camera.current.gameObject.layer) ? 1 : 0); RenderPortal(Camera.current); }
private void Start() { _playerTransform = GetComponent <Transform>(); _playerRB = GetComponent <Rigidbody2D>(); _playerBounds = GetComponent <BoxCollider2D>(); minX = CameraExtensions.OrthographicBounds(Camera.main).min.x + _playerBounds.bounds.size.x; maxX = CameraExtensions.OrthographicBounds(Camera.main).max.x - _playerBounds.bounds.size.x; _isDead = false; }
protected void Initialise(GameObject feedbackBlock, GameObject collisionChecker) { this.feedbackBlock = feedbackBlock; this.dragCollisionBlock = collisionChecker; feedbackBlock.Destroy <FeedbackEditorBlock>(); feedbackOutline = feedbackBlock.GetComponent <Outline>(); feedbackOutline.enabled = true; feedbackColliders = feedbackBlock.GetComponentsInChildren <BlockCollider>(); foreach (GameObject go in feedbackBlock.Children(true)) { if (Tags.EDITOR_PIP.HasTag(go)) { go.tag = Tags.TEMPLATE_PIP.TagName(); } else if (Tags.EDITOR_BLOCK.HasTag(go)) { go.tag = Tags.TEMPLATE_BLOCK.TagName(); } } if (Tags.EDITOR_BLOCK.HasTag(feedbackBlock)) { feedbackBlock.tag = Tags.TEMPLATE_BLOCK.TagName(); } pipColliders = dragCollisionBlock.GetComponentsInChildren <PipCollider>(); currentRotation = dragCollisionBlock.transform.rotation; dragCollisionBlock.DestroyInChildren <Renderer>(); dragCollisionBlock.DestroyInChildren <Outline>(); foreach (GameObject go in dragCollisionBlock.Children(true)) { if (Tags.EDITOR_PIP.HasTag(go)) { go.tag = Tags.TEMPLATE_PIP.TagName(); } else if (Tags.EDITOR_BLOCK.HasTag(go)) { go.tag = Tags.TEMPLATE_BLOCK.TagName(); } } if (Tags.EDITOR_BLOCK.HasTag(dragCollisionBlock)) { dragCollisionBlock.tag = Tags.TEMPLATE_BLOCK.TagName(); } Camera currentCamera = CameraExtensions.FindCameraUnderMouse(); if (currentCamera != null) { UpdateCurrentBlock(currentCamera); } }
void OnTriggerEnter(Collider other) { if (other.GetComponent <Rigidbody> () && CameraExtensions.CameraForObject(other.gameObject) != mainCamera && (ignoreRigidbodyTag == "" || !other.gameObject.CompareTag(ignoreRigidbodyTag))) { RigidbodyCollider collider = new RigidbodyCollider(); collider.collider = other; collider.triggerZDirection = (transform.InverseTransformPoint(other.transform.position).z > 0); colliders.Add(collider); } }
public static void SwitchCameraRender(Camera camera, int fromDimensionLayer, int toDimensionLayer, Material dimensionSkybox) { CameraExtensions.LayerCullingShow(camera, toDimensionLayer); CameraExtensions.LayerCullingHide(camera, fromDimensionLayer); if (dimensionSkybox) { if (camera.GetComponent <Skybox> ()) { camera.GetComponent <Skybox> ().material = dimensionSkybox; } } }
public static void SwitchCameraRender(Camera camera, int fromDimensionLayer, int toDimensionLayer, Material dimensionSkybox) { CameraExtensions.LayerCullingShow(camera, toDimensionLayer); CameraExtensions.LayerCullingHide(camera, fromDimensionLayer); if (dimensionSkybox) { if (camera.GetComponent <Skybox> ()) { camera.GetComponent <Skybox> ().material = dimensionSkybox; RenderSettings.skybox = dimensionSkybox; DynamicGI.UpdateEnvironment(); } } }
void Update() { if (moving) { playerSpeed += playerSpeedIncrement; player.transform.position = Vector3.MoveTowards(player.transform.position, destination, playerSpeed); cam.transform.position = Vector3.MoveTowards(cam.transform.position, destination, speed); Bounds bounds = CameraExtensions.OrthographicBounds(cam); if (cam.transform.position.y + bounds.size.y + 10f < player.transform.position.y) { moving = false; displayScores(); } } }
public void Start() { minX = CameraExtensions.OrthographicBounds(Camera.main).min.x; maxX = CameraExtensions.OrthographicBounds(Camera.main).max.x; minY = CameraExtensions.OrthographicBounds(Camera.main).min.y; maxY = CameraExtensions.OrthographicBounds(Camera.main).max.y; for (int i = 0; i < EnemyTypes.Count; i++) { Instantiate(EnemyTypes[i], new Vector3(Random.Range(minX, maxX), Random.Range(maxY, maxY + 3), 0), Quaternion.identity, transform); } }
void Update() { if (particleMoving) { bounds = CameraExtensions.OrthographicBounds(cam); if (particleSystem.transform.position.y < bounds.center.y + bounds.extents.y) { particleSystem.transform.position = new Vector3(particleSystem.transform.position.x, particleSystem.transform.position.y + particleSpeed, particleSystem.transform.position.z); } else { particleMoving = false; particleSystem.Stop(); } } }
void Start() { prefabs = new List <GameObject> (); camera = Camera.main; bounds = CameraExtensions.OrthographicBounds(Camera.main); float max = bounds.max.y; float min = bounds.min.y; float current = max; while (current > min) { GameObject go = Instantiate(prefab, new Vector3(0f, current, 10f), Quaternion.identity) as GameObject; go.transform.SetParent(this.transform); current -= spacer; prefabs.Add(go); } }