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);
        }
Beispiel #2
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.");
     }
 }
        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);
            }
        }
 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>();
     }
 }
Beispiel #5
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 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);
                }
            }
        }