Пример #1
0
        /// <summary>
        /// Load the Map
        /// </summary>
        public void Load()
        {
            // Check if the Map is already loaded
            if (IsLoaded)
            {
                return;
            }

            if (OnDemandStorage.UseManualMemoryManagement)
            {
                // Load the Map
                LoadTexture(Path);

                IsLoaded = true;

                // Create a dummy map for firing events
                MapSODemand eventMap = (MapSODemand)ScriptableObject.CreateInstance(typeof(MapSODemand));
                eventMap.name = name;
                eventMap.Path = Path;
                Events.OnMapSOLoad.Fire(eventMap);

                Debug.Log("[OD] ---> Map " + name + " enabling self. Path = " + Path);
                return;
            }

            // Return nothing
            Debug.Log("[OD] ERROR: Failed to load map " + name + " at path " + Path);
        }
Пример #2
0
        /// <summary>
        /// Unload the map
        /// </summary>
        public void Unload()
        {
            // We can only destroy the map, if it is loaded
            if (!IsLoaded)
            {
                return;
            }

            // Nuke the map
            if (OnDemandStorage.UseManualMemoryManagement)
            {
                Image.Free();
            }

            // Set flags
            IsLoaded = false;

            // Create a dummy map for firing events
            MapSODemand eventMap = (MapSODemand)ScriptableObject.CreateInstance(typeof(MapSODemand));

            eventMap.name = name;
            eventMap.Path = Path;
            Events.OnMapSOUnload.Fire(eventMap);

            // Log
            Debug.Log("[OD] <--- Map " + name + " disabling self. Path = " + Path);
        }
Пример #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))
                        {
                            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);
                        }
                    }
                }
            }
Пример #4
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
            {
                // 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;
            }
        }