Exemplo n.º 1
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;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Convert the value to a parsable String
        /// </summary>
        public String ValueToString()
        {
            if (Value == null)
            {
                return(null);
            }

            if (GameDatabase.Instance.ExistsTexture(Value.name) || OnDemandStorage.TextureExists(Value.name))
            {
                return(Value.name);
            }

            return("BUILTIN/" + Value.name);
        }