コード例 #1
0
        public void DrawRuntimeGizmos(RuntimeGizmoDrawer drawer)
        {
            Matrix4x4 m = Matrix4x4.identity;

            if (transform != null)
            {
                m = transform.localToWorldMatrix;
            }

            var origDrawerColor = drawer.color;

            Vector3 center = m.MultiplyPoint3x4(this.center);
            float   radius = m.MultiplyPoint3x4(Vector3.right).magnitude *this.radius;
            Vector3 x      = m.MultiplyVector(Vector3.right);
            Vector3 y      = m.MultiplyVector(Vector3.up);

            //Vector3 z = m.MultiplyVector(Vector3.forward); // unused

            // Sphere
            drawer.color = drawer.color.WithAlpha(origDrawerColor.a * 0.05f);
            drawer.DrawSphere(center, radius);

            // Wire lat-long sphere
            drawer.color = drawer.color.WithAlpha(origDrawerColor.a * 0.2f);
            int        latDiv = 6;
            float      latAngle = 180f / latDiv; float accumLatAngle = 0f;
            int        lonDiv    = 6;
            float      lonAngle  = 180f / lonDiv;
            Quaternion lonRot    = Quaternion.AngleAxis(lonAngle, y);
            Vector3    lonNormal = x;

            for (int i = 0; i < latDiv; i++)
            {
                accumLatAngle += latAngle;
                drawer.DrawWireArc(center: center + y * Mathf.Cos(accumLatAngle * Mathf.Deg2Rad) * radius,
                                   normal: y,
                                   radialStartDirection: x,
                                   radius: Mathf.Sin(accumLatAngle * Mathf.Deg2Rad) * radius,
                                   fractionOfCircleToDraw: 1.0f,
                                   numCircleSegments: 22);
            }
            for (int i = 0; i < latDiv; i++)
            {
                drawer.DrawWireArc(center: center,
                                   normal: lonNormal,
                                   radialStartDirection: y,
                                   radius: radius,
                                   fractionOfCircleToDraw: 1.0f,
                                   numCircleSegments: 22);
                lonNormal = lonRot * lonNormal;
            }

            drawer.color = origDrawerColor;
        }
コード例 #2
0
        public void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer)
        {
            if (!isActive)
            {
                drawer.color = Color.white;

                Vector3 pos    = _pinchPos;
                Vector3 normal = (pos - Camera.main.transform.position).normalized;

                Vector3 startDir = Vector3.Cross(Vector3.Cross(normal, Vector3.down), normal).normalized;
                drawer.DrawWireArc(pos, -normal, startDir, 0.03F, debugActivationAmount, 32);
                drawer.DrawWireArc(pos, -normal, startDir, 0.025F, debugActivationAmount, 32);
            }
        }
コード例 #3
0
ファイル: GizmoHands.cs プロジェクト: masterchop/Galaxies
        private void drawCircle(Vector3 pos, float radius, Vector3 normal,
                                RuntimeGizmoDrawer drawer, int resolution = 27)
        {
            var radialStartDir = normal.Perpendicular();

            drawer.DrawWireArc(pos, normal, radialStartDir, radius, 1f, resolution);
        }
コード例 #4
0
ファイル: GizmoHands.cs プロジェクト: masterchop/Galaxies
        private void drawCircle(Vector3 pos, float radius,
                                RuntimeGizmoDrawer drawer, int resolution = 27)
        {
            var dirToCam       = (facingCamera.transform.position - pos).normalized;
            var radialStartDir = dirToCam.Perpendicular();

            drawer.DrawWireArc(pos, dirToCam, radialStartDir, radius, 1f, resolution);
        }
コード例 #5
0
        private void drawHingeGizmo(RuntimeGizmoDrawer drawer)
        {
            drawer.color = LeapColor.purple;
            var   currentPlane      = this.currentPlane;
            float planeCircleRadius = 0.005f;

            for (int i = 0; i < 4; i++)
            {
                drawer.DrawWireArc(hingePosition, currentPlane.normal,
                                   currentPlane.normal.Vec().Perpendicular(),
                                   planeCircleRadius + i * -0.001f,
                                   1.0f);
            }
        }
コード例 #6
0
        public void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer)
        {
            drawer.color = LeapColor.cyan;

            var rDelta = 0.008f;
            var dt     = Time.deltaTime;
            FailedPaintGizmo gizmo;

            for (int i = 0; i < _failedPaintGizmos.Count; i++)
            {
                gizmo = _failedPaintGizmos[i];

                gizmo.t += dt;
                if (gizmo.t > gizmo.duration)
                {
                    gizmo.t          = gizmo.duration;
                    gizmo.isFinished = true;
                }

                var progress = _curve.Evaluate(gizmo.t / gizmo.duration);
                drawer.color = drawer.color.WithAlpha(Mathf.Sin(progress * Mathf.PI));

                for (int j = 0; j < 3; j++)
                {
                    var r = Mathf.Lerp(gizmo.initRingSize, gizmo.finalRingSize, progress)
                            - rDelta * j;

                    if (r > 0f)
                    {
                        drawer.DrawWireArc(gizmo.position, gizmo.normal, gizmo.normal.Perpendicular(),
                                           r, 1f, 32);
                    }
                }
                drawer.DrawDashedLine(gizmo.position, gizmo.colliderPos, segmentsPerMeter: 128);

                _failedPaintGizmos[i] = gizmo;
            }

            _failedPaintGizmos.RemoveAll((g) => g.isFinished);
        }
コード例 #7
0
ファイル: Circle.cs プロジェクト: tatoforever/AppExperiments
        public void DrawRuntimeGizmos(RuntimeGizmoDrawer drawer)
        {
            Matrix4x4 m = Matrix4x4.identity;

            if (transform != null)
            {
                m = transform.localToWorldMatrix;
            }

            drawer.PushMatrix();
            drawer.matrix = m;

            drawer.DrawWireArc(
                center: center,
                normal: direction,
                radialStartDirection: direction.Vec().GetPerpendicular(),
                radius: radius,
                fractionOfCircleToDraw: 1f,
                numCircleSegments: 44
                );

            drawer.PopMatrix();
        }
コード例 #8
0
    public void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer)
    {
        if (!this.enabled)
        {
            return;
        }
        if (!_drawDebug)
        {
            return;
        }

        // Sphere gizmo

        //drawer.color = LeapColor.forest.WithAlpha(0.2f);
        //float initAlpha = 0.2f;
        //int numRings = 8;
        //for (int i = 0; i < numRings; i++) {
        //  drawer.color = LeapColor.forest.WithAlpha(Mathf.Lerp(initAlpha, 0f, i / (float)numRings) * _widgetAlphaMult);
        //  float r = _widgetRadius - (_widgetRadius * (i / (float)numRings));
        //  drawer.DrawWireSphere(this.transform.position, r);
        //}

        var dir = Camera.main.transform.position.From(this.transform.position).normalized;

        drawer.color = LeapColor.forest;
        int   numDirRings  = 8;
        float angleStep    = 2f;
        float initDirAlpha = 0.9f;

        for (int i = 0; i < numDirRings; i++)
        {
            drawer.color = drawer.color.WithAlpha(Mathf.Lerp(initDirAlpha, 0f, i / (float)numDirRings) * _widgetAlphaMult);
            drawer.DrawWireArc(this.transform.position + (_widgetRadius * dir * Mathf.Sin(angleStep * i * Mathf.Deg2Rad)),
                               dir, dir.Perpendicular(),
                               _widgetRadius * Mathf.Cos(angleStep * i * Mathf.Deg2Rad),
                               1.0f, 32);
        }


        // Grasp gizmos

        float graspGizmoRadius = 0.03f;

        if (!Application.isPlaying)
        {
            drawer.color = LeapColor.forest;
            drawer.DrawWireSphere(this.transform.position, _widgetRadius);
        }

        if (_switchA != null)
        {
            if (_switchA.grasped)
            {
                drawer.color = LeapColor.forest.WithAlpha(0.7f);
                drawer.DrawWireSphere(_switchA.Position, graspGizmoRadius);

                var dirA             = Camera.main.transform.position.From(_switchA.Position).normalized;
                int numGizmoDirRings = 8;
                angleStep    = 9f;
                initDirAlpha = 0.8f;
                for (int i = 0; i < numGizmoDirRings; i++)
                {
                    drawer.color = drawer.color.WithAlpha(Mathf.Lerp(initDirAlpha, 0f, i / (float)numGizmoDirRings) * _widgetAlphaMult);
                    drawer.DrawWireArc(_switchA.Position + (graspGizmoRadius * dirA * Mathf.Sin(angleStep * i * Mathf.Deg2Rad)),
                                       dirA, dirA.Perpendicular(),
                                       graspGizmoRadius * Mathf.Cos(angleStep * i * Mathf.Deg2Rad),
                                       1.0f, (i == 0 ? 24 : 16));
                }
            }
            else if (_switchAWithinRange)
            {
                drawer.color = LeapColor.forest.WithAlpha(0.4f);
                drawer.DrawWireSphere(_switchA.Position, graspGizmoRadius * 0.7f);
            }
        }
        if (_switchB != null)
        {
            if (_switchB.grasped)
            {
                drawer.color = LeapColor.forest.WithAlpha(0.7f);
                drawer.DrawWireSphere(_switchB.Position, graspGizmoRadius);

                var dirB             = Camera.main.transform.position.From(_switchB.Position).normalized;
                int numGizmoDirRings = 8;
                angleStep    = 9f;
                initDirAlpha = 0.8f;
                for (int i = 0; i < numGizmoDirRings; i++)
                {
                    drawer.color = drawer.color.WithAlpha(Mathf.Lerp(initDirAlpha, 0f, i / (float)numGizmoDirRings) * _widgetAlphaMult);
                    drawer.DrawWireArc(_switchB.Position + (dirB * graspGizmoRadius * Mathf.Sin(angleStep * i * Mathf.Deg2Rad)),
                                       dirB, dirB.Perpendicular(),
                                       graspGizmoRadius * Mathf.Cos(angleStep * i * Mathf.Deg2Rad),
                                       1.0f, (i == 0 ? 24 : 16));
                }
            }
            else if (_switchBWithinRange)
            {
                drawer.color = LeapColor.mint.WithAlpha(0.4f);
                drawer.DrawWireSphere(_switchB.Position, graspGizmoRadius * 0.7f);
            }
        }

        bool switchAGrasped = _switchA != null && _switchA.grasped;
        bool switchBGrasped = _switchB != null && _switchB.grasped;

        if (switchAGrasped && switchBGrasped)
        {
            drawer.color = LeapColor.mint.WithAlpha(0.7f);

            var ATowardsB = (_switchB.Position - _switchA.Position).normalized;
            drawer.DrawLine(_switchA.Position + (ATowardsB) * graspGizmoRadius,
                            _switchB.Position - (ATowardsB) * graspGizmoRadius);
        }


        // Alpha multiplier
        var targetAlphaT = 0f;

        if (_switchAWithinRange || _switchBWithinRange)
        {
            targetAlphaT = 0.6f;

            if (_switchAWithinRange && _switchA.grasped)
            {
                targetAlphaT = 1.0f;
            }
            else if (_switchBWithinRange && _switchB.grasped)
            {
                targetAlphaT = 1.0f;
            }
        }

        if (_widgetAlphaT < targetAlphaT)
        {
            _widgetAlphaT += _widgetAlphaSpeed * Time.deltaTime;
            _widgetAlphaT  = Mathf.Min(_widgetAlphaT, targetAlphaT);
        }
        if (_widgetAlphaT > targetAlphaT)
        {
            _widgetAlphaT -= _widgetAlphaSpeed * Time.deltaTime;
            _widgetAlphaT  = Mathf.Max(_widgetAlphaT, targetAlphaT);
        }

        _widgetAlphaMult = _widgetAlphaCurve.Evaluate(_widgetAlphaT);
    }