import successful, grid has visuals
cell values and grid lines are displayed. no interaction available yet.
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
------------------- Code Monkey -------------------
|
||||
|
||||
Thank you for downloading the Code Monkey Utilities
|
||||
I hope you find them useful in your projects
|
||||
If you have any questions use the contact form
|
||||
Cheers!
|
||||
|
||||
unitycodemonkey.com
|
||||
--------------------------------------------------
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace CodeMonkey.MonoBehaviours {
|
||||
|
||||
/*
|
||||
* Script to handle Camera Movement and Zoom
|
||||
* Place on Camera GameObject
|
||||
* */
|
||||
public class CameraFollow : MonoBehaviour {
|
||||
|
||||
public static CameraFollow Instance { get; private set; }
|
||||
|
||||
private Camera myCamera;
|
||||
private Func<Vector3> GetCameraFollowPositionFunc;
|
||||
private Func<float> GetCameraZoomFunc;
|
||||
|
||||
public void Setup(Func<Vector3> GetCameraFollowPositionFunc, Func<float> GetCameraZoomFunc, bool teleportToFollowPosition, bool instantZoom) {
|
||||
this.GetCameraFollowPositionFunc = GetCameraFollowPositionFunc;
|
||||
this.GetCameraZoomFunc = GetCameraZoomFunc;
|
||||
|
||||
if (teleportToFollowPosition) {
|
||||
Vector3 cameraFollowPosition = GetCameraFollowPositionFunc();
|
||||
cameraFollowPosition.z = transform.position.z;
|
||||
transform.position = cameraFollowPosition;
|
||||
}
|
||||
|
||||
if (instantZoom) {
|
||||
myCamera.orthographicSize = GetCameraZoomFunc();
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake() {
|
||||
Instance = this;
|
||||
myCamera = transform.GetComponent<Camera>();
|
||||
}
|
||||
|
||||
public void SetCameraFollowPosition(Vector3 cameraFollowPosition) {
|
||||
SetGetCameraFollowPositionFunc(() => cameraFollowPosition);
|
||||
}
|
||||
|
||||
public void SetGetCameraFollowPositionFunc(Func<Vector3> GetCameraFollowPositionFunc) {
|
||||
this.GetCameraFollowPositionFunc = GetCameraFollowPositionFunc;
|
||||
}
|
||||
|
||||
public void SetCameraZoom(float cameraZoom) {
|
||||
SetGetCameraZoomFunc(() => cameraZoom);
|
||||
}
|
||||
|
||||
public void SetGetCameraZoomFunc(Func<float> GetCameraZoomFunc) {
|
||||
this.GetCameraZoomFunc = GetCameraZoomFunc;
|
||||
}
|
||||
|
||||
|
||||
private void Update() {
|
||||
HandleMovement();
|
||||
HandleZoom();
|
||||
}
|
||||
|
||||
private void HandleMovement() {
|
||||
if (GetCameraFollowPositionFunc == null) return;
|
||||
Vector3 cameraFollowPosition = GetCameraFollowPositionFunc();
|
||||
cameraFollowPosition.z = transform.position.z;
|
||||
|
||||
Vector3 cameraMoveDir = (cameraFollowPosition - transform.position).normalized;
|
||||
float distance = Vector3.Distance(cameraFollowPosition, transform.position);
|
||||
float cameraMoveSpeed = 3f;
|
||||
|
||||
if (distance > 0) {
|
||||
Vector3 newCameraPosition = transform.position + cameraMoveDir * distance * cameraMoveSpeed * Time.deltaTime;
|
||||
|
||||
float distanceAfterMoving = Vector3.Distance(newCameraPosition, cameraFollowPosition);
|
||||
|
||||
if (distanceAfterMoving > distance) {
|
||||
// Overshot the target
|
||||
newCameraPosition = cameraFollowPosition;
|
||||
}
|
||||
|
||||
transform.position = newCameraPosition;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleZoom() {
|
||||
if (GetCameraZoomFunc == null) return;
|
||||
float cameraZoom = GetCameraZoomFunc();
|
||||
|
||||
float cameraZoomDifference = cameraZoom - myCamera.orthographicSize;
|
||||
float cameraZoomSpeed = 1f;
|
||||
|
||||
myCamera.orthographicSize += cameraZoomDifference * cameraZoomSpeed * Time.deltaTime;
|
||||
|
||||
if (cameraZoomDifference > 0) {
|
||||
if (myCamera.orthographicSize > cameraZoom) {
|
||||
myCamera.orthographicSize = cameraZoom;
|
||||
}
|
||||
} else {
|
||||
if (myCamera.orthographicSize < cameraZoom) {
|
||||
myCamera.orthographicSize = cameraZoom;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f73a3eab49f30d344a207d7d3d931d98
|
||||
timeCreated: 1527867131
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
------------------- Code Monkey -------------------
|
||||
|
||||
Thank you for downloading the Code Monkey Utilities
|
||||
I hope you find them useful in your projects
|
||||
If you have any questions use the contact form
|
||||
Cheers!
|
||||
|
||||
unitycodemonkey.com
|
||||
--------------------------------------------------
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace CodeMonkey.MonoBehaviours {
|
||||
|
||||
/*
|
||||
* Easy set up for CameraFollow, it will follow the transform with zoom
|
||||
* */
|
||||
public class CameraFollowSetup : MonoBehaviour {
|
||||
|
||||
[SerializeField] private CameraFollow cameraFollow = null;
|
||||
[SerializeField] private Transform followTransform = null;
|
||||
[SerializeField] private float zoom = 50f;
|
||||
|
||||
private void Start() {
|
||||
if (followTransform == null) {
|
||||
Debug.LogError("followTransform is null! Intended?");
|
||||
cameraFollow.Setup(() => Vector3.zero, () => zoom, true, true);
|
||||
} else {
|
||||
cameraFollow.Setup(() => followTransform.position, () => zoom, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 31e947e7eb3216d40b72c592fa6847a3
|
||||
timeCreated: 1527867131
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
------------------- Code Monkey -------------------
|
||||
|
||||
Thank you for downloading the Code Monkey Utilities
|
||||
I hope you find them useful in your projects
|
||||
If you have any questions use the contact form
|
||||
Cheers!
|
||||
|
||||
unitycodemonkey.com
|
||||
--------------------------------------------------
|
||||
*/
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace CodeMonkey.MonoBehaviours {
|
||||
|
||||
/*
|
||||
* Trigger Actions on MonoBehaviour Component events
|
||||
* */
|
||||
public class ComponentActions : MonoBehaviour {
|
||||
|
||||
public Action OnDestroyFunc;
|
||||
public Action OnEnableFunc;
|
||||
public Action OnDisableFunc;
|
||||
public Action OnUpdate;
|
||||
|
||||
private void OnDestroy() {
|
||||
if (OnDestroyFunc != null) OnDestroyFunc();
|
||||
}
|
||||
|
||||
private void OnEnable() {
|
||||
if (OnEnableFunc != null) OnEnableFunc();
|
||||
}
|
||||
|
||||
private void OnDisable() {
|
||||
if (OnDisableFunc != null) OnDisableFunc();
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
if (OnUpdate != null) OnUpdate();
|
||||
}
|
||||
|
||||
|
||||
public static void CreateComponent(Action OnDestroyFunc = null, Action OnEnableFunc = null, Action OnDisableFunc = null, Action OnUpdate = null) {
|
||||
GameObject gameObject = new GameObject("ComponentActions");
|
||||
AddComponent(gameObject, OnDestroyFunc, OnEnableFunc, OnDisableFunc, OnUpdate);
|
||||
}
|
||||
|
||||
public static void AddComponent(GameObject gameObject, Action OnDestroyFunc = null, Action OnEnableFunc = null, Action OnDisableFunc = null, Action OnUpdate = null) {
|
||||
ComponentActions componentFuncs = gameObject.AddComponent<ComponentActions>();
|
||||
componentFuncs.OnDestroyFunc = OnDestroyFunc;
|
||||
componentFuncs.OnEnableFunc = OnEnableFunc;
|
||||
componentFuncs.OnDisableFunc = OnDisableFunc;
|
||||
componentFuncs.OnUpdate = OnUpdate;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb3e855e7fda2944b91078893f9e8fd8
|
||||
timeCreated: 1511794191
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
------------------- Code Monkey -------------------
|
||||
|
||||
Thank you for downloading the Code Monkey Utilities
|
||||
I hope you find them useful in your projects
|
||||
If you have any questions use the contact form
|
||||
Cheers!
|
||||
|
||||
unitycodemonkey.com
|
||||
--------------------------------------------------
|
||||
*/
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace CodeMonkey.MonoBehaviours {
|
||||
|
||||
/*
|
||||
* Automatically sort a Renderer (SpriteRenderer, MeshRenderer) based on his Y position
|
||||
* */
|
||||
public class PositionRendererSorter : MonoBehaviour {
|
||||
|
||||
[SerializeField] private int sortingOrderBase = 5000; // This number should be higher than what any of your sprites will be on the position.y
|
||||
[SerializeField] private int offset = 0;
|
||||
[SerializeField] private bool runOnlyOnce = false;
|
||||
|
||||
private float timer;
|
||||
private float timerMax = .1f;
|
||||
private Renderer myRenderer;
|
||||
|
||||
private void Awake() {
|
||||
myRenderer = gameObject.GetComponent<Renderer>();
|
||||
}
|
||||
|
||||
private void LateUpdate() {
|
||||
timer -= Time.deltaTime;
|
||||
if (timer <= 0f) {
|
||||
timer = timerMax;
|
||||
myRenderer.sortingOrder = (int)(sortingOrderBase - transform.position.y - offset);
|
||||
if (runOnlyOnce) {
|
||||
Destroy(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetOffset(int offset) {
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b330b302c69005c4f98a928f7d71b877
|
||||
timeCreated: 1526502963
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user