浏览代码

Added First Person Controller, Full Screen Fade Manager (alongside with Manager system) + SceneView <-> GameView POV link

/main
Thomas ICHÉ 6 年前
当前提交
fc2bb046
共有 34 个文件被更改,包括 913 次插入18 次删除
  1. 10
      Editor/MenuItems.cs
  2. 2
      Resources/Default_LevelStreamingManager.prefab
  3. 18
      Runtime/Actions/StreamingLevelAction.cs
  4. 13
      Runtime/Callable.cs
  5. 9
      Runtime/LevelStreaming/LevelStreamingManager.cs
  6. 7
      package.json
  7. 8
      Editor/GameViewLink.meta
  8. 38
      Editor/PropertyDrawers/NonNullCheckPropertyDrawer.cs
  9. 11
      Editor/PropertyDrawers/NonNullCheckPropertyDrawer.cs.meta
  10. 17
      Editor/PropertyDrawers/ScenePropertyDrawer.cs
  11. 11
      Editor/PropertyDrawers/ScenePropertyDrawer.cs.meta
  12. 202
      Resources/Default_FullScreenFadeManager.prefab
  13. 7
      Resources/Default_FullScreenFadeManager.prefab.meta
  14. 25
      Runtime/Actions/FullScreenFadeAction.cs
  15. 11
      Runtime/Actions/FullScreenFadeAction.cs.meta
  16. 8
      Runtime/Controllers.meta
  17. 8
      Runtime/Managers/Implementations.meta
  18. 8
      Runtime/PropertyAttributes.meta
  19. 142
      Editor/GameViewLink/LinkGameView.cs
  20. 11
      Editor/GameViewLink/LinkGameView.cs.meta
  21. 118
      Runtime/Controllers/FirstPersonController.cs
  22. 11
      Runtime/Controllers/FirstPersonController.cs.meta
  23. 89
      Runtime/Controllers/KeyboardGamepadPlayerInput.cs
  24. 11
      Runtime/Controllers/KeyboardGamepadPlayerInput.cs.meta
  25. 26
      Runtime/Controllers/PlayerInput.cs
  26. 11
      Runtime/Controllers/PlayerInput.cs.meta
  27. 68
      Runtime/Managers/Implementations/FullScreenFadeManager.cs
  28. 11
      Runtime/Managers/Implementations/FullScreenFadeManager.cs.meta
  29. 9
      Runtime/PropertyAttributes/NonNullCheckAttribute.cs
  30. 11
      Runtime/PropertyAttributes/NonNullCheckAttribute.cs.meta

10
Editor/MenuItems.cs


using System.Collections;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

static class MenuItems
public static class MenuItems
const int kMenuPriority = 330;
[MenuItem("Edit/Select None &D", priority = 149)]
static void UnselectAll()
{

static readonly string helperPreferenceName = "GameplayIngredients.toggleIngredientHelpers";
[MenuItem("Edit/Gameplay Ingredients/Toggle Helpers", priority = 117)]
[MenuItem("Edit/Gameplay Ingredients/Toggle Helpers", priority = kMenuPriority)]
static void ToggleIngredientHelpers()
{
bool value = EditorPrefs.GetBool(helperPreferenceName, false);

}
[MenuItem("Edit/Gameplay Ingredients/Toggle Helpers", true, 117)]
[MenuItem("Edit/Gameplay Ingredients/Toggle Helpers", validate = true, priority = kMenuPriority)]
static bool ToggleIngredientHelpersValidation()
{
Menu.SetChecked("Edit/Gameplay Ingredients/Toggle Helpers", EditorPrefs.GetBool(helperPreferenceName, false));

2
Resources/Default_LevelStreamingManager.prefab


m_SortingBucketNormalizedSize: 0
m_AdditionalShaderChannelsFlag: 0
m_SortingLayerID: 0
m_SortingOrder: 32767
m_SortingOrder: 32766
m_TargetDisplay: 0
--- !u!114 &4237660106662749795
MonoBehaviour:

18
Runtime/Actions/StreamingLevelAction.cs


using UnityEngine.Events;
using GameplayIngredients;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using NaughtyAttributes;
public string[] Scenes;
[ReorderableList]
public Scene[] Scenes;
public UnityEvent OnLoadComplete;
[ReorderableList]
public Callable[] OnLoadComplete;
Manager.Get<LevelStreamingManager>().LoadScenes(Action, Scenes, SceneToActivate, ShowUI, OnLoadComplete);
List<string> sceneNames = new List<string>();
foreach (var scene in Scenes)
sceneNames.Add(scene.name);
Manager.Get<LevelStreamingManager>().LoadScenes(Action, sceneNames.ToArray(), SceneToActivate, ShowUI, OnLoadComplete);
}
}
}

13
Runtime/Callable.cs


public static void Call(Callable[] calls)
{
foreach (var call in calls)
call.Execute();
{
if(call != null)
call.Execute();
else
Debug.LogError("Cannot execute call: Null or Missing");
}
call.Execute();
if (call != null)
call.Execute();
else
Debug.LogError("Cannot execute call: Null or Missing");
}
}
}

9
Runtime/LevelStreaming/LevelStreamingManager.cs


private AsyncOperation[] asyncOperations;
public void LoadScenes(StreamingAction action, string[] scenes, string sceneToActivate, bool showUI, UnityEvent onLoadComplete)
public void LoadScenes(StreamingAction action, string[] scenes, string sceneToActivate, bool showUI, Callable[] onLoadComplete)
{
if (EnableDebug)
DebugText.gameObject.SetActive(true);

{
Debug.LogWarning("Did not find any candidates to load or unload...");
if (onLoadComplete != null) onLoadComplete.Invoke();
if (onLoadComplete != null)
Callable.Call(onLoadComplete);
if (showUI)
LoadingRoot.SetActive(false);

}
}
IEnumerator LoadScenesCoroutine(StreamingAction action, List<string> scenes, string sceneToActivate, bool showUI, UnityEvent onLoadComplete)
IEnumerator LoadScenesCoroutine(StreamingAction action, List<string> scenes, string sceneToActivate, bool showUI, Callable[] onLoadComplete)
{
LogDebugInformation("START LOAD/UNLOAD FOR LEVELS...");
SetProgressBar(0.0f, true);

yield return new WaitForSeconds(DelayAfterLoad);
if (onLoadComplete != null)
onLoadComplete.Invoke();
Callable.Call(onLoadComplete);
if (showUI)
LoadingRoot.SetActive(false);

7
package.json


"displayName": "Gameplay Ingredients",
"version": "1.0.0-preview",
"unity": "2018.3",
"description": "Gameplay ingredients - A Collection of scripts for the editor and runtime to set-up gameplay actions and logic in your games"
"description": "Gameplay ingredients - A Collection of scripts for the editor and runtime to set-up gameplay actions and logic in your games",
"dependencies":
{
"com.unity.cinemachine" : "2.2.8",
"com.unity.inputsystem" : "0.1.2-preview"
}
}

8
Editor/GameViewLink.meta


fileFormatVersion: 2
guid: 0b748787917f8d7459fa7973629a9afe
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

38
Editor/PropertyDrawers/NonNullCheckPropertyDrawer.cs


using UnityEngine.SceneManagement;
using UnityEngine;
using UnityEditor;
namespace GameplayIngredients.Editor
{
[CustomPropertyDrawer(typeof(NonNullCheckAttribute))]
public class NonNullCheckPropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if(property.propertyType == SerializedPropertyType.ObjectReference)
{
bool valid = property.objectReferenceValue != null;
var color = GUI.backgroundColor;
GUI.backgroundColor = valid ? color : Color.red;
EditorGUI.ObjectField(position, property);
GUI.backgroundColor = color;
}
else
{
EditorGUI.LabelField(position, "Use [NonNullCheck] attribute only on Object fields");
}
}
static class Styles
{
public static GUIStyle errorfield;
static Styles()
{
errorfield = new GUIStyle(EditorStyles.objectField);
}
}
}
}

11
Editor/PropertyDrawers/NonNullCheckPropertyDrawer.cs.meta


fileFormatVersion: 2
guid: b3811924d58479541aaa75e0d3882b74
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

17
Editor/PropertyDrawers/ScenePropertyDrawer.cs


using UnityEngine.SceneManagement;
using UnityEngine;
using UnityEditor;
namespace GameplayIngredients.Editor
{
[CustomPropertyDrawer(typeof(Scene))]
public class ScenePropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.ObjectField(position, property);
}
}
}

11
Editor/PropertyDrawers/ScenePropertyDrawer.cs.meta


fileFormatVersion: 2
guid: 5923fcc50a6c23044be2c181ca42162b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

202
Resources/Default_FullScreenFadeManager.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &1138337785565518664
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1138337785565518665}
- component: {fileID: 1138337785565518667}
- component: {fileID: 1138337785565518666}
m_Layer: 5
m_Name: FullScreenMatte
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!224 &1138337785565518665
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1138337785565518664}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1138337785731963864}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &1138337785565518667
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1138337785565518664}
m_CullTransparentMesh: 0
--- !u!114 &1138337785565518666
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1138337785565518664}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0, g: 0, b: 0, a: 0}
m_RaycastTarget: 0
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 0}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
--- !u!1 &1138337785731963871
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1138337785731963864}
- component: {fileID: 1138337785731963866}
- component: {fileID: 1138337785731963865}
m_Layer: 5
m_Name: Canvas
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1138337785731963864
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1138337785731963871}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 1138337785565518665}
m_Father: {fileID: 1138337785854297217}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!223 &1138337785731963866
Canvas:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1138337785731963871}
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 0
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 1
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_AdditionalShaderChannelsFlag: 0
m_SortingLayerID: 0
m_SortingOrder: 32765
m_TargetDisplay: 0
--- !u!114 &1138337785731963865
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1138337785731963871}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1980459831, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
--- !u!1 &1138337785854297223
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1138337785854297217}
- component: {fileID: 1138337785854297216}
m_Layer: 0
m_Name: Default_FullScreenFadeManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1138337785854297217
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1138337785854297223}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1138337785731963864}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1138337785854297216
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1138337785854297223}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c3c1731f7f8331345a352b2b9c05f2cb, type: 3}
m_Name:
m_EditorClassIdentifier:
FullScreenFadePlane: {fileID: 1138337785565518666}

7
Resources/Default_FullScreenFadeManager.prefab.meta


fileFormatVersion: 2
guid: 7134ce259ccbdf048956ad46c0351336
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

25
Runtime/Actions/FullScreenFadeAction.cs


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using NaughtyAttributes;
namespace GameplayIngredients.Actions
{
public class FullScreenFadeAction : ActionBase
{
public FullScreenFadeManager.FadeMode Fading = FullScreenFadeManager.FadeMode.ToBlack;
public float Duration = 2.0f;
[ReorderableList]
public Callable[] OnComplete;
public override void Execute()
{
Manager.Get<FullScreenFadeManager>().Fade(Duration, Fading, OnComplete);
}
}
}

11
Runtime/Actions/FullScreenFadeAction.cs.meta


fileFormatVersion: 2
guid: 5d6566ceaa073c944b7d03f43819b2a0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 4112ad68bb67a9646acd12615491fc97, type: 3}
userData:
assetBundleName:
assetBundleVariant:

8
Runtime/Controllers.meta


fileFormatVersion: 2
guid: fe3adcbe3d5bae647b14b33f26888b39
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
Runtime/Managers/Implementations.meta


fileFormatVersion: 2
guid: dcd0e7c2728af96488efea2d28e1c2cf
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
Runtime/PropertyAttributes.meta


fileFormatVersion: 2
guid: d0e791fe1aeccb54287b96625bd374be
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

142
Editor/GameViewLink/LinkGameView.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace GameplayIngredients.Editor
{
static class LinkGameView
{
static readonly string kPreferenceName = "GameplayIngredients.LinkGameView";
static readonly string kLinkCameraName = "___LINK__SCENE__VIEW__CAMERA___";
static bool Active
{
get
{
return EditorPrefs.GetBool(kPreferenceName, false);
}
set
{
EditorPrefs.SetBool(kPreferenceName, value);
s_GameObject.SetActive(value);
UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
}
}
[InitializeOnLoadMethod]
static void Initialize()
{
SceneView.onSceneGUIDelegate += Update;
}
const string kMenuPath = "Edit/Link SceneView and GameView %,";
const string kMenuSelectPath = "Edit/Select Linked Camera %#,";
public const int kMenuPriority = 230;
[MenuItem(kMenuPath, priority = kMenuPriority, validate = false)]
static void Toggle()
{
if (Active)
Active = false;
else
Active = true;
}
[MenuItem(kMenuPath, priority = kMenuPriority, validate = true)]
static bool ToggleCheck()
{
Menu.SetChecked(kMenuPath, Active);
return SceneView.sceneViews.Count > 0;
}
[MenuItem(kMenuSelectPath, priority = kMenuPriority+1)]
static void Select()
{
if (s_GameObject != null)
Selection.activeGameObject = s_GameObject;
}
static GameObject s_GameObject;
static void Update(SceneView sceneView)
{
// Check if camera Exists
if (s_GameObject == null)
{
// If disconnected (should not happen, but hey...)
var result = GameObject.Find(kLinkCameraName);
if (result != null) // reconnect
s_GameObject = result;
else // Create the camera if it does not exist
s_GameObject = CreateLinkedCamera();
}
if (Active)
{
var sceneCamera = SceneView.lastActiveSceneView.camera;
var camera = s_GameObject.GetComponent<Camera>();
bool needRepaint = sceneCamera.transform.position != camera.transform.position
|| sceneCamera.transform.rotation != camera.transform.rotation
|| sceneCamera.fieldOfView != camera.fieldOfView;
if(needRepaint)
{
s_GameObject.transform.position = sceneCamera.transform.position;
s_GameObject.transform.rotation = sceneCamera.transform.rotation;
camera.fieldOfView = sceneCamera.fieldOfView;
UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
}
}
}
const string kDefaultPrefabName = "LinkGameViewCamera";
static GameObject CreateLinkedCamera()
{
// Try to find an Asset named as the default name
string[] assets = AssetDatabase.FindAssets(kDefaultPrefabName);
if(assets.Length > 0)
{
string path = AssetDatabase.GUIDToAssetPath(assets[0]);
GameObject obj = (GameObject)AssetDatabase.LoadAssetAtPath(path, typeof(GameObject));
if (obj != null)
{
var instance = GameObject.Instantiate(obj);
if(instance.GetComponent<Camera>() != null)
{
instance.hideFlags = HideFlags.HideAndDontSave;
instance.tag = "MainCamera";
instance.name = kLinkCameraName;
instance.SetActive(Active);
instance.GetComponent<Camera>().depth = int.MaxValue;
return instance;
}
else
{
Debug.LogWarning("LinkGameView Found default prefab but has no camera!");
}
}
else
Debug.LogWarning("LinkGameView Found default prefab but is not gameobject!");
}
// Otherwise ... Create default from code
var go = new GameObject(kLinkCameraName);
go.hideFlags = HideFlags.HideAndDontSave;
go.tag = "MainCamera";
var camera = go.AddComponent<Camera>();
camera.depth = int.MaxValue;
go.SetActive(Active);
return go;
}
}
}

11
Editor/GameViewLink/LinkGameView.cs.meta


fileFormatVersion: 2
guid: b80d5428a5e868b41ba603471f379a02
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

118
Runtime/Controllers/FirstPersonController.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients.Controllers
{
[RequireComponent(typeof(CharacterController))]
public class FirstPersonController : MonoBehaviour
{
public bool Paused = false;
[Header("Objects")]
[NonNullCheck]
public Transform m_Camera;
[NonNullCheck]
public PlayerInput m_Input;
[Header("Metrics")]
[Range(1.0f, 2.5f)]
public float PlayerHeight;
[Range(0.35f, 2.0f)]
public float PlayerRadius;
public float PlayerWeight = 3.0f;
[Header("Movement")]
[Range(0.0f, 12.5f)]
public float MoveSpeed;
public float TerminalVelocity = 54.16f;
public float TurnSpeed = 30;
[Header("Jump")]
public bool EnableJump = false;
public float JumpImpulse = 7.0f;
[Header("Look")]
public float PitchSpeed = 30;
public float MaxPitch = 80;
private CharacterController m_Controller;
private float m_Fall = 0.0f;
private float m_Pitch = 0.0f;
private bool m_Grounded = false;
public void Start()
{
m_Controller = GetComponent<CharacterController>();
}
public void Update()
{
if (m_Camera == null) return;
if (m_Input == null) return;
if (!Paused)
{
m_Input.UpdateInput();
UpdateRotation();
UpdatePlayerMovement();
}
}
public void SetPaused(bool paused)
{
Paused = paused;
}
public void OnValidate()
{
if (m_Controller == null)
m_Controller = GetComponent<CharacterController>();
float realHeight = PlayerHeight + PlayerRadius;
m_Controller.center = new Vector3(0, realHeight / 2, 0);
m_Controller.height = realHeight;
m_Controller.radius = PlayerRadius;
m_Camera.transform.localPosition = new Vector3(0, PlayerHeight, 0);
}
public void UpdateRotation()
{
m_Pitch = Mathf.Clamp(m_Pitch - (Time.deltaTime * PitchSpeed * m_Input.Look.y), -MaxPitch, MaxPitch);
m_Camera.transform.localEulerAngles = new Vector3(m_Pitch, 0, 0);
transform.Rotate(transform.up, Time.deltaTime * TurnSpeed * m_Input.Look.x);
}
public void UpdatePlayerMovement()
{
Vector3 move = (transform.forward * m_Input.Movement.y + transform.right * m_Input.Movement.x) * MoveSpeed;
m_Fall += PlayerWeight * 9.80665f * Time.deltaTime;
m_Fall = Mathf.Min(m_Fall, TerminalVelocity);
move += m_Fall * (-transform.up);
if (m_Grounded)
{
if (EnableJump && m_Input.Jump == PlayerInput.ButtonState.JustPressed)
{
m_Fall = -JumpImpulse;
}
}
m_Controller.Move(move * Time.deltaTime);
m_Grounded = m_Controller.isGrounded;
}
public void SetPlayerHeight(float value)
{
PlayerHeight = value;
OnValidate();
}
public void SetMoveSpeed(float value)
{
MoveSpeed = value;
}
}
}

11
Runtime/Controllers/FirstPersonController.cs.meta


fileFormatVersion: 2
guid: a343570c5b9740b45b62e566abd743cc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

89
Runtime/Controllers/KeyboardGamepadPlayerInput.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients.Controllers
{
public class KeyboardGamepadPlayerInput : PlayerInput
{
[Header("Behaviour")]
public float LookExponent = 2.0f;
[Range(0.0f, 0.7f)]
public float MovementDeadZone = 0.15f;
[Range(0.0f, 0.7f)]
public float LookDeadZone = 0.15f;
[Header("Gamepad Axes")]
public string MovementHorizontalAxis = "Horizontal";
public string MovementVerticalAxis = "Vertical";
public string LookHorizontalAxis = "Look X";
public string LookVerticalAxis = "Look Y";
[Header("Mouse Axes")]
public string MouseHorizontalAxis = "Mouse X";
public string MouseVerticalAxis = "Mouse Y";
[Header("Buttons")]
public string JumpButton = "Jump";
public string PauseButton = "Pause";
public string ActionButton = "Action";
public string ShootButton = "Shoot";
public string UpButton = "Up";
public string DownButton = "Down";
public string LeftButton = "Left";
public string RightButton = "Right";
public override Vector2 Look => m_Look;
public override Vector2 Movement => m_Movement;
public override ButtonState Pause => m_Pause;
public override ButtonState Jump => m_Jump;
public override ButtonState Shoot => m_Shoot;
public override ButtonState Action => m_Action;
Vector2 m_Movement;
Vector2 m_Look;
ButtonState m_Pause;
ButtonState m_Jump;
ButtonState m_Shoot;
ButtonState m_Action;
public override void UpdateInput()
{
m_Movement = new Vector2(Input.GetAxisRaw(MovementHorizontalAxis), Input.GetAxisRaw(MovementVerticalAxis));
Vector2 l = new Vector2(Input.GetAxisRaw(LookHorizontalAxis), Input.GetAxisRaw(LookVerticalAxis));
Vector2 ln = l.normalized;
float lm = Mathf.Clamp01(l.magnitude);
m_Look = ln * Mathf.Pow(Mathf.Clamp01(lm - LookDeadZone) / (1.0f - LookDeadZone), LookExponent);
if (m_Movement.magnitude < MovementDeadZone) m_Movement = Vector2.zero;
m_Look += new Vector2(Input.GetAxisRaw(MouseHorizontalAxis), Input.GetAxisRaw(MouseVerticalAxis));
m_Pause = GetButtonState(PauseButton);
m_Action = GetButtonState(ActionButton);
m_Jump = GetButtonState(JumpButton);
m_Shoot = GetButtonState(ShootButton);
}
ButtonState GetButtonState(string Button)
{
if (Input.GetButton(Button))
{
if (Input.GetButtonDown(Button))
return ButtonState.JustPressed;
else
return ButtonState.Pressed;
}
else
{
if (Input.GetButtonUp(Button))
return ButtonState.JustReleased;
else
return ButtonState.Released;
}
}
}
}

11
Runtime/Controllers/KeyboardGamepadPlayerInput.cs.meta


fileFormatVersion: 2
guid: 0cfde70461151044393814cb1c21024b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

26
Runtime/Controllers/PlayerInput.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients.Controllers
{
public abstract class PlayerInput : MonoBehaviour
{
public enum ButtonState
{
Released = 0,
JustPressed = 1,
Pressed = 2,
JustReleased = 3
}
public abstract Vector2 Look { get; }
public abstract Vector2 Movement { get; }
public abstract ButtonState Pause { get; }
public abstract ButtonState Jump { get; }
public abstract ButtonState Shoot { get; }
public abstract ButtonState Action { get; }
public abstract void UpdateInput();
}
}

11
Runtime/Controllers/PlayerInput.cs.meta


fileFormatVersion: 2
guid: 6baa71e0f1c63c54f9be7033f0a5b8f6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

68
Runtime/Managers/Implementations/FullScreenFadeManager.cs


using System.Collections;
using System;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
namespace GameplayIngredients
{
[ManagerDefaultPrefab("FullScreenFadeManager")]
public class FullScreenFadeManager : Manager
{
public enum FadeMode
{
FromBlack = 0,
ToBlack = 1
}
public Image FullScreenFadePlane;
private Coroutine m_Coroutine;
public void Fade(float duration, FadeMode mode, Callable[] OnComplete)
{
if (m_Coroutine != null)
{
StopCoroutine(m_Coroutine);
m_Coroutine = null;
}
switch (mode)
{
case FadeMode.ToBlack:
m_Coroutine = StartCoroutine(FadeCoroutine(duration, 1.0f, 1.0f, OnComplete));
break;
case FadeMode.FromBlack:
m_Coroutine = StartCoroutine(FadeCoroutine(duration, 0.0f, -1.0f, OnComplete));
break;
default: throw new NotImplementedException();
}
}
IEnumerator FadeCoroutine(float duration, float target, float sign, Callable[] OnComplete)
{
FullScreenFadePlane.gameObject.SetActive(true);
Color c = FullScreenFadePlane.color;
while (sign > 0 ? FullScreenFadePlane.color.a <= target : FullScreenFadePlane.color.a >= target)
{
c = FullScreenFadePlane.color;
c.a += sign * Time.unscaledDeltaTime / duration;
FullScreenFadePlane.color = c;
yield return new WaitForEndOfFrame();
}
Color finalColor = FullScreenFadePlane.color;
finalColor.a = target;
FullScreenFadePlane.color = finalColor;
Callable.Call(OnComplete);
FullScreenFadePlane.gameObject.SetActive(target != 0.0f);
yield return new WaitForEndOfFrame();
m_Coroutine = null;
}
}
}

11
Runtime/Managers/Implementations/FullScreenFadeManager.cs.meta


fileFormatVersion: 2
guid: c3c1731f7f8331345a352b2b9c05f2cb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
Runtime/PropertyAttributes/NonNullCheckAttribute.cs


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients
{
public class NonNullCheckAttribute : PropertyAttribute { }
}

11
Runtime/PropertyAttributes/NonNullCheckAttribute.cs.meta


fileFormatVersion: 2
guid: defe36a4f4b028143982e0d6aedaa35a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存