示例#1
0
            /// <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))
                        {
                            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.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 = OnDemandStorage.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);
                        }
                    }
                }
            }
示例#2
0
        /// <summary>
        /// Parse the Value from a string
        /// </summary>
        public void SetFromString(String s)
        {
            // Check if we are attempting to load a builtin texture
            if (s.StartsWith("BUILTIN/"))
            {
                String textureName = Regex.Replace(s, "BUILTIN/", "");
                Value = Resources.FindObjectsOfTypeAll <Texture>().FirstOrDefault(tex => tex.name == textureName) as Texture2D;
                if (Value != null)
                {
                    return;
                }

                Debug.LogError("[Kopernicus] Could not find built-in texture " + textureName);
                Logger.Active.Log("Could not find built-in texture " + textureName);
                return;
            }

            // Otherwise search the game database for one loaded from GameData/
            if (GameDatabase.Instance.ExistsTexture(s))
            {
                // Get the texture URL
                Value = GameDatabase.Instance.GetTexture(s, false);
                return;
            }

            // Or load the texture directly
            if (OnDemandStorage.TextureExists(s))
            {
                Value = OnDemandStorage.LoadTexture(s, false, true, false);

                // Upload it to the GPU if the parser could load something
                if (Value == null)
                {
                    return;
                }
                try
                {
                    Value.Apply(false, true);
                }
                catch
                {
                    Debug.LogError("[Kopernicus] Failed to upload texture " + Value.name + " to the GPU");
                    Logger.Active.Log("Failed to upload texture " + Value.name + " to the GPU");
                }

                return;
            }

            // Texture was not found
            Value = null;
        }
示例#3
0
        /// <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;
                    }

                    if (typeof(T) == typeof(CBAttributeMapSO))
                    {
                        CBAttributeMapSODemand cbMap = ScriptableObject.CreateInstance <CBAttributeMapSODemand>();
                        cbMap.Path     = s;
                        cbMap.Depth    = MapSO.MapDepth.Greyscale;
                        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.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);
                }
            }

            if (Value != null)
            {
                Value.name = s;
            }
        }
示例#4
0
 public static Texture2D LoadTexture(String path, Boolean compress, Boolean upload, Boolean unreadable)
 {
     return(OnDemandStorage.LoadTexture(path, compress, upload, unreadable));
 }