public void UpdatePlayable(TimelineAsset asset, double time, TurnDisplayData turn = null)
    {
        var director = GetComponent <PlayableDirector>();

        if (ActiveTurn != turn || director.playableAsset != asset)
        {
            ActiveTurn             = turn;
            director.playableAsset = asset;
            BattleCharacterTrackBinder.BindTracks(this, asset);
            director.RebuildGraph();
        }

        director.time = time % director.duration;
        director.Evaluate();
    }
Exemplo n.º 2
0
    private double CalculateLocks(TurnDisplayData turnData)
    {
        var turnStart = _battleLockEnd;

        if (turnData.TimelineAssetData.BattleLock.Start != -1)
        {
            turnStart -= turnData.TimelineAssetData.BattleLock.Start;
            if (turnStart < 0)
            {
                turnStart = 0;
            }
        }

        if (turnData.TimelineAssetData.CharacterLock.Start != -1)
        {
            var characterLockStart = turnStart + turnData.TimelineAssetData.CharacterLock.Start;
            if (turnData.CharacterBehaviour.ControllerLockEnd > characterLockStart)
            {
                turnStart += turnData.CharacterBehaviour.ControllerLockEnd - characterLockStart;
            }
        }

        for (var targetIndex = 0; targetIndex < turnData.TimelineAssetData.TargetLocks.Count; targetIndex++)
        {
            var targetLock = turnData.TimelineAssetData.TargetLocks[targetIndex];
            if (targetLock.Start != -1 && targetIndex < turnData.TargetBehaviours.Count)
            {
                var targetBehaviour = turnData.TargetBehaviours[targetIndex];
                var targetLockStart = turnStart + targetLock.Start;
                if (targetBehaviour.ControllerLockEnd > targetLockStart)
                {
                    turnStart += targetBehaviour.ControllerLockEnd - targetLockStart;
                }
            }
        }


        if (turnData.TimelineAssetData.BattleLock.Start != -1)
        {
            _battleLockEnd = turnStart + turnData.TimelineAssetData.BattleLock.End;
        }

        if (turnData.TimelineAssetData.CharacterLock.Start != -1)
        {
            var characterLockEnd = turnStart + turnData.TimelineAssetData.CharacterLock.End;
            if (turnData.CharacterBehaviour.ControllerLockEnd < characterLockEnd)
            {
                turnData.CharacterBehaviour.ControllerLockEnd = characterLockEnd;
            }
        }

        for (var targetIndex = 0; targetIndex < turnData.TimelineAssetData.TargetLocks.Count; targetIndex++)
        {
            var targetLock = turnData.TimelineAssetData.TargetLocks[targetIndex];
            if (targetLock.Start != -1 && targetIndex < turnData.TargetBehaviours.Count)
            {
                var targetBehaviour = turnData.TargetBehaviours[targetIndex];
                var targetLockEnd   = turnStart + targetLock.End;
                if (targetBehaviour.ControllerLockEnd < targetLockEnd)
                {
                    targetBehaviour.ControllerLockEnd = targetLockEnd;
                }
            }
        }

        return(turnStart);
    }
Exemplo n.º 3
0
    private void Update()
    {
        if (!_initialized)
        {
            return;
        }
        bool timelineUpdated = false;

        var newLookAhead = Math.Round((_playableDirector.time + LOOK_AHEAD) / LOOK_AHEAD_GRANULARITY) * LOOK_AHEAD_GRANULARITY;

        if (newLookAhead > _currentLookAhead)
        {
            foreach (var characterBehaviour in _characterBehaviours)
            {
                if (characterBehaviour.Value.IdleClip.end < newLookAhead)
                {
                    characterBehaviour.Value.IdleClip.duration = newLookAhead - characterBehaviour.Value.IdleClip.start;
                }
            }
            _currentLookAhead = newLookAhead;
        }
        while (_battleActive && _battleLockEnd < _currentLookAhead)
        {
            var turnData = new TurnDisplayData();
            turnData.Turn = _battleController.GenerateTurn();
            if (turnData.Turn == null)
            {
                _battleActive = false;
                break;
            }
            turnData.TimelineAssetData  = GetTimelineAssetData(turnData.Turn);
            turnData.CharacterBehaviour = _characterBehaviours[turnData.Turn.Character];
            turnData.TargetBehaviours   = new List <BattleCharacterBehaviour>();
            for (int i = 0; i < turnData.Turn.Targets.Count; i++)
            {
                Character target = turnData.Turn.Targets[i];
                turnData.TargetBehaviours.Add(_characterBehaviours[target]);
            }

            var turnStart   = CalculateLocks(turnData);
            var controlClip = turnData.CharacterBehaviour.BattleDirectorTrack.CreateClip <BattleDirectorAsset>();
            controlClip.start    = turnStart;
            controlClip.duration = turnData.TimelineAssetData.Asset.duration;
            var controlClipAsset = (BattleDirectorAsset)controlClip.asset;
            controlClipAsset.TurnDisplayData           = turnData;
            controlClipAsset.TurnDisplayData.StartTime = turnStart;
            controlClipAsset.TurnDisplayData.EndTime   = turnStart + turnData.TimelineAssetData.Asset.duration;

            if (controlClip.start < turnData.CharacterBehaviour.IdleClip.end)
            {
                var newDuration = controlClip.start - turnData.CharacterBehaviour.IdleClip.start;
                if (newDuration > 0)
                {
                    turnData.CharacterBehaviour.IdleClip.duration = newDuration;
                }
                else
                {
                    turnData.CharacterBehaviour.BattleDirectorTrack.timelineAsset.DeleteClip(turnData.CharacterBehaviour.IdleClip);
                }
                CreateIdleClip(turnData.CharacterBehaviour, controlClip.end);
            }

            for (int targetIndex = 0; targetIndex < turnData.TimelineAssetData.TargetLocks.Count; targetIndex++)
            {
                var targetLock      = turnData.TimelineAssetData.TargetLocks[targetIndex];
                var targetLockStart = targetLock.Start + turnStart;
                var targetLockEnd   = targetLock.End + turnStart;
                var targetBehaviour = turnData.TargetBehaviours[targetIndex];
                if (targetLockStart <= targetBehaviour.IdleClip.end && targetBehaviour.IdleClip.start <= targetLockEnd)
                {
                    var newDuration = targetLockStart - targetBehaviour.IdleClip.start;
                    if (newDuration > 0)
                    {
                        targetBehaviour.IdleClip.duration = newDuration;
                    }
                    else
                    {
                        targetBehaviour.BattleDirectorTrack.timelineAsset.DeleteClip(targetBehaviour.IdleClip);
                    }
                    CreateIdleClip(targetBehaviour, targetLockEnd);
                }
            }

            timelineUpdated = true;
        }
        if (timelineUpdated)
        {
            _playableDirector.initialTime = _playableDirector.time;
            _playableDirector.RebuildGraph();
        }
    }