コード例 #1
0
ファイル: BasePC2D.cs プロジェクト: CptMedo/Mars
        protected virtual void OnDrawGizmos()
        {
            if (ProCamera2D == null && Camera.main != null)
                ProCamera2D = Camera.main.GetComponent<ProCamera2D>();

            _gizmosDrawingFailed = false;

            if (ProCamera2D == null)
            {
                _gizmosDrawingFailed = true;
                return;
            }

            // Don't draw gizmos on other cameras
            if (Camera.current != ProCamera2D.GameCamera &&
                ((UnityEditor.SceneView.lastActiveSceneView != null && Camera.current != UnityEditor.SceneView.lastActiveSceneView.camera) ||
                (UnityEditor.SceneView.lastActiveSceneView == null)))
            {
                _gizmosDrawingFailed = true;
                return;
            }

            switch (ProCamera2D.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;
            }
        }
コード例 #2
0
        protected virtual void Start()
        {
            _transform = transform;

            if (ProCamera2D == null && Camera.main != null)
                ProCamera2D = Camera.main.GetComponent<ProCamera2D>();
            else if(ProCamera2D == null)
                ProCamera2D = FindObjectOfType(typeof(ProCamera2D)) as ProCamera2D;
            
            if (ProCamera2D == null)
            {
                Debug.LogError(GetType().Name + ": ProCamera2D not set and not found on the MainCamera, or no camera with the MainCamera tag assigned.");
                return;
            }

            ProCamera2D.OnReset += OnReset;
            ProCamera2D.PreMoveUpdate += OnPreMoveUpdate;
            ProCamera2D.PostMoveUpdate += OnPostMoveUpdate;

            switch (ProCamera2D.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;
            }
        }
コード例 #3
0
ファイル: BasePC2D.cs プロジェクト: Elendow/GGJ2016
        protected virtual void Awake()
        {
            _transform = transform;

            if (ProCamera2D == null && Camera.main != null)
                ProCamera2D = Camera.main.GetComponent<ProCamera2D>();
            else if (ProCamera2D == null)
                ProCamera2D = FindObjectOfType(typeof(ProCamera2D)) as ProCamera2D;
            
            if (ProCamera2D == null)
            {
                Debug.LogError(GetType().Name + ": ProCamera2D not set and not found on the MainCamera, or no camera with the MainCamera tag assigned.");
                return;
            }

            Enable();

            ResetAxisFunctions();
        }
コード例 #4
0
        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;
            }
        }
コード例 #5
0
        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;
            }
        }
コード例 #6
0
        IEnumerator Transition()
        {
            if (!UseTopBoundary && !UseBottomBoundary && !UseLeftBoundary && !UseRightBoundary)
            {
                NumericBoundaries.UseNumericBoundaries = false;
                yield break;
            }

            var         position       = transform.position;
            var         topBoundary    = AreBoundariesRelative ? position.y + TopBoundary : TopBoundary;
            var         bottomBoundary = AreBoundariesRelative ? position.y + BottomBoundary : BottomBoundary;
            var         leftBoundary   = AreBoundariesRelative ? position.x + LeftBoundary : LeftBoundary;
            var         rightBoundary  = AreBoundariesRelative ? position.x + RightBoundary : RightBoundary;
            const float epsilon        = 0.01f;

            // Avoid unnecessary transitions
            var skip = true;

            if (UseTopBoundary && (Mathf.Abs(NumericBoundaries.TopBoundary - topBoundary) > epsilon || !NumericBoundaries.UseTopBoundary))
            {
                skip = false;
            }
            if (skip && UseBottomBoundary && (Mathf.Abs(NumericBoundaries.BottomBoundary - bottomBoundary) > epsilon || !NumericBoundaries.UseBottomBoundary))
            {
                skip = false;
            }
            if (skip && UseLeftBoundary && (Mathf.Abs(NumericBoundaries.LeftBoundary - leftBoundary) > epsilon || !NumericBoundaries.UseLeftBoundary))
            {
                skip = false;
            }
            if (skip && UseRightBoundary && (Mathf.Abs(NumericBoundaries.RightBoundary - rightBoundary) > epsilon || !NumericBoundaries.UseRightBoundary))
            {
                skip = false;
            }
            if (skip)
            {
                yield break;
            }

            NumericBoundaries.UseNumericBoundaries = true;

            GetTargetBoundaries();

            _boundsAnim.UseTopBoundary    = UseTopBoundary;
            _boundsAnim.TopBoundary       = _targetTopBoundary;
            _boundsAnim.UseBottomBoundary = UseBottomBoundary;
            _boundsAnim.BottomBoundary    = _targetBottomBoundary;
            _boundsAnim.UseLeftBoundary   = UseLeftBoundary;
            _boundsAnim.LeftBoundary      = _targetLeftBoundary;
            _boundsAnim.UseRightBoundary  = UseRightBoundary;
            _boundsAnim.RightBoundary     = _targetRightBoundary;

            _boundsAnim.TransitionDuration = TransitionDuration;
            _boundsAnim.TransitionEaseType = TransitionEaseType;

            // Zoom
            if (ChangeZoom && _initialCamSize / TargetZoom != ProCamera2D.ScreenSizeInWorldCoordinates.y * .5f)
            {
                ProCamera2D.UpdateScreenSize(_initialCamSize / TargetZoom, ZoomSmoothness, TransitionEaseType);
            }


            // Move camera "manually"
            if (_boundsAnim.GetAnimsCount() > 1)
            {
                if (NumericBoundaries.MoveCameraToTargetRoutine != null)
                {
                    NumericBoundaries.StopCoroutine(NumericBoundaries.MoveCameraToTargetRoutine);
                }

                NumericBoundaries.MoveCameraToTargetRoutine = NumericBoundaries.StartCoroutine(MoveCameraToTarget());
            }

            // Start bounds animation
            yield return(new WaitForEndOfFrame());

            _boundsAnim.Transition();
        }
コード例 #7
0
        protected override void OnDestroy()
        {
            base.OnDestroy();

            ProCamera2D.RemovePositionDeltaChanger(this);
        }
コード例 #8
0
 void OnApplicationQuit()
 {
     _instance = null;
 }
コード例 #9
0
ファイル: ProCamera2D.cs プロジェクト: EunoiaGames/MTW
 void OnApplicationQuit()
 {
     _instance = null;
 }
コード例 #10
0
        IEnumerator EndCinematicRoutine()
        {
            if (_letterbox != null && LetterboxAmount > 0)
            {
                _letterbox.TweenTo(0f, LetterboxAnimDuration);
            }

            var initialPosH = Vector3H(_newPos);
            var initialPosV = Vector3V(_newPos);

            var currentCameraSize = ProCamera2D.ScreenSizeInWorldCoordinates.y * .5f;

            // Ease out
            var t = 0f;

            while (t <= 1.0f)
            {
                if (!_paused)
                {
                    t += ProCamera2D.DeltaTime / EndDuration;

                    var originalPosH = Vector3H(_originalPos);
                    var originalPosV = Vector3V(_originalPos);

                    if (_numericBoundariesPreviousState)
                    {
                        LimitToNumericBoundaries(ref originalPosH, ref originalPosV);
                    }

                    float newPosH = 0f;
                    float newPosV = 0f;
                    if (ProCamera2D.CameraTargets.Count > 0)
                    {
                        newPosH = Utils.EaseFromTo(initialPosH, originalPosH, t, EndEaseType);
                        newPosV = Utils.EaseFromTo(initialPosV, originalPosV, t, EndEaseType);
                    }
                    else
                    {
                        newPosH = Utils.EaseFromTo(initialPosH, Vector3H(_startPos), t, EndEaseType);
                        newPosV = Utils.EaseFromTo(initialPosV, Vector3V(_startPos), t, EndEaseType);
                    }

                    _newPos = VectorHVD(newPosH, newPosV, 0);

                    _newSize = Utils.EaseFromTo(currentCameraSize, _initialCameraSize, t, EndEaseType);
                }

                yield return(ProCamera2D.GetYield());
            }

            _isPlaying = false;

            if (_numericBoundaries != null)
            {
                _numericBoundaries.enabled = _numericBoundariesPreviousState;
            }

            if (OnCinematicFinished != null)
            {
                OnCinematicFinished.Invoke();
            }

            // Ugly hack... but no way around it at the moment
            if (ProCamera2D.CameraTargets.Count == 0)
            {
                ProCamera2D.Reset(true);
            }
        }
コード例 #11
0
        void Awake()
        {
            _instance = this;
            _transform = transform;

            if (GameCamera == null)
                GameCamera = GetComponent<Camera>();
            if (GameCamera == null)
                Debug.LogError("Unity Camera not set and not found on the GameObject: " + gameObject.name);

#if PC2D_TK2D_SUPPORT
            Tk2dCam = GetComponent<tk2dCamera>();
#endif

            // Reset the axis functions
            ResetAxisFunctions();

            // Remove empty targets
            for (int i = 0; i < CameraTargets.Count; i++)
            {
                if (CameraTargets[i].TargetTransform == null)
                {
                    CameraTargets.RemoveAt(i);
                }
            }

            ScreenSizeInWorldCoordinates = _startScreenSizeInWorldCoordinates = Utils.GetScreenSizeInWorldCoords(GameCamera, Mathf.Abs(Vector3D(_transform.localPosition)));

            _cameraDepthPos = Vector3D(_transform.localPosition);
            _originalCameraDepthSign = Mathf.Sign(_cameraDepthPos);

            // Center on target
            if (CenterTargetOnStart && CameraTargets.Count > 0)
            {
                var targetsMidPoint = GetTargetsWeightedMidPoint(CameraTargets);
                var cameraTargetPositionX = FollowHorizontal ? Vector3H(targetsMidPoint) : Vector3H(_transform.localPosition);
                var cameraTargetPositionY = FollowVertical ? Vector3V(targetsMidPoint) : Vector3V(_transform.localPosition);
                var finalPos = new Vector2(cameraTargetPositionX, cameraTargetPositionY);
                finalPos += new Vector2(OverallOffset.x, OverallOffset.y);
                MoveCameraInstantlyToPosition(finalPos);
            }
            else
            {
                _cameraTargetPosition = _transform.localPosition;
                _cameraTargetHorizontalPositionSmoothed = Vector3H(_cameraTargetPosition);
                _previousCameraTargetHorizontalPositionSmoothed = _cameraTargetHorizontalPositionSmoothed;
                _cameraTargetVerticalPositionSmoothed = Vector3V(_cameraTargetPosition);
                _previousCameraTargetVerticalPositionSmoothed = _cameraTargetVerticalPositionSmoothed;
            }
        }
コード例 #12
0
        void OnEnable()
        {
            ProCamera2DEditorHelper.AssignProCamera2D(target as BasePC2D);

            _proCamera2DParallax = (ProCamera2DParallax)target;

            _proCamera2D = _proCamera2DParallax.ProCamera2D;

            _script = MonoScript.FromMonoBehaviour(_proCamera2DParallax);

            // Parallax layers List
            _parallaxLayersList = new ReorderableList(serializedObject, serializedObject.FindProperty("ParallaxLayers"), false, true, true, true);

            // Draw element callback
            _parallaxLayersList.drawElementCallback = (rect, index, isActive, isFocused) =>
            {
                rect.y += 2;
                var element = _parallaxLayersList.serializedProperty.GetArrayElementAtIndex(index);

                #if UNITY_5
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y, 65, 10), new GUIContent("Camera", "The parallax camera"), EditorStyles.boldLabel);
                #else
				EditorGUI.PrefixLabel(new Rect(rect.x, rect.y, 65, 10), new GUIContent("Camera", "The parallax camera"));
                #endif
                EditorGUI.PropertyField(new Rect(
                        rect.x + 65,
                        rect.y,
                        80,
                        EditorGUIUtility.singleLineHeight),
                    element.FindPropertyRelative("ParallaxCamera"), GUIContent.none);


                // Speed slider
                #if UNITY_5
                EditorGUI.PrefixLabel(new Rect(rect.x + 170, rect.y, 65, 10), new GUIContent("Speed", "The relative speed at which the camera should move in comparison to the main camera."), EditorStyles.boldLabel);
                #else
				EditorGUI.PrefixLabel(new Rect(rect.x + 170, rect.y, 65, 10), new GUIContent("Speed", "The relative speed at which the camera should move in comparison to the main camera."));
                #endif
                EditorGUI.PropertyField(new Rect(
                        rect.x + 210,
                        rect.y,
                        rect.width - 210,
                        EditorGUIUtility.singleLineHeight),
                    element.FindPropertyRelative("Speed"), GUIContent.none);
                

                // Layer mask
                #if UNITY_5
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y + 25, 65, 10), new GUIContent("Culling Mask", "Which layers should this camera render?"), EditorStyles.boldLabel);
                #else
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y + 25, 65, 10), new GUIContent("Culling Mask", "Which layers should this camera render?"));
                #endif
                EditorGUI.PropertyField(new Rect(
                        rect.x + 85,
                        rect.y + 25,
                        rect.width - 85,
                        EditorGUIUtility.singleLineHeight),
                    element.FindPropertyRelative("LayerMask"), GUIContent.none);
            };

            // Draw header callback
            _parallaxLayersList.drawHeaderCallback = rect => EditorGUI.LabelField(rect, "Parallax layers");

            // Add element callback
            _parallaxLayersList.onAddCallback = list => AddParallaxLayer();

            // Remove element callback
            _parallaxLayersList.onRemoveCallback = list =>
            {  
                if (EditorUtility.DisplayDialog("Warning!", "Are you sure you want to delete this layer?", "Yes", "No"))
                {
                    var cam = list.serializedProperty.GetArrayElementAtIndex(list.index).FindPropertyRelative("ParallaxCamera").objectReferenceValue as Camera;
                    if (cam != null)
                        DestroyImmediate(cam.gameObject);

                    ReorderableList.defaultBehaviours.DoRemoveButton(list);
                }
            };

            // Select element callback
            _parallaxLayersList.onSelectCallback = list =>
            {  
                EditorGUIUtility.PingObject(list.serializedProperty.GetArrayElementAtIndex(list.index).FindPropertyRelative("ParallaxCamera").objectReferenceValue as Camera);
            };

            _parallaxLayersList.elementHeight = 65;
            _parallaxLayersList.headerHeight = 18;
            _parallaxLayersList.draggable = true;
        }
コード例 #13
0
        protected override void Start()
        {
            base.Start();

            if (ProCamera2D == null)
            {
                return;
            }

            _boundsAnim = new BoundariesAnimator(ProCamera2D);
            _boundsAnim.OnTransitionStarted += () =>
            {
                if (ProCamera2D.OnBoundariesTransitionStarted != null)
                {
                    ProCamera2D.OnBoundariesTransitionStarted();
                }
            };

            _boundsAnim.OnTransitionFinished += () =>
            {
                if (ProCamera2D.OnBoundariesTransitionFinished != null)
                {
                    ProCamera2D.OnBoundariesTransitionFinished();
                }
            };

            GetTargetBoundaries();

            if (SetAsStartingBoundaries)
            {
                ProCamera2D.CurrentBoundariesTriggerID = _instanceID;

                ProCamera2D.UseLeftBoundary = UseLeftBoundary;
                if (UseLeftBoundary)
                {
                    ProCamera2D.LeftBoundary = ProCamera2D.TargetLeftBoundary = _targetLeftBoundary;
                }

                ProCamera2D.UseRightBoundary = UseRightBoundary;
                if (UseRightBoundary)
                {
                    ProCamera2D.RightBoundary = ProCamera2D.TargetRightBoundary = _targetRightBoundary;
                }

                ProCamera2D.UseTopBoundary = UseTopBoundary;
                if (UseTopBoundary)
                {
                    ProCamera2D.TopBoundary = ProCamera2D.TargetTopBoundary = _targetTopBoundary;
                }

                ProCamera2D.UseBottomBoundary = UseBottomBoundary;
                if (UseBottomBoundary)
                {
                    ProCamera2D.BottomBoundary = ProCamera2D.TargetBottomBoundary = _targetBottomBoundary;
                }

                if (!UseTopBoundary && !UseBottomBoundary && !UseLeftBoundary && !UseRightBoundary)
                {
                    ProCamera2D.UseNumericBoundaries = false;
                }
                else
                {
                    ProCamera2D.UseNumericBoundaries = true;
                }
            }
        }
コード例 #14
0
        override protected void OnDrawGizmos()
        {
            // 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;
            }

            base.OnDrawGizmos();

            if (_gizmosDrawingFailed)
            {
                return;
            }

            float cameraDepthOffset = Vector3D(ProCamera2D.transform.position) + 5f * Vector3D(ProCamera2D.transform.forward);
            var   cameraCenter      = VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset);
            var   cameraDimensions  = Utils.GetScreenSizeInWorldCoords(ProCamera2D.GetComponent <Camera>());

            GetTargetBoundaries();

            Gizmos.DrawIcon(VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset - .05f * Mathf.Sign(Vector3D(ProCamera2D.transform.position))), "ProCamera2D/gizmo_icon_bg.png", false);

            Gizmos.color = EditorPrefsX.GetColor(PrefsData.BoundariesTriggerColorKey, PrefsData.BoundariesTriggerColorValue);
            if (UseTopBoundary)
            {
                Gizmos.DrawRay(VectorHVD(Vector3H(transform.position) - cameraDimensions.x / 2, _targetTopBoundary, cameraDepthOffset), ProCamera2D.transform.right * cameraDimensions.x);
                Utils.DrawArrowForGizmo(cameraCenter, VectorHV(0, _targetTopBoundary - Vector3V(transform.position)));

                Gizmos.DrawIcon(VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset), "ProCamera2D/gizmo_icon_bound_top.png", false);
            }

            if (UseBottomBoundary)
            {
                Gizmos.DrawRay(VectorHVD(Vector3H(transform.position) - cameraDimensions.x / 2, _targetBottomBoundary, cameraDepthOffset), ProCamera2D.transform.right * cameraDimensions.x);
                Utils.DrawArrowForGizmo(cameraCenter, VectorHV(0, _targetBottomBoundary - Vector3V(transform.position)));

                Gizmos.DrawIcon(VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset), "ProCamera2D/gizmo_icon_bound_bottom.png", false);
            }

            if (UseRightBoundary)
            {
                Gizmos.DrawRay(VectorHVD(_targetRightBoundary, Vector3V(transform.position) - cameraDimensions.y / 2, cameraDepthOffset), ProCamera2D.transform.up * cameraDimensions.y);
                Utils.DrawArrowForGizmo(cameraCenter, VectorHV(_targetRightBoundary - Vector3H(transform.position), 0));

                Gizmos.DrawIcon(VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset), "ProCamera2D/gizmo_icon_bound_right.png", false);
            }

            if (UseLeftBoundary)
            {
                Gizmos.DrawRay(VectorHVD(_targetLeftBoundary, Vector3V(transform.position) - cameraDimensions.y / 2, cameraDepthOffset), ProCamera2D.transform.up * cameraDimensions.y);
                Utils.DrawArrowForGizmo(cameraCenter, VectorHV(_targetLeftBoundary - Vector3H(transform.position), 0));

                Gizmos.DrawIcon(VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset), "ProCamera2D/gizmo_icon_bound_left.png", false);
            }

            if (SetAsStartingBoundaries)
            {
                Gizmos.DrawIcon(VectorHVD(Vector3H(transform.position), Vector3V(transform.position), cameraDepthOffset), "ProCamera2D/gizmo_icon_start.png", false);
            }
        }
コード例 #15
0
 void GetPixelPerfectPlugin()
 {
     _pixelPerfectPlugin = ProCamera2D.GetComponent <ProCamera2DPixelPerfect>();
 }
コード例 #16
0
        protected override void OnDestroy()
        {
            base.OnDestroy();

            ProCamera2D.RemovePreMover(this);
        }
コード例 #17
0
        IEnumerator Transition()
        {
            if (!UseTopBoundary && !UseBottomBoundary && !UseLeftBoundary && !UseRightBoundary)
            {
                NumericBoundaries.UseNumericBoundaries = false;
                yield break;
            }

            // Avoid unnecessary transitions
            var skip = true;

            if ((UseTopBoundary && NumericBoundaries.TopBoundary != TopBoundary))
            {
                skip = false;
            }
            if ((UseBottomBoundary && NumericBoundaries.BottomBoundary != BottomBoundary))
            {
                skip = false;
            }
            if ((UseLeftBoundary && NumericBoundaries.LeftBoundary != LeftBoundary))
            {
                skip = false;
            }
            if ((UseRightBoundary && NumericBoundaries.RightBoundary != RightBoundary))
            {
                skip = false;
            }
            if (skip)
            {
                yield break;
            }

            NumericBoundaries.UseNumericBoundaries = true;

            GetTargetBoundaries();

            _boundsAnim.UseTopBoundary    = UseTopBoundary;
            _boundsAnim.TopBoundary       = _targetTopBoundary;
            _boundsAnim.UseBottomBoundary = UseBottomBoundary;
            _boundsAnim.BottomBoundary    = _targetBottomBoundary;
            _boundsAnim.UseLeftBoundary   = UseLeftBoundary;
            _boundsAnim.LeftBoundary      = _targetLeftBoundary;
            _boundsAnim.UseRightBoundary  = UseRightBoundary;
            _boundsAnim.RightBoundary     = _targetRightBoundary;

            _boundsAnim.TransitionDuration = TransitionDuration;
            _boundsAnim.TransitionEaseType = TransitionEaseType;

            // Zoom
            if (ChangeZoom)
            {
                ProCamera2D.UpdateScreenSize(_initialCamSize / TargetZoom, ZoomSmoothness, TransitionEaseType);
            }


            // Move camera "manually"
            if (_boundsAnim.GetAnimsCount() > 1)
            {
                if (NumericBoundaries.MoveCameraToTargetRoutine != null)
                {
                    NumericBoundaries.StopCoroutine(NumericBoundaries.MoveCameraToTargetRoutine);
                }

                NumericBoundaries.MoveCameraToTargetRoutine = NumericBoundaries.StartCoroutine(MoveCameraToTarget());
            }

            // Start bounds animation
            yield return(new WaitForEndOfFrame());

            _boundsAnim.Transition();
        }
コード例 #18
0
        void ApplyInfluence(float deltaTime)
        {
            var currentHVel = Vector3H(ProCamera2D.TargetsMidPoint) - Vector3H(ProCamera2D.PreviousTargetsMidPoint);

            if (Mathf.Abs(currentHVel) < MovementThreshold.x)
            {
                currentHVel = 0f;
            }
            else
            {
                currentHVel /= deltaTime;
            }

            var currentVVel = Vector3V(ProCamera2D.TargetsMidPoint) - Vector3V(ProCamera2D.PreviousTargetsMidPoint);

            if (Mathf.Abs(currentVVel) < MovementThreshold.y)
            {
                currentVVel = 0f;
            }
            else
            {
                currentVVel /= deltaTime;
            }

            if (Progressive)
            {
                currentHVel = Mathf.Clamp(currentHVel * SpeedMultiplier, -LeftFocus * ProCamera2D.ScreenSizeInWorldCoordinates.x, RightFocus * ProCamera2D.ScreenSizeInWorldCoordinates.x);
                currentVVel = Mathf.Clamp(currentVVel * SpeedMultiplier, -BottomFocus * ProCamera2D.ScreenSizeInWorldCoordinates.y, TopFocus * ProCamera2D.ScreenSizeInWorldCoordinates.y);

                if (MaintainInfluenceOnStop)
                {
                    if ((Mathf.Sign(currentHVel) == 1 && currentHVel < _hVel) ||
                        (Mathf.Sign(currentHVel) == -1 && currentHVel > _hVel) ||
                        (Mathf.Abs(currentHVel) < EPSILON))
                    {
                        currentHVel = _hVel;
                    }

                    if ((Mathf.Sign(currentVVel) == 1 && currentVVel < _vVel) ||
                        (Mathf.Sign(currentVVel) == -1 && currentVVel > _vVel) ||
                        (Mathf.Abs(currentVVel) < EPSILON))
                    {
                        currentVVel = _vVel;
                    }
                }
            }
            else
            {
                if (MaintainInfluenceOnStop)
                {
                    bool switchedHorizontalDirection;
                    if (!_isFirstHorizontalCameraMovement && !(Mathf.Abs(currentHVel) < EPSILON))
                    {
                        _isFirstHorizontalCameraMovement = true;
                        switchedHorizontalDirection      = true;
                    }
                    else
                    {
                        switchedHorizontalDirection = Mathf.Sign(currentHVel) != Mathf.Sign(_targetHVel);
                    }

                    if (!(Mathf.Abs(currentHVel) < EPSILON) && switchedHorizontalDirection)
                    {
                        _targetHVel = (currentHVel < 0f ? -LeftFocus : RightFocus) * ProCamera2D.ScreenSizeInWorldCoordinates.x;
                    }
                    currentHVel = _targetHVel;

                    bool switchedVerticalDirection;
                    if (!_isFirstVerticalCameraMovement && !(Mathf.Abs(currentVVel) < EPSILON))
                    {
                        _isFirstVerticalCameraMovement = true;
                        switchedVerticalDirection      = true;
                    }
                    else
                    {
                        switchedVerticalDirection = Mathf.Sign(currentVVel) != Mathf.Sign(_targetVVel);
                    }

                    if (!(Mathf.Abs(currentVVel) < EPSILON) && switchedVerticalDirection)
                    {
                        _targetVVel = (currentVVel < 0f ? -BottomFocus : TopFocus) * ProCamera2D.ScreenSizeInWorldCoordinates.y;
                    }
                    currentVVel = _targetVVel;
                }
                else
                {
                    if (!(Mathf.Abs(currentHVel) < EPSILON))
                    {
                        currentHVel = (currentHVel < 0f ? -LeftFocus : RightFocus) * ProCamera2D.ScreenSizeInWorldCoordinates.x;
                    }
                    else
                    {
                        currentHVel = 0;
                    }

                    if (!(Mathf.Abs(currentVVel) < EPSILON))
                    {
                        currentVVel = (currentVVel < 0f ? -BottomFocus : TopFocus) * ProCamera2D.ScreenSizeInWorldCoordinates.y;
                    }
                    else
                    {
                        currentVVel = 0;
                    }
                }
            }

            // We need to clamp the values again to account for camera zooms
            currentHVel = Mathf.Clamp(currentHVel, -LeftFocus * ProCamera2D.ScreenSizeInWorldCoordinates.x, RightFocus * ProCamera2D.ScreenSizeInWorldCoordinates.x);
            currentVVel = Mathf.Clamp(currentVVel, -BottomFocus * ProCamera2D.ScreenSizeInWorldCoordinates.y, TopFocus * ProCamera2D.ScreenSizeInWorldCoordinates.y);

            // Smooth the values
            _hVel = Mathf.SmoothDamp(_hVel, currentHVel, ref _hVelSmooth, TransitionSmoothness);
            _vVel = Mathf.SmoothDamp(_vVel, currentVVel, ref _vVelSmooth, TransitionSmoothness);

            // Apply the influence
            ProCamera2D.ApplyInfluence(new Vector2(_hVel, _vVel));
        }
コード例 #19
0
        protected void UpdateScreenSize(float smoothness)
        {
            _targetCamSizeSmoothed = Mathf.SmoothDamp(_targetCamSizeSmoothed, _targetCamSize, ref _zoomVelocity, smoothness);

            ProCamera2D.UpdateScreenSize(_targetCamSizeSmoothed);
        }
コード例 #20
0
        IEnumerator GoToCinematicTargetRoutine(CinematicTarget cinematicTarget, int targetIndex)
        {
            if (cinematicTarget.TargetTransform == null)
            {
                yield break;
            }

            var initialPosH = Vector3H(ProCamera2D.LocalPosition);
            var initialPosV = Vector3V(ProCamera2D.LocalPosition);

            var currentCameraSize = ProCamera2D.ScreenSizeInWorldCoordinates.y * .5f;

            // Ease in
            var t = 0f;

            if (cinematicTarget.EaseInDuration > 0)
            {
                while (t <= 1.0f)
                {
                    if (!_paused)
                    {
                        t += ProCamera2D.DeltaTime / cinematicTarget.EaseInDuration;

                        var newPosH = Utils.EaseFromTo(initialPosH, Vector3H(cinematicTarget.TargetTransform.position) - Vector3H(ProCamera2D.ParentPosition), t, cinematicTarget.EaseType);
                        var newPosV = Utils.EaseFromTo(initialPosV, Vector3V(cinematicTarget.TargetTransform.position) - Vector3V(ProCamera2D.ParentPosition), t, cinematicTarget.EaseType);

                        if (UseNumericBoundaries)
                        {
                            LimitToNumericBoundaries(ref newPosH, ref newPosV);
                        }

                        _newPos = VectorHVD(newPosH, newPosV, 0);

                        _newSize = Utils.EaseFromTo(currentCameraSize, _initialCameraSize / cinematicTarget.Zoom, t, cinematicTarget.EaseType);

                        if (_skipTarget)
                        {
                            yield break;
                        }
                    }

                    yield return(ProCamera2D.GetYield());
                }
            }
            else
            {
                var newPosH = Vector3H(cinematicTarget.TargetTransform.position) - Vector3H(ProCamera2D.ParentPosition);
                var newPosV = Vector3V(cinematicTarget.TargetTransform.position) - Vector3V(ProCamera2D.ParentPosition);
                _newPos = VectorHVD(newPosH, newPosV, 0);

                _newSize = _initialCameraSize / cinematicTarget.Zoom;
            }

            // Dispatch target reached event
            if (OnCinematicTargetReached != null)
            {
                OnCinematicTargetReached.Invoke(targetIndex);
            }

            // Send target reached message
            if (!string.IsNullOrEmpty(cinematicTarget.SendMessageName))
            {
                cinematicTarget.TargetTransform.SendMessage(cinematicTarget.SendMessageName, cinematicTarget.SendMessageParam, SendMessageOptions.DontRequireReceiver);
            }

            // Hold
            t = 0f;
            while (cinematicTarget.HoldDuration < 0 || t <= cinematicTarget.HoldDuration)
            {
                if (!_paused)
                {
                    t += ProCamera2D.DeltaTime;

                    var newPosH = Vector3H(cinematicTarget.TargetTransform.position) - Vector3H(ProCamera2D.ParentPosition);
                    var newPosV = Vector3V(cinematicTarget.TargetTransform.position) - Vector3V(ProCamera2D.ParentPosition);

                    if (UseNumericBoundaries)
                    {
                        LimitToNumericBoundaries(ref newPosH, ref newPosV);
                    }

                    _newPos = VectorHVD(newPosH, newPosV, 0);

                    if (_skipTarget)
                    {
                        yield break;
                    }
                }

                yield return(ProCamera2D.GetYield());
            }
        }
コード例 #21
0
        IEnumerator TransitionRoutine(NumericBoundariesSettings numericBoundariesSettings, float targetSize, float transitionDuration = 1f, EaseType transitionEaseType = EaseType.EaseOut)
        {
            _transitioning = true;

            // Disable the current numeric boundaries
            _numericBoundaries.UseNumericBoundaries = false;

            // Size
            var initialSize = ProCamera2D.ScreenSizeInWorldCoordinates.y / 2f;

            //Position
            var initialCamPosH = Vector3H(ProCamera2D.LocalPosition);
            var initialCamPosV = Vector3V(ProCamera2D.LocalPosition);

            // Transition
            var t = 0f;

            while (t <= 1.0f)
            {
                // Prevents a NaN error on some platforms
                if (transitionDuration < float.Epsilon)
                {
                    t = 1.1f;
                }
                else if (ProCamera2D.DeltaTime > float.Epsilon)
                {
                    t += ProCamera2D.DeltaTime / transitionDuration;
                }

                // Size
                _newSize = transitionDuration > 0 ? Utils.EaseFromTo(initialSize, targetSize, t, transitionEaseType) : targetSize;

                // Position
                var targetPosH = ProCamera2D.CameraTargetPositionSmoothed.x;
                var targetPosV = ProCamera2D.CameraTargetPositionSmoothed.y;

                LimitToNumericBoundaries(
                    ref targetPosH,
                    ref targetPosV,
                    targetSize * ProCamera2D.GameCamera.aspect,
                    targetSize,
                    numericBoundariesSettings);

                var newPosH = Utils.EaseFromTo(initialCamPosH, targetPosH, t, transitionEaseType);
                var newPosV = Utils.EaseFromTo(initialCamPosV, targetPosV, t, transitionEaseType);
                _newPos = VectorHVD(newPosH, newPosV, 0);

                if (transitionDuration > 0)
                {
                    yield return(ProCamera2D.GetYield());
                }
            }

            _transitioning = false;

            _numericBoundaries.Settings = numericBoundariesSettings;

            _transitionRoutine = null;

            if (OnFinishedTransition != null)
            {
                OnFinishedTransition.Invoke(_currentRoomIndex, _previousRoomIndex);
            }

            _previousRoomIndex = _currentRoomIndex;
        }
コード例 #22
0
        void Awake()
        {
            _instance = this;
            _transform = transform;

            // Get parent position
            if (_transform.parent != null)
                _parentPosition = _transform.parent.position;

            if (GameCamera == null)
                GameCamera = GetComponent<Camera>();
            if (GameCamera == null)
                Debug.LogError("Unity Camera not set and not found on the GameObject: " + gameObject.name);

            #if PC2D_TK2D_SUPPORT
            Tk2dCam = GetComponent<tk2dCamera>();
            #endif

            // Reset the axis functions
            ResetAxisFunctions();

            // Remove empty targets
            for (int i = 0; i < CameraTargets.Count; i++)
            {
                if (CameraTargets[i].TargetTransform == null)
                {
                    CameraTargets.RemoveAt(i);
                }
            }

            _screenSizeInWorldCoordinates = _startScreenSizeInWorldCoordinates = Utils.GetScreenSizeInWorldCoords(GameCamera, Mathf.Abs(Vector3D(_transform.localPosition)));

            _originalCameraDepthSign = Mathf.Sign(Vector3D(_transform.localPosition));
        }
コード例 #23
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            // Show script link
            GUI.enabled = false;
            _script     = EditorGUILayout.ObjectField("Script", _script, typeof(MonoScript), false) as MonoScript;
            GUI.enabled = true;

            // ProCamera2D
            _tooltip = new GUIContent("Pro Camera 2D", "");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("ProCamera2D"), _tooltip);

            if (_proCamera2DParallax.ProCamera2D == null)
            {
                EditorGUILayout.HelpBox("ProCamera2D is not set.", MessageType.Error, true);
            }

            _proCamera2D = _proCamera2DParallax.ProCamera2D;
            if (_proCamera2D == null)
            {
                serializedObject.ApplyModifiedProperties();
                return;
            }

            // Perspective camera
            if (!_proCamera2D.GameCamera.orthographic)
            {
                EditorGUILayout.HelpBox("ProCamera2D Parallax needs an orthographic projection camera to work.", MessageType.Error, true);
            }

            // Parallax layers List
            _parallaxLayersList.DoLayoutList();

            var areSpeedsNotOrdered    = false;
            var isLayerMaskEmpty       = false;
            var isLayerMaskOverlapping = false;

            for (int i = 0; i < _proCamera2DParallax.ParallaxLayers.Count; i++)
            {
                // Detect unordered speeds
                if (i < _proCamera2DParallax.ParallaxLayers.Count - 1)
                {
                    if (_proCamera2DParallax.ParallaxLayers[i].Speed > _proCamera2DParallax.ParallaxLayers[i + 1].Speed)
                    {
                        areSpeedsNotOrdered = true;
                    }
                }

                // Detect empty layer masks
                if (_proCamera2DParallax.ParallaxLayers[i].LayerMask.value == 0)
                {
                    isLayerMaskEmpty = true;
                }

                // Detect equal layer masks
                for (int j = 0; j < _proCamera2DParallax.ParallaxLayers.Count; j++)
                {
                    if (i != j && _proCamera2DParallax.ParallaxLayers[i].LayerMask.value == _proCamera2DParallax.ParallaxLayers[j].LayerMask.value)
                    {
                        isLayerMaskOverlapping = true;
                    }
                }

                // Remove layers with no camera assigned
                if (_proCamera2DParallax.ParallaxLayers[i].ParallaxCamera == null)
                {
                    _proCamera2DParallax.ParallaxLayers.RemoveAt(i);
                    EditorGUIUtility.ExitGUI();
                    continue;
                }

                // Apply layer masks as camera culling mask
                _proCamera2DParallax.ParallaxLayers[i].ParallaxCamera.cullingMask = _proCamera2DParallax.ParallaxLayers[i].LayerMask;

                // Setup clear flags
                if (_proCamera2DParallax.ParallaxLayers[0].Speed > 1)
                {
                    _proCamera2D.GameCamera.clearFlags = CameraClearFlags.SolidColor;
                    _proCamera2DParallax.ParallaxLayers[i].ParallaxCamera.clearFlags = CameraClearFlags.Depth;
                }
                else
                {
                    _proCamera2DParallax.ParallaxLayers[0].ParallaxCamera.clearFlags = CameraClearFlags.SolidColor;
                    _proCamera2D.GameCamera.clearFlags = CameraClearFlags.Depth;

                    if (i > 0)
                    {
                        _proCamera2DParallax.ParallaxLayers[i].ParallaxCamera.clearFlags = CameraClearFlags.Depth;
                    }
                }
            }

            // Show warnings
            if (areSpeedsNotOrdered)
            {
                EditorGUILayout.HelpBox("Parallax layer speeds are not ordered.", MessageType.Warning, true);
            }

            if (isLayerMaskEmpty)
            {
                EditorGUILayout.HelpBox("One or more layer mask is empty.", MessageType.Warning, true);
            }

            if (isLayerMaskOverlapping)
            {
                EditorGUILayout.HelpBox("Two or more cameras are rendering the same layers. Check your Layer Masks.", MessageType.Warning, true);
            }


            // Setup depths
            for (int i = 0; i < _proCamera2DParallax.ParallaxLayers.Count; i++)
            {
                if (_proCamera2DParallax.ParallaxLayers[i].Speed > 1)
                {
                    _proCamera2DParallax.ParallaxLayers[i].ParallaxCamera.depth = _proCamera2D.GameCamera.depth + (i + 1);
                }
                else
                {
                    _proCamera2DParallax.ParallaxLayers[i].ParallaxCamera.depth = _proCamera2D.GameCamera.depth - _proCamera2DParallax.ParallaxLayers.Count + (i);
                }
            }

            // Show correct axis name
            var hAxis = "";
            var vAxis = "";

            switch (_proCamera2D.Axis)
            {
            case MovementAxis.XY:
                hAxis = "X";
                vAxis = "Y";
                break;

            case MovementAxis.XZ:
                hAxis = "X";
                vAxis = "Z";
                break;

            case MovementAxis.YZ:
                hAxis = "Y";
                vAxis = "Z";
                break;
            }

            // Follow X
            _tooltip = new GUIContent("Parallax " + hAxis, "Should the parallax occur on the horizontal axis?");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("ParallaxHorizontal"), _tooltip);

            // Follow Y
            _tooltip = new GUIContent("Parallax " + vAxis, "Should the parallax occur on the vertical axis?");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("ParallaxVertical"), _tooltip);

            // Root Position
            _tooltip = new GUIContent("Root Position", "The position at which your camera is going to start.");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("RootPosition"), _tooltip);

            // Reset offset button
            if (GUILayout.Button("Set Root Position"))
            {
                switch (_proCamera2D.Axis)
                {
                case MovementAxis.XY:
                    _proCamera2DParallax.RootPosition = new Vector3(_proCamera2D.transform.localPosition.x, _proCamera2D.transform.localPosition.y, 0);
                    break;

                case MovementAxis.XZ:
                    _proCamera2DParallax.RootPosition = new Vector3(_proCamera2D.transform.localPosition.x, 0, _proCamera2D.transform.localPosition.z);
                    break;

                case MovementAxis.YZ:
                    _proCamera2DParallax.RootPosition = new Vector3(0, _proCamera2D.transform.localPosition.y, _proCamera2D.transform.localPosition.z);
                    break;
                }
            }


            if (serializedObject.ApplyModifiedProperties())
            {
                for (int i = 0; i < _proCamera2DParallax.ParallaxLayers.Count; i++)
                {
                    _proCamera2DParallax.ParallaxLayers[i].ParallaxCamera.gameObject.name = "ParallaxCamera (" + _proCamera2DParallax.ParallaxLayers[i].Speed + ")";
                }
            }
        }
コード例 #24
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            // Show script link
            _script = EditorGUILayout.ObjectField("Script", _script, typeof(MonoScript), false) as MonoScript;

            // ProCamera2D
            _tooltip = new GUIContent("Pro Camera 2D", "");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("ProCamera2D"), _tooltip);

            if (_proCamera2DParallax.ProCamera2D == null)
                EditorGUILayout.HelpBox("ProCamera2D is not set.", MessageType.Error, true);

            _proCamera2D = _proCamera2DParallax.ProCamera2D;
            if (_proCamera2D == null)
            {
                serializedObject.ApplyModifiedProperties();
                return;
            }

            // Parallax layers List
            _parallaxLayersList.DoLayoutList();

            var areSpeedsNotOrdered = false;
            var isLayerMaskEmpty = false;
            var isLayerMaskOverlapping = false;
            for (int i = 0; i < _proCamera2DParallax.ParallaxLayers.Count; i++)
            {
                // Detect unordered speeds
                if (i < _proCamera2DParallax.ParallaxLayers.Count - 1)
                {
                    if (_proCamera2DParallax.ParallaxLayers[i].Speed > _proCamera2DParallax.ParallaxLayers[i + 1].Speed)
                        areSpeedsNotOrdered = true;
                }

                // Detect empty layer masks
                if (_proCamera2DParallax.ParallaxLayers[i].LayerMask.value == 0)
                    isLayerMaskEmpty = true;

                // Detect equal layer masks
                for (int j = 0; j < _proCamera2DParallax.ParallaxLayers.Count; j++)
                {
                    if (i != j && _proCamera2DParallax.ParallaxLayers[i].LayerMask.value == _proCamera2DParallax.ParallaxLayers[j].LayerMask.value)
                        isLayerMaskOverlapping = true;
                }

                // Remove layers with no camera assigned
                if (_proCamera2DParallax.ParallaxLayers[i].ParallaxCamera == null)
                {
                    _proCamera2DParallax.ParallaxLayers.RemoveAt(i);
                    EditorGUIUtility.ExitGUI();
                    continue;
                }
                
                // Apply layer masks as camera culling mask
                _proCamera2DParallax.ParallaxLayers[i].ParallaxCamera.cullingMask = _proCamera2DParallax.ParallaxLayers[i].LayerMask;

                // Setup clear flags
                if (_proCamera2DParallax.ParallaxLayers[0].Speed > 1)
                {
                    _proCamera2D.GameCamera.clearFlags = CameraClearFlags.SolidColor;
                    _proCamera2DParallax.ParallaxLayers[i].ParallaxCamera.clearFlags = CameraClearFlags.Depth;
                }
                else
                {
                    _proCamera2DParallax.ParallaxLayers[0].ParallaxCamera.clearFlags = CameraClearFlags.SolidColor;
                    _proCamera2D.GameCamera.clearFlags = CameraClearFlags.Depth;

                    if (i > 0)
                        _proCamera2DParallax.ParallaxLayers[i].ParallaxCamera.clearFlags = CameraClearFlags.Depth;
                }
            }

            // Show warnings
            if (areSpeedsNotOrdered)
                EditorGUILayout.HelpBox("Parallax layer speeds are not ordered.", MessageType.Warning, true);

            if (isLayerMaskEmpty)
                EditorGUILayout.HelpBox("One or more layer mask is empty.", MessageType.Warning, true);

            if (isLayerMaskOverlapping)
                EditorGUILayout.HelpBox("Two or more cameras are rendering the same layers. Check your Layer Masks.", MessageType.Warning, true);


            // Setup depths
            for (int i = 0; i < _proCamera2DParallax.ParallaxLayers.Count; i++)
            {
                if (_proCamera2DParallax.ParallaxLayers[i].Speed > 1)
                    _proCamera2DParallax.ParallaxLayers[i].ParallaxCamera.depth = _proCamera2D.GameCamera.depth + (i + 1);
                else
                    _proCamera2DParallax.ParallaxLayers[i].ParallaxCamera.depth = _proCamera2D.GameCamera.depth - _proCamera2DParallax.ParallaxLayers.Count + (i);
            }

            // Show correct axis name
            var hAxis = "";
            var vAxis = "";
            switch (_proCamera2D.Axis)
            {
                case MovementAxis.XY:
                    hAxis = "X";
                    vAxis = "Y";
                    break;

                case MovementAxis.XZ:
                    hAxis = "X";
                    vAxis = "Z";
                    break;

                case MovementAxis.YZ:
                    hAxis = "Y";
                    vAxis = "Z";
                    break;
            }

            // Follow X
            _tooltip = new GUIContent("Parallax " + hAxis, "Should the parallax occur on the horizontal axis?");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("ParallaxHorizontal"), _tooltip);

            // Follow Y
            _tooltip = new GUIContent("Parallax " + vAxis, "Should the parallax occur on the vertical axis?");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("ParallaxVertical"), _tooltip);

            // Root Position
            _tooltip = new GUIContent("Root Position", "The position at which your camera is going to start.");
            EditorGUILayout.PropertyField(serializedObject.FindProperty("RootPosition"), _tooltip);

            // Reset offset button
            if (GUILayout.Button("Set Root Position"))
            {
                switch (_proCamera2D.Axis)
                {
                    case MovementAxis.XY:
                        _proCamera2DParallax.RootPosition = new Vector3(_proCamera2D.transform.localPosition.x, _proCamera2D.transform.localPosition.y, 0);
                        break;

                    case MovementAxis.XZ:
                        _proCamera2DParallax.RootPosition = new Vector3(_proCamera2D.transform.localPosition.x, 0, _proCamera2D.transform.localPosition.z);
                        break;

                    case MovementAxis.YZ:
                        _proCamera2DParallax.RootPosition = new Vector3(0, _proCamera2D.transform.localPosition.y, _proCamera2D.transform.localPosition.z);
                        break;
                }
            }


            serializedObject.ApplyModifiedProperties();
        }
コード例 #25
0
        void OnEnable()
        {
            ProCamera2DEditorHelper.AssignProCamera2D(target as BasePC2D);

            _proCamera2DParallax = (ProCamera2DParallax)target;

            _proCamera2D = _proCamera2DParallax.ProCamera2D;

            _script = MonoScript.FromMonoBehaviour(_proCamera2DParallax);

            // Parallax layers List
            _parallaxLayersList = new ReorderableList(serializedObject, serializedObject.FindProperty("ParallaxLayers"), false, true, true, true);

            // Draw element callback
            _parallaxLayersList.drawElementCallback = (rect, index, isActive, isFocused) =>
            {
                rect.y += 2;
                var element = _parallaxLayersList.serializedProperty.GetArrayElementAtIndex(index);

                #if UNITY_5
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y, 65, 10), new GUIContent("Camera", "The parallax camera"), EditorStyles.boldLabel);
                #else
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y, 65, 10), new GUIContent("Camera", "The parallax camera"));
                #endif
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 65,
                                            rect.y,
                                            80,
                                            EditorGUIUtility.singleLineHeight),
                                        element.FindPropertyRelative("ParallaxCamera"), GUIContent.none);


                // Speed slider
                #if UNITY_5
                EditorGUI.PrefixLabel(new Rect(rect.x + 170, rect.y, 65, 10), new GUIContent("Speed", "The relative speed at which the camera should move in comparison to the main camera."), EditorStyles.boldLabel);
                #else
                EditorGUI.PrefixLabel(new Rect(rect.x + 170, rect.y, 65, 10), new GUIContent("Speed", "The relative speed at which the camera should move in comparison to the main camera."));
                #endif
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 210,
                                            rect.y,
                                            rect.width - 210,
                                            EditorGUIUtility.singleLineHeight),
                                        element.FindPropertyRelative("Speed"), GUIContent.none);


                // Layer mask
                #if UNITY_5
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y + 25, 65, 10), new GUIContent("Culling Mask", "Which layers should this camera render?"), EditorStyles.boldLabel);
                #else
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y + 25, 65, 10), new GUIContent("Culling Mask", "Which layers should this camera render?"));
                #endif
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 85,
                                            rect.y + 25,
                                            rect.width - 85,
                                            EditorGUIUtility.singleLineHeight),
                                        element.FindPropertyRelative("LayerMask"), GUIContent.none);
            };

            // Draw header callback
            _parallaxLayersList.drawHeaderCallback = rect => EditorGUI.LabelField(rect, "Parallax layers");

            // Add element callback
            _parallaxLayersList.onAddCallback = list => AddParallaxLayer();

            // Remove element callback
            _parallaxLayersList.onRemoveCallback = list =>
            {
                if (EditorUtility.DisplayDialog("Warning!", "Are you sure you want to delete this layer?", "Yes", "No"))
                {
                    var cam = list.serializedProperty.GetArrayElementAtIndex(list.index).FindPropertyRelative("ParallaxCamera").objectReferenceValue as Camera;
                    if (cam != null)
                    {
                        DestroyImmediate(cam.gameObject);
                    }

                    ReorderableList.defaultBehaviours.DoRemoveButton(list);
                }
            };

            // Select element callback
            _parallaxLayersList.onSelectCallback = list =>
            {
                EditorGUIUtility.PingObject(list.serializedProperty.GetArrayElementAtIndex(list.index).FindPropertyRelative("ParallaxCamera").objectReferenceValue as Camera);
            };

            _parallaxLayersList.elementHeight = 65;
            _parallaxLayersList.headerHeight  = 18;
            _parallaxLayersList.draggable     = true;
        }
コード例 #26
0
ファイル: ProCamera2D.cs プロジェクト: EunoiaGames/MTW
        void Awake()
        {
            _instance = this;
            _transform = transform;

            if (GameCamera == null)
                GameCamera = GetComponent<Camera>();
            if (GameCamera == null)
                Debug.LogError("Unity Camera not set and not found on the GameObject: " + gameObject.name);

            #if PC2D_TK2D_SUPPORT
            Tk2dCam = GetComponent<tk2dCamera>();
            #endif

            switch (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;
            }

            // Remove empty targets
            for (int i = 0; i < CameraTargets.Count; i++)
            {
                if (CameraTargets[i].TargetTransform == null)
                {
                    CameraTargets.RemoveAt(i);
                }
            }

            ScreenSizeInWorldCoordinates = Utils.GetScreenSizeInWorldCoords(GameCamera, Mathf.Abs(Vector3D(_transform.localPosition)));

            _cameraDepthPos = Vector3D(_transform.localPosition);
            _originalCameraDepthSign = Mathf.Sign(_cameraDepthPos);

            _transform.parent = new GameObject(gameObject.name + " Container").transform;

            // Center on target
            if (CenterTargetOnStart && CameraTargets.Count > 0)
            {
                var targetPos = GetTargetsWeightedMidPoint(CameraTargets);
                var cameraTargetPositionX = FollowHorizontal ? Vector3H(targetPos) : Vector3H(_transform.localPosition);
                var cameraTargetPositionY = FollowVertical ? Vector3V(targetPos) : Vector3V(_transform.localPosition);
                targetPos = VectorHV(cameraTargetPositionX, cameraTargetPositionY);
                targetPos += VectorHV(OverallOffset.x, OverallOffset.y);
                MoveCameraInstantlyToPosition(targetPos);
            }
            else
            {
                _cameraTargetPosition = _transform.localPosition;
                _cameraTargetHorizontalPositionSmoothed = Vector3H(_cameraTargetPosition);
                _previousCameraTargetHorizontalPositionSmoothed = _cameraTargetHorizontalPositionSmoothed;
                _cameraTargetVerticalPositionSmoothed = Vector3V(_cameraTargetPosition);
                _previousCameraTargetVerticalPositionSmoothed = _cameraTargetVerticalPositionSmoothed;
            }
        }
コード例 #27
0
        protected override void Awake()
        {
            base.Awake();

            ProCamera2D.AddPositionDeltaChanger(this);
        }
コード例 #28
0
        void OnDrawGizmos()
        {
            if (!enabled)
                return;

            if (ProCamera2D == null && Camera.main != null)
                ProCamera2D = Camera.main.GetComponent<ProCamera2D>();

            if (ProCamera2D == null)
                return;

            // Don't draw gizmos on other cameras
            if (Camera.current != ProCamera2D.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();
        }
コード例 #29
0
ファイル: ProCamera2D.cs プロジェクト: sdsunrunner/Swardman
        void Awake()
        {
            _instance  = this;
            _transform = transform;

            if (GameCamera == null)
            {
                GameCamera = GetComponent <Camera>();
            }
            if (GameCamera == null)
            {
                Debug.LogError("Unity Camera not set and not found on the GameObject: " + gameObject.name);
            }

#if PC2D_TK2D_SUPPORT
            Tk2dCam = GetComponent <tk2dCamera>();
#endif

            switch (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;
            }

            // Remove empty targets
            for (int i = 0; i < CameraTargets.Count; i++)
            {
                if (CameraTargets[i].TargetTransform == null)
                {
                    CameraTargets.RemoveAt(i);
                }
            }

            ScreenSizeInWorldCoordinates = _startScreenSizeInWorldCoordinates = Utils.GetScreenSizeInWorldCoords(GameCamera, Mathf.Abs(Vector3D(_transform.localPosition)));

            _cameraDepthPos          = Vector3D(_transform.localPosition);
            _originalCameraDepthSign = Mathf.Sign(_cameraDepthPos);

            // Center on target
            if (CenterTargetOnStart && CameraTargets.Count > 0)
            {
                var targetsMidPoint       = GetTargetsWeightedMidPoint(CameraTargets);
                var cameraTargetPositionX = FollowHorizontal ? Vector3H(targetsMidPoint) : Vector3H(_transform.localPosition);
                var cameraTargetPositionY = FollowVertical ? Vector3V(targetsMidPoint) : Vector3V(_transform.localPosition);
                var finalPos = new Vector2(cameraTargetPositionX, cameraTargetPositionY);
                finalPos += new Vector2(OverallOffset.x, OverallOffset.y);
                MoveCameraInstantlyToPosition(finalPos);
            }
            else
            {
                _cameraTargetPosition = _transform.localPosition;
                _cameraTargetHorizontalPositionSmoothed         = Vector3H(_cameraTargetPosition);
                _previousCameraTargetHorizontalPositionSmoothed = _cameraTargetHorizontalPositionSmoothed;
                _cameraTargetVerticalPositionSmoothed           = Vector3V(_cameraTargetPosition);
                _previousCameraTargetVerticalPositionSmoothed   = _cameraTargetVerticalPositionSmoothed;
            }
        }