Beispiel #1
0
        /// <summary>
        /// On fixedUpdate, checks the last movement and if needed casts a ray to detect obstacles
        /// </summary>
        protected virtual void Update()
        {
            _lastMovement        = this.transform.position - _positionLastFrame;
            _lastMovementSquared = _lastMovement.sqrMagnitude;

            // if we've moved further than our bounds, we may have missed something
            if (_lastMovementSquared > _squaredBoundsWidth)
            {
                float movementMagnitude = Mathf.Sqrt(_lastMovementSquared);

                // we cast a ray backwards to see if we should have hit something
                RaycastHit2D hitInfo = MMDebug.RayCast(_positionLastFrame, _lastMovement.normalized, movementMagnitude, ObstaclesLayerMask, Color.blue, true);

                if (hitInfo.collider != null)
                {
                    if (hitInfo.collider.isTrigger)
                    {
                        hitInfo.collider.SendMessage("OnTriggerEnter2D", _collider, SendMessageOptions.DontRequireReceiver);
                    }

                    if (!hitInfo.collider.isTrigger)
                    {
                        Hit = hitInfo;
                        this.gameObject.SendMessage("PreventedCollision2D", Hit, SendMessageOptions.DontRequireReceiver);
                        if (RepositionRigidbody)
                        {
                            this.transform.position = hitInfo.point - (_lastMovement / movementMagnitude) * _adjustedSmallestBoundsWidth;
                            _rigidbody.position     = hitInfo.point - (_lastMovement / movementMagnitude) * _adjustedSmallestBoundsWidth;
                        }
                    }
                }
            }
            _positionLastFrame = this.transform.position;
        }
Beispiel #2
0
        /// <summary>
        /// Draws a rectangle based on a Rect and color
        /// </summary>
        /// <param name="rectangle">Rectangle.</param>
        /// <param name="color">Color.</param>
        public static void DrawRectangle(Rect rectangle, Color color)
        {
            Vector3 pos   = new Vector3(rectangle.x + rectangle.width / 2, rectangle.y + rectangle.height / 2, 0.0f);
            Vector3 scale = new Vector3(rectangle.width, rectangle.height, 0.0f);

            MMDebug.DrawRectangle(pos, color, scale);
        }
Beispiel #3
0
 public static void Framerate(string[] args)
 {
     if (int.TryParse(args[1], out int framerate))
     {
         Application.targetFrameRate = framerate;
         MMDebug.DebugLogTime("Framerate set to " + framerate, "#FFC400", 3, true);
     }
 }
Beispiel #4
0
 public static void Timescale(string[] args)
 {
     if (float.TryParse(args[1], System.Globalization.NumberStyles.Float, CultureInfo.InvariantCulture, out float timescale))
     {
         Time.timeScale = timescale;
         MMDebug.DebugLogTime("Timescale set to " + timescale, "#FFC400", 3, true);
     }
 }
Beispiel #5
0
 public static void Vsync(string[] args)
 {
     if (int.TryParse(args[1], out int vSyncCount))
     {
         QualitySettings.vSyncCount = vSyncCount;
         MMDebug.DebugLogTime("VSyncCount set to " + vSyncCount, "#FFC400", 3, true);
     }
 }
Beispiel #6
0
 public virtual void Randomize()
 {
     MMDebug.DebugLogTime(this.name + " Randomize");
     RandomizePosition();
     RandomizeRotation();
     RandomizeScale();
     RemoveColliders();
     Cleanup();
 }
Beispiel #7
0
 public static void Biggest(string[] args)
 {
     if (int.TryParse(args[1], out int i1) && int.TryParse(args[2], out int i2))
     {
         string result;
         int    biggest = (i1 >= i2) ? i1 : i2;
         result = biggest + " is the biggest number";
         MMDebug.DebugLogTime(result, "#FFC400", 3, true);
     }
 }
Beispiel #8
0
        public static void Help()
        {
            string result = "LIST OF COMMANDS";

            foreach (MethodInfo method in MMDebug.Commands.OrderBy(m => m.Name))
            {
                result += "\n- <color=#FFFFFF>" + method.Name + "</color>";
            }
            MMDebug.DebugLogTime(result, "#FFC400", 3, true);
        }
Beispiel #9
0
        /// <summary>
        /// On DrawGizmos, we draw lines to show the path the object will follow
        /// </summary>
        protected virtual void OnDrawGizmos()
        {
                        #if UNITY_EDITOR
            if (PathElements == null)
            {
                return;
            }

            if (PathElements.Count == 0)
            {
                return;
            }

            // if we haven't stored the object's original position yet, we do it
            if (_originalTransformPositionStatus == false)
            {
                _originalTransformPosition       = transform.position;
                _originalTransformPositionStatus = true;
            }
            // if we're not in runtime mode and the transform has changed, we update our position
            if (transform.hasChanged && _active == false)
            {
                _originalTransformPosition = transform.position;
            }
            // for each point in the path
            for (int i = 0; i < PathElements.Count; i++)
            {
                // we draw a green point
                MMDebug.DrawGizmoPoint(_originalTransformPosition + PathElements[i].PathElementPosition, 0.2f, Color.green);

                // we draw a line towards the next point in the path
                if ((i + 1) < PathElements.Count)
                {
                    Gizmos.color = Color.white;
                    Gizmos.DrawLine(_originalTransformPosition + PathElements[i].PathElementPosition, _originalTransformPosition + PathElements[i + 1].PathElementPosition);
                }
                // we draw a line from the first to the last point if we're looping
                if ((i == PathElements.Count - 1) && (CycleOption == CycleOptions.Loop))
                {
                    Gizmos.color = Color.white;
                    Gizmos.DrawLine(_originalTransformPosition + PathElements[0].PathElementPosition, _originalTransformPosition + PathElements[i].PathElementPosition);
                }
            }

            // if the game is playing, we add a blue point to the destination, and a red point to the last visited point
            if (Application.isPlaying)
            {
                if (_currentPoint != null)
                {
                    MMDebug.DrawGizmoPoint(_originalTransformPosition + _currentPoint.Current, 0.2f, Color.blue);
                    MMDebug.DrawGizmoPoint(_originalTransformPosition + _previousPoint, 0.2f, Color.red);
                }
            }
                        #endif
        }
Beispiel #10
0
        /// <summary>
        /// We compute the axis value from the interval between neutral position, current stick position (vectorPosition) and max range
        /// </summary>
        /// <returns>The axis value, a float between -1 and 1</returns>
        /// <param name="vectorPosition">stick position.</param>
        protected virtual float EvaluateInputValue(float vectorPosition)
        {
            var x = Mathf.InverseLerp(0, MaxRange, Mathf.Abs(vectorPosition));

            MMDebug.DebugOnScreen("input:" + x);
            var y = curveKnob.Evaluate(x) * Mathf.Sign(vectorPosition);

            MMDebug.DebugOnScreen("result:" + y);
            return(y);
            //	return Mathf.Min(1.0f, x)* Mathf.Sign(vectorPosition);
        }
        static void DrawHandles(MMAutoRotate autoRotate, GizmoType gizmoType)
        {
            MMAutoRotate myTarget = autoRotate;

            // only draw gizmos if orbiting and gizmos enabled
            if (!myTarget.Orbiting || !myTarget.DrawGizmos)
            {
                return;
            }
            ;

            // if we're not playing, we compute our center/axis
            if (!Application.isPlaying)
            {
                if (myTarget.OrbitCenterTransform != null)
                {
                    myTarget._orbitCenter       = myTarget.OrbitCenterTransform.transform.position + myTarget.OrbitCenterOffset;
                    myTarget._worldRotationAxis = myTarget.OrbitCenterTransform.TransformDirection(myTarget.OrbitRotationAxis);
                    myTarget._rotationPlane.SetNormalAndPosition(myTarget._worldRotationAxis.normalized, myTarget._orbitCenter);

                    myTarget._snappedPosition = myTarget._rotationPlane.ClosestPointOnPlane(myTarget.transform.position);
                    myTarget._radius          = myTarget.OrbitRadius * Vector3.Normalize(myTarget._snappedPosition - myTarget._orbitCenter);
                }
            }

            // draws a plane disc
            Handles.color = myTarget.OrbitPlaneColor;
            Handles.DrawSolidDisc(myTarget._orbitCenter, myTarget._rotationPlane.normal, myTarget.OrbitRadius + 0.5f);

            // draws a circle to mark the orbit
            Handles.color = myTarget.OrbitLineColor;
            Handles.DrawWireArc(myTarget._orbitCenter, myTarget._rotationPlane.normal, Vector3.ProjectOnPlane(myTarget._orbitCenter + Vector3.forward, myTarget._rotationPlane.normal), 360f, myTarget.OrbitRadius);

            // draws an arrow to mark the direction
            Quaternion newRotation = Quaternion.AngleAxis(1f, myTarget._worldRotationAxis);
            Vector3    origin      = myTarget._orbitCenter + newRotation * myTarget._radius;

            newRotation = Quaternion.AngleAxis(15f, myTarget._worldRotationAxis);
            Vector3 direction = Vector3.zero;

            if (myTarget.OrbitRotationSpeed > 0f)
            {
                direction = (myTarget._orbitCenter + newRotation * myTarget._radius) - origin;
            }
            else
            {
                direction = origin - (myTarget._orbitCenter + newRotation * myTarget._radius);
            }
            MMDebug.DebugDrawArrow(origin, direction, myTarget.OrbitLineColor);
        }
        /// <summary>
        /// On awake we prepare our prompt listener
        /// </summary>
        protected virtual void Awake()
        {
            MMDebug.MMDebugLogEvent.Register(OnMMDebugLogEvent);
            DebugText.text = "";
            _rectTransform = this.gameObject.GetComponent <RectTransform>();

            CommandPrompt.onEndEdit.AddListener(val =>
            {
                CommandPrompt.text = "";
                if (val != "")
                {
                    MMDebug.DebugLogCommand(val);
                }
            });
        }
Beispiel #13
0
        /// <summary>
        /// Removes saved data and resets all achievements from a list
        /// </summary>
        /// <param name="listID">The ID of the achievement list to reset.</param>
        public static void ResetAchievements(string listID)
        {
            if (Achievements != null)
            {
                foreach (MMAchievement achievement in Achievements)
                {
                    achievement.ProgressCurrent = 0;
                    achievement.UnlockedStatus  = false;
                }
            }

            DeterminePath(listID);
            MMDebug.DebugLogTime("Removing " + _saveFileName);
            File.Delete(_saveFileName);
            MMDebug.DebugLogTime("Removing " + _saveFileName + ".meta");
            File.Delete(_saveFileName + ".meta");
            MMDebug.DebugLogTime("Achievements Reset");
        }
 private static void DisableDebugLogs()
 {
     MMDebug.SetDebugLogsEnabled(false);
 }
 private static void EnableDebugLogs()
 {
     MMDebug.SetDebugLogsEnabled(true);
 }
Beispiel #16
0
 /// <summary>
 /// On Awake we turn our static debug checks on or off
 /// </summary>
 protected virtual void Awake()
 {
     MMDebug.SetDebugLogsEnabled(DebugLogsEnabled);
     MMDebug.SetDebugDrawEnabled(DebugDrawEnabled);
 }
 public virtual void HorizontalAxisPressed(float value)
 {
     MMDebug.DebugOnScreen("horizontal movement", value);
 }
 public virtual void LeftJoystickMovement(Vector2 movement)
 {
     MMDebug.DebugOnScreen("left joystick", movement);
 }
 public virtual void RightJoystickMovement(Vector2 movement)
 {
     MMDebug.DebugOnScreen("right joystick", movement);
 }
 public virtual void RepositionableJoystickMovement(Vector2 movement)
 {
     MMDebug.DebugOnScreen("Repositionable joystick", movement);
 }
 private static void EnableDebugDraws()
 {
     MMDebug.SetDebugDrawEnabled(true);
 }
 public virtual void VerticalAxisPressed(float value)
 {
     MMDebug.DebugOnScreen("vertical movement", value);
 }
 /// <summary>
 /// Adds a menu item to disable debug logs
 /// </summary>
 private static void DisableDebugDraws()
 {
     MMDebug.SetDebugDrawEnabled(false);
 }
Beispiel #24
0
 public static void Sysinfo()
 {
     MMDebug.DebugLogTime(MMDebug.GetSystemInfo());
 }
Beispiel #25
0
        /// <summary>
        /// Draws a position gizmo
        /// </summary>
        /// <param name="mmGizmo"></param>
        private static void DrawPositionGizmo(MMGizmo mmGizmo)
        {
            switch (mmGizmo.PositionMode)
            {
            case MMGizmo.PositionModes.Point:
                MMDebug.DrawGizmoPoint(ComputeGizmoPosition(mmGizmo, mmGizmo._vector3Zero), mmGizmo.GizmoColor, mmGizmo.PositionSize);
                break;

            case MMGizmo.PositionModes.Cube:
                Gizmos.DrawCube(ComputeGizmoPosition(mmGizmo, mmGizmo._vector3Zero), Vector3.one * mmGizmo.PositionSize);
                break;

            case MMGizmo.PositionModes.Sphere:
                Gizmos.DrawSphere(ComputeGizmoPosition(mmGizmo, mmGizmo._vector3Zero), mmGizmo.PositionSize);
                break;

            case MMGizmo.PositionModes.WireCube:
                Gizmos.DrawWireCube(ComputeGizmoPosition(mmGizmo, mmGizmo._vector3Zero), Vector3.one * mmGizmo.PositionSize);
                break;

            case MMGizmo.PositionModes.WireSphere:
                Gizmos.DrawWireSphere(ComputeGizmoPosition(mmGizmo, mmGizmo._vector3Zero), mmGizmo.PositionSize);
                break;

            case MMGizmo.PositionModes.Texture:
                if (mmGizmo._positionTextureNotNull)
                {
                    Handles.BeginGUI();
                    mmGizmo._worldToGUIPosition = HandleUtility.WorldToGUIPoint(ComputeGizmoPosition(mmGizmo, mmGizmo.transform.position, false));
                    mmGizmo._textureRect        = new Rect(mmGizmo._worldToGUIPosition.x - mmGizmo.TextureSize.x / 2f, mmGizmo._worldToGUIPosition.y - mmGizmo.TextureSize.y / 2f, mmGizmo.TextureSize.x, mmGizmo.TextureSize.y);
                    GUI.Label(mmGizmo._textureRect, mmGizmo.PositionTexture);
                    Handles.EndGUI();
                }
                break;

            case MMGizmo.PositionModes.Arrows:
                Handles.color = Handles.xAxisColor;
                Handles.ArrowHandleCap(0, ComputeGizmoPosition(mmGizmo, mmGizmo.transform.position, false),
                                       Quaternion.LookRotation(mmGizmo.transform.right, mmGizmo.transform.up), mmGizmo.PositionSize, EventType.Repaint);
                Handles.color = Handles.yAxisColor;
                Handles.ArrowHandleCap(0, ComputeGizmoPosition(mmGizmo, mmGizmo.transform.position, false),
                                       Quaternion.LookRotation(mmGizmo.transform.up, mmGizmo.transform.up), mmGizmo.PositionSize, EventType.Repaint);
                Handles.color = Handles.zAxisColor;
                Handles.ArrowHandleCap(0, ComputeGizmoPosition(mmGizmo, mmGizmo.transform.position, false),
                                       Quaternion.LookRotation(mmGizmo.transform.forward, mmGizmo.transform.up), mmGizmo.PositionSize, EventType.Repaint);
                break;

            case MMGizmo.PositionModes.RightArrow:
                Handles.color = mmGizmo.GizmoColor;
                Handles.ArrowHandleCap(0, ComputeGizmoPosition(mmGizmo, mmGizmo.transform.position, false),
                                       Quaternion.LookRotation(mmGizmo.transform.right, mmGizmo.transform.up), mmGizmo.PositionSize, EventType.Repaint);
                break;

            case MMGizmo.PositionModes.UpArrow:
                Handles.color = mmGizmo.GizmoColor;
                Handles.ArrowHandleCap(0, ComputeGizmoPosition(mmGizmo, mmGizmo.transform.position, false),
                                       Quaternion.LookRotation(mmGizmo.transform.up, mmGizmo.transform.up), mmGizmo.PositionSize, EventType.Repaint);
                break;

            case MMGizmo.PositionModes.ForwardArrow:
                Handles.color = mmGizmo.GizmoColor;
                Handles.ArrowHandleCap(0, ComputeGizmoPosition(mmGizmo, mmGizmo.transform.position, false),
                                       Quaternion.LookRotation(mmGizmo.transform.forward, mmGizmo.transform.up), mmGizmo.PositionSize, EventType.Repaint);
                break;
            }
        }
 public virtual void RTPressed()
 {
     MMDebug.DebugOnScreen("Button RT Pressed");
 }
 /// <summary>
 /// On DrawGizmosSelected, we draw a yellow point at the position of our center of mass
 /// </summary>
 protected virtual void OnDrawGizmosSelected()
 {
     _gizmoCenter = this.transform.TransformPoint(CenterOfMassOffset);
     MMDebug.DrawGizmoPoint(_gizmoCenter, GizmoPointSize, Color.yellow);
 }
Beispiel #28
0
        public static void Now()
        {
            string message = "Time.time is " + Time.time;

            MMDebug.DebugLogTime(message, "", 3, true);
        }
 /// <summary>
 /// Asks for a reset of all the achievements in this list (they'll all be locked again, their progress lost).
 /// </summary>
 public virtual void ResetAchievements()
 {
     MMDebug.DebugLogTime("Reset Achievements");
     MMAchievementManager.ResetAchievements(AchievementsListID);
 }
Beispiel #30
0
 public static void Clear()
 {
     MMDebug.DebugLogClear();
 }