void Start() { dfUnity = DaggerfallUnity.Instance; songPlayer = GetComponent <DaggerfallSongPlayer>(); // Get local player GPS if not set if (LocalPlayerGPS == null) { LocalPlayerGPS = GameManager.Instance.PlayerGPS; } // Get player entity if (playerEntity == null) { playerEntity = GameManager.Instance.PlayerEntity; } // Get streaming world if not set if (StreamingWorld == null) { StreamingWorld = GameManager.Instance.StreamingWorld; } // Get required player components if (LocalPlayerGPS) { playerEnterExit = LocalPlayerGPS.GetComponent <PlayerEnterExit>(); playerWeather = LocalPlayerGPS.GetComponent <PlayerWeather>(); } }
void Awake() { dfUnity = DaggerfallUnity.Instance; playerGPS = GetComponent <PlayerGPS>(); world = FindObjectOfType <StreamingWorld>(); player = GameManager.Instance.PlayerEntityBehaviour; }
/// <summary>True when there's a recorded position before boarding and player is on the ship</summary> public bool IsOnShip() { StreamingWorld world = GameManager.Instance.StreamingWorld; DFPosition shipCoords = DaggerfallBankManager.GetShipCoords(); return(boardShipPosition != null && shipCoords != null && world.MapPixelX == shipCoords.X && world.MapPixelY == shipCoords.Y); }
void Start() { dfUnity = DaggerfallUnity.Instance; songPlayer = GetComponent <DaggerfallSongPlayer>(); // Get local player GPS if not set if (LocalPlayerGPS == null) { LocalPlayerGPS = GameManager.Instance.PlayerGPS; } // Get streaming world if not set if (StreamingWorld == null) { StreamingWorld = GameManager.Instance.StreamingWorld; } // Get required player components if (LocalPlayerGPS) { playerEnterExit = LocalPlayerGPS.GetComponent <PlayerEnterExit>(); playerWeather = LocalPlayerGPS.GetComponent <PlayerWeather>(); } // Shuffle song on load or fast travel StreamingWorld.OnInitWorld += StreamingWorld_OnInitWorld; }
void Awake() { dfUnity = DaggerfallUnity.Instance; //mainCamera = GameObject.FindGameObjectWithTag("MainCamera"); //playerMouseLook = GetComponent<PlayerMouseLook>(); playerGPS = GetComponent <PlayerGPS>(); world = FindObjectOfType <StreamingWorld>(); }
void Start() { dfUnity = DaggerfallUnity.Instance; songPlayer = GetComponent <DaggerfallSongPlayer>(); // Get local player GPS if not set if (LocalPlayerGPS == null) { LocalPlayerGPS = GameManager.Instance.PlayerGPS; } // Get player entity if (playerEntity == null) { playerEntity = GameManager.Instance.PlayerEntity; } // Get streaming world if not set if (StreamingWorld == null) { StreamingWorld = GameManager.Instance.StreamingWorld; } // Get required player components if (LocalPlayerGPS) { playerEnterExit = LocalPlayerGPS.GetComponent <PlayerEnterExit>(); playerWeather = LocalPlayerGPS.GetComponent <PlayerWeather>(); } // Use alternate music if set if (DaggerfallUnity.Settings.AlternateMusic) { DungeonInteriorSongs = _dungeonSongsFM; SunnySongs = _sunnySongsFM; CloudySongs = _cloudySongsFM; OvercastSongs = _overcastSongsFM; RainSongs = _weatherRainSongsFM; SnowSongs = _weatherSnowSongsFM; TempleSongs = _templeSongsFM; TavernSongs = new SongFiles[_tavernSongs.Length + _tavernSongsFM.Length]; Array.Copy(_tavernSongs, TavernSongs, _tavernSongs.Length); Array.Copy(_tavernSongsFM, 0, TavernSongs, _tavernSongs.Length, _tavernSongsFM.Length); NightSongs = _nightSongsFM; ShopSongs = _shopSongsFM; MagesGuildSongs = _magesGuildSongsFM; InteriorSongs = _interiorSongsFM; PalaceSongs = _palaceSongsFM; CastleSongs = _castleSongsFM; CourtSongs = _courtSongsFM; SneakingSongs = _sneakingSongsFM; } PlayerEnterExit.OnTransitionDungeonInterior += PlayerEnterExit_OnTransitionDungeonInterior; PlayerEnterExit.OnTransitionInterior += PlayerEnterExit_OnTransitionInterior; }
// Start new character to location specified in INI void StartNewCharacter() { DaggerfallUI.Instance.PopToHUD(); // Assign character sheet PlayerEntity playerEntity = FindPlayerEntity(); playerEntity.AssignCharacter(characterSheet); // Set game time DaggerfallUnity.Instance.WorldTime.Now.SetClassicGameStartTime(); // Get start parameters DFPosition mapPixel = new DFPosition(DaggerfallUnity.Settings.StartCellX, DaggerfallUnity.Settings.StartCellY); bool startInDungeon = DaggerfallUnity.Settings.StartInDungeon; // Read location if any DFLocation location = new DFLocation(); ContentReader.MapSummary mapSummary; bool hasLocation = DaggerfallUnity.Instance.ContentReader.HasLocation(mapPixel.X, mapPixel.Y, out mapSummary); if (hasLocation) { if (!DaggerfallUnity.Instance.ContentReader.GetLocation(mapSummary.RegionIndex, mapSummary.MapIndex, out location)) { hasLocation = false; } } // Start at specified location StreamingWorld streamingWorld = FindStreamingWorld(); if (hasLocation && startInDungeon && location.HasDungeon) { if (streamingWorld) { streamingWorld.TeleportToCoordinates(mapPixel.X, mapPixel.Y); streamingWorld.suppressWorld = true; } playerEnterExit.EnableDungeonParent(); playerEnterExit.StartDungeonInterior(location); } else { playerEnterExit.EnableExteriorParent(); if (streamingWorld) { streamingWorld.SetAutoReposition(StreamingWorld.RepositionMethods.Origin, Vector3.zero); streamingWorld.suppressWorld = false; } } // Start game GameManager.Instance.PauseGame(false); DaggerfallUI.Instance.FadeHUDFromBlack(); }
StreamingWorld FindStreamingWorld() { streamingWorld = FindObjectOfType <StreamingWorld>(); if (!streamingWorld) { throw new Exception("StreamingWorld not found."); } return(streamingWorld); }
void Start() { dfUnity = DaggerfallUnity.Instance; streamingWorld = GameObject.FindObjectOfType <StreamingWorld>(); titleScreen = GameObject.FindObjectOfType <ShowTitleScreen>(); //songPlayer = GameObject.FindObjectOfType<DaggerfallSongPlayer>(); playerEnterExit = GetComponent <PlayerEnterExit>(); //if (songPlayer) // songPlayer.Song = SongFilesAll.song_03; }
void Start() { if (!player) { player = GameObject.FindGameObjectWithTag("Player"); } if (!StreamingWorld) { StreamingWorld = GameObject.Find("StreamingWorld").GetComponent <StreamingWorld>(); } }
StreamingWorld FindStreamingWorld() { StreamingWorld streamingWorld = GameObject.FindObjectOfType <StreamingWorld>(); if (!streamingWorld) { throw new Exception("Could not find StreamingWorld."); } return(streamingWorld); }
void Start() { dfUnity = DaggerfallUnity.Instance; useDeferredReflections = (GameManager.Instance.MainCamera.renderingPath == RenderingPath.DeferredShading); if (!streamingWorld) { streamingWorld = GameObject.Find("StreamingWorld").GetComponent <StreamingWorld>(); } if (!streamingWorld) { DaggerfallUnity.LogMessage("InjectReflectiveMaterialProperty: Missing StreamingWorld reference.", true); if (Application.isEditor) { Debug.Break(); } else { Application.Quit(); } } if (GameObject.Find("DistantTerrain") != null) { Component[] components = GameObject.Find("DistantTerrain").GetComponents(typeof(Component)); foreach (Component component in components) { Type type = component.GetType(); if (type.Name == "DistantTerrain") { //System.Reflection.PropertyInfo pinfo = type.GetProperty("ExtraTranslationY"); System.Reflection.PropertyInfo extraTranslationYPropertyInfo = type.GetProperty("ExtraTranslationY"); extraTranslationY = (float)extraTranslationYPropertyInfo.GetValue(component, null); } } } //gameObjectReflectionPlaneGroundLevel = componentUpdateReflectionTextures.GameobjectReflectionPlaneGround; //gameObjectReflectionPlaneLowerLevel = componentUpdateReflectionTextures.GameobjectReflectionPlaneLowerLevel; //gameObjectReflectionPlaneSeaLevel = gameObjectReflectionPlaneLowerLevel; // get inactive gameobject StreamingTarget (just GameObject.Find() would fail to find inactive gameobjects) GameObject[] gameObjects = Resources.FindObjectsOfTypeAll <GameObject>(); foreach (GameObject currentGameObject in gameObjects) { string objectPathInHierarchy = GetGameObjectPath(currentGameObject); if (objectPathInHierarchy == "/Exterior/StreamingTarget") { gameObjectStreamingTarget = currentGameObject; } } }
public void PositionPlayerAtLocationEntrance() { DFPosition mapPixel = GameManager.Instance.PlayerGPS.CurrentMapPixel; ContentReader.MapSummary mapSummary; if (DaggerfallUnity.Instance.ContentReader.HasLocation(mapPixel.X, mapPixel.Y, out mapSummary)) { StreamingWorld world = GameManager.Instance.StreamingWorld; StreamingWorld.RepositionMethods reposition = StreamingWorld.RepositionMethods.None; reposition = StreamingWorld.RepositionMethods.RandomStartMarker; world.TeleportToCoordinates(mapPixel.X, mapPixel.Y, reposition); } }
void Start() { // Get Daggerfall Unity components streamingWorld = GameManager.Instance.StreamingWorld; playerWeather = GameManager.Instance.WeatherManager.PlayerWeather; windZone = GameManager.Instance.WeatherManager.GetComponent <WindZone>(); // Setup mod Setup(); Mod.MessageReceiver = VibrantWindModMessages.MessageReceiver; // Start mod ToggleMod(true, false); }
void Start() { dfUnity = DaggerfallUnity.Instance; useDeferredReflections = (GameManager.Instance.MainCamera.renderingPath == RenderingPath.DeferredShading); if (!streamingWorld) { streamingWorld = GameObject.Find("StreamingWorld").GetComponent <StreamingWorld>(); } if (!streamingWorld) { DaggerfallUnity.LogMessage("InjectReflectiveMaterialProperty: Missing StreamingWorld reference.", true); if (Application.isEditor) { Debug.Break(); } else { Application.Quit(); } } if (GameObject.Find("IncreasedTerrainDistanceMod") != null) { if (DaggerfallUnity.Settings.Nystul_IncreasedTerrainDistance) { extraTranslationY = GameObject.Find("IncreasedTerrainDistanceMod").GetComponent <ProjectIncreasedTerrainDistance.IncreasedTerrainDistance>().ExtraTranslationY; } } gameObjectReflectionPlaneGroundLevel = GameObject.Find("ReflectionPlaneBottom"); gameObjectReflectionPlaneSeaLevel = GameObject.Find("ReflectionPlaneSeaLevel"); gameObjectReflectionPlaneLowerLevel = gameObjectReflectionPlaneSeaLevel; // get inactive gameobject StreamingTarget (just GameObject.Find() would fail to find inactive gameobjects) GameObject[] gameObjects = Resources.FindObjectsOfTypeAll <GameObject>(); foreach (GameObject currentGameObject in gameObjects) { string objectPathInHierarchy = GetGameObjectPath(currentGameObject); if (objectPathInHierarchy == "/Exterior/StreamingTarget") { gameObjectStreamingTarget = currentGameObject; } } iniData = getIniParserConfigInjectionTextures(); }
void Start() { dfUnity = DaggerfallUnity.Instance; streamingWorld = GameObject.FindObjectOfType <StreamingWorld>(); playerEnterExit = GetComponent <PlayerEnterExit>(); playerGPS = GetComponent <PlayerGPS>(); playerMotor = GetComponent <PlayerMotor>(); playerMouseLook = GameObject.FindObjectOfType <PlayerMouseLook>(); titleScreen = GameObject.FindObjectOfType <ShowTitleScreen>(); // Get starting run speed if (playerMotor) { startRunSpeed = playerMotor.runSpeed; } }
//PlayerMotor playerMotor; //PlayerMouseLook playerMouseLook; //ShowTitleScreen titleScreen; //int timeScaleControl = 1; //int minTimeScaleControl = 1; //int maxTimeScaleControl = 150; //int timeScaleStep = 25; //float timeScaleMultiplier = 10f; //float startRunSpeed; //float startTorchRange; //bool showDebugStrings = false; //bool invertMouse = false; //bool hiRunSpeed = false; //bool hiTorchRange = false; void Start() { dfUnity = DaggerfallUnity.Instance; streamingWorld = GameObject.FindObjectOfType <StreamingWorld>(); playerEnterExit = GetComponent <PlayerEnterExit>(); playerGPS = GetComponent <PlayerGPS>(); //playerMotor = GetComponent<PlayerMotor>(); //playerMouseLook = GameObject.FindObjectOfType<PlayerMouseLook>(); //titleScreen = GameObject.FindObjectOfType<ShowTitleScreen>(); //// Get starting run speed //if (playerMotor) // startRunSpeed = playerMotor.runSpeed; //// Get starting torch range //if (PlayerTorch != null) // startTorchRange = PlayerTorch.range; }
void Start() { dfUnity = DaggerfallUnity.Instance; reflectionTexturesScript = GameObject.Find("ReflectionsMod").GetComponent <UpdateReflectionTextures>(); if (!streamingWorld) { streamingWorld = GameObject.Find("StreamingWorld").GetComponent <StreamingWorld>(); } if (!streamingWorld) { DaggerfallUnity.LogMessage("InjectReflectiveMaterialProperty: Missing StreamingWorld reference.", true); if (Application.isEditor) { Debug.Break(); } else { Application.Quit(); } } gameObjectReflectionPlaneGroundLevel = GameObject.Find("ReflectionPlaneBottom"); gameObjectReflectionPlaneSeaLevel = GameObject.Find("ReflectionPlaneSeaLevel"); gameObjectReflectionPlaneLowerLevel = gameObjectReflectionPlaneSeaLevel; // get inactive gameobject StreamingTarget (just GameObject.Find() would fail to find inactive gameobjects) GameObject[] gameObjects = Resources.FindObjectsOfTypeAll <GameObject>(); foreach (GameObject currentGameObject in gameObjects) { string objectPathInHierarchy = GetGameObjectPath(currentGameObject); if (objectPathInHierarchy == "/Exterior/StreamingTarget") { gameObjectStreamingTarget = currentGameObject; } } iniData = getIniParserConfigInjectionTextures(); }
void Start() { dfUnity = DaggerfallUnity.Instance; streamingWorld = GameObject.FindObjectOfType<StreamingWorld>(); playerEnterExit = GetComponent<PlayerEnterExit>(); playerGPS = GetComponent<PlayerGPS>(); playerMotor = GetComponent<PlayerMotor>(); playerMouseLook = GameObject.FindObjectOfType<PlayerMouseLook>(); titleScreen = GameObject.FindObjectOfType<ShowTitleScreen>(); // Get starting run speed if (playerMotor) startRunSpeed = playerMotor.runSpeed; // Get starting torch range if (PlayerTorch != null) startTorchRange = PlayerTorch.range; }
void StartFromClassicSave() { DaggerfallUnity.ResetUID(); RaiseOnNewGameEvent(); ResetWeaponManager(); // Save index must be in range if (classicSaveIndex < 0 || classicSaveIndex >= 6) { throw new IndexOutOfRangeException("classicSaveIndex out of range."); } // Open saves in parent path of Arena2 folder string path = SaveLoadManager.Instance.DaggerfallSavePath; SaveGames saveGames = new SaveGames(path); if (!saveGames.IsPathOpen) { throw new Exception(string.Format("Could not open Daggerfall saves path {0}", path)); } // Open save index if (!saveGames.TryOpenSave(classicSaveIndex)) { string error = string.Format("Could not open classic save index {0}.", classicSaveIndex); DaggerfallUI.MessageBox(error); DaggerfallUnity.LogMessage(string.Format(error), true); return; } // Get required save data SaveTree saveTree = saveGames.SaveTree; SaveVars saveVars = saveGames.SaveVars; if (NoWorld) { playerEnterExit.DisableAllParents(); } else { // Set player to world position playerEnterExit.EnableExteriorParent(); StreamingWorld streamingWorld = FindStreamingWorld(); int worldX = saveTree.Header.CharacterPosition.Position.WorldX; int worldZ = saveTree.Header.CharacterPosition.Position.WorldZ; streamingWorld.TeleportToWorldCoordinates(worldX, worldZ); streamingWorld.suppressWorld = false; } // Set game time DaggerfallUnity.Instance.WorldTime.Now.FromClassicDaggerfallTime(saveVars.GameTime); // Get character record List <SaveTreeBaseRecord> records = saveTree.FindRecords(RecordTypes.Character); if (records.Count != 1) { throw new Exception("SaveTree CharacterRecord not found."); } // Get prototypical character document data CharacterRecord characterRecord = (CharacterRecord)records[0]; characterDocument = characterRecord.ToCharacterDocument(); // Assign data to player entity PlayerEntity playerEntity = FindPlayerEntity(); playerEntity.AssignCharacter(characterDocument, characterRecord.ParsedData.level, characterRecord.ParsedData.startingHealth); // Assign items to player entity playerEntity.AssignItems(saveTree); // Assign gold pieces playerEntity.GoldPieces = (int)characterRecord.ParsedData.physicalGold; // Start game DaggerfallUI.Instance.PopToHUD(); GameManager.Instance.PauseGame(false); DaggerfallUI.Instance.FadeHUDFromBlack(); DaggerfallUI.PostMessage(PostStartMessage); if (OnStartGame != null) { OnStartGame(this, null); } }
// Start new character to location specified in INI void StartNewCharacter() { DaggerfallUnity.ResetUID(); RaiseOnNewGameEvent(); DaggerfallUI.Instance.PopToHUD(); ResetWeaponManager(); // Must have a character document if (characterDocument == null) { characterDocument = new CharacterDocument(); } // Assign character sheet PlayerEntity playerEntity = FindPlayerEntity(); playerEntity.AssignCharacter(characterDocument); // Set game time DaggerfallUnity.Instance.WorldTime.Now.SetClassicGameStartTime(); // Get start parameters DFPosition mapPixel = new DFPosition(DaggerfallUnity.Settings.StartCellX, DaggerfallUnity.Settings.StartCellY); bool startInDungeon = DaggerfallUnity.Settings.StartInDungeon; // Read location if any DFLocation location = new DFLocation(); ContentReader.MapSummary mapSummary; bool hasLocation = DaggerfallUnity.Instance.ContentReader.HasLocation(mapPixel.X, mapPixel.Y, out mapSummary); if (hasLocation) { if (!DaggerfallUnity.Instance.ContentReader.GetLocation(mapSummary.RegionIndex, mapSummary.MapIndex, out location)) { hasLocation = false; } } if (NoWorld) { playerEnterExit.DisableAllParents(); } else { // Start at specified location StreamingWorld streamingWorld = FindStreamingWorld(); if (hasLocation && startInDungeon && location.HasDungeon) { if (streamingWorld) { streamingWorld.TeleportToCoordinates(mapPixel.X, mapPixel.Y); streamingWorld.suppressWorld = true; } playerEnterExit.EnableDungeonParent(); playerEnterExit.StartDungeonInterior(location); } else { playerEnterExit.EnableExteriorParent(); if (streamingWorld) { streamingWorld.SetAutoReposition(StreamingWorld.RepositionMethods.Origin, Vector3.zero); streamingWorld.suppressWorld = false; } } } // Assign starting gear to player entity DaggerfallUnity.Instance.ItemHelper.AssignStartingGear(playerEntity); // Start game GameManager.Instance.PauseGame(false); DaggerfallUI.Instance.FadeHUDFromBlack(); DaggerfallUI.PostMessage(PostStartMessage); if (OnStartGame != null) { OnStartGame(this, null); } }
void Start() { if (!player) player = GameObject.FindGameObjectWithTag("Player"); if (!StreamingWorld) StreamingWorld = GameObject.Find("StreamingWorld").GetComponent<StreamingWorld>(); }
private void UpdateMode(TransportModes transportMode) { // Update the transport mode and stop any riding sounds playing. mode = transportMode; if (ridingAudioSource.isPlaying) { ridingAudioSource.Stop(); } if (mode == TransportModes.Horse || mode == TransportModes.Cart) { // Tell player motor we're riding. playerMotor.IsRiding = true; // Setup appropriate riding sounds. SoundClips sound = (mode == TransportModes.Horse) ? horseRidingSound2 : cartRidingSound; ridingAudioSource.clip = dfAudioSource.GetAudioClip((int)sound); // Setup appropriate riding textures. string textureName = (mode == TransportModes.Horse) ? horseTextureName : cartTextureName; for (int i = 0; i < 4; i++) { ridingTexures[i] = ImageReader.GetImageData(textureName, 0, i, true, true); } ridingTexture = ridingTexures[0]; // Initialise neighing timer. neighTime = Time.time + Random.Range(1, 5); } else { // Tell player motor we're not riding. playerMotor.IsRiding = false; } if (mode == TransportModes.Ship) { GameManager.Instance.PlayerMotor.CancelMovement = true; SerializablePlayer serializablePlayer = GetComponent <SerializablePlayer>(); DaggerfallUI.Instance.FadeBehaviour.SmashHUDToBlack(); StreamingWorld world = GameManager.Instance.StreamingWorld; DFPosition shipCoords = DaggerfallBankManager.GetShipCoords(); // Is there recorded position before boarding and is player on the ship? if (IsOnShip()) { // Check for terrain sampler changes. (so don't fall through floor) StreamingWorld.RepositionMethods reposition = StreamingWorld.RepositionMethods.None; if (boardShipPosition.terrainSamplerName != DaggerfallUnity.Instance.TerrainSampler.ToString() || boardShipPosition.terrainSamplerVersion != DaggerfallUnity.Instance.TerrainSampler.Version) { reposition = StreamingWorld.RepositionMethods.RandomStartMarker; if (DaggerfallUI.Instance.DaggerfallHUD != null) { DaggerfallUI.Instance.DaggerfallHUD.PopupText.AddText("Terrain sampler changed. Repositioning player."); } } // Restore player position from before boarding ship, caching ship scene first. SaveLoadManager.CacheScene(world.SceneName); // TODO: Should this should move into teleport to support other teleports? Issue only if inside. (e.g. recall) DFPosition mapPixel = MapsFile.WorldCoordToMapPixel(boardShipPosition.worldPosX, boardShipPosition.worldPosZ); world.TeleportToCoordinates(mapPixel.X, mapPixel.Y, reposition); serializablePlayer.RestorePosition(boardShipPosition); boardShipPosition = null; // Restore cached scene (ship is special case, cache will not be cleared) SaveLoadManager.RestoreCachedScene(world.SceneName); } else { // Record current player position before boarding ship, and cache scene. (ship is special case, cache will not be cleared) boardShipPosition = serializablePlayer.GetPlayerPositionData(); SaveLoadManager.CacheScene(world.SceneName); // Teleport to the players ship, restoring cached scene. world.TeleportToCoordinates(shipCoords.X, shipCoords.Y, StreamingWorld.RepositionMethods.RandomStartMarker); SaveLoadManager.RestoreCachedScene(world.SceneName); } DaggerfallUI.Instance.FadeBehaviour.FadeHUDFromBlack(); mode = TransportModes.Foot; } }
void StartFromClassicSave() { DaggerfallUnity.ResetUID(); QuestMachine.Instance.ClearState(); RaiseOnNewGameEvent(); ResetWeaponManager(); // Save index must be in range if (classicSaveIndex < 0 || classicSaveIndex >= 6) { throw new IndexOutOfRangeException("classicSaveIndex out of range."); } // Open saves in parent path of Arena2 folder string path = SaveLoadManager.Instance.DaggerfallSavePath; SaveGames saveGames = new SaveGames(path); if (!saveGames.IsPathOpen) { throw new Exception(string.Format("Could not open Daggerfall saves path {0}", path)); } // Open save index if (!saveGames.TryOpenSave(classicSaveIndex)) { string error = string.Format("Could not open classic save index {0}.", classicSaveIndex); DaggerfallUI.MessageBox(error); DaggerfallUnity.LogMessage(string.Format(error), true); return; } // Get required save data SaveTree saveTree = saveGames.SaveTree; SaveVars saveVars = saveGames.SaveVars; SaveTreeBaseRecord positionRecord = saveTree.FindRecord(RecordTypes.CharacterPositionRecord); if (NoWorld) { playerEnterExit.DisableAllParents(); } else { // Set player to world position playerEnterExit.EnableExteriorParent(); StreamingWorld streamingWorld = FindStreamingWorld(); int worldX = positionRecord.RecordRoot.Position.WorldX; int worldZ = positionRecord.RecordRoot.Position.WorldZ; streamingWorld.TeleportToWorldCoordinates(worldX, worldZ); streamingWorld.suppressWorld = false; } GameObject cameraObject = GameObject.FindGameObjectWithTag("MainCamera"); PlayerMouseLook mouseLook = cameraObject.GetComponent <PlayerMouseLook>(); if (mouseLook) { // Classic save value ranges from -256 (looking up) to 256 (looking down). // The maximum up and down range of view in classic is similar to 45 degrees up and down in DF Unity. float pitch = positionRecord.RecordRoot.Pitch; if (pitch != 0) { pitch = (pitch * 45 / 256); } mouseLook.Pitch = pitch; float yaw = positionRecord.RecordRoot.Yaw; // In classic saves 2048 units of yaw is 360 degrees. if (yaw != 0) { yaw = (yaw * 360 / 2048); } mouseLook.Yaw = yaw; } // Set whether the player's weapon is drawn GameManager.Instance.WeaponManager.Sheathed = (!saveVars.WeaponDrawn); // Set game time DaggerfallUnity.Instance.WorldTime.Now.FromClassicDaggerfallTime(saveVars.GameTime); // Get character record List <SaveTreeBaseRecord> records = saveTree.FindRecords(RecordTypes.Character); if (records.Count != 1) { throw new Exception("SaveTree CharacterRecord not found."); } // Get prototypical character document data CharacterRecord characterRecord = (CharacterRecord)records[0]; characterDocument = characterRecord.ToCharacterDocument(); // Assign data to player entity PlayerEntity playerEntity = FindPlayerEntity(); playerEntity.AssignCharacter(characterDocument, characterRecord.ParsedData.level, characterRecord.ParsedData.maxHealth, false); // Assign biography modifiers playerEntity.BiographyResistDiseaseMod = saveVars.BiographyResistDiseaseMod; playerEntity.BiographyResistMagicMod = saveVars.BiographyResistMagicMod; playerEntity.BiographyAvoidHitMod = saveVars.BiographyAvoidHitMod; playerEntity.BiographyResistPoisonMod = saveVars.BiographyResistPoisonMod; playerEntity.BiographyFatigueMod = saveVars.BiographyFatigueMod; // Assign faction data playerEntity.FactionData.ImportClassicReputation(saveVars); // Assign global variables playerEntity.GlobalVars.ImportClassicGlobalVars(saveVars); // Set time of last check for raising skills playerEntity.TimeOfLastSkillIncreaseCheck = saveVars.LastSkillCheckTime; // Assign items to player entity playerEntity.AssignItems(saveTree); // Assign gold pieces playerEntity.GoldPieces = (int)characterRecord.ParsedData.physicalGold; // GodMode setting playerEntity.GodMode = saveVars.GodMode; // Setup bank accounts var bankRecords = saveTree.FindRecord(RecordTypes.BankAccount); Banking.DaggerfallBankManager.ReadNativeBankData(bankRecords); // Get regional data. playerEntity.RegionData = saveVars.RegionData; // Set time tracked by playerEntity for game minute-based updates playerEntity.LastGameMinutes = saveVars.GameTime; // Start game DaggerfallUI.Instance.PopToHUD(); GameManager.Instance.PauseGame(false); DaggerfallUI.Instance.FadeHUDFromBlack(); DaggerfallUI.PostMessage(PostStartMessage); lastStartMethod = StartMethods.LoadClassicSave; SaveIndex = -1; if (OnStartGame != null) { OnStartGame(this, null); } }
void Awake() { dfUnity = DaggerfallUnity.Instance; playerGPS = GetComponent <PlayerGPS>(); world = FindObjectOfType <StreamingWorld>(); }
void Update() { GameObject goPlayerAdvanced = GameObject.Find("PlayerAdvanced"); PlayerGPS playerGPS = GameObject.Find("PlayerAdvanced").GetComponent <PlayerGPS>(); if (!playerGPS) { return; } //if (GameManager.Instance.IsPlayerInside) if (GameManager.Instance.IsPlayerInsideBuilding) { RaycastHit hit; float distanceToGround = 0; if (Physics.Raycast(goPlayerAdvanced.transform.position, -Vector3.up, out hit, 100.0F)) { distanceToGround = hit.distance; } // additional checks in distance of player/character controller in all directions - important so that reflections don't disappear too early, e.g attics near ladder float radius = GameManager.Instance.PlayerController.radius; float distanceToGroundNorth = 0, distanceToGroundSouth = 0, distanceToGroundWest = 0, distanceToGroundEast = 0; if (Physics.Raycast(goPlayerAdvanced.transform.position + new Vector3(0.0f, 0.0f, -radius), -Vector3.up, out hit, 100.0F)) { distanceToGroundNorth = hit.distance; } if (Physics.Raycast(goPlayerAdvanced.transform.position + new Vector3(0.0f, 0.0f, radius), -Vector3.up, out hit, 100.0F)) { distanceToGroundSouth = hit.distance; } if (Physics.Raycast(goPlayerAdvanced.transform.position + new Vector3(-radius, 0.0f, 0.0f), -Vector3.up, out hit, 100.0F)) { distanceToGroundWest = hit.distance; } if (Physics.Raycast(goPlayerAdvanced.transform.position + new Vector3(radius, 0.0f, 0.0f), -Vector3.up, out hit, 100.0F)) { distanceToGroundEast = hit.distance; } distanceToGround = Mathf.Min(distanceToGround, Mathf.Min(distanceToGroundNorth, Mathf.Min(distanceToGroundSouth, Mathf.Min(distanceToGroundWest, distanceToGroundEast)))); reflectionPlaneGround.transform.position = goPlayerAdvanced.transform.position - new Vector3(0.0f, distanceToGround, 0.0f); //new Vector3(0.0f, GameManager.Instance.PlayerController.height * 0.5f, 0.0f); float distanceLevelBelow = getDistanceToLowerLevel(goPlayerAdvanced); //Debug.Log(string.Format("distance to lower level: {0}", distanceLevelBelow)); reflectionPlaneLowerLevel.transform.position = goPlayerAdvanced.transform.position - new Vector3(0.0f, distanceLevelBelow, 0.0f); } else if (GameManager.Instance.IsPlayerInsideDungeon || GameManager.Instance.IsPlayerInsideCastle) { RaycastHit hit; float distanceToGround = 0; if (Physics.Raycast(goPlayerAdvanced.transform.position, -Vector3.up, out hit, 100.0F)) { distanceToGround = hit.distance; } reflectionPlaneGround.transform.position = goPlayerAdvanced.transform.position - new Vector3(0.0f, distanceToGround, 0.0f); //new Vector3(0.0f, GameManager.Instance.PlayerController.height * 0.5f, 0.0f); //Debug.Log(string.Format("distance to lower level: {0}", distanceLevelBelow)); Vector3 pos = goPlayerAdvanced.transform.position; reflectionPlaneLowerLevel.transform.position = new Vector3(pos.x, GameManager.Instance.PlayerEnterExit.blockWaterLevel * -1 * MeshReader.GlobalScale, pos.z); //// prevent underwater reflections below water level //if (reflectionPlaneGround.transform.position.y < reflectionPlaneLowerLevel.transform.position.y) //{ // reflectionPlaneGround.transform.position = reflectionPlaneLowerLevel.transform.position; //} } else //if (!GameManager.Instance.IsPlayerInside) { Terrain terrainInstancePlayerTerrain = null; int referenceLocationX = playerGPS.CurrentMapPixel.X; int referenceLocationY = playerGPS.CurrentMapPixel.Y; ContentReader.MapSummary mapSummary; // if there is no location at current player position... if (!DaggerfallUnity.Instance.ContentReader.HasLocation(referenceLocationX, referenceLocationY, out mapSummary)) { // search for largest location in local 8-neighborhood and take this as reference location for location reflection plane int maxLocationArea = -1; for (int y = -1; y <= +1; y++) { for (int x = -1; x <= +1; x++) { if (DaggerfallUnity.Instance.ContentReader.HasLocation(playerGPS.CurrentMapPixel.X + x, playerGPS.CurrentMapPixel.Y + y, out mapSummary)) { DFLocation location = DaggerfallUnity.Instance.ContentReader.MapFileReader.GetLocation(mapSummary.RegionIndex, mapSummary.MapIndex); byte locationRangeX = location.Exterior.ExteriorData.Width; byte locationRangeY = location.Exterior.ExteriorData.Height; int locationArea = locationRangeX * locationRangeY; if (locationArea > maxLocationArea) { referenceLocationX = playerGPS.CurrentMapPixel.X + x; referenceLocationY = playerGPS.CurrentMapPixel.Y + y; maxLocationArea = locationArea; } } } } } GameObject go = GameObject.Find("StreamingTarget"); if (go == null) { return; } foreach (Transform child in go.transform) { DaggerfallTerrain dfTerrain = child.GetComponent <DaggerfallTerrain>(); if (!dfTerrain) { continue; } if ((dfTerrain.MapPixelX != referenceLocationX) || (dfTerrain.MapPixelY != referenceLocationY)) { continue; } Terrain terrainInstance = child.GetComponent <Terrain>(); terrainInstancePlayerTerrain = terrainInstance; if ((terrainInstance) && (terrainInstance.terrainData)) { float scale = terrainInstance.terrainData.heightmapScale.x; float xSamplePos = DaggerfallUnity.Instance.TerrainSampler.HeightmapDimension * 0.55f; float ySamplePos = DaggerfallUnity.Instance.TerrainSampler.HeightmapDimension * 0.55f; Vector3 pos = new Vector3(xSamplePos * scale, 0, ySamplePos * scale); float height = terrainInstance.SampleHeight(pos + terrainInstance.transform.position); float positionY = height + terrainInstance.transform.position.y; reflectionPlaneGround.transform.position = new Vector3(goPlayerAdvanced.transform.position.x + terrainInstance.transform.position.x, positionY, goPlayerAdvanced.transform.position.z + terrainInstance.transform.position.z); } } if (!terrainInstancePlayerTerrain) { return; } //Debug.Log(string.Format("playerGPS: {0}, plane: {1}", goPlayerAdvanced.transform.position.y, reflectionPlaneGround.transform.position.y)); if (playerGPS.transform.position.y < reflectionPlaneGround.transform.position.y) { RaycastHit hit; float distanceToGround = 0; if (Physics.Raycast(goPlayerAdvanced.transform.position, -Vector3.up, out hit, 100.0F)) { distanceToGround = hit.distance; } //Debug.Log(string.Format("distance to ground: {0}", distanceToGround)); reflectionPlaneGround.transform.position = goPlayerAdvanced.transform.position - new Vector3(0.0f, distanceToGround, 0.0f); } StreamingWorld streamingWorld = GameObject.Find("StreamingWorld").GetComponent <StreamingWorld>(); Vector3 vecWaterHeight = new Vector3(0.0f, (DaggerfallUnity.Instance.TerrainSampler.OceanElevation + 0.0f) * streamingWorld.TerrainScale, 0.0f); // water height level on y-axis (+1.0f some coastlines are incorrect otherwise) Vector3 vecWaterHeightTransformed = terrainInstancePlayerTerrain.transform.TransformPoint(vecWaterHeight); // transform to world coordinates //Debug.Log(string.Format("x,y,z: {0}, {1}, {2}", vecWaterHeight.x, vecWaterHeight.y, vecWaterHeight.z)); //Debug.Log(string.Format("transformed x,y,z: {0}, {1}, {2}", vecWaterHeightTransformed.x, vecWaterHeightTransformed.y, vecWaterHeightTransformed.z)); reflectionPlaneLowerLevel.transform.position = new Vector3(goPlayerAdvanced.transform.position.x, vecWaterHeightTransformed.y, goPlayerAdvanced.transform.position.z); } if (GameManager.Instance.IsPlayerInsideBuilding && playerEnvironment != PlayerEnvironment.Building) { UpdateBackgroundSettingsIndoor(); } else if ((GameManager.Instance.IsPlayerInsideCastle || GameManager.Instance.IsPlayerInsideDungeon) && playerEnvironment != PlayerEnvironment.DungeonOrCastle) { UpdateBackgroundSettingsIndoor(); } else if (!GameManager.Instance.IsPlayerInside && playerEnvironment != PlayerEnvironment.Outdoors) { UpdateBackgroundSettingsOutdoor(); } }
StreamingWorld FindStreamingWorld() { streamingWorld = GameObject.FindObjectOfType<StreamingWorld>(); if (!streamingWorld) throw new Exception("StreamingWorld not found."); return streamingWorld; }
void StartFromClassicSave() { DaggerfallUnity.ResetUID(); QuestMachine.Instance.ClearState(); RaiseOnNewGameEvent(); ResetWeaponManager(); // Save index must be in range if (classicSaveIndex < 0 || classicSaveIndex >= 6) { throw new IndexOutOfRangeException("classicSaveIndex out of range."); } // Open saves in parent path of Arena2 folder string path = SaveLoadManager.Instance.DaggerfallSavePath; SaveGames saveGames = new SaveGames(path); if (!saveGames.IsPathOpen) { throw new Exception(string.Format("Could not open Daggerfall saves path {0}", path)); } // Open save index if (!saveGames.TryOpenSave(classicSaveIndex)) { string error = string.Format("Could not open classic save index {0}.", classicSaveIndex); DaggerfallUI.MessageBox(error); DaggerfallUnity.LogMessage(string.Format(error), true); return; } // Get required save data SaveTree saveTree = saveGames.SaveTree; SaveVars saveVars = saveGames.SaveVars; SaveTreeBaseRecord positionRecord = saveTree.FindRecord(RecordTypes.CharacterPositionRecord); if (NoWorld) { playerEnterExit.DisableAllParents(); } else { // Set player to world position playerEnterExit.EnableExteriorParent(); StreamingWorld streamingWorld = FindStreamingWorld(); int worldX = positionRecord.RecordRoot.Position.WorldX; int worldZ = positionRecord.RecordRoot.Position.WorldZ; streamingWorld.TeleportToWorldCoordinates(worldX, worldZ); streamingWorld.suppressWorld = false; } GameObject cameraObject = GameObject.FindGameObjectWithTag("MainCamera"); PlayerMouseLook mouseLook = cameraObject.GetComponent <PlayerMouseLook>(); if (mouseLook) { // Classic save value ranges from -256 (looking up) to 256 (looking down). // The maximum up and down range of view in classic is similar to 45 degrees up and down in DF Unity. float pitch = positionRecord.RecordRoot.Pitch; if (pitch != 0) { pitch = (pitch * 45 / 256); } mouseLook.Pitch = pitch; float yaw = positionRecord.RecordRoot.Yaw; // In classic saves 2048 units of yaw is 360 degrees. if (yaw != 0) { yaw = (yaw * 360 / 2048); } mouseLook.Yaw = yaw; } // Set whether the player's weapon is drawn WeaponManager weaponManager = GameManager.Instance.WeaponManager; weaponManager.Sheathed = (!saveVars.WeaponDrawn); // Set game time DaggerfallUnity.Instance.WorldTime.Now.FromClassicDaggerfallTime(saveVars.GameTime); // Get character record List <SaveTreeBaseRecord> records = saveTree.FindRecords(RecordTypes.Character); if (records.Count != 1) { throw new Exception("SaveTree CharacterRecord not found."); } // Get prototypical character document data CharacterRecord characterRecord = (CharacterRecord)records[0]; characterDocument = characterRecord.ToCharacterDocument(); // Assign data to player entity PlayerEntity playerEntity = FindPlayerEntity(); playerEntity.AssignCharacter(characterDocument, characterRecord.ParsedData.level, characterRecord.ParsedData.maxHealth, false); // Assign biography modifiers playerEntity.BiographyResistDiseaseMod = saveVars.BiographyResistDiseaseMod; playerEntity.BiographyResistMagicMod = saveVars.BiographyResistMagicMod; playerEntity.BiographyAvoidHitMod = saveVars.BiographyAvoidHitMod; playerEntity.BiographyResistPoisonMod = saveVars.BiographyResistPoisonMod; playerEntity.BiographyFatigueMod = saveVars.BiographyFatigueMod; // Assign faction data playerEntity.FactionData.ImportClassicReputation(saveVars); // Assign global variables playerEntity.GlobalVars.ImportClassicGlobalVars(saveVars); // Set time of last check for raising skills playerEntity.TimeOfLastSkillIncreaseCheck = saveVars.LastSkillCheckTime; // Assign items to player entity playerEntity.AssignItems(saveTree); // Assign guild memberships playerEntity.AssignGuildMemberships(saveTree); // Assign diseases and poisons to player entity playerEntity.AssignDiseasesAndPoisons(saveTree); // Assign gold pieces playerEntity.GoldPieces = (int)characterRecord.ParsedData.physicalGold; // Assign weapon hand being used weaponManager.UsingRightHand = !saveVars.UsingLeftHandWeapon; // GodMode setting playerEntity.GodMode = saveVars.GodMode; // Setup bank accounts var bankRecords = saveTree.FindRecord(RecordTypes.BankAccount); Banking.DaggerfallBankManager.ReadNativeBankData(bankRecords); // Get regional data. playerEntity.RegionData = saveVars.RegionData; // Set time tracked by playerEntity for game minute-based updates playerEntity.LastGameMinutes = saveVars.GameTime; // Get breath remaining if player was submerged (0 if they were not in the water) playerEntity.CurrentBreath = saveVars.BreathRemaining; // TODO: Import classic spellbook playerEntity.DeserializeSpellbook(null); // Get last type of crime committed playerEntity.CrimeCommitted = (PlayerEntity.Crimes)saveVars.CrimeCommitted; // Get weather byte[] climateWeathers = saveVars.ClimateWeathers; // Enums for thunder and snow are reversed in classic and Unity, so they are converted here. for (int i = 0; i < climateWeathers.Length; i++) { // TODO: 0x80 flag can be set for snow or rain, to add fog to these weathers. This isn't in DF Unity yet, so // temporarily removing the flag. climateWeathers[i] &= 0x7f; if (climateWeathers[i] == 5) { climateWeathers[i] = 6; } else if (climateWeathers[i] == 6) { climateWeathers[i] = 5; } } GameManager.Instance.WeatherManager.PlayerWeather.ClimateWeathers = climateWeathers; // Load character biography text playerEntity.BackStory = saveGames.BioFile.Lines; // Validate spellbook item DaggerfallUnity.Instance.ItemHelper.ValidateSpellbookItem(playerEntity); // Start game DaggerfallUI.Instance.PopToHUD(); GameManager.Instance.PauseGame(false); DaggerfallUI.Instance.FadeBehaviour.FadeHUDFromBlack(); DaggerfallUI.PostMessage(PostStartMessage); lastStartMethod = StartMethods.LoadClassicSave; SaveIndex = -1; if (OnStartGame != null) { OnStartGame(this, null); } }
// Start new character to location specified in INI void StartNewCharacter() { DaggerfallUnity.ResetUID(); QuestMachine.Instance.ClearState(); RaiseOnNewGameEvent(); DaggerfallUI.Instance.PopToHUD(); ResetWeaponManager(); SaveLoadManager.ClearSceneCache(true); GameManager.Instance.GuildManager.ClearMembershipData(); // Must have a character document if (characterDocument == null) { characterDocument = new CharacterDocument(); } // Assign character sheet PlayerEntity playerEntity = FindPlayerEntity(); playerEntity.AssignCharacter(characterDocument); // Set game time DaggerfallUnity.Instance.WorldTime.Now.SetClassicGameStartTime(); // Set time tracked in playerEntity playerEntity.LastGameMinutes = DaggerfallUnity.Instance.WorldTime.DaggerfallDateTime.ToClassicDaggerfallTime(); // Get start parameters DFPosition mapPixel = new DFPosition(DaggerfallUnity.Settings.StartCellX, DaggerfallUnity.Settings.StartCellY); bool startInDungeon = DaggerfallUnity.Settings.StartInDungeon; // Read location if any DFLocation location = new DFLocation(); ContentReader.MapSummary mapSummary; bool hasLocation = DaggerfallUnity.Instance.ContentReader.HasLocation(mapPixel.X, mapPixel.Y, out mapSummary); if (hasLocation) { if (!DaggerfallUnity.Instance.ContentReader.GetLocation(mapSummary.RegionIndex, mapSummary.MapIndex, out location)) { hasLocation = false; } } if (NoWorld) { playerEnterExit.DisableAllParents(); } else { // Start at specified location StreamingWorld streamingWorld = FindStreamingWorld(); if (hasLocation && startInDungeon && location.HasDungeon) { if (streamingWorld) { streamingWorld.TeleportToCoordinates(mapPixel.X, mapPixel.Y); streamingWorld.suppressWorld = true; } playerEnterExit.EnableDungeonParent(); playerEnterExit.StartDungeonInterior(location); } else { playerEnterExit.EnableExteriorParent(); if (streamingWorld) { streamingWorld.SetAutoReposition(StreamingWorld.RepositionMethods.Origin, Vector3.zero); streamingWorld.suppressWorld = false; } } } // Assign starting gear to player entity DaggerfallUnity.Instance.ItemHelper.AssignStartingGear(playerEntity, characterDocument.classIndex, characterDocument.isCustom); // Assign starting spells to player entity SetStartingSpells(playerEntity); // Apply biography effects to player entity BiogFile.ApplyEffects(characterDocument.biographyEffects, playerEntity); // Setup bank accounts and houses Banking.DaggerfallBankManager.SetupAccounts(); Banking.DaggerfallBankManager.SetupHouses(); // Initialize region data playerEntity.InitializeRegionData(); // Randomize weathers GameManager.Instance.WeatherManager.SetClimateWeathers(); // Start game GameManager.Instance.PauseGame(false); DaggerfallUI.Instance.FadeBehaviour.FadeHUDFromBlack(); DaggerfallUI.PostMessage(PostStartMessage); lastStartMethod = StartMethods.NewCharacter; // Offer main quest during pre-alpha QuestMachine.Instance.InstantiateQuest("__MQSTAGE00"); // Launch startup optional quest if (!string.IsNullOrEmpty(LaunchQuest)) { QuestMachine.Instance.InstantiateQuest(LaunchQuest); LaunchQuest = string.Empty; } // Launch any InitAtGameStart quests GameManager.Instance.QuestListsManager.InitAtGameStartQuests(); if (OnStartGame != null) { OnStartGame(this, null); } }
void Awake() { dfUnity = DaggerfallUnity.Instance; //mainCamera = GameObject.FindGameObjectWithTag("MainCamera"); //playerMouseLook = GetComponent<PlayerMouseLook>(); playerGPS = GetComponent<PlayerGPS>(); world = FindObjectOfType<StreamingWorld>(); }
void Update() { if (!DaggerfallUnity.Settings.Nystul_RealtimeReflections) { return; } GameObject goPlayerAdvanced = GameObject.Find("PlayerAdvanced"); PlayerGPS playerGPS = GameObject.Find("PlayerAdvanced").GetComponent <PlayerGPS>(); if (!playerGPS) { return; } if (GameManager.Instance.IsPlayerInside) { RaycastHit hit; float distanceToGround = 0; if (Physics.Raycast(goPlayerAdvanced.transform.position, -Vector3.up, out hit, 100.0F)) { distanceToGround = hit.distance; } reflectionPlaneBottom.transform.position = goPlayerAdvanced.transform.position - new Vector3(0.0f, distanceToGround, 0.0f); float distanceLevelBelow = getDistanceToLowerLevel(goPlayerAdvanced); //Debug.Log(string.Format("distance to lower level: {0}", distanceLevelBelow)); reflectionPlaneSeaLevel.transform.position = goPlayerAdvanced.transform.position - new Vector3(0.0f, distanceLevelBelow, 0.0f); } else //if (!GameManager.Instance.IsPlayerInside) { Terrain terrainInstancePlayerTerrain = null; int referenceLocationX = playerGPS.CurrentMapPixel.X; int referenceLocationY = playerGPS.CurrentMapPixel.Y; ContentReader.MapSummary mapSummary; // if there is no location at current player position... if (!DaggerfallUnity.Instance.ContentReader.HasLocation(referenceLocationX, referenceLocationY, out mapSummary)) { // search for largest location in local 8-neighborhood and take this as reference location for location reflection plane int maxLocationArea = -1; for (int y = -1; y <= +1; y++) { for (int x = -1; x <= +1; x++) { if (DaggerfallUnity.Instance.ContentReader.HasLocation(playerGPS.CurrentMapPixel.X + x, playerGPS.CurrentMapPixel.Y + y, out mapSummary)) { DFLocation location = DaggerfallUnity.Instance.ContentReader.MapFileReader.GetLocation(mapSummary.RegionIndex, mapSummary.MapIndex); byte locationRangeX = location.Exterior.ExteriorData.Width; byte locationRangeY = location.Exterior.ExteriorData.Height; int locationArea = locationRangeX * locationRangeY; if (locationArea > maxLocationArea) { referenceLocationX = playerGPS.CurrentMapPixel.X + x; referenceLocationY = playerGPS.CurrentMapPixel.Y + y; maxLocationArea = locationArea; } } } } } GameObject go = GameObject.Find("StreamingTarget"); if (go == null) { return; } foreach (Transform child in go.transform) { DaggerfallTerrain dfTerrain = child.GetComponent <DaggerfallTerrain>(); if (!dfTerrain) { continue; } if ((dfTerrain.MapPixelX != referenceLocationX) || (dfTerrain.MapPixelY != referenceLocationY)) { continue; } Terrain terrainInstance = child.GetComponent <Terrain>(); terrainInstancePlayerTerrain = terrainInstance; if ((terrainInstance) && (terrainInstance.terrainData)) { float scale = terrainInstance.terrainData.heightmapScale.x; float xSamplePos = DaggerfallUnity.Instance.TerrainSampler.HeightmapDimension * 0.55f; float ySamplePos = DaggerfallUnity.Instance.TerrainSampler.HeightmapDimension * 0.55f; Vector3 pos = new Vector3(xSamplePos * scale, 0, ySamplePos * scale); float height = terrainInstance.SampleHeight(pos + terrainInstance.transform.position); float positionY = height + terrainInstance.transform.position.y; reflectionPlaneBottom.transform.position = new Vector3(goPlayerAdvanced.transform.position.x + terrainInstance.transform.position.x, positionY, goPlayerAdvanced.transform.position.z + terrainInstance.transform.position.z); } } if (!terrainInstancePlayerTerrain) { return; } //Debug.Log(string.Format("playerGPS: {0}, plane: {1}", goPlayerAdvanced.transform.position.y, reflectionPlaneBottom.transform.position.y)); if (playerGPS.transform.position.y < reflectionPlaneBottom.transform.position.y) { RaycastHit hit; float distanceToGround = 0; if (Physics.Raycast(goPlayerAdvanced.transform.position, -Vector3.up, out hit, 100.0F)) { distanceToGround = hit.distance; } //Debug.Log(string.Format("distance to ground: {0}", distanceToGround)); reflectionPlaneBottom.transform.position = goPlayerAdvanced.transform.position - new Vector3(0.0f, distanceToGround, 0.0f); } StreamingWorld streamingWorld = GameObject.Find("StreamingWorld").GetComponent <StreamingWorld>(); Vector3 vecWaterHeight = new Vector3(0.0f, (DaggerfallUnity.Instance.TerrainSampler.OceanElevation) * streamingWorld.TerrainScale, 0.0f); // water height level on y-axis (+1.0f some coastlines are incorrect otherwise) Vector3 vecWaterHeightTransformed = terrainInstancePlayerTerrain.transform.TransformPoint(vecWaterHeight); // transform to world coordinates //Debug.Log(string.Format("x,y,z: {0}, {1}, {2}", vecWaterHeight.x, vecWaterHeight.y, vecWaterHeight.z)); //Debug.Log(string.Format("transformed x,y,z: {0}, {1}, {2}", vecWaterHeightTransformed.x, vecWaterHeightTransformed.y, vecWaterHeightTransformed.z)); reflectionPlaneSeaLevel.transform.position = new Vector3(goPlayerAdvanced.transform.position.x, vecWaterHeightTransformed.y, goPlayerAdvanced.transform.position.z); } if (GameManager.Instance.IsPlayerInside && !playerInside) { playerInside = true; // player now inside mirrorRefl.CurrentBackgroundSettings = MirrorReflection.EnvironmentSetting.IndoorSetting; mirrorReflSeaLevel.CurrentBackgroundSettings = MirrorReflection.EnvironmentSetting.IndoorSetting; if (useDeferredReflections) { componentDefferedPlanarReflections.enabled = true; } } else if (!GameManager.Instance.IsPlayerInside && playerInside) { playerInside = false; // player now outside mirrorRefl.CurrentBackgroundSettings = MirrorReflection.EnvironmentSetting.OutdoorSetting; mirrorReflSeaLevel.CurrentBackgroundSettings = MirrorReflection.EnvironmentSetting.OutdoorSetting; if (useDeferredReflections) { componentDefferedPlanarReflections.enabled = false; } } }
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 }