Insanely huge initial commit

This commit is contained in:
2026-02-21 16:40:15 -08:00
parent 208d626100
commit f74c547a13
33825 changed files with 5213498 additions and 0 deletions

View File

@@ -0,0 +1,236 @@
using System;
using UnityEngine;
namespace Com.LuisPedroFonseca.ProCamera2D
{
public abstract class BasePC2D : MonoBehaviour, ISerializationCallbackReceiver
{
public ProCamera2D ProCamera2D
{
get
{
if (_pc2D != null) return _pc2D;
_pc2D = GetComponent<ProCamera2D>();
if (_pc2D == null && Camera.main != null)
_pc2D = Camera.main.GetComponent<ProCamera2D>();
if (_pc2D == null)
_pc2D = FindObjectOfType<ProCamera2D>();
#if UNITY_EDITOR
if (!Application.isPlaying && _pc2D != null && UnityEditor.SceneManagement.EditorSceneManager.preventCrossSceneReferences && _pc2D.gameObject.scene != gameObject.scene)
{
Debug.LogWarning("ProCamera2D is in a different scene. Cross scene references are not supported during edit mode but everything will work correctly during play. Unfortunately the cross scene reference warnings are unavoidable at the moment.");
}
#endif
return _pc2D;
}
set { _pc2D = value; }
}
[SerializeField]
private ProCamera2D _pc2D;
protected Func<Vector3, float> Vector3H;
protected Func<Vector3, float> Vector3V;
protected Func<Vector3, float> Vector3D;
protected Func<float, float, Vector3> VectorHV;
protected Func<float, float, float, Vector3> VectorHVD;
protected Transform _transform;
bool _enabled;
[SerializeField, HideInInspector] private MovementAxis _serializedAxis;
protected virtual void Awake()
{
_transform = transform;
if(enabled)
Enable();
ResetAxisFunctions();
}
protected virtual void OnEnable()
{
Enable();
}
protected virtual void OnDisable()
{
Disable();
}
protected virtual void OnDestroy()
{
Disable();
}
/// <summary>Called when the method Reset is called on the Core. Use it to reset an extension.</summary>
public virtual void OnReset()
{
}
void Enable()
{
if (_enabled || _pc2D == null)
return;
_enabled = true;
_pc2D.OnReset += OnReset;
}
void Disable()
{
if (_pc2D != null && _enabled)
{
_enabled = false;
_pc2D.OnReset -= OnReset;
}
}
void ResetAxisFunctions()
{
if (Vector3H != null || ProCamera2D == null)
return;
switch (_pc2D.Axis)
{
case MovementAxis.XY:
Vector3H = vector => vector.x;
Vector3V = vector => vector.y;
Vector3D = vector => vector.z;
VectorHV = (h, v) => new Vector3(h, v, 0);
VectorHVD = (h, v, d) => new Vector3(h, v, d);
break;
case MovementAxis.XZ:
Vector3H = vector => vector.x;
Vector3V = vector => vector.z;
Vector3D = vector => vector.y;
VectorHV = (h, v) => new Vector3(h, 0, v);
VectorHVD = (h, v, d) => new Vector3(h, d, v);
break;
case MovementAxis.YZ:
Vector3H = vector => vector.z;
Vector3V = vector => vector.y;
Vector3D = vector => vector.x;
VectorHV = (h, v) => new Vector3(0, v, h);
VectorHVD = (h, v, d) => new Vector3(d, v, h);
break;
}
}
#if UNITY_EDITOR
int _drawGizmosCounter;
void OnDrawGizmos()
{
if (!enabled)
return;
if (_pc2D == null && Camera.main != null)
_pc2D = Camera.main.GetComponent<ProCamera2D>();
if (_pc2D == null)
return;
// Don't draw gizmos on other cameras
if (Camera.current != _pc2D.GameCamera &&
((UnityEditor.SceneView.lastActiveSceneView != null && Camera.current != UnityEditor.SceneView.lastActiveSceneView.camera) ||
(UnityEditor.SceneView.lastActiveSceneView == null)))
return;
ResetAxisFunctions();
// HACK to prevent Unity bug on startup: http://forum.unity3d.com/threads/screen-position-out-of-view-frustum.9918/
_drawGizmosCounter++;
if (_drawGizmosCounter < 5 && UnityEditor.EditorApplication.timeSinceStartup < 60f)
return;
DrawGizmos();
}
void OnDrawGizmosSelected()
{
if (!enabled)
return;
if (_pc2D == null && Camera.main != null)
_pc2D = Camera.main.GetComponent<ProCamera2D>();
if (_pc2D == null)
return;
// Don't draw gizmos on other cameras
if (Camera.current != _pc2D.GameCamera &&
((UnityEditor.SceneView.lastActiveSceneView != null && Camera.current != UnityEditor.SceneView.lastActiveSceneView.camera) ||
(UnityEditor.SceneView.lastActiveSceneView == null)))
return;
ResetAxisFunctions();
// HACK to prevent Unity bug on startup: http://forum.unity3d.com/threads/screen-position-out-of-view-frustum.9918/
_drawGizmosCounter++;
if (_drawGizmosCounter < 5 && UnityEditor.EditorApplication.timeSinceStartup < 60f)
return;
DrawGizmosSelected();
}
protected virtual void DrawGizmos()
{
}
protected virtual void DrawGizmosSelected()
{
}
#endif
#region ISerializationCallbackReceiver
public void OnBeforeSerialize()
{
if (ProCamera2D != null)
{
_serializedAxis = ProCamera2D.Axis;
}
}
public void OnAfterDeserialize()
{
switch (_serializedAxis)
{
case MovementAxis.XY:
Vector3H = vector => vector.x;
Vector3V = vector => vector.y;
Vector3D = vector => vector.z;
VectorHV = (h, v) => new Vector3(h, v, 0);
VectorHVD = (h, v, d) => new Vector3(h, v, d);
break;
case MovementAxis.XZ:
Vector3H = vector => vector.x;
Vector3V = vector => vector.z;
Vector3D = vector => vector.y;
VectorHV = (h, v) => new Vector3(h, 0, v);
VectorHVD = (h, v, d) => new Vector3(h, d, v);
break;
case MovementAxis.YZ:
Vector3H = vector => vector.z;
Vector3V = vector => vector.y;
Vector3D = vector => vector.x;
VectorHV = (h, v) => new Vector3(0, v, h);
VectorHVD = (h, v, d) => new Vector3(d, v, h);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
#endregion
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4eeae9fa8562d4f4eb938bab965d71ff
timeCreated: 1453709387
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,230 @@
using System;
using System.Collections;
using UnityEngine;
namespace Com.LuisPedroFonseca.ProCamera2D
{
abstract public class BaseTrigger : BasePC2D
{
public Action OnEnteredTrigger;
public Action OnExitedTrigger;
[TooltipAttribute("Every X seconds detect collision. Smaller intervals are more precise but also require more processing.")]
public float UpdateInterval = .1f;
public TriggerShape TriggerShape;
[TooltipAttribute("If enabled, use the targets mid point to know when inside/outside the trigger.")]
public bool UseTargetsMidPoint = true;
[TooltipAttribute("If UseTargetsMidPoint is disabled, use this transform to know when inside/outside the trigger.")]
public Transform TriggerTarget;
protected float _exclusiveInfluencePercentage;
Coroutine _testTriggerRoutine;
protected bool _insideTrigger;
protected Vector2 _vectorFromPointToCenter;
protected int _instanceID;
bool _triggerEnabled;
protected override void Awake()
{
base.Awake();
if (ProCamera2D == null)
return;
_instanceID = GetInstanceID();
// Small random time offset to avoid having all the triggers calculatations on the same frame
UpdateInterval += UnityEngine.Random.Range(-.02f, .02f);
// Start update routine
Toggle(true);
}
override protected void OnEnable()
{
base.OnEnable();
if(ProCamera2D == null)
return;
if (_triggerEnabled)
Toggle(true);
}
override protected void OnDisable()
{
base.OnDisable();
_testTriggerRoutine = null;
}
/// <summary>Manually enable or disable the trigger</summary>
/// <param name="value">If true it will enable the trigger. If false it will disable it.</param>
public void Toggle(bool value)
{
if (value)
{
if (_testTriggerRoutine == null)
_testTriggerRoutine = StartCoroutine(TestTriggerRoutine());
_triggerEnabled = true;
}
else
{
if (_testTriggerRoutine != null)
{
StopCoroutine(_testTriggerRoutine);
_testTriggerRoutine = null;
}
if (_insideTrigger)
ExitedTrigger();
_triggerEnabled = false;
}
}
/// <summary>Manually force the trigger to test if the target(s) is inside it</summary>
public void TestTrigger()
{
var triggerPos = ProCamera2D.TargetsMidPoint;
if (!UseTargetsMidPoint && TriggerTarget != null)
triggerPos = TriggerTarget.position;
if (TriggerShape == TriggerShape.RECTANGLE &&
Utils.IsInsideRectangle(
Vector3H(_transform.position),
Vector3V(_transform.position),
Vector3H(_transform.localScale),
Vector3V(_transform.localScale),
Vector3H(triggerPos),
Vector3V(triggerPos)))
{
if (!_insideTrigger)
EnteredTrigger();
}
else if (TriggerShape == TriggerShape.CIRCLE &&
Utils.IsInsideCircle(
Vector3H(_transform.position),
Vector3V(_transform.position),
(Vector3H(_transform.localScale) + Vector3V(_transform.localScale)) * .25f,
Vector3H(triggerPos),
Vector3V(triggerPos)))
{
if (!_insideTrigger)
EnteredTrigger();
}
else
{
if (_insideTrigger)
ExitedTrigger();
}
}
protected virtual void EnteredTrigger()
{
_insideTrigger = true;
if (OnEnteredTrigger != null)
OnEnteredTrigger();
}
protected virtual void ExitedTrigger()
{
_insideTrigger = false;
if (OnExitedTrigger != null)
OnExitedTrigger();
}
IEnumerator TestTriggerRoutine()
{
yield return new WaitForEndOfFrame();
var waitForSeconds = new WaitForSeconds(UpdateInterval);
var waitForSecondsRealtime = new WaitForSecondsRealtime(UpdateInterval);
while (true)
{
TestTrigger();
if(ProCamera2D.IgnoreTimeScale)
yield return waitForSecondsRealtime;
else
yield return waitForSeconds;
}
}
protected float GetDistanceToCenterPercentage(Vector2 point)
{
_vectorFromPointToCenter = point - new Vector2(Vector3H(_transform.position), Vector3V(_transform.position));
if (TriggerShape == TriggerShape.RECTANGLE)
{
var distancePercentageH = Vector3H(_vectorFromPointToCenter) / (Vector3H(_transform.localScale) * .5f);
var distancePercentageV = Vector3V(_vectorFromPointToCenter) / (Vector3V(_transform.localScale) * .5f);
var distancePercentage = (Mathf.Max(Mathf.Abs(distancePercentageH), Mathf.Abs(distancePercentageV))).Remap(_exclusiveInfluencePercentage, 1, 0, 1);
return distancePercentage;
}
else
{
var distancePercentage = (_vectorFromPointToCenter.magnitude / ((Vector3H(_transform.localScale) + Vector3V(_transform.localScale)) * .25f)).Remap(_exclusiveInfluencePercentage, 1, 0, 1);
return distancePercentage;
}
}
#if UNITY_EDITOR
override protected void DrawGizmos()
{
float cameraDepthOffset = Vector3D(ProCamera2D.transform.localPosition) + Mathf.Abs(Vector3D(ProCamera2D.transform.localPosition)) * Vector3D(ProCamera2D.transform.forward);
var cameraCenter = VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset);
Gizmos.color = EditorPrefsX.GetColor(PrefsData.TriggerShapeColorKey, PrefsData.TriggerShapeColorValue);
if (TriggerShape == TriggerShape.RECTANGLE)
{
Gizmos.DrawWireCube(cameraCenter, VectorHVD(Vector3H(transform.localScale), Vector3V(transform.localScale), 0f));
if (_exclusiveInfluencePercentage > 0)
Gizmos.DrawWireCube(cameraCenter, VectorHVD(Vector3H(transform.localScale) * _exclusiveInfluencePercentage, Vector3V(transform.localScale) * _exclusiveInfluencePercentage, 0f));
}
else
{
var axis = Vector3.zero;
switch (ProCamera2D.Axis)
{
case MovementAxis.XY:
axis = new Vector3(1f, 1f, 0f);
break;
case MovementAxis.XZ:
axis = new Vector3(1f, 0f, 1f);
break;
case MovementAxis.YZ:
axis = new Vector3(0f, 1f, 1f);
break;
}
Gizmos.matrix = Matrix4x4.TRS(cameraCenter, Quaternion.identity, axis);
Gizmos.DrawWireSphere(Vector3.zero, ((Vector3H(transform.localScale) + Vector3V(transform.localScale)) * .25f));
if (_exclusiveInfluencePercentage > 0)
Gizmos.DrawWireSphere(Vector3.zero, ((Vector3H(transform.localScale) + Vector3V(transform.localScale)) * .25f) * _exclusiveInfluencePercentage);
Gizmos.matrix = Matrix4x4.identity;
}
}
#endif
}
public enum TriggerShape
{
CIRCLE,
RECTANGLE
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b36ebbbf1bc7e4c5e8cbd8a2b01ac67d
timeCreated: 1453709387
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,372 @@
using UnityEngine;
using System;
using System.Collections;
namespace Com.LuisPedroFonseca.ProCamera2D
{
public class BoundariesAnimator
{
public Action OnTransitionStarted;
public Action OnTransitionFinished;
public bool UseTopBoundary;
public float TopBoundary;
public bool UseBottomBoundary;
public float BottomBoundary;
public bool UseLeftBoundary;
public float LeftBoundary;
public bool UseRightBoundary;
public float RightBoundary;
public float TransitionDuration = 1f;
public EaseType TransitionEaseType;
ProCamera2D ProCamera2D;
ProCamera2DNumericBoundaries NumericBoundaries;
Func<Vector3, float> Vector3H;
Func<Vector3, float> Vector3V;
public BoundariesAnimator(ProCamera2D proCamera2D, ProCamera2DNumericBoundaries numericBoundaries)
{
ProCamera2D = proCamera2D;
NumericBoundaries = numericBoundaries;
switch (ProCamera2D.Axis)
{
case MovementAxis.XY:
Vector3H = vector => vector.x;
Vector3V = vector => vector.y;
break;
case MovementAxis.XZ:
Vector3H = vector => vector.x;
Vector3V = vector => vector.z;
break;
case MovementAxis.YZ:
Vector3H = vector => vector.z;
Vector3V = vector => vector.y;
break;
}
}
public int GetAnimsCount()
{
var animsCount = 0;
if (UseLeftBoundary)
animsCount++;
else if (!UseLeftBoundary && NumericBoundaries.UseLeftBoundary && UseRightBoundary && RightBoundary < NumericBoundaries.TargetLeftBoundary)
animsCount++;
if (UseRightBoundary)
animsCount++;
else if (!UseRightBoundary && NumericBoundaries.UseRightBoundary && UseLeftBoundary && LeftBoundary > NumericBoundaries.TargetRightBoundary)
animsCount++;
if (UseTopBoundary)
animsCount++;
else if (!UseTopBoundary && NumericBoundaries.UseTopBoundary && UseBottomBoundary && BottomBoundary > NumericBoundaries.TargetTopBoundary)
animsCount++;
if (UseBottomBoundary)
animsCount++;
else if (!UseBottomBoundary && NumericBoundaries.UseBottomBoundary && UseTopBoundary && TopBoundary < NumericBoundaries.TargetBottomBoundary)
animsCount++;
return animsCount;
}
public void Transition()
{
if (!NumericBoundaries.HasFiredTransitionStarted && OnTransitionStarted != null)
{
NumericBoundaries.HasFiredTransitionStarted = true;
OnTransitionStarted();
}
NumericBoundaries.HasFiredTransitionFinished = false;
NumericBoundaries.UseNumericBoundaries = true;
// Animate boundaries
if (UseLeftBoundary)
{
NumericBoundaries.UseLeftBoundary = true;
if (NumericBoundaries.LeftBoundaryAnimRoutine != null)
NumericBoundaries.StopCoroutine(NumericBoundaries.LeftBoundaryAnimRoutine);
NumericBoundaries.LeftBoundaryAnimRoutine = NumericBoundaries.StartCoroutine(LeftTransitionRoutine(TransitionDuration));
}
else if (!UseLeftBoundary && NumericBoundaries.UseLeftBoundary && UseRightBoundary && RightBoundary < NumericBoundaries.TargetLeftBoundary)
{
NumericBoundaries.UseLeftBoundary = true;
UseLeftBoundary = true;
LeftBoundary = RightBoundary - ProCamera2D.ScreenSizeInWorldCoordinates.x * 100f;
if (NumericBoundaries.LeftBoundaryAnimRoutine != null)
NumericBoundaries.StopCoroutine(NumericBoundaries.LeftBoundaryAnimRoutine);
NumericBoundaries.LeftBoundaryAnimRoutine = NumericBoundaries.StartCoroutine(LeftTransitionRoutine(TransitionDuration, true));
}
else if (!UseLeftBoundary)
{
NumericBoundaries.UseLeftBoundary = false;
}
if (UseRightBoundary)
{
NumericBoundaries.UseRightBoundary = true;
if (NumericBoundaries.RightBoundaryAnimRoutine != null)
NumericBoundaries.StopCoroutine(NumericBoundaries.RightBoundaryAnimRoutine);
NumericBoundaries.RightBoundaryAnimRoutine = NumericBoundaries.StartCoroutine(RightTransitionRoutine(TransitionDuration));
}
else if (!UseRightBoundary && NumericBoundaries.UseRightBoundary && UseLeftBoundary && LeftBoundary > NumericBoundaries.TargetRightBoundary)
{
NumericBoundaries.UseRightBoundary = true;
UseRightBoundary = true;
RightBoundary = LeftBoundary + ProCamera2D.ScreenSizeInWorldCoordinates.x * 100f;
if (NumericBoundaries.RightBoundaryAnimRoutine != null)
NumericBoundaries.StopCoroutine(NumericBoundaries.RightBoundaryAnimRoutine);
NumericBoundaries.RightBoundaryAnimRoutine = NumericBoundaries.StartCoroutine(RightTransitionRoutine(TransitionDuration, true));
}
else if (!UseRightBoundary)
{
NumericBoundaries.UseRightBoundary = false;
}
if (UseTopBoundary)
{
NumericBoundaries.UseTopBoundary = true;
if (NumericBoundaries.TopBoundaryAnimRoutine != null)
NumericBoundaries.StopCoroutine(NumericBoundaries.TopBoundaryAnimRoutine);
NumericBoundaries.TopBoundaryAnimRoutine = NumericBoundaries.StartCoroutine(TopTransitionRoutine(TransitionDuration));
}
else if (!UseTopBoundary && NumericBoundaries.UseTopBoundary && UseBottomBoundary && BottomBoundary > NumericBoundaries.TargetTopBoundary)
{
NumericBoundaries.UseTopBoundary = true;
UseTopBoundary = true;
TopBoundary = BottomBoundary + ProCamera2D.ScreenSizeInWorldCoordinates.y * 100f;
if (NumericBoundaries.TopBoundaryAnimRoutine != null)
NumericBoundaries.StopCoroutine(NumericBoundaries.TopBoundaryAnimRoutine);
NumericBoundaries.TopBoundaryAnimRoutine = NumericBoundaries.StartCoroutine(TopTransitionRoutine(TransitionDuration, true));
}
else if (!UseTopBoundary)
{
NumericBoundaries.UseTopBoundary = false;
}
if (UseBottomBoundary)
{
NumericBoundaries.UseBottomBoundary = true;
if (NumericBoundaries.BottomBoundaryAnimRoutine != null)
NumericBoundaries.StopCoroutine(NumericBoundaries.BottomBoundaryAnimRoutine);
NumericBoundaries.BottomBoundaryAnimRoutine = NumericBoundaries.StartCoroutine(BottomTransitionRoutine(TransitionDuration));
}
else if (!UseBottomBoundary && NumericBoundaries.UseBottomBoundary && UseTopBoundary && TopBoundary < NumericBoundaries.TargetBottomBoundary)
{
NumericBoundaries.UseBottomBoundary = true;
UseBottomBoundary = true;
BottomBoundary = TopBoundary - ProCamera2D.ScreenSizeInWorldCoordinates.y * 100f;
if (NumericBoundaries.BottomBoundaryAnimRoutine != null)
NumericBoundaries.StopCoroutine(NumericBoundaries.BottomBoundaryAnimRoutine);
NumericBoundaries.BottomBoundaryAnimRoutine = NumericBoundaries.StartCoroutine(BottomTransitionRoutine(TransitionDuration, true));
}
else if (!UseBottomBoundary)
{
NumericBoundaries.UseBottomBoundary = false;
}
}
IEnumerator LeftTransitionRoutine(float duration, bool turnOffBoundaryAfterwards = false)
{
var initialLeftBoundary = Vector3H(ProCamera2D.LocalPosition) - ProCamera2D.ScreenSizeInWorldCoordinates.x / 2;
NumericBoundaries.TargetLeftBoundary = LeftBoundary;
var t = 0f;
while (t <= 1.0f)
{
t += ProCamera2D.DeltaTime / duration;
// Move left
if (UseLeftBoundary && UseRightBoundary && LeftBoundary < initialLeftBoundary)
{
NumericBoundaries.LeftBoundary = LeftBoundary;
}
// Move right
else if (UseLeftBoundary)
{
NumericBoundaries.LeftBoundary = Utils.EaseFromTo(initialLeftBoundary, LeftBoundary, t, TransitionEaseType);
var currentCamLeftEdge = Vector3H(ProCamera2D.LocalPosition) - ProCamera2D.ScreenSizeInWorldCoordinates.x / 2;
if (currentCamLeftEdge < NumericBoundaries.TargetLeftBoundary &&
NumericBoundaries.LeftBoundary < currentCamLeftEdge)
NumericBoundaries.LeftBoundary = currentCamLeftEdge;
}
yield return ProCamera2D.GetYield();
}
if (turnOffBoundaryAfterwards)
{
NumericBoundaries.UseLeftBoundary = false;
UseLeftBoundary = false;
}
if (!NumericBoundaries.HasFiredTransitionFinished && OnTransitionFinished != null)
{
NumericBoundaries.HasFiredTransitionStarted = false;
NumericBoundaries.HasFiredTransitionFinished = true;
OnTransitionFinished();
}
}
IEnumerator RightTransitionRoutine(float duration, bool turnOffBoundaryAfterwards = false)
{
var initialRightBoundary = Vector3H(ProCamera2D.LocalPosition) + ProCamera2D.ScreenSizeInWorldCoordinates.x / 2;
NumericBoundaries.TargetRightBoundary = RightBoundary;
var t = 0f;
while (t <= 1.0f)
{
t += ProCamera2D.DeltaTime / duration;
// Move right
if (UseRightBoundary && UseLeftBoundary && RightBoundary > initialRightBoundary)
{
NumericBoundaries.RightBoundary = RightBoundary;
}
// Move left
else if (UseRightBoundary)
{
NumericBoundaries.RightBoundary = Utils.EaseFromTo(initialRightBoundary, RightBoundary, t, TransitionEaseType);
var currentCamRightEdge = Vector3H(ProCamera2D.LocalPosition) + ProCamera2D.ScreenSizeInWorldCoordinates.x / 2;
if (currentCamRightEdge > NumericBoundaries.TargetRightBoundary &&
NumericBoundaries.RightBoundary > currentCamRightEdge)
NumericBoundaries.RightBoundary = currentCamRightEdge;
}
yield return ProCamera2D.GetYield();
}
if (turnOffBoundaryAfterwards)
{
NumericBoundaries.UseRightBoundary = false;
UseRightBoundary = false;
}
if (!NumericBoundaries.HasFiredTransitionFinished && OnTransitionFinished != null)
{
NumericBoundaries.HasFiredTransitionStarted = false;
NumericBoundaries.HasFiredTransitionFinished = true;
OnTransitionFinished();
}
}
IEnumerator TopTransitionRoutine(float duration, bool turnOffBoundaryAfterwards = false)
{
var initialTopBoundary = Vector3V(ProCamera2D.LocalPosition) + ProCamera2D.ScreenSizeInWorldCoordinates.y / 2;
NumericBoundaries.TargetTopBoundary = TopBoundary;
var t = 0f;
while (t <= 1.0f)
{
t += ProCamera2D.DeltaTime / duration;
// Move up
if (UseTopBoundary && UseBottomBoundary && TopBoundary > initialTopBoundary)
{
NumericBoundaries.TopBoundary = TopBoundary;
}
// Move down
else if (UseTopBoundary)
{
NumericBoundaries.TopBoundary = Utils.EaseFromTo(initialTopBoundary, TopBoundary, t, TransitionEaseType);
var currentCamTopEdge = Vector3V(ProCamera2D.LocalPosition) + ProCamera2D.ScreenSizeInWorldCoordinates.y / 2;
if (currentCamTopEdge > NumericBoundaries.TargetTopBoundary &&
NumericBoundaries.TopBoundary > currentCamTopEdge)
NumericBoundaries.TopBoundary = currentCamTopEdge;
}
yield return ProCamera2D.GetYield();
}
if (turnOffBoundaryAfterwards)
{
NumericBoundaries.UseTopBoundary = false;
UseTopBoundary = false;
}
if (!NumericBoundaries.HasFiredTransitionFinished && OnTransitionFinished != null)
{
NumericBoundaries.HasFiredTransitionStarted = false;
NumericBoundaries.HasFiredTransitionFinished = true;
OnTransitionFinished();
}
}
IEnumerator BottomTransitionRoutine(float duration, bool turnOffBoundaryAfterwards = false)
{
var initialBottomBoundary = Vector3V(ProCamera2D.LocalPosition) - ProCamera2D.ScreenSizeInWorldCoordinates.y / 2;
NumericBoundaries.TargetBottomBoundary = BottomBoundary;
var t = 0f;
while (t <= 1.0f)
{
t += ProCamera2D.DeltaTime / duration;
// Move down
if (UseBottomBoundary && UseTopBoundary && BottomBoundary < initialBottomBoundary)
{
NumericBoundaries.BottomBoundary = BottomBoundary;
}
// Move up
else if (UseBottomBoundary)
{
NumericBoundaries.BottomBoundary = Utils.EaseFromTo(initialBottomBoundary, BottomBoundary, t, TransitionEaseType);
var currentCamBottomEdge = Vector3V(ProCamera2D.LocalPosition) - ProCamera2D.ScreenSizeInWorldCoordinates.y / 2;
if (currentCamBottomEdge < NumericBoundaries.TargetBottomBoundary &&
NumericBoundaries.BottomBoundary < currentCamBottomEdge)
NumericBoundaries.BottomBoundary = currentCamBottomEdge;
}
yield return ProCamera2D.GetYield();
}
if (turnOffBoundaryAfterwards)
{
NumericBoundaries.UseBottomBoundary = false;
UseBottomBoundary = false;
}
if (!NumericBoundaries.HasFiredTransitionFinished && OnTransitionFinished != null)
{
NumericBoundaries.HasFiredTransitionStarted = false;
NumericBoundaries.HasFiredTransitionFinished = true;
OnTransitionFinished();
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 189a6e28bac9643759ef1b01a4328d01
timeCreated: 1429281456
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,40 @@
using System;
using UnityEngine;
namespace Com.LuisPedroFonseca.ProCamera2D
{
[Serializable]
public class CameraTarget
{
public Transform TargetTransform;
public float TargetInfluence
{
set
{
TargetInfluenceH = value;
TargetInfluenceV = value;
}
}
[RangeAttribute(0f, 1f)]
public float TargetInfluenceH = 1f;
[RangeAttribute(0f, 1f)]
public float TargetInfluenceV = 1f;
public Vector2 TargetOffset;
public Vector3 TargetPosition
{
get
{
if (TargetTransform != null)
return _targetPosition = TargetTransform.position;
else
return _targetPosition;
}
}
Vector3 _targetPosition;
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 3e0fcaf74434343259050f5f11d998f0
timeCreated: 1432593543
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
using System.Collections.Generic;
using UnityEngine;
namespace Com.LuisPedroFonseca.ProCamera2D
{
[System.Serializable]
[CreateAssetMenu(menuName = "ProCamera2D/Constant Shake Preset")]
public class ConstantShakePreset : ScriptableObject
{
public float Intensity = .3f;
public List<ConstantShakeLayer> Layers;
}
[System.Serializable]
public struct ConstantShakeLayer
{
[MinMaxSlider(0.001f, 10f)]
public Vector2 Frequency;
[Range(0f, 100f)]
public float AmplitudeHorizontal;
[Range(0f, 100f)]
public float AmplitudeVertical;
[Range(0f, 100f)]
public float AmplitudeDepth;
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 2b203a55d908247b5a828b0c77fca2c1
timeCreated: 1487263380
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
namespace Com.LuisPedroFonseca.ProCamera2D
{
public enum MovementAxis
{
XY,
XZ,
YZ
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 2156a7911234749219b1562c116fbae8
timeCreated: 1432599265
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
namespace Com.LuisPedroFonseca.ProCamera2D
{
public enum UpdateType
{
LateUpdate,
FixedUpdate,
ManualUpdate
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 40bf6ecc65d754092959189e66e01906
timeCreated: 1432599301
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
using UnityEngine;
namespace Com.LuisPedroFonseca.ProCamera2D
{
public interface IPositionDeltaChanger
{
Vector3 AdjustDelta(float deltaTime, Vector3 originalDelta);
int PDCOrder { get; set;}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 115d44f578d1f4b0895ea97e52aaff1c
timeCreated: 1454609120
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
using UnityEngine;
namespace Com.LuisPedroFonseca.ProCamera2D
{
public interface IPositionOverrider
{
Vector3 OverridePosition(float deltaTime, Vector3 originalPosition);
int POOrder { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b7f0378f234734fe1bcee70739d44960
timeCreated: 1454652912
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
using UnityEngine;
namespace Com.LuisPedroFonseca.ProCamera2D
{
public interface IPostMover
{
void PostMove(float deltaTime);
int PMOrder { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: bfb0d95b2946d4048b4a72b3c5c88a4d
timeCreated: 1455021848
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
using UnityEngine;
namespace Com.LuisPedroFonseca.ProCamera2D
{
public interface IPreMover
{
void PreMove(float deltaTime);
int PrMOrder { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 32bf46b1206e344308f4d7b271c6676c
timeCreated: 1455023700
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
namespace Com.LuisPedroFonseca.ProCamera2D
{
public interface ISizeDeltaChanger
{
float AdjustSize(float deltaTime, float originalDelta);
int SDCOrder { get; set;}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 434498afe170f4dd0bb5bab7925edfbc
timeCreated: 1454660357
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
namespace Com.LuisPedroFonseca.ProCamera2D
{
public interface ISizeOverrider
{
float OverrideSize(float deltaTime, float originalSize);
int SOOrder { get; set;}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 2fa9ca6042aa143529e3cb816d3b4cae
timeCreated: 1454659084
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,246 @@
// KDTree.cs - A Stark, September 2009.
// This class implements a data structure that stores a list of points in space.
// A common task in game programming is to take a supplied point and discover which
// of a stored set of points is nearest to it. For example, in path-plotting, it is often
// useful to know which waypoint is nearest to the player's current
// position. The kd-tree allows this "nearest neighbour" search to be carried out quickly,
// or at least much more quickly than a simple linear search through the list.
// At present, the class only allows for construction (using the MakeFromPoints static method)
// and nearest-neighbour searching (using FindNearest). More exotic kd-trees are possible, and
// this class may be extended in the future if there seems to be a need.
// The nearest-neighbour search returns an integer index - it is assumed that the original
// array of points is available for the lifetime of the tree, and the index refers to that
// array.
using UnityEngine;
using System.Collections;
namespace Com.LuisPedroFonseca.ProCamera2D
{
public class KDTree
{
public KDTree[] lr;
public Vector3 pivot;
public int pivotIndex;
public int axis;
// Change this value to 2 if you only need two-dimensional X,Y points. The search will
// be quicker in two dimensions.
const int numDims = 3;
public KDTree()
{
lr = new KDTree[2];
}
// Make a new tree from a list of points.
public static KDTree MakeFromPoints(params Vector3[] points)
{
int[] indices = Iota(points.Length);
return MakeFromPointsInner(0, 0, points.Length - 1, points, indices);
}
// Recursively build a tree by separating points at plane boundaries.
static KDTree MakeFromPointsInner(
int depth,
int stIndex, int enIndex,
Vector3[] points,
int[] inds
)
{
KDTree root = new KDTree();
root.axis = depth % numDims;
int splitPoint = FindPivotIndex(points, inds, stIndex, enIndex, root.axis);
root.pivotIndex = inds[splitPoint];
root.pivot = points[root.pivotIndex];
int leftEndIndex = splitPoint - 1;
if (leftEndIndex >= stIndex)
{
root.lr[0] = MakeFromPointsInner(depth + 1, stIndex, leftEndIndex, points, inds);
}
int rightStartIndex = splitPoint + 1;
if (rightStartIndex <= enIndex)
{
root.lr[1] = MakeFromPointsInner(depth + 1, rightStartIndex, enIndex, points, inds);
}
return root;
}
static void SwapElements(int[] arr, int a, int b)
{
int temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
}
// Simple "median of three" heuristic to find a reasonable splitting plane.
static int FindSplitPoint(Vector3[] points, int[] inds, int stIndex, int enIndex, int axis)
{
float a = points[inds[stIndex]][axis];
float b = points[inds[enIndex]][axis];
int midIndex = (stIndex + enIndex) / 2;
float m = points[inds[midIndex]][axis];
if (a > b)
{
if (m > a)
{
return stIndex;
}
if (b > m)
{
return enIndex;
}
return midIndex;
}
else
{
if (a > m)
{
return stIndex;
}
if (m > b)
{
return enIndex;
}
return midIndex;
}
}
// Find a new pivot index from the range by splitting the points that fall either side
// of its plane.
public static int FindPivotIndex(Vector3[] points, int[] inds, int stIndex, int enIndex, int axis)
{
int splitPoint = FindSplitPoint(points, inds, stIndex, enIndex, axis);
// int splitPoint = Random.Range(stIndex, enIndex);
Vector3 pivot = points[inds[splitPoint]];
SwapElements(inds, stIndex, splitPoint);
int currPt = stIndex + 1;
int endPt = enIndex;
while (currPt <= endPt)
{
Vector3 curr = points[inds[currPt]];
if ((curr[axis] > pivot[axis]))
{
SwapElements(inds, currPt, endPt);
endPt--;
}
else
{
SwapElements(inds, currPt - 1, currPt);
currPt++;
}
}
return currPt - 1;
}
public static int[] Iota(int num)
{
int[] result = new int[num];
for (int i = 0; i < num; i++)
{
result[i] = i;
}
return result;
}
// Find the nearest point in the set to the supplied point.
public int FindNearest(Vector3 pt)
{
float bestSqDist = 1000000000f;
int bestIndex = -1;
Search(pt, ref bestSqDist, ref bestIndex);
return bestIndex;
}
// Recursively search the tree.
void Search(Vector3 pt, ref float bestSqSoFar, ref int bestIndex)
{
float mySqDist = (pivot - pt).sqrMagnitude;
if (mySqDist < bestSqSoFar)
{
bestSqSoFar = mySqDist;
bestIndex = pivotIndex;
}
float planeDist = pt[axis] - pivot[axis]; //DistFromSplitPlane(pt, pivot, axis);
int selector = planeDist <= 0 ? 0 : 1;
if (lr[selector] != null)
{
lr[selector].Search(pt, ref bestSqSoFar, ref bestIndex);
}
selector = (selector + 1) % 2;
float sqPlaneDist = planeDist * planeDist;
if ((lr[selector] != null) && (bestSqSoFar > sqPlaneDist))
{
lr[selector].Search(pt, ref bestSqSoFar, ref bestIndex);
}
}
// Get a point's distance from an axis-aligned plane.
float DistFromSplitPlane(Vector3 pt, Vector3 planePt, int axis)
{
return pt[axis] - planePt[axis];
}
// Simple output of tree structure - mainly useful for getting a rough
// idea of how deep the tree is (and therefore how well the splitting
// heuristic is performing).
public string Dump(int level)
{
string result = pivotIndex.ToString().PadLeft(level) + "\n";
if (lr[0] != null)
{
result += lr[0].Dump(level + 2);
}
if (lr[1] != null)
{
result += lr[1].Dump(level + 2);
}
return result;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d9a1cf7ede4d947249edafbcf3c2bbed
timeCreated: 1447935924
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,247 @@
using System;
using UnityEngine;
namespace Com.LuisPedroFonseca.ProCamera2D
{
public struct RaycastOrigins
{
public Vector3 TopRight;
public Vector3 TopLeft;
public Vector3 BottomRight;
public Vector3 BottomLeft;
}
public struct CameraCollisionState
{
public bool VTopLeft;
public bool HTopLeft;
public bool VTopRight;
public bool HTopRight;
public bool VBottomLeft;
public bool HBottomLeft;
public bool VBottomRight;
public bool HBottomRight;
}
public class MoveInColliderBoundaries
{
Func<Vector3, float> Vector3H;
Func<Vector3, float> Vector3V;
Func<float, float, Vector3> VectorHV;
const float Offset = .2f;
const float RaySizeCompensation = .2f;
public Transform CameraTransform;
public Vector2 CameraSize;
public LayerMask CameraCollisionMask;
public int TotalHorizontalRays = 3;
public int TotalVerticalRays = 3;
public RaycastOrigins RaycastOrigins { get { return _raycastOrigins; } }
RaycastOrigins _raycastOrigins;
public CameraCollisionState CameraCollisionState { get { return _cameraCollisionState; } }
CameraCollisionState _cameraCollisionState;
RaycastHit _raycastHit;
float _verticalDistanceBetweenRays;
float _horizontalDistanceBetweenRays;
ProCamera2D _proCamera2D;
public MoveInColliderBoundaries(ProCamera2D proCamera2D)
{
_proCamera2D = proCamera2D;
switch (_proCamera2D.Axis)
{
case MovementAxis.XY:
Vector3H = vector => vector.x;
Vector3V = vector => vector.y;
VectorHV = (h, v) => new Vector3(h, v, 0);
break;
case MovementAxis.XZ:
Vector3H = vector => vector.x;
Vector3V = vector => vector.z;
VectorHV = (h, v) => new Vector3(h, 0, v);
break;
case MovementAxis.YZ:
Vector3H = vector => vector.z;
Vector3V = vector => vector.y;
VectorHV = (h, v) => new Vector3(0, v, h);
break;
}
}
public Vector3 Move(Vector3 deltaMovement)
{
// Update raycasts origins
UpdateRaycastOrigins();
// Shoot corner rays to calculate offset and force movement if needed
GetOffsetAndForceMovement(_raycastOrigins.BottomLeft, ref deltaMovement, ref _cameraCollisionState.HBottomLeft, ref _cameraCollisionState.VBottomLeft, -1f, -1f);
GetOffsetAndForceMovement(_raycastOrigins.BottomRight, ref deltaMovement, ref _cameraCollisionState.HBottomRight, ref _cameraCollisionState.VBottomRight, 1f, -1f);
GetOffsetAndForceMovement(_raycastOrigins.TopLeft, ref deltaMovement, ref _cameraCollisionState.HTopLeft, ref _cameraCollisionState.VTopLeft, -1f, 1f);
GetOffsetAndForceMovement(_raycastOrigins.TopRight, ref deltaMovement, ref _cameraCollisionState.HTopRight, ref _cameraCollisionState.VTopRight, 1f, 1f);
// Check movement in the horizontal dir
float h = 0f;
if (Vector3H(deltaMovement) != 0)
h = MoveInAxis(Vector3H(deltaMovement), true);
// Check movement in the vertical dir
float v = 0f;
if (Vector3V(deltaMovement) != 0)
v = MoveInAxis(Vector3V(deltaMovement), false);
// Return updated movement
return VectorHV(h, v);
}
void UpdateRaycastOrigins()
{
_raycastOrigins.BottomRight = VectorHV(Vector3H(CameraTransform.localPosition) + (CameraSize.x / 2), Vector3V(CameraTransform.localPosition) - (CameraSize.y / 2));
_raycastOrigins.BottomLeft = VectorHV(Vector3H(CameraTransform.localPosition) - (CameraSize.x / 2), Vector3V(CameraTransform.localPosition) - (CameraSize.y / 2));
_raycastOrigins.TopRight = VectorHV(Vector3H(CameraTransform.localPosition) + (CameraSize.x / 2), Vector3V(CameraTransform.localPosition) + (CameraSize.y / 2));
_raycastOrigins.TopLeft = VectorHV(Vector3H(CameraTransform.localPosition) - (CameraSize.x / 2), Vector3V(CameraTransform.localPosition) + (CameraSize.y / 2));
_horizontalDistanceBetweenRays = CameraSize.x / (TotalVerticalRays - 1);
_verticalDistanceBetweenRays = CameraSize.y / (TotalHorizontalRays - 1);
}
void GetOffsetAndForceMovement(Vector3 rayTargetPos, ref Vector3 deltaMovement, ref bool horizontalCheck, ref bool verticalCheck, float hSign, float vSign)
{
Vector3 rayOrigin = VectorHV(Vector3H(CameraTransform.localPosition), Vector3V(CameraTransform.localPosition));
Vector3 rayDirection = (rayTargetPos - rayOrigin).normalized;
float raySize = (rayTargetPos - rayOrigin).magnitude + .01f + .5f;
DrawRay(rayOrigin, rayDirection * raySize, Color.yellow);
if (Physics.Raycast(rayOrigin, rayDirection, out _raycastHit, raySize, CameraCollisionMask))
{
if (Mathf.Abs(Vector3H(_raycastHit.normal)) > Mathf.Abs(Vector3V(_raycastHit.normal)))
{
horizontalCheck = !verticalCheck;
if (Vector3H(deltaMovement) == 0)
{
var deltaMovH = .1f * hSign;
deltaMovement = VectorHV(deltaMovH, Vector3V(deltaMovement));
var h = MoveInAxis(Vector3H(deltaMovement), true);
deltaMovement = VectorHV(h, Vector3V(deltaMovement));
}
}
else
{
verticalCheck = !horizontalCheck;
if (Vector3V(deltaMovement) == 0)
{
var deltaMovV = .1f * vSign;
deltaMovement = VectorHV(Vector3H(deltaMovement), deltaMovV);
var v = MoveInAxis(Vector3V(deltaMovement), false);
deltaMovement = VectorHV(Vector3H(deltaMovement), v);
}
}
}
else
{
horizontalCheck = false;
verticalCheck = false;
}
}
float MoveInAxis(float deltaMovement, bool isHorizontal)
{
bool isPositiveDirection = deltaMovement > 0;
float rayDistance = Mathf.Abs(deltaMovement) + RaySizeCompensation;
Vector3 rayDirection;
Vector3 initialRayOrigin;
if (isHorizontal)
{
rayDirection = isPositiveDirection ? CameraTransform.right : -CameraTransform.right;
initialRayOrigin = isPositiveDirection ? _raycastOrigins.BottomRight : _raycastOrigins.BottomLeft;
}
else
{
rayDirection = isPositiveDirection ? CameraTransform.up : -CameraTransform.up;
initialRayOrigin = isPositiveDirection ? _raycastOrigins.TopLeft : _raycastOrigins.BottomLeft;
}
float raycastHitPos = Mathf.NegativeInfinity;
bool hasRayHit = false;
var totalRays = isHorizontal ? TotalHorizontalRays : TotalVerticalRays;
for (int i = 0; i < totalRays; i++)
{
float rayH = isHorizontal ? Vector3H(initialRayOrigin) : Vector3H(initialRayOrigin) + i * _horizontalDistanceBetweenRays;
float rayV = isHorizontal ? Vector3V(initialRayOrigin) + i * _verticalDistanceBetweenRays : Vector3V(initialRayOrigin);
// Add a small offset to avoid collisions at "zero"
if (isHorizontal)
{
if ((isPositiveDirection && _cameraCollisionState.VBottomRight && i == 0) ||
(!isPositiveDirection && _cameraCollisionState.VBottomLeft && i == 0))
rayV += Offset;
if ((isPositiveDirection && _cameraCollisionState.VTopRight && i == totalRays - 1) ||
(!isPositiveDirection && _cameraCollisionState.VTopLeft && i == totalRays - 1))
rayV -= Offset;
}
else
{
if ((isPositiveDirection && _cameraCollisionState.HTopLeft && i == 0) ||
(!isPositiveDirection && _cameraCollisionState.HBottomLeft && i == 0))
rayH += Offset;
if ((isPositiveDirection && _cameraCollisionState.HTopRight && i == totalRays - 1) ||
(!isPositiveDirection && _cameraCollisionState.HBottomRight && i == totalRays - 1))
rayH -= Offset;
}
Vector3 ray = VectorHV(rayH, rayV);
// Raycast
if (Physics.Raycast(ray, rayDirection, out _raycastHit, rayDistance, CameraCollisionMask))
{
DrawRay(ray, rayDirection * rayDistance, Color.red);
if (isHorizontal &&
hasRayHit &&
(isPositiveDirection && raycastHitPos <= Vector3H(_raycastHit.point)) ||
(!isPositiveDirection && raycastHitPos >= Vector3H(_raycastHit.point)))
continue;
else if (hasRayHit &&
(isPositiveDirection && raycastHitPos <= Vector3V(_raycastHit.point)) ||
(!isPositiveDirection && raycastHitPos >= Vector3V(_raycastHit.point)))
continue;
hasRayHit = true;
deltaMovement = isHorizontal ? Vector3H(_raycastHit.point) - Vector3H(ray) + (isPositiveDirection ? -RaySizeCompensation : RaySizeCompensation) :
Vector3V(_raycastHit.point) - Vector3V(ray) + (isPositiveDirection ? -RaySizeCompensation : RaySizeCompensation);
raycastHitPos = isHorizontal ? Vector3H(_raycastHit.point) : Vector3V(_raycastHit.point);
}
else
{
DrawRay(ray, rayDirection * rayDistance, Color.cyan);
}
}
return deltaMovement;
}
private void DrawRay(Vector3 start, Vector3 dir, Color color, float duration = 0)
{
if (duration != 0)
Debug.DrawRay(start, dir, color, duration);
else
Debug.DrawRay(start, dir, color);
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 51b351be489d24540af410c7fc90e168
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,32 @@
using UnityEngine;
namespace Com.LuisPedroFonseca.ProCamera2D
{
[System.Serializable]
[CreateAssetMenu(menuName = "ProCamera2D/Shake Preset")]
public class ShakePreset : ScriptableObject
{
public Vector3 Strength = new Vector2(10, 10);
[Range(.02f, 3f)]
public float Duration = .5f;
[Range(1, 100)]
public int Vibrato = 10;
[Range(0f, 1f)]
public float Randomness = .1f;
[Range(0f, .5f)]
public float Smoothness = .1f;
public bool UseRandomInitialAngle = true;
[Range(0f, 360f)]
public float InitialAngle;
public Vector3 Rotation;
public bool IgnoreTimeScale;
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cbf2b71a297b84564b930517da7ba2d8
timeCreated: 1487290733
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: c7c50ff96274b40608e26e241ae15e11
folderAsset: yes
timeCreated: 1432929171
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,776 @@
// Helper class derived from:
// http://wiki.unity3d.com/index.php/ArrayPrefs2
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
namespace Com.LuisPedroFonseca.ProCamera2D
{
public static class EditorPrefsX
{
static private int endianDiff1;
static private int endianDiff2;
static private int idx;
static private byte[] byteBlock;
enum ArrayType
{
Float,
Int32,
Bool,
String,
Vector2,
Vector3,
Quaternion,
Color
}
public static bool SetBool(String name, bool value)
{
#if UNITY_EDITOR
try
{
EditorPrefs.SetInt(name, value ? 1 : 0);
}
catch
{
return false;
}
#endif
return true;
}
public static bool GetBool(String name)
{
#if UNITY_EDITOR
return EditorPrefs.GetInt(name) == 1;
#else
return true;
#endif
}
public static bool GetBool(String name, bool defaultValue)
{
#if UNITY_EDITOR
return (1 == EditorPrefs.GetInt(name, defaultValue ? 1 : 0));
#else
return true;
#endif
}
public static long GetLong(string key, long defaultValue)
{
#if UNITY_EDITOR
int lowBits, highBits;
SplitLong(defaultValue, out lowBits, out highBits);
lowBits = EditorPrefs.GetInt(key + "_lowBits", lowBits);
highBits = EditorPrefs.GetInt(key + "_highBits", highBits);
// unsigned, to prevent loss of sign bit.
ulong ret = (uint)highBits;
ret = (ret << 32);
return (long)(ret | (ulong)(uint)lowBits);
#else
return 0;
#endif
}
public static long GetLong(string key)
{
#if UNITY_EDITOR
int lowBits = EditorPrefs.GetInt(key + "_lowBits");
int highBits = EditorPrefs.GetInt(key + "_highBits");
// unsigned, to prevent loss of sign bit.
ulong ret = (uint)highBits;
ret = (ret << 32);
return (long)(ret | (ulong)(uint)lowBits);
#else
return 0;
#endif
}
private static void SplitLong(long input, out int lowBits, out int highBits)
{
// unsigned everything, to prevent loss of sign bit.
lowBits = (int)(uint)(ulong)input;
highBits = (int)(uint)(input >> 32);
}
public static void SetLong(string key, long value)
{
#if UNITY_EDITOR
int lowBits, highBits;
SplitLong(value, out lowBits, out highBits);
EditorPrefs.SetInt(key + "_lowBits", lowBits);
EditorPrefs.SetInt(key + "_highBits", highBits);
#endif
}
public static bool SetVector2(String key, Vector2 vector)
{
return SetFloatArray(key, new float[]{ vector.x, vector.y });
}
static Vector2 GetVector2(String key)
{
var floatArray = GetFloatArray(key);
if (floatArray.Length < 2)
{
return Vector2.zero;
}
return new Vector2(floatArray[0], floatArray[1]);
}
public static Vector2 GetVector2(String key, Vector2 defaultValue)
{
#if UNITY_EDITOR
if (EditorPrefs.HasKey(key))
{
return GetVector2(key);
}
return defaultValue;
#else
return Vector2.zero;
#endif
}
public static bool SetVector3(String key, Vector3 vector)
{
return SetFloatArray(key, new float []{ vector.x, vector.y, vector.z });
}
public static Vector3 GetVector3(String key)
{
var floatArray = GetFloatArray(key);
if (floatArray.Length < 3)
{
return Vector3.zero;
}
return new Vector3(floatArray[0], floatArray[1], floatArray[2]);
}
public static Vector3 GetVector3(String key, Vector3 defaultValue)
{
#if UNITY_EDITOR
if (EditorPrefs.HasKey(key))
{
return GetVector3(key);
}
return defaultValue;
#else
return Vector3.zero;
#endif
}
public static bool SetQuaternion(String key, Quaternion vector)
{
return SetFloatArray(key, new float[]{ vector.x, vector.y, vector.z, vector.w });
}
public static Quaternion GetQuaternion(String key)
{
var floatArray = GetFloatArray(key);
if (floatArray.Length < 4)
{
return Quaternion.identity;
}
return new Quaternion(floatArray[0], floatArray[1], floatArray[2], floatArray[3]);
}
public static Quaternion GetQuaternion(String key, Quaternion defaultValue)
{
#if UNITY_EDITOR
if (EditorPrefs.HasKey(key))
{
return GetQuaternion(key);
}
return defaultValue;
#else
return Quaternion.identity;
#endif
}
public static bool SetColor(String key, Color color)
{
return SetFloatArray(key, new float[]{ color.r, color.g, color.b, color.a });
}
public static Color GetColor(String key)
{
var floatArray = GetFloatArray(key);
if (floatArray.Length < 4)
{
return new Color(0.0f, 0.0f, 0.0f, 0.0f);
}
return new Color(floatArray[0], floatArray[1], floatArray[2], floatArray[3]);
}
public static Color GetColor(String key, Color defaultValue)
{
#if UNITY_EDITOR
if (EditorPrefs.HasKey(key))
{
return GetColor(key);
}
return defaultValue;
#else
return Color.white;
#endif
}
public static bool SetBoolArray(String key, bool[] boolArray)
{
// Make a byte array that's a multiple of 8 in length, plus 5 bytes to store the number of entries as an int32 (+ identifier)
// We have to store the number of entries, since the boolArray length might not be a multiple of 8, so there could be some padded zeroes
var bytes = new byte[(boolArray.Length + 7) / 8 + 5];
bytes[0] = System.Convert.ToByte(ArrayType.Bool); // Identifier
int mask = 1;
int targetIndex = 5;
for (int i = 0; i < boolArray.Length; i++)
{
if (boolArray[i])
bytes[targetIndex] |= (byte)mask;
mask <<= 1;
if (mask > 128)
{
mask = 1;
targetIndex++;
}
}
Initialize();
ConvertInt32ToBytes(boolArray.Length, bytes); // The number of entries in the boolArray goes in the first 4 bytes
return SaveBytes(key, bytes);
}
public static bool[] GetBoolArray(String key)
{
if (PlayerPrefs.HasKey(key))
{
var bytes = System.Convert.FromBase64String(PlayerPrefs.GetString(key));
if (bytes.Length < 5)
{
Debug.LogError("Corrupt preference file for " + key);
return new bool[0];
}
if ((ArrayType)bytes[0] != ArrayType.Bool)
{
Debug.LogError(key + " is not a boolean array");
return new bool[0];
}
Initialize();
int count = ConvertBytesToInt32(bytes);
var boolArray = new bool[count];
int mask = 1;
int targetIndex = 5;
for (int i = 0; i < boolArray.Length; i++)
{
boolArray[i] = (bytes[targetIndex] & (byte)mask) != 0;
mask <<= 1;
if (mask > 128)
{
mask = 1;
targetIndex++;
}
}
return boolArray;
}
return new bool[0];
}
public static bool[] GetBoolArray(String key, bool defaultValue, int defaultSize)
{
#if UNITY_EDITOR
if (EditorPrefs.HasKey(key))
{
return GetBoolArray(key);
}
var boolArray = new bool[defaultSize];
for (int i = 0; i < defaultSize; i++)
{
boolArray[i] = defaultValue;
}
return boolArray;
#else
return new bool[0];
#endif
}
public static bool SetStringArray(String key, String[] stringArray)
{
#if UNITY_EDITOR
var bytes = new byte[stringArray.Length + 1];
bytes[0] = System.Convert.ToByte(ArrayType.String); // Identifier
Initialize();
// Store the length of each string that's in stringArray, so we can extract the correct strings in GetStringArray
for (var i = 0; i < stringArray.Length; i++)
{
if (stringArray[i] == null)
{
Debug.LogError("Can't save null entries in the string array when setting " + key);
return false;
}
if (stringArray[i].Length > 255)
{
Debug.LogError("Strings cannot be longer than 255 characters when setting " + key);
return false;
}
bytes[idx++] = (byte)stringArray[i].Length;
}
try
{
EditorPrefs.SetString(key, System.Convert.ToBase64String(bytes) + "|" + String.Join("", stringArray));
}
catch
{
return false;
}
#endif
return true;
}
public static String[] GetStringArray(String key)
{
#if UNITY_EDITOR
if (EditorPrefs.HasKey(key))
{
var completeString = EditorPrefs.GetString(key);
var separatorIndex = completeString.IndexOf("|"[0]);
if (separatorIndex < 4)
{
Debug.LogError("Corrupt preference file for " + key);
return new String[0];
}
var bytes = System.Convert.FromBase64String(completeString.Substring(0, separatorIndex));
if ((ArrayType)bytes[0] != ArrayType.String)
{
Debug.LogError(key + " is not a string array");
return new String[0];
}
Initialize();
var numberOfEntries = bytes.Length - 1;
var stringArray = new String[numberOfEntries];
var stringIndex = separatorIndex + 1;
for (var i = 0; i < numberOfEntries; i++)
{
int stringLength = bytes[idx++];
if (stringIndex + stringLength > completeString.Length)
{
Debug.LogError("Corrupt preference file for " + key);
return new String[0];
}
stringArray[i] = completeString.Substring(stringIndex, stringLength);
stringIndex += stringLength;
}
return stringArray;
}
#endif
return new String[0];
}
public static String[] GetStringArray(String key, String defaultValue, int defaultSize)
{
#if UNITY_EDITOR
if (EditorPrefs.HasKey(key))
{
return GetStringArray(key);
}
var stringArray = new String[defaultSize];
for (int i = 0; i < defaultSize; i++)
{
stringArray[i] = defaultValue;
}
return stringArray;
#else
return new String[0];
#endif
}
public static bool SetIntArray(String key, int[] intArray)
{
return SetValue(key, intArray, ArrayType.Int32, 1, ConvertFromInt);
}
public static bool SetFloatArray(String key, float[] floatArray)
{
return SetValue(key, floatArray, ArrayType.Float, 1, ConvertFromFloat);
}
public static bool SetVector2Array(String key, Vector2[] vector2Array)
{
return SetValue(key, vector2Array, ArrayType.Vector2, 2, ConvertFromVector2);
}
public static bool SetVector3Array(String key, Vector3[] vector3Array)
{
return SetValue(key, vector3Array, ArrayType.Vector3, 3, ConvertFromVector3);
}
public static bool SetQuaternionArray(String key, Quaternion[] quaternionArray)
{
return SetValue(key, quaternionArray, ArrayType.Quaternion, 4, ConvertFromQuaternion);
}
public static bool SetColorArray(String key, Color[] colorArray)
{
return SetValue(key, colorArray, ArrayType.Color, 4, ConvertFromColor);
}
private static bool SetValue<T>(String key, T array, ArrayType arrayType, int vectorNumber, Action<T, byte[],int> convert) where T : IList
{
var bytes = new byte[(4 * array.Count) * vectorNumber + 1];
bytes[0] = System.Convert.ToByte(arrayType); // Identifier
Initialize();
for (var i = 0; i < array.Count; i++)
{
convert(array, bytes, i);
}
return SaveBytes(key, bytes);
}
private static void ConvertFromInt(int[] array, byte[] bytes, int i)
{
ConvertInt32ToBytes(array[i], bytes);
}
private static void ConvertFromFloat(float[] array, byte[] bytes, int i)
{
ConvertFloatToBytes(array[i], bytes);
}
private static void ConvertFromVector2(Vector2[] array, byte[] bytes, int i)
{
ConvertFloatToBytes(array[i].x, bytes);
ConvertFloatToBytes(array[i].y, bytes);
}
private static void ConvertFromVector3(Vector3[] array, byte[] bytes, int i)
{
ConvertFloatToBytes(array[i].x, bytes);
ConvertFloatToBytes(array[i].y, bytes);
ConvertFloatToBytes(array[i].z, bytes);
}
private static void ConvertFromQuaternion(Quaternion[] array, byte[] bytes, int i)
{
ConvertFloatToBytes(array[i].x, bytes);
ConvertFloatToBytes(array[i].y, bytes);
ConvertFloatToBytes(array[i].z, bytes);
ConvertFloatToBytes(array[i].w, bytes);
}
private static void ConvertFromColor(Color[] array, byte[] bytes, int i)
{
ConvertFloatToBytes(array[i].r, bytes);
ConvertFloatToBytes(array[i].g, bytes);
ConvertFloatToBytes(array[i].b, bytes);
ConvertFloatToBytes(array[i].a, bytes);
}
public static int[] GetIntArray(String key)
{
var intList = new List<int>();
GetValue(key, intList, ArrayType.Int32, 1, ConvertToInt);
return intList.ToArray();
}
public static int[] GetIntArray(String key, int defaultValue, int defaultSize)
{
#if UNITY_EDITOR
if (EditorPrefs.HasKey(key))
{
return GetIntArray(key);
}
var intArray = new int[defaultSize];
for (int i = 0; i < defaultSize; i++)
{
intArray[i] = defaultValue;
}
return intArray;
#else
return new int[0];
#endif
}
public static float[] GetFloatArray(String key)
{
var floatList = new List<float>();
GetValue(key, floatList, ArrayType.Float, 1, ConvertToFloat);
return floatList.ToArray();
}
public static float[] GetFloatArray(String key, float defaultValue, int defaultSize)
{
#if UNITY_EDITOR
if (EditorPrefs.HasKey(key))
{
return GetFloatArray(key);
}
var floatArray = new float[defaultSize];
for (int i = 0; i < defaultSize; i++)
{
floatArray[i] = defaultValue;
}
return floatArray;
#else
return new float[0];
#endif
}
public static Vector2[] GetVector2Array(String key)
{
var vector2List = new List<Vector2>();
GetValue(key, vector2List, ArrayType.Vector2, 2, ConvertToVector2);
return vector2List.ToArray();
}
public static Vector2[] GetVector2Array(String key, Vector2 defaultValue, int defaultSize)
{
#if UNITY_EDITOR
if (EditorPrefs.HasKey(key))
{
return GetVector2Array(key);
}
var vector2Array = new Vector2[defaultSize];
for (int i = 0; i < defaultSize; i++)
{
vector2Array[i] = defaultValue;
}
return vector2Array;
#else
return new Vector2[0];
#endif
}
public static Vector3[] GetVector3Array(String key)
{
var vector3List = new List<Vector3>();
GetValue(key, vector3List, ArrayType.Vector3, 3, ConvertToVector3);
return vector3List.ToArray();
}
public static Vector3[] GetVector3Array(String key, Vector3 defaultValue, int defaultSize)
{
#if UNITY_EDITOR
if (EditorPrefs.HasKey(key))
{
return GetVector3Array(key);
}
var vector3Array = new Vector3[defaultSize];
for (int i = 0; i < defaultSize; i++)
{
vector3Array[i] = defaultValue;
}
return vector3Array;
#else
return new Vector3[0];
#endif
}
public static Quaternion[] GetQuaternionArray(String key)
{
var quaternionList = new List<Quaternion>();
GetValue(key, quaternionList, ArrayType.Quaternion, 4, ConvertToQuaternion);
return quaternionList.ToArray();
}
public static Quaternion[] GetQuaternionArray(String key, Quaternion defaultValue, int defaultSize)
{
#if UNITY_EDITOR
if (EditorPrefs.HasKey(key))
{
return GetQuaternionArray(key);
}
var quaternionArray = new Quaternion[defaultSize];
for (int i = 0; i < defaultSize; i++)
{
quaternionArray[i] = defaultValue;
}
return quaternionArray;
#else
return new Quaternion[0];
#endif
}
public static Color[] GetColorArray(String key)
{
var colorList = new List<Color>();
GetValue(key, colorList, ArrayType.Color, 4, ConvertToColor);
return colorList.ToArray();
}
public static Color[] GetColorArray(String key, Color defaultValue, int defaultSize)
{
#if UNITY_EDITOR
if (EditorPrefs.HasKey(key))
{
return GetColorArray(key);
}
var colorArray = new Color[defaultSize];
for (int i = 0; i < defaultSize; i++)
{
colorArray[i] = defaultValue;
}
return colorArray;
#else
return new Color[0];
#endif
}
private static void GetValue<T>(String key, T list, ArrayType arrayType, int vectorNumber, Action<T, byte[]> convert) where T : IList
{
#if UNITY_EDITOR
if (EditorPrefs.HasKey(key))
{
var bytes = System.Convert.FromBase64String(EditorPrefs.GetString(key));
if ((bytes.Length - 1) % (vectorNumber * 4) != 0)
{
Debug.LogError("Corrupt preference file for " + key);
return;
}
if ((ArrayType)bytes[0] != arrayType)
{
Debug.LogError(key + " is not a " + arrayType.ToString() + " array");
return;
}
Initialize();
var end = (bytes.Length - 1) / (vectorNumber * 4);
for (var i = 0; i < end; i++)
{
convert(list, bytes);
}
}
#endif
}
private static void ConvertToInt(List<int> list, byte[] bytes)
{
list.Add(ConvertBytesToInt32(bytes));
}
private static void ConvertToFloat(List<float> list, byte[] bytes)
{
list.Add(ConvertBytesToFloat(bytes));
}
private static void ConvertToVector2(List<Vector2> list, byte[] bytes)
{
list.Add(new Vector2(ConvertBytesToFloat(bytes), ConvertBytesToFloat(bytes)));
}
private static void ConvertToVector3(List<Vector3> list, byte[] bytes)
{
list.Add(new Vector3(ConvertBytesToFloat(bytes), ConvertBytesToFloat(bytes), ConvertBytesToFloat(bytes)));
}
private static void ConvertToQuaternion(List<Quaternion> list, byte[] bytes)
{
list.Add(new Quaternion(ConvertBytesToFloat(bytes), ConvertBytesToFloat(bytes), ConvertBytesToFloat(bytes), ConvertBytesToFloat(bytes)));
}
private static void ConvertToColor(List<Color> list, byte[] bytes)
{
list.Add(new Color(ConvertBytesToFloat(bytes), ConvertBytesToFloat(bytes), ConvertBytesToFloat(bytes), ConvertBytesToFloat(bytes)));
}
public static void ShowArrayType(String key)
{
#if UNITY_EDITOR
var bytes = System.Convert.FromBase64String(EditorPrefs.GetString(key));
if (bytes.Length > 0)
{
ArrayType arrayType = (ArrayType)bytes[0];
Debug.Log(key + " is a " + arrayType.ToString() + " array");
}
#endif
}
private static void Initialize()
{
if (System.BitConverter.IsLittleEndian)
{
endianDiff1 = 0;
endianDiff2 = 0;
}
else
{
endianDiff1 = 3;
endianDiff2 = 1;
}
if (byteBlock == null)
{
byteBlock = new byte[4];
}
idx = 1;
}
private static bool SaveBytes(String key, byte[] bytes)
{
#if UNITY_EDITOR
try
{
EditorPrefs.SetString(key, System.Convert.ToBase64String(bytes));
}
catch
{
return false;
}
#endif
return true;
}
private static void ConvertFloatToBytes(float f, byte[] bytes)
{
byteBlock = System.BitConverter.GetBytes(f);
ConvertTo4Bytes(bytes);
}
private static float ConvertBytesToFloat(byte[] bytes)
{
ConvertFrom4Bytes(bytes);
return System.BitConverter.ToSingle(byteBlock, 0);
}
private static void ConvertInt32ToBytes(int i, byte[] bytes)
{
byteBlock = System.BitConverter.GetBytes(i);
ConvertTo4Bytes(bytes);
}
private static int ConvertBytesToInt32(byte[] bytes)
{
ConvertFrom4Bytes(bytes);
return System.BitConverter.ToInt32(byteBlock, 0);
}
private static void ConvertTo4Bytes(byte[] bytes)
{
bytes[idx] = byteBlock[endianDiff1];
bytes[idx + 1] = byteBlock[1 + endianDiff2];
bytes[idx + 2] = byteBlock[2 - endianDiff2];
bytes[idx + 3] = byteBlock[3 - endianDiff1];
idx += 4;
}
private static void ConvertFrom4Bytes(byte[] bytes)
{
byteBlock[endianDiff1] = bytes[idx];
byteBlock[1 + endianDiff2] = bytes[idx + 1];
byteBlock[2 - endianDiff2] = bytes[idx + 2];
byteBlock[3 - endianDiff1] = bytes[idx + 3];
idx += 4;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0cc1f1523bb654cfa9771ed42e226719
timeCreated: 1432894729
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
// https://gist.github.com/frarees/9791517
using UnityEngine;
namespace Com.LuisPedroFonseca.ProCamera2D
{
public class MinMaxSliderAttribute : PropertyAttribute
{
public readonly float max;
public readonly float min;
public MinMaxSliderAttribute(float min, float max)
{
this.min = min;
this.max = max;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 43e42d399775d409e8b8cd61655066a7
timeCreated: 1487610127
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,84 @@
using UnityEngine;
namespace Com.LuisPedroFonseca.ProCamera2D
{
public static class PrefsData
{
// ProCamera2D
public static string NumericBoundariesColorKey = "Numeric Boundaries";
public static Color NumericBoundariesColorValue = Color.white;
public static string TargetsMidPointColorKey = "Targets Mid Point";
public static Color TargetsMidPointColorValue = Color.yellow;
public static string InfluencesColorKey = "Influences Sum";
public static Color InfluencesColorValue = Color.red;
public static string ShakeInfluenceColorKey = "Shake Influence";
public static Color ShakeInfluenceColorValue = Color.red;
public static string OverallOffsetColorKey = "Overall Offset";
public static Color OverallOffsetColorValue = Color.yellow;
public static string CamDistanceColorKey = "Camera Distance Limit";
public static Color CamDistanceColorValue = Color.red;
public static string CamTargetPositionColorKey = "Camera Target Position";
public static Color CamTargetPositionColorValue = new Color(.3f, .3f, .1f);
public static string CamTargetPositionSmoothedColorKey = "Camera Target Position Smoothed";
public static Color CamTargetPositionSmoothedColorValue = new Color(.5f, .3f, .1f);
public static string CurrentCameraPositionColorKey = "Current Camera Position";
public static Color CurrentCameraPositionColorValue = new Color(.8f, .3f, .1f);
public static string CameraWindowColorKey = "Camera Window";
public static Color CameraWindowColorValue = Color.red;
// Forward Focus
public static string ForwardFocusColorKey = "Forward Focus";
public static Color ForwardFocusColorValue = Color.red;
// Zoom To Fit
public static string ZoomToFitColorKey = "Zoom To Fit";
public static Color ZoomToFitColorValue = Color.magenta;
// Boundaries Trigger
public static string BoundariesTriggerColorKey = "Trigger Boundaries";
public static Color BoundariesTriggerColorValue = new Color(Color.cyan.r, Color.cyan.g, Color.cyan.b, .3f);
// Influence Trigger
public static string InfluenceTriggerColorKey = "Trigger Influence";
public static Color InfluenceTriggerColorValue = new Color(Color.cyan.r, Color.cyan.g, Color.cyan.b, .3f);
// Zoom Trigger
public static string ZoomTriggerColorKey = "Trigger Zoom";
public static Color ZoomTriggerColorValue = new Color(Color.cyan.r, Color.cyan.g, Color.cyan.b, .3f);
// Trigger shape
public static string TriggerShapeColorKey = "Trigger Shape";
public static Color TriggerShapeColorValue = new Color(Color.cyan.r, Color.cyan.g, Color.cyan.b, .3f);
// Rails
public static string RailsColorKey = "Rails";
public static Color RailsColorValue = Color.white;
public static float RailsSnapping = .1f;
// Pan Edges
public static string PanEdgesColorKey = "Pan Edges";
public static Color PanEdgesColorValue = Color.red;
// Rooms
public static string RoomsColorKey = "Rooms";
public static Color RoomsColorValue = Color.red;
public static float RoomsSnapping = .1f;
// Content Fitter
public static string FitterFillColorKey = "Fitter Fill";
public static Color FitterFillColorValue = new Color(1f, 1f, 1f, 0.1f);
public static string FitterLineColorKey = "Fitter Line";
public static Color FitterLineColorValue = new Color(1f, 1f, 1f, 0.6f);
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 223eb64f1d6c540d3a207a36649b582f
timeCreated: 1432929192
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,161 @@
using System.Collections.Generic;
using UnityEngine;
namespace Com.LuisPedroFonseca.ProCamera2D
{
public enum EaseType
{
EaseInOut,
EaseOut,
EaseIn,
Linear
}
public static class Utils
{
public static float EaseFromTo(float start, float end, float value, EaseType type = EaseType.EaseInOut)
{
value = Mathf.Clamp01(value);
switch (type)
{
case EaseType.EaseInOut:
return Mathf.Lerp(start, end, value * value * (3.0f - 2.0f * value));
case EaseType.EaseOut:
return Mathf.Lerp(start, end, Mathf.Sin(value * Mathf.PI * 0.5f));
case EaseType.EaseIn:
return Mathf.Lerp(start, end, 1.0f - Mathf.Cos(value * Mathf.PI * 0.5f));
default:
return Mathf.Lerp(start, end, value);
}
}
public static float SmoothApproach(float pastPosition, float pastTargetPosition, float targetPosition, float speed, float deltaTime)
{
float t = deltaTime * speed;
float v = (targetPosition - pastTargetPosition) / t;
float f = pastPosition - pastTargetPosition + v;
return targetPosition - v + f * Mathf.Exp(-t);
}
public static float Remap(this float value, float from1, float to1, float from2, float to2)
{
return Mathf.Clamp((value - from1) / (to1 - from1) * (to2 - from2) + from2, from2, to2);
}
public static void DrawArrowForGizmo(Vector3 pos, Vector3 direction, float arrowHeadLength = 0.25f, float arrowHeadAngle = 20.0f)
{
Gizmos.DrawRay(pos, direction);
DrawArrowEnd(true, pos, direction, Gizmos.color, arrowHeadLength, arrowHeadAngle);
}
public static void DrawArrowForGizmo(Vector3 pos, Vector3 direction, Color color, float arrowHeadLength = 0.25f, float arrowHeadAngle = 20.0f)
{
Gizmos.DrawRay(pos, direction);
DrawArrowEnd(true, pos, direction, color, arrowHeadLength, arrowHeadAngle);
}
public static void DrawArrowForDebug(Vector3 pos, Vector3 direction, float arrowHeadLength = 0.25f, float arrowHeadAngle = 20.0f)
{
Debug.DrawRay(pos, direction);
DrawArrowEnd(false, pos, direction, Gizmos.color, arrowHeadLength, arrowHeadAngle);
}
public static void DrawArrowForDebug(Vector3 pos, Vector3 direction, Color color, float arrowHeadLength = 0.25f, float arrowHeadAngle = 20.0f)
{
Debug.DrawRay(pos, direction, color);
DrawArrowEnd(false, pos, direction, color, arrowHeadLength, arrowHeadAngle);
}
static void DrawArrowEnd(bool gizmos, Vector3 pos, Vector3 direction, Color color, float arrowHeadLength = 0.25f, float arrowHeadAngle = 20.0f)
{
if (direction == Vector3.zero)
return;
Vector3 right = Quaternion.LookRotation(direction) * Quaternion.Euler(arrowHeadAngle, 0, 0) * Vector3.back;
Vector3 left = Quaternion.LookRotation(direction) * Quaternion.Euler(-arrowHeadAngle, 0, 0) * Vector3.back;
Vector3 up = Quaternion.LookRotation(direction) * Quaternion.Euler(0, arrowHeadAngle, 0) * Vector3.back;
Vector3 down = Quaternion.LookRotation(direction) * Quaternion.Euler(0, -arrowHeadAngle, 0) * Vector3.back;
if (gizmos)
{
Gizmos.color = color;
Gizmos.DrawRay(pos + direction, right * arrowHeadLength);
Gizmos.DrawRay(pos + direction, left * arrowHeadLength);
Gizmos.DrawRay(pos + direction, up * arrowHeadLength);
Gizmos.DrawRay(pos + direction, down * arrowHeadLength);
}
else
{
Debug.DrawRay(pos + direction, right * arrowHeadLength, color);
Debug.DrawRay(pos + direction, left * arrowHeadLength, color);
Debug.DrawRay(pos + direction, up * arrowHeadLength, color);
Debug.DrawRay(pos + direction, down * arrowHeadLength, color);
}
}
public static bool AreNearlyEqual(float a, float b, float tolerance = .02f)
{
return Mathf.Abs(a - b) < tolerance;
}
public static Vector2 GetScreenSizeInWorldCoords(Camera gameCamera, float distance = 10f)
{
float width = 0f;
float height = 0f;
if (gameCamera.orthographic)
{
if (gameCamera.orthographicSize <= .001f)
return Vector2.zero;
var p1 = gameCamera.ViewportToWorldPoint(new Vector3(0, 0, gameCamera.nearClipPlane));
var p2 = gameCamera.ViewportToWorldPoint(new Vector3(1, 0, gameCamera.nearClipPlane));
var p3 = gameCamera.ViewportToWorldPoint(new Vector3(1, 1, gameCamera.nearClipPlane));
width = (p2 - p1).magnitude;
height = (p3 - p2).magnitude;
}
else
{
height = 2.0f * Mathf.Abs(distance) * Mathf.Tan(gameCamera.fieldOfView * 0.5f * Mathf.Deg2Rad);
width = height * gameCamera.aspect;
}
return new Vector2(width, height);
}
public static Vector3 GetVectorsSum(IList<Vector3> input)
{
Vector3 output = Vector3.zero;
for (int i = 0; i < input.Count; i++)
{
output += input[i];
}
return output;
}
public static float AlignToGrid(float input, float gridSize)
{
return Mathf.Round((Mathf.Round(input / gridSize) * gridSize) / gridSize) * gridSize;
}
public static bool IsInsideRectangle(float x, float y, float width, float height, float pointX, float pointY)
{
if (pointX >= x - width * .5f &&
pointX <= x + width * .5f &&
pointY >= y - height * .5f &&
pointY <= y + height * .5f)
return true;
return false;
}
public static bool IsInsideCircle(float x, float y, float radius, float pointX, float pointY)
{
return (pointX - x) * (pointX - x) + (pointY - y) * (pointY - y) < radius * radius;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: aaa55419b59a448a0a59f9a5197d32f2
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData: