示例#1
0
        // Token: 0x06002564 RID: 9572 RVA: 0x000D97B0 File Offset: 0x000D7BB0
        public LevelObject(Vector3 newPoint, Quaternion newRotation, Vector3 newScale, ushort newID, string newName, Guid newGUID, ELevelObjectPlacementOrigin newPlacementOrigin, uint newInstanceID, AssetReference <MaterialPaletteAsset> customMaterialOverride, int materialIndexOverride, bool isHierarchyItem)
        {
            this._id         = newID;
            this._name       = newName;
            this._GUID       = newGUID;
            this._instanceID = newInstanceID;
            if (this.GUID == Guid.Empty)
            {
                this._asset = (ObjectAsset)Assets.find(EAssetType.OBJECT, this.name);
                if (this.asset == null || this.asset.id != this.id)
                {
                    this._asset = (ObjectAsset)Assets.find(EAssetType.OBJECT, this.id);
                }
                if (this.asset != null)
                {
                    this._GUID = this.asset.GUID;
                }
            }
            else
            {
                this._asset = Assets.find <ObjectAsset>(new AssetReference <ObjectAsset>(this.GUID));
            }
            if (this.asset == null)
            {
                return;
            }
            this._name                     = this.asset.name;
            this.state                     = this.asset.getState();
            this.placementOrigin           = newPlacementOrigin;
            this.areConditionsMet          = true;
            this.haveConditionsBeenChecked = false;
            GameObject modelGameObject = this.asset.modelGameObject;

            if (Dedicator.isDedicated)
            {
                if (modelGameObject != null)
                {
                    this._transform         = UnityEngine.Object.Instantiate <GameObject>(modelGameObject).transform;
                    this.transform.name     = ((!isHierarchyItem) ? this.id.ToString() : this.GUID.ToString("N"));
                    this.transform.parent   = LevelObjects.models;
                    this.transform.position = newPoint;
                    this.transform.rotation = newRotation;
                    this.isDecal            = this.transform.FindChild("Decal");
                    if (this.asset.useScale)
                    {
                        this.transform.localScale = newScale;
                    }
                }
                this.renderers = null;
            }
            else if (modelGameObject != null)
            {
                this._transform         = UnityEngine.Object.Instantiate <GameObject>(modelGameObject).transform;
                this.transform.name     = ((!isHierarchyItem) ? this.id.ToString() : this.GUID.ToString("N"));
                this.transform.parent   = LevelObjects.models;
                this.transform.position = newPoint;
                this.transform.rotation = newRotation;
                this.isDecal            = this.transform.FindChild("Decal");
                if (this.asset.useScale)
                {
                    this.transform.localScale = newScale;
                }
                if (this.asset.useWaterHeightTransparentSort)
                {
                    this.transform.gameObject.AddComponent <WaterHeightTransparentSort>();
                }
                if (this.asset.shouldAddNightLightScript)
                {
                    NightLight nightLight = this.transform.gameObject.AddComponent <NightLight>();
                    Transform  transform  = this.transform.FindChild("Light");
                    if (transform)
                    {
                        nightLight.target = transform.GetComponent <Light>();
                    }
                }
                this.renderers = new List <Renderer>();
                Material material = null;
                AssetReference <MaterialPaletteAsset> reference = customMaterialOverride;
                if (!reference.isValid)
                {
                    reference = this.asset.materialPalette;
                }
                if (reference.isValid)
                {
                    MaterialPaletteAsset materialPaletteAsset = Assets.find <MaterialPaletteAsset>(reference);
                    if (materialPaletteAsset != null)
                    {
                        int index;
                        if (materialIndexOverride == -1)
                        {
                            UnityEngine.Random.State state = UnityEngine.Random.state;
                            UnityEngine.Random.InitState((int)this.instanceID);
                            index = UnityEngine.Random.Range(0, materialPaletteAsset.materials.Count);
                            UnityEngine.Random.state = state;
                        }
                        else
                        {
                            index = Mathf.Clamp(materialIndexOverride, 0, materialPaletteAsset.materials.Count - 1);
                        }
                        material = Assets.load <Material>(materialPaletteAsset.materials[index]);
                    }
                }
                GameObject skyboxGameObject = this.asset.skyboxGameObject;
                if (skyboxGameObject != null)
                {
                    this._skybox         = UnityEngine.Object.Instantiate <GameObject>(skyboxGameObject).transform;
                    this.skybox.name     = this.id.ToString() + "_Skybox";
                    this.skybox.parent   = LevelObjects.models;
                    this.skybox.position = newPoint;
                    this.skybox.rotation = newRotation;
                    if (this.asset.useScale)
                    {
                        this.skybox.localScale = newScale;
                    }
                    if (this.isLandmarkQualityMet)
                    {
                        this.enableSkybox();
                    }
                    else
                    {
                        this.disableSkybox();
                    }
                    this.skybox.GetComponentsInChildren <Renderer>(true, this.renderers);
                    for (int i = 0; i < this.renderers.Count; i++)
                    {
                        this.renderers[i].shadowCastingMode = ShadowCastingMode.Off;
                        if (material != null)
                        {
                            this.renderers[i].sharedMaterial = material;
                        }
                    }
                    this.renderers.Clear();
                }
                this.transform.GetComponentsInChildren <Renderer>(true, this.renderers);
                if (material != null)
                {
                    for (int j = 0; j < this.renderers.Count; j++)
                    {
                        this.renderers[j].sharedMaterial = material;
                    }
                }
                if (this.asset.isCollisionImportant && Provider.isServer && !Dedicator.isDedicated)
                {
                    this.enableCollision();
                }
                else
                {
                    this.disableCollision();
                }
                this.disableVisual();
            }
            if (this.transform != null)
            {
                if (this.isDecal && !Level.isEditor && this.asset.interactability == EObjectInteractability.NONE && this.asset.rubble == EObjectRubble.NONE)
                {
                    Collider component = this.transform.GetComponent <Collider>();
                    if (component != null)
                    {
                        UnityEngine.Object.Destroy(component);
                    }
                }
                if (Level.isEditor)
                {
                    if (isHierarchyItem)
                    {
                        Rigidbody component2 = this.transform.GetComponent <Rigidbody>();
                        if (component2 != null)
                        {
                            UnityEngine.Object.Destroy(component2);
                        }
                    }
                    else
                    {
                        Rigidbody rigidbody = this.transform.GetComponent <Rigidbody>();
                        if (rigidbody == null)
                        {
                            rigidbody             = this.transform.gameObject.AddComponent <Rigidbody>();
                            rigidbody.useGravity  = false;
                            rigidbody.isKinematic = true;
                        }
                    }
                }
                else if (this.asset.interactability == EObjectInteractability.NONE && this.asset.rubble == EObjectRubble.NONE)
                {
                    Rigidbody component3 = this.transform.GetComponent <Rigidbody>();
                    if (component3 != null)
                    {
                        UnityEngine.Object.Destroy(component3);
                    }
                    if (this.asset.type == EObjectType.SMALL)
                    {
                        Collider component4 = this.transform.GetComponent <Collider>();
                        if (component4 != null)
                        {
                            UnityEngine.Object.Destroy(component4);
                        }
                    }
                }
                if ((Level.isEditor || Provider.isServer) && this.asset.type != EObjectType.SMALL)
                {
                    GameObject navGameObject = this.asset.navGameObject;
                    if (navGameObject != null)
                    {
                        Transform transform2 = UnityEngine.Object.Instantiate <GameObject>(navGameObject).transform;
                        transform2.name          = "Nav";
                        transform2.parent        = this.transform;
                        transform2.localPosition = Vector3.zero;
                        transform2.localRotation = Quaternion.identity;
                        transform2.localScale    = Vector3.one;
                        if (Level.isEditor)
                        {
                            Rigidbody rigidbody2 = transform2.GetComponent <Rigidbody>();
                            if (rigidbody2 == null)
                            {
                                rigidbody2             = transform2.gameObject.AddComponent <Rigidbody>();
                                rigidbody2.useGravity  = false;
                                rigidbody2.isKinematic = true;
                            }
                        }
                        else
                        {
                            LevelObject.reuseableRigidbodyList.Clear();
                            transform2.GetComponentsInChildren <Rigidbody>(LevelObject.reuseableRigidbodyList);
                            foreach (Rigidbody obj in LevelObject.reuseableRigidbodyList)
                            {
                                UnityEngine.Object.Destroy(obj);
                            }
                        }
                    }
                }
                if (Provider.isServer)
                {
                    GameObject triggersGameObject = this.asset.triggersGameObject;
                    if (triggersGameObject != null)
                    {
                        Transform transform3 = UnityEngine.Object.Instantiate <GameObject>(triggersGameObject).transform;
                        transform3.name          = "Triggers";
                        transform3.parent        = this.transform;
                        transform3.localPosition = Vector3.zero;
                        transform3.localRotation = Quaternion.identity;
                        transform3.localScale    = Vector3.one;
                    }
                }
                if (this.asset.type != EObjectType.SMALL)
                {
                    if (Level.isEditor)
                    {
                        Transform transform4 = this.transform.FindChild("Block");
                        if (transform4 != null && this.transform.GetComponent <Collider>() == null)
                        {
                            BoxCollider boxCollider  = (BoxCollider)transform4.GetComponent <Collider>();
                            BoxCollider boxCollider2 = this.transform.gameObject.AddComponent <BoxCollider>();
                            boxCollider2.center = boxCollider.center;
                            boxCollider2.size   = boxCollider.size;
                        }
                    }
                    else if (Provider.isClient)
                    {
                        GameObject slotsGameObject = this.asset.slotsGameObject;
                        if (slotsGameObject != null)
                        {
                            Transform transform5 = UnityEngine.Object.Instantiate <GameObject>(slotsGameObject).transform;
                            transform5.name          = "Slots";
                            transform5.parent        = this.transform;
                            transform5.localPosition = Vector3.zero;
                            transform5.localRotation = Quaternion.identity;
                            transform5.localScale    = Vector3.one;
                            LevelObject.reuseableRigidbodyList.Clear();
                            transform5.GetComponentsInChildren <Rigidbody>(LevelObject.reuseableRigidbodyList);
                            foreach (Rigidbody obj2 in LevelObject.reuseableRigidbodyList)
                            {
                                UnityEngine.Object.Destroy(obj2);
                            }
                        }
                    }
                    if (this.asset.slotsGameObject != null)
                    {
                    }
                }
                if (this.asset.interactability != EObjectInteractability.NONE)
                {
                    if (this.asset.interactability == EObjectInteractability.BINARY_STATE)
                    {
                        this._interactableObj = this.transform.gameObject.AddComponent <InteractableObjectBinaryState>();
                    }
                    else if (this.asset.interactability == EObjectInteractability.DROPPER)
                    {
                        this._interactableObj = this.transform.gameObject.AddComponent <InteractableObjectDropper>();
                    }
                    else if (this.asset.interactability == EObjectInteractability.NOTE)
                    {
                        this._interactableObj = this.transform.gameObject.AddComponent <InteractableObjectNote>();
                    }
                    else if (this.asset.interactability == EObjectInteractability.WATER || this.asset.interactability == EObjectInteractability.FUEL)
                    {
                        this._interactableObj = this.transform.gameObject.AddComponent <InteractableObjectResource>();
                    }
                    else if (this.asset.interactability == EObjectInteractability.NPC)
                    {
                        this._interactableObj = this.transform.gameObject.AddComponent <InteractableObjectNPC>();
                    }
                    else if (this.asset.interactability == EObjectInteractability.QUEST)
                    {
                        this._interactableObj = this.transform.gameObject.AddComponent <InteractableObjectQuest>();
                    }
                    if (this.interactable != null)
                    {
                        this.interactable.updateState(this.asset, this.state);
                    }
                }
                if (this.asset.rubble != EObjectRubble.NONE)
                {
                    if (this.asset.rubble == EObjectRubble.DESTROY)
                    {
                        this._rubble = this.transform.gameObject.AddComponent <InteractableObjectRubble>();
                    }
                    if (this.rubble != null)
                    {
                        this.rubble.updateState(this.asset, this.state);
                    }
                    if (this.asset.rubbleEditor == EObjectRubbleEditor.DEAD && Level.isEditor)
                    {
                        Transform transform6 = this.transform.FindChild("Editor");
                        if (transform6 != null)
                        {
                            transform6.gameObject.SetActive(true);
                        }
                    }
                }
                if (this.asset.conditions != null && this.asset.conditions.Length > 0 && !Level.isEditor && !Dedicator.isDedicated)
                {
                    this.areConditionsMet  = false;
                    Player.onPlayerCreated = (PlayerCreated)Delegate.Combine(Player.onPlayerCreated, new PlayerCreated(this.onPlayerCreated));
                }
                if (this.asset.foliage.isValid)
                {
                    FoliageSurfaceComponent foliageSurfaceComponent = this.transform.gameObject.AddComponent <FoliageSurfaceComponent>();
                    foliageSurfaceComponent.foliage         = this.asset.foliage;
                    foliageSurfaceComponent.surfaceCollider = this.transform.gameObject.GetComponent <Collider>();
                }
            }
        }
示例#2
0
 // Token: 0x06002563 RID: 9571 RVA: 0x000D9788 File Offset: 0x000D7B88
 public LevelObject(Vector3 newPoint, Quaternion newRotation, Vector3 newScale, ushort newID, string newName, Guid newGUID, ELevelObjectPlacementOrigin newPlacementOrigin, uint newInstanceID) : this(newPoint, newRotation, newScale, newID, newName, newGUID, newPlacementOrigin, newInstanceID, AssetReference <MaterialPaletteAsset> .invalid, -1, false)
 {
 }
示例#3
0
        public static Transform addObject(Vector3 position, Quaternion rotation, Vector3 scale, ushort id, string name, Guid GUID, ELevelObjectPlacementOrigin placementOrigin)
        {
            byte b;
            byte b2;

            if (Regions.tryGetCoordinate(position, out b, out b2))
            {
                LevelObject levelObject = new LevelObject(position, rotation, scale, id, name, GUID, placementOrigin, LevelObjects.generateUniqueInstanceID());
                levelObject.enableCollision();
                levelObject.enableVisual();
                levelObject.disableSkybox();
                LevelObjects.objects[(int)b, (int)b2].Add(levelObject);
                LevelObjects._total++;
                return(levelObject.transform);
            }
            return(null);
        }
示例#4
0
 public static void load()
 {
     LevelObjects._models                 = new GameObject().transform;
     LevelObjects.models.name             = "Objects";
     LevelObjects.models.parent           = Level.level;
     LevelObjects.models.tag              = "Logic";
     LevelObjects.models.gameObject.layer = LayerMasks.LOGIC;
     LevelObjects._objects                = new List <LevelObject> [(int)Regions.WORLD_SIZE, (int)Regions.WORLD_SIZE];
     LevelObjects._buildables             = new List <LevelBuildableObject> [(int)Regions.WORLD_SIZE, (int)Regions.WORLD_SIZE];
     LevelObjects._total              = 0;
     LevelObjects._regions            = new bool[(int)Regions.WORLD_SIZE, (int)Regions.WORLD_SIZE];
     LevelObjects._loads              = new int[(int)Regions.WORLD_SIZE, (int)Regions.WORLD_SIZE];
     LevelObjects.shouldInstantlyLoad = true;
     LevelObjects.isHierarchyReady    = false;
     for (byte b = 0; b < Regions.WORLD_SIZE; b += 1)
     {
         for (byte b2 = 0; b2 < Regions.WORLD_SIZE; b2 += 1)
         {
             LevelObjects.loads[(int)b, (int)b2] = -1;
         }
     }
     for (byte b3 = 0; b3 < Regions.WORLD_SIZE; b3 += 1)
     {
         for (byte b4 = 0; b4 < Regions.WORLD_SIZE; b4 += 1)
         {
             LevelObjects.objects[(int)b3, (int)b4]    = new List <LevelObject>();
             LevelObjects.buildables[(int)b3, (int)b4] = new List <LevelBuildableObject>();
         }
     }
     if (Level.info.configData.Use_Legacy_Objects)
     {
         if (ReadWrite.fileExists(Level.info.path + "/Level/Objects.dat", false, false))
         {
             River river = new River(Level.info.path + "/Level/Objects.dat", false);
             byte  b5    = river.readByte();
             bool  flag  = true;
             if (b5 > 0)
             {
                 if (b5 > 1 && b5 < 3)
                 {
                     river.readSteamID();
                 }
                 if (b5 > 8)
                 {
                     LevelObjects.availableInstanceID = river.readUInt32();
                 }
                 else
                 {
                     LevelObjects.availableInstanceID = 1u;
                 }
                 for (byte b6 = 0; b6 < Regions.WORLD_SIZE; b6 += 1)
                 {
                     for (byte b7 = 0; b7 < Regions.WORLD_SIZE; b7 += 1)
                     {
                         ushort num = river.readUInt16();
                         for (ushort num2 = 0; num2 < num; num2 += 1)
                         {
                             Vector3    vector      = river.readSingleVector3();
                             Quaternion newRotation = river.readSingleQuaternion();
                             Vector3    newScale;
                             if (b5 > 3)
                             {
                                 newScale = river.readSingleVector3();
                             }
                             else
                             {
                                 newScale = Vector3.one;
                             }
                             ushort num3    = river.readUInt16();
                             string newName = string.Empty;
                             if (b5 > 5)
                             {
                                 newName = river.readString();
                             }
                             Guid newGUID = Guid.Empty;
                             if (b5 > 7)
                             {
                                 newGUID = river.readGUID();
                             }
                             ELevelObjectPlacementOrigin newPlacementOrigin = ELevelObjectPlacementOrigin.MANUAL;
                             if (b5 > 6)
                             {
                                 newPlacementOrigin = (ELevelObjectPlacementOrigin)river.readByte();
                             }
                             uint newInstanceID;
                             if (b5 > 8)
                             {
                                 newInstanceID = river.readUInt32();
                             }
                             else
                             {
                                 newInstanceID = LevelObjects.generateUniqueInstanceID();
                             }
                             if (num3 != 0)
                             {
                                 LevelObject levelObject = new LevelObject(vector, newRotation, newScale, num3, newName, newGUID, newPlacementOrigin, newInstanceID);
                                 if (levelObject.asset == null)
                                 {
                                     flag = false;
                                 }
                                 if (Level.isEditor)
                                 {
                                     byte b8;
                                     byte b9;
                                     Regions.tryGetCoordinate(vector, out b8, out b9);
                                     if (b8 != b6 || b9 != b7)
                                     {
                                         Debug.LogError(string.Concat(new object[]
                                         {
                                             num3,
                                             " should be in ",
                                             b8,
                                             ", ",
                                             b9,
                                             " but was in ",
                                             b6,
                                             ", ",
                                             b7,
                                             "!"
                                         }));
                                     }
                                     LevelObjects.objects[(int)b8, (int)b9].Add(levelObject);
                                 }
                                 else
                                 {
                                     LevelObjects.objects[(int)b6, (int)b7].Add(levelObject);
                                 }
                                 LevelObjects._total++;
                             }
                         }
                     }
                 }
             }
             if (flag)
             {
                 LevelObjects._hash = river.getHash();
             }
             else
             {
                 LevelObjects._hash = new byte[20];
             }
             river.closeRiver();
         }
         else
         {
             for (byte b10 = 0; b10 < Regions.WORLD_SIZE; b10 += 1)
             {
                 for (byte b11 = 0; b11 < Regions.WORLD_SIZE; b11 += 1)
                 {
                     if (ReadWrite.fileExists(string.Concat(new object[]
                     {
                         Level.info.path,
                         "/Objects/Objects_",
                         b10,
                         "_",
                         b11,
                         ".dat"
                     }), false, false))
                     {
                         River river2 = new River(string.Concat(new object[]
                         {
                             Level.info.path,
                             "/Objects/Objects_",
                             b10,
                             "_",
                             b11,
                             ".dat"
                         }), false);
                         byte b12 = river2.readByte();
                         if (b12 > 0)
                         {
                             ushort num4 = river2.readUInt16();
                             for (ushort num5 = 0; num5 < num4; num5 += 1)
                             {
                                 Vector3    position = river2.readSingleVector3();
                                 Quaternion rotation = river2.readSingleQuaternion();
                                 ushort     num6     = river2.readUInt16();
                                 string     empty    = string.Empty;
                                 Guid       empty2   = Guid.Empty;
                                 ELevelObjectPlacementOrigin placementOrigin = ELevelObjectPlacementOrigin.MANUAL;
                                 if (num6 != 0)
                                 {
                                     LevelObjects.addObject(position, rotation, Vector3.one, num6, empty, empty2, placementOrigin);
                                 }
                             }
                         }
                         river2.closeRiver();
                     }
                 }
             }
             LevelObjects._hash = new byte[20];
         }
     }
     else
     {
         LevelObjects._hash = new byte[20];
     }
     if ((Provider.isServer || Level.isEditor) && ReadWrite.fileExists(Level.info.path + "/Level/Buildables.dat", false, false))
     {
         River river3 = new River(Level.info.path + "/Level/Buildables.dat", false);
         river3.readByte();
         for (byte b13 = 0; b13 < Regions.WORLD_SIZE; b13 += 1)
         {
             for (byte b14 = 0; b14 < Regions.WORLD_SIZE; b14 += 1)
             {
                 ushort num7 = river3.readUInt16();
                 for (ushort num8 = 0; num8 < num7; num8 += 1)
                 {
                     Vector3    vector2      = river3.readSingleVector3();
                     Quaternion newRotation2 = river3.readSingleQuaternion();
                     ushort     num9         = river3.readUInt16();
                     if (num9 != 0)
                     {
                         LevelBuildableObject item = new LevelBuildableObject(vector2, newRotation2, num9);
                         if (Level.isEditor)
                         {
                             byte b15;
                             byte b16;
                             Regions.tryGetCoordinate(vector2, out b15, out b16);
                             if (b15 != b13 || b16 != b14)
                             {
                                 Debug.LogError(string.Concat(new object[]
                                 {
                                     num9,
                                     " should be in ",
                                     b15,
                                     ", ",
                                     b16,
                                     " but was in ",
                                     b13,
                                     ", ",
                                     b14,
                                     "!"
                                 }));
                             }
                             LevelObjects.buildables[(int)b15, (int)b16].Add(item);
                         }
                         else
                         {
                             LevelObjects.buildables[(int)b13, (int)b14].Add(item);
                         }
                         LevelObjects._total++;
                     }
                 }
             }
         }
         river3.closeRiver();
     }
     if (Level.info.configData.Use_Legacy_Objects && !Dedicator.isDedicated && !Level.isEditor)
     {
         for (byte b17 = 0; b17 < Regions.WORLD_SIZE; b17 += 1)
         {
             for (byte b18 = 0; b18 < Regions.WORLD_SIZE; b18 += 1)
             {
                 for (int i = 0; i < LevelObjects.objects[(int)b17, (int)b18].Count; i++)
                 {
                     LevelObject levelObject2 = LevelObjects.objects[(int)b17, (int)b18][i];
                     if (levelObject2.asset != null && !(levelObject2.transform == null))
                     {
                         if (levelObject2.asset.lod != EObjectLOD.NONE)
                         {
                             ObjectsLOD objectsLOD = levelObject2.transform.gameObject.AddComponent <ObjectsLOD>();
                             objectsLOD.lod    = levelObject2.asset.lod;
                             objectsLOD.bias   = levelObject2.asset.lodBias;
                             objectsLOD.center = levelObject2.asset.lodCenter;
                             objectsLOD.size   = levelObject2.asset.lodSize;
                             objectsLOD.calculateBounds();
                         }
                     }
                 }
             }
         }
     }
     if (Level.isEditor)
     {
         LevelObjects.reun  = new IReun[256];
         LevelObjects.step  = 0;
         LevelObjects.frame = 0;
     }
 }
示例#5
0
        public static DevkitHierarchyWorldObject addDevkitObject(Guid GUID, Vector3 position, Quaternion rotation, Vector3 scale, ELevelObjectPlacementOrigin placementOrigin)
        {
            GameObject gameObject = new GameObject();

            gameObject.transform.position   = position;
            gameObject.transform.rotation   = rotation;
            gameObject.transform.localScale = scale;
            DevkitTransactionUtility.recordInstantiation(gameObject);
            DevkitHierarchyWorldObject devkitHierarchyWorldObject = gameObject.AddComponent <DevkitHierarchyWorldObject>();

            LevelHierarchy.initItem(devkitHierarchyWorldObject);
            devkitHierarchyWorldObject.GUID            = GUID;
            devkitHierarchyWorldObject.placementOrigin = placementOrigin;
            return(devkitHierarchyWorldObject);
        }