public static void CreateEmptySkill(string SkillId, GameObject PlayerModel, ModelTargetType modelType, RuntimeAnimatorController controll) { string ModelName = PlayerModel.name; GameObject ShowRoot = new GameObject("ShowRoot_" + SkillId); //获取模型 实例化 GameObject Player = null; if (PlayerModel != null) { Player = UnityEngine.Object.Instantiate(PlayerModel) as GameObject; Player.name = ModelName; Player.transform.parent = ShowRoot.transform; } else { Player = new GameObject(ModelName); Player.transform.parent = ShowRoot.transform; } //获取animator 赋值 if (controll != null) { if (Player.GetComponent <Animator>() == null) { Player.AddComponent <Animator>(); } Player.GetComponent <Animator>().runtimeAnimatorController = controll; } GameObject newSequence = new GameObject("Sequence_" + ModelName); JSequencer sequence = newSequence.AddComponent <JSequencer>(); JTimelineContainer ccontainer = sequence.CreateNewTimelineContainer(Player.transform); JTimelineAnimation aniline = (JTimelineAnimation)ccontainer.AddNewTimeline(TimeLineType.Animation); /* foreach (SkillNames.GuideAction gui in Enum.GetValues(typeof(SkillNames.GuideAction))) * { * JAnimationTrack track = aniline.AddNewTrack(); * track.name = SkillNames.ActionNames[(int)gui]; * }*/ JTimelineEffect effectline = (JTimelineEffect)ccontainer.AddNewTimeline(TimeLineType.Effect); foreach (SkillNames.Effect gui in Enum.GetValues(typeof(SkillNames.Effect))) { JEffectTrack track = effectline.AddNewTrack(); track.name = SkillNames.EffectNames[(int)gui]; } /* JTimelineSound soundline = (JTimelineSound)ccontainer.AddNewTimeline(TimeLineType.Sound); * foreach (SkillNames.Sound gui in Enum.GetValues(typeof(SkillNames.Sound))) * { * JSoundTrack track = soundline.AddNewTrack(); * track.name = SkillNames.SoundNames[(int)gui]; * }*/ }
//生成序列 public static JSequencer GenerateSequence(SkillAssetData skillart) { //id 名称 string SkillId = EditorDataContainer.GetSkillStringById(skillart.skillArt.id); //模型名称 string ModelName = skillart.skillArt.modelName; //起始动作 string guideAction = skillart.skillArt.guideAction; //持续动作 string guidingAction = skillart.skillArt.guidingAction; //结束动作 string endAction = skillart.skillArt.endAction; //animator名称 string animatorName = skillart.skillArt.animationController; RuntimeAnimatorController animationControllerObj = skillart.skillArt.animationControllerObj; //模型类型 主角 NPC ModelTargetType modelType = skillart.skillArt.modelType; //技能列表 List <SkillEffectUnit> beginEffect = skillart.skillArt.beginEffect; //技能列表 List <SkillEffectUnit> unitEffect = skillart.skillArt.unitEffect; //技能列表 List <SkillEffectUnit> tipEffect = skillart.skillArt.tipEffect; //技能列表 List <SkillEffectUnit> hitEffect = skillart.skillArt.hitEffect; GameObject ShowRoot = new GameObject("ShowRoot_" + SkillId); //获取模型 实例化 GameObject PlayerModel = AssetUtility.GetFBXAsset(modelType, ModelName); GameObject Player = null; if (PlayerModel != null) { Player = UnityEngine.Object.Instantiate(PlayerModel) as GameObject; Player.name = ModelName; Player.transform.parent = ShowRoot.transform; } else { Player = new GameObject(ModelName); Player.transform.parent = ShowRoot.transform; } //获取animator 赋值 RuntimeAnimatorController controll = animationControllerObj;// AssetUtility.GetAnimationCtl(modelType, ModelName, animatorName); if (controll != null) { if (Player.GetComponent <Animator>() == null) { Player.AddComponent <Animator>(); } Player.GetComponent <Animator>().runtimeAnimatorController = controll; } //新建队列 GameObject newSequence = new GameObject("Sequence_" + ModelName); JSequencer sequence = newSequence.AddComponent <JSequencer>(); JTimelineContainer ccontainer = sequence.CreateNewTimelineContainer(Player.transform); JTimelineEffect effectline = (JTimelineEffect)ccontainer.AddNewTimeline(TimeLineType.Effect); if (guideAction != "-1") { JEffectTrack track = effectline.AddNewTrack(); track.name = SkillNames.EffectNames[(int)SkillNames.Effect.GuideAction]; JEffectClipData clip = ScriptableObject.CreateInstance <JEffectClipData>(); clip.effectType = EffectType.Animation; clip.TargetObject = effectline.AffectedObject.gameObject; clip.animController = controll; clip.StateName = guideAction; clip.PlaybackDuration = MecanimAnimationUtility.GetStateDurationWithAnimatorController(guideAction, controll); clip.StartTime = 0; track.AddClip(clip); } if (guidingAction != "-1") { JEffectTrack track = effectline.AddNewTrack(); track.name = SkillNames.EffectNames[(int)SkillNames.Effect.GuidingAction]; JEffectClipData clip = ScriptableObject.CreateInstance <JEffectClipData>(); clip.effectType = EffectType.Animation; clip.TargetObject = effectline.AffectedObject.gameObject; clip.animController = controll; clip.StateName = guidingAction; clip.PlaybackDuration = MecanimAnimationUtility.GetStateDurationWithAnimatorController(guidingAction, controll); float t = guidingAction == "-1" ? 0 : MecanimAnimationUtility.GetStateDurationWithAnimatorController(guideAction, controll); clip.StartTime = t; track.AddClip(clip); } if (endAction != "-1") { JEffectTrack track = effectline.AddNewTrack(); track.name = SkillNames.EffectNames[(int)SkillNames.Effect.EndAction]; float t1 = guideAction == "-1" ? 0 : MecanimAnimationUtility.GetStateDurationWithAnimatorController(guideAction, controll); float t = guidingAction == "-1" ? 0 : MecanimAnimationUtility.GetStateDurationWithAnimatorController(guidingAction, controll); JEffectClipData clip = ScriptableObject.CreateInstance <JEffectClipData>(); clip.effectType = EffectType.Animation; clip.TargetObject = effectline.AffectedObject.gameObject; clip.animController = controll; clip.StateName = endAction; clip.PlaybackDuration = MecanimAnimationUtility.GetStateDurationWithAnimatorController(endAction, controll); clip.StartTime = t1 + t; track.AddClip(clip); } if (beginEffect != null) { //一个特效 一条轨道 foreach (SkillEffectUnit effect in beginEffect) { //特效名称 JEffectTrack track = effectline.AddNewTrack(); int index = beginEffect.IndexOf(effect); if (index > 2) { index = 2; } track.name = SkillNames.EffectNames[(int)SkillNames.Effect.BeginEffect0 + index]; JEffectClipData clip = ScriptableObject.CreateInstance <JEffectClipData>(); clip.effectType = EffectType.Particle; clip.effectunit = effect.Copy(); clip.TargetObject = effectline.AffectedObject.gameObject; clip.PlaybackDuration = (float)effect.artEffect.phaseTime / 1000.0f; clip.StartTime = (float)effect.artEffect.beginTime / 1000.0f; track.AddClip(clip); } } if (unitEffect != null) { //一个特效 一条轨道 foreach (SkillEffectUnit effect in unitEffect) { //特效名称 JEffectTrack track = effectline.AddNewTrack(); track.name = SkillNames.EffectNames[(int)SkillNames.Effect.UnitEffect]; JEffectClipData clip = ScriptableObject.CreateInstance <JEffectClipData>(); clip.effectType = EffectType.Trajectory; clip.effectunit = effect.Copy(); clip.skillunit = skillart.skillUnit.Copy(); clip.TargetObject = effectline.AffectedObject.gameObject; clip.PlaybackDuration = (float)effect.artEffect.phaseTime / 1000.0f; clip.StartTime = (float)effect.artEffect.beginTime / 1000.0f; track.AddClip(clip); } } if (tipEffect != null) { //一个特效 一条轨道 foreach (SkillEffectUnit effect in tipEffect) { //特效名称 JEffectTrack track = effectline.AddNewTrack(); track.name = SkillNames.EffectNames[(int)SkillNames.Effect.TipEffect]; JEffectClipData clip = ScriptableObject.CreateInstance <JEffectClipData>(); clip.effectType = EffectType.Particle; clip.effectunit = effect.Copy(); clip.TargetObject = effectline.AffectedObject.gameObject; clip.PlaybackDuration = (float)effect.artEffect.phaseTime / 1000.0f; clip.StartTime = (float)effect.artEffect.beginTime / 1000.0f; track.AddClip(clip); } } if (hitEffect != null) { //一个特效 一条轨道 foreach (SkillEffectUnit effect in hitEffect) { //特效名称 JEffectTrack track = effectline.AddNewTrack(); track.name = SkillNames.EffectNames[(int)SkillNames.Effect.HitEffect]; JEffectClipData clip = ScriptableObject.CreateInstance <JEffectClipData>(); clip.effectType = EffectType.Particle; clip.effectunit = effect.Copy(); clip.TargetObject = effectline.AffectedObject.gameObject; clip.PlaybackDuration = (float)effect.artEffect.phaseTime / 1000.0f; clip.StartTime = (float)effect.artEffect.beginTime / 1000.0f; track.AddClip(clip); // track.AddClip(effectName, (float)effect.artEffect.beginTime / 1000.0f, (float)effect.artEffect.phaseTime / 1000.0f, effectPrefab, effect.configure); } } if (skillart.skillArt.beginCameraAction != null) { //一个特效 一条轨道 foreach (SkillCameraAction effect in skillart.skillArt.beginCameraAction) { JEffectTrack track = effectline.AddNewTrack(); track.name = SkillNames.EffectNames[(int)SkillNames.Effect.BeginCameraAction]; JEffectClipData clip = ScriptableObject.CreateInstance <JEffectClipData>(); clip.effectType = EffectType.Camera; clip.cameraAction = effect.Copy(); clip.TargetCamera = Camera.main; clip.TargetObject = effectline.AffectedObject.gameObject; clip.PlaybackDuration = (float)effect.phaseTime; clip.StartTime = (float)effect.delay; track.AddClip(clip); } } if (skillart.skillArt.moveCameraAction != null) { foreach (SkillCameraAction effect in skillart.skillArt.moveCameraAction) { JEffectTrack track = effectline.AddNewTrack(); track.name = SkillNames.EffectNames[(int)SkillNames.Effect.MoveCameraAction]; JEffectClipData clip = ScriptableObject.CreateInstance <JEffectClipData>(); clip.effectType = EffectType.Camera; clip.cameraAction = effect.Copy(); clip.TargetCamera = Camera.main; clip.TargetObject = effectline.AffectedObject.gameObject; clip.PlaybackDuration = (float)effect.phaseTime; clip.StartTime = (float)effect.delay; track.AddClip(clip); } } if (skillart.skillArt.hitCameraAction != null) { foreach (SkillCameraAction effect in skillart.skillArt.hitCameraAction) { JEffectTrack track = effectline.AddNewTrack(); track.name = SkillNames.EffectNames[(int)SkillNames.Effect.HitCameraAction]; JEffectClipData clip = ScriptableObject.CreateInstance <JEffectClipData>(); clip.effectType = EffectType.Camera; clip.cameraAction = effect.Copy(); clip.TargetCamera = Camera.main; clip.TargetObject = effectline.AffectedObject.gameObject; clip.PlaybackDuration = (float)effect.phaseTime; clip.StartTime = (float)effect.delay; track.AddClip(clip); } } return(sequence); }
/// <summary> /// 侧边栏渲染 /// </summary> private void DrawSideBarAndTimeLines() { CountClip = 0; foreach (KeyValuePair <UnityEngine.Object, List <JClipRenderData> > kvp in timelineClipRenderDataMap) { foreach (var clip in kvp.Value) { clip.index = CountClip++; } } TypeList = CurrentSequence.SortedTimelinesLists; JTimelineContainer[] containers = CurrentSequence.SortedTimelineContainers; for (int i = 0; i < containers.Length; i++) { GUILayout.BeginVertical(); JTimelineContainer container = containers[i]; GUILayout.BeginHorizontal(); GUILayout.Box(new GUIContent("", ""), USEditorUtility.USeqSkin.GetStyle("TimelinePaneBackground"), GUILayout.Height(lineHeight), GUILayout.MaxWidth(FloatingWidth)); Rect FloatingRect = GUILayoutUtility.GetLastRect(); GUILayout.Box(new GUIContent("", ""), USEditorUtility.USeqSkin.GetStyle("TimelinePaneBackground"), GUILayout.Height(lineHeight), GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); FloatingRect.width -= lineHeight + 1; bool CurcontainerfoldState = false; if (FoldStateDict.ContainsKey(i + 1)) { Rect temp = FloatingRect; temp.width = 20; FoldStateDict[i + 1] = EditorGUI.Foldout(temp, FoldStateDict[i + 1], ""); CurcontainerfoldState = FoldStateDict[i + 1]; Rect temp1 = FloatingRect; temp1.x += 20; // temp1.y -= 1; temp1.width -= 20; // temp1.height -=2; if (GUI.Button(temp1, new GUIContent(container.AffectedObject.name, "模型"), EditorStyles.toolbarButton)) { ResetSelection(); Selection.activeGameObject = container.gameObject; } Rect menuBtn = FloatingRect; menuBtn.x = menuBtn.x + menuBtn.width; menuBtn.width = lineHeight; if (GUI.Button(menuBtn, new GUIContent("", USEditorUtility.DeleteButton, "Delete Timelines"), USEditorUtility.ToolbarButtonSmall)) { GameObject.DestroyImmediate(container.gameObject); } } if (CurcontainerfoldState) { foreach (TimeLineType type in showTypeList) { // TODO: 遍历操作 int index = (int)type; GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Box(new GUIContent("", ""), USEditorUtility.USeqSkin.GetStyle("TimelinePaneBackground"), GUILayout.Height(lineHeight), GUILayout.MaxWidth(FloatingWidth)); Rect FloatingRect1 = GUILayoutUtility.GetLastRect(); GUILayout.Box(new GUIContent("", ""), USEditorUtility.USeqSkin.GetStyle("TimelinePaneBackground"), GUILayout.Height(lineHeight), GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); GUILayout.EndVertical(); FloatingRect1.x = +20; FloatingRect1.width -= (20 + lineHeight + 1); int foldkey = (i + 1) * 100 + index; bool Curfoldstate = false; if (FoldStateDict.ContainsKey(foldkey)) { FoldStateDict[foldkey] = EditorGUI.Foldout(FloatingRect1, FoldStateDict[foldkey], Enum.GetName(typeof(TimeLineType), type)); Curfoldstate = FoldStateDict[foldkey]; } Rect menuBtn = FloatingRect1; menuBtn.x = menuBtn.x + menuBtn.width + 1.0f; menuBtn.width = lineHeight; if (GUI.Button(menuBtn, new GUIContent("", USEditorUtility.MoreButton, "Add Timeline"), USEditorUtility.ToolbarButtonSmall)) { JTimelineBase line = container.AddNewTimeline(type); if (line) { AddNewTrack(line); } } if (Curfoldstate) { List <JTimelineBase> timelines = TypeList[index]; for (int k = 0; k < timelines.Count; k++) { GUILayout.BeginVertical(); JTimelineBase line = timelines[k]; if (line.TimelineContainer == container) { #region ExtensionRegion SideBarAndLineForAnimation(line); SideBarAndLineForParticle(line); SideBarAndLineForSound(line); SideBarAndLineForTranform(line); SideBarAndLineForEvent(line); SideBarAndLineForTrajectory(line); SideBarAndLineForCamera(line); SideBarAndLineForEffect(line); #endregion } GUILayout.EndVertical(); } } } } GUILayout.EndVertical(); } }