示例#1
0
        static void CreateLineResourceShort(float z)
        {
            {
                LineResource resource            = ResourcePool.RentDisplay <LineResource>();
                NativeList <LineWithColor> lines = new NativeList <LineWithColor>();
                for (int i = 0; i < MaxSegmentsForMesh / 2; i++)
                {
                    lines.Add(new LineWithColor(
                                  new Vector3(i, 0, z), Color.green,
                                  new Vector3(i + 1, 1, z), Color.green
                                  ));
                }

                resource.Set(lines);
            }

            {
                LineResource resource            = ResourcePool.RentDisplay <LineResource>();
                NativeList <LineWithColor> lines = new NativeList <LineWithColor>();
                for (int i = 0; i < MaxSegmentsForMesh / 2; i++)
                {
                    lines.Add(new LineWithColor(
                                  new Vector3(i, 0, z + 1), 0.1f * i,
                                  new Vector3(i + 1, 1, z + 1), 0.1f * i
                                  ));
                }

                resource.UseColormap = true;
                resource.Colormap    = ColormapId.hsv;
                resource.Set(lines);
            }

            {
                LineResource resource            = ResourcePool.RentDisplay <LineResource>();
                NativeList <LineWithColor> lines = new NativeList <LineWithColor>();
                for (int i = 0; i < MaxSegmentsForMesh / 2; i++)
                {
                    lines.Add(new LineWithColor(
                                  new Vector3(i, 0, z + 2), Color.red.WithAlpha(0.25f),
                                  new Vector3(i + 1, 1, z + 2), Color.green
                                  ));
                }

                resource.Set(lines);
            }

            {
                LineResource resource            = ResourcePool.RentDisplay <LineResource>();
                NativeList <LineWithColor> lines = new NativeList <LineWithColor>();
                for (int i = 0; i < MaxSegmentsForMesh / 2; i++)
                {
                    lines.Add(new LineWithColor(
                                  new Vector3(i, 0, z + 3), 0.1f * i,
                                  new Vector3(i + 1, 1, z + 3), 0.1f * i
                                  ));
                }

                resource.UseColormap = true;
                resource.Tint        = Color.white.WithAlpha(0.25f);
                resource.Colormap    = ColormapId.hsv;
                resource.Set(lines);
            }
        }
示例#2
0
        static void CreateLineResource(float z)
        {
            using (NativeList <LineWithColor> lines = new NativeList <LineWithColor>())
            {
                LineResource resource = ResourcePool.RentDisplay <LineResource>();

                for (int i = 0; i < MaxSegmentsForMesh + 10; i++)
                {
                    lines.Add(new LineWithColor(
                                  new Vector3(i, 0, z), Color.green,
                                  new Vector3(i + 1, 1, z), Color.green
                                  ));
                }

                resource.Set(lines);
            }

            using (NativeList <LineWithColor> lines = new NativeList <LineWithColor>())
            {
                LineResource resource = ResourcePool.RentDisplay <LineResource>();
                for (int i = 0; i < MaxSegmentsForMesh + 10; i++)
                {
                    lines.Add(new LineWithColor(
                                  new Vector3(i, 0, z + 1), 0.025f * i,
                                  new Vector3(i + 1, 1, z + 1), 0.025f * i
                                  ));
                }

                resource.UseColormap = true;
                resource.Colormap    = ColormapId.hsv;
                resource.Set(lines);
            }

            using (NativeList <LineWithColor> lines = new NativeList <LineWithColor>())
            {
                LineResource resource = ResourcePool.RentDisplay <LineResource>();
                for (int i = 0; i < MaxSegmentsForMesh + 10; i++)
                {
                    lines.Add(new LineWithColor(
                                  new Vector3(i, 0, z + 2), new Color(1, 0, 0, 0.5f),
                                  new Vector3(i + 1, 1, z + 2), Color.green
                                  ));
                }

                resource.Set(lines);
            }

            using (NativeList <LineWithColor> lines = new NativeList <LineWithColor>())
            {
                LineResource resource = ResourcePool.RentDisplay <LineResource>();
                for (int i = 0; i < MaxSegmentsForMesh + 10; i++)
                {
                    lines.Add(new LineWithColor(
                                  new Vector3(i, 0, z + 3), 0.025f * i,
                                  new Vector3(i + 1, 1, z + 3), 0.025f * i
                                  ));
                }

                resource.UseColormap = true;
                resource.Tint        = new Color(1, 1, 1, 0.5f);
                resource.Colormap    = ColormapId.hsv;
                resource.Set(lines);
            }
        }
示例#3
0
        protected override void Update()
        {
            base.Update();;

            var   discPosition = disc.Transform.localPosition;
            float discDistance = discPosition.Magnitude();

            if (Vector3.Distance(discPosition, DiscRestPosition) < 0.005f)
            {
                if (dragBack)
                {
                    disc.Transform.localPosition  = DiscRestPosition;
                    ringUp.Transform.localScale   = dragBackDistance * Vector3.one;
                    ringDown.Transform.localScale = dragBackDistance * Vector3.one;
                    dragBack = false;
                    lines.Reset();
                }

                return;
            }

            float angle = -Mathf.Atan2(discPosition.z, discPosition.x) * Mathf.Rad2Deg;

            link.Transform.localScale = new Vector3(discDistance, 0.002f, linkWidth);
            link.Transform.SetLocalPose(new Pose(discPosition / 2, Quaternion.AngleAxis(angle, Vector3.up)));

            float ringSize = dragBackDistance + 0.1f * (discDistance - dragBackDistance);

            ringUp.Transform.localScale   = ringSize * Vector3.one;
            ringDown.Transform.localScale = ringSize * Vector3.one;

            if (dragBack)
            {
                disc.Transform.localPosition += 0.2f * (DiscRestPosition - discPosition);
                return;
            }

            float openingAngle = -90 - angle;

            if (currentAngle != null)
            {
                if (openingAngle - currentAngle.Value > 180)
                {
                    openingAngle -= 360;
                }
                else if (openingAngle - currentAngle.Value < -180)
                {
                    openingAngle += 360;
                }
            }

            currentAngle = openingAngle;

            const int ringElements = 32;

            lineBuffer.Clear();
            lineBuffer.EnsureCapacity(ringElements + 1);
            Vector3 a0 = 1.1f * ringSize * Vector3.forward;
            Vector3 a  = a0;

            for (int i = 0; i < ringElements; i++)
            {
                float   bAngle = Mathf.Deg2Rad / ringElements * openingAngle * (i + 1) + Mathf.PI / 2;
                Vector3 b      = 1.1f * ringSize * new Vector3(Mathf.Cos(bAngle), 0, Mathf.Sin(bAngle));
                lineBuffer.Add(new LineWithColor(a, b));
                a = b;
            }

            lineBuffer.Add(new LineWithColor(Vector3.zero, a0));
            lines.Set(lineBuffer);

            Moved?.Invoke(this, openingAngle);
        }