Пример #1
0
        public void OnSceneGUI()
        {
            if (Application.isPlaying)
            {
                return;
            }

            if (leTarget == null)
            {
                leTarget = (LSBody)(target);
            }
            Vector3 TargetPosition = leTarget.cachedTransform.position;

            TargetPosition.y += .55f;
            Vector3[] PolyLine;
            switch (leTarget.Shape)
            {
            case ColliderType.Circle:
                Handles.color = FrameColor;
                Handles.CircleCap(1, TargetPosition, CapRotation, FixedMath.ToFloat(leTarget.Radius));
                Handles.CircleCap(1, TargetPosition, CapRotation, FixedMath.ToFloat(leTarget.Radius) + -.005f);
                Handles.CircleCap(1, TargetPosition, CapRotation, FixedMath.ToFloat(leTarget.Radius) + .005f);


                Vector3 NewVec = TargetPosition;
                NewVec.x       -= (float)Math.Round(FixedMath.ToDouble(leTarget.Radius), 4, MidpointRounding.AwayFromZero);
                Handles.color   = MoveColor;
                NewVec          = Handles.FreeMoveHandle(NewVec, Quaternion.identity, .35f, Vector3.zero, Handles.SphereCap);
                leTarget.Radius = FixedMath.Create(NewVec.x - TargetPosition.x);
                if (leTarget.Radius < 0)
                {
                    leTarget.Radius = -leTarget.Radius;
                }
                break;

            case ColliderType.AABox:
                float halfWidth  = FixedMath.ToFloat(leTarget.HalfWidth);
                float halfHeight = FixedMath.ToFloat(leTarget.HalfHeight);
                PolyLine = new Vector3[5];
                for (int i = 0; i < 4; i++)
                {
                    PolyLine[i] = TargetPosition;
                }

                PolyLine[0].x += halfWidth;
                PolyLine[0].z += halfHeight;

                PolyLine[1].x += halfWidth;
                PolyLine[1].z -= halfHeight;

                PolyLine[2].x -= halfWidth;
                PolyLine[2].z -= halfHeight;

                PolyLine[3].x -= halfWidth;
                PolyLine[3].z += halfHeight;

                PolyLine[4]   = PolyLine[0];
                Handles.color = FrameColor;
                Handles.DrawAAPolyLine(5f, PolyLine);
                Handles.color = MoveColor;

                Vector3 WidthScaler = TargetPosition;
                WidthScaler.x     -= (float)LSEditorUtility.Round(leTarget.HalfWidth);
                WidthScaler        = Handles.FreeMoveHandle(WidthScaler, Quaternion.identity, .35f, Vector3.zero, Handles.SphereCap);
                leTarget.HalfWidth = FixedMath.Create(WidthScaler.x - TargetPosition.x);

                Vector3 HeightScaler = TargetPosition;
                HeightScaler.z     -= (float)LSEditorUtility.Round(leTarget.HalfHeight);
                HeightScaler        = Handles.FreeMoveHandle(HeightScaler, Quaternion.identity, .35f, Vector3.zero, Handles.SphereCap);
                leTarget.HalfHeight = FixedMath.Create(HeightScaler.z - TargetPosition.z);
                if (leTarget.HalfWidth <= 0)
                {
                    leTarget.HalfWidth = -leTarget.HalfWidth;
                }
                if (leTarget.HalfHeight < 0)
                {
                    leTarget.HalfHeight = -leTarget.HalfHeight;
                }

                break;

            case ColliderType.Polygon:
                if (leTarget.Vertices == null || leTarget.Vertices.Length == 0)
                {
                    break;
                }

                PolyLine      = new Vector3[leTarget.Vertices.Length + 1];
                Handles.color = MoveColor;
                for (int i = 0; i < leTarget.Vertices.Length; i++)
                {
                    Vector3 vertPos     = leTarget.Vertices[i].ToVector3(0f) + TargetPosition;
                    Vector3 freemoveVec = Handles.FreeMoveHandle(vertPos, Quaternion.identity, .35f, Vector3.zero, Handles.SphereCap) - TargetPosition;
                    leTarget.Vertices[i] = new Vector2d(FixedMath.Create(freemoveVec.x), FixedMath.Create(freemoveVec.z));
                    Handles.Label(vertPos, "V" + i.ToString());
                    PolyLine[i] = vertPos;
                }

                PolyLine[leTarget.Vertices.Length] = PolyLine[0];
                Handles.color = FrameColor;
                Handles.DrawAAPolyLine(5f, PolyLine);
                break;
            }
        }