diff --git a/Assets/DLFMSample/Delos - Light Above The Sky.mp3 b/Assets/DLFMSample/Delos - Light Above The Sky.mp3 new file mode 100644 index 0000000..daf552d Binary files /dev/null and b/Assets/DLFMSample/Delos - Light Above The Sky.mp3 differ diff --git a/Assets/DLFMSample/Delos - Light Above The Sky.mp3.meta b/Assets/DLFMSample/Delos - Light Above The Sky.mp3.meta new file mode 100644 index 0000000..87c74e8 --- /dev/null +++ b/Assets/DLFMSample/Delos - Light Above The Sky.mp3.meta @@ -0,0 +1,22 @@ +fileFormatVersion: 2 +guid: d84f8a3f700c39d4d94537bbcba24761 +AudioImporter: + externalObjects: {} + serializedVersion: 6 + defaultSettings: + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + preloadAudioData: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/DLFMSample/NewAudioMixer.mixer b/Assets/DLFMSample/NewAudioMixer.mixer new file mode 100644 index 0000000..51789d3 --- /dev/null +++ b/Assets/DLFMSample/NewAudioMixer.mixer @@ -0,0 +1,135 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!241 &24100000 +AudioMixerController: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: NewAudioMixer + m_OutputGroup: {fileID: 0} + m_MasterGroup: {fileID: 24300002} + m_Snapshots: + - {fileID: 24500006} + m_StartSnapshot: {fileID: 24500006} + m_SuspendThreshold: -80 + m_EnableSuspend: 1 + m_UpdateMode: 0 + m_ExposedParameters: [] + m_AudioMixerGroupViews: + - guids: + - 2e56caa10b03d2b48aab4d11c12021f7 + - 322533cf3b9bba54584be71d6bc4c36f + - 63b5d0aadf6defc4781ccf27dcd3212e + name: View + m_CurrentViewIndex: 0 + m_TargetSnapshot: {fileID: 24500006} +--- !u!243 &24300002 +AudioMixerGroupController: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Master + m_AudioMixer: {fileID: 24100000} + m_GroupID: 2e56caa10b03d2b48aab4d11c12021f7 + m_Children: + - {fileID: 243159630443108008} + - {fileID: 243736800746631566} + m_Volume: 85383db9e6fd2ad4ba49edc92f6a7a9f + m_Pitch: f99a7c2f1d68ef64eb65af7db3f17ed1 + m_Effects: + - {fileID: 24400004} + m_UserColorIndex: 0 + m_Mute: 0 + m_Solo: 0 + m_BypassEffects: 0 +--- !u!244 &24400004 +AudioMixerEffectController: + m_ObjectHideFlags: 3 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_EffectID: 86d94f750707f2d4f9cb7c6464b9d5a1 + m_EffectName: Attenuation + m_MixLevel: 7e9ab68080b4c9e46b36a29d476d393c + m_Parameters: [] + m_SendTarget: {fileID: 0} + m_EnableWetMix: 0 + m_Bypass: 0 +--- !u!245 &24500006 +AudioMixerSnapshotController: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Snapshot + m_AudioMixer: {fileID: 24100000} + m_SnapshotID: cc1460d2ebb162843827ceb9fc034609 + m_FloatValues: {} + m_TransitionOverrides: {} +--- !u!243 &243159630443108008 +AudioMixerGroupController: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: BackGroundMusic + m_AudioMixer: {fileID: 24100000} + m_GroupID: 322533cf3b9bba54584be71d6bc4c36f + m_Children: [] + m_Volume: 787fd58580bbb35458e71c261e11cc44 + m_Pitch: 26725e43732261647832ccb90cc7079a + m_Effects: + - {fileID: 244373443531088772} + m_UserColorIndex: 0 + m_Mute: 0 + m_Solo: 0 + m_BypassEffects: 0 +--- !u!243 &243736800746631566 +AudioMixerGroupController: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Effect + m_AudioMixer: {fileID: 24100000} + m_GroupID: 63b5d0aadf6defc4781ccf27dcd3212e + m_Children: [] + m_Volume: 6de58d687e55c0a4fa82619c024845d7 + m_Pitch: 18cc243afd30f214bb836ca7698be735 + m_Effects: + - {fileID: 244419882805022256} + m_UserColorIndex: 0 + m_Mute: 0 + m_Solo: 0 + m_BypassEffects: 0 +--- !u!244 &244373443531088772 +AudioMixerEffectController: + m_ObjectHideFlags: 3 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_EffectID: ecb49877185562e44936148d9fd39962 + m_EffectName: Attenuation + m_MixLevel: b92ea95f9be369b43a29ec95d0c682e2 + m_Parameters: [] + m_SendTarget: {fileID: 0} + m_EnableWetMix: 0 + m_Bypass: 0 +--- !u!244 &244419882805022256 +AudioMixerEffectController: + m_ObjectHideFlags: 3 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_EffectID: 5e443c88f838b1144872ebb4c03e53cc + m_EffectName: Attenuation + m_MixLevel: 8ec2a7a74e8ab3444b52ddc990af0003 + m_Parameters: [] + m_SendTarget: {fileID: 0} + m_EnableWetMix: 0 + m_Bypass: 0 diff --git a/Assets/DLFMSample/NewAudioMixer.mixer.meta b/Assets/DLFMSample/NewAudioMixer.mixer.meta new file mode 100644 index 0000000..48f2e52 --- /dev/null +++ b/Assets/DLFMSample/NewAudioMixer.mixer.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b639d1633d0edae448d51635e8c53c91 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 24100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/DLFMSample/Scripts/BGMController.cs b/Assets/DLFMSample/Scripts/BGMController.cs new file mode 100644 index 0000000..a58907d --- /dev/null +++ b/Assets/DLFMSample/Scripts/BGMController.cs @@ -0,0 +1,28 @@ +using Event; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Level +{ + public class BGMController : MonoBehaviour + { + [SerializeField] private AudioSource source; + + private void Awake() + { + if (source == null) { source = GetComponent(); } + EventManager.onStateChange.AddListener(OnStateChange, Priority.Lowest); + } + + private StateChangeEventArgs OnStateChange(StateChangeEventArgs e) + { + if (!e.canceled) + { + if (e.newState == GameState.Playing) { source.Play(); } + if (e.newState == GameState.WaitingRespawn) { source.Pause(); } + } + return e; + } + } +} diff --git a/Assets/DLFMSample/Scripts/BGMController.cs.meta b/Assets/DLFMSample/Scripts/BGMController.cs.meta new file mode 100644 index 0000000..8577f87 --- /dev/null +++ b/Assets/DLFMSample/Scripts/BGMController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1c66be0ea05c72448a8fb54eae0e753e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/DLFMSample/Scripts/CameraFollower.cs b/Assets/DLFMSample/Scripts/CameraFollower.cs index d3aadca..c68e19c 100644 --- a/Assets/DLFMSample/Scripts/CameraFollower.cs +++ b/Assets/DLFMSample/Scripts/CameraFollower.cs @@ -9,35 +9,15 @@ namespace Level { public class CameraFollower : MonoBehaviour { - public class Task - { - public Vector3 startRotation; - public Vector3 targetRotation; - public float startDistance; - public float targetDistance; - public AnimationCurve curve; - public float startTime = 0f; - - public Task(Vector3 arg1, Vector3 arg2, float arg3, float arg4, AnimationCurve arg5) - { - this.startRotation = arg1; - this.targetRotation = arg2; - this.startDistance = arg3; - this.targetDistance = arg4; - this.curve = arg5; - } - } - public Transform line; public float distance; private Vector3 currentVelocity = Vector3.zero; public float smoothTime; + public bool enable; private Vector3 followPoint; private Vector3 vector; - private Task runningTask; private Tweener rotaterX; private Tweener rotaterY; - private Tweener rotaterZ; private Tweener distanceChanger; void Start() @@ -47,22 +27,12 @@ void Start() vector = (transform.position - followPoint) / Vector3.Distance(transform.position, followPoint) * distance; } - void Update() + void Update() { + if (!enable) return; followPoint = Vector3.SmoothDamp(followPoint, line.position, ref currentVelocity, smoothTime); transform.LookAt(followPoint); transform.position = followPoint + vector; - /* - if (runningTask != null) - { - if (runningTask.startTime == 0f) - runningTask.startTime = Time.time; - Rotate(Vector3.Lerp(runningTask.startRotation, runningTask.targetRotation, runningTask.curve.Evaluate(Time.time - runningTask.startTime)), Mathf.Lerp(runningTask.startDistance, runningTask.targetDistance, runningTask.curve.Evaluate(Time.time - runningTask.startTime))); - distance = Vector3.Distance(followPoint, transform.position); - if (Time.time >= runningTask.startTime + runningTask.curve.length) - runningTask = null; - } - */ } /// @@ -74,32 +44,28 @@ void Update() /// 时间曲线 public void Rotate(Vector2 target, float distance, float duration, AnimationCurve curve) { + if (!enable) return; if (rotaterX != null) - { + { rotaterX.Kill(false); rotaterX = null; - } + } if (rotaterY != null) { rotaterY.Kill(false); rotaterY = null; } - if (rotaterZ != null) - { - rotaterZ.Kill(false); - rotaterZ = null; - } if (distanceChanger != null) - { + { distanceChanger.Kill(false); distanceChanger = null; - } - if (target.x != transform.eulerAngles.x) - rotaterX = DOTween.To(() => transform.eulerAngles.x, x => { transform.RotateAround(followPoint, Vector3.right, x - transform.eulerAngles.x); }, target.x, duration).SetEase(curve); - if (target.y != transform.eulerAngles.y) - rotaterY = DOTween.To(() => transform.eulerAngles.y, y => { transform.RotateAround(followPoint, Vector3.up, y - transform.eulerAngles.y); }, target.y, duration).SetEase(curve); - if (Vector3.Distance(transform.position, followPoint) != distance) - distanceChanger = DOTween.To(() => Vector3.Distance(transform.position, followPoint), d => vector = (transform.position - followPoint) / Vector3.Distance(transform.position, followPoint) * d, distance, duration).SetEase(curve); - } - } + } + if (target.x != transform.eulerAngles.x) + rotaterX = DOTween.To(() => transform.eulerAngles.x, x => { transform.RotateAround(followPoint, Vector3.right, x - transform.eulerAngles.x); }, target.x, duration).SetEase(curve); + if (target.y != transform.eulerAngles.y) + rotaterY = DOTween.To(() => transform.eulerAngles.y, y => { transform.RotateAround(followPoint, Vector3.up, y - transform.eulerAngles.y); }, target.y, duration).SetEase(curve); + if (Vector3.Distance(transform.position, followPoint) != distance) + distanceChanger = DOTween.To(() => Vector3.Distance(transform.position, followPoint), d => vector = (transform.position - followPoint) / Vector3.Distance(transform.position, followPoint) * d, distance, duration).SetEase(curve); + } + } } diff --git a/Assets/DLFMSample/Scripts/Events/EventManager.cs b/Assets/DLFMSample/Scripts/Events/EventManager.cs new file mode 100644 index 0000000..ee8fd04 --- /dev/null +++ b/Assets/DLFMSample/Scripts/Events/EventManager.cs @@ -0,0 +1,86 @@ +using Level; +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Events; + +namespace Event +{ + public enum Priority + { + Highest, + High, + Normal, + Low, + Lowest + } + + public class HandlerAttributes + { + public Func action; + public Priority priority; + + public HandlerAttributes(Func action, Priority priority) + { + this.action = action; + this.priority = priority; + } + } + + public class EventBase + { + private static LinkedList> handlers = new LinkedList>(); + + public void AddListener(Func action, Priority priority) + { + if (priority == Priority.Lowest) + { + handlers.AddLast(new HandlerAttributes(action, priority)); + return; + } + foreach (HandlerAttributes handler in handlers) + { + if ((int)handler.priority < (int)priority) + { + handlers.AddBefore(handlers.Find(handler), new HandlerAttributes(action, priority)); + break; + } + } + } + + public void RemoveListener(Func action) + { + foreach (HandlerAttributes handler in handlers) + { + if (action == handler.action) + { + handlers.Remove(handlers.Find(handler)); + break; + } + } + } + + public void Invoke(T arg) + { + foreach (HandlerAttributes handler in handlers) + { + arg = handler.action.Invoke(arg); + } + } + } + + public static class EventManager + { + public class StateChangeEvent: EventBase + { + public void Invoke(GameState oldState, GameState newState) + { + Invoke(new StateChangeEventArgs(oldState, newState)); + } + } + + + public static StateChangeEvent onStateChange = new StateChangeEvent(); + } +} diff --git a/Assets/DLFMSample/Scripts/Events/EventManager.cs.meta b/Assets/DLFMSample/Scripts/Events/EventManager.cs.meta new file mode 100644 index 0000000..5f1621b --- /dev/null +++ b/Assets/DLFMSample/Scripts/Events/EventManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d2179921c4113a44fa89a047d64c65e1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/DLFMSample/Scripts/Events/GameOverEventArgs.cs b/Assets/DLFMSample/Scripts/Events/GameOverEventArgs.cs new file mode 100644 index 0000000..4d1763e --- /dev/null +++ b/Assets/DLFMSample/Scripts/Events/GameOverEventArgs.cs @@ -0,0 +1,17 @@ +using Level; +using System.Collections; +using System.Collections.Generic; + +namespace Event +{ + public class GameOverEventArgs + { + public readonly DeathCause deathCause; + public bool canceled = false; + + public GameOverEventArgs(DeathCause deathCause) + { + this.deathCause = deathCause; + } + } +} \ No newline at end of file diff --git a/Assets/DLFMSample/Scripts/Events/GameOverEventArgs.cs.meta b/Assets/DLFMSample/Scripts/Events/GameOverEventArgs.cs.meta new file mode 100644 index 0000000..38ae829 --- /dev/null +++ b/Assets/DLFMSample/Scripts/Events/GameOverEventArgs.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f3375e2eecb180e41bf17050b32f8c2e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/DLFMSample/Scripts/Events/LineDieEventArgs.cs b/Assets/DLFMSample/Scripts/Events/LineDieEventArgs.cs new file mode 100644 index 0000000..9f31aa1 --- /dev/null +++ b/Assets/DLFMSample/Scripts/Events/LineDieEventArgs.cs @@ -0,0 +1,20 @@ +using Level; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Event +{ + public class LineDieEventArgs + { + public readonly Line line; + public readonly DeathCause cause; + public bool canceled = false; + + public LineDieEventArgs (Line line, DeathCause cause) + { + this.line = line; + this.cause = cause; + } + } +} diff --git a/Assets/DLFMSample/Scripts/Events/LineDieEventArgs.cs.meta b/Assets/DLFMSample/Scripts/Events/LineDieEventArgs.cs.meta new file mode 100644 index 0000000..9fc48cc --- /dev/null +++ b/Assets/DLFMSample/Scripts/Events/LineDieEventArgs.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 781d2c652e11a7145bfdf7156c601008 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/DLFMSample/Scripts/Events/LineTurnEventArgs.cs b/Assets/DLFMSample/Scripts/Events/LineTurnEventArgs.cs new file mode 100644 index 0000000..379902b --- /dev/null +++ b/Assets/DLFMSample/Scripts/Events/LineTurnEventArgs.cs @@ -0,0 +1,24 @@ +using Level; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Event +{ + public class LineTurnEventArgs + { + public readonly Line line; + public readonly Vector3 lastway; + public Vector3 newway; + public bool foucs; + public bool canceled = false; + + public LineTurnEventArgs(Line line, Vector3 lastway, Vector3 newway, bool foucs) + { + this.line = line; + this.lastway = lastway; + this.newway = newway; + this.foucs = foucs; + } + } +} diff --git a/Assets/DLFMSample/Scripts/Events/LineTurnEventArgs.cs.meta b/Assets/DLFMSample/Scripts/Events/LineTurnEventArgs.cs.meta new file mode 100644 index 0000000..58a8321 --- /dev/null +++ b/Assets/DLFMSample/Scripts/Events/LineTurnEventArgs.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a25a37bdc9e970e4296ebeca6236ec1f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/DLFMSample/Scripts/Events/StateChange.cs b/Assets/DLFMSample/Scripts/Events/StateChangeEventArgs.cs similarity index 71% rename from Assets/DLFMSample/Scripts/Events/StateChange.cs rename to Assets/DLFMSample/Scripts/Events/StateChangeEventArgs.cs index 0759871..a8fd65f 100644 --- a/Assets/DLFMSample/Scripts/Events/StateChange.cs +++ b/Assets/DLFMSample/Scripts/Events/StateChangeEventArgs.cs @@ -4,14 +4,13 @@ namespace Event { - public class StateChangeEvent + public class StateChangeEventArgs { public readonly GameState lastState; public readonly GameState newState; public bool canceled = false; - public string test; - public StateChangeEvent(GameState lastState, GameState newState) + public StateChangeEventArgs(GameState lastState, GameState newState) { this.lastState = lastState; this.newState = newState; diff --git a/Assets/DLFMSample/Scripts/Events/StateChange.cs.meta b/Assets/DLFMSample/Scripts/Events/StateChangeEventArgs.cs.meta similarity index 100% rename from Assets/DLFMSample/Scripts/Events/StateChange.cs.meta rename to Assets/DLFMSample/Scripts/Events/StateChangeEventArgs.cs.meta diff --git a/Assets/DLFMSample/Scripts/GameController.cs b/Assets/DLFMSample/Scripts/GameController.cs index 3806736..add229d 100644 --- a/Assets/DLFMSample/Scripts/GameController.cs +++ b/Assets/DLFMSample/Scripts/GameController.cs @@ -28,23 +28,14 @@ public enum GameState public class GameController : MonoBehaviour { - [Serializable] - public class EventsClass - { - public delegate void StateChange(ref StateChangeEvent arg); - public UnityEvent onStart = new UnityEvent(); - public StateChange OnStateChange; - } - [HideInInspector] public static GameController instance = null; public Button bgButton; - public static EventsClass events = new EventsClass(); private static GameState _state = GameState.SelectingSkins; public static GameState State { get { return _state; } - set { RunStateChangeEvent(value); } + set { if (_state != value) { EventManager.onStateChange.Invoke(_state, value); } } } public static bool IsStarted @@ -52,36 +43,20 @@ public static bool IsStarted get { return !(_state == GameState.SelectingSkins || _state == GameState.WaitingStart); } } - private static void RunStateChangeEvent() + private static StateChangeEventArgs OnStateChange(StateChangeEventArgs arg) { - RunStateChangeEvent((GameState)((int)_state + 1)); - } - - private static void RunStateChangeEvent(GameState newState) - { - StateChangeEvent arg = new StateChangeEvent(_state, newState); - try { events.OnStateChange.BeginInvoke(ref arg, ar => { events.OnStateChange.EndInvoke(ref arg, ar); StateChangeEventCompleted(arg); }, null); } - catch (NullReferenceException) { StateChangeEventCompleted(arg); } - } - - private static void StateChangeEventCompleted(StateChangeEvent arg) - { - Debug.Log("test: " + arg.test); - if (arg.canceled) - return; - _state = arg.newState; - switch (_state) - { - case GameState.Playing: - events.onStart.Invoke(); - instance.bgButton.onClick.RemoveListener(RunStateChangeEvent); - break; - } + if (!arg.canceled) + _state = arg.newState; + return arg; } private void Awake() - { - bgButton.onClick.AddListener(RunStateChangeEvent); + { + bgButton.onClick.AddListener(() => { + if (_state != GameState.Playing && _state != GameState.WaitingRespawn && (int)_state + 1 < Enum.GetNames(typeof(GameState)).Length) + State = (GameState)((int)_state + 1); + }); + EventManager.onStateChange.AddListener(OnStateChange, Priority.Lowest); if (instance == null && instance != this) instance = this; else diff --git a/Assets/DLFMSample/Scripts/Line.cs b/Assets/DLFMSample/Scripts/Line.cs index 06d9191..b1726f5 100644 --- a/Assets/DLFMSample/Scripts/Line.cs +++ b/Assets/DLFMSample/Scripts/Line.cs @@ -1,3 +1,4 @@ +using Event; using System; using System.Collections; using System.Collections.Generic; @@ -12,10 +13,8 @@ public class Line : MonoBehaviour [Serializable] public class EventsClass { - [Serializable] - public class DieEvent : UnityEvent { } - public UnityEvent onTurn; - public DieEvent onDie; + public EventBase onTurn = new EventBase(); + public EventBase onDie = new EventBase(); public UnityEvent OnExitGround; public UnityEvent OnEnterGround; } @@ -62,21 +61,28 @@ public bool IsGrounded private void UpdateTurnListener(bool value) { if (value) - GameController.instance.bgButton.onClick.AddListener(() => { Turn(false); }); - else - GameController.instance.bgButton.onClick.RemoveListener(() => { Turn(false); }); + if (GameController.IsStarted) { GameController.instance.bgButton.onClick.AddListener(() => { Turn(false); }); } + else + if (GameController.IsStarted) { GameController.instance.bgButton.onClick.RemoveListener(() => { Turn(false); }); } } void Awake() { rigidbody = GetComponent(); - GameController.events.onStart.AddListener(() => { if (_controlled) moving = true;}); + EventManager.onStateChange.AddListener((StateChangeEventArgs e) => { + if (e.newState == GameState.Playing && !e.canceled) + { + moving = true; + if (_controlled) { GameController.instance.bgButton.onClick.AddListener(() => { Turn(false); }); } + } + return e; + }, Priority.Lowest); + events.onDie.AddListener(OnDie, Priority.Lowest); + events.onTurn.AddListener(OnTurn, Priority.Lowest); } void Start() { - UpdateTurnListener(_controlled); - bodiesParent = new GameObject("Bodies").transform; previousFrameIsGrounded = IsGrounded; } @@ -112,53 +118,61 @@ void Update() } } - private void CreateBody() - { - if (body != null && (transform.localScale.z / 2) < Vector3.Distance(lastTurnPosition, transform.position)) - { - body.localScale += Vector3.forward * transform.localScale.z / 2; - body.Translate(Vector3.forward * transform.localScale.z / 4, Space.Self); - } - body = Instantiate(bodyObject, transform.position, transform.rotation, bodiesParent).transform; - lastTurnPosition = transform.position; - } - /// /// ʹÏßתÍä /// /// Ç¿ÖÆתÍä(¼´ÎÞÊÓcontrolled, IsGrounded, State) public void Turn(bool focus) { - if ((_controlled && IsGrounded && GameController.State == GameState.Playing) || focus) - { - (transform.localEulerAngles, nextWay) = (nextWay, transform.localEulerAngles); - CreateBody(); + events.onTurn.Invoke(new LineTurnEventArgs(this, transform.localEulerAngles, nextWay, focus)); + } + + public LineDieEventArgs OnDie(LineDieEventArgs e) + { + if (!e.canceled) + { + switch (e.cause) + { + case DeathCause.Obstacle: + moving = false; + rigidbody.isKinematic = true; + break; + } } + return e; } - /// - /// ¸øÒ¯ËÀ - /// - /// ÔõôËÀµÄ - public void Die(DeathCause deathCause) + public LineTurnEventArgs OnTurn(LineTurnEventArgs e) { - switch (deathCause) + if (!e.canceled) { - case DeathCause.Obstacle: - moving = false; - rigidbody.isKinematic = true; - break; - } - events.onDie.Invoke(deathCause); + if ((IsGrounded && GameController.State == GameState.Playing) || e.foucs) + { + (transform.localEulerAngles, nextWay) = (nextWay, transform.localEulerAngles); + CreateBody(); + } + } + return e; } void OnCollisionEnter(Collision collision) { touchings.Add(collision.gameObject); - if (collision.gameObject.CompareTag("Obstacle")) - Die(DeathCause.Obstacle); - } + if (collision.gameObject.CompareTag("Obstacle")) { events.onDie.Invoke(new LineDieEventArgs(this, DeathCause.Obstacle)); } + } private void OnCollisionExit(Collision collision) { touchings.Remove(collision.gameObject); } + + private void CreateBody() + { + if (bodiesParent == null) { bodiesParent = new GameObject("Bodies").transform; } + if (body != null && (transform.localScale.z / 2) < Vector3.Distance(lastTurnPosition, transform.position)) + { + body.localScale += Vector3.forward * transform.localScale.z / 2; + body.Translate(Vector3.forward * transform.localScale.z / 4, Space.Self); + } + body = Instantiate(bodyObject, transform.position, transform.rotation, bodiesParent).transform; + lastTurnPosition = transform.position; + } } } diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index bf74797..d383fa1 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -616,12 +616,6 @@ MonoBehaviour: moving: 0 _controlled: 1 events: - onTurn: - m_PersistentCalls: - m_Calls: [] - onDie: - m_PersistentCalls: - m_Calls: [] OnExitGround: m_PersistentCalls: m_Calls: [] @@ -879,6 +873,8 @@ GameObject: - component: {fileID: 963194226} - component: {fileID: 963194229} - component: {fileID: 963194230} + - component: {fileID: 963194232} + - component: {fileID: 963194231} m_Layer: 0 m_Name: Main Camera m_TagString: MainCamera @@ -916,7 +912,7 @@ Camera: y: 0 width: 1 height: 1 - near clip plane: 0.3 + near clip plane: 0.01 far clip plane: 1000 field of view: 60 orthographic: 0 @@ -977,7 +973,118 @@ MonoBehaviour: m_EditorClassIdentifier: line: {fileID: 711418601} distance: 30 - smoothTime: 0.3 + smoothTime: 0.5 + enable: 1 +--- !u!114 &963194231 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 963194225} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1c66be0ea05c72448a8fb54eae0e753e, type: 3} + m_Name: + m_EditorClassIdentifier: + source: {fileID: 0} +--- !u!82 &963194232 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 963194225} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 243159630443108008, guid: b639d1633d0edae448d51635e8c53c91, + type: 2} + m_audioClip: {fileID: 8300000, guid: d84f8a3f700c39d4d94537bbcba24761, type: 3} + m_PlayOnAwake: 0 + m_Volume: 1 + m_Pitch: 1 + Loop: 0 + Mute: 0 + Spatialize: 0 + SpatializePostEffects: 0 + Priority: 128 + DopplerLevel: 1 + MinDistance: 1 + MaxDistance: 500 + Pan2D: 0 + rolloffMode: 0 + BypassEffects: 0 + BypassListenerEffects: 0 + BypassReverbZones: 0 + rolloffCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + panLevelCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + spreadCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + reverbZoneMixCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 --- !u!1 &1231657479 GameObject: m_ObjectHideFlags: 0