Esempio n. 1
0
        /// <summary>
        /// Load animation from config asset, based on animation identifier.
        /// </summary>
        /// <param name="identifier">Animation identifier.</param>
        /// <param name="config">Config asset to load from.</param>
        /// <remarks>Config must contain a section called 'anim_xxx', where xxx is this animation's unique identifier.
        /// Under this section, we should have the following keys:
        ///     - repeats = true / false - does this animation loops, or remain stuck on last step after done?
        ///     - steps_count = how many steps we have in this animation.
        ///     - setp_x_duration[x is step index] = duration, in seconds, of this animation step.
        ///     - setp_x_source[x is step index] = index in spritesheet file, format is: "x,y".
        /// For more info, check out demo_spritesheet.ini in test assets folder.</remarks>
        public SpriteAnimation(string identifier, ConfigAsset config)
        {
            // set identifier
            Identifier = identifier;

            // get general stuff
            string section = "anim_" + identifier;

            Repeats = config.GetBool(section, "repeats");
            int steps = config.GetInt(section, "steps_count", -1);

            // sanity
            if (steps < 0)
            {
                throw new Exception($"Missing animation {identifier} section in config file, or missing 'steps_count' key!");
            }

            // load all steps
            for (int i = 0; i < steps; ++i)
            {
                string prefix   = "step_" + i.ToString();
                float  duration = config.GetFloat(section, prefix + "_duration");
                PointI index    = PointI.FromString(config.GetStr(section, prefix + "_source"));
                AddStep(new SpriteAnimationStep()
                {
                    Duration = duration, Index = index
                });
            }
        }
        /// <summary>
        /// Loads a config asset.
        /// </summary>
        /// <param name="path">Config path.</param>
        /// <param name="useCache">Should we use cache for this asset to make future loadings faster?</param>
        /// <param name="useAssetsRoot">If true, path will be relative to 'AssetsRoot'. If false, will be relative to working directory.</param>
        /// <returns>Loaded config asset.</returns>
        public ConfigAsset LoadConfig(string path, bool useCache = true, bool useAssetsRoot = true)
        {
            var ret = new ConfigAsset(_BonEngineBind.BON_Assets_LoadConfig(ToAssetsPath(path, true, useAssetsRoot), useCache));

            ret.Path = path;
            return(ret);
        }
Esempio n. 3
0
        /// <summary>
        /// Load animation from config asset, based on animation identifier.
        /// </summary>
        /// <param name="identifier">Animation identifier.</param>
        /// <param name="config">Config asset to load from.</param>
        /// <remarks>Config must contain a section called 'anim_xxx', where xxx is this animation's unique identifier.
        /// Under this section, we should have the following keys:
        ///     - repeats = true / false - does this animation loops, or remain stuck on last step after done?
        ///     - steps_count = how many steps we have in this animation.
        ///     - setp_x_duration [x is step index] = duration, in seconds, of this animation step.
        ///     - setp_x_source [x is step index] = index in spritesheet file, format is: "x,y".
        ///     - step_x_tag [x is step index] = optional tag to attach to this step.
        /// For more info, check out demo_spritesheet.ini in test assets folder.</remarks>
        public SpriteAnimation(string identifier, ConfigAsset config)
        {
            // set identifier
            Identifier = identifier;

            // get general stuff
            string section = "anim_" + identifier;

            Repeats = config.GetBool(section, "repeats");
            int steps = config.GetInt(section, "steps_count", -1);

            // sanity
            if (steps < 0)
            {
                throw new Exception($"Missing animation {identifier} section in config file, or missing 'steps_count' key!");
            }

            // load all steps
            for (int i = 0; i < steps; ++i)
            {
                string prefix = "step_" + i.ToString();

                // read duration
                float duration = config.GetFloat(section, prefix + "_duration", -100f);
                if (duration == -100f)
                {
                    throw new FormatException($"Missing or invalid duration value for step {i} in animation '{identifier}'.");
                }

                // read source index
                PointI index = config.GetPointI(section, prefix + "_source", new PointI(-100, -100));
                if (index.X == -100f)
                {
                    throw new FormatException($"Missing or invalid source value for step {i} in animation '{identifier}'.");
                }

                // read optional tag and add step
                string tag = config.GetStr(section, prefix + "_tag", null);
                AddStep(new SpriteAnimationStep()
                {
                    Duration = duration, Index = index, Tag = tag
                });
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Load spritesheet properties from config asset.
        /// Note: this will replace all existing settings.
        /// </summary>
        /// <param name="config">Config file to load from.</param>
        /// <remarks>Config must contain the following section:
        /// [general]
        ///     - sprites_count = how many sprites there are in this spritesheet, format is: "x,y".
        ///     - animations = list of comma-separated animations found in this spritesheet config.
        ///                     for every animation listed here, you need to also include a section with animation data.
        ///                     check out 'SpriteAnimation' constructor for more info.
        ///
        /// [bookmarks]
        ///     - optional, contains a list of values where every key is a bookmark identifier and value is sprite index "x,y".
        ///         later, you can use this to set sprites from spritesheet by names. for example: sheet.SetSprite(sprite, "item_sword");
        ///
        /// For more info, check out demo_spritesheet.ini in test assets folder.
        /// </remarks>
        public void LoadFromConfig(ConfigAsset config)
        {
            // load general settings
            SpritesCount = PointI.FromString(config.GetStr("general", "sprites_count", "0,0"));

            // load bookmarks
            var bookmarks = config.Keys("bookmarks");

            foreach (var book in bookmarks)
            {
                var value = PointI.FromString(config.GetStr("bookmarks", book, "0,0"));
                _bookmarks.Add(book, value);
            }

            // load animations
            var animations = config.GetStr("general", "animations", "").Split(',');

            foreach (var anim in animations)
            {
                var animationName   = anim.Trim();
                var spriteAnimation = new SpriteAnimation(animationName, config);
                _animations.Add(animationName, spriteAnimation);
            }
        }
Esempio n. 5
0
     // ... stash global data here
  
 #if !UNITY_EDITOR
     private void OnEnable() {
         config = this;
     }
Esempio n. 6
0
 /// <summary>
 /// Create the spritesheet from config file.
 /// </summary>
 /// <param name="config">Config asset to load spritesheet from.</param>
 public SpriteSheet(ConfigAsset config)
 {
     LoadFromConfig(config);
 }
Esempio n. 7
0
        /// <summary>
        /// Creates an empty config.
        /// </summary>
        public ConfigAsset CreateEmptyConfig()
        {
            var ret = new ConfigAsset(_BonEngineBind.BON_Assets_CreateEmptyConfig());

            return(ret);
        }
Esempio n. 8
0
        /// <summary>
        /// Loads a config asset.
        /// </summary>
        /// <param name="filename">Config path.</param>
        /// <param name="useCache">Should we use cache for this asset to make future loadings faster?</param>
        /// <returns>Loaded config asset.</returns>
        public ConfigAsset LoadConfig(string filename, bool useCache = true)
        {
            var ret = new ConfigAsset(_BonEngineBind.BON_Assets_LoadConfig(ToAssetsPath(filename, true), useCache));

            return(ret);
        }
Esempio n. 9
0
 /// <summary>
 /// Saves a config file.
 /// </summary>
 /// <returns>True if saving was successful.</returns>
 public bool SaveConfig(ConfigAsset config, string path)
 {
     return(_BonEngineBind.BON_Assets_SaveConfig(config._handle, ToAssetsPath(path, false)));
 }
Esempio n. 10
0
 /// <summary>
 /// Load input binds from config asset.
 /// </summary>
 /// <param name="config">Config asset to load key binds from (must appear under 'controls' section).</param>
 /// <param name="removeOldBinds">If true, will clear all previous key binds.</param>
 public void LoadControlsFromConfig(ConfigAsset config, bool removeOldBinds)
 {
     _BonEngineBind.BON_Input_LoadControlsFromConfig(config._handle, removeOldBinds);
 }
Esempio n. 11
0
 /// <summary>
 /// Saves a config file.
 /// </summary>
 /// <param name="config">Config asset to save.</param>
 /// <param name="path">Output file path.</param>
 /// <param name="useAssetsRoot">If true, will append path to assets root. If false, will treat it as relative path to working directory.</param>
 /// <returns>True if saving was successful.</returns>
 public bool SaveConfig(ConfigAsset config, string path, bool useAssetsRoot = true)
 {
     return(_BonEngineBind.BON_Assets_SaveConfig(config._handle, useAssetsRoot ? ToAssetsPath(path, false) : path));
 }
Esempio n. 12
0
 /// <summary>
 /// Load stylesheet from config file.
 /// </summary>
 /// <param name="config">Config asset to load stylesheet from.</param>
 public void LoadStyleFrom(ConfigAsset config)
 {
     _BonEngineBind.BON_UIElement_LoadStyleFrom(_handle, config._handle);
 }
Esempio n. 13
0
    static IEnumerator _LoadConfig(Action onComplete)
    {
        ConfigAsset asset    = null;
        ConfigData  data     = null;
        float       progress = 0f;
        //string assetPath = string.Format("file:///{0}/ConfigMapObjectData.a", Util.AssetRoot);
        string assetPath = string.Format("{0}/ConfigMapObjectData.a", Util.AssetsPath);
        WWW    www       = new WWW(assetPath);

        for (; !www.isDone;)
        {
            progress = www.progress;
            //LoadingWindow.LoginPanel.Instance.SetProgressBar(0.7f + progress * 0.1f);
            yield return(new WaitForEndOfFrame());
        }
        if (!string.IsNullOrEmpty(www.error))
        {
            Debug.LogError(www.error);
        }
        else
        {
            asset = www.assetBundle.mainAsset as ConfigAsset;
            //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopswatch();
            //sw.Start();
            data = asset.Deserialize();
            //sw.Stop();
            //Debug.LogWarning("11111111111111111111:" + sw.ElapsedMilliseconds);
            if (ConfigManager.Instance.configs.ContainsKey(asset.name))
            {
                ConfigManager.Instance.configs[asset.name] = data;
            }
            else
            {
                ConfigManager.Instance.configs.Add(asset.name, data);
            }
            www.assetBundle.Unload(true);
        }
        www.Dispose();
        www = null;
        yield return(new WaitForEndOfFrame());

        assetPath = string.Format("{0}/ConfigMapObjectDungeonData.a", Util.AssetsPath);
        www       = new WWW(assetPath);
        for (; !www.isDone;)
        {
            progress = www.progress;
            //LoadingWindow.LoginPanel.Instance.SetProgressBar(0.8f + progress * 0.1f);
            yield return(new WaitForEndOfFrame());
        }
        if (!string.IsNullOrEmpty(www.error))
        {
            Debug.LogError(www.error);
        }
        else
        {
            asset = www.assetBundle.mainAsset as ConfigAsset;
            //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            //sw.Start();
            data = asset.Deserialize();
            //sw.Stop();
            //Debug.LogWarning("22222222222222222222222222:" + sw.ElapsedMilliseconds);
            if (ConfigManager.Instance.configs.ContainsKey(asset.name))
            {
                ConfigManager.Instance.configs[asset.name] = data;
            }
            else
            {
                ConfigManager.Instance.configs.Add(asset.name, data);
            }
            www.assetBundle.Unload(true);
        }
        www.Dispose();
        www = null;
        yield return(new WaitForEndOfFrame());

        //assetPath = string.Format("file:///{0}/Config.a", Util.AssetRoot);
        assetPath = string.Format("{0}/Config.a", Util.AssetsPath);
        www       = new WWW(assetPath);
        for (; !www.isDone;)
        {
            progress = www.progress;
            //LoadingWindow.LoginPanel.Instance.SetProgressBar(0.9f + progress * 0.05f);
            yield return(new WaitForEndOfFrame());
        }
        if (!string.IsNullOrEmpty(www.error))
        {
            Debug.Log(string.Format("assetPath:{0}", assetPath));
            Debug.LogError(www.error);
        }
        else
        {
            Object[] configs = www.assetBundle.LoadAllAssets();

            for (int i = 0; i < configs.Length; ++i)
            {
                Object config = configs[i];
                if (config is ConfigAsset)
                {
                    asset = config as ConfigAsset;
                    data  = asset.Deserialize();
                    ConfigManager.Instance.configs.Add(asset.name, data);
                    //LoadingWindow.LoginPanel.Instance.SetProgressBar(0.95f + (i + 1f) / configs.Length * 0.05f);
                    yield return(new WaitForEndOfFrame());
                }
            }

            www.assetBundle.Unload(true);
        }
        www.Dispose();
        www = null;

        //LoadingWindow.LoginPanel.Instance.SetProgressBar(1f);
        //LoadingWindow.LoginPanel.Instance.ShowTip("");
        //LoadingWindow.LoginPanel.Instance.ShowProgressBar(false);
        //LoadingWindow.Instance.ShowLogin(true);

        if (onComplete != null)
        {
            onComplete();
        }
    }