public void Sync(KAnimControllerBase controller) { if (!((Object)masterController == (Object)null) && !((Object)controller == (Object)null)) { KAnim.Anim currentAnim = masterController.GetCurrentAnim(); if (currentAnim != null) { KAnim.PlayMode mode = masterController.GetMode(); float playSpeed = masterController.GetPlaySpeed(); float elapsedTime = masterController.GetElapsedTime(); controller.Play(currentAnim.name, mode, playSpeed, elapsedTime); Facing component = controller.GetComponent <Facing>(); if ((Object)component != (Object)null) { Vector3 position = component.transform.GetPosition(); float x = position.x; x += ((!masterController.FlipX) ? 0.5f : (-0.5f)); component.Face(x); } else { controller.FlipX = masterController.FlipX; controller.FlipY = masterController.FlipY; } } } }
protected KAnimControllerBase() { KAnim.Anim.Frame invalidFrame = KAnim.Anim.Frame.InvalidFrame; curAnimFrameIdx = invalidFrame.idx; KAnim.Anim.Frame invalidFrame2 = KAnim.Anim.Frame.InvalidFrame; prevAnimFrame = invalidFrame2.idx; eventManagerHandle = HandleVector <int> .InvalidHandle; overrideAnimFiles = new List <OverrideAnimFileData>(); DeepProfiler = new DeepProfiler(false); playSpeed = 1f; mode = KAnim.PlayMode.Once; stopped = true; animHeight = 1f; animWidth = 1f; _enabled = true; hiddenSymbols = new List <KAnimHashedString>(); anims = new Dictionary <HashedString, AnimLookupData>(); overrideAnims = new Dictionary <HashedString, AnimLookupData>(); animQueue = new Queue <AnimData>(); fgLayer = Grid.SceneLayer.NoLayer; base._002Ector(); previousFrame = -1; currentFrame = -1; PlaySpeedMultiplier = 1f; synchronizer = new KAnimSynchronizer(this); layering = new KAnimLayering(this, fgLayer); isVisible = true; }
private void Restart(HashedString anim_name, KAnim.PlayMode mode = KAnim.PlayMode.Once, float speed = 1f, float time_offset = 0f) { if (curBuild == null) { Debug.LogWarning("[" + base.gameObject.name + "] Missing build while trying to play anim [" + anim_name + "]", base.gameObject); } else { Queue <AnimData> queue = new Queue <AnimData>(); queue.Enqueue(new AnimData { anim = anim_name, mode = mode, speed = speed, timeOffset = time_offset }); while (animQueue.Count > 0) { queue.Enqueue(animQueue.Dequeue()); } animQueue = queue; if (animQueue.Count == 1 && stopped) { StartQueuedAnim(); } } }
public void Play(HashedString anim_name, KAnim.PlayMode mode = KAnim.PlayMode.Once, float speed = 1f, float time_offset = 0f) { if (!stopped) { Stop(); } Queue(anim_name, mode, speed, time_offset); }
public StatesInstance(EmoteChore master, GameObject emoter, HashedString emote_kanim, HashedString[] emote_anims, KAnim.PlayMode mode, bool flip_x) : base(master) { emoteKAnim = emote_kanim; emoteAnims = emote_anims; this.mode = mode; base.sm.emoter.Set(emoter, base.smi); }
public StatesInstance(ReactEmoteChore master, GameObject emoter, EmoteReactable reactable, HashedString emote_kanim, HashedString[] emote_anims, KAnim.PlayMode mode) : base(master) { emoteKAnim = emote_kanim; emoteAnims = emote_anims; this.mode = mode; base.sm.reactable.Set(reactable, base.smi); base.sm.emoter.Set(emoter, base.smi); }
public Instance(IStateMachineTarget master, string kanim_file, HashedString[] anims, KAnim.PlayMode mode, Vector3 offset, Color32 tint_colour) : base(master) { animController = FXHelpers.CreateEffect(kanim_file, smi.master.transform.GetPosition() + offset, smi.master.transform); //animController.gameObject.Subscribe(-1061186183, OnAnimQueueComplete); animController.TintColour = tint_colour; sm.fx.Set(animController.gameObject, smi); this.anims = anims; this.mode = mode; }
public Instance(IStateMachineTarget master, string kanim_file, string anim, KAnim.PlayMode mode, Vector3 offset, Color32 tint_colour) : base(master) { animController = FXHelpers.CreateEffect(kanim_file, base.smi.master.transform.GetPosition() + offset, base.smi.master.transform, false, Grid.SceneLayer.Front, false); animController.gameObject.Subscribe(-1061186183, OnAnimQueueComplete); animController.TintColour = tint_colour; base.sm.fx.Set(animController.gameObject, base.smi); this.anim = anim; this.mode = mode; }
/// <summary> /// Optimizes the play mode used for animations. /// </summary> /// <param name="anim">The anim file that is playing.</param> /// <param name="currentMode">The current play mode requested by the game.</param> /// <returns>The play mode to use for playing it taking optimizations into account.</returns> public KAnim.PlayMode GetAnimState(KAnim.Anim anim, KAnim.PlayMode currentMode) { var mode = currentMode; if (anim != null && idleAnims.TryGetValue(anim.id, out AnimWrapper status) && status.anim == anim) { mode = status.veryTrivial ? KAnim.PlayMode.Paused : KAnim.PlayMode.Once; } return(mode); }
public void Play(HashedString[] anim_names, KAnim.PlayMode mode = KAnim.PlayMode.Once) { if (!stopped) { Stop(); } for (int i = 0; i < anim_names.Length - 1; i++) { Queue(anim_names[i], KAnim.PlayMode.Once, 1f, 0f); } Queue(anim_names[anim_names.Length - 1], mode, 1f, 0f); }
protected void StartQueuedAnim() { StopAnimEventSequence(); previousFrame = -1; currentFrame = -1; SuspendUpdates(false); stopped = false; OnStartQueuedAnim(); AnimData animData = animQueue.Dequeue(); while (animData.mode == KAnim.PlayMode.Loop && animQueue.Count > 0) { animData = animQueue.Dequeue(); } if (overrideAnims == null || !overrideAnims.TryGetValue(animData.anim, out AnimLookupData value)) { if (!anims.TryGetValue(animData.anim, out value)) { bool flag = true; if ((UnityEngine.Object)showWhenMissing != (UnityEngine.Object)null) { showWhenMissing.SetActive(true); } if (flag) { TriggerStop(); return; } } else if ((UnityEngine.Object)showWhenMissing != (UnityEngine.Object)null) { showWhenMissing.SetActive(false); } } curAnim = GetAnim(value.animIndex); int num = 0; if (animData.mode == KAnim.PlayMode.Loop && randomiseLoopedOffset) { num = UnityEngine.Random.Range(0, curAnim.numFrames - 1); } prevAnimFrame = -1; curAnimFrameIdx = GetFrameIdxFromOffset(num); currentFrame = curAnimFrameIdx; mode = animData.mode; playSpeed = animData.speed * PlaySpeedMultiplier; SetElapsedTime((float)num / curAnim.frameRate + animData.timeOffset); synchronizer.Sync(); StartAnimEventSequence(); AnimEnter(animData.anim); }
public static string GetModeString(KAnim.PlayMode mode) { switch (mode) { case KAnim.PlayMode.Once: return("Once"); case KAnim.PlayMode.Loop: return("Loop"); case KAnim.PlayMode.Paused: return("Paused"); default: return("Unknown"); } }
public void Queue(HashedString anim_name, KAnim.PlayMode mode = KAnim.PlayMode.Once, float speed = 1f, float time_offset = 0f) { animQueue.Enqueue(new AnimData { anim = anim_name, mode = mode, speed = speed, timeOffset = time_offset }); this.mode = ((mode != KAnim.PlayMode.Paused) ? KAnim.PlayMode.Once : KAnim.PlayMode.Paused); if (aem != null) { aem.SetMode(eventManagerHandle, this.mode); } if (animQueue.Count == 1 && stopped) { StartQueuedAnim(); } }
/// <summary> /// Adjusts the play mode if the anim is trivial. /// </summary> internal static KAnim.PlayMode UpdateMode(KAnim.PlayMode mode, KAnimControllerBase controller) { var anim = controller.GetCurrentAnim(); var inst = KAnimLoopOptimizer.Instance; if (anim != null && mode == KAnim.PlayMode.Loop && inst != null && controller. animQueue.Count == 0) { // Will set "paused" only if the anim is so short as to be unnoticeable mode = inst.GetAnimState(anim, mode); if (mode == KAnim.PlayMode.Paused) { // Trigger an instant stop controller.Stop(); controller.currentFrame = 0; controller.SetElapsedTime(0.0f); PathPatches.DeferAnimQueueTrigger.TriggerAndQueue(controller, (int)GameHashes.AnimQueueComplete, null); } } return(mode); }
public void PlayAnims() { if (base.def.anims != null && base.def.anims.Length != 0) { KBatchedAnimController component = GetComponent <KBatchedAnimController>(); for (int i = 0; i < base.def.anims.Length; i++) { KAnim.PlayMode mode = KAnim.PlayMode.Once; if (base.def.loop && i == base.def.anims.Length - 1) { mode = KAnim.PlayMode.Loop; } if (i == 0) { component.Play(base.def.anims[i], mode, 1f, 0f); } else { component.Queue(base.def.anims[i], mode, 1f, 0f); } } } }
protected override void OnSpawn() { base.OnSpawn(); var kanim = Assets.GetAnim("fishingline_kanim"); string snapto = "snapto_pivot"; if (type == GuideType.Complete) { Subscribe((int)GameHashes.OperationalChanged, OnOperationalChangedDelegate); lineAnim = "line"; string hookAnim = "hook"; playMode = KAnim.PlayMode.Loop; line = AddGuide(kbac, snapto, kanim, lineAnim, true); hook = AddGuide(line, snapto, kanim, hookAnim, true); hook.Play(hookAnim, playMode); } else { lineAnim = "line_place"; playMode = KAnim.PlayMode.Once; line = AddGuide(kbac, snapto, kanim, lineAnim, false); } RefreshDepth(); }
public EmoteChore(IStateMachineTarget target, ChoreType chore_type, HashedString emote_kanim, HashedString[] emote_anims, KAnim.PlayMode play_mode, bool flip_x = false) : base(chore_type, target, target.GetComponent <ChoreProvider>(), false, (Action <Chore>)null, (Action <Chore>)null, (Action <Chore>)null, PriorityScreen.PriorityClass.compulsory, 5, false, true, 0, false, ReportManager.ReportType.WorkTime) { base.smi = new StatesInstance(this, target.gameObject, emote_kanim, emote_anims, play_mode, flip_x); }
public ReactEmoteChore(IStateMachineTarget target, ChoreType chore_type, EmoteReactable reactable, HashedString emote_kanim, HashedString[] emote_anims, KAnim.PlayMode play_mode, Func <StatusItem> get_status_item) : base(chore_type, target, target.GetComponent <ChoreProvider>(), false, (Action <Chore>)null, (Action <Chore>)null, (Action <Chore>)null, PriorityScreen.PriorityClass.basic, 5, false, true, 0, false, ReportManager.ReportType.WorkTime) { AddPrecondition(ChorePreconditions.instance.IsMoving, null); AddPrecondition(ChorePreconditions.instance.IsOffLadder, null); AddPrecondition(ChorePreconditions.instance.NotInTube, null); AddPrecondition(ChorePreconditions.instance.IsAwake, null); getStatusItem = get_status_item; base.smi = new StatesInstance(this, target.gameObject, reactable, emote_kanim, emote_anims, play_mode); }
private static GameStateMachine <BaggedStates, BaggedStates.Instance, IStateMachineTarget, BaggedStates.Def> .State PlayAnimStub(GameStateMachine <BaggedStates, BaggedStates.Instance, IStateMachineTarget, BaggedStates.Def> .State @this, string _1, KAnim.PlayMode _2) { return(@this); }