示例#1
0
文件: Ring.cs 项目: koreldan/SpaceW
    protected override void UpdateNode()
    {
        RingMaterial.renderQueue = (int)RenderQueue + RenderQueueOffset;

        using (new Timer("Ring.UpdateNode()"))
        {
            Segments.RemoveAll(m => m == null);

            if (SegmentCount != Segments.Count)
            {
                Helper.ResizeArrayTo(ref Segments, SegmentCount, i => RingSegment.Create(this), null);
            }

            var angleStep = Helper.Divide(360.0f, SegmentCount);

            for (var i = SegmentCount - 1; i >= 0; i--)
            {
                var angle    = angleStep * i;
                var rotation = Quaternion.Euler(0.0f, angle, 0.0f);

                Segments[i].UpdateNode(RingSegmentMesh, RingMaterial, rotation);
            }
        }

        SetUniforms(RingMaterial);

        if (planetoid != null)
        {
            SetShadows(planetoid.MPB, planetoid.Shadows);
        }
    }
示例#2
0
    private void UpdateNode()
    {
        using (new Timer("Ring.UpdateNode()"))
        {
            Segments.RemoveAll(m => m == null);

            if (SegmentCount != Segments.Count)
            {
                Helper.ResizeArrayTo(ref Segments, SegmentCount, i => RingSegment.Create(this), null);
            }

            var angleStep = Helper.Divide(360.0f, SegmentCount);

            for (var i = SegmentCount - 1; i >= 0; i--)
            {
                var angle    = angleStep * i;
                var rotation = Quaternion.Euler(0.0f, angle, 0.0f);

                Segments[i].UpdateNode(RingSegmentMesh, RingMaterial, rotation);
            }
        }
    }
    public override void Generate()
    {
        PreGenerate();

        foreach (Transform child in transform)
        {
            child.gameObject.GetComponent <RingBehaviour>().Die();
        }

        float scale = 0.05f;

        foreach (List <ProcessUnit> data in lsys.Units)
        {
            if (data.Count == 0)
            {
                break;
            }

            float dynamicsSum = 0.0f;
            foreach (ProcessUnit unit in data)
            {
                dynamicsSum += unit.Dynamic;
            }

            dynamicsSum = dynamicsSum / data.Count;
            float speedMul           = (0.05f + (2.45f / 128.0f * dynamicsSum)) * 60.0f * 0.2f;
            float comp               = 1.0f / scale;
            float rotateCompensation = 0.1f / scale;

            GameObject ring = GameObject.Instantiate(RingProto, transform);
            ring.transform.localScale = new Vector3(0.0f, 0.0f, 0.0f);

            ring.transform.Rotate(new Vector3(RandomRange(0.0f, 360.0f), RandomRange(0.0f, 360.0f), RandomRange(0.0f, 360.0f)));

            RingBehaviour ringBehave = ring.GetComponent <RingBehaviour>();
            ringBehave.Rotation    = new Vector3(RandomRange(-2.0f, 2.0f) * rotateCompensation * speedMul, RandomRange(-2.0f, 2.0f) * rotateCompensation * speedMul, RandomRange(-2.0f, 2.0f) * rotateCompensation * speedMul);
            ringBehave.TargetScale = scale;
            ringBehave.Scale       = 0.0f;
            ringBehave.gen         = this;

            float degsPerSegment = 360.0f / data.Count;
            float startRotation  = 0.0f;

            List <RingSegment> list        = new List <RingSegment>();
            RingSegment        lastSegment = null;

            // clump segments
            // TODO: Join segments
            foreach (ProcessUnit unit in data)
            {
                if (lastSegment == null)
                {
                    lastSegment = new RingSegment(unit, 0, startRotation);
                    list.Add(lastSegment);
                }
                else
                {
                    if (lastSegment.Unit.Content != unit.Content)
                    {
                        lastSegment = new RingSegment(unit, 0, startRotation);
                        list.Add(lastSegment);
                    }
                }

                lastSegment.NumSegments = lastSegment.NumSegments + 1;
                startRotation          += degsPerSegment;
            }


            // fehler tritt bei doppelten auf

            startRotation = 0.0f;
            foreach (RingSegment arc in list)
            {
                startRotation += (arc.NumSegments * degsPerSegment);

                if (arc.Unit.Content != '0')
                {
                    float      width = (0.2f + (2.0f / 128.0f * arc.Unit.Dynamic)) * 0.1f;
                    GameObject obj   = meshgen.GetArcObject(((arc.NumSegments * degsPerSegment)) * Mathf.Deg2Rad, 0.4f * comp * 0.1f, width * comp, ring.transform, lookup[arc.Unit.Content]);
                    obj.transform.Rotate(new Vector3(0.0f, 0.0f, startRotation), Space.Self);
                }
            }

            scale += 0.1f;
        }
    }