Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • lolm/open-world
1 result
Select Git revision
Show changes
Commits on Source (2)
Showing
with 985 additions and 500 deletions
No preview for this file type
......@@ -10,10 +10,9 @@ GameObject:
m_Component:
- component: {fileID: 400000}
- component: {fileID: 14300000}
- component: {fileID: 11400000}
- component: {fileID: 5400000}
- component: {fileID: 8200000}
- component: {fileID: 473079243}
- component: {fileID: 473079249}
m_Layer: 0
m_Name: FPSController
m_TagString: Untagged
......@@ -63,6 +62,133 @@ CharacterController:
m_SkinWidth: 0.08
m_MinMoveDistance: 0
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 100000}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 05ec5cf00ca181d45a42ba1870e148c3, type: 3}
m_Name:
m_EditorClassIdentifier:
mask:
serializedVersion: 2
m_Bits: 4294967295
m_IsWalking: 0
m_WalkSpeed: 5
m_RunSpeed: 10
m_RunstepLenghten: 0.7
m_JumpSpeed: 10
m_StickToGroundForce: 10
m_GravityMultiplier: 2
m_MouseLook:
XSensitivity: 2
YSensitivity: 2
clampVerticalRotation: 1
MinimumX: -90
MaximumX: 90
smooth: 0
smoothTime: 5
lockCursor: 1
m_UseFovKick: 1
m_FovKick:
Camera: {fileID: 0}
originalFov: 0
FOVIncrease: 3
TimeToIncrease: 1
TimeToDecrease: 1
IncreaseCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 1
inSlope: 2
outSlope: 2
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
m_UseHeadBob: 1
m_HeadBob:
HorizontalBobRange: 0.1
VerticalBobRange: 0.1
Bobcurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.5
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
- serializedVersion: 3
time: 1.5
value: -1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 2
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
VerticaltoHorizontalRatio: 2
m_JumpBob:
BobDuration: 0.2
BobAmount: 0.1
m_StepInterval: 5
m_FootstepSounds:
- {fileID: 8300000, guid: 42e65e088b3f4374e851b8dbd38f3df9, type: 3}
- {fileID: 8300000, guid: 8bc94ec6ed537e743b481638bdcd503d, type: 3}
m_JumpSound: {fileID: 8300000, guid: 5897aeed9b676024fbb8c694b421a861, type: 3}
m_LandSound: {fileID: 8300000, guid: 3b09d59f4499d45428baa7a21e954296, type: 3}
--- !u!54 &5400000
Rigidbody:
m_ObjectHideFlags: 0
......@@ -186,164 +312,6 @@ AudioSource:
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 0
--- !u!114 &473079243
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 100000}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a7ef4e7e61ae474c92d64cc78b87656e, type: 3}
m_Name:
m_EditorClassIdentifier:
mask:
serializedVersion: 2
m_Bits: 4294967295
m_IsWalking: 0
m_WalkSpeed: 5
m_RunSpeed: 10
m_RunstepLenghten: 0.7
m_JumpSpeed: 10
m_StickToGroundForce: 10
m_GravityMultiplier: 2
m_MouseLook:
XSensitivity: 0.2
YSensitivity: 0.2
clampVerticalRotation: 1
MinimumX: -90
MaximumX: 90
smooth: 0
smoothTime: 5
lockCursor: 1
m_UseFovKick: 1
m_FovKick:
Camera: {fileID: 0}
originalFov: 0
FOVIncrease: 3
TimeToIncrease: 1
TimeToDecrease: 1
IncreaseCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
- serializedVersion: 3
time: 1
value: 1
inSlope: 2
outSlope: 2
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
m_UseHeadBob: 1
m_HeadBob:
HorizontalBobRange: 0.1
VerticalBobRange: 0.1
Bobcurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
- serializedVersion: 3
time: 0.5
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
- serializedVersion: 3
time: 1
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
- serializedVersion: 3
time: 1.5
value: -1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
- serializedVersion: 3
time: 2
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
VerticaltoHorizontalRatio: 2
m_JumpBob:
BobDuration: 0.2
BobAmount: 0.1
m_StepInterval: 5
m_FootstepSounds:
- {fileID: 8300000, guid: 610b4620772375a4f967cfbd83af58ba, type: 3}
- {fileID: 8300000, guid: 8240b86343bbc114b81b0ec5067bfbb6, type: 3}
m_JumpSound: {fileID: 8300000, guid: 5e061e0f4a12b57479168d9ec0b356d6, type: 3}
m_LandSound: {fileID: 8300000, guid: ec20eb1b1cb6fb14bab0d2939b15ae69, type: 3}
--- !u!114 &473079249
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 100000}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 62899f850307741f2a39c98a8b639597, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Actions: {fileID: -944628639613478452, guid: 112606516e989d846ae72910c4279a85,
type: 3}
m_NotificationBehavior: 0
m_UIInputModule: {fileID: 0}
m_DeviceLostEvent:
m_PersistentCalls:
m_Calls: []
m_DeviceRegainedEvent:
m_PersistentCalls:
m_Calls: []
m_ControlsChangedEvent:
m_PersistentCalls:
m_Calls: []
m_ActionEvents: []
m_NeverAutoSwitchControlSchemes: 0
m_DefaultControlScheme:
m_DefaultActionMap: Map
m_SplitScreenIndex: -1
m_Camera: {fileID: 0}
--- !u!1 &100002
GameObject:
m_ObjectHideFlags: 0
......@@ -355,6 +323,7 @@ GameObject:
- component: {fileID: 400002}
- component: {fileID: 2000000}
- component: {fileID: 8100000}
- component: {fileID: 4512692206274578779}
m_Layer: 0
m_Name: FirstPersonCharacter
m_TagString: MainCamera
......@@ -370,7 +339,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 100002}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0.8, z: 0}
m_LocalPosition: {x: 0, y: 1.8, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
......@@ -436,3 +405,47 @@ AudioListener:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 100002}
m_Enabled: 1
--- !u!114 &4512692206274578779
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 100002}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a79441f348de89743a2939f4d699eac1, type: 3}
m_Name:
m_EditorClassIdentifier:
m_RenderShadows: 1
m_RequiresDepthTextureOption: 2
m_RequiresOpaqueTextureOption: 2
m_CameraType: 0
m_Cameras: []
m_RendererIndex: -1
m_VolumeLayerMask:
serializedVersion: 2
m_Bits: 1
m_VolumeTrigger: {fileID: 0}
m_VolumeFrameworkUpdateModeOption: 2
m_RenderPostProcessing: 1
m_Antialiasing: 0
m_AntialiasingQuality: 2
m_StopNaN: 0
m_Dithering: 0
m_ClearDepth: 1
m_AllowXRRendering: 1
m_AllowHDROutput: 1
m_UseScreenCoordOverride: 0
m_ScreenSizeOverride: {x: 0, y: 0, z: 0, w: 0}
m_ScreenCoordScaleBias: {x: 0, y: 0, z: 0, w: 0}
m_RequiresDepthTexture: 0
m_RequiresColorTexture: 0
m_Version: 2
m_TaaSettings:
quality: 3
frameInfluence: 0.1
jitterScale: 1
mipBias: 0
varianceClampScale: 0.9
contrastAdaptiveSharpening: 0
fileFormatVersion: 2
guid: 17d6ce5c2c68a4c41ac4f6e4462bce2c
guid: e9d1257f09cc8c845bc69088e74d6966
PrefabImporter:
externalObjects: {}
userData:
......
fileFormatVersion: 2
guid: 610b4620772375a4f967cfbd83af58ba
guid: 42e65e088b3f4374e851b8dbd38f3df9
AudioImporter:
serializedVersion: 5
format: -1
......
fileFormatVersion: 2
guid: 8240b86343bbc114b81b0ec5067bfbb6
guid: 8bc94ec6ed537e743b481638bdcd503d
AudioImporter:
serializedVersion: 5
format: -1
......
fileFormatVersion: 2
guid: 7c11cd2288a49634084792edfc16ee5b
guid: 5a9383dda6cabc047b7a297602e93eb4
AudioImporter:
serializedVersion: 5
format: -1
......
fileFormatVersion: 2
guid: 88f3ec47a8cb8994ebddfcaebc9b366d
guid: e9714160ce34f2b4ab63ff8c27bd68e1
AudioImporter:
serializedVersion: 5
format: -1
......
fileFormatVersion: 2
guid: 5e061e0f4a12b57479168d9ec0b356d6
guid: 5897aeed9b676024fbb8c694b421a861
AudioImporter:
serializedVersion: 5
format: -1
......
fileFormatVersion: 2
guid: ec20eb1b1cb6fb14bab0d2939b15ae69
guid: 3b09d59f4499d45428baa7a21e954296
AudioImporter:
serializedVersion: 5
format: -1
......
using System;
using UnityEngine;
using UnityEngine.EventSystems;
namespace UnityStandardAssets.CrossPlatformInput
{
public class AxisTouchButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
// designed to work in a pair with another axis touch button
// (typically with one having -1 and one having 1 axisValues)
public string axisName = "Horizontal"; // The name of the axis
public float axisValue = 1; // The axis that the value has
public float responseSpeed = 3; // The speed at which the axis touch button responds
public float returnToCentreSpeed = 3; // The speed at which the button will return to its centre
AxisTouchButton m_PairedWith; // Which button this one is paired with
CrossPlatformInputManager.VirtualAxis m_Axis; // A reference to the virtual axis as it is in the cross platform input
void OnEnable()
{
if (!CrossPlatformInputManager.AxisExists(axisName))
{
// if the axis doesnt exist create a new one in cross platform input
m_Axis = new CrossPlatformInputManager.VirtualAxis(axisName);
CrossPlatformInputManager.RegisterVirtualAxis(m_Axis);
}
else
{
m_Axis = CrossPlatformInputManager.VirtualAxisReference(axisName);
}
FindPairedButton();
}
void FindPairedButton()
{
// find the other button witch which this button should be paired
// (it should have the same axisName)
var otherAxisButtons = FindObjectsOfType(typeof(AxisTouchButton)) as AxisTouchButton[];
if (otherAxisButtons != null)
{
for (int i = 0; i < otherAxisButtons.Length; i++)
{
if (otherAxisButtons[i].axisName == axisName && otherAxisButtons[i] != this)
{
m_PairedWith = otherAxisButtons[i];
}
}
}
}
void OnDisable()
{
// The object is disabled so remove it from the cross platform input system
m_Axis.Remove();
}
public void OnPointerDown(PointerEventData data)
{
if (m_PairedWith == null)
{
FindPairedButton();
}
// update the axis and record that the button has been pressed this frame
m_Axis.Update(Mathf.MoveTowards(m_Axis.GetValue, axisValue, responseSpeed * Time.deltaTime));
}
public void OnPointerUp(PointerEventData data)
{
m_Axis.Update(Mathf.MoveTowards(m_Axis.GetValue, 0, responseSpeed * Time.deltaTime));
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 9ab98b66288df7b4fa182075f2f12bd6
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
using System;
using UnityEngine;
namespace UnityStandardAssets.CrossPlatformInput
{
public class ButtonHandler : MonoBehaviour
{
public string Name;
void OnEnable()
{
}
public void SetDownState()
{
CrossPlatformInputManager.SetButtonDown(Name);
}
public void SetUpState()
{
CrossPlatformInputManager.SetButtonUp(Name);
}
public void SetAxisPositiveState()
{
CrossPlatformInputManager.SetAxisPositive(Name);
}
public void SetAxisNeutralState()
{
CrossPlatformInputManager.SetAxisZero(Name);
}
public void SetAxisNegativeState()
{
CrossPlatformInputManager.SetAxisNegative(Name);
}
public void Update()
{
}
}
}
fileFormatVersion: 2
guid: 85bf3be603548374ca46f521a3aa7fda
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
using System;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput.PlatformSpecific;
namespace UnityStandardAssets.CrossPlatformInput
{
public static class CrossPlatformInputManager
{
public enum ActiveInputMethod
{
Hardware,
Touch
}
private static VirtualInput activeInput;
private static VirtualInput s_TouchInput;
private static VirtualInput s_HardwareInput;
static CrossPlatformInputManager()
{
s_TouchInput = new MobileInput();
s_HardwareInput = new StandaloneInput();
#if MOBILE_INPUT
activeInput = s_TouchInput;
#else
activeInput = s_HardwareInput;
#endif
}
public static void SwitchActiveInputMethod(ActiveInputMethod activeInputMethod)
{
switch (activeInputMethod)
{
case ActiveInputMethod.Hardware:
activeInput = s_HardwareInput;
break;
case ActiveInputMethod.Touch:
activeInput = s_TouchInput;
break;
}
}
public static bool AxisExists(string name)
{
return activeInput.AxisExists(name);
}
public static bool ButtonExists(string name)
{
return activeInput.ButtonExists(name);
}
public static void RegisterVirtualAxis(VirtualAxis axis)
{
activeInput.RegisterVirtualAxis(axis);
}
public static void RegisterVirtualButton(VirtualButton button)
{
activeInput.RegisterVirtualButton(button);
}
public static void UnRegisterVirtualAxis(string name)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
activeInput.UnRegisterVirtualAxis(name);
}
public static void UnRegisterVirtualButton(string name)
{
activeInput.UnRegisterVirtualButton(name);
}
// returns a reference to a named virtual axis if it exists otherwise null
public static VirtualAxis VirtualAxisReference(string name)
{
return activeInput.VirtualAxisReference(name);
}
// returns the platform appropriate axis for the given name
public static float GetAxis(string name)
{
return GetAxis(name, false);
}
public static float GetAxisRaw(string name)
{
return GetAxis(name, true);
}
// private function handles both types of axis (raw and not raw)
private static float GetAxis(string name, bool raw)
{
return activeInput.GetAxis(name, raw);
}
// -- Button handling --
public static bool GetButton(string name)
{
return activeInput.GetButton(name);
}
public static bool GetButtonDown(string name)
{
return activeInput.GetButtonDown(name);
}
public static bool GetButtonUp(string name)
{
return activeInput.GetButtonUp(name);
}
public static void SetButtonDown(string name)
{
activeInput.SetButtonDown(name);
}
public static void SetButtonUp(string name)
{
activeInput.SetButtonUp(name);
}
public static void SetAxisPositive(string name)
{
activeInput.SetAxisPositive(name);
}
public static void SetAxisNegative(string name)
{
activeInput.SetAxisNegative(name);
}
public static void SetAxisZero(string name)
{
activeInput.SetAxisZero(name);
}
public static void SetAxis(string name, float value)
{
activeInput.SetAxis(name, value);
}
public static Vector3 mousePosition
{
get { return activeInput.MousePosition(); }
}
public static void SetVirtualMousePositionX(float f)
{
activeInput.SetVirtualMousePositionX(f);
}
public static void SetVirtualMousePositionY(float f)
{
activeInput.SetVirtualMousePositionY(f);
}
public static void SetVirtualMousePositionZ(float f)
{
activeInput.SetVirtualMousePositionZ(f);
}
// virtual axis and button classes - applies to mobile input
// Can be mapped to touch joysticks, tilt, gyro, etc, depending on desired implementation.
// Could also be implemented by other input devices - kinect, electronic sensors, etc
public class VirtualAxis
{
public string name { get; private set; }
private float m_Value;
public bool matchWithInputManager { get; private set; }
public VirtualAxis(string name)
: this(name, true)
{
}
public VirtualAxis(string name, bool matchToInputSettings)
{
this.name = name;
matchWithInputManager = matchToInputSettings;
}
// removes an axes from the cross platform input system
public void Remove()
{
UnRegisterVirtualAxis(name);
}
// a controller gameobject (eg. a virtual thumbstick) should update this class
public void Update(float value)
{
m_Value = value;
}
public float GetValue
{
get { return m_Value; }
}
public float GetValueRaw
{
get { return m_Value; }
}
}
// a controller gameobject (eg. a virtual GUI button) should call the
// 'pressed' function of this class. Other objects can then read the
// Get/Down/Up state of this button.
public class VirtualButton
{
public string name { get; private set; }
public bool matchWithInputManager { get; private set; }
private int m_LastPressedFrame = -5;
private int m_ReleasedFrame = -5;
private bool m_Pressed;
public VirtualButton(string name)
: this(name, true)
{
}
public VirtualButton(string name, bool matchToInputSettings)
{
this.name = name;
matchWithInputManager = matchToInputSettings;
}
// A controller gameobject should call this function when the button is pressed down
public void Pressed()
{
if (m_Pressed)
{
return;
}
m_Pressed = true;
m_LastPressedFrame = Time.frameCount;
}
// A controller gameobject should call this function when the button is released
public void Released()
{
m_Pressed = false;
m_ReleasedFrame = Time.frameCount;
}
// the controller gameobject should call Remove when the button is destroyed or disabled
public void Remove()
{
UnRegisterVirtualButton(name);
}
// these are the states of the button which can be read via the cross platform input system
public bool GetButton
{
get { return m_Pressed; }
}
public bool GetButtonDown
{
get
{
return m_LastPressedFrame - Time.frameCount == -1;
}
}
public bool GetButtonUp
{
get
{
return (m_ReleasedFrame == Time.frameCount - 1);
}
}
}
}
}
fileFormatVersion: 2
guid: 6ac1ce5a5adfd9f46adbf5b6f752a47c
labels:
- Done
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: -1010
icon: {instanceID: 0}
userData:
assetBundleName:
......@@ -2,50 +2,53 @@ using System;
using UnityEngine;
[Serializable]
public class CurveControlledBob
namespace UnityStandardAssets.Utility
{
public float HorizontalBobRange = 0.33f;
public float VerticalBobRange = 0.33f;
public AnimationCurve Bobcurve = new AnimationCurve(new Keyframe(0f, 0f), new Keyframe(0.5f, 1f),
new Keyframe(1f, 0f), new Keyframe(1.5f, -1f),
new Keyframe(2f, 0f)); // sin curve for head bob
public float VerticaltoHorizontalRatio = 1f;
private float m_CyclePositionX;
private float m_CyclePositionY;
private float m_BobBaseInterval;
private Vector3 m_OriginalCameraPosition;
private float m_Time;
public void Setup(Camera camera, float bobBaseInterval)
[Serializable]
public class CurveControlledBob
{
m_BobBaseInterval = bobBaseInterval;
m_OriginalCameraPosition = camera.transform.localPosition;
// get the length of the curve in time
m_Time = Bobcurve[Bobcurve.length - 1].time;
}
public float HorizontalBobRange = 0.33f;
public float VerticalBobRange = 0.33f;
public AnimationCurve Bobcurve = new AnimationCurve(new Keyframe(0f, 0f), new Keyframe(0.5f, 1f),
new Keyframe(1f, 0f), new Keyframe(1.5f, -1f),
new Keyframe(2f, 0f)); // sin curve for head bob
public float VerticaltoHorizontalRatio = 1f;
private float m_CyclePositionX;
private float m_CyclePositionY;
private float m_BobBaseInterval;
private Vector3 m_OriginalCameraPosition;
private float m_Time;
public Vector3 DoHeadBob(float speed)
{
float xPos = m_OriginalCameraPosition.x + (Bobcurve.Evaluate(m_CyclePositionX)*HorizontalBobRange);
float yPos = m_OriginalCameraPosition.y + (Bobcurve.Evaluate(m_CyclePositionY)*VerticalBobRange);
m_CyclePositionX += (speed*Time.deltaTime)/m_BobBaseInterval;
m_CyclePositionY += ((speed*Time.deltaTime)/m_BobBaseInterval)*VerticaltoHorizontalRatio;
if (m_CyclePositionX > m_Time)
public void Setup(Camera camera, float bobBaseInterval)
{
m_CyclePositionX = m_CyclePositionX - m_Time;
m_BobBaseInterval = bobBaseInterval;
m_OriginalCameraPosition = camera.transform.localPosition;
// get the length of the curve in time
m_Time = Bobcurve[Bobcurve.length - 1].time;
}
if (m_CyclePositionY > m_Time)
public Vector3 DoHeadBob(float speed)
{
m_CyclePositionY = m_CyclePositionY - m_Time;
float xPos = m_OriginalCameraPosition.x + (Bobcurve.Evaluate(m_CyclePositionX)*HorizontalBobRange);
float yPos = m_OriginalCameraPosition.y + (Bobcurve.Evaluate(m_CyclePositionY)*VerticalBobRange);
m_CyclePositionX += (speed*Time.deltaTime)/m_BobBaseInterval;
m_CyclePositionY += ((speed*Time.deltaTime)/m_BobBaseInterval)*VerticaltoHorizontalRatio;
if (m_CyclePositionX > m_Time)
{
m_CyclePositionX = m_CyclePositionX - m_Time;
}
if (m_CyclePositionY > m_Time)
{
m_CyclePositionY = m_CyclePositionY - m_Time;
}
return new Vector3(xPos, yPos, 0f);
}
return new Vector3(xPos, yPos, 0f);
}
}
fileFormatVersion: 2
guid: eb8f0bb9ccf74831aae810b90df68607
timeCreated: 1655203117
\ No newline at end of file
fileFormatVersion: 2
guid: 492f54f4accf00440828ffcb9e4fcc19
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
......@@ -2,69 +2,72 @@ using System;
using System.Collections;
using UnityEngine;
[Serializable]
public class FOVKick
namespace UnityStandardAssets.Utility
{
public Camera Camera; // optional camera setup, if null the main camera will be used
[HideInInspector] public float originalFov; // the original fov
public float FOVIncrease = 3f; // the amount the field of view increases when going into a run
public float TimeToIncrease = 1f; // the amount of time the field of view will increase over
public float TimeToDecrease = 1f; // the amount of time the field of view will take to return to its original size
public AnimationCurve IncreaseCurve;
public void Setup(Camera camera)
[Serializable]
public class FOVKick
{
CheckStatus(camera);
Camera = camera;
originalFov = camera.fieldOfView;
}
public Camera Camera; // optional camera setup, if null the main camera will be used
[HideInInspector] public float originalFov; // the original fov
public float FOVIncrease = 3f; // the amount the field of view increases when going into a run
public float TimeToIncrease = 1f; // the amount of time the field of view will increase over
public float TimeToDecrease = 1f; // the amount of time the field of view will take to return to its original size
public AnimationCurve IncreaseCurve;
private void CheckStatus(Camera camera)
{
if (camera == null)
public void Setup(Camera camera)
{
throw new Exception("FOVKick camera is null, please supply the camera to the constructor");
CheckStatus(camera);
Camera = camera;
originalFov = camera.fieldOfView;
}
if (IncreaseCurve == null)
private void CheckStatus(Camera camera)
{
throw new Exception(
"FOVKick Increase curve is null, please define the curve for the field of view kicks");
if (camera == null)
{
throw new Exception("FOVKick camera is null, please supply the camera to the constructor");
}
if (IncreaseCurve == null)
{
throw new Exception(
"FOVKick Increase curve is null, please define the curve for the field of view kicks");
}
}
}
public void ChangeCamera(Camera camera)
{
Camera = camera;
}
public void ChangeCamera(Camera camera)
{
Camera = camera;
}
public IEnumerator FOVKickUp()
{
float t = Mathf.Abs((Camera.fieldOfView - originalFov)/FOVIncrease);
while (t < TimeToIncrease)
public IEnumerator FOVKickUp()
{
Camera.fieldOfView = originalFov + (IncreaseCurve.Evaluate(t/TimeToIncrease)*FOVIncrease);
t += Time.deltaTime;
yield return new WaitForEndOfFrame();
float t = Mathf.Abs((Camera.fieldOfView - originalFov)/FOVIncrease);
while (t < TimeToIncrease)
{
Camera.fieldOfView = originalFov + (IncreaseCurve.Evaluate(t/TimeToIncrease)*FOVIncrease);
t += Time.deltaTime;
yield return new WaitForEndOfFrame();
}
}
}
public IEnumerator FOVKickDown()
{
float t = Mathf.Abs((Camera.fieldOfView - originalFov)/FOVIncrease);
while (t > 0)
public IEnumerator FOVKickDown()
{
Camera.fieldOfView = originalFov + (IncreaseCurve.Evaluate(t/TimeToDecrease)*FOVIncrease);
t -= Time.deltaTime;
yield return new WaitForEndOfFrame();
float t = Mathf.Abs((Camera.fieldOfView - originalFov)/FOVIncrease);
while (t > 0)
{
Camera.fieldOfView = originalFov + (IncreaseCurve.Evaluate(t/TimeToDecrease)*FOVIncrease);
t -= Time.deltaTime;
yield return new WaitForEndOfFrame();
}
//make sure that fov returns to the original size
Camera.fieldOfView = originalFov;
}
//make sure that fov returns to the original size
Camera.fieldOfView = originalFov;
}
}
\ No newline at end of file
}
fileFormatVersion: 2
guid: 7b68adcecf544b35bc6c59d49fa13830
timeCreated: 1655203124
\ No newline at end of file
fileFormatVersion: 2
guid: 6045a93fb05b9c74884821030da2c46c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

using System;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityStandardAssets.CrossPlatformInput;
using UnityStandardAssets.Utility;
using Random = UnityEngine.Random;
[RequireComponent(typeof (CharacterController))]
[RequireComponent(typeof (AudioSource))]
public class FirstPersonController : MonoBehaviour
namespace UnityStandardAssets.Characters.FirstPerson
{
[SerializeField] LayerMask mask;
[SerializeField] private bool m_IsWalking = default;
[SerializeField] private float m_WalkSpeed = default;
[SerializeField] private float m_RunSpeed = default;
[SerializeField] [Range(0f, 1f)] private float m_RunstepLenghten = default;
[SerializeField] private float m_JumpSpeed = default;
[SerializeField] private float m_StickToGroundForce = default;
[SerializeField] private float m_GravityMultiplier = default;
[SerializeField] private MouseLook m_MouseLook = default;
[SerializeField] private bool m_UseFovKick = default;
[SerializeField] private FOVKick m_FovKick = new FOVKick();
[SerializeField] private bool m_UseHeadBob = default;
[SerializeField] private CurveControlledBob m_HeadBob = new CurveControlledBob();
[SerializeField] private LerpControlledBob m_JumpBob = new LerpControlledBob();
[SerializeField] private float m_StepInterval = default;
[SerializeField] private AudioClip[] m_FootstepSounds = default; // an array of footstep sounds that will be randomly selected from.
[SerializeField] private AudioClip m_JumpSound = default; // the sound played when character leaves the ground.
[SerializeField] private AudioClip m_LandSound = default; // the sound played when character touches back on ground.
private Camera m_Camera;
private bool m_Jump;
private float m_YRotation;
private Vector2 m_Input;
private Vector3 m_MoveDir = Vector3.zero;
private CharacterController m_CharacterController;
private CollisionFlags m_CollisionFlags;
private bool m_PreviouslyGrounded;
private Vector3 m_OriginalCameraPosition;
private float m_StepCycle;
private float m_NextStep;
private bool m_Jumping;
private AudioSource m_AudioSource;
private float speed;
private float mouseX;
private float mouseY;
bool cheatOn = false;
float initialRunSpeed, initialJumpSpeed;
// Use this for initialization
private void Start()
{
var playerInput = GetComponent<PlayerInput>();
playerInput.actions.Enable();
m_CharacterController = GetComponent<CharacterController>();
m_Camera = Camera.main;
m_OriginalCameraPosition = m_Camera.transform.localPosition;
m_FovKick.Setup(m_Camera);
m_HeadBob.Setup(m_Camera, m_StepInterval);
m_StepCycle = 0f;
m_NextStep = m_StepCycle/2f;
m_Jumping = false;
m_AudioSource = GetComponent<AudioSource>();
m_MouseLook.Init(transform , m_Camera.transform);
speed = m_WalkSpeed;
initialRunSpeed = m_RunSpeed;
initialJumpSpeed = m_JumpSpeed;
}
// Update is called once per frame
private void Update()
[RequireComponent(typeof (CharacterController))]
[RequireComponent(typeof (AudioSource))]
public class FirstPersonController : MonoBehaviour
{
RotateView();
if (!m_PreviouslyGrounded && m_CharacterController.isGrounded)
[SerializeField] LayerMask mask;
[SerializeField] private bool m_IsWalking = default;
[SerializeField] private float m_WalkSpeed = default;
[SerializeField] private float m_RunSpeed = default;
[SerializeField] [Range(0f, 1f)] private float m_RunstepLenghten = default;
[SerializeField] private float m_JumpSpeed = default;
[SerializeField] private float m_StickToGroundForce = default;
[SerializeField] private float m_GravityMultiplier = default;
[SerializeField] private MouseLook m_MouseLook = default;
[SerializeField] private bool m_UseFovKick = default;
[SerializeField] private FOVKick m_FovKick = new FOVKick();
[SerializeField] private bool m_UseHeadBob = default;
[SerializeField] private CurveControlledBob m_HeadBob = new CurveControlledBob();
[SerializeField] private LerpControlledBob m_JumpBob = new LerpControlledBob();
[SerializeField] private float m_StepInterval = default;
[SerializeField] private AudioClip[] m_FootstepSounds = default; // an array of footstep sounds that will be randomly selected from.
[SerializeField] private AudioClip m_JumpSound = default; // the sound played when character leaves the ground.
[SerializeField] private AudioClip m_LandSound = default; // the sound played when character touches back on ground.
private Camera m_Camera;
private bool m_Jump;
private float m_YRotation;
private Vector2 m_Input;
private Vector3 m_MoveDir = Vector3.zero;
private CharacterController m_CharacterController;
private CollisionFlags m_CollisionFlags;
private bool m_PreviouslyGrounded;
private Vector3 m_OriginalCameraPosition;
private float m_StepCycle;
private float m_NextStep;
private bool m_Jumping;
private AudioSource m_AudioSource;
bool cheatOn = false;
float initialRunSpeed, initialJumpSpeed;
// Use this for initialization
private void Start()
{
StartCoroutine(m_JumpBob.DoBobCycle());
PlayLandingSound();
m_MoveDir.y = 0f;
m_CharacterController = GetComponent<CharacterController>();
m_Camera = Camera.main;
m_OriginalCameraPosition = m_Camera.transform.localPosition;
m_FovKick.Setup(m_Camera);
m_HeadBob.Setup(m_Camera, m_StepInterval);
m_StepCycle = 0f;
m_NextStep = m_StepCycle/2f;
m_Jumping = false;
}
if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded)
{
m_MoveDir.y = 0f;
}
m_PreviouslyGrounded = m_CharacterController.isGrounded;
}
m_AudioSource = GetComponent<AudioSource>();
m_MouseLook.Init(transform , m_Camera.transform);
void OnJump()
{
// the jump state needs to read here to make sure it is not missed
if (!m_Jump)
{
m_Jump = true;
initialRunSpeed = m_RunSpeed;
initialJumpSpeed = m_JumpSpeed;
}
}
void OnRun(InputValue value)
{
m_IsWalking = !value.isPressed;
bool waswalking = m_IsWalking;
speed = m_IsWalking ? m_WalkSpeed : m_RunSpeed;
// handle speed change to give an fov kick
// only if the player is going to a run, is running and the fovkick is to be used
if (m_IsWalking != waswalking && m_UseFovKick && m_CharacterController.velocity.sqrMagnitude > 0)
// Update is called once per frame
private void Update()
{
StopAllCoroutines();
StartCoroutine(!m_IsWalking ? m_FovKick.FOVKickUp() : m_FovKick.FOVKickDown());
}
}
void OnMouseX(InputValue value)
{
mouseX = value.Get<float>();
}
if (Input.GetKeyDown(KeyCode.PageUp))
{
cheatOn = !cheatOn;
void OnMouseY(InputValue value)
{
mouseY = value.Get<float>();
}
m_RunSpeed = cheatOn ? 200f : initialRunSpeed;
m_JumpSpeed = cheatOn ? 30f : initialJumpSpeed;
}
void OnMovement(InputValue value)
{
var horizontal = value.Get<Vector2>().x;
var vertical = value.Get<Vector2>().y;
RotateView();
// the jump state needs to read here to make sure it is not missed
if (!m_Jump)
{
m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
}
m_Input = new Vector2(horizontal, vertical);
if (!m_PreviouslyGrounded && m_CharacterController.isGrounded)
{
StartCoroutine(m_JumpBob.DoBobCycle());
PlayLandingSound();
m_MoveDir.y = 0f;
m_Jumping = false;
}
if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded)
{
m_MoveDir.y = 0f;
}
// normalize input if it exceeds 1 in combined length:
if (m_Input.sqrMagnitude > 1)
{
m_Input.Normalize();
m_PreviouslyGrounded = m_CharacterController.isGrounded;
}
}
void OnGodMode(InputValue value)
{
cheatOn = !cheatOn;
m_RunSpeed = cheatOn ? 200f : initialRunSpeed;
m_JumpSpeed = cheatOn ? 30f : initialJumpSpeed;
}
private void PlayLandingSound()
{
if (cheatOn) return;
private void PlayLandingSound()
{
if (cheatOn) return;
m_AudioSource.clip = m_LandSound;
m_AudioSource.Play();
m_NextStep = m_StepCycle + .5f;
}
m_AudioSource.clip = m_LandSound;
m_AudioSource.Play();
m_NextStep = m_StepCycle + .5f;
}
private void FixedUpdate()
{
// float speed;
// GetInput(out speed);
// always move along the camera forward as it is the direction that it being aimed at
Vector3 desiredMove = transform.forward * m_Input.y + transform.right * m_Input.x;
// get a normal for the surface that is being touched to move along it
RaycastHit hitInfo;
Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.down, out hitInfo,
m_CharacterController.height / 2f, Physics.AllLayers, QueryTriggerInteraction.Ignore);
desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;
m_MoveDir.x = desiredMove.x*speed;
m_MoveDir.z = desiredMove.z*speed;
if (m_CharacterController.isGrounded)
private void FixedUpdate()
{
m_MoveDir.y = -m_StickToGroundForce;
float speed;
GetInput(out speed);
// always move along the camera forward as it is the direction that it being aimed at
Vector3 desiredMove = transform.forward*m_Input.y + transform.right*m_Input.x;
if (m_Jump)
{
m_MoveDir.y = m_JumpSpeed;
PlayJumpSound();
m_Jump = false;
m_Jumping = true;
}
}
else
{
m_MoveDir += Physics.gravity * m_GravityMultiplier * Time.fixedDeltaTime;
}
m_CollisionFlags = m_CharacterController.Move(m_MoveDir*Time.fixedDeltaTime);
// get a normal for the surface that is being touched to move along it
RaycastHit hitInfo;
Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.down, out hitInfo,
m_CharacterController.height/2f, mask, QueryTriggerInteraction.Ignore);
desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;
ProgressStepCycle(speed);
UpdateCameraPosition(speed);
m_MoveDir.x = desiredMove.x*speed;
m_MoveDir.z = desiredMove.z*speed;
m_MouseLook.UpdateCursorLock();
}
if (m_CharacterController.isGrounded)
{
m_MoveDir.y = -m_StickToGroundForce;
if (m_Jump)
{
m_MoveDir.y = m_JumpSpeed;
PlayJumpSound();
m_Jump = false;
m_Jumping = true;
}
}
else
{
m_MoveDir += Physics.gravity*m_GravityMultiplier*Time.fixedDeltaTime;
}
m_CollisionFlags = m_CharacterController.Move(m_MoveDir*Time.fixedDeltaTime);
private void PlayJumpSound()
{
if (cheatOn) return;
ProgressStepCycle(speed);
UpdateCameraPosition(speed);
m_AudioSource.clip = m_JumpSound;
m_AudioSource.Play();
}
m_MouseLook.UpdateCursorLock();
}
private void ProgressStepCycle(float speed)
{
if (m_CharacterController.velocity.sqrMagnitude > 0 && (m_Input.x != 0 || m_Input.y != 0))
private void PlayJumpSound()
{
m_StepCycle += (m_CharacterController.velocity.magnitude + (speed*(m_IsWalking ? 1f : m_RunstepLenghten)))*
Time.fixedDeltaTime;
}
if (cheatOn) return;
if (!(m_StepCycle > m_NextStep))
{
return;
m_AudioSource.clip = m_JumpSound;
m_AudioSource.Play();
}
m_NextStep = m_StepCycle + m_StepInterval;
PlayFootStepAudio();
}
private void ProgressStepCycle(float speed)
{
if (m_CharacterController.velocity.sqrMagnitude > 0 && (m_Input.x != 0 || m_Input.y != 0))
{
m_StepCycle += (m_CharacterController.velocity.magnitude + (speed*(m_IsWalking ? 1f : m_RunstepLenghten)))*
Time.fixedDeltaTime;
}
if (!(m_StepCycle > m_NextStep))
{
return;
}
private void PlayFootStepAudio()
{
if (cheatOn) return;
m_NextStep = m_StepCycle + m_StepInterval;
if (!m_CharacterController.isGrounded)
{
return;
}
if (m_FootstepSounds.Length == 0)
{
return;
PlayFootStepAudio();
}
// pick & play a random footstep sound from the array,
// excluding sound at index 0
int n = Random.Range(1, m_FootstepSounds.Length);
m_AudioSource.clip = m_FootstepSounds[n];
m_AudioSource.PlayOneShot(m_AudioSource.clip);
// move picked sound to index 0 so it's not picked next time
m_FootstepSounds[n] = m_FootstepSounds[0];
m_FootstepSounds[0] = m_AudioSource.clip;
}
private void UpdateCameraPosition(float speed)
{
Vector3 newCameraPosition;
if (!m_UseHeadBob)
private void PlayFootStepAudio()
{
return;
}
if (m_CharacterController.velocity.magnitude > 0 && m_CharacterController.isGrounded)
{
m_Camera.transform.localPosition =
m_HeadBob.DoHeadBob(m_CharacterController.velocity.magnitude +
(speed*(m_IsWalking ? 1f : m_RunstepLenghten)));
newCameraPosition = m_Camera.transform.localPosition;
newCameraPosition.y = m_Camera.transform.localPosition.y - m_JumpBob.Offset();
if (cheatOn) return;
if (!m_CharacterController.isGrounded)
{
return;
}
// pick & play a random footstep sound from the array,
// excluding sound at index 0
int n = Random.Range(1, m_FootstepSounds.Length);
m_AudioSource.clip = m_FootstepSounds[n];
m_AudioSource.PlayOneShot(m_AudioSource.clip);
// move picked sound to index 0 so it's not picked next time
m_FootstepSounds[n] = m_FootstepSounds[0];
m_FootstepSounds[0] = m_AudioSource.clip;
}
else
private void UpdateCameraPosition(float speed)
{
newCameraPosition = m_Camera.transform.localPosition;
newCameraPosition.y = m_OriginalCameraPosition.y - m_JumpBob.Offset();
Vector3 newCameraPosition;
if (!m_UseHeadBob)
{
return;
}
if (m_CharacterController.velocity.magnitude > 0 && m_CharacterController.isGrounded)
{
m_Camera.transform.localPosition =
m_HeadBob.DoHeadBob(m_CharacterController.velocity.magnitude +
(speed*(m_IsWalking ? 1f : m_RunstepLenghten)));
newCameraPosition = m_Camera.transform.localPosition;
newCameraPosition.y = m_Camera.transform.localPosition.y - m_JumpBob.Offset();
}
else
{
newCameraPosition = m_Camera.transform.localPosition;
newCameraPosition.y = m_OriginalCameraPosition.y - m_JumpBob.Offset();
}
m_Camera.transform.localPosition = newCameraPosition;
}
m_Camera.transform.localPosition = newCameraPosition;
}
private void RotateView()
{
m_MouseLook.LookRotation(transform, m_Camera.transform, mouseX, mouseY);
}
private void GetInput(out float speed)
{
// Read input
float horizontal = CrossPlatformInputManager.GetAxis("Horizontal");
float vertical = CrossPlatformInputManager.GetAxis("Vertical");
bool waswalking = m_IsWalking;
#if !MOBILE_INPUT
// On standalone builds, walk/run speed is modified by a key press.
// keep track of whether or not the character is walking or running
m_IsWalking = !Input.GetKey(KeyCode.LeftShift);
#endif
// set the desired speed to be walking or running
speed = m_IsWalking ? m_WalkSpeed : m_RunSpeed;
m_Input = new Vector2(horizontal, vertical);
// normalize input if it exceeds 1 in combined length:
if (m_Input.sqrMagnitude > 1)
{
m_Input.Normalize();
}
// handle speed change to give an fov kick
// only if the player is going to a run, is running and the fovkick is to be used
if (m_IsWalking != waswalking && m_UseFovKick && m_CharacterController.velocity.sqrMagnitude > 0)
{
StopAllCoroutines();
StartCoroutine(!m_IsWalking ? m_FovKick.FOVKickUp() : m_FovKick.FOVKickDown());
}
}
private void OnControllerColliderHit(ControllerColliderHit hit)
{
Rigidbody body = hit.collider.attachedRigidbody;
//dont move the rigidbody if the character is on top of it
if (m_CollisionFlags == CollisionFlags.Below)
private void RotateView()
{
return;
m_MouseLook.LookRotation (transform, m_Camera.transform);
}
if (body == null || body.isKinematic)
private void OnControllerColliderHit(ControllerColliderHit hit)
{
return;
Rigidbody body = hit.collider.attachedRigidbody;
//dont move the rigidbody if the character is on top of it
if (m_CollisionFlags == CollisionFlags.Below)
{
return;
}
if (body == null || body.isKinematic)
{
return;
}
body.AddForceAtPosition(m_CharacterController.velocity*0.1f, hit.point, ForceMode.Impulse);
}
body.AddForceAtPosition(m_CharacterController.velocity*0.1f, hit.point, ForceMode.Impulse);
}
}
\ No newline at end of file
}