Example #1
0
 private void DistortReal(LocalizedHitData data)
 {
     if (data._damage > 0f)
     {
         Renderer[] array = null;
         if (this._renderersRoot)
         {
             LOD_GroupToggle component = this._renderersRoot.GetComponent <LOD_GroupToggle>();
             if (component && component._levels != null && component._levels.Length > 0)
             {
                 array = component._levels[0].Renderers;
             }
         }
         if (array == null)
         {
             array = ((!(this._renderersRoot != null)) ? base.gameObject : this._renderersRoot).GetComponentsInChildren <Renderer>();
         }
         float num = Mathf.Clamp(data._damage * data._distortRatio * 10f / this._maxHP, 1f, Mathf.Lerp(2f, 10f, (this._maxHP - 100f) / 400f));
         for (int i = 0; i < array.Length; i++)
         {
             if (array[i] && array[i].enabled)
             {
                 Transform  transform  = array[i].transform;
                 GameObject gameObject = transform.gameObject;
                 float      num2       = Vector3.Distance(array[i].bounds.center, data._position);
                 if (num2 < 12f)
                 {
                     float num3 = (1f - num2 / 12f) * num;
                     transform.localRotation *= Quaternion.Euler((float)UnityEngine.Random.Range(-1, 1) * num3, (float)UnityEngine.Random.Range(-1, 1) * num3, (float)UnityEngine.Random.Range(-1, 1) * num3);
                 }
             }
         }
     }
 }
Example #2
0
        public void CreateStructure(bool isRepair = false)
        {
            if (this._wasBuilt && isRepair)
            {
                if (this._bridgeRoot)
                {
                    UnityEngine.Object.Destroy(this._bridgeRoot.gameObject);
                }
                this._bridgeRoot = null;
                base.StartCoroutine(this.DelayedAwake(true));
            }
            GameObject gameObject = (!this._bridgeRoot) ? null : this._bridgeRoot.gameObject;

            this._bridgeRoot        = this.CreateBridge(this._anchor1.transform.position, this._anchor2.transform.position);
            this._bridgeRoot.name   = "BridgeRoot" + ((!this._wasBuilt) ? "Ghost" : "Built");
            this._bridgeRoot.parent = base.transform;
            if (gameObject)
            {
                UnityEngine.Object.Destroy(gameObject);
            }
            if (this._wasBuilt)
            {
                base.transform.position = this._anchor1.transform.position;
                this._bridgeRoot.parent = base.transform;
                LOD_GroupToggle lod_GroupToggle = this._bridgeRoot.gameObject.AddComponent <LOD_GroupToggle>();
                lod_GroupToggle.enabled    = false;
                lod_GroupToggle._levels    = new LOD_GroupToggle.LodLevel[2];
                lod_GroupToggle._levels[0] = new LOD_GroupToggle.LodLevel
                {
                    Renderers       = this._bridgeRoot.GetComponentsInChildren <Renderer>(),
                    VisibleDistance = Vector3.Distance(this._anchor1.transform.position, this._anchor2.transform.position) + 20f
                };
                lod_GroupToggle._levels[1] = new LOD_GroupToggle.LodLevel
                {
                    VisibleDistance = 10000f
                };
                List <Renderer> list   = new List <Renderer>();
                Vector3         vector = this._bridgeRoot.GetChild(0).position;
                int             num    = Mathf.CeilToInt(Vector3.Distance(this._anchor1.transform.position, this._anchor2.transform.position) / this._maxColliderLength);
                int             num2   = Mathf.CeilToInt((float)this._bridgeRoot.childCount / (float)num);
                for (int i = 1; i <= num; i++)
                {
                    int num3 = num2 * i;
                    if (num3 >= this._bridgeRoot.childCount)
                    {
                        num3 = this._bridgeRoot.childCount - 1;
                    }
                    Transform child     = this._bridgeRoot.GetChild(num3);
                    Vector3   position  = child.position;
                    Transform transform = new GameObject("Floor" + i).transform;
                    transform.gameObject.layer = 21;
                    transform.parent           = base.transform;
                    transform.position         = vector;
                    transform.LookAt(position);
                    BoxCollider boxCollider = transform.gameObject.AddComponent <BoxCollider>();
                    boxCollider.center = transform.InverseTransformPoint(Vector3.Lerp(vector, position, 0.5f));
                    boxCollider.size   = new Vector3(4.5f, this._logWidth * 0.65f, Vector3.Distance(vector, position) + ((i != num) ? 0f : (this._logWidth / 2f)));
                    transform.tag      = "UnderfootWood";
                    MeshRenderer meshRenderer = transform.gameObject.AddComponent <MeshRenderer>();
                    meshRenderer.sharedMaterial = Prefabs.Instance.LogBridgeBuiltPrefabLOD1.sharedMaterial;
                    MeshFilter meshFilter = transform.gameObject.AddComponent <MeshFilter>();
                    meshFilter.sharedMesh = Prefabs.Instance.LogBridgeBuiltPrefabLOD1.GetComponent <MeshFilter>().sharedMesh;
                    list.Add(meshRenderer);
                    getStructureStrength getStructureStrength = null;
                    if (!getStructureStrength)
                    {
                        getStructureStrength           = transform.gameObject.AddComponent <getStructureStrength>();
                        getStructureStrength._type     = getStructureStrength.structureType.floor;
                        getStructureStrength._strength = getStructureStrength.strength.weak;
                    }
                    transform.gameObject.AddComponent <BuildingHealthHitRelay>();
                    gridObjectBlocker exists = null;
                    if (!exists)
                    {
                        transform.gameObject.AddComponent <gridObjectBlocker>();
                    }
                    vector = position;
                }
                lod_GroupToggle._levels[1].Renderers = list.ToArray();
                lod_GroupToggle.enabled = true;
            }
            if (this._wasBuilt && isRepair)
            {
                this._bridgeRoot.parent = base.transform;
            }
        }
Example #3
0
        protected override void CreateStructure(bool isRepair = false)
        {
            Renderer renderer = null;

            if (isRepair)
            {
                LOD_GroupToggle component = this._wallRoot.GetComponent <LOD_GroupToggle>();
                if (component)
                {
                    renderer = component._levels[1].Renderers[0];
                }
                base.Clear();
                base.StartCoroutine(base.DelayedAwake(true));
            }
            this._logLength = this._offset;
            this._logWidth  = this._offset;
            int layer = LayerMask.NameToLayer("Prop");

            this._wallRoot        = this.SpawnStructure();
            this._wallRoot.parent = base.transform;
            if (this._wasBuilt)
            {
                this._gridToken = InsideCheck.AddWallChunk(this._p1, this._p2, this._colliderHeight + 0.5f);
                GameObject gameObject = this._wallRoot.gameObject;
                gameObject.tag   = "jumpObject";
                gameObject.layer = layer;
                BoxCollider boxCollider = this._wallRoot.gameObject.AddComponent <BoxCollider>();
                Vector3     vector      = base.transform.InverseTransformVector(this._p2 - this._p1);
                boxCollider.size = new Vector3(this._logWidth, this._colliderHeight, Mathf.Abs(vector.z));
                Vector3 center = boxCollider.size / 2f;
                center.x           = 0f;
                boxCollider.center = center;
                this._wallRoot.gameObject.AddComponent <WeaponHitSfxInfo>()._sfx = SfxInfo.SfxTypes.HitRock;
                this._wallRoot.gameObject.AddComponent <BuildingHealthHitRelay>();
                this._wallRoot.gameObject.AddComponent <gridObjectBlocker>();
                foreach (Renderer renderer2 in this._wallRoot.GetComponentsInChildren <Renderer>())
                {
                    renderer2.transform.rotation *= Quaternion.Euler(UnityEngine.Random.Range(-this._randomFactor, this._randomFactor), UnityEngine.Random.Range(-this._randomFactor, this._randomFactor), UnityEngine.Random.Range(-this._randomFactor, this._randomFactor));
                }
                BuildingHealth component2 = base.GetComponent <BuildingHealth>();
                if (component2)
                {
                    component2._renderersRoot = this._wallRoot.gameObject;
                    if (BoltNetwork.isRunning)
                    {
                        component2.SetMpRandomDistortColliders(new Collider[]
                        {
                            boxCollider
                        });
                    }
                }
                if (!renderer)
                {
                    Transform transform = new GameObject("RockWall LOD").transform;
                    transform.gameObject.layer = 21;
                    transform.parent           = base.transform;
                    transform.localRotation    = Quaternion.identity;
                    transform.localPosition    = Vector3.zero;
                    renderer = transform.gameObject.AddComponent <MeshRenderer>();
                    renderer.sharedMaterial = Prefabs.Instance.RockFenceChunksBuiltPrefabsLOD1[0].sharedMaterial;
                    MeshFilter meshFilter = transform.gameObject.AddComponent <MeshFilter>();
                    int        value      = Mathf.RoundToInt(Vector3.Distance(this._p1, this._p2) / this._offset);
                    int        num        = Mathf.Clamp(value, 0, Prefabs.Instance.RockFenceChunksBuiltPrefabsLOD1.Length - 1);
                    meshFilter.sharedMesh = Prefabs.Instance.RockFenceChunksBuiltPrefabsLOD1[num].GetComponent <MeshFilter>().sharedMesh;
                }
                LOD_GroupToggle lod_GroupToggle = this._wallRoot.gameObject.AddComponent <LOD_GroupToggle>();
                lod_GroupToggle.enabled = false;
                lod_GroupToggle._levels = new LOD_GroupToggle.LodLevel[2];
                Renderer[] componentsInChildren;
                lod_GroupToggle._levels[0] = new LOD_GroupToggle.LodLevel
                {
                    Renderers       = componentsInChildren,
                    VisibleDistance = 50f
                };
                lod_GroupToggle._levels[1] = new LOD_GroupToggle.LodLevel
                {
                    Renderers = new Renderer[]
                    {
                        renderer
                    },
                    VisibleDistance = 10000f
                };
            }
        }
Example #4
0
        public void RespawnBuilding()
        {
            if (BoltNetwork.isServer)
            {
                base.state.repairTrigger = false;
            }
            else if (BoltNetwork.isClient)
            {
                this.HpActual = this._maxHP;
                LocalPlayer.Create.Grabber.Reset();
            }
            DynamicBuilding dynamicBuilding = (!base.transform.parent) ? null : base.transform.parent.GetComponentInParent <DynamicBuilding>();

            if (dynamicBuilding == null)
            {
                dynamicBuilding = base.transform.GetComponent <DynamicBuilding>();
            }
            if (dynamicBuilding)
            {
                dynamicBuilding.LockPhysics();
            }
            GameObject gameObject2;

            if (this._type != BuildingTypes.None)
            {
                GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(Prefabs.Instance.Constructions._blueprints.Find((BuildingBlueprint bp) => bp._type == this._type)._builtPrefab);
                gameObject.transform.position = base.transform.position;
                gameObject.transform.rotation = base.transform.rotation;
                if (dynamicBuilding && this._repairMode == BuildingHealth.RepairModes.RenderersOnly)
                {
                    Collider[] componentsInChildren = gameObject.GetComponentsInChildren <Collider>(true);
                    for (int i = 0; i < componentsInChildren.Length; i++)
                    {
                        componentsInChildren[i].enabled = false;
                    }
                }
                if (this._repairMode == BuildingHealth.RepairModes.RenderersOnly)
                {
                    base.SendMessage("RespawningRenderersFrom", gameObject, SendMessageOptions.DontRequireReceiver);
                    Transform       transform       = (!this._renderersRoot) ? base.transform : this._renderersRoot.transform;
                    LOD_GroupToggle lod_GroupToggle = (!transform.parent) ? null : transform.parent.GetComponent <LOD_GroupToggle>();
                    for (int j = transform.childCount - 1; j >= 0; j--)
                    {
                        Transform child = transform.GetChild(j);
                        if ((!child.GetComponent <StoreInformation>() || child.GetComponent <ForceRepairRespawn>()) && !child.GetComponent <SkipRepairRespawn>() && !child.name.Contains("Anchor"))
                        {
                            UnityEngine.Object.Destroy(child.gameObject);
                        }
                    }
                    Transform transform2 = (!this._renderersRoot) ? gameObject.transform : gameObject.GetComponent <BuildingHealth>()._renderersRoot.transform;
                    for (int k = transform2.childCount - 1; k >= 0; k--)
                    {
                        Transform child2 = transform2.GetChild(k);
                        if ((!child2.GetComponent <StoreInformation>() || child2.GetComponent <ForceRepairRespawn>()) && !child2.GetComponent <SkipRepairRespawn>() && !child2.name.Contains("Anchor"))
                        {
                            child2.parent = transform;
                            if (lod_GroupToggle)
                            {
                                lod_GroupToggle._levels[0].Renderers[k] = child2.GetComponentInChildren <Renderer>();
                            }
                        }
                    }
                    if (lod_GroupToggle)
                    {
                        lod_GroupToggle.RefreshVisibility(true);
                    }
                    UnityEngine.Object.Destroy(gameObject);
                    gameObject2 = base.gameObject;
                }
                else
                {
                    TreeStructure component = base.GetComponent <TreeStructure>();
                    if (component)
                    {
                        TreeStructure component2 = gameObject.GetComponent <TreeStructure>();
                        component2.TreeId = component.TreeId;
                    }
                    UnityEngine.Object.Destroy(base.gameObject);
                    gameObject2 = gameObject;
                    if (BoltNetwork.isServer)
                    {
                        BoltNetwork.Attach(gameObject);
                    }
                }
                if (this._type == BuildingTypes.Shelter)
                {
                    EventRegistry.Achievements.Publish(TfEvent.Achievements.RepairedShelter, null);
                }
            }
            else
            {
                gameObject2 = base.gameObject;
            }
            gameObject2.SendMessage("ResetHP", SendMessageOptions.DontRequireReceiver);
            gameObject2.SendMessage("CreateStructure", true, SendMessageOptions.DontRequireReceiver);
            trapTrigger componentInChildren = base.GetComponentInChildren <trapTrigger>();

            if (componentInChildren && componentInChildren.GetComponentInParent <PrefabIdentifier>().gameObject == base.gameObject)
            {
                componentInChildren.CopyTrapStatusTo(gameObject2.GetComponentInChildren <trapTrigger>());
            }
            if (dynamicBuilding)
            {
                raftOnLand component3 = base.transform.GetComponent <raftOnLand>();
                if (component3)
                {
                    dynamicBuilding.UnlockPhysics();
                    component3.StartCoroutine(component3.fixBounceOnSpawn());
                }
                else
                {
                    dynamicBuilding.Invoke("UnlockPhysics", 0.1f);
                }
            }
            if (LocalPlayer.Sfx)
            {
                LocalPlayer.Sfx.PlayTwinkle();
            }
        }
Example #5
0
        private IEnumerator CollapseRoutine(Vector3 origin)
        {
            if (!this._collapsing)
            {
                this._collapsing = true;
                if (this._type == BuildingTypes.WorkBench || this._type == BuildingTypes.Chair || this._type == BuildingTypes.BoneChair)
                {
                    activateBench componentInChildren = base.transform.GetComponentInChildren <activateBench>();
                    if (componentInChildren)
                    {
                        componentInChildren.gameObject.SetActive(false);
                        if (componentInChildren.Sheen)
                        {
                            componentInChildren.Sheen.SetActive(false);
                        }
                        if (componentInChildren.MyPickUp)
                        {
                            componentInChildren.MyPickUp.SetActive(false);
                        }
                    }
                }
                if (BoltNetwork.isServer)
                {
                    yield return(YieldPresets.WaitPointOneSeconds);
                }
                if (this._type == BuildingTypes.WeaponRack)
                {
                    base.BroadcastMessage("OnBeginCollapse", SendMessageOptions.DontRequireReceiver);
                }
                else
                {
                    base.SendMessage("OnBeginCollapse", SendMessageOptions.DontRequireReceiver);
                }
                if ((this._type == BuildingTypes.HouseBoat || this._type == BuildingTypes.Raft || this._type == BuildingTypes.RaftEx) && LocalPlayer.Transform.IsChildOf(base.transform))
                {
                    RaftPush[] componentsInChildren = base.transform.GetComponentsInChildren <RaftPush>(true);
                    if (componentsInChildren.Length > 0)
                    {
                        foreach (RaftPush raftPush in componentsInChildren)
                        {
                            raftPush.SendMessage("offRaft");
                        }
                    }
                }
                for (int j = base.transform.childCount - 1; j >= 0; j--)
                {
                    LODGroup component = base.transform.GetChild(j).GetComponent <LODGroup>();
                    if (component)
                    {
                        LOD[] lods = component.GetLODs();
                        if (lods != null && (lods.Length > 1 & lods[1].renderers != null))
                        {
                            for (int k = 0; k < lods[1].renderers.Length; k++)
                            {
                                UnityEngine.Object.Destroy(lods[1].renderers[k].gameObject);
                            }
                        }
                        break;
                    }
                }
                Transform       renderersRoot = (!this._renderersRoot) ? base.transform : this._renderersRoot.transform;
                LOD_GroupToggle lgt           = (!renderersRoot.parent) ? null : renderersRoot.parent.GetComponent <LOD_GroupToggle>();
                if (lgt)
                {
                    lgt.ForceVisibility(0);
                    for (int l = lgt._levels.Length - 1; l > 0; l--)
                    {
                        foreach (Renderer renderer in lgt._levels[l].Renderers)
                        {
                            if (renderer)
                            {
                                renderer.transform.parent = null;
                                UnityEngine.Object.Destroy(renderer.gameObject);
                            }
                        }
                    }
                    UnityEngine.Object.Destroy(lgt);
                }
                if (!BoltNetwork.isClient)
                {
                    yield return(YieldPresets.WaitPointZeroFiveSeconds);

                    for (int n = base.transform.childCount - 1; n >= 0; n--)
                    {
                        Transform      child      = base.transform.GetChild(n);
                        BuildingHealth component2 = child.GetComponent <BuildingHealth>();
                        if (component2)
                        {
                            child.parent = null;
                            component2.Collapse(child.position);
                            Transform transform = child.Find("Trigger");
                            if (transform)
                            {
                                UnityEngine.Object.Destroy(transform.gameObject);
                            }
                        }
                        else
                        {
                            FoundationHealth component3 = child.GetComponent <FoundationHealth>();
                            if (component3)
                            {
                                child.parent = null;
                                component3.Collapse(child.position);
                            }
                            else if (BoltNetwork.isRunning && child.GetComponent <BoltEntity>())
                            {
                                child.parent = null;
                                destroyAfter destroyAfter = child.gameObject.AddComponent <destroyAfter>();
                                destroyAfter.destroyTime = 2.5f;
                                Transform transform2 = child.Find("Trigger");
                                if (transform2)
                                {
                                    UnityEngine.Object.Destroy(transform2.gameObject);
                                }
                            }
                        }
                        if (BoltNetwork.isRunning)
                        {
                            CoopAutoAttach component4 = child.GetComponent <CoopAutoAttach>();
                            if (component4)
                            {
                                UnityEngine.Object.Destroy(component4);
                            }
                        }
                    }
                }
                if (LocalPlayer.Sfx)
                {
                    LocalPlayer.Sfx.PlayStructureBreak(base.gameObject, this._maxHP / 2000f);
                }
                if (LocalPlayer.HitReactions != null)
                {
                    LocalPlayer.HitReactions.disableImpact(0.15f);
                }
                Renderer[] renderers = null;
                if (lgt && lgt._levels != null && lgt._levels.Length > 0)
                {
                    renderers = lgt._levels[0].Renderers;
                }
                if (renderers == null || renderers.Length == 0)
                {
                    renderers = ((!this._renderersRoot) ? base.GetComponentsInChildren <MeshRenderer>() : this._renderersRoot.GetComponentsInChildren <MeshRenderer>());
                }
                foreach (Renderer renderer2 in renderers)
                {
                    GameObject gameObject = renderer2.gameObject;
                    if (renderer2.enabled && gameObject.activeInHierarchy)
                    {
                        Transform transform3 = renderer2.transform;
                        if (!gameObject.GetComponent <Collider>())
                        {
                            MeshFilter component5 = renderer2.GetComponent <MeshFilter>();
                            if (!component5 || !component5.sharedMesh)
                            {
                                goto IL_7BB;
                            }
                            BoxCollider boxCollider = gameObject.AddComponent <BoxCollider>();
                            Bounds      bounds      = component5.sharedMesh.bounds;
                            boxCollider.size   = bounds.size * 0.9f;
                            boxCollider.center = bounds.center;
                        }
                        gameObject.layer  = this._detachedLayer;
                        transform3.parent = null;
                        Rigidbody rigidbody = gameObject.AddComponent <Rigidbody>();
                        if (rigidbody)
                        {
                            rigidbody.AddForce(((transform3.position - origin).normalized + Vector3.up) * (2.5f * this._destructionForceMultiplier), ForceMode.Impulse);
                            rigidbody.AddRelativeTorque(Vector3.up * (2f * this._destructionForceMultiplier), ForceMode.Impulse);
                            rigidbody.mass = 10f;
                        }
                        destroyAfter destroyAfter2 = gameObject.AddComponent <destroyAfter>();
                        if (this._type == BuildingTypes.WeaponRack)
                        {
                            destroyAfter2.destroyTime = 1.5f;
                        }
                        else
                        {
                            destroyAfter2.destroyTime = 5f;
                        }
                    }
                    IL_7BB :;
                }
                if (this._repairTrigger)
                {
                    UnityEngine.Object.Destroy(this._repairTrigger.gameObject);
                    this._repairTrigger = null;
                }
                this.SpawnCollapseDust();
                if (!BoltNetwork.isClient)
                {
                    if (!BoltNetwork.isRunning)
                    {
                        yield return(YieldPresets.WaitOneSecond);
                    }
                    else
                    {
                        yield return(YieldPresets.WaitTwoSeconds);
                    }
                    GameStats.DestroyedStructure.Invoke();
                    if (this._destroyTarget)
                    {
                        this._destroyTarget.transform.parent = null;
                        if (!BoltNetwork.isRunning)
                        {
                            UnityEngine.Object.Destroy(this._destroyTarget);
                        }
                        else
                        {
                            BoltNetwork.Destroy(this._destroyTarget);
                        }
                    }
                    else
                    {
                        base.transform.parent = null;
                        if (!BoltNetwork.isRunning)
                        {
                            UnityEngine.Object.Destroy(base.gameObject);
                        }
                        else
                        {
                            BoltNetwork.Destroy(base.gameObject);
                        }
                    }
                }
            }
            yield break;
        }
        protected void CreateStructure(bool isRepair = false)
        {
            Renderer renderer = null;

            if (isRepair)
            {
                LOD_GroupToggle component = this._wallRoot.GetComponent <LOD_GroupToggle>();
                if (component)
                {
                    renderer = component._levels[1].Renderers[0];
                }
                this.Clear();
            }
            int num = LayerMask.NameToLayer("Prop");

            this._wallRoot = this.SpawnEdge();
            if (this._wasPlaced || this._wasBuilt)
            {
                this._wallRoot.parent = base.transform;
            }
            if (this._wasBuilt)
            {
                foreach (Renderer renderer2 in this._wallRoot.GetComponentsInChildren <Renderer>())
                {
                    if (renderer2.name.Equals("s"))
                    {
                        renderer2.transform.rotation *= Quaternion.Euler(UnityEngine.Random.Range(-this._stickRandomFactor, this._stickRandomFactor), UnityEngine.Random.Range(-this._stickRandomFactor, this._stickRandomFactor), UnityEngine.Random.Range(-this._stickRandomFactor, this._stickRandomFactor));
                    }
                    else
                    {
                        renderer2.transform.rotation *= Quaternion.Euler(UnityEngine.Random.Range(-this._rockRandomFactor, this._rockRandomFactor), UnityEngine.Random.Range(-this._rockRandomFactor, this._rockRandomFactor), UnityEngine.Random.Range(-this._rockRandomFactor, this._rockRandomFactor));
                    }
                }
                if (!this._collision)
                {
                    Vector3 rhs = this._chunk.P2 - this._chunk.P1;
                    this._collision               = new GameObject("Collision").transform;
                    this._collision.parent        = this._wallRoot;
                    this._collision.localPosition = Vector3.zero;
                    this._collision.localRotation = Quaternion.Euler(0f, 0f, (Vector3.Dot(base.transform.forward, rhs) <= 0f) ? 146f : 34f);
                    BoxCollider boxCollider = this._collision.gameObject.AddComponent <BoxCollider>();
                    boxCollider.size       = new Vector3(3f, 0.5f, Vector3.Distance(this._chunk.P1, this._chunk.P2));
                    boxCollider.center     = new Vector3(2f, 0f, boxCollider.size.z / 2f - 0.5f);
                    this._collision.parent = base.transform;
                }
                if (!renderer)
                {
                    int       logCount  = this._logCount;
                    bool      flag      = Mathf.Abs(base.transform.localEulerAngles.y) > 10f && Mathf.Abs(base.transform.localEulerAngles.y) < 350f;
                    Transform transform = new GameObject("DWR LOD").transform;
                    transform.gameObject.layer = 21;
                    transform.parent           = base.transform;
                    transform.position         = ((!flag) ? this._chunk.P1 : this._chunk.P2);
                    transform.localRotation    = ((!flag) ? this._wallRoot.localRotation : Quaternion.Euler(this._wallRoot.localEulerAngles.x, this._wallRoot.localEulerAngles.y + 180f, this._wallRoot.localEulerAngles.z));
                    renderer = transform.gameObject.AddComponent <MeshRenderer>();
                    renderer.sharedMaterials = Prefabs.Instance.DefensiveWallReinforcementBuiltPrefabLOD1[0].sharedMaterials;
                    MeshFilter meshFilter = transform.gameObject.AddComponent <MeshFilter>();
                    meshFilter.sharedMesh = Prefabs.Instance.DefensiveWallReinforcementBuiltPrefabLOD1[Mathf.Clamp(logCount, 0, Prefabs.Instance.DefensiveWallReinforcementBuiltPrefabLOD1.Length - 1)].GetComponent <MeshFilter>().sharedMesh;
                }
                LOD_GroupToggle lod_GroupToggle = this._wallRoot.gameObject.AddComponent <LOD_GroupToggle>();
                lod_GroupToggle.enabled = false;
                lod_GroupToggle._levels = new LOD_GroupToggle.LodLevel[2];
                Renderer[] componentsInChildren;
                lod_GroupToggle._levels[0] = new LOD_GroupToggle.LodLevel
                {
                    Renderers       = componentsInChildren,
                    VisibleDistance = 60f
                };
                lod_GroupToggle._levels[1] = new LOD_GroupToggle.LodLevel
                {
                    Renderers = new Renderer[]
                    {
                        renderer
                    },
                    VisibleDistance = 250f
                };
            }
        }
Example #7
0
        protected override void CreateStructure(bool isRepair = false)
        {
            Renderer renderer = null;

            if (isRepair)
            {
                LOD_GroupToggle component = this._wallRoot.GetComponent <LOD_GroupToggle>();
                if (component)
                {
                    renderer = component._levels[1].Renderers[0];
                }
                base.Clear();
                base.StartCoroutine(base.DelayedAwake(true));
            }
            Vector3 size = this._logRenderer.bounds.size;

            this._logLength = size.y;
            this._logWidth  = size.z;
            int layer = LayerMask.NameToLayer("Prop");

            this._wallRoot        = this.SpawnStructure();
            this._wallRoot.parent = base.transform;
            if (this._wasBuilt)
            {
                this._gridToken = InsideCheck.AddWallChunk(this._p1, this._p2, this._logLength);
                GameObject gameObject = this._wallRoot.gameObject;
                gameObject.tag   = "structure";
                gameObject.layer = layer;
                BoxCollider boxCollider = this._wallRoot.gameObject.AddComponent <BoxCollider>();
                Vector3     vector      = base.transform.InverseTransformVector(this._p2 - this._p1);
                boxCollider.size = new Vector3(this._logWidth, this._logLength, Mathf.Abs(vector.z));
                Vector3 center = boxCollider.size / 2f;
                center.x           = 0f;
                center.y          -= 1f;
                center.z          -= this._logWidth / 2f;
                boxCollider.center = center;
                BuildingHealth component2 = base.GetComponent <BuildingHealth>();
                if (component2)
                {
                    component2._renderersRoot = this._wallRoot.gameObject;
                    if (BoltNetwork.isRunning)
                    {
                        component2.SetMpRandomDistortColliders(new Collider[]
                        {
                            boxCollider
                        });
                    }
                }
                this._wallRoot.gameObject.AddComponent <BuildingHealthHitRelay>();
                getStructureStrength getStructureStrength = this._wallRoot.gameObject.AddComponent <getStructureStrength>();
                getStructureStrength._type     = getStructureStrength.structureType.wall;
                getStructureStrength._strength = getStructureStrength.strength.veryStrong;
                this._wallRoot.gameObject.AddComponent <gridObjectBlocker>();
                if (!renderer)
                {
                    int       logCost   = this.GetLogCost();
                    bool      flag      = logCost % 2 == 0;
                    bool      flag2     = this._p1.y > this._p2.y;
                    Transform transform = new GameObject("DW LOD Skewer").transform;
                    transform.parent           = base.transform;
                    transform.localEulerAngles = ((!flag2) ? new Vector3(0f, 180f, 0f) : Vector3.zero);
                    transform.position         = this._p1 + transform.forward * (((float)logCost * 0.5f - 0.5f) * (float)((!flag2) ? -1 : 1) * base.LogWidth);
                    Transform transform2 = new GameObject("DW LOD").transform;
                    transform2.gameObject.layer = 21;
                    transform2.parent           = transform;
                    transform2.localPosition    = Vector3.zero;
                    Prefabs.Instance.Constructions._defensiveWallSkewLOD.SetSkew(transform, transform2, transform.eulerAngles.x);
                    renderer = transform2.gameObject.AddComponent <MeshRenderer>();
                    renderer.sharedMaterial = Prefabs.Instance.LogWallDefensiveExBuiltPrefabLOD1[0].sharedMaterial;
                    MeshFilter meshFilter = transform2.gameObject.AddComponent <MeshFilter>();
                    meshFilter.sharedMesh = Prefabs.Instance.LogWallDefensiveExBuiltPrefabLOD1[Mathf.Clamp(logCost, 0, Prefabs.Instance.LogWallDefensiveExBuiltPrefabLOD1.Length - 1)].GetComponent <MeshFilter>().sharedMesh;
                }
                LOD_GroupToggle lod_GroupToggle = this._wallRoot.gameObject.AddComponent <LOD_GroupToggle>();
                lod_GroupToggle.enabled    = false;
                lod_GroupToggle._levels    = new LOD_GroupToggle.LodLevel[2];
                lod_GroupToggle._levels[0] = new LOD_GroupToggle.LodLevel
                {
                    Renderers       = this._wallRoot.GetComponentsInChildren <Renderer>(),
                    VisibleDistance = 100f
                };
                lod_GroupToggle._levels[1] = new LOD_GroupToggle.LodLevel
                {
                    Renderers = new Renderer[]
                    {
                        renderer
                    },
                    VisibleDistance = 10000f
                };
            }
        }