private void OnDisable() { if (Inst == this) { Inst = null; } }
void Awake() { cameraBounds = FindObjectOfType <CameraBounds>(); boundingBox = GetComponent <BoundingBox>(); boundingBox.OnCollision.AddListener(OnCollsionDetected); }
// Update is called once per frame void SpawnBubble() { float scale = Random.Range(0.2f, 1.1f); if (gameObjectList.Count < numBubbles) { CameraBounds camScript = FindObjectOfType <CameraBounds>(); GameObject gameObject = (GameObject)Instantiate(prefabBubble); gameObject.transform.parent = this.transform.parent; gameObject.transform.parent = this.transform; gameObject.name = "Bubble " + gameObjectList.Count; gameObject.transform.localScale = new Vector3(scale, scale, scale); //Debug.Log("Camerabounds=" + camScript.OrthographicBounds()); RandomizeBubblePosition bubblepos = gameObject.GetComponent <RandomizeBubblePosition>(); //orthographic size is equal to half the camera width float upperXBound = camScript.OrthographicBounds().size.x * 2; bubblepos.xOffset = Random.Range(xAnimationOffset, upperXBound); bubblepos.yOffset = Random.Range(-2f, 8f); gameObjectList.Add(gameObject); } else { CancelInvoke("SpawnBubble"); } }
private void ClampCameraToWorldBounds() { if (m_worldBounds) { CameraBounds cameraBounds = CheckCurrentCameraBoundsAt(m_mainCamera.transform.position); if (!cameraBounds.m_isInsideLeftBound) { float clampedX = m_worldBounds.bounds.min.x + GetCameraOrthoSizeX(); ClampCameraToX(clampedX); } else if (!cameraBounds.m_isInsideRightBound) { float clampedX = m_worldBounds.bounds.max.x - GetCameraOrthoSizeX(); ClampCameraToX(clampedX); } else if (m_keepCameraClamped && IsCameraInsideBoundsAt(m_cameraInitialPosLocalSpace)) { m_keepCameraClamped = false; ResetToInitialPos(); } else if (m_keepCameraClamped) { m_mainCamera.transform.position = m_cameraClampPosition; } } }
private void SelectState(string stateName, int stateIndex) { if (IndexOfState(stateName) == stateIndex) { // Adds a SymbolLayer to display maximum temperature in state SymbolLayer maxTempLayer = new SymbolLayer(MAX_TEMP_LAYER_ID, GEOJSON_SRC_ID) { Filter = Expression.All( Expression.Eq(Expression.Get("element"), ("All-Time Maximum Temperature")), Expression.Eq(Expression.Get("state"), (stateName)) ) }; map.Functions.UpdateLayer(maxTempLayer); // Adds a SymbolLayer to display minimum temperature in state SymbolLayer minTempLayer = new SymbolLayer(MIN_TEMP_LAYER_ID, GEOJSON_SRC_ID) { Filter = (Expression.All( Expression.Eq(Expression.Get("element"), ("All-Time Minimum Temperature")), Expression.Eq(Expression.Get("state"), (stateName)))) }; map.Functions.UpdateLayer(minTempLayer); var cameara = new CameraBounds(states[stateIndex].bounds, 100); map.Functions.AnimateCamera(cameara, 100); } }
protected virtual void Start() { camBounds = Camera.main.GetComponent <GameUtils>().CameraBounds; transform.position = new Vector3(camBounds.topRightCorner.x + startXPos, camBounds.bottomLeftCorner.y + Random.Range(camBounds.centerOfScreen.y / 6, 5 * camBounds.centerOfScreen.y / 6), 0f); }
void Update() { if (input.TeleportButtonPressed) { transform.position = CameraBounds.getRandomPointInsideBounds(2, 0); } }
// ---------------------------------------------------------------- // Serialization // ---------------------------------------------------------------- public RoomData ToData() { RoomData rd = new RoomData(MyWorldData, RoomKey); // -- General Properties -- rd.SetPosGlobal(PosGlobal); rd.SetDesignerFlag(MyRoomData.DesignerFlag); rd.SetIsSecret(MyRoomData.IsSecret); rd.isClustStart = MyRoomData.isClustStart; //rd.HasPlayerBeenHere = MyRoomData.HasPlayerBeenHere; // Find CameraBounds manually. CameraBounds cameraBounds = GetComponentInChildren <CameraBounds>(); if (cameraBounds != null) { rd.cameraBoundsData = cameraBounds.ToData() as CameraBoundsData; } // -- Props -- Prop[] allProps = FindObjectsOfType <Prop>(); foreach (Prop prop in allProps) { if (!prop.DoSaveInRoomFile()) { continue; } // This type of Prop doesn't save to Room file? Skip it. rd.AddPropData(prop.ToData()); } // Reverse the propDatas list so it's saved in the same order each time. (Kinda weird, but this is the easy solution.) rd.allPropDatas.Reverse(); return(rd); }
private bool IsCameraInsideBoundsAt(Vector3 posInLocalSpace) { Vector3 posInGlobalSpace = m_mainCamera.transform.parent.TransformPoint(posInLocalSpace); CameraBounds bounds = CheckCurrentCameraBoundsAt(posInGlobalSpace); return(bounds.IsInsideBounds()); }
public ZigZagMovement(Transform transform, float shipWidth) { var cameraBounds = CameraBounds.GetCameraBounds(Camera.main); maxY = cameraBounds.max.y - shipWidth / 2; minY = cameraBounds.min.y + shipWidth / 2; this.transform = transform; }
public void RandomSpawnAsteroid(int qtd) { for (int i = 0; i < qtd; i++) { SpawnAsteroid(CameraBounds.getRandomPointInsideBounds (minimumDistanceFromBorders, minimumDistanceFromPlayer), Asteroid.Size.LARGE); } }
public static CameraBounds GetInstance() { if (instance == null) { instance = FindObjectOfType <CameraBounds>(); } return(instance); }
private void Awake() { var myCamera = Camera.main; var bounds = CameraBounds.GetCameraBounds(myCamera); var middle = (bounds.max.y - bounds.min.y) / 2 + bounds.min.y; initialPosition = new Vector2(bounds.min.x + offsetInitialPosition, middle); InstantiatePlayerShips(); }
public CameraBoundsViewModel(CameraBounds cameraBounds) { if (cameraBounds.Camera == null) { throw new ArgumentException("The CameraBounds expected by this object needs to use a Camera"); } mCameraBounds = cameraBounds; }
void Awake() { AllCells = generateCells(); cameraTarget = transform.position; CellPrefab = cellPrefab; EnemyCells = GameObject.FindObjectsOfType <EnemyController>().ToList(); bounds = FindObjectOfType <CameraBounds>(); }
public void UpdateTo(CameraSave cameraSave) { if (mCameraBounds == null) { mCameraBounds = new CameraBounds(cameraSave); } mCameraBounds.CameraSave = cameraSave; mCameraBounds.UpdateBounds(0); }
public ReactiveHud() { mCameraBounds = new CameraBounds(EditorData.BoundsCamera); mSplineMover = new SplineMover(); mCurrentSplinePointMarker = new SplinePointSelectionMarker(); mSelf = this; }
public void SetCameraBounds(CameraBounds cameraBounds) { this.cameraBounds = cameraBounds; cameraBounds.CameraHeightOffset = OrthographicSize; cameraBounds.CameraWidthOffset = cameraBounds.CameraHeightOffset * cameraComponent.aspect; Vector2 clampedBoundsWorldPosition = cameraBounds.GetClampedBoundsPosition(transform.position); Vector2 clampedBoundsLocalPosition = transform.InverseTransformVector(clampedBoundsWorldPosition); transform.localPosition = clampedBoundsLocalPosition; }
private void Awake() { Vector2 minScreen = m_Camera.ScreenToWorldPoint(Vector3.zero); m_Bounds = new CameraBounds() { Left = minScreen.x, Right = Mathf.Abs(minScreen.x), Up = Mathf.Abs(minScreen.y), Down = minScreen.y }; }
public PlaneOrthoBoundControlledCamera(ISceneNode node, Props initialProps, bool acceptsInput, CameraBounds?bounds = null) { this.node = node; AcceptsInput = acceptsInput; realProps = visibleProps = initialProps; Bounds = bounds ?? new CameraBounds { PlaneBounds = new AaRectangle2(Vector2.Zero, float.MaxValue / 2, float.MaxValue / 2), MaxDistance = float.MaxValue, MinDistance = 0 }; }
public void addCameraBounds() { if (bounds == null) { GameObject go = new GameObject("CameraBounds"); CameraBounds cb = go.AddComponent <CameraBounds>(); cb.guiColour = new Color(0, 0, 1f, 0.1f); cb.pointa = new Vector3(20, 20, 0); this.bounds = cb; //EditorUtility.SetDirty(this); } }
private void OnTriggerStay2D(Collider2D other) { if (other.tag == "MapBounds") { if (currentMap != null && other.gameObject.name == currentMap.gameObject.name) { return; } other.GetComponent <CameraBounds>().CinemachineInThisMap.SetActive(true); currentMap.CinemachineInThisMap.SetActive(false); currentMap = other.GetComponent <CameraBounds>(); } }
public void AddBounds(string name, CameraBounds camBounds, float minx, float maxx, float miny, float maxy) { clampBounds.Add(new ClampBounds { Name = name, XMin = minx + horzExtent, YMin = miny + vertExtent, XMax = maxx - horzExtent, YMax = maxy - vertExtent, CameraBounds = camBounds }); CurrentRoom = name; }
public static CameraBounds GetCameraBoundsInWorld(Camera cam) { CameraBounds output = new CameraBounds(); float halfVertLen = cam.orthographicSize; float halfHorLen = halfVertLen * Screen.width / Screen.height; output.up = cam.transform.position + new Vector3(0f, halfVertLen, 0f); output.down = cam.transform.position + new Vector3(0f, -halfVertLen, 0f); output.left = cam.transform.position + new Vector3(-halfHorLen, 0f, 0f); output.right = cam.transform.position + new Vector3(halfHorLen, 0f, 0f); return(output); }
public Rect GetCameraBoundsLocal() { CameraBounds cameraBounds = GetComponentInChildren <CameraBounds>(); if (cameraBounds != null) { return(new Rect() { size = cameraBounds.Size, center = cameraBounds.PosLocal, }); } return(new Rect(0, 0, 20, 20)); }
/// <summary> /// <para>Get the camera view bounds adding up the extra space</para> /// </summary> /// <param name="myCamera"></param> /// <returns>Returns the points of the bounds forming a square. The first and the last point are the same</returns> private Vector2[] GetCameraViewBounds(Camera myCamera) { var bounds = CameraBounds.GetCameraBounds(myCamera); var max = bounds.max; var min = bounds.min; return(new[] { new Vector2(max.x + extraSpace, max.y + extraSpace), new Vector2(min.x - extraSpace, max.y + extraSpace), new Vector2(min.x - extraSpace, min.y - extraSpace), new Vector2(max.x + extraSpace, min.y - extraSpace), new Vector2(max.x + extraSpace, max.y + extraSpace), }); }
void InitializeCamera() { cameraBounds = new CameraBounds(); //Intialize the camera bounds so that the object instantiation is possible //Orthographic size is half the height of the camera's view cameraBounds.bottomLeft = new Vector3( Camera.main.transform.position.x - Camera.main.aspect * Camera.main.orthographicSize, //This gives half width Camera.main.transform.position.y - Camera.main.orthographicSize, //Similarly, this gives half height 0 ); cameraBounds.topRight = new Vector3( Camera.main.transform.position.x + Camera.main.aspect * Camera.main.orthographicSize, Camera.main.transform.position.y + Camera.main.orthographicSize, 0 ); }
/// <summary> /// <para>Set up the positions for the enemy spawning taking into account the camera bounds.</para> /// </summary> private void SetUpLimits() { var myCamera = Camera.main; if (myCamera == null) { return; } var bounds = CameraBounds.GetCameraBounds(myCamera); var max = bounds.max; var min = bounds.min; limitX = max.x + xOffset; minY = min.y + yOffset; maxY = max.y - yOffset; }
public ReactiveHud() { mCameraBounds = new CameraBounds(EditorData.BoundsCamera); mCurrentAxisAlignedRectangleHighlight = ShapeManager.AddAxisAlignedRectangle(); mCurrentAxisAlignedRectangleHighlight.Visible = false; mCurrentAxisAlignedCubeHighlight = ShapeManager.AddAxisAlignedRectangle(); mCurrentAxisAlignedCubeHighlight.Visible = false; mCurrentCircleHighlight = ShapeManager.AddAxisAlignedRectangle(); mCurrentCircleHighlight.Visible = false; mCurrentSphereHighlight = ShapeManager.AddAxisAlignedRectangle(); mCurrentSphereHighlight.Visible = false; mCrossHair = new Crosshair(); mCrossHair.Visible = false; float screensize = 5f; Vector3 forwardVector = MathFunctions.ForwardVector3; Matrix rotationMatrix = SpriteManager.Camera.RotationMatrix; MathFunctions.TransformVector(ref forwardVector, ref rotationMatrix); float planeDistance = Vector3.Dot(forwardVector, -SpriteManager.Camera.Position); float planeScreenHeight = 2f * planeDistance * (float)Math.Tan((double)SpriteManager.Camera.FieldOfView); float planeScreenWidth = planeScreenHeight / SpriteManager.Camera.FieldOfView; float width = screensize * planeScreenWidth / (float)SpriteManager.Camera.DestinationRectangle.Width; float height = screensize * planeScreenHeight / (float)SpriteManager.Camera.DestinationRectangle.Height; mNewPointPolygon = Polygon.CreateEquilateral(3, Math.Min(width, height), 0); //.3f, 0); mNewPointPolygon.Color = EditorProperties.NewPointPolygonColor; mPointText = TextManager.AddText(""); NewPointPolygonScale = 10 / SpriteManager.Camera.PixelsPerUnitAt(mNewPointPolygon.Z); }
private CameraBounds CheckCurrentCameraBoundsAt(Vector3 posInGlobalSpace) { CameraBounds bounds = new CameraBounds(); float orthoSizeX = GetCameraOrthoSizeX(); float leftBound = posInGlobalSpace.x - orthoSizeX; float rightBound = posInGlobalSpace.x + orthoSizeX; if (leftBound >= m_worldBounds.bounds.min.x) { bounds.m_isInsideLeftBound = true; } if (rightBound <= m_worldBounds.bounds.max.x) { bounds.m_isInsideRightBound = true; } return(bounds); }
void Awake() { _instance = this; c = GetComponent<Camera>(); pixelRect = c.pixelRect; }
void Awake() { Instance = this; }
void OnDestroy() { Instance = null; }