*
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1008a0df24ef4ce478220abaa9ff5515
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 247a053c22235ca4baf81d4473c8ee2e
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
@@ -0,0 +1,105 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class CameraMotionController : MonoBehaviour {
|
||||
public GameObject player;
|
||||
public float staticRectangleWidth = 200;
|
||||
public float staticRectangleHeight = 200;
|
||||
public bool drawDebug = true;
|
||||
private Camera camera;
|
||||
private Rect staticRect;
|
||||
public bool SpritePixels = true;
|
||||
public PixelPerfectCamera pixelController;
|
||||
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
camera = gameObject.GetComponent<Camera>();
|
||||
staticRect = new Rect();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void LateUpdate () {
|
||||
UpdateRectangle();
|
||||
MoveCameraToPlayer();
|
||||
}
|
||||
|
||||
void OnLevelWasLoaded(int level) {
|
||||
Debug.LogWarning("Loaded level: " + level);
|
||||
}
|
||||
|
||||
void MoveCameraToPlayer(){
|
||||
var pb = player.GetComponent<SpriteRenderer>().bounds;
|
||||
var playerRect = Tools.BoundsToRect(pb);
|
||||
|
||||
Vector3 offset = Vector3.zero;
|
||||
|
||||
var rightOffset = staticRect.xMax - playerRect.xMax;
|
||||
var leftOffset = staticRect.xMin - playerRect.xMin;
|
||||
|
||||
var topOffset = staticRect.yMax - playerRect.yMax;
|
||||
var bottomOffset = staticRect.yMin - playerRect.yMin;
|
||||
|
||||
if(rightOffset < 0){
|
||||
offset -= Vector3.right * rightOffset;
|
||||
}
|
||||
|
||||
if(leftOffset > 0){
|
||||
offset -= Vector3.right * leftOffset;
|
||||
}
|
||||
|
||||
if(bottomOffset > 0){
|
||||
offset -= Vector3.up * bottomOffset;
|
||||
}
|
||||
|
||||
if(topOffset < 0){
|
||||
offset -= Vector3.up * topOffset;
|
||||
}
|
||||
|
||||
transform.position += offset * Time.deltaTime * 5;
|
||||
|
||||
}
|
||||
|
||||
void UpdateRectangle(){
|
||||
float camUnitHeight = camera.orthographicSize * 2;
|
||||
float camPixelsToUnits = camUnitHeight / camera.pixelHeight;
|
||||
|
||||
|
||||
|
||||
float unitHW = staticRectangleWidth * 0.5f * camPixelsToUnits;
|
||||
float unitHH = staticRectangleHeight * 0.5f * camPixelsToUnits;
|
||||
|
||||
if(SpritePixels && pixelController != null){
|
||||
unitHW *= pixelController.zoom;
|
||||
unitHH *= pixelController.zoom;
|
||||
}
|
||||
|
||||
Vector2 center = transform.position;
|
||||
|
||||
staticRect.x = center.x - unitHW;
|
||||
staticRect.y = center.y - unitHH;
|
||||
staticRect.width = unitHW * 2;
|
||||
staticRect.height = unitHH * 2;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected(){
|
||||
if(staticRect == null){
|
||||
staticRect = new Rect();
|
||||
}
|
||||
if(camera == null){
|
||||
camera = gameObject.GetComponent<Camera>();
|
||||
}
|
||||
UpdateRectangle();
|
||||
if(drawDebug){
|
||||
|
||||
var pb = player.GetComponent<SpriteRenderer>().bounds;
|
||||
var rect = new Rect(pb.min.x, pb.min.y, pb.max.x - pb.min.x, pb.max.y - pb.min.y);
|
||||
//Tools.BeginGui(false);
|
||||
bool i = staticRect.Overlaps(rect);
|
||||
Tools.DrawRectangle(staticRect, i ? new Color(0,1,0,0.3f) : new Color(1,0,0,0.3f));
|
||||
//Tools.EndGui();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e91c551e7ff829349ad26a5c9f92b6ea
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c0f2f7b15fcedf4db1396948cd8a5b8
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 749950ad239c3654e8f5fbf653ddf7c4
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2110c428dd13ee94e820635147e1374e
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ba507ba2918f674f92c64d1e0d00f6a
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dee209359da750a41aad099ad9761004
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26be46f10ce60f543bd72a2b1470c62c
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89175d26136b1744089d9c08f67413bb
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 517b9e85b303d7a428dbf0167ca602fa
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b70bbe54052fd7b4da7f018b375d67fa
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ceb20877cb4ddef4dbef1c9101cffd8c
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21882795a3c135942afbb7501f51fc76
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3f527c1131cdd54c8a7bdfb409ee251
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4dcd18ae8fcf87441b7dc388c7811482
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0eee01ddf557fcb4f86bf56029ab8221
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a456b02b0b5434408ee8091551406c3
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26e06356950130c4c9da00b713ec6690
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e5f2d2c98db83d438726ebfca915f44
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35fd8be7b6bd48e49b34116345e86fd0
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d10bc9dd9b478c4d8b9162226bcc29a
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e018d17c39605cb45acc772d218003e8
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23489dec0f476714fb4b4432d87899f7
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aac71e63902ae6943b1bb3da3c192371
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0470a0c73181614791597b5b1ed7a89
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33ba3c98cc3980a488e40dc6d2d29ac1
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 315112fd2d420f4438daab5929e241be
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae7408343e07eef49931a51d8749c02d
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c3734cc2dfe45a40a4733443304155c
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21786137419eebd48b0ec9af80e6d3ce
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
Reference in New Issue
Block a user