Skip to content

Commit

Permalink
disable animator, when clip playing
Browse files Browse the repository at this point in the history
  • Loading branch information
k-okawa committed Feb 11, 2022
1 parent 6a87408 commit 546061c
Show file tree
Hide file tree
Showing 4 changed files with 433 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
using System;
using UnityEngine;
using UnityEngine.Playables;

namespace Bg.WaypointSystemForTimeline {
[Serializable]
public class WaypointTimelinePlayableBehaviour : PlayableBehaviour {
// is stop animator controller when clip in
[Tooltip("If GameObject has animator component enabled, waypoint system dose not work.")]
[SerializeField] private bool _isStopAnimator = true;

private WaypointComponent _wayPointComponent;
private Animator _animator;

public override void OnBehaviourPause (Playable playable, FrameData info) {
EnableAnimator(true);
}

public override void OnGraphStop (Playable playable) {
EnableAnimator(true);
}

public override void OnBehaviourPlay(Playable playable, FrameData info) {
EnableAnimator(false);
}

public override void ProcessFrame(Playable playable, FrameData info, object playerData) {
if (playerData == null) {
return;
}

var wayPointsComponent = playerData as WaypointComponent;
_wayPointComponent = playerData as WaypointComponent;
_animator = _wayPointComponent.GetComponent<Animator>();
EnableAnimator(false);

double t = playable.GetTime() / playable.GetDuration();
wayPointsComponent.SetPosition((float)t);
_wayPointComponent.SetPosition((float)t);
}

private void EnableAnimator(bool isEnable) {
if (!_isStopAnimator || _animator == null) return;
_animator.enabled = isEnable;
}
}
}
2 changes: 1 addition & 1 deletion Assets/Bg/WaypointSystemForTimeline/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.bg.waypointystemfortimeline",
"displayName": "WaypointSystemForTimeline",
"version": "1.0.3",
"version": "1.0.4",
"author": {
"name": "KyoheiOkawa"
}
Expand Down
37 changes: 34 additions & 3 deletions Assets/Bg/WaypointSystemForTimelineSample/Basic/Basic.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44657874, g: 0.49641275, b: 0.5748172, a: 1}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 11
serializedVersion: 12
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2
Expand Down Expand Up @@ -98,7 +98,7 @@ LightmapSettings:
m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1
m_LightingSettings: {fileID: 0}
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
Expand All @@ -118,6 +118,8 @@ NavMeshSettings:
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
maxJobWorkers: 0
preserveTilesOutsideBounds: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
Expand Down Expand Up @@ -256,6 +258,7 @@ Light:
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_UseViewFrustumForShadowCasterCull: 1
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &643984079
Expand Down Expand Up @@ -319,6 +322,7 @@ MeshRenderer:
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
Expand All @@ -343,6 +347,7 @@ MeshRenderer:
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &908891472
MeshFilter:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -375,6 +380,7 @@ GameObject:
m_Component:
- component: {fileID: 1000423089}
- component: {fileID: 1000423088}
- component: {fileID: 1000423090}
m_Layer: 0
m_Name: LookForwardWaypoint
m_TagString: Untagged
Expand Down Expand Up @@ -428,6 +434,25 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!95 &1000423090
Animator:
serializedVersion: 3
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1000423087}
m_Enabled: 1
m_Avatar: {fileID: 0}
m_Controller: {fileID: 0}
m_CullingMode: 0
m_UpdateMode: 0
m_ApplyRootMotion: 0
m_LinearVelocityBlending: 0
m_WarningMessage:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorControllerStateOnDisable: 0
--- !u!1 &1138514637
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -572,6 +597,7 @@ MeshRenderer:
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
Expand All @@ -596,6 +622,7 @@ MeshRenderer:
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &1297932810
MeshFilter:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -660,6 +687,8 @@ PlayableDirector:
value: {fileID: 441310730}
- key: {fileID: -979716376006852858, guid: 33a9b07e5eb714ba7b3ca878fa81964e, type: 2}
value: {fileID: 1000423088}
- key: {fileID: 2878600430250776528, guid: 33a9b07e5eb714ba7b3ca878fa81964e, type: 2}
value: {fileID: 1000423090}
m_ExposedReferences:
m_References: []
--- !u!4 &1387083686
Expand Down Expand Up @@ -723,6 +752,7 @@ MeshRenderer:
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
Expand All @@ -747,6 +777,7 @@ MeshRenderer:
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &1737083698
MeshFilter:
m_ObjectHideFlags: 0
Expand Down
Loading

0 comments on commit 546061c

Please sign in to comment.