/// <summary> /// Checks for replacement building data within a block. /// </summary> /// <param name="blockName">Block name</param> /// <param name="blockIndex">Block index</param> /// <param name="recordIndex">Record index of building within block</param> /// <param name="buildingData">BuildingReplacementData output</param> /// <returns>True if replacement data found, false otherwise</returns> public static bool GetBuildingReplacementData(string blockName, int blockIndex, int recordIndex, out BuildingReplacementData buildingData) { if (DaggerfallUnity.Settings.AssetInjection) { BlockRecordKey blockRecordKey = new BlockRecordKey() { blockIndex = blockIndex, recordIndex = recordIndex, variant = WorldDataVariants.NoVariant }; string variant = WorldDataVariants.GetBuildingVariant(ref blockRecordKey, blockName); if (buildings.ContainsKey(blockRecordKey)) { buildingData = buildings[blockRecordKey]; return(buildingData.BuildingType != noReplacementIndicator); } else { string fileName = GetBuildingReplacementFilename(blockName, blockIndex, recordIndex, variant); // Seek from loose files if (File.Exists(Path.Combine(worldDataPath, fileName))) { string buildingReplacementJson = File.ReadAllText(Path.Combine(worldDataPath, fileName)); buildingData = (BuildingReplacementData)SaveLoadManager.Deserialize(typeof(BuildingReplacementData), buildingReplacementJson); #if !UNITY_EDITOR // Cache building replacement data, unless running in editor buildings.Add(blockRecordKey, buildingData); #endif return(true); } // Seek from mods TextAsset buildingReplacementJsonAsset; if (ModManager.Instance != null && ModManager.Instance.TryGetAsset(fileName, false, out buildingReplacementJsonAsset)) { buildingData = (BuildingReplacementData)SaveLoadManager.Deserialize(typeof(BuildingReplacementData), buildingReplacementJsonAsset.text); #if !UNITY_EDITOR // Cache building replacement data, unless running in editor buildings.Add(blockRecordKey, buildingData); #endif return(true); } #if !UNITY_EDITOR // Only look for replacement data once, non variant. So only look for replaced buildings once (unless running in editor) if (variant == WorldDataVariants.NoVariant) { buildings.Add(blockRecordKey, noReplacementBuilding); } #endif } } buildingData = noReplacementBuilding; return(false); }
public static bool GetBuildingReplacementData(string blockName, int blockIndex, int recordIndex, out BuildingReplacementData buildingData) { if (DaggerfallUnity.Settings.MeshAndTextureReplacement) { BlockRecordId blockRecordId = new BlockRecordId() { blockIndex = blockIndex, recordIndex = recordIndex }; if (Buildings.ContainsKey(blockRecordId)) { buildingData = Buildings[blockRecordId]; return(buildingData.BuildingType != noReplacementBT); } else { string fileName = GetBuildingReplacementFilename(blockName, blockIndex, recordIndex); // Seek from loose files if (File.Exists(Path.Combine(worldDataPath, fileName))) { string buildingReplacementJson = File.ReadAllText(Path.Combine(worldDataPath, fileName)); buildingData = (BuildingReplacementData)SaveLoadManager.Deserialize(typeof(BuildingReplacementData), buildingReplacementJson); #if !UNITY_EDITOR // Cache building replacement data, unless running in editor Buildings.Add(blockRecordId, buildingData); #endif return(true); } // Seek from mods TextAsset buildingReplacementJsonAsset; if (ModManager.Instance != null && ModManager.Instance.TryGetAsset(fileName, false, out buildingReplacementJsonAsset)) { buildingData = (BuildingReplacementData)SaveLoadManager.Deserialize(typeof(BuildingReplacementData), buildingReplacementJsonAsset.text); #if !UNITY_EDITOR // Cache building replacement data, unless running in editor Buildings.Add(blockRecordId, buildingData); #endif return(true); } #if !UNITY_EDITOR // Only look for replacement data once, unless running in editor Buildings.Add(blockRecordId, noReplacementData); #endif } } buildingData = noReplacementData; return(false); }