/// <summary> /// Parse the Value from a string /// </summary> public void SetFromString(String s) { // Should we use OnDemand? Boolean useOnDemand = OnDemandStorage.useOnDemand; if (s.StartsWith("BUILTIN/")) { s = s.Substring(8); Value = Utility.FindMapSO <T>(s); } else { // check if OnDemand. if (useOnDemand) { if (Utility.TextureExists(s)) { String mapName = s; mapName = mapName.Substring(s.LastIndexOf('/') + 1); Int32 lastDot = mapName.LastIndexOf('.'); if (lastDot > 0) { mapName = mapName.Substring(0, lastDot); } if (typeof(T) == typeof(CBAttributeMapSO)) { CBAttributeMapSODemand valCB = ScriptableObject.CreateInstance <CBAttributeMapSODemand>(); valCB.Path = s; valCB.Depth = MapSO.MapDepth.RGB; valCB.name = mapName + " (CBRGB) for " + generatedBody.name; valCB.AutoLoad = OnDemandStorage.onDemandLoadOnMissing; OnDemandStorage.AddMap(generatedBody.name, valCB); Value = valCB as T; } else { OnDemand.MapSODemand valMap = ScriptableObject.CreateInstance <MapSODemand>(); valMap.Path = s; valMap.Depth = MapSO.MapDepth.RGB; valMap.name = mapName + " (RGB) for " + generatedBody.name; valMap.AutoLoad = OnDemandStorage.onDemandLoadOnMissing; OnDemandStorage.AddMap(generatedBody.name, valMap); Value = valMap as T; } } } else { // Load the texture Texture2D map = Utility.LoadTexture(s, false, false, false); if (map != null) { // Create a new map script object Value = ScriptableObject.CreateInstance <T>(); Value.CreateMap(MapSO.MapDepth.RGB, map); UnityEngine.Object.DestroyImmediate(map); } } } }
// Load the MapSO public void SetFromString(string s) { // Should we use OnDemand? bool useOnDemand = OnDemandStorage.useOnDemand; if (s.StartsWith("BUILTIN/")) { value = Utility.FindMapSO <T>(s); } else { // are we on-demand? Don't load now. if (useOnDemand) { if (Utility.TextureExists(s)) { string mapName = s; mapName = mapName.Substring(s.LastIndexOf('/') + 1); int lastDot = mapName.LastIndexOf('.'); if (lastDot > 0) { mapName = mapName.Substring(0, lastDot); } if (typeof(T) == typeof(CBAttributeMapSO)) { CBAttributeMapSODemand valCB = ScriptableObject.CreateInstance <CBAttributeMapSODemand>(); valCB.Path = s; valCB.Depth = MapSO.MapDepth.Greyscale; valCB.name = mapName + " (CBG) for " + generatedBody.name; valCB.AutoLoad = OnDemandStorage.onDemandLoadOnMissing; OnDemandStorage.AddMap(generatedBody.name, valCB); value = valCB as T; } else { MapSODemand valMap = ScriptableObject.CreateInstance <MapSODemand>(); valMap.Path = s; valMap.Depth = MapSO.MapDepth.Greyscale; valMap.name = mapName + " (G) for " + generatedBody.name; valMap.AutoLoad = OnDemandStorage.onDemandLoadOnMissing; OnDemandStorage.AddMap(generatedBody.name, valMap); value = valMap as T; } } } else // Load the texture { Texture2D map = Utility.LoadTexture(s, false, false, false); if (map != null) { // Create a new map script object value = ScriptableObject.CreateInstance <T>(); value.CreateMap(MapSO.MapDepth.Greyscale, map); UnityEngine.Object.DestroyImmediate(map); } } } value.name = s; }
/// <summary> /// Parse the Value from a string /// </summary> public void SetFromString(String s) { // Should we use OnDemand? Boolean useOnDemand = OnDemandStorage.UseOnDemand; Boolean useOnDemandBiomes = OnDemandStorage.UseOnDemandBiomes; if (s.StartsWith("BUILTIN/")) { s = s.Substring(8); Value = Utility.FindMapSO <T>(s); } else { // check if OnDemand. if (useOnDemand && typeof(T) == typeof(MapSO) || useOnDemandBiomes && typeof(T) == typeof(CBAttributeMapSO)) { if (!Utility.TextureExists(s)) { return; } if (typeof(T) == typeof(CBAttributeMapSO)) { CBAttributeMapSODemand cbMap = ScriptableObject.CreateInstance <CBAttributeMapSODemand>(); cbMap.Path = s; cbMap.Depth = MapSO.MapDepth.RGB; cbMap.AutoLoad = OnDemandStorage.OnDemandLoadOnMissing; OnDemandStorage.AddMap(generatedBody.name, cbMap); Value = cbMap as T; } else { MapSODemand map = ScriptableObject.CreateInstance <MapSODemand>(); map.Path = s; map.Depth = MapSO.MapDepth.RGB; map.AutoLoad = OnDemandStorage.OnDemandLoadOnMissing; OnDemandStorage.AddMap(generatedBody.name, map); Value = map as T; } } else { // Load the texture Texture2D map = Utility.LoadTexture(s, false, false, false); if (map == null) { return; } // Create a new map script object Value = ScriptableObject.CreateInstance <T>(); Value.CreateMap(MapSO.MapDepth.RGB, map); Object.DestroyImmediate(map); } } if (Value != null) { Value.name = s; } }
/// <summary> /// Parse the Value from a string /// </summary> public void SetFromString(String s) { // Should we use OnDemand? Boolean useOnDemand = OnDemandStorage.UseOnDemand; Boolean useOnDemandBiomes = OnDemandStorage.UseOnDemandBiomes; if (s.StartsWith("BUILTIN/")) { s = s.Substring(8); Value = Utility.FindMapSO <T>(s); } else { // are we on-demand? Don't load now. if (useOnDemand && typeof(T) == typeof(MapSO) || useOnDemandBiomes && typeof(T) == typeof(CBAttributeMapSO)) { if (!Utility.TextureExists(s)) { return; } String mapName = s; mapName = mapName.Substring(s.LastIndexOf('/') + 1); Int32 lastDot = mapName.LastIndexOf('.'); if (lastDot > 0) { mapName = mapName.Substring(0, lastDot); } if (typeof(T) == typeof(CBAttributeMapSO)) { CBAttributeMapSODemand cbMap = ScriptableObject.CreateInstance <CBAttributeMapSODemand>(); cbMap.Path = s; cbMap.Depth = MapSO.MapDepth.Greyscale; cbMap.name = mapName + " (CBG) for " + generatedBody.name; cbMap.AutoLoad = OnDemandStorage.OnDemandLoadOnMissing; OnDemandStorage.AddMap(generatedBody.name, cbMap); Value = cbMap as T; } else { MapSODemand map = ScriptableObject.CreateInstance <MapSODemand>(); map.Path = s; map.Depth = MapSO.MapDepth.Greyscale; map.name = mapName + " (G) for " + generatedBody.name; map.AutoLoad = OnDemandStorage.OnDemandLoadOnMissing; OnDemandStorage.AddMap(generatedBody.name, map); Value = map as T; } } else // Load the texture { Texture2D map = OnDemandStorage.LoadTexture(s, false, false, false); if (map == null) { return; } // Create a new map script object Value = ScriptableObject.CreateInstance <T>(); Value.CreateMap(MapSO.MapDepth.Greyscale, map); Object.DestroyImmediate(map); } } }