first implementation of freeze

This commit is contained in:
Novvator 2021-03-08 14:16:20 +00:00
parent 2b3a950208
commit 660569601d
14 changed files with 188 additions and 27 deletions

View File

@ -0,0 +1,18 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0228856d50ce2a845abd7b3eda114390, type: 3}
m_Name: PA_Freeze
m_EditorClassIdentifier:
_artefactID: 12
_dialogueKey:
_name: Freeze
_power: {fileID: 0}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c2e37ff6639a22e4eacc5e95d8e13723
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -2538,11 +2538,11 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 4676633831318799747, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.y
value: -0.017264403
value: -0.017264389
objectReference: {fileID: 0}
- target: {fileID: 4676633831318799747, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.z
value: 0.009297725
value: 0.009297717
objectReference: {fileID: 0}
- target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalPosition.x
@ -2558,19 +2558,19 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.w
value: 0.9680315
value: 0.9663801
objectReference: {fileID: 0}
- target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.x
value: 0.24655113
value: 0.24613053
objectReference: {fileID: 0}
- target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.y
value: 0.044697862
value: 0.07205816
objectReference: {fileID: 0}
- target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.z
value: -0.011384245
value: -0.018352732
objectReference: {fileID: 0}
- target: {fileID: 4676633831414007564, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_Name
@ -2624,6 +2624,10 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4676633831598614294, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: _freeze
value:
objectReference: {fileID: 11400000, guid: 0cd9cf6494bb6f54d9b97631010d780e, type: 2}
- target: {fileID: 4676633831598614294, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: _cheatBlink
value: 0
@ -2632,6 +2636,22 @@ PrefabInstance:
propertyPath: _cheatBoost
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4676633831598614294, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: _cheatFreeze
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4676633831945762665, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_DefaultControlScheme
value: PCMR
objectReference: {fileID: 0}
- target: {fileID: 4676633831945762666, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: playerTimeScale
value:
objectReference: {fileID: 11400000, guid: 39c05ba9d0743074b9eb0e561ba1fcb8, type: 2}
- target: {fileID: 4676633831945762667, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: playerTimeScale
value:
objectReference: {fileID: 11400000, guid: 39c05ba9d0743074b9eb0e561ba1fcb8, type: 2}
- target: {fileID: 4676633831945762708, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_Height
value: 1.5
@ -2662,11 +2682,11 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 4676633832789495666, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.y
value: -0.017264403
value: -0.017264389
objectReference: {fileID: 0}
- target: {fileID: 4676633832789495666, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.z
value: 0.009297725
value: 0.009297717
objectReference: {fileID: 0}
- target: {fileID: 4676633832858914730, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_XAxis.m_InvertInput
@ -2702,19 +2722,19 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 4676633832928372887, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.w
value: 0.9996367
value: 0.9984866
objectReference: {fileID: 0}
- target: {fileID: 4676633832928372887, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.x
value: 0.0047711134
value: 0.0047656302
objectReference: {fileID: 0}
- target: {fileID: 4676633832928372887, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.y
value: 0.023356276
value: 0.048239034
objectReference: {fileID: 0}
- target: {fileID: 4676633832928372887, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
propertyPath: m_LocalRotation.z
value: -0.0125784995
value: -0.02597908
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3}
@ -7364,6 +7384,7 @@ MonoBehaviour:
inputSettings: {fileID: 11400000, guid: 87faf39b6f22e524984c1680a88045ac, type: 2}
dialogue: {fileID: 11400000, guid: 56369c4e83cc59e44bf55cd16fafc4e8, type: 2}
artefacts: {fileID: 11400000, guid: f523ac0d77530064b8b41c627b13fae0, type: 2}
playerTimeScale: {fileID: 11400000, guid: 39c05ba9d0743074b9eb0e561ba1fcb8, type: 2}
--- !u!114 &2070784759
MonoBehaviour:
m_ObjectHideFlags: 0

View File

@ -16,6 +16,7 @@ public class PickUpDisplay : MonoBehaviour
[SerializeField] private InputSettings inputSettings;
[SerializeField] private DialogueSystem dialogue;
[SerializeField] private ArtefactSystem artefacts;
[SerializeField] private SerialFloat playerTimeScale;
private Artefact chosenArtefact;
@ -35,22 +36,24 @@ public class PickUpDisplay : MonoBehaviour
public void PopUpOn()
{
_paused = true;
artefactUI.SetActive(true);
Player.GetComponent<PlayerInput>().enabled = false;
//artefactUI.SetActive(true);
//Player.GetComponent<PlayerInput>().enabled = false;
artefactText.text = "You have unlocked " + chosenArtefact.Name + "!";
inputSettings.updateMode = (InputSettings.UpdateMode)1;
//inputSettings.updateMode = (InputSettings.UpdateMode)1;
Time.timeScale = 0f;
//playerTimeScale.Value = 0f;
}
public void PopUpOff()
{
_paused = false;
artefactUI.SetActive(false);
inputSettings.updateMode = (InputSettings.UpdateMode)2;
Player.GetComponent<PlayerInput>().enabled = true;
//artefactUI.SetActive(false);
//inputSettings.updateMode = (InputSettings.UpdateMode)2;
//Player.GetComponent<PlayerInput>().enabled = true;
Time.timeScale = 1.0f;
//playerTimeScale.Value = 1.0f;
dialogue.PlayLine(chosenArtefact.dialogueKey);
//dialogue.PlayLine(chosenArtefact.dialogueKey);
chosenArtefact = null;
}
}

View File

@ -1,6 +1,7 @@
using Extensions;
using UnityEngine;
using NaughtyAttributes;
using Ktyl.Util;
public class PlayerController : MonoBehaviour
{
@ -68,6 +69,10 @@ public class PlayerController : MonoBehaviour
private const float TAU = Mathf.PI * 2f;
private const float HALF_PI = Mathf.PI / 2f;
[SerializeField]
private SerialFloat playerTimeScale;
private enum JumpState
{
None,
@ -149,6 +154,17 @@ public class PlayerController : MonoBehaviour
}
}
/*private void UpdateFreeze( float dt)
{
if( _powers.Freeze.CanConsume )
{
Time.timeScale = 0f;
_powers.Freeze.Consume();
}
}
*/
private void UpdateJump(float dt)
{
_fallTime = _grounded ? 0f : (_fallTime + dt);
@ -257,7 +273,7 @@ public class PlayerController : MonoBehaviour
private void FixedUpdate()
{
float dt = Time.fixedDeltaTime;
float dt = Time.fixedUnscaledDeltaTime * playerTimeScale;
_overrideDelta = Vector2.zero;
@ -273,6 +289,7 @@ public class PlayerController : MonoBehaviour
UpdateJump( dt );
UpdateLook( dt );
UpdateBlink( dt );
//UpdateFreeze( dt );
UpdateGravity( dt );
UpdateDrag( dt );
UpdateMovement( dt );

View File

@ -16,20 +16,25 @@ public class PlayerInputHandler : MonoBehaviour
[SerializeField]
private Camera _camera;
[SerializeField]
private SerialFloat playerTimeScale;
public class PlayerInputState
{
public BufferedInput Jump;
public BufferedInput Blink;
public BufferedInput Use;
public BufferedInput Freeze;
public CameraRelativeInput Move;
public Vector2 Look;
public float MoveRotation;
public PlayerInputState( float jumpBuffer, float blinkBuffer, float useBuffer )
public PlayerInputState( float jumpBuffer, float blinkBuffer, float useBuffer , float freezeBuffer)
{
Jump = new BufferedInput( jumpBuffer );
Blink = new BufferedInput( blinkBuffer );
Use = new BufferedInput( useBuffer );
Freeze = new BufferedInput( freezeBuffer );
Move = new CameraRelativeInput();
Look = Vector2.zero;
}
@ -39,6 +44,7 @@ public class PlayerInputHandler : MonoBehaviour
Jump.Update(deltaTime);
Blink.Update(deltaTime);
Use.Update(deltaTime);
Freeze.Update(deltaTime);
}
}
@ -48,16 +54,17 @@ public class PlayerInputHandler : MonoBehaviour
private void Awake()
{
_state = new PlayerInputState(
_inputSettings.JumpBufferTime,
_inputSettings.BlinkBufferTime,
_inputSettings.UseBufferTime
);
_state = new PlayerInputState(
_inputSettings.JumpBufferTime,
_inputSettings.BlinkBufferTime,
_inputSettings.UseBufferTime,
_inputSettings.FreezeBufferTime
) ;
}
private void FixedUpdate()
{
_state.Update( Time.fixedDeltaTime );
_state.Update( Time.fixedDeltaTime);
float cameraRotation = _camera.transform.rotation.eulerAngles.y;
_state.Move.SetAngle(-cameraRotation);
@ -85,4 +92,10 @@ public class PlayerInputHandler : MonoBehaviour
if(context.started)
EventHandler.current.ArtefactPickUp(_nearbyArtefactID.Value);
}
public void Freeze(InputAction.CallbackContext context)
{
_state.Freeze.Set( context.ReadValueAsButton() );
}
}

View File

@ -8,6 +8,7 @@ public class PlayerInputSettings : ScriptableObject
public float JumpBufferTime => _jumpBufferTime;
public float BlinkBufferTime => _blinkBufferTime;
public float UseBufferTime => _useBufferTime;
public float FreezeBufferTime => _freezeBufferTime;
[SerializeField]
private float _jumpBufferTime;
@ -17,4 +18,7 @@ public class PlayerInputSettings : ScriptableObject
[SerializeField]
private float _useBufferTime;
[SerializeField]
private float _freezeBufferTime;
}

View File

@ -12,6 +12,9 @@ public class PlayerPowers : MonoBehaviour
[SerializeField]
private bool _cheatBoost;
[SerializeField]
private bool _cheatFreeze;
[Header( "References" )]
[SerializeField]
private PlayerPower _blink;
@ -19,12 +22,17 @@ public class PlayerPowers : MonoBehaviour
[SerializeField]
private PlayerPower _boost;
[SerializeField]
private PlayerPower _freeze;
public PlayerPower Blink => _blink;
public PlayerPower Boost => _boost;
public PlayerPower Freeze => _freeze;
public void UpdatePowers( float dt, bool grounded )
{
_blink.UpdatePower( dt, _cheatBlink, grounded );
_boost.UpdatePower( dt, _cheatBoost, grounded );
_boost.UpdatePower(dt, _cheatFreeze, grounded);
}
}

View File

@ -44,6 +44,14 @@
"expectedControlType": "Button",
"processors": "",
"interactions": ""
},
{
"name": "Freeze",
"type": "Button",
"id": "29f1599e-fe43-47df-ad25-8e712263d0ab",
"expectedControlType": "Button",
"processors": "",
"interactions": ""
}
],
"bindings": [
@ -200,6 +208,17 @@
"action": "Blink",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "8c9e09a3-477e-4760-bdba-f81beaec4988",
"path": "<Keyboard>/g",
"interactions": "",
"processors": "",
"groups": "PCMR",
"action": "Freeze",
"isComposite": false,
"isPartOfComposite": false
}
]
}

View File

@ -15,3 +15,4 @@ MonoBehaviour:
_jumpBufferTime: 0.1
_blinkBufferTime: 0.1
_useBufferTime: 0.1
_freezeBufferTime: 2

View File

@ -0,0 +1,17 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 24d28ac60e22b5547b2beb8679625039, type: 3}
m_Name: Freeze
m_EditorClassIdentifier:
_regenerateOnGround: 0
_regenerateInAir: 0
_regenerateTime: 0

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0cd9cf6494bb6f54d9b97631010d780e
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,16 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 76553ada4233edc458c3fed9b69e128f, type: 3}
m_Name: playerTimeScale
m_EditorClassIdentifier:
_initialValue: 1
_readOnly: 0

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 39c05ba9d0743074b9eb0e561ba1fcb8
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant: