add ckg
plantilla base para movimiento básico
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class objectToOverrideSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool canBeOverriden = true;
|
||||
|
||||
public GameObject objectToOverride;
|
||||
|
||||
[Space]
|
||||
[Header ("Remote Events On Object Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useRemoteEventsOnObjectOnStart;
|
||||
public List<string> remoteEventNameListOnObjectOnStart = new List<string> ();
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
public bool useRemoteEventsOnObjectOnEnd;
|
||||
public List<string> remoteEventNameListOnObjectOnEnd = new List<string> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Remote Events On Player Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useRemoteEventsOnPlayerOnStart;
|
||||
public List<string> remoteEventNameListOnPlayerOnStart = new List<string> ();
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
public bool useRemoteEventsOnPlayerOnEnd;
|
||||
public List<string> remoteEventNameListOnPlayerOnEnd = new List<string> ();
|
||||
|
||||
GameObject currentPlayer;
|
||||
|
||||
public bool canBeOverridenActive ()
|
||||
{
|
||||
return canBeOverriden;
|
||||
}
|
||||
|
||||
public GameObject getObjectToOverride ()
|
||||
{
|
||||
if (objectToOverride == null) {
|
||||
objectToOverride = gameObject;
|
||||
}
|
||||
|
||||
return objectToOverride;
|
||||
}
|
||||
|
||||
public void setCurrentPlayer (GameObject newPlayer)
|
||||
{
|
||||
currentPlayer = newPlayer;
|
||||
}
|
||||
|
||||
public void setOverrideControlExternally (bool state)
|
||||
{
|
||||
if (currentPlayer != null) {
|
||||
playerComponentsManager mainPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (mainPlayerComponentsManager != null) {
|
||||
|
||||
overrideElementControlSystem mainOverrideElementControlSystem = mainPlayerComponentsManager.getOverrideElementControlSystem ();
|
||||
|
||||
if (mainOverrideElementControlSystem != null) {
|
||||
if (state) {
|
||||
if (!mainOverrideElementControlSystem.usingOverride) {
|
||||
bool checkForExternalObjectsToDriveOrRideEnabled = mainOverrideElementControlSystem.isCheckForExternalObjectsToDriveOrRideEnabled ();
|
||||
|
||||
mainOverrideElementControlSystem.setCheckForExternalObjectsToDriveOrRideEnabledState (false);
|
||||
|
||||
mainOverrideElementControlSystem.overrideElementControl (objectToOverride);
|
||||
|
||||
mainOverrideElementControlSystem.setCheckForExternalObjectsToDriveOrRideEnabledState (checkForExternalObjectsToDriveOrRideEnabled);
|
||||
}
|
||||
} else {
|
||||
if (mainOverrideElementControlSystem.usingOverride) {
|
||||
mainOverrideElementControlSystem.stopCurrentOverrideControl ();
|
||||
}
|
||||
}
|
||||
|
||||
mainOverrideElementControlSystem.setInputStopOverrideControlPausedState (state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0adfc0de6a462d141b0dd5fef223c193
|
||||
timeCreated: 1544174470
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Override System/objectToOverrideSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,255 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class overrideCameraController : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool cameraControllerEnabled = true;
|
||||
public Transform targetToFollow;
|
||||
public Transform pivotTransform;
|
||||
public Transform cameraTransform;
|
||||
public bool cameraActive;
|
||||
|
||||
public Vector2 xLimits;
|
||||
public float rotationSpeed = 10;
|
||||
public float cameraRotationSpeedVertical = 5;
|
||||
public float cameraRotationSpeedHorizontal = 5;
|
||||
|
||||
public LayerMask layer;
|
||||
public float clipCastRadius;
|
||||
public float backClipSpeed;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public float controllerRadius = 2;
|
||||
public bool reapearInCertainPosition;
|
||||
public Transform positionToReapear;
|
||||
|
||||
[Space]
|
||||
[Header ("Gizmo Settings")]
|
||||
[Space]
|
||||
|
||||
public bool showGizmo;
|
||||
public Color gizmoColor = Color.yellow;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public overrideInputManager overrideInput;
|
||||
|
||||
Vector2 axisValues;
|
||||
Vector2 mouseAxis;
|
||||
Vector2 lookAngle;
|
||||
|
||||
Quaternion currentPivotRotation;
|
||||
float currentCameraUpRotation;
|
||||
|
||||
Ray ray;
|
||||
RaycastHit[] hits;
|
||||
float currentCameraDistance;
|
||||
float originalCameraDistance;
|
||||
float cameraSpeed;
|
||||
|
||||
Coroutine updateCoroutine;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
originalCameraDistance = cameraTransform.localPosition.magnitude;
|
||||
}
|
||||
|
||||
public void stopUpdateCoroutine ()
|
||||
{
|
||||
if (updateCoroutine != null) {
|
||||
StopCoroutine (updateCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator updateSystemCoroutine ()
|
||||
{
|
||||
var waitTime = new WaitForSecondsRealtime (0.0001f);
|
||||
|
||||
while (true) {
|
||||
updateSystem ();
|
||||
|
||||
yield return waitTime;
|
||||
}
|
||||
}
|
||||
|
||||
void updateSystem ()
|
||||
{
|
||||
if (cameraControllerEnabled && cameraActive && !overrideInput.isGamePaused ()) {
|
||||
transform.position = targetToFollow.position;
|
||||
|
||||
//get the current input axis values from the input manager
|
||||
axisValues = overrideInput.getCustomMouseAxis ();
|
||||
mouseAxis.x = axisValues.x;
|
||||
mouseAxis.y = axisValues.y;
|
||||
|
||||
//if the first camera view is enabled
|
||||
lookAngle.x = mouseAxis.x * rotationSpeed;
|
||||
lookAngle.y -= mouseAxis.y * rotationSpeed;
|
||||
|
||||
//clamp these values to limit the camera rotation
|
||||
lookAngle.y = Mathf.Clamp (lookAngle.y, xLimits.x, xLimits.y);
|
||||
|
||||
currentPivotRotation = Quaternion.Euler (lookAngle.y, 0, 0);
|
||||
|
||||
pivotTransform.localRotation = Quaternion.Slerp (pivotTransform.localRotation, currentPivotRotation, cameraRotationSpeedVertical * Time.deltaTime);
|
||||
|
||||
currentCameraUpRotation = Mathf.Lerp (currentCameraUpRotation, lookAngle.x, cameraRotationSpeedHorizontal * Time.deltaTime);
|
||||
|
||||
transform.Rotate (0, currentCameraUpRotation, 0);
|
||||
|
||||
//get the current camera position for the camera collision detection
|
||||
currentCameraDistance = checkCameraCollision ();
|
||||
|
||||
//set the local camera position
|
||||
currentCameraDistance = Mathf.Clamp (currentCameraDistance, 0, originalCameraDistance);
|
||||
cameraTransform.localPosition = -Vector3.forward * currentCameraDistance;
|
||||
}
|
||||
}
|
||||
|
||||
public Transform getCameraTransform ()
|
||||
{
|
||||
return cameraTransform;
|
||||
}
|
||||
|
||||
public void setCameraActiveState (bool state)
|
||||
{
|
||||
if (!cameraControllerEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
cameraActive = state;
|
||||
|
||||
stopUpdateCoroutine ();
|
||||
|
||||
if (!cameraActive) {
|
||||
lookAngle = Vector2.zero;
|
||||
mouseAxis = Vector2.zero;
|
||||
axisValues = Vector2.zero;
|
||||
currentPivotRotation = Quaternion.identity;
|
||||
|
||||
currentCameraUpRotation = 0;
|
||||
|
||||
pivotTransform.localRotation = Quaternion.identity;
|
||||
|
||||
transform.rotation = Quaternion.identity;
|
||||
}
|
||||
|
||||
if (cameraActive) {
|
||||
updateCoroutine = StartCoroutine (updateSystemCoroutine ());
|
||||
}
|
||||
}
|
||||
|
||||
public bool isCameraControllerEnabled ()
|
||||
{
|
||||
return cameraControllerEnabled;
|
||||
}
|
||||
|
||||
public void setParentState (bool state)
|
||||
{
|
||||
if (targetToFollow != null) {
|
||||
if (state) {
|
||||
transform.SetParent (null);
|
||||
transform.position = targetToFollow.position;
|
||||
} else {
|
||||
transform.SetParent (targetToFollow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetLocalRotationPosition ()
|
||||
{
|
||||
transform.localRotation = Quaternion.identity;
|
||||
transform.localPosition = Vector3.zero;
|
||||
}
|
||||
|
||||
public void resetRotation (Quaternion newRotation)
|
||||
{
|
||||
transform.eulerAngles = new Vector3 (0, newRotation.eulerAngles.y, 0);
|
||||
}
|
||||
|
||||
//adjust the camera position to avoid cross any collider
|
||||
public float checkCameraCollision ()
|
||||
{
|
||||
//launch a ray from the pivot position to the camera direction
|
||||
ray = new Ray (pivotTransform.position, -pivotTransform.forward);
|
||||
|
||||
//store the hits received
|
||||
hits = Physics.SphereCastAll (ray, clipCastRadius, originalCameraDistance + clipCastRadius, layer);
|
||||
float closest = Mathf.Infinity;
|
||||
float hitDist = originalCameraDistance;
|
||||
|
||||
//find the closest
|
||||
for (int i = 0; i < hits.Length; i++) {
|
||||
if (hits [i].distance < closest && !hits [i].collider.isTrigger) {
|
||||
//the camera will be moved that hitDist in its forward direction
|
||||
closest = hits [i].distance;
|
||||
hitDist = -pivotTransform.InverseTransformPoint (hits [i].point).z;
|
||||
}
|
||||
}
|
||||
|
||||
//clamp the hidDist value
|
||||
if (hitDist < 0) {
|
||||
hitDist = 0;
|
||||
}
|
||||
|
||||
if (hitDist > originalCameraDistance) {
|
||||
hitDist = originalCameraDistance;
|
||||
}
|
||||
|
||||
//return the value of the collision in the camera
|
||||
return Mathf.SmoothDamp (currentCameraDistance, hitDist, ref cameraSpeed, currentCameraDistance > hitDist ? 0 : backClipSpeed);
|
||||
}
|
||||
|
||||
public float getControllerRadius ()
|
||||
{
|
||||
return controllerRadius;
|
||||
}
|
||||
|
||||
public bool reapearInCertainPositionActive ()
|
||||
{
|
||||
return reapearInCertainPosition;
|
||||
}
|
||||
|
||||
public Vector3 getPositionToReapear ()
|
||||
{
|
||||
if (positionToReapear != null) {
|
||||
return positionToReapear.position;
|
||||
} else {
|
||||
return Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
//Draw gizmos
|
||||
void OnDrawGizmos ()
|
||||
{
|
||||
if (!showGizmo) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
|
||||
DrawGizmos ();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected ()
|
||||
{
|
||||
DrawGizmos ();
|
||||
}
|
||||
|
||||
void DrawGizmos ()
|
||||
{
|
||||
if (showGizmo) {
|
||||
Gizmos.color = gizmoColor;
|
||||
Gizmos.DrawWireSphere (transform.position, controllerRadius);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f07ecb0c6ac15674fa7bfad504c00703
|
||||
timeCreated: 1532042956
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Override System/overrideCameraController.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,311 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class overrideController : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public LayerMask layer;
|
||||
public float moveSpeedMultiplier;
|
||||
public float airControlAmount;
|
||||
public float jumpPower;
|
||||
public bool canJump;
|
||||
public float brakeForce = 5;
|
||||
|
||||
public float timeToJumpOnCollidingExit = 0.4f;
|
||||
|
||||
public LayerMask layerMask;
|
||||
|
||||
public float raycastDistance;
|
||||
|
||||
[Space]
|
||||
[Header ("Angular Velocity Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useAngularVelocity;
|
||||
public float angularVelocityRotationSpeed = 100;
|
||||
public float angularVelocityRotationLerpSpeed = 5;
|
||||
public bool applyForceOnAngularVelocity;
|
||||
public float forceMultiplierOnAngularVelocity;
|
||||
|
||||
[Space]
|
||||
[Header ("Run Settings")]
|
||||
[Space]
|
||||
|
||||
public bool canRun;
|
||||
public float runSpeed;
|
||||
|
||||
[Space]
|
||||
[Header ("Impulse Settings")]
|
||||
[Space]
|
||||
|
||||
public bool canImpulse;
|
||||
public float impulseForce;
|
||||
public float impulseCoolDown = 0.5f;
|
||||
|
||||
[Space]
|
||||
[Header ("Damage Settings")]
|
||||
[Space]
|
||||
|
||||
public bool damageObjectsEnabled;
|
||||
public float damageObjectsMultiplier;
|
||||
public bool ignoreShield;
|
||||
public float collisionForceLimit;
|
||||
public bool canActivateReactionSystemTemporally;
|
||||
public int damageReactionID = -1;
|
||||
|
||||
public int damageTypeID = -1;
|
||||
|
||||
public bool damageCanBeBlocked = true;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool controllerEnabled;
|
||||
public bool onGround;
|
||||
public float currentSpeed;
|
||||
public bool runActive;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public overrideInputManager overrideInput;
|
||||
public Transform overrideCameraTransform;
|
||||
public Transform overrideCameraParentTransform;
|
||||
|
||||
public Transform controllerMeshParent;
|
||||
public GameObject controllerMesh;
|
||||
public Transform raycastPosition;
|
||||
|
||||
public Rigidbody mainRigidbody;
|
||||
|
||||
float lastTimeImpulse;
|
||||
|
||||
float horizontalAxis;
|
||||
float verticalAxis;
|
||||
Vector3 moveInput;
|
||||
|
||||
Vector2 axisValues;
|
||||
bool braking;
|
||||
|
||||
float lastTimeOnGround;
|
||||
|
||||
Vector3 forceToApply;
|
||||
|
||||
bool externalForceActivated;
|
||||
Vector3 externalForceValue;
|
||||
|
||||
ContactPoint currentContact;
|
||||
|
||||
Coroutine updateCoroutine;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (mainRigidbody == null) {
|
||||
mainRigidbody = GetComponent<Rigidbody> ();
|
||||
}
|
||||
}
|
||||
|
||||
public void stopUpdateCoroutine ()
|
||||
{
|
||||
if (updateCoroutine != null) {
|
||||
StopCoroutine (updateCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator updateSystemCoroutine ()
|
||||
{
|
||||
var waitTime = new WaitForSecondsRealtime (0.0001f);
|
||||
|
||||
while (true) {
|
||||
updateSystem ();
|
||||
|
||||
yield return waitTime;
|
||||
}
|
||||
}
|
||||
|
||||
void updateSystem ()
|
||||
{
|
||||
if (controllerEnabled) {
|
||||
if (Physics.Raycast (raycastPosition.position, -raycastPosition.up, raycastDistance, layerMask)) {
|
||||
onGround = true;
|
||||
lastTimeOnGround = Time.time;
|
||||
} else {
|
||||
onGround = false;
|
||||
}
|
||||
|
||||
axisValues = overrideInput.getCustomMovementAxis ();
|
||||
|
||||
horizontalAxis = axisValues.x;
|
||||
verticalAxis = axisValues.y;
|
||||
|
||||
moveInput = verticalAxis * overrideCameraTransform.forward + horizontalAxis * overrideCameraTransform.right;
|
||||
|
||||
forceToApply = Vector3.zero;
|
||||
|
||||
if (onGround) {
|
||||
forceToApply = moveInput * moveSpeedMultiplier;
|
||||
} else {
|
||||
forceToApply = moveInput * airControlAmount;
|
||||
}
|
||||
|
||||
if (externalForceActivated) {
|
||||
mainRigidbody.AddForce (externalForceValue);
|
||||
onGround = false;
|
||||
externalForceActivated = false;
|
||||
}
|
||||
|
||||
if (onGround) {
|
||||
currentSpeed = mainRigidbody.linearVelocity.magnitude;
|
||||
|
||||
if (runActive) {
|
||||
forceToApply *= runSpeed;
|
||||
}
|
||||
|
||||
if (useAngularVelocity) {
|
||||
if (forceToApply != Vector3.zero) {
|
||||
Quaternion targeRotation = Quaternion.LookRotation (Vector3.Cross (forceToApply, overrideCameraTransform.up), transform.up);
|
||||
|
||||
mainRigidbody.rotation = Quaternion.Lerp (mainRigidbody.rotation, targeRotation, Time.deltaTime * angularVelocityRotationLerpSpeed);
|
||||
mainRigidbody.angularVelocity = mainRigidbody.rotation * new Vector3 (0f, 0f, -angularVelocityRotationSpeed);
|
||||
|
||||
if (applyForceOnAngularVelocity) {
|
||||
mainRigidbody.AddForce (forceToApply * forceMultiplierOnAngularVelocity, ForceMode.VelocityChange);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mainRigidbody.AddForce (forceToApply, ForceMode.VelocityChange);
|
||||
}
|
||||
} else {
|
||||
mainRigidbody.AddForce (forceToApply);
|
||||
}
|
||||
|
||||
if (braking) {
|
||||
float verticalVelocity = overrideCameraTransform.InverseTransformDirection (mainRigidbody.linearVelocity).y;
|
||||
Vector3 downVelocity = overrideCameraTransform.up * verticalVelocity;
|
||||
|
||||
mainRigidbody.linearVelocity = Vector3.Lerp (mainRigidbody.linearVelocity, Vector3.zero + downVelocity, Time.deltaTime * brakeForce);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void changeControllerState (bool state)
|
||||
{
|
||||
controllerEnabled = state;
|
||||
|
||||
stopUpdateCoroutine ();
|
||||
|
||||
braking = false;
|
||||
runActive = false;
|
||||
|
||||
axisValues = Vector2.zero;
|
||||
moveInput = Vector3.zero;
|
||||
horizontalAxis = 0;
|
||||
verticalAxis = 0;
|
||||
|
||||
if (mainRigidbody != null) {
|
||||
mainRigidbody.linearVelocity = Vector3.zero;
|
||||
mainRigidbody.isKinematic = !state;
|
||||
}
|
||||
|
||||
if (controllerEnabled) {
|
||||
updateCoroutine = StartCoroutine (updateSystemCoroutine ());
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter (Collision collision)
|
||||
{
|
||||
if (damageObjectsEnabled) {
|
||||
|
||||
currentContact = collision.contacts [0];
|
||||
|
||||
float collisionMagnitude = collision.relativeVelocity.magnitude;
|
||||
|
||||
//check that the collision is not with the player
|
||||
//if the velocity of the collision is higher that the limit
|
||||
if (collisionMagnitude > collisionForceLimit) {
|
||||
applyDamage.checkHealth (gameObject, collision.collider.gameObject, collisionMagnitude * damageObjectsMultiplier,
|
||||
currentContact.normal, currentContact.point, gameObject, false, true, ignoreShield, false, damageCanBeBlocked,
|
||||
canActivateReactionSystemTemporally, damageReactionID, damageTypeID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setControllerMesh (GameObject newControllerMesh)
|
||||
{
|
||||
controllerMesh = newControllerMesh;
|
||||
|
||||
controllerMesh.transform.SetParent (controllerMeshParent);
|
||||
|
||||
controllerMesh.AddComponent<parentAssignedSystem> ().assignParent (gameObject);
|
||||
}
|
||||
|
||||
public GameObject getControllerMesh ()
|
||||
{
|
||||
return controllerMesh;
|
||||
}
|
||||
|
||||
public void removeControllerMesh ()
|
||||
{
|
||||
controllerMesh.transform.SetParent (null);
|
||||
|
||||
parentAssignedSystem currentParentAssignedSystem = controllerMesh.GetComponent<parentAssignedSystem> ();
|
||||
|
||||
if (currentParentAssignedSystem != null) {
|
||||
Destroy (currentParentAssignedSystem);
|
||||
}
|
||||
}
|
||||
|
||||
public void inputJump ()
|
||||
{
|
||||
if (canJump && onGround && Time.time < lastTimeOnGround + timeToJumpOnCollidingExit) {
|
||||
externalForceValue = overrideCameraTransform.up * mainRigidbody.mass * jumpPower;
|
||||
|
||||
externalForceActivated = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void inputSetBrakeState (bool state)
|
||||
{
|
||||
if (state) {
|
||||
if (onGround) {
|
||||
braking = true;
|
||||
}
|
||||
} else {
|
||||
braking = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void inputImpulse ()
|
||||
{
|
||||
if (canImpulse) {
|
||||
if (Time.time > impulseCoolDown + lastTimeImpulse) {
|
||||
|
||||
lastTimeImpulse = Time.time;
|
||||
|
||||
Vector3 dashDirection = moveInput;
|
||||
|
||||
dashDirection.Normalize ();
|
||||
|
||||
if (dashDirection == Vector3.zero || dashDirection.magnitude < 0.1f) {
|
||||
dashDirection = overrideCameraParentTransform.forward;
|
||||
}
|
||||
|
||||
externalForceValue = dashDirection * impulseForce * mainRigidbody.mass;
|
||||
|
||||
externalForceActivated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void inputRunState (bool state)
|
||||
{
|
||||
if (canRun) {
|
||||
runActive = state;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dc5daaf357072b241b0a0dcca583bd3b
|
||||
timeCreated: 1532299831
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Override System/overrideController.cs
|
||||
uploadId: 814740
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b923e30de17efa4594ab5d838b96eaa
|
||||
timeCreated: 1532012615
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Override System/overrideElementControlSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,468 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class overrideInputManager : MonoBehaviour
|
||||
{
|
||||
public List<multiAxes> multiAxesList = new List<multiAxes> ();
|
||||
|
||||
public bool inputEnabled;
|
||||
public bool isPlayerController;
|
||||
public playerInputManager playerInput;
|
||||
|
||||
public UnityEvent startOverrideFunction;
|
||||
public UnityEvent stopOverrideFunction;
|
||||
|
||||
public bool usePreOverrideFunctions;
|
||||
public UnityEvent preStartOverrideFunction;
|
||||
public UnityEvent preStopOverrideFunction;
|
||||
|
||||
public bool activateActionScreen = true;
|
||||
public string actionScreenName;
|
||||
|
||||
public bool destroyObjectOnStopOverride;
|
||||
public UnityEvent eventToDestroy;
|
||||
|
||||
public bool showDebugActions;
|
||||
|
||||
public overrideCameraController overrideCameraControllerManager;
|
||||
|
||||
GameObject currentPlayer;
|
||||
playerController playerControllerManager;
|
||||
|
||||
public inputManager input;
|
||||
|
||||
overrideElementControlSystem currentOverrideElementControlSystem;
|
||||
|
||||
multiAxes currentMultiAxes;
|
||||
Axes currentAxes;
|
||||
|
||||
int currentMultiAxesCount;
|
||||
int currentAxesCount;
|
||||
|
||||
int MAIndex;
|
||||
int AIndex;
|
||||
|
||||
Coroutine updateCoroutine;
|
||||
|
||||
bool playerInputAssigned;
|
||||
|
||||
public void stopUpdateCoroutine ()
|
||||
{
|
||||
if (updateCoroutine != null) {
|
||||
StopCoroutine (updateCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator updateSystemCoroutine ()
|
||||
{
|
||||
var waitTime = new WaitForSecondsRealtime (0.0001f);
|
||||
|
||||
while (true) {
|
||||
updateSystem ();
|
||||
|
||||
yield return waitTime;
|
||||
}
|
||||
}
|
||||
|
||||
void updateSystem ()
|
||||
{
|
||||
if (inputEnabled) {
|
||||
for (MAIndex = 0; MAIndex < currentMultiAxesCount; MAIndex++) {
|
||||
currentMultiAxes = multiAxesList [MAIndex];
|
||||
|
||||
if (currentMultiAxes.currentlyActive) {
|
||||
currentAxesCount = currentMultiAxes.axes.Count;
|
||||
|
||||
for (AIndex = 0; AIndex < currentAxesCount; AIndex++) {
|
||||
currentAxes = currentMultiAxes.axes [AIndex];
|
||||
|
||||
if (currentAxes.actionEnabled) {
|
||||
if (playerInput.checkPlayerInputButtonFromMultiAxesList (currentMultiAxes.multiAxesStringIndex, currentAxes.axesStringIndex,
|
||||
currentAxes.buttonPressType, currentAxes.canBeUsedOnPausedGame)) {
|
||||
|
||||
if (showDebugActions) {
|
||||
print (currentAxes.Name);
|
||||
}
|
||||
|
||||
currentAxes.buttonEvent.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 getCustomRawMovementAxis ()
|
||||
{
|
||||
if (!inputEnabled) {
|
||||
return Vector2.zero;
|
||||
}
|
||||
|
||||
return playerInput.getPlayerRawMovementAxis ();
|
||||
}
|
||||
|
||||
public Vector2 getCustomMovementAxis ()
|
||||
{
|
||||
if (!inputEnabled) {
|
||||
return Vector2.zero;
|
||||
}
|
||||
|
||||
return playerInput.getPlayerMovementAxis ();
|
||||
}
|
||||
|
||||
public Vector2 getCustomMouseAxis ()
|
||||
{
|
||||
if (!inputEnabled) {
|
||||
return Vector2.zero;
|
||||
}
|
||||
|
||||
return playerInput.getPlayerMouseAxis ();
|
||||
}
|
||||
|
||||
public void setCustomInputEnabledState (bool state)
|
||||
{
|
||||
inputEnabled = state;
|
||||
|
||||
stopUpdateCoroutine ();
|
||||
|
||||
if (inputEnabled) {
|
||||
updateCoroutine = StartCoroutine (updateSystemCoroutine ());
|
||||
}
|
||||
}
|
||||
|
||||
public void setPlayerInfo (GameObject player)
|
||||
{
|
||||
currentPlayer = player;
|
||||
|
||||
if (currentPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
findInputManager ();
|
||||
|
||||
currentMultiAxesCount = multiAxesList.Count;
|
||||
|
||||
playerComponentsManager mainPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
playerControllerManager = mainPlayerComponentsManager.getPlayerController ();
|
||||
|
||||
currentOverrideElementControlSystem = mainPlayerComponentsManager.getOverrideElementControlSystem ();
|
||||
|
||||
if (isPlayerController) {
|
||||
playerInputManager currentPlayerInputManager = mainPlayerComponentsManager.getPlayerInputManager ();
|
||||
|
||||
if (currentPlayerInputManager != null) {
|
||||
playerInput.setTouchMovementControl (currentPlayerInputManager.getTouchMovementControl ());
|
||||
|
||||
playerInput.setTouchCameraControl (currentPlayerInputManager.getTouchCameraControl ());
|
||||
}
|
||||
} else {
|
||||
playerInput = mainPlayerComponentsManager.getPlayerInputManager ();
|
||||
}
|
||||
|
||||
playerInputAssigned = playerInput != null;
|
||||
}
|
||||
|
||||
public void overrideControlState (bool state, GameObject currentPlayer)
|
||||
{
|
||||
if (state) {
|
||||
setPlayerInfo (currentPlayer);
|
||||
|
||||
startOverrideFunction.Invoke ();
|
||||
} else {
|
||||
stopOverrideFunction.Invoke ();
|
||||
}
|
||||
|
||||
if (playerInput != null) {
|
||||
if (isPlayerController) {
|
||||
playerInput.setPlayerID (playerControllerManager.getPlayerID ());
|
||||
playerInput.setPlayerInputEnabledState (state);
|
||||
} else {
|
||||
playerInput.setInputCurrentlyActiveState (!state);
|
||||
}
|
||||
}
|
||||
|
||||
setCustomInputEnabledState (state);
|
||||
|
||||
checkActivateActionScreen (state);
|
||||
}
|
||||
|
||||
public void checkActivateActionScreen (bool state)
|
||||
{
|
||||
if (activateActionScreen) {
|
||||
if (playerControllerManager != null) {
|
||||
playerControllerManager.getPlayerInput ().enableOrDisableActionScreen (actionScreenName, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setPreOverrideControlState (bool state)
|
||||
{
|
||||
if (usePreOverrideFunctions) {
|
||||
if (state) {
|
||||
preStartOverrideFunction.Invoke ();
|
||||
} else {
|
||||
preStopOverrideFunction.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stopOverride ()
|
||||
{
|
||||
if (inputEnabled) {
|
||||
currentOverrideElementControlSystem.stopCurrentOverrideControl ();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeNewTemporalObjectFromOverrideControlSystem (GameObject newObject)
|
||||
{
|
||||
if (currentOverrideElementControlSystem != null) {
|
||||
currentOverrideElementControlSystem.removeNewTemporalObject (newObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void setPlayerInputActionState (bool playerInputActionState, string multiAxesInputName, string axesInputName)
|
||||
{
|
||||
for (int i = 0; i < multiAxesList.Count; i++) {
|
||||
if (multiAxesList [i].axesName.Equals (multiAxesInputName)) {
|
||||
for (int j = 0; j < multiAxesList [i].axes.Count; j++) {
|
||||
if (multiAxesList [i].axes [j].Name.Equals (axesInputName)) {
|
||||
multiAxesList [i].axes [j].actionEnabled = playerInputActionState;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setPlayerInputMultiAxesState (bool playerInputMultiAxesState, string multiAxesInputName)
|
||||
{
|
||||
for (int i = 0; i < multiAxesList.Count; i++) {
|
||||
if (multiAxesList [i].axesName.Equals (multiAxesInputName)) {
|
||||
multiAxesList [i].currentlyActive = playerInputMultiAxesState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void enablePlayerInputMultiAxes (string multiAxesInputName)
|
||||
{
|
||||
for (int i = 0; i < multiAxesList.Count; i++) {
|
||||
if (multiAxesList [i].axesName.Equals (multiAxesInputName)) {
|
||||
multiAxesList [i].currentlyActive = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void disablePlayerInputMultiAxes (string multiAxesInputName)
|
||||
{
|
||||
for (int i = 0; i < multiAxesList.Count; i++) {
|
||||
if (multiAxesList [i].axesName.Equals (multiAxesInputName)) {
|
||||
multiAxesList [i].currentlyActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool isGamePaused ()
|
||||
{
|
||||
if (playerInputAssigned) {
|
||||
return playerInput.isGameManagerPaused ();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//EDITOR FUNCTIONS
|
||||
public void addNewAxes ()
|
||||
{
|
||||
findInputManager ();
|
||||
|
||||
if (input != null) {
|
||||
multiAxes newMultiAxes = new multiAxes ();
|
||||
|
||||
newMultiAxes.multiAxesStringList = new string [input.multiAxesList.Count];
|
||||
|
||||
for (int i = 0; i < input.multiAxesList.Count; i++) {
|
||||
string axesName = input.multiAxesList [i].axesName;
|
||||
newMultiAxes.multiAxesStringList [i] = axesName;
|
||||
}
|
||||
|
||||
multiAxesList.Add (newMultiAxes);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
}
|
||||
|
||||
public void addNewAction (int multiAxesIndex)
|
||||
{
|
||||
findInputManager ();
|
||||
|
||||
if (input != null) {
|
||||
multiAxes currentMultiAxesList = multiAxesList [multiAxesIndex];
|
||||
|
||||
Axes newAxes = new Axes ();
|
||||
|
||||
newAxes.axesStringList = new string [input.multiAxesList [currentMultiAxesList.multiAxesStringIndex].axes.Count];
|
||||
|
||||
for (int i = 0; i < input.multiAxesList [currentMultiAxesList.multiAxesStringIndex].axes.Count; i++) {
|
||||
string actionName = input.multiAxesList [currentMultiAxesList.multiAxesStringIndex].axes [i].Name;
|
||||
newAxes.axesStringList [i] = actionName;
|
||||
}
|
||||
|
||||
newAxes.multiAxesStringIndex = multiAxesIndex;
|
||||
currentMultiAxesList.axes.Add (newAxes);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateMultiAxesList ()
|
||||
{
|
||||
findInputManager ();
|
||||
|
||||
if (input != null) {
|
||||
for (int i = 0; i < multiAxesList.Count; i++) {
|
||||
multiAxesList [i].multiAxesStringList = new string [input.multiAxesList.Count];
|
||||
|
||||
for (int j = 0; j < input.multiAxesList.Count; j++) {
|
||||
string axesName = input.multiAxesList [j].axesName;
|
||||
multiAxesList [i].multiAxesStringList [j] = axesName;
|
||||
}
|
||||
|
||||
multiAxesList [i].axesName = input.multiAxesList [multiAxesList [i].multiAxesStringIndex].axesName;
|
||||
}
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAxesList (int multiAxesListIndex)
|
||||
{
|
||||
findInputManager ();
|
||||
|
||||
if (input != null) {
|
||||
multiAxes currentMultiAxesList = multiAxesList [multiAxesListIndex];
|
||||
|
||||
for (int i = 0; i < currentMultiAxesList.axes.Count; i++) {
|
||||
currentMultiAxesList.axes [i].axesStringList = new string [input.multiAxesList [currentMultiAxesList.multiAxesStringIndex].axes.Count];
|
||||
|
||||
for (int j = 0; j < input.multiAxesList [currentMultiAxesList.multiAxesStringIndex].axes.Count; j++) {
|
||||
string actionName = input.multiAxesList [currentMultiAxesList.multiAxesStringIndex].axes [j].Name;
|
||||
currentMultiAxesList.axes [i].axesStringList [j] = actionName;
|
||||
}
|
||||
}
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
}
|
||||
|
||||
public void setAllAxesList (int multiAxesListIndex)
|
||||
{
|
||||
findInputManager ();
|
||||
|
||||
if (input != null) {
|
||||
|
||||
multiAxes currentMultiAxesList = multiAxesList [multiAxesListIndex];
|
||||
|
||||
currentMultiAxesList.axes.Clear ();
|
||||
|
||||
for (int i = 0; i < input.multiAxesList [currentMultiAxesList.multiAxesStringIndex].axes.Count; i++) {
|
||||
Axes newAxes = new Axes ();
|
||||
|
||||
newAxes.axesStringList = new string [input.multiAxesList [currentMultiAxesList.multiAxesStringIndex].axes.Count];
|
||||
|
||||
for (int j = 0; j < input.multiAxesList [currentMultiAxesList.multiAxesStringIndex].axes.Count; j++) {
|
||||
string actionName = input.multiAxesList [currentMultiAxesList.multiAxesStringIndex].axes [j].Name;
|
||||
newAxes.axesStringList [j] = actionName;
|
||||
}
|
||||
|
||||
newAxes.multiAxesStringIndex = multiAxesListIndex;
|
||||
newAxes.axesStringIndex = i;
|
||||
newAxes.Name = input.multiAxesList [currentMultiAxesList.multiAxesStringIndex].axes [i].Name;
|
||||
newAxes.actionName = newAxes.Name;
|
||||
|
||||
currentMultiAxesList.axes.Add (newAxes);
|
||||
}
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
}
|
||||
|
||||
void findInputManager ()
|
||||
{
|
||||
bool inputManagerLocated = input != null;
|
||||
|
||||
if (!inputManagerLocated) {
|
||||
input = inputManager.Instance;
|
||||
|
||||
inputManagerLocated = input != null;
|
||||
}
|
||||
|
||||
if (!inputManagerLocated) {
|
||||
input = FindObjectOfType<inputManager> ();
|
||||
|
||||
input.getComponentInstanceOnApplicationPlaying ();
|
||||
|
||||
inputManagerLocated = input != null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setMultiAxesEnabledState (bool state)
|
||||
{
|
||||
for (int i = 0; i < multiAxesList.Count; i++) {
|
||||
multiAxesList [i].currentlyActive = state;
|
||||
}
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void setAllActionsEnabledState (int multiAxesListIndex, bool state)
|
||||
{
|
||||
for (int j = 0; j < multiAxesList [multiAxesListIndex].axes.Count; j++) {
|
||||
multiAxesList [multiAxesListIndex].axes [j].actionEnabled = state;
|
||||
}
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public overrideCameraController getOverrideCameraControllerManager ()
|
||||
{
|
||||
return overrideCameraControllerManager;
|
||||
}
|
||||
|
||||
public void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class multiAxes
|
||||
{
|
||||
public string axesName;
|
||||
public List<Axes> axes = new List<Axes> ();
|
||||
public GameObject screenActionsGameObject;
|
||||
public bool currentlyActive = true;
|
||||
public int multiAxesStringIndex;
|
||||
public string [] multiAxesStringList;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class Axes
|
||||
{
|
||||
public string actionName = "New Action";
|
||||
public string Name;
|
||||
public bool actionEnabled = true;
|
||||
|
||||
public bool canBeUsedOnPausedGame;
|
||||
|
||||
public inputManager.buttonType buttonPressType;
|
||||
|
||||
public UnityEvent buttonEvent;
|
||||
|
||||
public int axesStringIndex;
|
||||
public string [] axesStringList;
|
||||
|
||||
public int multiAxesStringIndex;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd5af0f47a36dde49b1d1d6e68aa1cd7
|
||||
timeCreated: 1532024878
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 40995
|
||||
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
|
||||
packageVersion: 3.77g
|
||||
assetPath: Assets/Game Kit Controller/Scripts/Override System/overrideInputManager.cs
|
||||
uploadId: 814740
|
||||
Reference in New Issue
Block a user