void Awake()
        {
            if (!DaggerfallUnity.Settings.Nystul_IncreasedTerrainDistance)
                return;

            dfUnity = DaggerfallUnity.Instance;

            dfUnity.TerrainSampler = new ImprovedTerrainSampler();

            //ImprovedTerrainSampler improvedTerrainSampler = DaggerfallUnity.Instance.TerrainSampler as ImprovedTerrainSampler;
            //if (improvedTerrainSampler == null)
            //{
            //    DaggerfallUnity.LogMessage("IncreasedTerrainDistance: TerrainSampler instance is not of type ImprovedTerrainSampler (use ITerrainSampler terrainSampler = new ImprovedTerrainSampler() in DaggerfallUnity.cs)", true);
            //}

            if (!streamingWorld)
                streamingWorld = GameObject.Find("StreamingWorld").GetComponent<StreamingWorld>();
            if (!streamingWorld)
            {
                DaggerfallUnity.LogMessage("IncreasedTerrainDistance: Missing StreamingWorld reference.", true);
                if (Application.isEditor)
                    Debug.Break();
                else
                    Application.Quit();
            }

            if (!playerGPS)
                playerGPS = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerGPS>();
            if (!playerGPS)
            {
                DaggerfallUnity.LogMessage("IncreasedTerrainDistance: Missing PlayerGPS reference.", true);
                if (Application.isEditor)
                    Debug.Break();
                else
                    Application.Quit();
            }

            if (!weatherManager)
            {
                //weatherManager = GameObject.Find("WeatherManager").GetComponent<WeatherManager>();
                WeatherManager[] weatherManagers = Resources.FindObjectsOfTypeAll<WeatherManager>();
                foreach (WeatherManager currentWeatherManager in weatherManagers)
                {
                    GameObject go = currentWeatherManager.gameObject;
                    string objectPathInHierarchy = GetGameObjectPath(go);
                    if (objectPathInHierarchy == "/Exterior/WeatherManager")
                    {
                        weatherManager = currentWeatherManager;
                        break;
                    }
                }
            }
            if (!weatherManager)
            {
                DaggerfallUnity.LogMessage("IncreasedTerrainDistance: Missing WeatherManager reference.", true);
                if (Application.isEditor)
                    Debug.Break();
                else
                    Application.Quit();
            }

            SetupGameObjects(); // create cameras here in OnAwake() so MirrorReflection script of ReflectionsMod can find cameras in its Start() function
        }
Пример #2
0
        void FixedUpdate()
        {
            DaggerfallDateTime.Seasons playerSeason = dfUnity.WorldTime.Now.SeasonValue;
            int playerClimateIndex = GameManager.Instance.PlayerGPS.CurrentClimateIndex;

            // Get player inside flag
            // Can only do this when PlayerEnterExit is available, otherwise default to true
            bool playerInside     = (playerEnterExit == null) ? true : playerEnterExit.IsPlayerInside;
            bool playerInBuilding = (playerEnterExit == null) ? false : playerEnterExit.IsPlayerInsideBuilding;

            // Play splash footsteps whether player is walking on or swimming in exterior water
            bool playerOnExteriorWater = (GameManager.Instance.PlayerMotor.OnExteriorWater == PlayerMotor.OnExteriorWaterMethod.Swimming || GameManager.Instance.PlayerMotor.OnExteriorWater == PlayerMotor.OnExteriorWaterMethod.WaterWalking);

            // Change footstep sounds between winter/summer variants or when player enters/exits an interior space
            if (playerSeason != currentSeason || playerClimateIndex != currentClimateIndex || isInside != playerInside || playerOnExteriorWater != isInOutsideWater)
            {
                currentSeason       = playerSeason;
                currentClimateIndex = playerClimateIndex;
                isInside            = playerInside;
                isInOutsideWater    = playerOnExteriorWater;
                if (!isInside)
                {
                    if (currentSeason == DaggerfallDateTime.Seasons.Winter && !WeatherManager.IsSnowFreeClimate(currentClimateIndex))
                    {
                        currentFootstepSound1 = FootstepSoundSnow1;
                        currentFootstepSound2 = FootstepSoundSnow2;
                    }
                    else
                    {
                        currentFootstepSound1 = FootstepSoundOutside1;
                        currentFootstepSound2 = FootstepSoundOutside2;
                    }
                }
                else if (playerInBuilding)
                {
                    currentFootstepSound1 = FootstepSoundBuilding1;
                    currentFootstepSound2 = FootstepSoundBuilding2;
                }
                else // in dungeon
                {
                    currentFootstepSound1 = FootstepSoundDungeon1;
                    currentFootstepSound2 = FootstepSoundDungeon2;
                }

                clip1 = null;
                clip2 = null;
            }

            // walking on water tile
            if (playerOnExteriorWater)
            {
                currentFootstepSound1 = FootstepSoundSubmerged;
                currentFootstepSound2 = FootstepSoundSubmerged;
                clip1 = null;
                clip2 = null;
            }

            // Use water sounds if in dungeon water
            if (GameManager.Instance.PlayerEnterExit.IsPlayerInsideDungeon && playerEnterExit.blockWaterLevel != 10000)
            {
                // In water, deep depth
                if ((currentFootstepSound1 != FootstepSoundSubmerged) && playerEnterExit.IsPlayerSwimming)
                {
                    currentFootstepSound1 = FootstepSoundSubmerged;
                    currentFootstepSound2 = FootstepSoundSubmerged;
                    clip1 = null;
                    clip2 = null;
                }
                // In water, shallow depth
                else if ((currentFootstepSound1 != FootstepSoundShallow) && !playerEnterExit.IsPlayerSwimming && (playerMotor.transform.position.y - 0.95f) < (playerEnterExit.blockWaterLevel * -1 * MeshReader.GlobalScale))
                {
                    currentFootstepSound1 = FootstepSoundShallow;
                    currentFootstepSound2 = FootstepSoundShallow;
                    clip1 = null;
                    clip2 = null;
                }
            }

            // Not in water, reset footsteps to normal
            if ((!playerOnExteriorWater) &&
                (currentFootstepSound1 == FootstepSoundSubmerged || currentFootstepSound1 == FootstepSoundShallow) &&
                (playerEnterExit.blockWaterLevel == 10000 || (playerMotor.transform.position.y - 0.95f) >= (playerEnterExit.blockWaterLevel * -1 * MeshReader.GlobalScale)))
            {
                currentFootstepSound1 = FootstepSoundDungeon1;
                currentFootstepSound2 = FootstepSoundDungeon2;

                clip1 = null;
                clip2 = null;
            }

            // Reload clips if needed
            if (clip1 == null)
            {
                clip1 = dfAudioSource.GetAudioClip((int)currentFootstepSound1);
            }
            if (clip2 == null)
            {
                clip2 = dfAudioSource.GetAudioClip((int)currentFootstepSound2);
            }

            // Check whether player is on foot and abort playing footsteps if not.
            if (playerMotor.IsLevitating || !transportManager.IsOnFoot && GameManager.Instance.PlayerMotor.OnExteriorWater == PlayerMotor.OnExteriorWaterMethod.None)
            {
                distance = 0f;
                return;
            }

            // Check if player is grounded
            // Note: In classic, submerged "footstep" sound is only played when walking on the floor while in the water, but it sounds like a swimming sound
            // and when outside is played while swimming at the water's surface, so it seems better to play it all the time while submerged in water.
            if (currentFootstepSound1 != FootstepSoundSubmerged)
            {
                if (!IsGrounded())
                {
                    // Player has lost grounding
                    distance      = 0f;
                    lostGrounding = true;
                    return;
                }
                else
                {
                    // Player is grounded but we might need to reset after losing grounding
                    if (lostGrounding)
                    {
                        distance      = 0f;
                        lastPosition  = GetHorizontalPosition();
                        lostGrounding = false;
                        return;
                    }
                }
            }

            // Get distance player travelled horizontally
            Vector3 position = GetHorizontalPosition();

            distance    += Vector3.Distance(position, lastPosition);
            lastPosition = position;

            // Get threshold
            float threshold = WalkStepInterval;

            if (playerMotor)
            {
                threshold = (playerMotor.IsRunning) ? RunStepInterval : WalkStepInterval;
            }

            // Play sound if over distance threshold
            if (distance > threshold && customAudioSource && clip1 && clip2)
            {
                float volumeScale = FootstepVolumeScale;
                if (playerMotor.IsMovingLessThanHalfSpeed)
                {
                    volumeScale *= 0.5f;
                }

                if (!alternateStep)
                {
                    customAudioSource.PlayOneShot(clip1, volumeScale * DaggerfallUnity.Settings.SoundVolume);
                }
                else
                {
                    customAudioSource.PlayOneShot(clip2, volumeScale * DaggerfallUnity.Settings.SoundVolume);
                }

                alternateStep = (!alternateStep);
                distance      = 0f;
            }
        }
        private bool GetRefrences()
        {
            try
            {
                if (!_depthMaskShader)
                    _depthMaskShader = Resources.Load("DepthMask") as Shader;
                if (!_UnlitAlphaFadeShader)
                    _UnlitAlphaFadeShader = Resources.Load("UnlitAlphaWithFade") as Shader;
                if (!StarMaskMat)
                    StarMaskMat = new Material(_depthMaskShader);
                if (!_skyObjMat)
                    _skyObjMat = new Material(_UnlitAlphaFadeShader);
                if (!StarsMat)
                    StarsMat = Instantiate(Resources.Load("Stars")) as Material;
                if (!SkyMat)
                    SkyMat = Instantiate(Resources.Load("Sky")) as Material;
                if (!_cloudGen)
                    _cloudGen = this.GetComponent<CloudGenerator>();
                if(!_cloudGen)
                    _cloudGen = gameObject.AddComponent<CloudGenerator>();
                if (!_containerPrefab)
                    _containerPrefab = Resources.Load("EnhancedSkyContainer", typeof(GameObject)) as GameObject;
                if (!dfallSky)
                    dfallSky = GameManager.Instance.SkyRig.gameObject;
                if (!playerEE)
                    playerEE = GameManager.Instance.PlayerEnterExit;
                if (!exteriorParent)
                    exteriorParent = GameManager.Instance.ExteriorParent;
                if (!weatherMan)
                    weatherMan = GameManager.Instance.WeatherManager;

            }
            catch
            {
                DaggerfallUnity.LogMessage("Error in SkyManager.GetRefrences()", true);
                return false;
            }
            if (dfallSky && playerEE && exteriorParent && weatherMan && _cloudGen && _containerPrefab && _depthMaskShader && _UnlitAlphaFadeShader
                && StarMaskMat && _skyObjMat && StarsMat && SkyMat)
                return true;
            else
                return false;
        }