Exemplo n.º 1
0
        private bool LockCurrentPoint()
        {
            bool result = false;

            if (this._multiPointsPositions.Count > 2 && Vector3.Distance(base.transform.position, this._multiPointsPositions[0]) < this._closureSnappingDistance)
            {
                this._multiPointsPositions.Add(this._multiPointsPositions[0]);
                result = true;
            }
            else
            {
                Vector3 supportSnappedPoint = this.GetSupportSnappedPoint();
                if (this._multiPointsPositions.Count > 1)
                {
                    Vector3 item = MathEx.TryAngleSnap(supportSnappedPoint, this._multiPointsPositions[this._multiPointsPositions.Count - 1], this._multiPointsPositions[this._multiPointsPositions.Count - 2], PlayerPreferences.BuildingSnapAngle, PlayerPreferences.BuildingSnapRange, true);
                    item.y = base.transform.position.y;
                    this._multiPointsPositions.Add(item);
                }
                else
                {
                    this._multiPointsPositions.Add(supportSnappedPoint);
                }
            }
            if (this._multiPointsPositions.Count > 1)
            {
                this._newPool = new Queue <Transform>();
                WallArchitect.Edge edge = this.CreateEdge(this._multiPointsPositions[this._multiPointsPositions.Count - 2], this._multiPointsPositions[this._multiPointsPositions.Count - 1]);
                edge._root.parent = this._wallRoot.transform;
                this._edges.Add(edge);
                this._logPool.Clear();
            }
            return(result);
        }
Exemplo n.º 2
0
 protected WallArchitect.Edge CreateEdge(Vector3 p1, Vector3 p2)
 {
     WallArchitect.Edge edge = this.CalcEdge(p1, p2);
     edge._root   = this.SpawnEdge(edge);
     edge._height = this._currentHeight;
     return(edge);
 }
Exemplo n.º 3
0
 private void CreateStructure()
 {
     for (int i = 1; i < this._multiPointsPositions.Count; i++)
     {
         WallArchitect.Edge item = this.CalcEdge(this._multiPointsPositions[i - 1], this._multiPointsPositions[i]);
         this._edges.Add(item);
     }
 }
Exemplo n.º 4
0
        private WallArchitect.Edge CalcEdge(Vector3 p1, Vector3 p2)
        {
            int     num = 0;
            Vector3 a   = p1;

            WallArchitect.Edge edge = new WallArchitect.Edge
            {
                _p1 = p1,
                _p2 = p2
            };
            bool aboveTerrain = p1.y - Terrain.activeTerrain.SampleHeight(p1) > -1f;

            edge._hlength  = Vector3.Scale(p2 - p1, new Vector3(1f, 0f, 1f)).magnitude;
            edge._segments = new WallArchitect.HorizontalSegment[Mathf.CeilToInt(edge._hlength / this._maxSegmentHorizontalLength)];
            float   d      = edge._hlength / (float)edge._segments.Length;
            float   num2   = this._logWidth / 2f * 0.98f;
            Vector3 b      = (p2 - p1).normalized * d;
            Vector3 vector = p1;

            for (int i = 0; i < edge._segments.Length; i++)
            {
                bool flag = false;
                WallArchitect.HorizontalSegment horizontalSegment = new WallArchitect.HorizontalSegment();
                horizontalSegment._p1     = vector;
                horizontalSegment._p2     = ((i + 1 != edge._segments.Length) ? this.GetSegmentPointFloorPosition(aboveTerrain, vector + b, out flag) : p2);
                horizontalSegment._axis   = (horizontalSegment._p2 - horizontalSegment._p1).normalized * d;
                horizontalSegment._length = Vector3.Distance(horizontalSegment._p1, horizontalSegment._p2);
                if (num == 1 && !flag)
                {
                    Vector3 vector2 = Vector3.Lerp(a, horizontalSegment._p2, 0.5f);
                    vector2.y                += this.SegmentPointTestOffset / 2f;
                    horizontalSegment._p1     = vector2;
                    vector2.y                += num2;
                    edge._segments[i - 1]._p2 = vector2;
                }
                if (flag && edge._segments.Length == 2)
                {
                    num++;
                }
                else
                {
                    num = 0;
                    a   = horizontalSegment._p2;
                }
                vector = horizontalSegment._p2;
                WallArchitect.HorizontalSegment horizontalSegment2 = horizontalSegment;
                horizontalSegment2._p1.y = horizontalSegment2._p1.y + num2;
                WallArchitect.HorizontalSegment horizontalSegment3 = horizontalSegment;
                horizontalSegment3._p2.y = horizontalSegment3._p2.y + num2;
                edge._segments[i]        = horizontalSegment;
            }
            return(edge);
        }
Exemplo n.º 5
0
        private void UpdateAutoFill(bool doCleanUp)
        {
            bool flag = this._autofillmode && this.CurrentSupport != null && this.CurrentSupport.GetMultiPointsPositions(true) != null;

            if (flag)
            {
                if (this._multiPointsPositions.Count > 0)
                {
                    this.Clear();
                    this._wallRoot = new GameObject("WallRoot");
                    this._multiPointsPositions.Clear();
                }
                LocalPlayer.Create.BuildingPlacer.Clear = false;
                this._canPlaceLock = true;
                Create.CanLock     = true;
                List <Vector3> multiPointsPositions = this.CurrentSupport.GetMultiPointsPositions(true);
                float          height = this.CurrentSupport.GetHeight();
                if (multiPointsPositions.Count > 1)
                {
                    List <Transform> list = new List <Transform>();
                    for (int i = 0; i < multiPointsPositions.Count; i++)
                    {
                        Vector3 item = multiPointsPositions[i];
                        item.y += height;
                        this._multiPointsPositions.Add(item);
                        if (i > 0)
                        {
                            this._newPool = new Queue <Transform>();
                            WallArchitect.Edge edge = this.CreateEdge(this._multiPointsPositions[this._multiPointsPositions.Count - 2], this._multiPointsPositions[this._multiPointsPositions.Count - 1]);
                            edge._root.parent = this._wallRoot.transform;
                            this._edges.Add(edge);
                            list.AddRange(this._newPool);
                            this._newPool.Clear();
                        }
                    }
                    this._logPool = new Queue <Transform>(list);
                    base.GetComponent <Renderer>().enabled = false;
                }
                else
                {
                    this._multiPointsPositions.Clear();
                    base.GetComponent <Renderer>().enabled = true;
                }
            }
            else if (this._autofillmode || doCleanUp)
            {
                this.Clear();
                this._wallRoot = new GameObject("WallRoot");
                this._multiPointsPositions.Clear();
                this.ShowTempWall();
                base.GetComponent <Renderer>().enabled = true;
            }
        }
Exemplo n.º 6
0
        protected override Transform SpawnEdge(WallArchitect.Edge edge)
        {
            Transform transform = new GameObject("RockPathEdge").transform;

            transform.transform.position = edge._p1;
            transform.LookAt(edge._p2);
            for (int i = 0; i < edge._segments.Length; i++)
            {
                WallArchitect.HorizontalSegment horizontalSegment = edge._segments[i];
                Vector3   a          = horizontalSegment._p2 - horizontalSegment._p1;
                Vector3   normalized = Vector3.Scale(a, new Vector3(1f, 0f, 1f)).normalized;
                Transform transform2 = new GameObject("S" + i).transform;
                transform2.parent   = transform;
                transform2.position = horizontalSegment._p1;
                transform2.LookAt(horizontalSegment._p2);
                horizontalSegment._root = transform2;
                Vector3 vector  = horizontalSegment._p1 + transform2.right * (float)this._width;
                Vector3 vector2 = horizontalSegment._p1 - transform2.right * (float)this._width;
                float   num     = Vector3.Distance(horizontalSegment._p1, horizontalSegment._p2);
                int     num2    = Mathf.RoundToInt(num / this._logWidth) + 1;
                if (num2 < 1)
                {
                    num2 = 1;
                }
                Vector3 vector3 = normalized * (num / (float)num2);
                vector  += vector3 / 2f;
                vector2 += vector3 / 2f;
                Terrain activeTerrain = Terrain.activeTerrain;
                for (int j = 0; j < num2; j++)
                {
                    vector.y = activeTerrain.SampleHeight(vector);
                    Transform transform3 = base.NewLog(vector, transform2.rotation);
                    transform3.localScale = Vector3.one;
                    transform3.parent     = transform2;
                    this._newPool.Enqueue(transform3);
                    vector   += vector3;
                    vector2.y = activeTerrain.SampleHeight(vector2);
                    Transform transform4 = base.NewLog(vector2, transform2.rotation);
                    transform4.localScale = Vector3.one;
                    transform4.parent     = transform2;
                    this._newPool.Enqueue(transform4);
                    vector2 += vector3;
                }
            }
            return(transform);
        }
Exemplo n.º 7
0
        protected override Transform SpawnEdge(WallArchitect.Edge edge)
        {
            Transform transform = new GameObject("RockFenceEdge").transform;

            transform.transform.position = edge._p1;
            transform.LookAt(edge._p2);
            for (int i = 0; i < edge._segments.Length; i++)
            {
                WallArchitect.HorizontalSegment horizontalSegment = edge._segments[i];
                Vector3    vector     = horizontalSegment._p1;
                Vector3    vector2    = horizontalSegment._p2 - horizontalSegment._p1;
                Vector3    normalized = Vector3.Scale(vector2, new Vector3(1f, 0f, 1f)).normalized;
                float      y          = Mathf.Tan(Vector3.Angle(vector2, normalized) * 0.0174532924f) * this._offset;
                Quaternion rotation   = Quaternion.LookRotation(-vector2);
                Transform  transform2 = new GameObject("S" + i).transform;
                transform2.parent   = transform;
                transform2.position = horizontalSegment._p1;
                transform2.LookAt(horizontalSegment._p2);
                horizontalSegment._root = transform2;
                bool  flag = horizontalSegment._p1.y < horizontalSegment._p2.y;
                float num  = Vector3.Distance(horizontalSegment._p1, horizontalSegment._p2);
                int   j    = Mathf.RoundToInt(num / this._offset);
                if (j < 1)
                {
                    j = 1;
                }
                Vector3 a = normalized * this._offset;
                a.y = y;
                if (!flag)
                {
                    a.y *= -1f;
                }
                vector.y -= 0.15f;
                while (j > 0)
                {
                    int num2 = Mathf.Min(j, 5);
                    j -= num2;
                    Transform transform3 = UnityEngine.Object.Instantiate <Transform>(Prefabs.Instance.RockFenceChunksGhostPrefabs[num2 - 1], vector, rotation);
                    transform3.GetComponentInChildren <Renderer>().sharedMaterial = Create.CurrentGhostMat;
                    transform3.parent = transform2;
                    vector           += a * (float)num2;
                }
            }
            return(transform);
        }
Exemplo n.º 8
0
        protected override Transform SpawnEdge(WallArchitect.Edge edge)
        {
            Transform transform = new GameObject("WallDefensiveEdge").transform;

            transform.transform.position = edge._p1;
            Vector3    vector     = edge._p2 - edge._p1;
            Vector3    normalized = Vector3.Scale(vector, new Vector3(1f, 0f, 1f)).normalized;
            float      y          = Mathf.Tan(Vector3.Angle(vector, normalized) * 0.0174532924f) * this._logWidth;
            Quaternion rotation   = Quaternion.LookRotation(Vector3.forward);

            for (int i = 0; i < edge._segments.Length; i++)
            {
                WallArchitect.HorizontalSegment horizontalSegment = edge._segments[i];
                Vector3   vector2    = horizontalSegment._p1;
                Transform transform2 = new GameObject("Segment" + i).transform;
                transform2.parent       = transform;
                horizontalSegment._root = transform2;
                transform2.position     = horizontalSegment._p1;
                float   num  = Vector3.Distance(horizontalSegment._p1, horizontalSegment._p2);
                int     num2 = Mathf.RoundToInt(num / this._logWidth);
                Vector3 b    = normalized * num / (float)num2;
                b.y = y;
                if (vector.y < 0f)
                {
                    b.y *= -1f;
                }
                for (int j = 0; j < num2; j++)
                {
                    Transform transform3 = base.NewLog(vector2, rotation);
                    transform3.parent = transform2;
                    this._newPool.Enqueue(transform3);
                    vector2 += b;
                }
            }
            return(transform);
        }
Exemplo n.º 9
0
        protected virtual Transform SpawnEdge(WallArchitect.Edge edge)
        {
            Transform transform = new GameObject("WallEdge").transform;

            transform.transform.position = edge._p1;
            Vector3 vector = edge._p2 - edge._p1;
            int     num    = Mathf.RoundToInt(this._currentHeight);

            if (this._autofillmode || Vector3.Distance(edge._p1, edge._p2) > this._logWidth * 3.5f)
            {
                Vector3 b = new Vector3(0f, this._logWidth * 0.95f, 0f);
                for (int i = 0; i < edge._segments.Length; i++)
                {
                    WallArchitect.HorizontalSegment horizontalSegment = edge._segments[i];
                    Quaternion rotation   = Quaternion.LookRotation(horizontalSegment._axis);
                    Vector3    vector2    = horizontalSegment._p1;
                    Transform  transform2 = new GameObject("Segment" + i).transform;
                    transform2.parent = transform;
                    transform2.LookAt(horizontalSegment._axis);
                    horizontalSegment._root = transform2;
                    transform2.position     = horizontalSegment._p1;
                    Vector3 localScale = new Vector3(1f, 1f, horizontalSegment._length / this._logLength);
                    Vector3 vector3    = new Vector3(1f, 1f, 0.31f + (localScale.z - 1f) / 2f);
                    float   num2       = 1f - vector3.z / localScale.z;
                    for (int j = 0; j < num; j++)
                    {
                        Transform transform3 = this.NewLog(vector2, rotation);
                        transform3.parent = transform2;
                        this._newPool.Enqueue(transform3);
                        transform3.localScale = localScale;
                        vector2 += b;
                    }
                }
            }
            else
            {
                Vector3    normalized  = Vector3.Scale(vector, new Vector3(1f, 0f, 1f)).normalized;
                float      y           = Mathf.Tan(Vector3.Angle(vector, normalized) * 0.0174532924f) * this._logWidth;
                Quaternion rotation2   = Quaternion.LookRotation(Vector3.up);
                Vector3    localScale2 = new Vector3(1f, 1f, (float)num * 0.95f * this._logWidth / this._logLength);
                float      num3        = this._logWidth / 2f * 0.98f;
                for (int k = 0; k < edge._segments.Length; k++)
                {
                    WallArchitect.HorizontalSegment horizontalSegment2 = edge._segments[k];
                    Vector3 vector4 = horizontalSegment2._p1;
                    vector4.y -= num3;
                    Transform transform4 = new GameObject("Segment" + k).transform;
                    transform4.parent        = transform;
                    horizontalSegment2._root = transform4;
                    transform4.position      = horizontalSegment2._p1;
                    float   num4    = Vector3.Distance(horizontalSegment2._p1, horizontalSegment2._p2);
                    int     num5    = Mathf.Max(Mathf.RoundToInt((num4 - this._logWidth * 0.96f / 2f) / this._logWidth), 1);
                    Vector3 vector5 = normalized * this._logWidth * 0.98f;
                    vector5.y = y;
                    vector4  += vector5 / 2f;
                    if (vector.y < 0f)
                    {
                        vector5.y *= -1f;
                    }
                    for (int l = 0; l < num5; l++)
                    {
                        Transform transform5 = this.NewLog(vector4, rotation2);
                        transform5.parent = transform4;
                        this._newPool.Enqueue(transform5);
                        vector4 += vector5;
                        transform5.localScale = localScale2;
                    }
                }
            }
            return(transform);
        }
Exemplo n.º 10
0
        private void Update()
        {
            if (this._canPlayerToggleAutofillmode && TheForest.Utils.Input.GetButtonDown("Craft") && this.CurrentSupport != null)
            {
                this._canScriptToggleAutofillmode = false;
                this._autofillmode = !this._autofillmode;
                PlayerPreferences.ExWallAutofill = this._autofillmode;
                PlayerPrefs.SetInt("ExWallAutofill", (!PlayerPreferences.ExWallAutofill) ? 0 : 1);
                this._saveAutofill = true;
                this.UpdateAutoFill(true);
            }
            bool flag = false;
            bool flag3;

            if (!this._autofillmode)
            {
                bool flag2 = this._multiPointsPositions.Count > 0;
                if (flag2 && TheForest.Utils.Input.GetButtonDown("AltFire"))
                {
                    this._tmpEdge.Clear();
                    this._tmpEdge = null;
                    if (this._multiPointsPositions.Count > 1)
                    {
                        this._edges[this._edges.Count - 1].Clear();
                        this._edges.RemoveAt(this._edges.Count - 1);
                    }
                    this._multiPointsPositions.RemoveAt(this._multiPointsPositions.Count - 1);
                }
                Create.CanLock     = this.CanLock;
                this._canPlaceLock = this.CanPlaceLock;
                flag3 = (this._canPlaceLock || this.CanPlaceNoLock);
                if ((Create.CanLock || this._canPlaceLock) && this._multiPointsPositions.Count > 0)
                {
                    Vector3    vector = base.transform.position - this._multiPointsPositions[this._multiPointsPositions.Count - 1];
                    RaycastHit raycastHit;
                    if (Physics.SphereCast(this._multiPointsPositions[this._multiPointsPositions.Count - 1] + Vector3.up, 0.5f, vector.normalized, out raycastHit, vector.magnitude, 1 << LayerMask.NameToLayer("treeMid")))
                    {
                        Create.CanLock     = false;
                        this._canPlaceLock = false;
                        flag3 = false;
                        LocalPlayer.Create.BuildingPlacer.Clear = false;
                    }
                }
                if ((Create.CanLock && TheForest.Utils.Input.GetButtonDown("Fire1")) || (this._canPlaceLock && TheForest.Utils.Input.GetButtonDown("Build")))
                {
                    this.LockCurrentPoint();
                    base.GetComponent <Renderer>().enabled = false;
                }
                this.UpdateHeight();
                bool flag4 = this._multiPointsPositions.Count > 2 && Vector3.Distance(this._multiPointsPositions.First <Vector3>(), this._multiPointsPositions.Last <Vector3>()) > this._logLength;
                if (flag4 && TheForest.Utils.Input.GetButtonDown("Rotate"))
                {
                    this._multiPointsPositions.Add(this._multiPointsPositions.First <Vector3>());
                    this._newPool = new Queue <Transform>();
                    WallArchitect.Edge edge = this.CreateEdge(this._multiPointsPositions[this._multiPointsPositions.Count - 2], this._multiPointsPositions[this._multiPointsPositions.Count - 1]);
                    edge._root.parent = this._wallRoot.transform;
                    this._edges.Add(edge);
                    this._logPool.Clear();
                    flag = true;
                }
                this.ShowTempWall();
            }
            else
            {
                flag3 = false;
                this.UpdateHeight();
                if (this._multiPointsPositions.Count > 1)
                {
                    Create.CanLock = true;
                    if (this._autofillmode && TheForest.Utils.Input.GetButtonDown("Build"))
                    {
                        flag = true;
                    }
                }
                else
                {
                    Create.CanLock = false;
                    this.ShowTempWall();
                }
            }
            bool flag5 = LocalPlayer.Create.BuildingPlacer.OnDynamicClear && (Create.CanLock || this._canPlaceLock || flag3) && (this._multiPointsPositions.Count > 1 || (this._multiPointsPositions.Count == 1 && Vector3.Distance(base.transform.position, this._multiPointsPositions[this._multiPointsPositions.Count - 1]) > this.MinPlaceLockLength));

            if (LocalPlayer.Create.BuildingPlacer.Clear != flag5)
            {
                LocalPlayer.Create.BuildingPlacer.Clear = flag5;
            }
            if (flag)
            {
                LocalPlayer.Create.PlaceGhost(false);
            }
            else
            {
                this._caster.CastForAnchors <PrefabIdentifier>(new Action <PrefabIdentifier>(this.CheckTargetingSupport));
            }
            bool flag6             = !this._autofillmode && this._multiPointsPositions.Count == 0;
            bool canToggleAutofill = this._canPlayerToggleAutofillmode && this.CurrentSupport != null;
            bool canLock           = !flag6 && Create.CanLock;
            bool canUnlock         = !this._autofillmode && this._multiPointsPositions.Count > 0;
            bool showAutofillPlace = this._autofillmode && flag5;
            bool showManualPlace   = !this._autofillmode && flag5;

            this.ConstructionIcons.Show(flag6, canToggleAutofill, showAutofillPlace, showManualPlace, canLock, canUnlock, false);
        }
Exemplo n.º 11
0
        private IEnumerator OnPlaced()
        {
            base.enabled = false;
            yield return(null);

            if (!this._autofillmode && this.CanLock && this._multiPointsPositions.Last <Vector3>() != this._multiPointsPositions.First <Vector3>())
            {
                this.LockCurrentPoint();
            }
            if (Scene.HudGui)
            {
                Scene.HudGui.WallConstructionIcons.Shutdown();
            }
            if (this._tmpEdge != null && this._tmpEdge._root)
            {
                this._tmpEdge._root.parent = null;
                UnityEngine.Object.Destroy(this._tmpEdge._root.gameObject);
            }
            LocalPlayer.Create.Grabber.ClosePlace();
            int   chunkCount  = 0;
            float lengthCount = 0f;

            for (int i = 0; i < this._edges.Count; i++)
            {
                WallArchitect.Edge edge = this._edges[i];
                float height            = (!this._autofillmode) ? edge._height : this._currentHeight;
                lengthCount += edge._hlength;
                for (int j = 0; j < edge._segments.Length; j++)
                {
                    WallArchitect.HorizontalSegment horizontalSegment = edge._segments[j];
                    if (this.CheckForDoubledUpGhost(horizontalSegment))
                    {
                        IStructureSupport segmentSupport = this.GetSegmentSupport(horizontalSegment);
                        if (BoltNetwork.isRunning)
                        {
                            PlaceWallChunk     placeWallChunk     = PlaceWallChunk.Create(GlobalTargets.OnlyServer);
                            CoopWallChunkToken coopWallChunkToken = new CoopWallChunkToken();
                            coopWallChunkToken.P1 = horizontalSegment._p1;
                            coopWallChunkToken.P2 = horizontalSegment._p2;
                            coopWallChunkToken.PointsPositions = this.MultiPointsPositions.ToArray();
                            coopWallChunkToken.Additions       = WallChunkArchitect.Additions.Wall;
                            coopWallChunkToken.Height          = height;
                            placeWallChunk.parent  = ((segmentSupport == null) ? base.transform.GetComponentInParent <BoltEntity>() : (segmentSupport as Component).GetComponentInParent <BoltEntity>());
                            placeWallChunk.token   = coopWallChunkToken;
                            placeWallChunk.prefab  = this.ChunkPrefab.GetComponent <BoltEntity>().prefabId;
                            placeWallChunk.support = null;
                            placeWallChunk.Send();
                        }
                        else
                        {
                            WallChunkArchitect wallChunkArchitect = UnityEngine.Object.Instantiate <WallChunkArchitect>(this.ChunkPrefab);
                            wallChunkArchitect.transform.parent   = ((segmentSupport == null) ? base.transform.parent : (segmentSupport as Component).transform);
                            wallChunkArchitect.transform.position = horizontalSegment._p1;
                            wallChunkArchitect.transform.LookAt(horizontalSegment._p2);
                            wallChunkArchitect.MultipointPositions = this._multiPointsPositions;
                            wallChunkArchitect.P1             = horizontalSegment._p1;
                            wallChunkArchitect.P2             = horizontalSegment._p2;
                            wallChunkArchitect.CurrentSupport = segmentSupport;
                            wallChunkArchitect.Height         = height;
                        }
                        chunkCount++;
                    }
                }
            }
            if (!base.GetType().IsSubclassOf(typeof(WallArchitect)))
            {
                EventRegistry.Achievements.Publish(TfEvent.Achievements.PlacedWall, Mathf.FloorToInt(lengthCount));
            }
            if (!BoltNetwork.isRunning)
            {
                yield return(null);

                yield return(null);

                yield return(null);

                yield return(null);

                UnityEngine.Object.Destroy(base.gameObject);
            }
            else
            {
                CoopDestroyPredictedGhost coopDestroyPredictedGhost = base.gameObject.AddComponent <CoopDestroyPredictedGhost>();
                coopDestroyPredictedGhost.count = (float)chunkCount;
                coopDestroyPredictedGhost.delay = 0.005f;
                base.gameObject.AddComponent <destroyAfter>().destroyTime = 2f;
            }
            yield break;
        }
Exemplo n.º 12
0
        protected override Transform SpawnEdge(WallArchitect.Edge edge)
        {
            Transform transform = new GameObject("StickFenceEdge").transform;

            transform.transform.position = edge._p1;
            transform.LookAt(edge._p2);
            Quaternion rotation = Quaternion.LookRotation(Vector3.forward);
            Quaternion rhs      = Quaternion.FromToRotation(Vector3.up, Vector3.forward);

            for (int i = 0; i < edge._segments.Length; i++)
            {
                WallArchitect.HorizontalSegment horizontalSegment = edge._segments[i];
                Vector3   vector     = horizontalSegment._p1;
                Vector3   vector2    = horizontalSegment._p2 - horizontalSegment._p1;
                Vector3   normalized = Vector3.Scale(vector2, new Vector3(1f, 0f, 1f)).normalized;
                float     y          = Mathf.Tan(Vector3.Angle(vector2, normalized) * 0.0174532924f) * this._logWidth * (float)this._spread;
                Transform transform2 = new GameObject("S" + i).transform;
                transform2.parent   = transform;
                transform2.position = horizontalSegment._p1;
                transform2.LookAt(horizontalSegment._p2);
                horizontalSegment._root = transform2;
                bool  flag = horizontalSegment._p1.y < horizontalSegment._p2.y;
                float num  = Vector3.Distance(horizontalSegment._p1, horizontalSegment._p2);
                int   num2 = Mathf.RoundToInt(num / (this._logWidth * (float)this._spread));
                if (num2 > 1)
                {
                    num2--;
                }
                else
                {
                    num2 = 1;
                }
                Vector3 vector3 = normalized * (num / (float)num2);
                vector3.y = y;
                if (!flag)
                {
                    vector3.y *= -1f;
                }
                vector += vector3 / 2f;
                for (int j = 0; j < num2; j++)
                {
                    Transform transform3 = base.NewLog(vector, rotation);
                    transform3.localScale = Vector3.one;
                    transform3.parent     = transform2;
                    this._newPool.Enqueue(transform3);
                    vector += vector3;
                }
                Vector3 vector4 = new Vector3(0f, this._logLength * 0.45f, this._logWidth / 2f);
                Vector3 vector5 = new Vector3(0f, this._logLength * 0.8f, this._logWidth / 2f);
                vector4 += vector3 / 2f;
                vector5 += vector3 / 2f;
                Vector3    localScale = new Vector3(1f, num * 0.335f, 1f);
                Quaternion rotation2  = Quaternion.LookRotation(transform2.forward) * rhs;
                Debug.DrawRay(horizontalSegment._p1 + vector4, -transform2.up, Color.red);
                Transform transform4 = base.NewLog(horizontalSegment._p1 + vector4, rotation2);
                transform4.parent     = transform2;
                transform4.localScale = localScale;
                this._newPool.Enqueue(transform4);
                transform4            = base.NewLog(horizontalSegment._p1 + vector5, rotation2);
                transform4.parent     = transform2;
                transform4.localScale = localScale;
                this._newPool.Enqueue(transform4);
            }
            return(transform);
        }
Exemplo n.º 13
0
        protected override Transform SpawnEdge(WallArchitect.Edge edge)
        {
            Transform transform = new GameObject("StickFenceEdge").transform;

            transform.transform.position = edge._p1;
            transform.LookAt(edge._p2);
            Quaternion quaternion = Quaternion.LookRotation(Vector3.forward);
            Quaternion rhs        = Quaternion.FromToRotation(Vector3.up, Vector3.forward);

            for (int i = 0; i < edge._segments.Length; i++)
            {
                WallArchitect.HorizontalSegment horizontalSegment = edge._segments[i];
                Vector3   position   = horizontalSegment._p1;
                Vector3   vector     = Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.5f);
                Vector3   vector2    = new Vector3(0f, this._logLength, 0f);
                Vector3   vector3    = horizontalSegment._p2 - horizontalSegment._p1;
                Vector3   normalized = Vector3.Scale(vector3, new Vector3(1f, 0f, 1f)).normalized;
                float     y          = Mathf.Tan(Vector3.Angle(vector3, normalized) * 0.0174532924f) * this._logWidth * (float)this._spread;
                Transform transform2 = new GameObject("S" + i).transform;
                transform2.parent   = transform;
                transform2.position = horizontalSegment._p1;
                transform2.LookAt(horizontalSegment._p2);
                horizontalSegment._root = transform2;
                bool    flag    = horizontalSegment._p1.y < horizontalSegment._p2.y;
                float   num     = Vector3.Distance(horizontalSegment._p1, horizontalSegment._p2);
                int     num2    = 4;
                Vector3 vector4 = normalized * (num / (float)num2);
                vector4.y = y;
                if (!flag)
                {
                    vector4.y *= -1f;
                }
                for (int j = 0; j < num2; j++)
                {
                    Transform transform3;
                    switch (j)
                    {
                    case 0:
                        transform3 = base.NewLog(position, Quaternion.LookRotation(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.1f) + vector2 - horizontalSegment._p1) * rhs);
                        Debug.DrawLine(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.1f) + vector2, horizontalSegment._p1, Color.red);
                        break;

                    case 1:
                        position   = vector;
                        transform3 = base.NewLog(position, Quaternion.LookRotation(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.35f) + vector2 - vector) * rhs);
                        Debug.DrawLine(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.35f) + vector2, vector, Color.blue);
                        break;

                    case 2:
                        position   = vector;
                        transform3 = base.NewLog(position, Quaternion.LookRotation(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.7f) + vector2 - vector) * rhs);
                        Debug.DrawLine(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.7f) + vector2, vector, Color.green);
                        break;

                    default:
                        position   = horizontalSegment._p2;
                        transform3 = base.NewLog(position, Quaternion.LookRotation(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.9f) + vector2 - horizontalSegment._p2) * rhs);
                        Debug.DrawLine(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.9f) + vector2, horizontalSegment._p2, Color.yellow);
                        break;
                    }
                    transform3.name   = "v" + j;
                    transform3.parent = transform2;
                    this._newPool.Enqueue(transform3);
                }
                Vector3    vector5    = new Vector3(0f, this._logLength * 0.4f, this._logWidth / 2f);
                Vector3    b          = vector5 + (horizontalSegment._p2 - horizontalSegment._p1) / 2f;
                Quaternion rotation   = Quaternion.LookRotation(vector + vector2 * 0.6f - (horizontalSegment._p1 + vector5)) * rhs;
                Transform  transform4 = base.NewLog(horizontalSegment._p1 + vector5, rotation);
                transform4.name   = "h1";
                transform4.parent = transform2;
                this._newPool.Enqueue(transform4);
                transform4        = base.NewLog(horizontalSegment._p1 + b, rotation);
                transform4.name   = "h2";
                transform4.parent = transform2;
                this._newPool.Enqueue(transform4);
                Quaternion rotation2  = Quaternion.LookRotation(horizontalSegment._p1 + vector2 * 0.8f - vector) * rhs;
                Transform  transform5 = base.NewLog(vector, rotation2);
                transform5.name   = "d1";
                transform5.parent = transform2;
                this._newPool.Enqueue(transform5);
                transform5        = base.NewLog(horizontalSegment._p2, rotation2);
                transform5.name   = "d2";
                transform5.parent = transform2;
                this._newPool.Enqueue(transform5);
            }
            return(transform);
        }
Exemplo n.º 14
0
 private void Update()
 {
     bool flag = this._multiPointsPositions.Count >= 2;
     if (LocalPlayer.Create.BuildingPlacer.Clear != flag)
     {
         Scene.HudGui.PlaceWallIcon.SetActive(flag);
         LocalPlayer.Create.BuildingPlacer.Clear = flag;
     }
     bool flag2 = false;
     if (TheForest.Utils.Input.GetButtonDown("AltFire") && this._multiPointsPositions.Count > 0)
     {
         UnityEngine.Object.Destroy(this._tmpEdge._root.gameObject);
         this._tmpEdge = null;
         if (this._multiPointsPositions.Count > 1)
         {
             UnityEngine.Object.Destroy(this._edges[this._edges.Count - 1]._root.gameObject);
             this._edges.RemoveAt(this._edges.Count - 1);
         }
         this._multiPointsPositions.RemoveAt(this._multiPointsPositions.Count - 1);
     }
     bool canLock = this.CanLock;
     if (canLock && this._multiPointsPositions.Count > 1)
     {
         Vector3 forward = this._multiPointsPositions[this._multiPointsPositions.Count - 2] - this._multiPointsPositions[this._multiPointsPositions.Count - 1];
         Scene.HudGui.AngleAndDistanceGizmoWall.gameObject.SetActive(true);
         Scene.HudGui.AngleAndDistanceGizmoWall.position = this._multiPointsPositions.Last<Vector3>() + Vector3.up;
         Scene.HudGui.AngleAndDistanceGizmoWall.rotation = Quaternion.LookRotation(forward);
     }
     else
     {
         Scene.HudGui.AngleAndDistanceGizmoWall.gameObject.SetActive(false);
     }
     if (TheForest.Utils.Input.GetButtonDown("Fire1") && canLock)
     {
         this.LockCurrentPoint();
         base.GetComponent<Renderer>().enabled = false;
     }
     bool flag3 = this._multiPointsPositions.Count == 0 && this.CurrentSupport != null && this.CurrentSupport.GetMultiPointsPositions() != null;
     if (TheForest.Utils.Input.GetButtonAfterDelay("Craft", 0.5f) && flag3)
     {
         this._multiPointsPositions = new List<Vector3>(this.CurrentSupport.GetMultiPointsPositions());
         float height = this.CurrentSupport.GetHeight();
         for (int i = 0; i < this._multiPointsPositions.Count; i++)
         {
             Vector3 value = this._multiPointsPositions[i];
             value.y += height;
             this._multiPointsPositions[i] = value;
         }
         this._checkGround = false;
         this._newPool = new Queue<Transform>();
         this.CreateStructure();
         flag3 = false;
         flag2 = true;
     }
     bool flag4 = this._multiPointsPositions.Count > 2 && Vector3.Distance(this._multiPointsPositions.First<Vector3>(), this._multiPointsPositions.Last<Vector3>()) > this._logLength;
     if (flag4 && TheForest.Utils.Input.GetButtonDown("Rotate"))
     {
         this._multiPointsPositions.Add(this._multiPointsPositions.First<Vector3>());
         this._newPool = new Queue<Transform>();
         WallArchitect.Edge edge = this.CreateEdge(this._multiPointsPositions[this._multiPointsPositions.Count - 2], this._multiPointsPositions[this._multiPointsPositions.Count - 1]);
         edge._root.parent = this._wallRoot.transform;
         this._edges.Add(edge);
         this._logPool.Clear();
         flag2 = true;
     }
     this.ShowTempWall();
     if (flag2)
     {
         LocalPlayer.Create.PlaceGhost(false);
     }
     Scene.HudGui.LockPositionIcon.SetActive(this._multiPointsPositions.Count < this._maxPoints && canLock);
     Scene.HudGui.UnlockPositionIcon.SetActive(this._multiPointsPositions.Count > 0);
     Scene.HudGui.AutoFillPointsIcon.SetActive(flag3);
 }
Exemplo n.º 15
0
 private WallArchitect.Edge CalcEdge(Vector3 p1, Vector3 p2)
 {
     WallArchitect.Edge edge = new WallArchitect.Edge
     {
         _p1 = p1,
         _p2 = p2
     };
     edge._hlength = Vector3.Scale(p2 - p1, new Vector3(1f, 0f, 1f)).magnitude;
     edge._segments = new WallArchitect.HorizontalSegment[Mathf.CeilToInt(edge._hlength / this._maxSegmentHorizontalLength)];
     float d = edge._hlength / (float)edge._segments.Length;
     float num = this._logWidth / 2f * 0.98f;
     Vector3 b = (p2 - p1).normalized * d;
     Vector3 vector = p1;
     for (int i = 0; i < edge._segments.Length; i++)
     {
         WallArchitect.HorizontalSegment horizontalSegment = new WallArchitect.HorizontalSegment();
         horizontalSegment._p1 = vector;
         horizontalSegment._p2 = ((i + 1 != edge._segments.Length) ? this.GetSegmentPointFloorPosition(vector + b) : p2);
         horizontalSegment._axis = (horizontalSegment._p2 - horizontalSegment._p1).normalized * d;
         horizontalSegment._length = Vector3.Distance(horizontalSegment._p1, horizontalSegment._p2);
         vector = horizontalSegment._p2;
         WallArchitect.HorizontalSegment expr_13C_cp_0 = horizontalSegment;
         expr_13C_cp_0._p1.y = expr_13C_cp_0._p1.y + num;
         WallArchitect.HorizontalSegment expr_150_cp_0 = horizontalSegment;
         expr_150_cp_0._p2.y = expr_150_cp_0._p2.y + num;
         edge._segments[i] = horizontalSegment;
     }
     return edge;
 }
Exemplo n.º 16
0
 protected virtual void ShowTempWall()
 {
     Vector3 p = (this._multiPointsPositions.Count <= 0) ? (base.transform.position - LocalPlayer.MainCamTr.right / 2f) : this._multiPointsPositions[this._multiPointsPositions.Count - 1];
     Vector3 p2;
     if (this._multiPointsPositions.Count > 2 && Vector3.Distance(base.transform.position, this._multiPointsPositions[0]) < this._closureSnappingDistance)
     {
         p2 = this._multiPointsPositions[0];
     }
     else if (this._multiPointsPositions.Count == 0)
     {
         p2 = base.transform.position + LocalPlayer.MainCamTr.right / 2f;
     }
     else
     {
         p2 = base.transform.position;
     }
     GameObject gameObject = null;
     if (this._tmpEdge != null && this._tmpEdge._root)
     {
         gameObject = this._tmpEdge._root.gameObject;
     }
     this._newPool = new Queue<Transform>();
     this._tmpEdge = this.CreateEdge(p, p2);
     this._tmpEdge._root.name = "TempWall";
     this._logPool = this._newPool;
     if (gameObject)
     {
         UnityEngine.Object.Destroy(gameObject);
     }
 }