Exemple #1
0
        protected override void GenerateContents(Vector3[][] spectrumValues)
        {
            int     finalResolution = this._WindWaves.FinalResolution;
            Vector4 tileSizeScales  = this._WindWaves.TileSizeScales;
            int     num             = (this._Water.Seed == 0) ? UnityEngine.Random.Range(0, 1000000) : this._Water.Seed;

            WaterQualityLevel[] qualityLevelsDirect = WaterQualitySettings.Instance.GetQualityLevelsDirect();
            int maxSpectrumResolution = qualityLevelsDirect[qualityLevelsDirect.Length - 1].MaxSpectrumResolution;

            if (finalResolution > maxSpectrumResolution)
            {
                Debug.LogWarningFormat("In water quality settings spectrum resolution of {0} is max, but at runtime a spectrum with resolution of {1} is generated. That may generate some unexpected behaviour. Make sure that the last water quality level has the highest resolution and don't alter it at runtime.", new object[]
                {
                    maxSpectrumResolution,
                    finalResolution
                });
            }
            for (byte b = 0; b < 4; b += 1)
            {
                UnityEngine.Random.State state = UnityEngine.Random.state;
                UnityEngine.Random.InitState(num + (int)b);
                this._Spectrum.ComputeSpectrum(spectrumValues[(int)b], tileSizeScales[(int)b], maxSpectrumResolution, null);
                UnityEngine.Random.state = state;
            }
        }
Exemple #2
0
 public InstancedRandom(Int32 seed)
 {
     this.globalState = UnityEngine.Random.state;
     UnityEngine.Random.InitState(seed);
     this.localState          = UnityEngine.Random.state;
     UnityEngine.Random.state = this.globalState;
 }
Exemple #3
0
        /// <summary>
        /// Server-side function. Creates a new random district in the given region.
        /// </summary>
        private District CreateDistrict(Region r)
        {
            string name = GetRandomDistrictName();

            UnityEngine.Random.State seed = UnityEngine.Random.state;
            return(CreateDistrict(new DistrictData(r.Id, seed, name)));
        }
Exemple #4
0
        /// <summary>
        /// Creates an instance of a wrapper around the <c>UnityEngine.Random</c> engine using the provided <paramref name="state"/> data to directly initialize the engine's state.
        /// </summary>
        /// <param name="state">State data generated from an earlier call to <see cref="IRandom.SaveState()"/> on a binary-compatible type of random engine.</param>
        /// <returns>A newly created instance of the <c>UnityEngine.Random</c> engine.</returns>
        public static UnityRandom CreateWithState(UnityEngine.Random.State state)
        {
            var instance = CreateUninitialized();

            instance.RestoreState(state);
            return(instance);
        }
Exemple #5
0
        public void SetupWaves()
        {
            //create basic waves based off basic wave settings
            UnityEngine.Random.State backupSeed = UnityEngine.Random.state;
            UnityEngine.Random.InitState(randomSeed);
            float a       = basicWaves.amplitude;
            float d       = basicWaves.direction;
            float l       = basicWaves.wavelength;
            int   numWave = BasicWaves.numWaves;

            _waves = new Wave[numWave];

            float r = 1f / numWave;

            for (int i = 0; i < numWave; i++)
            {
                float p   = Mathf.Lerp(0.5f, 1.5f, (float)i * r);
                float amp = a * p * UnityEngine.Random.Range(0.8f, 1.2f);
                float dir = d + UnityEngine.Random.Range(-45f, 45f);
                float len = l * p * UnityEngine.Random.Range(0.6f, 1.4f);
                _waves[i] = new Wave(amp, dir, len);
                UnityEngine.Random.InitState(randomSeed + i + 1);
            }
            UnityEngine.Random.state = backupSeed;
        }
        public static void UnityShuffle <T>(this IList <T> list, UnityEngine.Random.State random)
        {
            var temp = UnityEngine.Random.state;

            UnityEngine.Random.state = random;
            UnityShuffle(list);
            UnityEngine.Random.state = temp;
        }
        public int RandomRange(int min, int max)
        {
            UnityEngine.Random.state = _state;
            var result = UnityEngine.Random.Range(min, max);

            _state = UnityEngine.Random.state;
            return(result);
        }
Exemple #8
0
        public void End()
        {
            m_meshColors.Clear();
            m_rbColors.Clear();

            UnityEngine.Random.state = m_oldRandomState;
            m_oldRandomState         = default(UnityEngine.Random.State);
        }
Exemple #9
0
        public int Range(int min, int max)
        {
            UnityEngine.Random.State externalState = ApplyInternalState();
            int result = UnityEngine.Random.Range(min, max);

            RevertState(externalState);
            return(result);
        }
Exemple #10
0
        public float Range(float min, float max)
        {
            UnityEngine.Random.State externalState = ApplyInternalState();
            float result = UnityEngine.Random.Range(min, max);

            RevertState(externalState);
            return(result);
        }
Exemple #11
0
        // TODO: does it make sense to wrap this way? considering erreyone is static
        public Random(UnityEngine.Random.State unityRandomState, Eunomia.WordList nounList)
        {
            // TODO: test if we're re-setting when we deserialize
            this.unityRandomState    = unityRandomState;
            UnityEngine.Random.state = this.unityRandomState;

            this.NounList = nounList;
        }
        public float RandomRange(float min, float max)
        {
            UnityEngine.Random.state = _state;
            var result = UnityEngine.Random.Range(min, max);

            _state = UnityEngine.Random.state;
            return(result);
        }
Exemple #13
0
        public static T Random <T>(this IList <T> list, int seed)
        {
            UnityEngine.Random.State oldState = UnityEngine.Random.state;
            UnityEngine.Random.InitState(seed);
            T item = list.Random();

            UnityEngine.Random.state = oldState;
            return(item);
        }
        void Start()
        {
            var oldState = UnityEngine.Random.state;

            UnityEngine.Random.InitState(0xaf77);

            Cooldown                 = 0.0f;
            SpawnedEnemyCount        = 0;
            RandomState              = UnityEngine.Random.state;
            UnityEngine.Random.state = oldState;
        }
Exemple #15
0
        public void Begin()
        {
            if (m_meshColors.Count > 0 || m_rbColors.Count > 0)
            {
                Debug.LogError("Begin() called more than once before calling End().");
                return;
            }

            m_oldRandomState = UnityEngine.Random.state;
            UnityEngine.Random.InitState(RandomSeed);
        }
        /// <summary>
        /// 指定した最大値より小さい 0 以上の乱数を返します。
        /// </summary>
        /// <param name="maxValue">生成される乱数の排他的上限値。maxValue は 0 以上にする必要があります。</param>
        /// <returns>0 以上で maxValue 未満の 32 ビット符号付き整数。
        /// つまり、通常は戻り値の範囲に 0 は含まれますが、maxValue は含まれません。
        /// ただし、maxValue が 0 の場合は、0 が返されます。
        /// </returns>
        /// <exception cref="System.ArgumentOutOfRangeException">maxValue が 0 未満です。</exception>
        public override int Next(int maxValue)
        {
            if (maxValue < 0)
            {
                throw new System.ArgumentOutOfRangeException();
            }
            UnityEngine.Random.state = state;
            var v = UnityEngine.Random.Range(0, maxValue);

            state = UnityEngine.Random.state;
            return(v);
        }
Exemple #17
0
        private void InitSeed()
        {
            UnityEngine.Random.State originalRandomState = UnityEngine.Random.state;
            if (!UseFixedSeed)
            {
                Seed  = UnityEngine.Random.Range(0, int.MaxValue);
                Seed ^= (int)System.DateTime.Now.Ticks;
                Seed ^= (int)Time.unscaledTime;
                Seed &= int.MaxValue;
            }

            UnityEngine.Random.InitState(Seed);
        }
        static StackObject *set_state_2(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            UnityEngine.Random.State value = (UnityEngine.Random.State) typeof(UnityEngine.Random.State).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            UnityEngine.Random.state = value;

            return(__ret);
        }
Exemple #19
0
        public static bool Prefix(ref WorldGenerator __instance, ref List <WorldGenerator.River> __result)
        {
            UnityEngine.Random.State state = UnityEngine.Random.state;
            UnityEngine.Random.InitState(__instance.m_riverSeed);
            DateTime now = DateTime.Now;
            List <WorldGenerator.River> list  = new List <WorldGenerator.River>();
            List <UnityEngine.Vector2>  list2 = new List <UnityEngine.Vector2>(__instance.m_lakes);

            while (list2.Count > 1)
            {
                UnityEngine.Vector2 vector = list2[0];
                int num = __instance.FindRandomRiverEnd(list, __instance.m_lakes, vector, WorldGenOptions.GenOptions.usingData.riverMultipleMaxDistance, 0.4f, 128f);
                if (num == -1 && !__instance.HaveRiver(list, vector))
                {
                    num = __instance.FindRandomRiverEnd(list, __instance.m_lakes, vector, 5000f, 0.4f, 128f);
                }
                if (num != -1)
                {
                    WorldGenerator.River river = new WorldGenerator.River();
                    river.p0       = vector;
                    river.p1       = __instance.m_lakes[num];
                    river.center   = (river.p0 + river.p1) * 0.5f;
                    river.widthMax = UnityEngine.Random.Range(WorldGenOptions.GenOptions.usingData.riverWidthMaxLowerRange, WorldGenOptions.GenOptions.usingData.riverWidthMaxUpperRange);
                    river.widthMin = UnityEngine.Random.Range(WorldGenOptions.GenOptions.usingData.riverWidthMinLowerRange, river.widthMax);
                    float num2 = UnityEngine.Vector2.Distance(river.p0, river.p1);
                    river.curveWidth      = num2 / WorldGenOptions.GenOptions.usingData.riverCurveWidth;
                    river.curveWavelength = num2 / WorldGenOptions.GenOptions.usingData.riverWavelength;
                    list.Add(river);
                }
                else
                {
                    list2.RemoveAt(0);
                }
            }
            ZLog.Log("Rivers:" + list.Count);
            __instance.RenderRivers(list);
            ZLog.Log("River Calc time " + (DateTime.Now - now).TotalMilliseconds + " ms");
            UnityEngine.Random.state = state;
            __result = list;
            return(false);
        }
Exemple #20
0
 static void Prefix(bool dontremove, bool random)
 {
     if (!random)
     {
         return;
     }
     useSeed   = seedConfig.Bind("General", "UseSeed", false, "Whether or not to use seeds when playing MYSTERY?");
     takenSeed = seedConfig.Bind("General", "SeedNum", defaultValue: seedVal, "This is the seed used to play MYSTERY?. Please insert numbers between 0 and 4,294,967,295 into this field.");
     rngHold   = UnityEngine.Random.state;
     if (useSeed.Value)
     {
         taken      = true;
         editedSeed = unchecked ((int)takenSeed.Value);
         UnityEngine.Random.InitState(editedSeed);
         System.Diagnostics.Debug.WriteLine("Initialized! The seed number is " + editedSeed);
     }
     else
     {
         System.Diagnostics.Debug.WriteLine("You didn't use seeds this run! (or the config file broke tremendously lol)");
     }
 }
        protected void Update()
        {
            var oldState = UnityEngine.Random.state;

            UnityEngine.Random.state = RandomState;

            Cooldown -= Time.deltaTime;

            if (Cooldown <= 0.0f)
            {
                var settings = TwoStickBootstrap.Settings;
                var enemy    = Object.Instantiate(settings.EnemyPrefab);
                //@TODO set transform
                ComputeSpawnLocation(enemy);
                SpawnedEnemyCount++;
                Cooldown = ComputeCooldown(SpawnedEnemyCount);
            }

            RandomState = UnityEngine.Random.state;

            UnityEngine.Random.state = oldState;
        }
        /// <summary> Return color based on type </summary>
        public static Color GetTypeColor(System.Type type)
        {
            VerifyLoaded();
            if (type == null)
            {
                return(Color.gray);
            }
            Color col;

            if (!typeColors.TryGetValue(type, out col))
            {
                string typeName = type.PrettyName();
                if (settings[lastKey].typeColors.ContainsKey(typeName))
                {
                    typeColors.Add(type, settings[lastKey].typeColors[typeName]);
                }
                else
                {
#if UNITY_5_4_OR_NEWER
                    UnityEngine.Random.State oldState = UnityEngine.Random.state;
                    UnityEngine.Random.InitState(typeName.GetHashCode());
#else
                    int oldSeed = UnityEngine.Random.seed;
                    UnityEngine.Random.seed = typeName.GetHashCode();
#endif
                    col = new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value);
                    typeColors.Add(type, col);
#if UNITY_5_4_OR_NEWER
                    UnityEngine.Random.state = oldState;
#else
                    UnityEngine.Random.seed = oldSeed;
#endif
                }
            }
            return(col);
        }
Exemple #23
0
 public void Init(NiceRNG hadesRngOther)
 {
     _seed  = hadesRngOther._seed;
     _state = hadesRngOther._state;
 }
        public override void OnInspectorGUI()
        {
            TargetMeshRenderer.gameObject.SetActive(false);
            try
            {
                foreach (PortalController p in targets)
                {
                    Undo.RecordObject(p, "Portal Controller Editor Changes");
                }

                EditorGUI.BeginChangeCheck();
                PortalController.TargetController = (PortalController)EditorGUILayout.ObjectField(
                    new GUIContent("Target Controller", "The targetTransform of this Portal."),
                    PortalController.TargetController, typeof(PortalController), true, null);
                if (EditorGUI.EndChangeCheck())
                {
                    foreach (PortalController p in targets)
                    {
                        p.TargetController = PortalController.TargetController;
                    }
                }

                //if (!PortalController.PortalScript.PortalCamera ||
                //    !PortalController.TargetController.PortalScript.PortalCamera) return;

                EditorGUI.BeginChangeCheck();
                PortalController.Portal =
                    (GameObject)EditorGUILayout.ObjectField(
                        new GUIContent("Portal Prefab", "The Prefab to use for when the Portal is spawned"),
                        PortalController.Portal, typeof(GameObject), false, null);
                if (EditorGUI.EndChangeCheck())
                {
                    foreach (PortalController p in targets)
                    {
                        p.Portal = PortalController.Portal;
                    }
                }


                if (SKSGlobalRenderSettings.ShouldOverrideMask)
                {
                    EditorGUILayout.HelpBox("Your Global Portal Settings are currently overriding the mask",
                                            MessageType.Warning);
                }

                EditorGUI.BeginChangeCheck();
                PortalController.Mask = (Texture2D)EditorGUILayout.ObjectField(new GUIContent("Portal Mask", "The transparency mask to use on the Portal"), PortalController.Mask, typeof(Texture2D), false, GUILayout.MaxHeight(EditorGUIUtility.singleLineHeight));

                if (EditorGUI.EndChangeCheck())
                {
                    foreach (PortalController p in targets)
                    {
                        p.Mask = PortalController.Mask;
                    }
                }

                EditorGUI.BeginChangeCheck();
                Material material =
                    (Material)EditorGUILayout.ObjectField(
                        new GUIContent("Portal Material", "The material to use for the Portal"),
                        PortalController.PortalMaterial, typeof(Material), false, null);
                if (EditorGUI.EndChangeCheck())
                {
                    PortalMaterial = material;
                    foreach (PortalController p in targets)
                    {
                        p.PortalMaterial = PortalController.PortalMaterial;
                    }
                }


                EditorGUI.BeginChangeCheck();
                PortalController.Enterable =
                    EditorGUILayout.Toggle(
                        new GUIContent("Enterable", "Is the Portal Enterable by Teleportable Objects?"),
                        PortalController.Enterable);
                if (EditorGUI.EndChangeCheck())
                {
                    foreach (PortalController p in targets)
                    {
                        p.Enterable = PortalController.Enterable;
                    }
                }

                EditorGUI.BeginChangeCheck();
                PortalController.Is3D =
                    EditorGUILayout.Toggle(
                        new GUIContent("Portal is 3D Object", "Is the Portal a 3d object, such as a Crystal ball?"),
                        PortalController.Is3D);
                if (EditorGUI.EndChangeCheck())
                {
                    foreach (PortalController p in targets)
                    {
                        p.Is3D = PortalController.Is3D;
                    }
                }

                EditorGUI.BeginChangeCheck();
                PortalController.DetectionScale = EditorGUILayout.Slider(
                    new GUIContent("Detection zone Scale", "The scale of the portal detection zone."),
                    PortalController.DetectionScale, 1f, 10f);
                if (EditorGUI.EndChangeCheck())
                {
                    foreach (PortalController p in targets)
                    {
                        p.DetectionScale = PortalController.DetectionScale;
                    }
                }
                //Show the Portal Material Inspector
                if (Application.isPlaying)
                {
                    return;
                }

                EditorGUILayout.LabelField("Portal Material Preview:");

                if (PortalController.PortalMaterial)
                {
                    if (_matEditor == null)
                    {
                        _matEditor = UnityEditor.Editor.CreateEditor(PortalController.PortalMaterial);
                    }
                }

                _matEditor.DrawHeader();
                _matEditor.OnInspectorGUI();
            }
            catch
            {
                //Just for cleanliness
            }
            finally
            {
                if (!SKSGlobalRenderSettings.Preview)
                {
                    //CleanupTemp();
                }
            }

            //Cache state of random
            UnityEngine.Random.State seed = UnityEngine.Random.state;
            //Make color deterministic based on ID
            UnityEngine.Random.InitState(PortalController.GetInstanceID());
            PortalController.color = UnityEngine.Random.ColorHSV(0, 1, 0.48f, 0.48f, 0.81f, 0.81f);
            //Reset the random
            UnityEngine.Random.state = seed;
        }
Exemple #25
0
 public RandomGeneratorUnity(long seed)
 {
     UnityEngine.Random.InitState((int)seed);
     m_State = UnityEngine.Random.state;
 }
Exemple #26
0
 private UnityEngine.Random.State ApplyInternalState()
 {
     UnityEngine.Random.State state = UnityEngine.Random.state;
     UnityEngine.Random.state = _state;
     return(state);
 }
Exemple #27
0
 private void RevertState(UnityEngine.Random.State externalState)
 {
     _state = UnityEngine.Random.state;
     UnityEngine.Random.state = externalState;
 }
Exemple #28
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>();
                }
            }
        }
Exemple #29
0
 private void RestoreState()
 {
     this.localState          = UnityEngine.Random.state;
     UnityEngine.Random.state = this.globalState;
 }
Exemple #30
0
 private void SetState(int seed)
 {
     UnityEngine.Random.State externalState = ApplyInternalState();
     UnityEngine.Random.InitState(seed);
     RevertState(externalState);
 }