/// <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 }
/// <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); }
/// <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; } }