Esempio 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);
    }
Esempio n. 2
0
        public static void UpdateTime(
            CreatureManager creature_manager,
            CreatureGameController game_controller,
            CreatureMetaData meta_data,
            string active_animation_name,
            float local_time_scale,
            float region_offsets_z,
            bool should_loop,
            ref float local_time)
        {
            if (active_animation_name == null || active_animation_name.Length == 0)
            {
                return;
            }

            bool morph_targets_valid = false;

            if (game_controller != null)
            {
                if ((meta_data != null) && game_controller.morph_targets_active)
                {
                    morph_targets_valid = meta_data.morph_data.isValid();
                }
            }

            var   old_time   = creature_manager.getActualRuntime();
            float time_delta = (Time.deltaTime * local_time_scale);

            creature_manager.region_offsets_z = region_offsets_z;
            creature_manager.should_loop      = should_loop;

            if (morph_targets_valid)
            {
                game_controller.computeMorphTargetsPt();
                meta_data.updateMorphStep(creature_manager, time_delta);
            }
            else
            {
                creature_manager.Update(time_delta);
            }

            local_time = creature_manager.getActualRuntime();

            bool reached_anim_end = false;

            if ((local_time < old_time) && (game_controller != null))
            {
                game_controller.AnimClipFrameResetEvent();
                reached_anim_end = true;
            }

            if (local_time >= creature_manager.GetAnimation(active_animation_name).end_time)
            {
                reached_anim_end = true;
            }

            if (reached_anim_end && (game_controller != null))
            {
                game_controller.AnimationReachedEnd(active_animation_name);
            }
        }