plantilla base para movimiento básico
This commit is contained in:
Robii Aragon
2026-02-05 05:07:55 -08:00
parent 195b696771
commit 779f2c8b20
14443 changed files with 23840465 additions and 452 deletions

View File

@@ -0,0 +1,355 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class artificialObjectGravity : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public LayerMask layer;
public float rayDistance;
public PhysicsMaterial highFrictionMaterial;
public float gravityForce = 9.8f;
[Space]
[Header ("Debug")]
[Space]
public bool onGround;
public bool active = true;
public Vector3 normal;
public Vector3 hitPoint;
public Vector3 auxNormal;
public bool normalAssigned;
public bool zeroGravityActive;
[Space]
[Header ("Center Point Settings")]
[Space]
public bool useCenterPointActive;
public Transform currentCenterPoint;
public bool useInverseDirectionToCenterPoint;
public bool useCenterPointListForRigidbodies;
public List<Transform> centerPointList = new List<Transform> ();
RaycastHit hit;
bool onGroundChecked;
float groundAdherence = 10;
Rigidbody mainRigidbody;
Collider mainCollider;
bool objectActivated;
float originalGravityForce;
Vector3 currentNormalDirection;
float minDistance;
float currentDistance;
float downVelocity;
bool useGravityActive;
Vector3 currentPosition;
bool mainRigidbodyLocated;
public void getComponents ()
{
if (!objectActivated) {
if (mainRigidbody == null) {
mainRigidbody = GetComponent<Rigidbody> ();
}
if (mainRigidbody != null) {
mainRigidbodyLocated = true;
}
if (mainCollider == null) {
mainCollider = GetComponent<Collider> ();
}
objectActivated = true;
originalGravityForce = gravityForce;
}
}
//this script is added to an object with a rigidbody, to change its gravity, disabling the useGravity parameter, and adding force in a new direction
//checking in the object is in its new ground or not
void FixedUpdate ()
{
//if nothing pauses the script and the gameObject has rigidbody and it is not kinematic
if (active && mainRigidbodyLocated) {
if (!mainRigidbody.isKinematic) {
//check if the object is on ground or in the air, to apply or not force in its gravity direction
currentNormalDirection = normal;
currentPosition = transform.position;
if (useCenterPointActive) {
if (useCenterPointListForRigidbodies) {
minDistance = Mathf.Infinity;
for (int i = 0; i < centerPointList.Count; i++) {
currentDistance = GKC_Utils.distance (currentPosition, centerPointList [i].position);
if (currentDistance < minDistance) {
minDistance = currentDistance;
currentCenterPoint = centerPointList [i];
}
}
}
if (useInverseDirectionToCenterPoint) {
currentNormalDirection = currentPosition - currentCenterPoint.position;
} else {
currentNormalDirection = currentCenterPoint.position - currentPosition;
}
currentNormalDirection = currentNormalDirection / currentNormalDirection.magnitude;
}
if (zeroGravityActive) {
if (onGround) {
onGround = false;
onGroundChecked = false;
mainCollider.material = null;
}
} else {
if (onGround) {
if (!onGroundChecked) {
onGroundChecked = true;
mainCollider.material = highFrictionMaterial;
}
} else {
if (onGroundChecked) {
onGroundChecked = false;
mainCollider.material = null;
}
mainRigidbody.AddForce (gravityForce * mainRigidbody.mass * currentNormalDirection);
if (useGravityActive) {
mainRigidbody.useGravity = false;
useGravityActive = false;
}
}
//use a raycast to check the ground
if (Physics.Raycast (currentPosition, currentNormalDirection, out hit, (rayDistance + transform.localScale.x / 2), layer)) {
if (!hit.collider.isTrigger && hit.rigidbody == null) {
onGround = true;
downVelocity = transform.InverseTransformDirection (mainRigidbody.linearVelocity).y;
if (downVelocity > .5f) {
mainRigidbody.position = Vector3.MoveTowards (mainRigidbody.position, hit.point, Time.deltaTime * groundAdherence);
}
if (downVelocity < .01f) {
mainRigidbody.linearVelocity = Vector3.zero;
}
}
} else {
onGround = false;
}
}
}
}
//if the gameObject has not rigidbody, remove the script
if (!mainRigidbodyLocated) {
gameObject.layer = LayerMask.NameToLayer ("Default");
Destroy (this);
}
}
//when the object is dropped, set its forward direction to move until a surface will be detected
public void enableGravity (LayerMask layer, PhysicsMaterial frictionMaterial, Vector3 normalDirection)
{
getComponents ();
this.layer = layer;
highFrictionMaterial = frictionMaterial;
mainRigidbody.useGravity = false;
useGravityActive = false;
normal = normalDirection;
normalAssigned = false;
}
public void setActiveState (bool state)
{
active = state;
}
public void removeGravity ()
{
//set the layer again to default, active the gravity and remove the script
gameObject.layer = LayerMask.NameToLayer ("Default");
if (mainRigidbody != null) {
mainRigidbody.useGravity = true;
useGravityActive = true;
}
Destroy (this);
}
public void removeGravityComponent ()
{
gameObject.layer = LayerMask.NameToLayer ("Default");
Destroy (this);
}
public void removeJustGravityComponent ()
{
Destroy (this);
}
void OnCollisionEnter (Collision collision)
{
//when the objects collides with anything, use the normal of the collision
if (active && collision.gameObject.layer != LayerMask.NameToLayer ("Ignore Raycast") && !normalAssigned && !mainRigidbody.isKinematic) {
//get the normal of the collision
Vector3 direction = collision.contacts [0].normal;
//Debug.DrawRay (transform.position,-direction, Color.red, 200,false);
if (Physics.Raycast (transform.position, -direction, out hit, 3, layer)) {
if (!hit.collider.isTrigger && hit.rigidbody == null) {
normal = -hit.normal;
//the hit point is used for the turret rotation
hitPoint = hit.point;
// @todo Tag doesn't exist, layer used now in stead. Fix me when refactoring this code.
bool isTurret = gameObject.CompareTag ("turret");
//check the type of object
if (isTurret) {
//if the direction is the actual ground, remove the script to set the regular gravity
if (normal == -Vector3.up) {
removeGravity ();
return;
}
normalAssigned = true;
}
//if the object is an ally turret, call a function to set it kinematic when it touch the ground
if (isTurret) {
if (!mainRigidbody.isKinematic) {
StartCoroutine (rotateToSurface ());
}
}
}
}
}
}
//when an ally turret hits a surface, rotate the turret to that surface, so the player can set a turret in any place to help him
IEnumerator rotateToSurface ()
{
mainRigidbody.useGravity = true;
mainRigidbody.isKinematic = true;
useGravityActive = true;
//it rotates the turret in the same way that the player rotates with his gravity power
Quaternion rot = transform.rotation;
Vector3 myForward = Vector3.Cross (transform.right, -normal);
Quaternion dstRot = Quaternion.LookRotation (myForward, -normal);
for (float t = 0; t < 1;) {
t += Time.deltaTime * 3;
transform.rotation = Quaternion.Slerp (rot, dstRot, t);
transform.position = Vector3.MoveTowards (transform.position, hitPoint + 0.5f * transform.up, t);
yield return null;
}
gameObject.layer = LayerMask.NameToLayer ("Default");
//if the surface is the regular ground, remove the artificial gravity, and make the turret stays kinematic when it will touch the ground
if (-normal == Vector3.up) {
SendMessage ("enabledKinematic", false);
removeGravity ();
}
}
public void setZeroGravityActiveState (bool state)
{
getComponents ();
zeroGravityActive = state;
if (zeroGravityActive) {
mainRigidbody.useGravity = false;
}
}
//set directly a new normal
public void setCurrentGravity (Vector3 newNormal)
{
getComponents ();
mainRigidbody.useGravity = false;
normal = newNormal;
normalAssigned = true;
useGravityActive = false;
}
public void setUseCenterPointActiveState (bool state, Transform newCenterPoint)
{
useCenterPointActive = state;
currentCenterPoint = newCenterPoint;
}
public void setUseInverseDirectionToCenterPointState (bool state)
{
useInverseDirectionToCenterPoint = state;
}
public void setGravityForceValue (bool setOriginal, float newValue)
{
if (setOriginal) {
gravityForce = originalGravityForce;
} else {
gravityForce = newValue;
}
}
public void setUseCenterPointListForRigidbodiesState (bool state, List<Transform> newCenterPointList)
{
useCenterPointListForRigidbodies = state;
centerPointList = newCenterPointList;
}
}

View File

@@ -0,0 +1,17 @@
fileFormatVersion: 2
guid: 15f2b67244ee18540ae6145ed17d0267
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/Gravity/artificialObjectGravity.cs
uploadId: 814740

View File

@@ -0,0 +1,36 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class gravityObjectManager : MonoBehaviour
{
public virtual void onGroundOrOnAir (bool state)
{
}
public virtual bool isSearchingSurface ()
{
return false;
}
public virtual Vector3 getCurrentNormal ()
{
return Vector3.zero;
}
public virtual Transform getGravityCenter ()
{
return null;
}
public virtual bool isPlayerSearchingGravitySurface ()
{
return false;
}
public virtual bool isUsingRegularGravity ()
{
return true;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 0a28881ef15326848897eeb315777aec
timeCreated: 1631144186
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/Gravity/gravityObjectManager.cs
uploadId: 814740

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,17 @@
fileFormatVersion: 2
guid: dbda9b2425530df4b8b032d1b4ffe1a4
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/Gravity/gravitySystem.cs
uploadId: 814740

View File

@@ -0,0 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class objectToUseArtificialGravitySystem : MonoBehaviour
{
//custom values for the artificial gravity object
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 68c0393f83226774d8d46c57bdec126c
timeCreated: 1545593882
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/Gravity/objectToUseArtificialGravitySystem.cs
uploadId: 814740

View File

@@ -0,0 +1,55 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class parentAssignedSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public GameObject parentGameObject;
[Space]
[Header ("Main Settings")]
[Space]
public bool parentAssigned;
public void assignParent (GameObject newParent)
{
parentGameObject = newParent;
parentAssigned = parentGameObject != null;
}
public GameObject getAssignedParent ()
{
if (!parentAssigned) {
if (parentGameObject == null) {
parentGameObject = gameObject;
}
parentAssigned = parentGameObject != null;
}
return parentGameObject;
}
public Transform getAssignedParentTransform ()
{
if (!parentAssigned) {
if (parentGameObject == null) {
parentGameObject = gameObject;
}
parentAssigned = parentGameObject != null;
}
if (parentAssigned) {
return parentGameObject.transform;
}
return null;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 571b463d360e31943bec101ce5d5ad1d
timeCreated: 1532368654
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/Gravity/parentAssignedSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,517 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class setGravity : MonoBehaviour
{
public bool useWithPlayer;
public bool useWithNPC;
public bool useWithVehicles;
public bool useWithAnyRigidbody;
public bool rotateVehicleToGravityDirection;
public bool useCenterPointOnVehicle;
public string playerTag = "Player";
public string friendTag = "friend";
public string enemyTag = "enemy";
public bool checkOnlyForArtificialGravitySystem;
public bool setCustomGravityForce;
public float customGravityForce;
public bool setCustomGravityForceOnCharactersEnabled;
public triggerType typeOfTrigger;
public enum triggerType
{
enter,
exit,
both
}
public bool setGravityMode = true;
public bool setRegularGravity;
public bool setZeroGravity;
public bool disableZeroGravity;
public bool movePlayerToGravityPosition;
public Transform raycastPositionToGetGravityPosition;
public LayerMask layermaskToGetGravityPosition;
public float teleportSpeed;
public float rotationSpeed;
public bool useCustomGravityDirection;
public Vector3 customGravityDirection;
public bool useCenterPoint;
public Transform centerPoint;
public bool useCenterPointForRigidbodies;
public bool useInverseDirectionToCenterPoint;
public bool useCenterPointOnCharacters;
public bool useCenterPointList;
public bool useCenterIfPointListTooClose = true;
public List<Transform> centerPointList = new List<Transform> ();
public bool useCenterPointListForRigidbodies;
public bool changeGravityDirectionActive;
public bool rotateToSurfaceSmoothly = true;
public bool setCircumnavigateSurfaceState;
public bool circumnavigateSurfaceState;
public bool setCheckSurfaceInFrontState;
public bool checkSurfaceInFrontState;
public bool setCheckSurfaceBelowLedgeState;
public bool checkSurfaceBelowLedgeState;
public bool preservePlayerVelocity = true;
public bool storeSetGravityManager = true;
public bool setTargetParent;
public GameObject targetParent;
public bool setRigidbodiesParent;
public bool useAnimation = true;
public string animationName = "arrowAnim";
public Animation mainAnimation;
public bool dropObjectIfGabbed = true;
public bool dropObjectOnlyIfNotGrabbedPhysically;
public List<artificialObjectGravity> artificialObjectGravityList = new List<artificialObjectGravity> ();
public List<GameObject> vehicleGameObjectList = new List<GameObject> ();
public bool useInitialObjectsOnGravityList;
public List<GameObject> initialObjectsOnGravityList = new List<GameObject> ();
public bool showDebugPrint;
bool inside;
GameObject objectToChangeGravity;
GameObject character;
grabObjects grabObjectsManager;
grabbedObjectState currentGrabbedObject;
bool initialObjectLisChecked;
vehicleGravityControl currentVehicleGravityControl;
void Start ()
{
if (useAnimation && mainAnimation == null) {
mainAnimation = GetComponent<Animation> ();
if (mainAnimation == null) {
useAnimation = false;
}
}
if (centerPoint == null) {
centerPoint = transform;
}
}
//set a custom gravity for the player and the vehicles, in the direction of the arrow
void Update ()
{
if (useAnimation) {
mainAnimation.Play (animationName);
}
if (!initialObjectLisChecked) {
if (useInitialObjectsOnGravityList) {
for (int i = 0; i < initialObjectsOnGravityList.Count; i++) {
if (initialObjectsOnGravityList [i] != null) {
checkObjectOnGravitySystem (initialObjectsOnGravityList [i], true);
}
}
}
initialObjectLisChecked = true;
}
}
void OnTriggerEnter (Collider col)
{
if (typeOfTrigger == triggerType.enter || typeOfTrigger == triggerType.both) {
checkTriggerType (col, true);
}
}
void OnTriggerExit (Collider col)
{
if (typeOfTrigger == triggerType.exit || typeOfTrigger == triggerType.both) {
checkTriggerType (col, false);
}
}
public void checkObjectGravityOnEnter (GameObject objectToCheck)
{
checkTriggerType (objectToCheck.GetComponent<Collider> (), true);
}
public void checkObjectGravityOnExit (GameObject objectToCheck)
{
checkTriggerType (objectToCheck.GetComponent<Collider> (), false);
}
public void checkTriggerType (Collider col, bool isEnter)
{
if (col == null) {
return;
}
if (col.isTrigger) {
if (showDebugPrint) {
print (applyDamage.isVehicle (col.gameObject));
}
if (useWithVehicles && !applyDamage.isVehicle (col.gameObject)) {
return;
} else {
return;
}
}
checkObjectOnGravitySystem (col.gameObject, isEnter);
}
public void checkObjectOnGravitySystem (GameObject objectToCheck, bool isEnter)
{
objectToChangeGravity = objectToCheck;
if (showDebugPrint) {
print ("Checking gravity on " + objectToChangeGravity.name);
}
//if the player is not driving, stop the gravity power
bool checkResult = (useWithPlayer && objectToChangeGravity.CompareTag (playerTag)) ||
(useWithNPC && objectToChangeGravity.CompareTag (friendTag)) ||
(useWithNPC && objectToChangeGravity.CompareTag (enemyTag));
if (checkResult) {
playerController currentPlayerController = objectToChangeGravity.GetComponent<playerController> ();
if (!currentPlayerController.isPlayerDriving ()) {
gravitySystem currentGravitySystem = objectToChangeGravity.GetComponent<gravitySystem> ();
if (currentGravitySystem != null) {
if (!storeSetGravityManager || currentGravitySystem.getCurrentSetGravityManager () != this) {
if (storeSetGravityManager) {
if (isEnter) {
currentGravitySystem.setCurrentSetGravityManager (this);
} else {
currentGravitySystem.setCurrentSetGravityManager (null);
}
}
if (setCheckSurfaceInFrontState) {
currentGravitySystem.setCheckSurfaceInFrontState (checkSurfaceInFrontState);
}
if (setCheckSurfaceBelowLedgeState) {
currentGravitySystem.setCheckSurfaceBelowLedgeState (checkSurfaceBelowLedgeState);
}
if (setCircumnavigateSurfaceState) {
currentGravitySystem.setCircumnavigateSurfaceState (circumnavigateSurfaceState);
}
if (setGravityMode) {
if (setRegularGravity) {
if (currentGravitySystem.isZeroGravityModeOn ()) {
currentGravitySystem.setZeroGravityModeOnState (false);
} else {
currentGravitySystem.deactivateGravityPower ();
}
} else if (setZeroGravity) {
currentGravitySystem.setZeroGravityModeOnState (true);
} else if (movePlayerToGravityPosition) {
Vector3 rayPosition = raycastPositionToGetGravityPosition.position;
Vector3 rayDirection = raycastPositionToGetGravityPosition.forward;
RaycastHit hit = new RaycastHit ();
if (Physics.Raycast (rayPosition, rayDirection, out hit, Mathf.Infinity, layermaskToGetGravityPosition)) {
currentGravitySystem.teleportPlayer (hit.point, teleportSpeed, hit.normal, rotationSpeed);
}
} else {
if (disableZeroGravity) {
currentGravitySystem.setZeroGravityModeOnStateWithOutRotation (false);
}
if (changeGravityDirectionActive) {
Vector3 newGravityDirection = -getGravityDirection (objectToChangeGravity.transform.position);
if (currentGravitySystem.getCurrentNormal () != newGravityDirection) {
currentGravitySystem.changeGravityDirectionDirectly (newGravityDirection, preservePlayerVelocity);
}
if (setTargetParent) {
currentGravitySystem.addParent (targetParent);
}
} else {
objectToChangeGravity.GetComponent<playerStatesManager> ().checkPlayerStates (true, true, true, true, true, false, true, true);
if (rotateToSurfaceSmoothly) {
currentGravitySystem.changeOnTrigger (getGravityDirection (objectToChangeGravity.transform.position), transform.right);
} else {
currentGravitySystem.setNormal (getGravityDirection (objectToChangeGravity.transform.position));
}
}
}
}
if (setCustomGravityForceOnCharactersEnabled) {
if (setCustomGravityForce) {
if (isEnter) {
currentPlayerController.setGravityForceValue (false, customGravityForce);
} else {
currentPlayerController.setOriginalGravityForceValue ();
}
}
}
if (useCenterPointOnCharacters) {
if (useCenterPoint) {
if (centerPoint != null) {
currentGravitySystem.setCurrentGravityCenterPoint (centerPoint);
}
}
} else {
currentGravitySystem.setCurrentGravityCenterPoint (null);
}
}
}
}
} else {
bool checkObjectResult = false;
Rigidbody objectToChangeGravityRigidbody = objectToChangeGravity.GetComponent<Rigidbody> ();
if (objectToChangeGravityRigidbody != null) {
checkObjectResult = true;
}
if (useWithVehicles) {
//if the player is driving, disable the gravity control in the vehicle
currentVehicleGravityControl = objectToChangeGravity.GetComponent<vehicleGravityControl> ();
if (currentVehicleGravityControl == null) {
GameObject currentVehicle = applyDamage.getVehicle (objectToChangeGravity);
if (currentVehicle != null) {
if (showDebugPrint) {
print ("Checking if object has vehicle gravity control " + currentVehicle.name);
}
currentVehicleGravityControl = currentVehicle.GetComponent<vehicleGravityControl> ();
}
}
if (currentVehicleGravityControl != null) {
checkObjectResult = true;
if (showDebugPrint) {
print ("Vehicle located " + currentVehicleGravityControl.name);
}
if (isEnter) {
if (vehicleGameObjectList.Contains (currentVehicleGravityControl.gameObject)) {
checkObjectResult = false;
}
}
}
}
if (showDebugPrint) {
print (checkObjectResult);
}
if (checkObjectResult) {
//if the object is being carried by the player, make him drop it
currentGrabbedObject = objectToChangeGravity.GetComponent<grabbedObjectState> ();
if (currentGrabbedObject != null) {
if (dropObjectIfGabbed) {
if (!dropObjectOnlyIfNotGrabbedPhysically || !currentGrabbedObject.isCarryingObjectPhysically ()) {
GKC_Utils.dropObject (currentGrabbedObject.getCurrentHolder (), objectToChangeGravity);
}
}
}
if (showDebugPrint) {
print (useWithVehicles + " " + (currentVehicleGravityControl != null));
}
if (useWithVehicles && currentVehicleGravityControl != null) {
if (showDebugPrint) {
print ("VEHICLE LOCATED, SETTING NEW GRAVITY " + currentVehicleGravityControl.name);
}
if (currentVehicleGravityControl.isGravityControlEnabled ()) {
if (isEnter) {
if (!vehicleGameObjectList.Contains (currentVehicleGravityControl.gameObject)) {
vehicleGameObjectList.Add (currentVehicleGravityControl.gameObject);
}
} else {
if (vehicleGameObjectList.Contains (currentVehicleGravityControl.gameObject)) {
vehicleGameObjectList.Remove (currentVehicleGravityControl.gameObject);
}
}
if (setRegularGravity) {
currentVehicleGravityControl.deactivateGravityPower ();
} else {
if (useCenterPoint) {
if (useCenterPointOnVehicle) {
currentVehicleGravityControl.setUseCenterPointActiveState (isEnter, centerPoint);
}
}
if (rotateVehicleToGravityDirection) {
if (useCenterPoint) {
currentVehicleGravityControl.rotateVehicleToRaycastDirection (getGravityDirection (currentVehicleGravityControl.transform.position));
} else {
currentVehicleGravityControl.rotateVehicleToLandSurface (-getGravityDirection (currentVehicleGravityControl.transform.position));
}
} else {
currentVehicleGravityControl.activateGravityPower (getGravityDirection (currentVehicleGravityControl.transform.position), transform.right);
}
}
}
} else {
if (objectToChangeGravityRigidbody != null) {
if (useWithAnyRigidbody || checkOnlyForArtificialGravitySystem) {
artificialObjectGravity currentArtificialObjectGravity = objectToChangeGravity.GetComponent<artificialObjectGravity> ();
if (checkOnlyForArtificialGravitySystem) {
objectToUseArtificialGravitySystem currentObjectToUseArtificialGravitySystem = objectToChangeGravity.GetComponent<objectToUseArtificialGravitySystem> ();
if (currentObjectToUseArtificialGravitySystem == null && !currentArtificialObjectGravity) {
return;
}
}
if (currentArtificialObjectGravity == null) {
currentArtificialObjectGravity = objectToChangeGravity.AddComponent<artificialObjectGravity> ();
}
if (setRegularGravity) {
if (artificialObjectGravityList.Contains (currentArtificialObjectGravity)) {
artificialObjectGravityList.Remove (currentArtificialObjectGravity);
}
currentArtificialObjectGravity.removeGravity ();
if (setRigidbodiesParent) {
objectToChangeGravity.transform.SetParent (null);
}
} else {
if (!artificialObjectGravityList.Contains (currentArtificialObjectGravity)) {
artificialObjectGravityList.Add (currentArtificialObjectGravity);
}
if (useCenterPointForRigidbodies && centerPoint != null) {
currentArtificialObjectGravity.setUseCenterPointActiveState (useCenterPointForRigidbodies, centerPoint);
}
if (useCenterPointListForRigidbodies) {
currentArtificialObjectGravity.setUseCenterPointListForRigidbodiesState (useCenterPointListForRigidbodies, centerPointList);
}
currentArtificialObjectGravity.setUseInverseDirectionToCenterPointState (useInverseDirectionToCenterPoint);
currentArtificialObjectGravity.setCurrentGravity (getGravityDirection (objectToChangeGravity.transform.position));
if (setCustomGravityForce) {
currentArtificialObjectGravity.setGravityForceValue (false, customGravityForce);
}
if (setRigidbodiesParent) {
objectToChangeGravity.transform.SetParent (targetParent.transform);
} else {
objectToChangeGravity.transform.SetParent (null);
}
}
}
}
}
}
}
}
public Vector3 getGravityDirection (Vector3 objectPosition)
{
if (useCustomGravityDirection) {
return customGravityDirection;
} else {
if (useCenterPoint) {
Transform centerPointToUse = transform;
if (useCenterPointList) {
float minDistance = Mathf.Infinity;
for (int i = 0; i < centerPointList.Count; i++) {
float currentDistance = GKC_Utils.distance (objectPosition, centerPointList [i].position);
if (currentDistance < minDistance) {
minDistance = currentDistance;
centerPointToUse = centerPointList [i];
}
}
if (useCenterIfPointListTooClose) {
float distanceToCenter = GKC_Utils.distance (objectPosition, centerPoint.position);
if (minDistance < distanceToCenter) {
centerPointToUse = centerPoint;
}
}
} else {
centerPointToUse = centerPoint;
}
Vector3 heading = centerPointToUse.position - objectToChangeGravity.transform.position;
float distance = heading.magnitude;
Vector3 direction = heading / distance;
return direction;
} else {
return transform.up;
}
}
}
public void reverseGravityDirection ()
{
useInverseDirectionToCenterPoint = !useInverseDirectionToCenterPoint;
for (int i = 0; i < artificialObjectGravityList.Count; i++) {
artificialObjectGravityList [i].setUseInverseDirectionToCenterPointState (useInverseDirectionToCenterPoint);
}
}
}

View File

@@ -0,0 +1,17 @@
fileFormatVersion: 2
guid: f71362bbf87b5594ba07be53350c6bce
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/Gravity/setGravity.cs
uploadId: 814740

View File

@@ -0,0 +1,91 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class updateCharacterGravityTriggerSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool updateGravityEnabled = true;
public string playerTag = "Player";
public bool ignoreUpdateGravityIfCharacterHasDifferentDirection;
public float maxGravityAngleDifference;
public bool ignoreRecalculateSurface;
[Space]
[Header ("Components")]
[Space]
public Transform gravityDirectionTransform;
void OnTriggerEnter (Collider col)
{
if (!updateGravityEnabled) {
return;
}
checkTriggerType (col, true);
}
void OnTriggerExit (Collider col)
{
if (!updateGravityEnabled) {
return;
}
checkTriggerType (col, false);
}
public void checkTriggerType (Collider col, bool isEnter)
{
if (col == null) {
return;
}
if (col.isTrigger) {
return;
}
checkObjectOnGravitySystem (col.gameObject, isEnter);
}
public void checkObjectOnGravitySystem (GameObject objectToCheck, bool isEnter)
{
//if the player is not driving, stop the gravity power
bool checkResult = objectToCheck.CompareTag (playerTag);
if (checkResult) {
gravitySystem currentGravitySystem = objectToCheck.GetComponent<gravitySystem> ();
if (currentGravitySystem != null) {
if (gravityDirectionTransform == null) {
gravityDirectionTransform = transform;
}
bool updateGravityResult = true;
if (ignoreUpdateGravityIfCharacterHasDifferentDirection) {
if (currentGravitySystem.getCurrentNormal () != gravityDirectionTransform.up) {
float currentAngleDifference = Vector3.Angle (currentGravitySystem.getCurrentNormal (), gravityDirectionTransform.up);
if (Mathf.Abs (currentAngleDifference) > maxGravityAngleDifference) {
updateGravityResult = false;
}
}
}
if (updateGravityResult) {
currentGravitySystem.setUpdateCurrentNormalByExternalTransformState (isEnter, gravityDirectionTransform, ignoreRecalculateSurface);
}
}
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: c52d3018b16b0394ba6c9bb849e852e5
timeCreated: 1671764159
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/Gravity/updateCharacterGravityTriggerSystem.cs
uploadId: 814740

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 641b7a2593f6e1e4fb8f3acf98d0c96e
timeCreated: 1458418806
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/Gravity/vehicleGravityControl.cs
uploadId: 814740

View File

@@ -0,0 +1,869 @@
using System.Collections;
using System.Collections.Generic;
using GameKitController.Audio;
using UnityEngine;
public class zeroGravityRoomSystem : MonoBehaviour
{
public bool roomHasRegularGravity;
public bool roomHasZeroGravity;
public Transform gravityDirectionTransform;
[TextArea (2, 5)] public string explanation = "The Gravity Direction will use the Up direction of the above Gravity Direction Transform object.";
public bool useNewGravityOutside;
public bool outsideHasZeroGravity;
public Transform outsideGravityDirectionTransform;
public bool objectsAffectedByGravity = true;
public bool charactersAffectedByGravity = true;
public bool changeGravityForceForObjects;
public float newGravityForceForObjects;
public bool changeGravityForceForCharacters;
public float newGravityForceForCharacters;
public bool addForceToObjectsOnZeroGravityState;
public float forceAmountToObjectOnZeroGravity;
public Transform forceDirectionToObjectsOnZeroGravity;
public ForceMode forceModeToObjectsOnZeroGravity;
public bool addInitialForceToObjectsOnZeroGravityState;
public float initialForceToObjectsOnZeroGravity;
public float initialForceRadiusToObjectsOnZeroGravity;
public Transform initialForcePositionToObjectsOnZeroGravity;
public List<string> nonAffectedObjectsTagList = new List<string> ();
public List<string> charactersTagList = new List<string> ();
public string playerTag;
public List<Transform> roomPointsList = new List<Transform> ();
public List<Vector2> roomPoints2DList = new List<Vector2> ();
public List<GameObject> objectsInsideList = new List<GameObject> ();
public List<GameObject> charactersInsideList = new List<GameObject> ();
public List<GameObject> charactersInsideListAtStart = new List<GameObject> ();
public bool addObjectsInsideParent;
public Transform objectsInsideParent;
public Transform highestPointPoisition;
public Transform lowestPointPosition;
public List<objectInfo> objectInfoList = new List<objectInfo> ();
public bool debugModeActive;
public bool debugModeListActive;
public bool showDebugPrint;
public bool useSounds;
public AudioSource mainAudioSource;
public AudioClip regularGravitySound;
public AudioElement regularGravityAudioElement;
public AudioClip zeroGravitySound;
public AudioElement zeroGravityAudioElement;
public AudioClip customGravitySound;
public AudioElement customGravityAudioElement;
public bool useSoundsOnCharacters;
public AudioClip soundOnEntering;
public AudioElement onEnteringAudioElement;
public AudioClip soundOnExiting;
public AudioElement onExitingAudioElement;
public bool showGizmo = true;
public Vector3 centerGizmoScale = Vector3.one;
public Color roomCenterColor = Color.gray;
public Color gizmoLabelColor = Color.white;
public Color linesColor = Color.yellow;
public bool useHandleForWaypoints;
public float offsetOnNewRoomPoint = 2;
public Vector3 roomCenter;
public Transform roomPointsParent;
Vector3 currentGravityDirection;
bool charactersInsideAtStartAdded;
private void InitializeAudioElements ()
{
if (mainAudioSource != null) {
regularGravityAudioElement.audioSource = mainAudioSource;
zeroGravityAudioElement.audioSource = mainAudioSource;
customGravityAudioElement.audioSource = mainAudioSource;
onEnteringAudioElement.audioSource = mainAudioSource;
onExitingAudioElement.audioSource = mainAudioSource;
}
if (regularGravitySound != null) {
regularGravityAudioElement.clip = regularGravitySound;
}
if (zeroGravitySound != null) {
zeroGravityAudioElement.clip = zeroGravitySound;
}
if (customGravitySound != null) {
customGravityAudioElement.clip = customGravitySound;
}
if (soundOnEntering != null) {
onEnteringAudioElement.clip = soundOnEntering;
}
if (soundOnExiting != null) {
onExitingAudioElement.clip = soundOnExiting;
}
}
void Start ()
{
InitializeAudioElements ();
for (int i = 0; i < roomPointsList.Count; i++) {
roomPoints2DList.Add (new Vector2 (roomPointsList [i].position.x, roomPointsList [i].position.z));
}
currentGravityDirection = gravityDirectionTransform.up;
if (addObjectsInsideParent) {
addChildsFromParent (objectsInsideParent);
}
for (int i = 0; i < objectsInsideList.Count; i++) {
if (objectsInsideList [i] != null) {
setObjectInsideState (objectsInsideList [i]);
} else {
print ("WARNING: some object in the object inside list has been removed or doesn't exists," +
" make sure there are no empty elements in the Gravity Room " + gameObject.name);
}
}
if (addInitialForceToObjectsOnZeroGravityState && roomHasZeroGravity) {
addExplosionForceToObjectsOnZeroGravity ();
}
}
void Update ()
{
if (debugModeActive) {
int objectInfoListCount = objectInfoList.Count;
for (int k = 0; k < objectInfoListCount; k++) {
Vector2 currentPosition = new Vector2 (objectInfoList [k].objectTransform.position.x, objectInfoList [k].objectTransform.position.z);
int j = roomPoints2DList.Count - 1;
bool inside = false;
int roomPoints2DListCount = roomPoints2DList.Count;
for (int i = 0; i < roomPoints2DListCount; j = i++) {
if (((roomPoints2DList [i].y <= currentPosition.y && currentPosition.y < roomPoints2DList [j].y) ||
(roomPoints2DList [j].y <= currentPosition.y && currentPosition.y < roomPoints2DList [i].y)) &&
(currentPosition.x < (roomPoints2DList [j].x - roomPoints2DList [i].x) * (currentPosition.y - roomPoints2DList [i].y) /
(roomPoints2DList [j].y - roomPoints2DList [i].y) + roomPoints2DList [i].x)) {
inside = !inside;
}
}
objectInfoList [k].isInside = inside;
}
}
if (!charactersInsideAtStartAdded) {
if (Time.time > 0.05f) {
for (int i = 0; i < charactersInsideListAtStart.Count; i++) {
if (charactersInsideListAtStart [i] != null) {
checkObjectToAdd (charactersInsideListAtStart [i]);
}
}
charactersInsideAtStartAdded = true;
}
}
}
public void checkObjectToAdd (GameObject newObject)
{
if (charactersTagList.Contains (newObject.tag)) {
if (!charactersInsideList.Contains (newObject)) {
charactersInsideList.Add (newObject);
playerComponentsManager mainPlayerComponentsManager = newObject.GetComponent<playerComponentsManager> ();
playerController currentPlayerController = mainPlayerComponentsManager.getPlayerController ();
gravitySystem currentGravitySystem = mainPlayerComponentsManager.getGravitySystem ();
if (!currentGravitySystem.isCharacterRotatingToSurface () && currentGravitySystem.getCurrentZeroGravityRoom () != this) {
if (useSoundsOnCharacters) {
playSound (onEnteringAudioElement);
}
// print ("inside " + gameObject.name);
//the character is inside the room
if (newObject.CompareTag (playerTag)) {
if (currentGravitySystem != null) {
currentGravitySystem.setCurrentZeroGravityRoom (this);
}
}
if (charactersAffectedByGravity) {
if (roomHasRegularGravity) {
currentGravitySystem.setZeroGravityModeOnState (false);
} else if (roomHasZeroGravity) {
currentGravitySystem.setZeroGravityModeOnState (true);
} else {
currentGravitySystem.setZeroGravityModeOnStateWithOutRotation (false);
currentGravitySystem.changeGravityDirectionDirectlyInvertedValue (currentGravityDirection, true);
}
if (changeGravityForceForCharacters) {
if (currentPlayerController != null) {
currentPlayerController.setGravityForceValue (false, newGravityForceForCharacters);
}
}
}
}
}
}
if (nonAffectedObjectsTagList.Contains (newObject.tag) || FindParentWithTag (newObject, nonAffectedObjectsTagList)) {
return;
}
if (!objectsInsideList.Contains (newObject)) {
objectsInsideList.Add (newObject);
setObjectInsideState (newObject);
}
}
public void checkObjectToRemove (GameObject newObject)
{
//check characters state
if (charactersTagList.Contains (newObject.tag)) {
if (charactersInsideList.Contains (newObject)) {
playerComponentsManager mainPlayerComponentsManager = newObject.GetComponent<playerComponentsManager> ();
playerController currentPlayerController = mainPlayerComponentsManager.getPlayerController ();
gravitySystem currentGravitySystem = mainPlayerComponentsManager.getGravitySystem ();
Vector3 characterPosition = currentGravitySystem.getGravityCenter ().position;
Vector2 objectPosition = new Vector2 (characterPosition.x, characterPosition.z);
//the character is inside the room
if (!ContainsPoint (objectPosition) || !checkInsideFarthestPosition (newObject.transform.position)) {
//the character is outside the room
if (currentGravitySystem != null && currentGravitySystem.getCurrentZeroGravityRoom () == this && !currentGravitySystem.isCharacterRotatingToSurface ()) {
// print ("outisde " + gameObject.name);
if (useSoundsOnCharacters) {
playSound (onExitingAudioElement);
}
if (charactersAffectedByGravity) {
if (useNewGravityOutside) {
if (outsideHasZeroGravity) {
currentGravitySystem.setZeroGravityModeOnState (true);
} else {
currentGravitySystem.setZeroGravityModeOnStateWithOutRotation (false);
currentGravitySystem.changeGravityDirectionDirectlyInvertedValue (outsideGravityDirectionTransform.up, true);
}
} else {
currentGravitySystem.setZeroGravityModeOnState (false);
}
if (changeGravityForceForCharacters) {
if (currentPlayerController != null) {
currentPlayerController.setGravityForceValue (true, 0);
//print ("original");
}
}
}
if (newObject.CompareTag (playerTag)) {
currentGravitySystem.setCurrentZeroGravityRoom (null);
}
}
charactersInsideList.Remove (newObject);
}
}
return;
}
//check objects state
if (objectsInsideList.Contains (newObject)) {
Vector2 objectPosition = new Vector2 (newObject.transform.position.x, newObject.transform.position.z);
if (!ContainsPoint (objectPosition) || !checkInsideFarthestPosition (newObject.transform.position)) {
removeObjectFromRoom (newObject);
}
}
}
public void removeObjectFromRoom (GameObject newObject)
{
objectsInsideList.Remove (newObject);
if (debugModeListActive) {
for (int i = 0; i < objectInfoList.Count; i++) {
if (objectInfoList [i].objectTransform == newObject.transform) {
objectInfoList.RemoveAt (i);
}
}
}
artificialObjectGravity currentArtificialObjectGravity = newObject.GetComponent<artificialObjectGravity> ();
Rigidbody currentRigidbody = newObject.GetComponent<Rigidbody> ();
grabbedObjectState currentGrabbedObjectState = newObject.GetComponent<grabbedObjectState> ();
if (currentGrabbedObjectState != null) {
if (currentGrabbedObjectState.getCurrentZeroGravityRoom () == this) {
currentGrabbedObjectState.setInsideZeroGravityRoomState (false);
currentGrabbedObjectState.setCurrentZeroGravityRoom (null);
if (currentArtificialObjectGravity != null) {
if (currentGrabbedObjectState.isGrabbed ()) {
currentArtificialObjectGravity.removeJustGravityComponent ();
} else {
currentArtificialObjectGravity.removeGravityComponent ();
}
}
if (!currentGrabbedObjectState.isGrabbed ()) {
currentRigidbody.useGravity = true;
}
if (useNewGravityOutside) {
if (outsideHasZeroGravity) {
if (currentArtificialObjectGravity != null) {
currentArtificialObjectGravity.removeGravity ();
}
currentRigidbody.useGravity = false;
} else {
if (currentArtificialObjectGravity == null) {
currentArtificialObjectGravity = newObject.AddComponent<artificialObjectGravity> ();
}
currentArtificialObjectGravity.setCurrentGravity (outsideGravityDirectionTransform.up);
}
}
}
}
}
public void setObjectInsideState (GameObject newObject)
{
if (newObject == null) {
return;
}
Rigidbody currentRigidbody = newObject.GetComponent<Rigidbody> ();
if (currentRigidbody != null) {
if (showDebugPrint) {
print (currentRigidbody.name);
}
grabbedObjectState currentGrabbedObjectState = newObject.GetComponent<grabbedObjectState> ();
if (currentGrabbedObjectState == null) {
currentGrabbedObjectState = newObject.AddComponent<grabbedObjectState> ();
}
if (currentGrabbedObjectState != null) {
currentGrabbedObjectState.setInsideZeroGravityRoomState (true);
currentGrabbedObjectState.setCurrentZeroGravityRoom (this);
}
artificialObjectGravity currentArtificialObjectGravity = newObject.GetComponent<artificialObjectGravity> ();
if (roomHasRegularGravity || !objectsAffectedByGravity) {
if (currentArtificialObjectGravity != null) {
currentArtificialObjectGravity.removeGravity ();
} else {
currentRigidbody.useGravity = true;
}
if (showDebugPrint) {
print ("regular gravity");
}
} else if (roomHasZeroGravity) {
if (currentArtificialObjectGravity != null) {
currentArtificialObjectGravity.removeGravity ();
}
currentRigidbody.useGravity = false;
if (showDebugPrint) {
print ("zero gravity");
}
} else {
if (currentArtificialObjectGravity == null) {
currentArtificialObjectGravity = newObject.AddComponent<artificialObjectGravity> ();
}
currentArtificialObjectGravity.setCurrentGravity (currentGravityDirection);
if (showDebugPrint) {
print ("custom gravity");
}
}
if (debugModeListActive) {
objectInfo newObjectInfo = new objectInfo ();
newObjectInfo.objectTransform = newObject.transform;
objectInfoList.Add (newObjectInfo);
}
if (changeGravityForceForObjects && currentArtificialObjectGravity != null) {
currentArtificialObjectGravity.setGravityForceValue (false, -newGravityForceForObjects);
}
}
}
public bool ContainsPoint (Vector2 currentPosition)
{
int j = roomPoints2DList.Count - 1;
bool inside = false;
Vector2 currentPointsI = Vector2.zero;
Vector2 currentPointsJ = Vector2.zero;
int roomPoints2DListCount = roomPoints2DList.Count;
for (int i = 0; i < roomPoints2DListCount; j = i++) {
currentPointsI = roomPoints2DList [i];
currentPointsJ = roomPoints2DList [j];
if (((currentPointsI.y <= currentPosition.y && currentPosition.y < currentPointsJ.y) ||
(currentPointsJ.y <= currentPosition.y && currentPosition.y < currentPointsI.y)) &&
(currentPosition.x < (currentPointsJ.x - currentPointsI.x) * (currentPosition.y - currentPointsI.y) /
(currentPointsJ.y - currentPointsI.y) + currentPointsI.x)) {
inside = !inside;
}
}
return inside;
}
public bool checkInsideFarthestPosition (Vector3 currentPosition)
{
bool inside = false;
if (currentPosition.y < highestPointPoisition.position.y && currentPosition.y > lowestPointPosition.position.y) {
inside = true;
}
return inside;
}
public bool objectInsideRoom (GameObject objectToCheck)
{
if (objectsInsideList.Contains (objectToCheck)) {
return true;
}
return false;
}
public bool FindParentWithTag (GameObject childObject, List<string> tagList)
{
Transform t = childObject.transform;
while (t.parent != null) {
if (tagList.Contains (t.parent.tag)) {
return true;
}
t = t.parent;
}
return false;
}
public void setNewGravityForceValueForObjectsInsideRoom (float newGravityForceValue)
{
setGravityForceValueForObjectsInsideRoom (false, newGravityForceValue);
}
public void setOriginalGravityForceValueForObjectsInsideRoom ()
{
setGravityForceValueForObjectsInsideRoom (true, 0);
}
public void setGravityForceValueForObjectsInsideRoom (bool setOriginal, float newValue)
{
for (int i = 0; i < objectsInsideList.Count; i++) {
if (changeGravityForceForObjects) {
if (objectsInsideList [i] != null) {
artificialObjectGravity currentArtificialObjectGravity = objectsInsideList [i].GetComponent<artificialObjectGravity> ();
if (currentArtificialObjectGravity != null) {
currentArtificialObjectGravity.setGravityForceValue (setOriginal, newValue);
}
}
}
}
for (int i = 0; i < charactersInsideList.Count; i++) {
if (changeGravityForceForCharacters) {
playerController currentPlayerController = charactersInsideList [i].GetComponent<playerController> ();
if (currentPlayerController != null) {
currentPlayerController.setGravityForceValue (setOriginal, newValue);
}
}
}
}
public void setZeroGravityStateOnRoom ()
{
if (roomHasZeroGravity) {
return;
}
playSound (zeroGravityAudioElement);
roomHasRegularGravity = false;
roomHasZeroGravity = true;
updateObjectsAndCharactersGravityInsideRoom ();
addForceToObjectsOnZeroGravity ();
}
public void setRegularGravityStateOnRoom ()
{
if (roomHasRegularGravity) {
return;
}
playSound (regularGravityAudioElement);
roomHasRegularGravity = true;
roomHasZeroGravity = false;
updateObjectsAndCharactersGravityInsideRoom ();
}
public void setCustomGravityStateOnRoom ()
{
playSound (customGravityAudioElement);
roomHasRegularGravity = false;
roomHasZeroGravity = false;
updateObjectsAndCharactersGravityInsideRoom ();
}
public void setCustomGravityStateOnRoom (Transform newGravityDirectionTransform)
{
currentGravityDirection = newGravityDirectionTransform.up;
roomHasRegularGravity = false;
roomHasZeroGravity = false;
updateObjectsAndCharactersGravityInsideRoom ();
}
public void setOriginalGravityDirectionStateOnRoom ()
{
currentGravityDirection = gravityDirectionTransform.up;
roomHasRegularGravity = false;
roomHasZeroGravity = false;
updateObjectsAndCharactersGravityInsideRoom ();
}
public void updateObjectsAndCharactersGravityInsideRoom ()
{
for (int i = 0; i < objectsInsideList.Count; i++) {
if (objectsInsideList [i] != null) {
setObjectInsideState (objectsInsideList [i]);
}
}
setCharactersGravityStateOnRoom (roomHasRegularGravity, roomHasZeroGravity);
}
public void setCharactersGravityStateOnRoom (bool hasRegularGravity, bool hasZeroGravity)
{
if (charactersAffectedByGravity) {
for (int i = 0; i < charactersInsideList.Count; i++) {
playerComponentsManager mainPlayerComponentsManager = charactersInsideList [i].GetComponent<playerComponentsManager> ();
playerController currentPlayerController = mainPlayerComponentsManager.getPlayerController ();
gravitySystem currentGravitySystem = mainPlayerComponentsManager.getGravitySystem ();
if (hasRegularGravity) {
currentGravitySystem.setZeroGravityModeOnState (false);
} else if (hasZeroGravity) {
currentGravitySystem.setZeroGravityModeOnState (true);
} else {
currentGravitySystem.setZeroGravityModeOnStateWithOutRotation (false);
currentGravitySystem.changeGravityDirectionDirectlyInvertedValue (currentGravityDirection, true);
}
if (changeGravityForceForCharacters) {
if (currentPlayerController != null) {
currentPlayerController.setGravityForceValue (false, newGravityForceForCharacters);
}
}
}
}
}
public void addForceToObjectsOnZeroGravity ()
{
if (addForceToObjectsOnZeroGravityState) {
for (int i = 0; i < objectsInsideList.Count; i++) {
if (objectsInsideList [i] != null) {
Rigidbody currentRigidbody = objectsInsideList [i].GetComponent<Rigidbody> ();
if (currentRigidbody != null) {
currentRigidbody.AddForce (forceDirectionToObjectsOnZeroGravity.up * forceAmountToObjectOnZeroGravity, forceModeToObjectsOnZeroGravity);
}
} else {
print ("WARNING: some object in the object inside list has been removed or doesn't exists," +
" make sure there are no empty elements in the Gravity Room " + gameObject.name);
}
}
}
}
public void addExplosionForceToObjectsOnZeroGravity ()
{
for (int i = 0; i < objectsInsideList.Count; i++) {
if (objectsInsideList [i] != null) {
Rigidbody currentRigidbody = objectsInsideList [i].GetComponent<Rigidbody> ();
if (currentRigidbody != null) {
currentRigidbody.AddExplosionForce (initialForceToObjectsOnZeroGravity, initialForcePositionToObjectsOnZeroGravity.position,
initialForceRadiusToObjectsOnZeroGravity);
}
} else {
print ("WARNING: some object in the object inside list has been removed or doesn't exists," +
" make sure there are no empty elements in the Gravity Room " + gameObject.name);
}
}
}
public void playSound (AudioElement sound)
{
if (useSounds) {
if (sound != null) {
AudioPlayer.PlayOneShot (sound, gameObject);
}
}
}
public void addObjectToRoom (GameObject objectToAdd)
{
checkObjectToAdd (objectToAdd);
}
public void addObjectsToRoom (Transform parentToCheck)
{
Component[] childrens = parentToCheck.GetComponentsInChildren (typeof(Rigidbody));
foreach (Rigidbody child in childrens) {
if (!child.isKinematic && child.GetComponent<Collider> ()) {
checkObjectToAdd (child.gameObject);
}
}
}
public void addChildsFromParent (Transform parentToCheck)
{
Component[] childrens = parentToCheck.GetComponentsInChildren (typeof(Rigidbody));
foreach (Rigidbody child in childrens) {
if (!child.isKinematic && child.GetComponent<Collider> ()) {
objectsInsideList.Add (child.gameObject);
}
}
}
//EDITOR FUNCTIONS
public void renameRoomPoints ()
{
for (int i = 0; i < roomPointsList.Count; i++) {
roomPointsList [i].name = (i + 1).ToString ();
}
updateComponent ();
}
public void addRoomPoint ()
{
GameObject newRoomPoint = new GameObject ();
if (roomPointsParent == null) {
roomPointsParent = transform;
}
newRoomPoint.transform.SetParent (roomPointsParent);
newRoomPoint.name = (roomPointsList.Count + 1).ToString ();
Vector3 newPosition = Vector3.zero;
if (roomPointsList.Count > 0) {
newPosition = roomPointsList [roomPointsList.Count - 1].transform.localPosition + Vector3.right * offsetOnNewRoomPoint + Vector3.forward * offsetOnNewRoomPoint;
}
newRoomPoint.transform.localPosition = newPosition;
roomPointsList.Add (newRoomPoint.transform);
updateComponent ();
}
public void addRoomPoint (int index)
{
GameObject newRoomPoint = new GameObject ();
if (roomPointsParent == null) {
roomPointsParent = transform;
}
newRoomPoint.transform.SetParent (roomPointsParent);
Vector3 newPosition = roomPointsList [index].transform.localPosition + Vector3.right * offsetOnNewRoomPoint + Vector3.forward * offsetOnNewRoomPoint;
newRoomPoint.transform.localPosition = newPosition;
roomPointsList.Insert (index + 1, newRoomPoint.transform);
renameRoomPoints ();
updateComponent ();
}
public void removeRoomPoint (int index)
{
if (roomPointsList [index] != null) {
DestroyImmediate (roomPointsList [index].gameObject);
}
roomPointsList.RemoveAt (index);
updateComponent ();
}
public void removeAllRoomPoints ()
{
for (int i = 0; i < roomPointsList.Count; i++) {
DestroyImmediate (roomPointsList [i].gameObject);
}
roomPointsList.Clear ();
updateComponent ();
}
void updateComponent ()
{
GKC_Utils.updateComponent (this);
}
//draw every floor position and a line between floors
#if UNITY_EDITOR
void OnDrawGizmos ()
{
if (!showGizmo) {
return;
}
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
DrawGizmos ();
}
}
void OnDrawGizmosSelected ()
{
DrawGizmos ();
}
//draw the pivot and the final positions of every door
void DrawGizmos ()
{
if (showGizmo) {
roomCenter = Vector3.zero;
for (int i = 0; i < roomPointsList.Count; i++) {
if (roomPointsList [i] != null) {
if (i + 1 < roomPointsList.Count) {
if (roomPointsList [i + 1] != null) {
Gizmos.color = linesColor;
Gizmos.DrawLine (roomPointsList [i].position, roomPointsList [i + 1].position);
}
}
if (i == roomPointsList.Count - 1) {
if (roomPointsList [0] != null) {
Gizmos.color = linesColor;
Gizmos.DrawLine (roomPointsList [i].position, roomPointsList [0].position);
}
}
roomCenter += roomPointsList [i].position;
}
}
roomCenter /= roomPointsList.Count;
Gizmos.color = Color.white;
Gizmos.DrawLine (highestPointPoisition.position, roomCenter);
Gizmos.DrawSphere (highestPointPoisition.position, 0.2f);
Gizmos.DrawLine (lowestPointPosition.position, roomCenter);
Gizmos.DrawSphere (lowestPointPosition.position, 0.2f);
Gizmos.color = roomCenterColor;
Gizmos.DrawCube (roomCenter, centerGizmoScale);
}
}
#endif
[System.Serializable]
public class objectInfo
{
public Transform objectTransform;
public bool isInside;
}
[System.Serializable]
public class characterInfo
{
public GameObject characterGameObject;
public gravitySystem currentGravitySystem;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: f6601e05306d0074fbb72d5f168102d0
timeCreated: 1534913179
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/Gravity/zeroGravityRoomSystem.cs
uploadId: 814740