Ejemplo n.º 1
0
    public CreatureManager GetCreatureManager()
    {
        if (HasNoValidAsset())
        {
            Debug.LogError("Input Creature JSON file not set for CreatureAsset: " + name, this);
            ResetState();
            return(null);
        }

        if (creature_manager != null)
        {
            return(creature_manager);
        }

        Dictionary <string, object> load_data = LoadCreatureJsonData();

        CreatureModule.Creature new_creature = new CreatureModule.Creature(ref load_data);
        creature_manager = new CreatureModule.CreatureManager(new_creature);
        creature_manager.CreateAllAnimations(ref load_data);

        var all_animations = creature_manager.animations;

        foreach (KeyValuePair <string, CreatureAnimationAssetData> entry in animation_clip_overides)
        {
            var cur_name           = entry.Key;
            var cur_animation_data = entry.Value;

            if (all_animations.ContainsKey(cur_name))
            {
                // Set Animation Frame Ranges
                all_animations[cur_name].start_time = cur_animation_data.start_frame;
                all_animations[cur_name].end_time   = cur_animation_data.end_frame;

                // Decide if we need to make point caches
                if (cur_animation_data.make_point_cache)
                {
                    var stopWatch = new System.Diagnostics.Stopwatch();
                    stopWatch.Start();

                    creature_manager.MakePointCache(cur_name, cur_animation_data.cache_approximation);

                    stopWatch.Stop();
                    Debug.Log("Creature Point Cache generation took: " + stopWatch.ElapsedMilliseconds);
                }
            }
        }



        is_dirty = true;

        // Load meta data if available
        creature_meta_data = null;
        if (creatureMetaJSON != null)
        {
            creature_meta_data = new CreatureMetaData();
            CreatureModule.Utils.BuildCreatureMetaData(
                creature_meta_data,
                creatureMetaJSON.text,
                physics_assets,
                skin_swap_names);
        }

        return(creature_manager);
    }