TreeEditor.TreeGroup.UpdateDistribution C# (CSharp) Method

UpdateDistribution() public method

public UpdateDistribution ( bool completeUpdate, bool updateSubGroups ) : void
completeUpdate bool
updateSubGroups bool
return void
        public void UpdateDistribution(bool completeUpdate, bool updateSubGroups)
        {
            UnityEngine.Random.InitState(this._internalSeed);
            if (completeUpdate)
            {
                float distributionSum = 0f;
                float[] numArray = new float[100];
                float distributionStep = 1f / ((float) numArray.Length);
                float num3 = numArray.Length - 1f;
                for (int j = 0; j < numArray.Length; j++)
                {
                    float time = ((float) j) / num3;
                    numArray[j] = Mathf.Clamp01(this.distributionCurve.Evaluate(time));
                    distributionSum += numArray[j];
                }
                for (int k = 0; k < this.nodes.Count; k++)
                {
                    float num10;
                    float num11;
                    int num12;
                    TreeNode node = this.nodes[k];
                    if (this.lockFlags == 0)
                    {
                        if (((k == 0) && (this.nodes.Count == 1)) && ((this.parentGroup == null) || (this.parentGroup.GetType() == typeof(TreeGroupRoot))))
                        {
                            node.offset = 0f;
                            node.baseAngle = 0f;
                            node.pitch = 0f;
                            node.scale = (Mathf.Clamp01(this.distributionScaleCurve.Evaluate(node.offset)) * this.distributionScale) + (1f - this.distributionScale);
                        }
                        else
                        {
                            int index = 0;
                            int count = 0;
                            for (int n = 0; n < this.nodes.Count; n++)
                            {
                                if (this.nodes[n].parentID == node.parentID)
                                {
                                    if (k == n)
                                    {
                                        index = count;
                                    }
                                    count++;
                                }
                            }
                            switch (this.distributionMode)
                            {
                                case DistributionMode.Random:
                                    num10 = 0f;
                                    num11 = 0f;
                                    num12 = 0;
                                    goto Label_01DB;

                                case DistributionMode.Alternate:
                                {
                                    float num14 = this.ComputeOffset(index, count, distributionSum, distributionStep);
                                    float num15 = 180f * index;
                                    node.baseAngle = num15 + ((num14 * this.distributionTwirl) * 360f);
                                    node.offset = num14;
                                    break;
                                }
                                case DistributionMode.Opposite:
                                {
                                    float num16 = this.ComputeOffset(index / 2, count / 2, distributionSum, distributionStep);
                                    float num17 = (90f * (index / 2)) + ((index % 2) * 180f);
                                    node.baseAngle = num17 + ((num16 * this.distributionTwirl) * 360f);
                                    node.offset = num16;
                                    break;
                                }
                                case DistributionMode.Whorled:
                                {
                                    int distributionNodes = this.distributionNodes;
                                    int num19 = index % distributionNodes;
                                    int num20 = index / distributionNodes;
                                    float num21 = this.ComputeOffset(index / distributionNodes, count / distributionNodes, distributionSum, distributionStep);
                                    float num22 = ((360f / ((float) distributionNodes)) * num19) + ((180f / ((float) distributionNodes)) * num20);
                                    node.baseAngle = num22 + ((num21 * this.distributionTwirl) * 360f);
                                    node.offset = num21;
                                    break;
                                }
                            }
                        }
                    }
                    continue;
                Label_01CA:
                    num11 = UnityEngine.Random.value * distributionSum;
                    num12++;
                Label_01DB:
                    if (num12 < 5)
                    {
                        goto Label_01CA;
                    }
                    for (int m = 0; m < numArray.Length; m++)
                    {
                        num10 = ((float) m) / num3;
                        num11 -= numArray[m];
                        if (num11 <= 0f)
                        {
                            break;
                        }
                    }
                    node.baseAngle = UnityEngine.Random.value * 360f;
                    node.offset = num10;
                }
            }
            for (int i = 0; i < this.nodes.Count; i++)
            {
                TreeNode node2 = this.nodes[i];
                if (node2.parent == null)
                {
                    node2.visible = true;
                }
                else
                {
                    node2.visible = node2.parent.visible;
                    if (node2.offset > node2.parent.breakOffset)
                    {
                        node2.visible = false;
                    }
                }
                if (this.lockFlags == 0)
                {
                    node2.angle = node2.baseAngle;
                    node2.pitch = (Mathf.Clamp(this.distributionPitchCurve.Evaluate(node2.offset), -1f, 1f) * -75f) * this.distributionPitch;
                }
                else
                {
                    node2.angle = node2.baseAngle;
                }
                node2.scale = (Mathf.Clamp01(this.distributionScaleCurve.Evaluate(node2.offset)) * this.distributionScale) + (1f - this.distributionScale);
            }
            if ((this.parentGroup == null) || (this.parentGroup.GetType() == typeof(TreeGroupRoot)))
            {
                for (int num24 = 0; num24 < this.nodes.Count; num24++)
                {
                    this.nodes[num24].animSeed = 0f;
                }
            }
            else
            {
                for (int num25 = 0; num25 < this.nodes.Count; num25++)
                {
                    if (this.nodes[num25].parent == null)
                    {
                        this.nodes[num25].animSeed = 0f;
                    }
                    else if (this.nodes[num25].parent.animSeed == 0f)
                    {
                        this.nodes[num25].animSeed = ((((float) this.nodes[num25].seed) / 9.78f) % 1f) + 0.001f;
                    }
                    else
                    {
                        this.nodes[num25].animSeed = this.nodes[num25].parent.animSeed;
                    }
                }
            }
            if (updateSubGroups)
            {
                for (int num26 = 0; num26 < this.childGroups.Count; num26++)
                {
                    this.childGroups[num26].UpdateDistribution(completeUpdate, updateSubGroups);
                }
            }
        }

Usage Example

Beispiel #1
0
        public void UpdateDistribution(int id)
        {
            TreeGroup group = this.GetGroup(id);

            if (group == null)
            {
                return;
            }
            int seed = UnityEngine.Random.seed;

            this.ClearReferences();
            this.ValidateReferences();
            group.UpdateDistribution(true, true);
            this.ClearReferences();
            UnityEngine.Random.seed = seed;
        }