Exemplo n.º 1
0
        public void Start()
        {
            if (boxCollider == null)
            {
                Debug.LogError("This script requires a box collider to be assigned.");
                return;
            }

            MobileTouchCamera mobileTouchCam = GetComponent <MobileTouchCamera>();

            var boxMin = boxCollider.bounds.min;
            var boxMax = boxCollider.bounds.max;

            if (mobileTouchCam.CameraAxes == CameraPlaneAxes.XY_2D_SIDESCROLL)
            {
                mobileTouchCam.BoundaryMin = new Vector2(boxMin.x, boxMin.y);
                mobileTouchCam.BoundaryMax = new Vector2(boxMax.x, boxMax.y);
            }
            else
            {
                mobileTouchCam.BoundaryMin = new Vector2(boxMin.x, boxMin.z);
                mobileTouchCam.BoundaryMax = new Vector2(boxMax.x, boxMax.z);
            }
            mobileTouchCam.ResetCameraBoundaries();
        }
Exemplo n.º 2
0
        private void NormalizePosAndRot(Vector3 focusPosition, float zoom, ref Vector3 pos, ref Quaternion rot)
        {
            float tiltTarget;

            if (MobileTouchCamera.EnableZoomTilt)
            {
                float zoomProgress = Mathf.Clamp01((zoom - MobileTouchCamera.CamZoomMin) / (MobileTouchCamera.CamZoomMax - MobileTouchCamera.CamZoomMin));
                tiltTarget = Mathf.Lerp(MobileTouchCamera.ZoomTiltAngleMin, MobileTouchCamera.ZoomTiltAngleMax, zoomProgress);
            }
            else
            {
                tiltTarget = MobileTouchCamera.GetCurrentTileAngleDeg();
            }
            float   tiltTargetRadian  = Mathf.Deg2Rad * tiltTarget;
            Vector3 right             = MobileTouchCamera.Transform.right;
            Vector3 camForwardOnPlane = Vector3.Cross(MobileTouchCamera.RefPlane.normal, right);

            pos = focusPosition + camForwardOnPlane * zoom * Mathf.Cos(tiltTargetRadian) + MobileTouchCamera.RefPlane.normal * zoom * Mathf.Sin(tiltTargetRadian);
            Vector3   forward = (focusPosition - pos).normalized;
            Vector3   up      = Vector3.Cross(forward, right);
            Matrix4x4 matrix  = new Matrix4x4(right, up, forward, new Vector4(0, 0, 0, 1));

            rot = matrix.rotation;
            MobileTouchCamera.Transform.rotation = rot;
            Vector3 intersectionScreenFocusEnd  = MobileTouchCamera.GetIntersectionPoint(MobileTouchCamera.Cam.ScreenPointToRay(new Vector3(Screen.width * focusScreenPos.x, Screen.height * focusScreenPos.y, 0)));
            Vector3 intersectionScreenCenterEnd = MobileTouchCamera.GetIntersectionPoint(MobileTouchCamera.Cam.ScreenPointToRay(new Vector3(Screen.width * 0.5f, Screen.height * 0.5f, 0)));

            pos += (intersectionScreenCenterEnd - intersectionScreenFocusEnd);

            MobileTouchCamera.CamZoom = zoom;
        }
        /// <summary>
        /// Method to swap the boundary min/max values in case they aren't right.
        /// </summary>
        private void CheckSwapBoundary(MobileTouchCamera mobileTouchCamera)
        {
            Vector2 boundaryMin = mobileTouchCamera.BoundaryMin;
            Vector2 boundaryMax = mobileTouchCamera.BoundaryMax;

            //Automatically swap min with max when necessary.
            bool autoSwap = false;

            if (boundaryMax.x < boundaryMin.x)
            {
                Undo.RecordObject(target, "Mobile Touch Camera Boundary Auto Swap");
                Swap(ref boundaryMax.x, ref boundaryMin.x);
                autoSwap = true;
            }
            if (boundaryMax.y < boundaryMin.y)
            {
                Undo.RecordObject(target, "Mobile Touch Camera Boundary Auto Swap");
                Swap(ref boundaryMax.y, ref boundaryMin.y);
                autoSwap = true;
            }

            if (autoSwap == true)
            {
                EditorUtility.SetDirty(mobileTouchCamera);
            }

            mobileTouchCamera.BoundaryMin = boundaryMin;
            mobileTouchCamera.BoundaryMax = boundaryMax;
        }
Exemplo n.º 4
0
        public void FocusCameraOnTarget(Vector3 targetPosition, Quaternion targetRotation, float targetZoom)
        {
            timeTransitionStart = Time.time;
            posTransitionStart  = Transform.position;
            rotTransitionStart  = Transform.rotation;
            zoomTransitionStart = MobileTouchCamera.CamZoom;
            rotTransitionEnd    = targetRotation;
            zoomTransitionEnd   = targetZoom;

            MobileTouchCamera.CamZoom            = targetZoom;
            MobileTouchCamera.Transform.rotation = targetRotation;
            Vector3 intersectionScreenCenterEnd = MobileTouchCamera.GetIntersectionPoint(MobileTouchCamera.Cam.ScreenPointToRay(new Vector3(Screen.width * focusScreenPos.x, Screen.height * focusScreenPos.y, 0)));
            Vector3 focusVector = targetPosition - intersectionScreenCenterEnd;

            posTransitionEnd = posTransitionStart + focusVector;

            NormalizePosAndRot(targetPosition, targetZoom, ref posTransitionEnd, ref rotTransitionEnd);


            posTransitionEnd = MobileTouchCamera.GetClampToBoundaries(posTransitionEnd, true);

            MobileTouchCamera.Transform.rotation = rotTransitionStart;
            MobileTouchCamera.CamZoom            = zoomTransitionStart;

            if (Mathf.Approximately(transitionDuration, 0))
            {
                SetTransform(posTransitionEnd, rotTransitionEnd, zoomTransitionEnd);
                return;
            }

            isTransitionStarted = true;
        }
Exemplo n.º 5
0
 void Awake()
 {
     // BitBenderGames
     mobileTouchCamera = FindObjectOfType <BitBenderGames.MobileTouchCamera>();
     costs             = FindObjectOfType <Costs>();
     soundInterface    = FindObjectOfType <SoundInterface>();
 }
Exemplo n.º 6
0
        private Vector3 DrawOneWayHandle(MobileTouchCamera mobileTouchCamera, float handleSize, Vector2 pRelative, float offset)
        {
            Vector3 point    = mobileTouchCamera.UnprojectVector2(pRelative, offset);
            Vector3 pointNew = Handles.FreeMoveHandle(point, Quaternion.identity, handleSize, Vector3.one, Handles.DotCap);

            return(mobileTouchCamera.ProjectVector3(pointNew));
        }
        private void KeepinCenter(Vector3 targetPosition, Quaternion targetRotation, float targetZoom)
        {
//			Debug.Log ("target zoom "+ targetZoom);
            timeTransitionStart = Time.time;
            posTransitionStart  = Transform.position;
            rotTransitionStart  = Transform.rotation;
            zoomTransitionStart = MobileTouchCamera.CamZoom;
            rotTransitionEnd    = targetRotation;
            zoomTransitionEnd   = targetZoom;



            MobileTouchCamera.Transform.rotation = targetRotation;
            MobileTouchCamera.CamZoom            = targetZoom;
            Vector3 intersectionScreenCenterEnd = MobileTouchCamera.GetIntersectionPoint(MobileTouchCamera.Cam.ScreenPointToRay(new Vector3(Screen.width * 0.5f, Screen.height * 0.5f, 0)));
            Vector3 focusVector = targetPosition - intersectionScreenCenterEnd;

            posTransitionEnd = MobileTouchCamera.GetClampToBoundaries(posTransitionStart + focusVector, true);
            MobileTouchCamera.Transform.rotation = rotTransitionStart;
            MobileTouchCamera.CamZoom            = zoomTransitionStart;

            if (Mathf.Approximately(transitionDuration, 0))
            {
                SetTransform(posTransitionEnd, targetRotation, targetZoom);
                return;
            }

            isTransitionStarted = true;
        }
        private Vector3 GetIntersectionPoint(MobileTouchCamera mobileTouchCamera, Ray ray)
        {
            var   RefPlane = new Plane(new Vector3(0, 0, -1), mobileTouchCamera.GroundLevelOffset);
            var   Cam      = mobileTouchCamera.GetComponent <Camera>();
            float distance = 0;
            bool  success  = RefPlane.Raycast(ray, out distance);

            return(ray.origin + ray.direction * distance);
        }
Exemplo n.º 9
0
 public void Awake()
 {
     mobileTouchCam = FindObjectOfType <MobileTouchCamera>();
     if (mobileTouchCam == null)
     {
         Debug.LogError("No MobileTouchCamera found in scene. This script will not work without this.");
     }
     touchInputController = mobileTouchCam.GetComponent <TouchInputController>();
     if (touchInputController == null)
     {
         Debug.LogError("No TouchInputController found in scene. Make sure this component exists and is attached to the MobileTouchCamera gameObject.");
     }
 }
Exemplo n.º 10
0
 public void Start()
 {
     instance = this;
     touchInputController.OnInputClick  += InputControllerOnInputClick;
     touchInputController.OnDragStart   += InputControllerOnDragStart;
     touchInputController.OnDragUpdate  += InputControllerOnDragUpdate;
     touchInputController.OnDragStop    += InputControllerOnDragStop;
     touchInputController.OnFingerDown  += InputControllerOnFingerDown;
     touchInputController.OnFingerUp    += InputControllerOnFingerUp;
     touchInputController.OnPinchStart  += InputControllerOnPinchStart;
     touchInputController.OnPinchUpdate += InputControllerOnPinchUpdate;
     touchInputController.OnPinchStop   += InputControllerOnPinchStop;
     isStarted = true;
 }
Exemplo n.º 11
0
        private void NormalizeRoot(MobileTouchCamera mobileTouchCamera)
        {
            var     cam      = mobileTouchCamera.GetComponent <Camera>();
            Vector3 camRight = GetIntersectionPoint(mobileTouchCamera, cam.ScreenPointToRay(new Vector3(Screen.width, Screen.height * 0.5f, 0)));
            Vector3 camLeft  = GetIntersectionPoint(mobileTouchCamera, cam.ScreenPointToRay(new Vector3(0, Screen.height * 0.5f, 0)));

            Vector2 Dir2d       = new Vector2(camRight.x - camLeft.x, camRight.y - camLeft.y);
            float   angleOffset = Vector2.SignedAngle(Dir2d, Vector2.right);

            if (Mathf.Abs(angleOffset) > 0.001f)
            {
                mobileTouchCamera.transform.root.eulerAngles = new Vector3(0, 0, angleOffset);
                EditorUtility.SetDirty(mobileTouchCamera.transform.root);
            }
        }
//		BorderScript borderScript;

        public void Awake()
        {
            cam = MobileTouchCamera.Instance.main;
            mobileTouchCamera       = cam.GetComponent <MobileTouchCamera> ();
            touchInputController    = cam.GetComponent <TouchInputController> ();
            mobilePickingController = cam.GetComponent <MobilePickingController> ();

            #region detail callbacks
            touchInputController.OnInputClick          += OnInputClick;
            touchInputController.OnDragStart           += OnDragStart;
            touchInputController.OnDragStop            += OnDragStop;
            touchInputController.OnDragUpdate          += OnDragUpdate;
            touchInputController.OnFingerDown          += OnFingerDown;
            touchInputController.OnPinchStart          += OnPinchStart;
            touchInputController.OnPinchStop           += OnPinchStop;
            touchInputController.OnPinchUpdateExtended += new TouchInputController.PinchUpdateExtendedDelegate(OnPinchUpdate);
            #endregion
        }
Exemplo n.º 13
0
        public void Awake()
        {
            cam = FindObjectOfType <Camera>();
            mobileTouchCamera       = cam.GetComponent <MobileTouchCamera>();
            touchInputController    = cam.GetComponent <TouchInputController>();
            mobilePickingController = cam.GetComponent <MobilePickingController>();

            #region detail callbacks
            touchInputController.OnInputClick  += new TouchInputController.InputClickDelegate(OnInputClick);
            touchInputController.OnDragStart   += new TouchInputController.Input1PositionDelegate(OnDragStart);
            touchInputController.OnDragStop    += new TouchInputController.DragStopDelegate(OnDragStop);
            touchInputController.OnDragUpdate  += new TouchInputController.DragUpdateDelegate(OnDragUpdate);
            touchInputController.OnFingerDown  += new TouchInputController.Input1PositionDelegate(OnFingerDown);
            touchInputController.OnPinchStart  += new TouchInputController.PinchStartDelegate(OnPinchStart);
            touchInputController.OnPinchStop   += new System.Action(OnPinchStop);
            touchInputController.OnPinchUpdate += new TouchInputController.PinchUpdateDelegate(OnPinchUpdate);
            #endregion

            ShowInfoText("Mobile Touch Camera Demo\nSwipe: Scroll\nPinch: Zoom\nTap: Pick Item", 5);
        }
Exemplo n.º 14
0
        public void Awake()
        {
            Application.targetFrameRate = 60;

            cam = FindObjectOfType <Camera>();
            mobileTouchCamera       = cam.GetComponent <MobileTouchCamera>();
            touchInputController    = cam.GetComponent <TouchInputController>();
            mobilePickingController = cam.GetComponent <MobilePickingController>();

            #region detail callbacks
            touchInputController.OnInputClick          += OnInputClick;
            touchInputController.OnDragStart           += OnDragStart;
            touchInputController.OnDragStop            += OnDragStop;
            touchInputController.OnDragUpdate          += OnDragUpdate;
            touchInputController.OnFingerDown          += OnFingerDown;
            touchInputController.OnPinchStart          += OnPinchStart;
            touchInputController.OnPinchStop           += OnPinchStop;
            touchInputController.OnPinchUpdateExtended += new TouchInputController.PinchUpdateExtendedDelegate(OnPinchUpdate);
            #endregion

            ShowInfoText("Mobile Touch Camera Demo\nSwipe: Scroll\nPinch: Zoom\nTap: Pick Item", introTextOnScreenTime);
        }
 public void Awake()
 {
     if (mobileTouchCam == null)
     {
         mobileTouchCam = FindObjectOfType <MobileTouchCamera>();
     }
     if (mobileTouchCam == null)
     {
         Debug.LogError("No MobileTouchCamera found in scene. This script will not work without this.");
     }
     if (pickableTransform == null)
     {
         pickableTransform = this.transform;
     }
     if (gameObject.GetComponent <Collider>() == null && gameObject.GetComponent <Collider2D>() == null)
     {
         Debug.LogError("MobileTouchPickable must be placed on a gameObject that also has a Collider or Collider2D component attached.");
     }
     if (mobileTouchCam.GetComponent <MobilePickingController>() == null) //Auto add picking controller component to mobile touch cam go.
     {
         mobileTouchCam.gameObject.AddComponent <MobilePickingController>();
     }
 }
Exemplo n.º 16
0
        public override void OnInspectorGUI()
        {
            MobileTouchCamera mobileTouchCamera = (MobileTouchCamera)target;

            DrawPropertyField("cameraAxes");
            DrawPropertyField("camZoomMin");
            DrawPropertyField("camZoomMax");
            DrawPropertyField("camOverzoomMargin");

            #region boundary
            SerializedProperty serializedPropertyBoundaryMin = serializedObject.FindProperty("boundaryMin");
            Vector2            vector2BoundaryMin            = serializedPropertyBoundaryMin.vector2Value;

            SerializedProperty serializedPropertyBoundaryMax = serializedObject.FindProperty("boundaryMax");
            Vector2            vector2BoundaryMax            = serializedPropertyBoundaryMax.vector2Value;

            const float sizeLabel      = 100;
            const float sizeFloatInput = 70;
            EditorGUILayout.LabelField(new GUIContent("Boundary", "These values define the scrolling borders for the camera. The camera will not scroll further than defined here."), EditorStyles.boldLabel);

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Top", GUILayout.Width(sizeLabel));
            GUILayout.FlexibleSpace();
            GUILayout.FlexibleSpace();
            vector2BoundaryMax.y = EditorGUILayout.FloatField(vector2BoundaryMax.y, GUILayout.Width(sizeFloatInput));
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Left/Right", GUILayout.Width(sizeLabel));
            GUILayout.FlexibleSpace();
            vector2BoundaryMin.x = EditorGUILayout.FloatField(vector2BoundaryMin.x, GUILayout.Width(sizeFloatInput));
            GUILayout.FlexibleSpace();
            vector2BoundaryMax.x = EditorGUILayout.FloatField(vector2BoundaryMax.x, GUILayout.Width(sizeFloatInput));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Bottom", GUILayout.Width(sizeLabel));
            GUILayout.FlexibleSpace();
            GUILayout.FlexibleSpace();
            vector2BoundaryMin.y = EditorGUILayout.FloatField(vector2BoundaryMin.y, GUILayout.Width(sizeFloatInput));
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            serializedPropertyBoundaryMin.vector2Value = vector2BoundaryMin;
            serializedPropertyBoundaryMax.vector2Value = vector2BoundaryMax;
            #endregion

            DrawPropertyField("camFollowFactor");
            DrawPropertyField("autoScrollDamp");
            DrawPropertyField("groundLevelOffset");
            GUI.enabled = mobileTouchCamera.GetComponent <Camera>().orthographic == false;
            DrawPropertyField("perspectiveZoomMode");
            GUI.enabled = true;

            DrawPropertyField("OnPickItem");
            DrawPropertyField("OnPickItem2D");
            DrawPropertyField("OnPickItemDoubleClick");
            DrawPropertyField("OnPickItem2DDoubleClick");

            if (GUI.changed)
            {
                serializedObject.ApplyModifiedProperties();
            }
        }
        public void OnSceneGUI()
        {
            MobileTouchCamera mobileTouchCamera = (MobileTouchCamera)target;

            if (Event.current.rawType == EventType.MouseUp)
            {
                CheckSwapBoundary(mobileTouchCamera);
            }

            Vector2 boundaryMin = mobileTouchCamera.BoundaryMin;
            Vector2 boundaryMax = mobileTouchCamera.BoundaryMax;

            float   offset       = mobileTouchCamera.GroundLevelOffset;
            Vector3 pBottomLeft  = mobileTouchCamera.UnprojectVector2(new Vector2(boundaryMin.x, boundaryMin.y), offset);
            Vector3 pBottomRight = mobileTouchCamera.UnprojectVector2(new Vector2(boundaryMax.x, boundaryMin.y), offset);
            Vector3 pTopLeft     = mobileTouchCamera.UnprojectVector2(new Vector2(boundaryMin.x, boundaryMax.y), offset);
            Vector3 pTopRight    = mobileTouchCamera.UnprojectVector2(new Vector2(boundaryMax.x, boundaryMax.y), offset);

            Handles.color = new Color(0, .4f, 1f, 1f);
            float handleSize = HandleUtility.GetHandleSize(mobileTouchCamera.Transform.position) * 0.1f;

            #region min/max handles
            pBottomLeft = DrawSphereHandle(pBottomLeft, handleSize);
            pTopRight   = DrawSphereHandle(pTopRight, handleSize);
            boundaryMin = mobileTouchCamera.ProjectVector3(pBottomLeft);
            boundaryMax = mobileTouchCamera.ProjectVector3(pTopRight);
            #endregion

            #region min/max handles that need to be remapped
            Vector3 pBottomRightNew = DrawSphereHandle(pBottomRight, handleSize);
            Vector3 pTopLeftNew     = DrawSphereHandle(pTopLeft, handleSize);

            if (Vector3.Distance(pBottomRight, pBottomRightNew) > 0)
            {
                Vector2 pBottomRight2d = mobileTouchCamera.ProjectVector3(pBottomRightNew);
                boundaryMin.y = pBottomRight2d.y;
                boundaryMax.x = pBottomRight2d.x;
            }
            if (Vector3.Distance(pTopLeft, pTopLeftNew) > 0)
            {
                Vector2 pTopLeftNew2d = mobileTouchCamera.ProjectVector3(pTopLeftNew);
                boundaryMin.x = pTopLeftNew2d.x;
                boundaryMax.y = pTopLeftNew2d.y;
            }
            #endregion

            #region one way handles
            Handles.color = new Color(1, 1, 1, 1);
            handleSize    = HandleUtility.GetHandleSize(mobileTouchCamera.Transform.position) * 0.05f;
            boundaryMax.x = DrawOneWayHandle(mobileTouchCamera, handleSize, new Vector2(boundaryMax.x, 0.5f * (boundaryMax.y + boundaryMin.y)), offset).x;
            boundaryMax.y = DrawOneWayHandle(mobileTouchCamera, handleSize, new Vector2(0.5f * (boundaryMax.x + boundaryMin.x), boundaryMax.y), offset).y;
            boundaryMin.x = DrawOneWayHandle(mobileTouchCamera, handleSize, new Vector2(boundaryMin.x, 0.5f * (boundaryMax.y + boundaryMin.y)), offset).x;
            boundaryMin.y = DrawOneWayHandle(mobileTouchCamera, handleSize, new Vector2(0.5f * (boundaryMax.x + boundaryMin.x), boundaryMin.y), offset).y;
            #endregion

            if (Vector2.Distance(mobileTouchCamera.BoundaryMin, boundaryMin) > float.Epsilon || Vector2.Distance(mobileTouchCamera.BoundaryMax, boundaryMax) > float.Epsilon)
            {
                Undo.RecordObject(target, "Mobile Touch Camera Boundary Modification");
                mobileTouchCamera.BoundaryMin = boundaryMin;
                mobileTouchCamera.BoundaryMax = boundaryMax;
                EditorUtility.SetDirty(mobileTouchCamera);
            }
        }
        public override void OnInspectorGUI()
        {
            MobileTouchCamera mobileTouchCamera = (MobileTouchCamera)target;

            DrawPropertyField("m_Script");

            string camAxesError = mobileTouchCamera.CheckCameraAxesErrors();
            bool   isAxesValid  = string.IsNullOrEmpty(camAxesError);

            DrawPropertyField("cameraAxes", isAxesValid);
            DrawErrorLine(camAxesError, Color.red);
            GUI.enabled = mobileTouchCamera.GetComponent <Camera>().orthographic == false;
            DrawPropertyField("perspectiveZoomMode");
            GUI.enabled = true;
            bool isZoomValid = mobileTouchCamera.CamZoomMax >= mobileTouchCamera.CamZoomMin;

            DrawPropertyField("camZoomMin", isZoomValid);
            DrawPropertyField("camZoomMax", isZoomValid);
            if (isZoomValid == false)
            {
                DrawErrorLine("Cam Zoom Max must be bigger than Cam Zoom Min", Color.red);
            }
            DrawPropertyField("camOverzoomMargin");
            DrawPropertyField("camOverdragMargin");

            #region boundary
            SerializedProperty serializedPropertyBoundaryMin = serializedObject.FindProperty("boundaryMin");
            Vector2            vector2BoundaryMin            = serializedPropertyBoundaryMin.vector2Value;

            SerializedProperty serializedPropertyBoundaryMax = serializedObject.FindProperty("boundaryMax");
            Vector2            vector2BoundaryMax            = serializedPropertyBoundaryMax.vector2Value;

            EditorGUILayout.LabelField(new GUIContent("Boundary", "These values define the scrolling borders for the camera. The camera will not scroll further than defined here. The boundary is drawn as yellow rectangular gizmo in the scene-view when the camera is selected."), EditorStyles.boldLabel);

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Top", GUILayout.Width(sizeLabel));
            GUILayout.FlexibleSpace();
            GUILayout.FlexibleSpace();
            bool isBoundaryYValid = vector2BoundaryMax.y >= vector2BoundaryMin.y;
            bool isBoundaryXValid = vector2BoundaryMax.x >= vector2BoundaryMin.x;
            WrapWithValidationColor(() => {
                vector2BoundaryMax.y = EditorGUILayout.FloatField(vector2BoundaryMax.y, GUILayout.Width(sizeFloatInput));
            }, isBoundaryYValid);
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            WrapWithValidationColor(() => {
                Draw2FloatFields("Left/Right", ref vector2BoundaryMin.x, ref vector2BoundaryMax.x);
            }, isBoundaryXValid);

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Bottom", GUILayout.Width(sizeLabel));
            GUILayout.FlexibleSpace();
            GUILayout.FlexibleSpace();
            WrapWithValidationColor(() => {
                vector2BoundaryMin.y = EditorGUILayout.FloatField(vector2BoundaryMin.y, GUILayout.Width(sizeFloatInput));
            }, isBoundaryYValid);
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            if (isBoundaryYValid == false)
            {
                DrawErrorLine("The value for Top needs to be bigger\nthan the value for Bottom.", Color.red);
            }
            if (isBoundaryXValid == false)
            {
                DrawErrorLine("The value for Right needs to be bigger\nthan the value for Left.", Color.red);
            }

            serializedPropertyBoundaryMin.vector2Value = vector2BoundaryMin;
            serializedPropertyBoundaryMax.vector2Value = vector2BoundaryMax;
            #endregion

            DrawPropertyField("camFollowFactor");

            #region auto scroll damp
            AutoScrollDampMode selectedDampMode = (AutoScrollDampMode)serializedObject.FindProperty("autoScrollDampMode").enumValueIndex;
            if (selectedDampMode == AutoScrollDampMode.DEFAULT && mobileTouchCamera.AutoScrollDamp != 300)
            {
                serializedObject.FindProperty("autoScrollDampMode").enumValueIndex = (int)AutoScrollDampMode.CUSTOM; //Set selected mode to custom in case it was set to default but the damp wasn't the default value. This may happen for users that have changed the damp and upgraded from an older version of the asset.
                selectedDampMode = AutoScrollDampMode.CUSTOM;
            }
            DrawPropertyField("autoScrollDampMode");
            if (selectedDampMode == AutoScrollDampMode.CUSTOM)
            {
                DrawPropertyField("autoScrollDamp", true, true, subSettingsInset);
                DrawPropertyField("autoScrollDampCurve", true, true, subSettingsInset);
            }
            #endregion

            DrawPropertyField("groundLevelOffset");
            DrawPropertyField("enableRotation");
            DrawPropertyField("enableTilt");
            const float minTiltErrorAngle   = 10;
            const float minTiltWarningAngle = 40;
            const float maxTiltErrorAngle   = 90;
            if (mobileTouchCamera.EnableTilt == true)
            {
                DrawPropertyField("tiltAngleMin", mobileTouchCamera.TiltAngleMin >= minTiltErrorAngle, mobileTouchCamera.TiltAngleMin >= minTiltWarningAngle, subSettingsInset);
                if (mobileTouchCamera.TiltAngleMin < minTiltErrorAngle)
                {
                    DrawErrorLine("Error: The minimum tilt angle\nmust not be lower than " + minTiltErrorAngle + ".\nOtherwise the camera computation\nis guaranteed to become instable.", Color.red);
                }
                else if (mobileTouchCamera.TiltAngleMin < minTiltWarningAngle)
                {
                    DrawErrorLine("Warning: The minimum tilt angle\nshould not be lower than " + minTiltWarningAngle + ".\nOtherwise the camera computations\nmay become instable.", Color.yellow);
                }
                DrawPropertyField("tiltAngleMax", mobileTouchCamera.TiltAngleMax <= maxTiltErrorAngle, true, subSettingsInset);
                if (mobileTouchCamera.TiltAngleMax > maxTiltErrorAngle)
                {
                    DrawErrorLine("The maximum tilt angle\nmust not be higher than " + maxTiltErrorAngle + ".\nOtherwise the camera computation\nmay become instable.", Color.red);
                }
                if (mobileTouchCamera.TiltAngleMax < mobileTouchCamera.TiltAngleMin)
                {
                    DrawErrorLine("Tilt Angle Max must be bigger than Tilt Angle Min", Color.red);
                }
            }
            DrawPropertyField("enableZoomTilt");
            if (mobileTouchCamera.EnableZoomTilt == true)
            {
                DrawPropertyField("zoomTiltAngleMin", mobileTouchCamera.ZoomTiltAngleMin >= minTiltErrorAngle, mobileTouchCamera.ZoomTiltAngleMin >= minTiltWarningAngle, subSettingsInset);
                DrawPropertyField("zoomTiltAngleMax", mobileTouchCamera.ZoomTiltAngleMax <= maxTiltErrorAngle, true, subSettingsInset);
            }

            DrawPropertyField("OnPickItem");
            DrawPropertyField("OnPickItem2D");
            DrawPropertyField("OnPickItemDoubleClick");
            DrawPropertyField("OnPickItem2DDoubleClick");

            DrawPropertyField("expertModeEnabled");
            SerializedProperty serializedPropertyExpertMode = serializedObject.FindProperty("expertModeEnabled");
            if (serializedPropertyExpertMode.boolValue == true)
            {
                DrawPropertyField("zoomBackSpringFactor");
                DrawPropertyField("dragBackSpringFactor");
                DrawPropertyField("autoScrollVelocityMax");
                DrawPropertyField("dampFactorTimeMultiplier");
                DrawPropertyField("isPinchModeExclusive");
                DrawPropertyField("customZoomSensitivity");
                DrawPropertyField("terrainCollider");
                DrawPropertyField("cameraTransform");

                DrawPropertyField("rotationDetectionDeltaThreshold");
                DrawPropertyField("rotationMinPinchDistance");
                DrawPropertyField("rotationLockThreshold");

                DrawPropertyField("pinchModeDetectionMoveTreshold");
                DrawPropertyField("pinchTiltModeThreshold");
                DrawPropertyField("pinchTiltSpeed");
            }

            if (GUI.changed)
            {
                serializedObject.ApplyModifiedProperties();

                //Detect modified properties.
                AutoScrollDampMode dampModeAfterApply = (AutoScrollDampMode)serializedObject.FindProperty("autoScrollDampMode").enumValueIndex;
                if (selectedDampMode != dampModeAfterApply)
                {
                    OnScrollDampModeChanged(dampModeAfterApply);
                }
            }
        }
Exemplo n.º 19
0
 private void ResetRoot(MobileTouchCamera mobileTouchCamera)
 {
     mobileTouchCamera.transform.root.eulerAngles = new Vector3(0, 0, 0);
     EditorUtility.SetDirty(mobileTouchCamera.transform.root);
 }
    bool wasFirstRoadBuilt = false; // for tutorial mode



    void Awake()
    {
        mobileTouchCamera = FindObjectOfType <BitBenderGames.MobileTouchCamera>();
        costs             = FindObjectOfType <Costs>();
        tutorial          = FindObjectOfType <Tutorial>();
    }
Exemplo n.º 21
0
 public void Awake()
 {
     MobileTouchCamera   = GetComponent <MobileTouchCamera>();
     isTransitionStarted = false;
 }