Exemple #1
0
        private FoundationArchitect.Edge CalcEdge(Vector3 p1, Vector3 p2)
        {
            FoundationArchitect.Edge edge = new FoundationArchitect.Edge
            {
                _p1 = p1,
                _p2 = p2
            };
            edge._hlength  = Vector3.Distance(p1, p2);
            edge._segments = new FoundationArchitect.HorizontalSegment[Mathf.CeilToInt(edge._hlength / this._maxSegmentHorizontalLength)];
            float edgeSegmentLength = this.GetEdgeSegmentLength(edge._hlength);

            edge._axis = (p2 - p1).normalized * edgeSegmentLength;
            Vector3 vector = p1;
            Vector3 b      = this.GetSegmentPointFloorPosition(vector);

            for (int i = 0; i < edge._segments.Length; i++)
            {
                FoundationArchitect.HorizontalSegment horizontalSegment = new FoundationArchitect.HorizontalSegment();
                horizontalSegment._p1 = vector;
                horizontalSegment._p2 = ((i + 1 != edge._segments.Length) ? (vector + edge._axis) : p2);
                Vector3 segmentPointFloorPosition = this.GetSegmentPointFloorPosition(horizontalSegment._p2);
                horizontalSegment._height   = Mathf.Max(Vector3.Distance(vector, b), Vector3.Distance(horizontalSegment._p2, segmentPointFloorPosition));
                horizontalSegment._segments = new FoundationArchitect.VerticalSegment[Mathf.CeilToInt(horizontalSegment._height / this._logLength)];
                for (int j = 0; j < horizontalSegment._segments.Length; j++)
                {
                    FoundationArchitect.VerticalSegment verticalSegment = new FoundationArchitect.VerticalSegment();
                    float num = (j + 1 != horizontalSegment._segments.Length) ? this._logLength : (horizontalSegment._height - (float)j * this._logLength);
                    if (num >= this._maxHeightWithoutDiagonal)
                    {
                        verticalSegment._diag = true;
                    }
                    horizontalSegment._segments[j] = verticalSegment;
                }
                vector            = horizontalSegment._p2;
                b                 = segmentPointFloorPosition;
                edge._segments[i] = horizontalSegment;
            }
            return(edge);
        }
Exemple #2
0
        private GameObject SpawnEdge(FoundationArchitect.Edge edge, int edgeNum)
        {
            GameObject gameObject = new GameObject("Edge" + edgeNum);
            Transform  transform  = gameObject.transform;

            gameObject.transform.position = edge._p1;
            float      num                = edge._hlength / (float)edge._segments.Length;
            Vector3    localScale         = new Vector3(1f, 1f, num / this._logLength);
            Vector3    localScale2        = new Vector3(1f, 1f, this.CalcDiagonalLength(1f, localScale.z));
            Vector3    vector             = edge._axis / 2f;
            Vector3    b                  = new Vector3(0f, this._logLength / 2f, 0f);
            Vector3    b2                 = new Vector3(0f, this._logLength, 0f);
            Quaternion rotation           = Quaternion.Euler(90f, 0f, 0f);
            Quaternion rotation2          = Quaternion.LookRotation(edge._axis);
            Vector3    forward            = vector - b;
            Quaternion rotation3          = Quaternion.LookRotation(forward);
            float      logStackScaleRatio = (this._maxScaleLogCost <= 0f) ? 0f : (this._maxLogScale / this._maxScaleLogCost);
            float      num2               = 0f;
            Transform  transform2         = transform;

            edge._totalLogs = 0;
            int num3 = this._edges.Take(edgeNum).Sum((FoundationArchitect.Edge e) => e._segments.Length);

            string[] array = new string[]
            {
                "SLTier1",
                "SLTier2",
                "SLTier3"
            };
            float num4 = b2.y * (float)Mathf.CeilToInt(this.MaxHeight / b2.y / 3f) - 0.4f;

            for (int i = 0; i < edge._segments.Length; i++)
            {
                FoundationArchitect.HorizontalSegment horizontalSegment = edge._segments[i];
                Vector3 vector2 = Vector3.zero;
                num2 = 0f;
                Transform transform3 = new GameObject(i.ToString()).transform;
                transform3.parent = transform;
                int  j    = 0;
                bool flag = this._wasBuilt;
                for (int k = 0; k < horizontalSegment._segments.Length; k++)
                {
                    if (this.SegmentTierValidation(num3 + i, j))
                    {
                        FoundationArchitect.VerticalSegment verticalSegment = horizontalSegment._segments[k];
                        if (flag)
                        {
                            flag                = false;
                            transform2          = new GameObject("t").transform;
                            transform2.parent   = transform3;
                            transform2.position = horizontalSegment._p1 - vector2 + vector - new Vector3(0f, num4 / 2f, 0f);
                            transform2.rotation = rotation2;
                            transform2.tag      = array[j];
                            BoxCollider boxCollider = transform2.gameObject.AddComponent <BoxCollider>();
                            boxCollider.size = new Vector3(1.1f, num4 + 0.4f, 4.8f * localScale.z);
                            FoundationChunkTier foundationChunkTier = transform2.gameObject.AddComponent <FoundationChunkTier>();
                            foundationChunkTier._edgeNum    = edgeNum;
                            foundationChunkTier._segmentNum = i;
                            foundationChunkTier._tierNum    = j;
                            this._chunks.Add(foundationChunkTier);
                            transform2.gameObject.AddComponent <gridObjectBlocker>();
                            getStructureStrength getStructureStrength = transform2.gameObject.AddComponent <getStructureStrength>();
                            getStructureStrength._strength = getStructureStrength.strength.strong;
                        }
                        if (edge._isFirst && i == 0)
                        {
                            edge._totalLogs++;
                            Transform transform4 = this.NewLog(edge._p1 - vector2 - b, rotation);
                            if (!this._wasBuilt)
                            {
                                this.StackLogsByScale(ref num2, logStackScaleRatio, 1f, ref transform2, transform4, transform3);
                            }
                            else
                            {
                                transform4.parent = transform2;
                            }
                            transform4.localScale = Vector3.one;
                            this._newPool.Push(transform4);
                        }
                        if (!edge._isClosing || i + 1 < edge._segments.Length)
                        {
                            edge._totalLogs++;
                            Transform transform5 = this.NewLog(horizontalSegment._p2 - vector2 - b, rotation);
                            if (!this._wasBuilt)
                            {
                                this.StackLogsByScale(ref num2, logStackScaleRatio, 1f, ref transform2, transform5, transform3);
                            }
                            else
                            {
                                transform5.parent = transform2;
                            }
                            transform5.localScale = Vector3.one;
                            this._newPool.Push(transform5);
                        }
                        edge._totalLogs++;
                        Transform transform6 = this.NewLog(horizontalSegment._p1 - vector2 + vector, rotation2);
                        if (!this._wasBuilt)
                        {
                            this.StackLogsByScale(ref num2, logStackScaleRatio, localScale.z, ref transform2, transform6, transform3);
                        }
                        else
                        {
                            transform6.parent = transform2;
                        }
                        transform6.localScale = localScale;
                        this._newPool.Push(transform6);
                        if (verticalSegment._diag)
                        {
                            edge._totalLogs++;
                            transform6 = this.NewLog(transform6.position - b, rotation3);
                            if (!this._wasBuilt)
                            {
                                this.StackLogsByScale(ref num2, logStackScaleRatio, localScale.z, ref transform2, transform6, transform3);
                            }
                            else
                            {
                                transform6.parent = transform2;
                            }
                            transform6.localScale = localScale2;
                            this._newPool.Push(transform6);
                        }
                    }
                    vector2 += b2;
                    if (this._wasBuilt && j < 2 && vector2.y > num4 * (float)(1 + j))
                    {
                        j++;
                        flag = true;
                    }
                }
                if (!flag)
                {
                    j++;
                }
                while (j <= 2)
                {
                    this._chunks.Add(null);
                    j++;
                }
            }
            if (edge._isFirst)
            {
                this._foundationRoot.transform.position = edge._p1;
            }
            gameObject.transform.parent = this._foundationRoot.transform;
            return(gameObject);
        }