From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Scripts/XEditor/XCutSceneEditor/XActor.cs | 169 ++++++++++++++++++ .../Scripts/XEditor/XCutSceneEditor/XActor.cs.meta | 8 + .../XEditor/XCutSceneEditor/XCutSceneCamera.cs | 175 +++++++++++++++++++ .../XCutSceneEditor/XCutSceneCamera.cs.meta | 8 + .../Scripts/XEditor/XCutSceneEditor/XCutSceneUI.cs | 77 +++++++++ .../XEditor/XCutSceneEditor/XCutSceneUI.cs.meta | 8 + .../XEditor/XCutSceneEditor/XScriptStandalone.cs | 191 +++++++++++++++++++++ .../XCutSceneEditor/XScriptStandalone.cs.meta | 8 + 8 files changed, 644 insertions(+) create mode 100644 Client/Assets/Scripts/XEditor/XCutSceneEditor/XActor.cs create mode 100644 Client/Assets/Scripts/XEditor/XCutSceneEditor/XActor.cs.meta create mode 100644 Client/Assets/Scripts/XEditor/XCutSceneEditor/XCutSceneCamera.cs create mode 100644 Client/Assets/Scripts/XEditor/XCutSceneEditor/XCutSceneCamera.cs.meta create mode 100644 Client/Assets/Scripts/XEditor/XCutSceneEditor/XCutSceneUI.cs create mode 100644 Client/Assets/Scripts/XEditor/XCutSceneEditor/XCutSceneUI.cs.meta create mode 100644 Client/Assets/Scripts/XEditor/XCutSceneEditor/XScriptStandalone.cs create mode 100644 Client/Assets/Scripts/XEditor/XCutSceneEditor/XScriptStandalone.cs.meta (limited to 'Client/Assets/Scripts/XEditor/XCutSceneEditor') diff --git a/Client/Assets/Scripts/XEditor/XCutSceneEditor/XActor.cs b/Client/Assets/Scripts/XEditor/XCutSceneEditor/XActor.cs new file mode 100644 index 00000000..10da6925 --- /dev/null +++ b/Client/Assets/Scripts/XEditor/XCutSceneEditor/XActor.cs @@ -0,0 +1,169 @@ +#if UNITY_EDITOR +using UnityEngine; +using XEditor; +using XUtliPoolLib; +using UnityEditor; + +namespace XEditor +{ + internal class XActor + { + private GameObject _actor = null; + private Transform _shadow = null; + private Transform _bip = null; + private Animator _ator = null; + + private static Terrain _terrain = null; + + private AudioSource _audio_motion = null; + private AudioSource _audio_action = null; + private AudioSource _audio_skill = null; + + static XActor() + { + _terrain = Terrain.activeTerrain; + /*if (_terrain == null) + { + SceneTable.RowData sceneConf = XSceneMgr.singleton.GetSceneData(_scene_id); + if (sceneConf.BlockFilePath.Length > 0) + { + _grid = new XGrid(); + if (!_grid.LoadFile(@"Assets\Resources\" + sceneConf.BlockFilePath)) + { + Debug.Log(@"Load Grid file: Assets\Resources\" + sceneConf.BlockFilePath + " failed!"); + _grid = null; + } + } + }*/ + } + + public GameObject Actor { get { return _actor; } } + public Transform Bip { get { return _bip; } } + + public XActor(float x, float y, float z, string clip) + { + _actor = AssetDatabase.LoadAssetAtPath("Assets/Editor/EditorResources/Prefabs/ZJ_zhanshi.prefab", typeof(GameObject)) as GameObject; + _actor = UnityEngine.Object.Instantiate(_actor) as GameObject; + DisablePhysic(); + _actor.transform.position = new Vector3(x, y, z); + _ator = _actor.GetComponent(); + + AnimatorOverrideController overrideController = new AnimatorOverrideController(); + + overrideController.runtimeAnimatorController = _ator.runtimeAnimatorController; + _ator.runtimeAnimatorController = overrideController; + + overrideController["Idle"] = XResourceLoaderMgr.singleton.GetSharedResource(clip, ".anim"); + + _shadow = _actor.transform.Find("Shadow"); + if (_shadow != null) _shadow.GetComponent().enabled = true; + + _ator.cullingMode = AnimatorCullingMode.AlwaysAnimate; + } + + public XActor(string prefab, float x, float y, float z, string clip) + { + _actor = XResourceLoaderMgr.singleton.CreateFromPrefab(prefab, new Vector3(x, y, z), Quaternion.identity) as GameObject; + _ator = _actor.GetComponent(); + DisablePhysic(); + if (_ator != null) + { + AnimatorOverrideController overrideController = new AnimatorOverrideController(); + + overrideController.runtimeAnimatorController = _ator.runtimeAnimatorController; + _ator.runtimeAnimatorController = overrideController; + + overrideController["Idle"] = XResourceLoaderMgr.singleton.GetSharedResource(clip, ".anim"); + + _shadow = _actor.transform.Find("Shadow"); + if (_shadow != null) _shadow.GetComponent().enabled = true; + + _ator.cullingMode = AnimatorCullingMode.AlwaysAnimate; + } + } + + public XActor(uint id, float x, float y, float z, string clip) + { + _actor = UnityEngine.Object.Instantiate(XStatisticsLibrary.GetDummy(id), new Vector3(x, y, z), Quaternion.identity) as GameObject; + _ator = _actor.GetComponent(); + DisablePhysic(); + AnimatorOverrideController overrideController = new AnimatorOverrideController(); + + overrideController.runtimeAnimatorController = _ator.runtimeAnimatorController; + _ator.runtimeAnimatorController = overrideController; + + overrideController["Idle"] = XResourceLoaderMgr.singleton.GetSharedResource(clip, ".anim"); + + _shadow = _actor.transform.Find("Shadow"); + if (_shadow != null) _shadow.GetComponent().enabled = true; + + _ator.cullingMode = AnimatorCullingMode.AlwaysAnimate; + } + private void DisablePhysic() + { + if (_actor != null) + { + CharacterController cc = _actor.GetComponent(); + if (cc != null) cc.enabled = false; + } + } + public void Update(float fDelta) + { + StickShadow(); + } + + public AudioSource GetAudioSourceByChannel(AudioChannel channel) + { + switch (channel) + { + case AudioChannel.Action: + { + if (_audio_action == null) + _audio_action = _actor.AddComponent(); + + return _audio_action; + } + case AudioChannel.Motion: + { + if (_audio_motion == null) + _audio_motion = _actor.AddComponent(); + + return _audio_motion; + } + case AudioChannel.Skill: + { + if (_audio_skill == null) + _audio_skill = _actor.AddComponent(); + + return _audio_skill; + } + } + + return _audio_action; + } + + protected void StickShadow() + { + if (_bip == null) return; + + Vector3 shadow_pos; + + shadow_pos.x = _bip.position.x; + shadow_pos.z = _bip.position.z; + shadow_pos.y = XActor.TerrainY(_bip.transform.position) + 0.02f; + + _shadow.position = shadow_pos; + } + + public static float TerrainY(Vector3 pos) + { + if (_terrain != null) + { + return _terrain.SampleHeight(pos); + } + + return 0; + } + } +} +#endif \ No newline at end of file diff --git a/Client/Assets/Scripts/XEditor/XCutSceneEditor/XActor.cs.meta b/Client/Assets/Scripts/XEditor/XCutSceneEditor/XActor.cs.meta new file mode 100644 index 00000000..6a6a396d --- /dev/null +++ b/Client/Assets/Scripts/XEditor/XCutSceneEditor/XActor.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bd3b38fa8b5218048b476a668d580aaa +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/XEditor/XCutSceneEditor/XCutSceneCamera.cs b/Client/Assets/Scripts/XEditor/XCutSceneEditor/XCutSceneCamera.cs new file mode 100644 index 00000000..dd33f871 --- /dev/null +++ b/Client/Assets/Scripts/XEditor/XCutSceneEditor/XCutSceneCamera.cs @@ -0,0 +1,175 @@ +#if UNITY_EDITOR +using System; +using UnityEngine; +using XUtliPoolLib; + +namespace XEditor +{ + internal class XCutSceneCamera + { + private GameObject _cameraObject = null; + + private GameObject _dummyObject = null; + private Transform _dummyCamera = null; + private Transform _cameraTransform = null; + + private Animator _ator = null; + public AnimatorOverrideController _overrideController = new AnimatorOverrideController(); + + private UnityEngine.Camera _camera = null; + + private bool _root_pos_inited = false; + + private Vector3 _root_pos = Vector3.zero; + + private Quaternion _idle_root_rotation = Quaternion.identity; + private Vector3 _dummyCamera_pos = Vector3.zero; + + private CameraMotionSpace _effect_axis = CameraMotionSpace.World; + private XCameraMotionData _motion = new XCameraMotionData(); + + public XActor Target = null; + + private string _trigger = null; + + public UnityEngine.Camera UnityCamera + { + get { return _camera; } + } + + public Transform CameraTrans + { + get { return _cameraTransform; } + } + + public Animator CameraAnimator + { + get { return _ator; } + } + + public Vector3 Position + { + get { return _cameraTransform.position; } + } + + public Quaternion Rotaton + { + get { return _cameraTransform.rotation; } + } + + public bool Initialize() + { + _cameraObject = GameObject.Find(@"Main Camera"); + + if (null != _cameraObject) + { + _camera = _cameraObject.GetComponent(); + _cameraTransform = _cameraObject.transform; + + XResourceLoaderMgr.SafeDestroy(ref _dummyObject); + _dummyObject = XResourceLoaderMgr.singleton.CreateFromPrefab("Prefabs/DummyCamera") as GameObject; + _dummyObject.name = "Dummy Camera"; + + _dummyCamera = _dummyObject.transform.GetChild(0); + _ator = _dummyObject.GetComponent(); + + _overrideController.runtimeAnimatorController = _ator.runtimeAnimatorController; + _ator.runtimeAnimatorController = _overrideController; + + _root_pos_inited = false; + } + + return true; + } + + public void OverrideAnimClip(string motion, string clipname) + { + //get override clip + AnimationClip animClip = XResourceLoaderMgr.singleton.GetSharedResource(clipname, ".anim"); + OverrideAnimClip(motion, animClip); + } + + public void OverrideAnimClip(string motion, AnimationClip clip) + { + //override + if (clip != null && _overrideController[motion] != clip) _overrideController[motion] = clip; + } + + public void PostUpdate(float fDeltaT) + { + if (!_root_pos_inited) + { + _root_pos = _dummyCamera.position; + _root_pos_inited = true; + + _idle_root_rotation = _motion.Follow_Position ? Quaternion.Euler(0, 180, 0) : Quaternion.identity; + } + + InnerUpdateEx(); + TriggerEffect(); + } + + private void InnerPosition() + { + _dummyCamera_pos = _idle_root_rotation * (_dummyCamera.position - _dummyObject.transform.position) + _dummyObject.transform.position; + } + + private void InnerUpdateEx() + { + InnerPosition(); + + Vector3 v_self_p = Target == null ? Vector3.zero : Target.Actor.transform.position; + + Vector3 forward = Vector3.Cross(_dummyCamera.forward, _dummyCamera.up); + Quaternion q = Quaternion.LookRotation(forward, _dummyCamera.up); + + Vector3 delta = (_dummyCamera_pos - _root_pos); + Vector3 target_pos = _root_pos + (_motion.Follow_Position ? v_self_p : Vector3.zero); + + _cameraTransform.rotation = _idle_root_rotation * q; + + switch (_effect_axis) + { + case CameraMotionSpace.World: + { + target_pos += delta; + } break; + } + + _cameraTransform.position = target_pos; + } + + public void Effect(XCameraMotionData motion) + { + //must be called from UPDATE pass + AnimationClip clip = XResourceLoaderMgr.singleton.GetSharedResource(motion.Motion, ".anim"); + + if (clip != null) + { + _trigger = "ToEffect"; + if (_overrideController["CameraEffect"] != clip) _overrideController["CameraEffect"] = clip; + + _motion.Follow_Position = motion.Follow_Position; + _motion.Coordinate = motion.Coordinate; + _motion.AutoSync_At_Begin = motion.AutoSync_At_Begin; + _motion.LookAt_Target = motion.LookAt_Target; + + _motion.Motion = motion.Motion; + } + } + + private void TriggerEffect() + { + if (_trigger != null && !_ator.IsInTransition(0)) + { + _effect_axis = _motion.Coordinate; + + _ator.SetTrigger(_trigger); + _root_pos_inited = false; + + _trigger = null; + } + } + } +} +#endif \ No newline at end of file diff --git a/Client/Assets/Scripts/XEditor/XCutSceneEditor/XCutSceneCamera.cs.meta b/Client/Assets/Scripts/XEditor/XCutSceneEditor/XCutSceneCamera.cs.meta new file mode 100644 index 00000000..6a416832 --- /dev/null +++ b/Client/Assets/Scripts/XEditor/XCutSceneEditor/XCutSceneCamera.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: dee1aadae6624184e959a5e3a447de60 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/XEditor/XCutSceneEditor/XCutSceneUI.cs b/Client/Assets/Scripts/XEditor/XCutSceneEditor/XCutSceneUI.cs new file mode 100644 index 00000000..ad881dae --- /dev/null +++ b/Client/Assets/Scripts/XEditor/XCutSceneEditor/XCutSceneUI.cs @@ -0,0 +1,77 @@ +#if UNITY_EDITOR +using UnityEngine; +using XUtliPoolLib; +using XEditor; + +public class XCutSceneUI : XSingleton +{ + public UISprite m_BG; + public UILabel m_Text; + public UILabel m_Skip; + public UIPlayTween m_IntroTween; + public UILabel m_Name; + + public GameObject _objUI; + + public override bool Init() + { + UIPanel p = NGUITools.CreateUI(false); + + _objUI = XResourceLoaderMgr.singleton.CreateFromPrefab("UI/Common/CutSceneUI") as GameObject; + + if (null != _objUI) + { + _objUI.transform.parent = p.transform; + _objUI.transform.localPosition = new Vector3(0.0f, 0.0f, 0); + _objUI.transform.localScale = new Vector3(1, 1, 1); + } + + UIRoot rt = p.gameObject.GetComponent(); + rt.scalingStyle = UIRoot.Scaling.FixedSize; + rt.manualHeight = 1148; + + m_Text = _objUI.transform.Find("_canvas/DownBG/Text").GetComponent(); + + m_Name = _objUI.transform.Find("_canvas/Intro/Name").GetComponent(); + m_IntroTween = _objUI.transform.Find("_canvas/Intro").GetComponent(); + + m_Text.text = ""; + + _objUI.SetActive(false); + m_IntroTween.gameObject.SetActive(false); + return true; + } + + public void SetText(string text) + { + m_Text.text = text; + } + + public void SetVisible(bool visible) + { + _objUI.SetActive(visible); + } + + public void SetIntroText(bool enabled, string name, string text, float x, float y) + { + if (!_objUI.activeInHierarchy) return; + + if (enabled) + { + m_Name.text = name; + + m_IntroTween.gameObject.transform.localPosition = new Vector2(x, y); + m_IntroTween.tweenGroup = 0; + m_IntroTween.ResetByGroup(true, 0); + m_IntroTween.Play(true); + + } + else + { + m_IntroTween.tweenGroup = 1; + m_IntroTween.ResetByGroup(true, 1); + m_IntroTween.Play(true); + } + } +} +#endif \ No newline at end of file diff --git a/Client/Assets/Scripts/XEditor/XCutSceneEditor/XCutSceneUI.cs.meta b/Client/Assets/Scripts/XEditor/XCutSceneEditor/XCutSceneUI.cs.meta new file mode 100644 index 00000000..be172409 --- /dev/null +++ b/Client/Assets/Scripts/XEditor/XCutSceneEditor/XCutSceneUI.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 608b30d1d55920f469da985b4a5289d0 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Client/Assets/Scripts/XEditor/XCutSceneEditor/XScriptStandalone.cs b/Client/Assets/Scripts/XEditor/XCutSceneEditor/XScriptStandalone.cs new file mode 100644 index 00000000..bdaac549 --- /dev/null +++ b/Client/Assets/Scripts/XEditor/XCutSceneEditor/XScriptStandalone.cs @@ -0,0 +1,191 @@ +#if UNITY_EDITOR +using UnityEngine; +using XEditor; +using XUtliPoolLib; +using System.Collections.Generic; +using System.Collections; + +public class XScriptStandalone : MonoBehaviour +{ + private XCutSceneCamera _cut_scene_camera = null; + private List _actors = new List(); + + private uint _token = 0; + + [SerializeField] + public XCutSceneData _cut_scene_data = null; + + public GameObject _ui_root; + + // Use this for initialization + void Start () + { + _cut_scene_camera = new XCutSceneCamera(); + _cut_scene_camera.Initialize(); + + XCameraMotionData m = new XCameraMotionData(); + m.AutoSync_At_Begin = false; + m.Coordinate = CameraMotionSpace.World; + m.Follow_Position = _cut_scene_data.GeneralShow; + m.LookAt_Target = false; + m.At = 0; + m.Motion = _cut_scene_data.CameraClip; + + _cut_scene_camera.Effect(m); + _cut_scene_camera.UnityCamera.fieldOfView = _cut_scene_data.FieldOfView; + + XCutSceneUI.singleton.Init(); + XCutSceneUI.singleton.SetText(""); + + if (!_cut_scene_data.GeneralShow) + { + foreach (XActorDataClip clip in _cut_scene_data.Actors) + { + XResourceLoaderMgr.singleton.GetSharedResource(clip.Clip, ".anim"); + XTimerMgr.singleton.SetTimer(clip.TimeLineAt / 30.0f - 0.016f, BeOnStage, clip); + } + + foreach (XPlayerDataClip clip in _cut_scene_data.Player) + { + XResourceLoaderMgr.singleton.GetSharedResource(clip.Clip1, ".anim"); + XTimerMgr.singleton.SetTimer(clip.TimeLineAt / 30.0f - 0.016f, BePlayerOnStage, clip); + } + + foreach (XFxDataClip clip in _cut_scene_data.Fxs) + { + XTimerMgr.singleton.SetTimer(clip.TimeLineAt / 30.0f, Fx, clip); + } + } + + foreach (XAudioDataClip clip in _cut_scene_data.Audios) + { + XTimerMgr.singleton.SetTimer(clip.TimeLineAt / 30.0f, Audio, clip); + } + + if (_cut_scene_data.AutoEnd) XTimerMgr.singleton.SetTimer((_cut_scene_data.TotalFrame - 30) / 30.0f, EndShow, null); + + if (_cut_scene_data.Mourningborder) + { + XCutSceneUI.singleton.SetVisible(true); + + foreach (XSubTitleDataClip clip in _cut_scene_data.SubTitle) + { + XTimerMgr.singleton.SetTimer(clip.TimeLineAt / 30.0f, SubTitle, clip); + } + + foreach (XSlashDataClip clip in _cut_scene_data.Slash) + { + XTimerMgr.singleton.SetTimer(clip.TimeLineAt / 30.0f, Slash, clip); + } + } + } + + // Update is called once per frame + void Update () + { + XTimerMgr.singleton.Update(Time.deltaTime); + + foreach (XActor actor in _actors) + actor.Update(Time.deltaTime); + } + + void BePlayerOnStage(object o) + { + XPlayerDataClip clip = o as XPlayerDataClip; + _actors.Add(new XActor(clip.AppearX, clip.AppearY, clip.AppearZ, clip.Clip1)); + } + + void BeOnStage(object o) + { + XActor target = null; + + XActorDataClip clip = o as XActorDataClip; + if(clip.bUsingID) + target = new XActor((uint)clip.StatisticsID, clip.AppearX, clip.AppearY, clip.AppearZ, clip.Clip); + else + target = new XActor(clip.Prefab, clip.AppearX, clip.AppearY, clip.AppearZ, clip.Clip); + + _actors.Add(target); + } + + void Fx(object o) + { + XFxDataClip clip = o as XFxDataClip; + + Transform transform = (clip.BindIdx < 0) ? null : _actors[clip.BindIdx].Actor.transform; + if (clip.Bone != null && clip.Bone.Length > 0) + transform = transform.Find(clip.Bone); + else + transform = null; + + XFx fx = XFxMgr.singleton.CreateFx(clip.Fx); + + fx.DelayDestroy = clip.Destroy_Delay; + if (transform != null) + fx.Play(transform,Vector3.zero, clip.Scale * Vector3.one, 1, clip.Follow); + else + fx.Play(new Vector3(clip.AppearX, clip.AppearY, clip.AppearZ), XCommon.singleton.FloatToQuaternion(clip.Face),Vector3.one); + } + + void Audio(object o) + { + XAudioDataClip clip = o as XAudioDataClip; + + if (clip.BindIdx < 0) return; + + //AudioClip audio = XResourceLoaderMgr.singleton.GetSharedResource(clip.Clip); + //AudioSource source = _actors[clip.BindIdx].GetAudioSourceByChannel(clip.Channel); + + XFmod fmod = _actors[clip.BindIdx].Actor.GetComponent(); + if(fmod == null) + fmod = _actors[clip.BindIdx].Actor.AddComponent(); + + fmod.StartEvent("event:/" + clip.Clip, clip.Channel); + //source.Stop(); + + //source.clip = audio; + //source.volume = clip.Volume; + //source.loop = clip.Loop; + //source.Play(); + } + + void SubTitle(object o) + { + XSubTitleDataClip clip = o as XSubTitleDataClip; + + XCutSceneUI.singleton.SetText(clip.Context); + XTimerMgr.singleton.KillTimer(_token); + + _token = XTimerMgr.singleton.SetTimer(clip.Duration / 30.0f, EndSubTitle, null); + } + + void Slash(object o) + { + XSlashDataClip clip = o as XSlashDataClip; + + XCutSceneUI.singleton.SetIntroText(true, clip.Name, clip.Discription, clip.AnchorX, clip.AnchorY); + + XTimerMgr.singleton.SetTimer(clip.Duration, EndSlash, null); + } + + void EndShow(object o) + { + XTimerMgr.singleton.KillTimer(_token); + } + + void EndSlash(object o) + { + XCutSceneUI.singleton.SetIntroText(false, "", "", 0, 0); + } + + void EndSubTitle(object o) + { + XCutSceneUI.singleton.SetText(""); + } + + void LateUpdate() + { + _cut_scene_camera.PostUpdate(Time.deltaTime); + } +} +#endif \ No newline at end of file diff --git a/Client/Assets/Scripts/XEditor/XCutSceneEditor/XScriptStandalone.cs.meta b/Client/Assets/Scripts/XEditor/XCutSceneEditor/XScriptStandalone.cs.meta new file mode 100644 index 00000000..e64b53bd --- /dev/null +++ b/Client/Assets/Scripts/XEditor/XCutSceneEditor/XScriptStandalone.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ed8a14250c743d94ab894b0e2200a094 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: -- cgit v1.1-26-g67d0