private void DeleteClip(MorphAnimationClip clip) { int index = _morphAnimator.Clips.IndexOf(clip); if (_morphAnimator.DefaultClipIndex >= index) { _morphAnimator.DefaultClipIndex -= 1; } _morphAnimator.Clips.Remove(clip); _currentClip = null; _currentKeyframe = null; if (_morphAnimator.DefaultClipIndex == -1 && _morphAnimator.Clips.Count > 0) { _morphAnimator.DefaultClipIndex = 0; } for (int i = 0; i < _morphAnimator.Clips.Count; i++) { if (_morphAnimator.Clips[i].TransitionClip == index) { _morphAnimator.Clips[i].TransitionClip = -1; } else if (_morphAnimator.Clips[i].TransitionClip > index) { _morphAnimator.Clips[i].TransitionClip -= 1; } } }
public void Init(SkinnedMeshRenderer skinnedMesh, MorphAnimationData data, MorphAnimator animator) { _skinnedMeshRenderer = skinnedMesh; _morphAnimationData = data; _morphAnimator = animator; _currentClip = null; _currentKeyframe = null; _currentBone = null; _currentBoneParent = null; _keepingDistance = 0; _isRecord = false; _isPreview = false; _previewIndex = 0; _previewLocation = 0; _isRenameClip = false; _newNameClip = ""; _keyframeView = Vector2.zero; _clipSizeWidth = 150; _clipSizeHeight = 30; _moveCenter = Vector2.zero; _keyframePropertyViewWidth = 0; _keyframePropertyViewHeight = 0; _keyframePropertyView = Vector2.zero; _boneNameFiltrate = ""; _clipPropertyViewWidth = 0; _clipPropertyViewHeight = 0; ReviewClips(); }
private void EventCallBack(MorphAnimationKeyframe frame) { if (frame.EventCallBack.CallTarget && frame.EventCallBack.CallMethod != "<None>") { frame.EventCallBack.CallTarget.SendMessage(frame.EventCallBack.CallMethod); } }
private void DeleteKeyframe() { _currentClip.Keyframes.Remove(_currentKeyframe); _currentKeyframe = null; if (_currentClip.Keyframes.Count < 2) { _currentClip.Eligible = false; } }
private void SelectKeyframe(MorphAnimationKeyframe frame) { _currentKeyframe = frame; for (int i = 0; i < _skinnedMeshRenderer.bones.Length; i++) { _skinnedMeshRenderer.bones[i].localPosition = frame.Positions[i]; _skinnedMeshRenderer.bones[i].localRotation = frame.Rotations[i]; _skinnedMeshRenderer.bones[i].localScale = frame.Scales[i]; } }
public void CopyBy(MorphAnimationKeyframe frame) { for (int i = 0; i < Positions.Length; i++) { Positions[i] = frame.Positions[i]; Rotations[i] = frame.Rotations[i]; Scales[i] = frame.Scales[i]; } EventCallBack = new MorphCallBack(); Time = frame.Time; }
private void CloneKeyframe() { MorphAnimationKeyframe frame = new MorphAnimationKeyframe(_morphAnimationData); frame.CopyBy(_currentKeyframe); _currentClip.Keyframes.Add(frame); _currentKeyframe = frame; if (_currentClip.Keyframes.Count >= 2) { _currentClip.Eligible = true; } }
private void UpdateAnimationTransition() { MorphAnimationKeyframe currentframe = _currentClip.Keyframes[_playIndex]; MorphAnimationKeyframe lastframe; if (_playIndex >= _currentClip.Keyframes.Count - 1) { lastframe = Clips[_currentClip.TransitionClip].Keyframes[0]; } else { lastframe = _currentClip.Keyframes[_playIndex + 1]; } if (_playLocation <= currentframe.Time) { _playLocation += Speed * (IgnoreTimeScale ? Time.fixedDeltaTime : Time.deltaTime); } else { _playIndex += 1; _playLocation = 0f; if (_playIndex >= _currentClip.Keyframes.Count) { SwitchClip(Clips[_currentClip.TransitionClip]); return; } EventCallBack(_currentClip.Keyframes[_playIndex]); return; } float location = _playLocation / currentframe.Time; for (int i = 0; i < _skinnedMeshRenderer.bones.Length; i++) { _skinnedMeshRenderer.bones[i].localPosition = Vector3.Lerp(currentframe.Positions[i], lastframe.Positions[i], location); _skinnedMeshRenderer.bones[i].localRotation = Quaternion.Lerp(currentframe.Rotations[i], lastframe.Rotations[i], location); _skinnedMeshRenderer.bones[i].localScale = Vector3.Lerp(currentframe.Scales[i], lastframe.Scales[i], location); } }
private void PreviewAnimation() { if (_isPreview) { MorphAnimationKeyframe currentframe = _currentClip.Keyframes[_previewIndex]; MorphAnimationKeyframe lastframe; if (_previewIndex + 1 >= _currentClip.Keyframes.Count) { lastframe = _currentClip.Keyframes[0]; } else { lastframe = _currentClip.Keyframes[_previewIndex + 1]; } if (_previewLocation <= currentframe.Time) { _previewLocation += Time.deltaTime; } else { _previewIndex += 1; _previewLocation = 0f; if (_previewIndex >= _currentClip.Keyframes.Count) { _previewIndex = 0; } return; } float location = _previewLocation / currentframe.Time; for (int i = 0; i < _skinnedMeshRenderer.bones.Length; i++) { _skinnedMeshRenderer.bones[i].localPosition = Vector3.Lerp(currentframe.Positions[i], lastframe.Positions[i], location); _skinnedMeshRenderer.bones[i].localRotation = Quaternion.Lerp(currentframe.Rotations[i], lastframe.Rotations[i], location); _skinnedMeshRenderer.bones[i].localScale = Vector3.Lerp(currentframe.Scales[i], lastframe.Scales[i], location); } } }
private void SelectClip(MorphAnimationClip clip) { _currentClip = clip; _currentKeyframe = null; }