Inheritance: MonoBehaviour
Example #1
0
 private void OnDisable()
 {
     if (Inst == this)
     {
         Inst = null;
     }
 }
Example #2
0
    void Awake()
    {
        cameraBounds = FindObjectOfType <CameraBounds>();
        boundingBox  = GetComponent <BoundingBox>();

        boundingBox.OnCollision.AddListener(OnCollsionDetected);
    }
Example #3
0
    // 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");
        }
    }
Example #4
0
 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;
         }
     }
 }
Example #5
0
        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);
            }
        }
Example #6
0
    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);
    }
Example #7
0
 void Update()
 {
     if (input.TeleportButtonPressed)
     {
         transform.position = CameraBounds.getRandomPointInsideBounds(2, 0);
     }
 }
Example #8
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);
    }
Example #9
0
    private bool IsCameraInsideBoundsAt(Vector3 posInLocalSpace)
    {
        Vector3      posInGlobalSpace = m_mainCamera.transform.parent.TransformPoint(posInLocalSpace);
        CameraBounds bounds           = CheckCurrentCameraBoundsAt(posInGlobalSpace);

        return(bounds.IsInsideBounds());
    }
Example #10
0
    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;
    }
Example #11
0
 public void RandomSpawnAsteroid(int qtd)
 {
     for (int i = 0; i < qtd; i++)
     {
         SpawnAsteroid(CameraBounds.getRandomPointInsideBounds
                           (minimumDistanceFromBorders, minimumDistanceFromPlayer), Asteroid.Size.LARGE);
     }
 }
Example #12
0
 public static CameraBounds GetInstance()
 {
     if (instance == null)
     {
         instance = FindObjectOfType <CameraBounds>();
     }
     return(instance);
 }
Example #13
0
    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();
    }
Example #14
0
        public CameraBoundsViewModel(CameraBounds cameraBounds)
        {
            if (cameraBounds.Camera == null)
            {
                throw new ArgumentException("The CameraBounds expected by this object needs to use a Camera");
            }

            mCameraBounds = cameraBounds;
        }
Example #15
0
    void Awake()
    {
        AllCells     = generateCells();
        cameraTarget = transform.position;
        CellPrefab   = cellPrefab;

        EnemyCells = GameObject.FindObjectsOfType <EnemyController>().ToList();

        bounds = FindObjectOfType <CameraBounds>();
    }
Example #16
0
        public void UpdateTo(CameraSave cameraSave)
        {
            if (mCameraBounds == null)
            {
                mCameraBounds = new CameraBounds(cameraSave);
            }

            mCameraBounds.CameraSave = cameraSave;
            mCameraBounds.UpdateBounds(0);
        }
Example #17
0
        public ReactiveHud()
        {
            mCameraBounds = new CameraBounds(EditorData.BoundsCamera);

            mSplineMover = new SplineMover();

            mCurrentSplinePointMarker = new SplinePointSelectionMarker();

            mSelf = this;
        }
Example #18
0
    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
        };
    }
Example #20
0
 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;
 }
Example #24
0
    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);
    }
Example #25
0
    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));
    }
Example #26
0
    /// <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),
        });
    }
Example #27
0
 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
         );
 }
Example #28
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;
    }
Example #29
0
        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);
        }
Example #30
0
    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);
    }
Example #31
0
 void Awake()
 {
     _instance = this;
     c = GetComponent<Camera>();
     pixelRect = c.pixelRect;
 }
Example #32
0
 void Awake()
 {
     Instance = this;
 }
Example #33
0
 void OnDestroy()
 {
     Instance = null;
 }