plantilla base para movimiento básico
This commit is contained in:
Robii Aragon
2026-02-05 05:07:55 -08:00
parent ed7b223c04
commit fd87a6ffd5
14441 changed files with 13711084 additions and 20 deletions

View File

@@ -0,0 +1,101 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class checkObjectOnTrigger : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool putObjectSystemEnabled = true;
public bool useCertainObjectToPlace;
public GameObject certainObjectToPlace;
public string objectNameToPlace;
public bool useObjectNameListToPlace;
public List<string> objectNameListToPlace = new List<string> ();
[Space]
[Header ("Debug")]
[Space]
public bool anyObjectPlaced;
public List<GameObject> objectsPlacedList = new List<GameObject> ();
[Space]
[Header ("Events Settings")]
[Space]
public bool useEventOnObjectPlaced;
public UnityEvent objectPlacedEvent;
public bool useEventOnObjectRemoved;
public UnityEvent objectRemovedEvent;
objectToPlaceSystem currentObjectToPlaceSystem;
public void checkObjectOnTriggerEnter (GameObject newObject)
{
if (checkIfObjectCanBePlaced (newObject)) {
if (!objectsPlacedList.Contains (newObject)) {
objectsPlacedList.Add (newObject);
if (useEventOnObjectPlaced) {
objectPlacedEvent.Invoke ();
}
anyObjectPlaced = true;
}
}
}
public void checkObjectOnTriggerExit (GameObject newObject)
{
if (checkIfObjectCanBePlaced (newObject)) {
if (objectsPlacedList.Contains (newObject)) {
objectsPlacedList.Remove (newObject);
if (useEventOnObjectRemoved) {
objectRemovedEvent.Invoke ();
}
if (objectsPlacedList.Count == 0) {
anyObjectPlaced = false;
}
}
}
}
bool checkIfObjectCanBePlaced (GameObject objectToCheck)
{
if (useCertainObjectToPlace) {
if (objectToCheck == certainObjectToPlace || objectToCheck.transform.IsChildOf (certainObjectToPlace.transform)) {
return true;
}
} else {
currentObjectToPlaceSystem = objectToCheck.GetComponent<objectToPlaceSystem> ();
if (currentObjectToPlaceSystem != null) {
if (useObjectNameListToPlace) {
if (objectNameListToPlace.Contains (currentObjectToPlaceSystem.getObjectName ())) {
return true;
}
} else {
if (objectNameToPlace == currentObjectToPlaceSystem.getObjectName ()) {
return true;
}
}
}
}
return false;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 715ab915fd669884e921c091b1cc0469
timeCreated: 1715565742
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/Grab Objects/checkObjectOnTrigger.cs
uploadId: 814740

View File

@@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class grabObjectEventSystem : MonoBehaviour
{
public bool useEventOnGrab = true;
public UnityEvent eventOnGrab;
public bool useEventOnDrop;
public UnityEvent eventOnDrop;
public void callEventOnGrab ()
{
if (useEventOnGrab) {
eventOnGrab.Invoke ();
}
}
public void callEventOnDrop ()
{
if (useEventOnDrop) {
eventOnDrop.Invoke ();
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: e0e57f3acd14e1e4f9598b64b1dfd809
timeCreated: 1538545272
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/Grab Objects/grabObjectEventSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,95 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class grabObjectGenericModeMountPointSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool grabObjectsEnabled = true;
public bool useCustomGrabbedObjectScaleMultiplier;
public float customGrabbedObjectScaleMultiplier;
[Space]
[Header ("Mount Point List Settings")]
[Space]
public List<objectPointInfo> objectPointInfoList = new List<objectPointInfo> ();
public bool isUseCustomGrabbedObjectScaleMultiplierActive ()
{
return useCustomGrabbedObjectScaleMultiplier;
}
public float getCustomGrabbedObjectScaleMultiplier ()
{
return customGrabbedObjectScaleMultiplier;
}
public bool isGrabObjectsEnabled ()
{
return grabObjectsEnabled;
}
public Transform getMountPointByName (string mountPointName)
{
int mountPointIndex = objectPointInfoList.FindIndex (s => s.Name.Equals (mountPointName));
if (mountPointIndex > -1) {
return objectPointInfoList [mountPointIndex].objectTransform;
}
return null;
}
public Transform getDefaultMountPoint ()
{
for (int i = 0; i < objectPointInfoList.Count; i++) {
if (objectPointInfoList [i].usePointAsDefault) {
return objectPointInfoList [i].objectTransform;
}
}
return null;
}
public Transform getReferencePositionByName (string mountPointName, string referencePositionName)
{
int mountPointIndex = objectPointInfoList.FindIndex (s => s.Name.Equals (mountPointName));
if (mountPointIndex > -1) {
int referencePositionIndex =
objectPointInfoList [mountPointIndex].referencePositionInfoList.FindIndex (s => s.Name.Equals (referencePositionName));
if (referencePositionIndex > -1) {
return objectPointInfoList [mountPointIndex].referencePositionInfoList [referencePositionIndex].referencePosition;
}
}
return null;
}
[System.Serializable]
public class objectPointInfo
{
public string Name;
public Transform objectTransform;
public bool usePointAsDefault;
[Space]
public List<referencePositionInfo> referencePositionInfoList = new List<referencePositionInfo> ();
}
[System.Serializable]
public class referencePositionInfo
{
public string Name;
public Transform referencePosition;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: d5cbc9f5fd7fc50438363f1d074fb40e
timeCreated: 1712472553
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/Grab Objects/grabObjectGenericModeMountPointSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,16 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class grabObjectParent : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public GameObject objectToGrab;
public GameObject getObjectToGrab ()
{
return objectToGrab;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 9038c21d02043ce409855595c491711a
timeCreated: 1538553733
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/Grab Objects/grabObjectParent.cs
uploadId: 814740

View File

@@ -0,0 +1,89 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class grabObjectProperties : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool objectUsesWeight = true;
public float objectWeight;
public bool useExtraGrabDistance;
public float extraGrabDistance;
[Space]
[Header ("Mass Settings")]
[Space]
public bool useCustomMassToThrow;
public float customMassToThrow;
public float customObjectMassDividerOnThrow = 1;
[Space]
[Header ("Events Settings")]
[Space]
public bool useEventsOnGrabObject;
public UnityEvent eventOnGrabObject;
public bool useEventsOnDropObject;
public UnityEvent eventOnDropObject;
public bool useEventToSetPlayer;
public eventParameters.eventToCallWithGameObject eventToSetPlayer;
[Space]
[Header ("Components")]
[Space]
public Collider mainTrigger;
public float getObjectWeight ()
{
if (objectUsesWeight) {
return objectWeight;
}
return 0;
}
public float getExtraGrabDistance ()
{
if (useExtraGrabDistance) {
return extraGrabDistance;
}
return 0;
}
public void checkEventsOnGrabObject ()
{
if (useEventsOnGrabObject) {
eventOnGrabObject.Invoke ();
}
}
public void checkEventsOnDropObject ()
{
if (useEventsOnDropObject) {
eventOnDropObject.Invoke ();
}
}
public void checkEventToSetPlayer (GameObject newPlayer)
{
if (useEventToSetPlayer) {
eventToSetPlayer.Invoke (newPlayer);
}
}
public Collider getMainTrigger ()
{
return mainTrigger;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 62709d3623aa140479f7331f492884ea
timeCreated: 1566325342
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/Grab Objects/grabObjectProperties.cs
uploadId: 814740

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,17 @@
fileFormatVersion: 2
guid: f47d648953d25984c9ce75582138d4bf
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/Grab Objects/grabObjects.cs
uploadId: 814740

View File

@@ -0,0 +1,634 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
public class grabObjectsPowerSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool grabObjectsEnabled;
public float grabRadius = 10;
public List<string> ableToGrabTags = new List<string> ();
public LayerMask layerToDamage;
public LayerMask layerToDetectObjects;
public float carryObjectsSpeed = 5;
public float minForceToLaunchObjects = 300;
public float maxForceToLaunchObjects = 3500;
public float addForceToLaunchObjectsSpeed = 1200;
public float waitTimeToDropObjects = 1;
public bool useCarryObjectsPositionOffset;
public Vector3 carryObjectsPositionOffset;
[Space]
[Header ("Grab Single Object Settings")]
[Space]
public bool grabSingleObjectOnCameraView;
[Space]
[Header ("Remote Events Settings")]
[Space]
public bool useRemoteEventOnObjectsFound;
public List<string> remoteEventNameListOnGrabObject = new List<string> ();
public List<string> remoteEventNameListOnDropObject = new List<string> ();
[Space]
[Header ("Other Settings")]
[Space]
public bool setCheckOnTriggerEnterEnabledState;
public bool checkOnTriggerEnterEnabled;
public LayerMask layermaskToCheckOnTriggerEnter;
[Space]
public bool setUseCustomDamageAmountState;
public bool useCustomDamageAmount;
public float customDamageAmount;
[Space]
[Header ("Debug")]
[Space]
public bool showGizmo;
public bool carryingObjects;
public bool firstPersonActive;
public bool firstPersonPreviouslyActive;
public List<grabbedObject> grabbedObjectList = new List<grabbedObject> ();
[Space]
[Header ("Events Settings")]
[Space]
public bool useEventsOnThrowObjects;
public UnityEvent eventOnThrowObjects;
public UnityEvent eventOnDropObjects;
public UnityEvent eventOnGrabObject;
[Space]
[Header ("Components")]
[Space]
public grabObjects grabObjectsManager;
public Transform mainCameraTransform;
public otherPowers mainOtherPowers;
public Transform carryObjectsTransform;
public List<Transform> carryObjectsTransformFirstPersonList = new List<Transform> ();
public List<Transform> carryObjectsTransformThirdPersonList = new List<Transform> ();
public bool useCarryObjectsAnimation = true;
public Animation carryObjectsTransformAnimation;
public string carryObjectsAnimationName = "grabObjects";
public Slider slider;
public Collider mainPlayerCollider;
Transform closestCarryObjecsTransformFirstPerson;
Transform closestCarryObjecsTransformThirdPerson;
float currentForceToLaunchObjects;
bool playerCurrentlyBusy;
RaycastHit hit;
bool canMove;
Vector3 currentObjectPosition;
Vector3 nextObjectPosition;
float currentObjectDistance;
grabbedObject currentGrabbedObject;
float lastTimeObjectsGrabbed;
void FixedUpdate ()
{
playerCurrentlyBusy = mainOtherPowers.playerIsBusy ();
canMove = mainOtherPowers.canMove;
if (carryingObjects) {
if (grabbedObjectList.Count > 0) {
firstPersonActive = mainOtherPowers.isFirstPersonActive ();
if (firstPersonActive != firstPersonPreviouslyActive) {
firstPersonPreviouslyActive = firstPersonActive;
for (int i = 0; i < grabbedObjectList.Count; i++) {
currentGrabbedObject = grabbedObjectList [i];
if (currentGrabbedObject.objectToMove != null) {
if (firstPersonActive) {
currentGrabbedObject.objectToMove.transform.SetParent (currentGrabbedObject.objectToFollowFirstPerson);
} else {
currentGrabbedObject.objectToMove.transform.SetParent (currentGrabbedObject.objectToFollowThirdPerson);
}
}
}
}
//when all the objects are stored, then set their position close to the player
for (int k = 0; k < grabbedObjectList.Count; k++) {
currentGrabbedObject = grabbedObjectList [k];
if (currentGrabbedObject.objectToMove != null) {
currentObjectDistance = GKC_Utils.distance (currentGrabbedObject.objectToMove.transform.localPosition, Vector3.zero);
if (currentObjectDistance > 0.8f) {
if (useCarryObjectsPositionOffset) {
if (firstPersonActive) {
nextObjectPosition = currentGrabbedObject.objectToFollowFirstPerson.position;
nextObjectPosition += currentGrabbedObject.objectToFollowFirstPerson.TransformDirection (carryObjectsPositionOffset);
} else {
nextObjectPosition = currentGrabbedObject.objectToFollowThirdPerson.position;
nextObjectPosition += currentGrabbedObject.objectToFollowThirdPerson.TransformVector (carryObjectsPositionOffset);
}
} else {
nextObjectPosition = currentGrabbedObject.objectToFollowThirdPerson.position;
if (firstPersonActive) {
nextObjectPosition = currentGrabbedObject.objectToFollowFirstPerson.position;
}
}
currentObjectPosition = currentGrabbedObject.objectToMove.transform.position;
currentGrabbedObject.mainRigidbody.linearVelocity = (nextObjectPosition - currentObjectPosition) * carryObjectsSpeed;
} else {
currentGrabbedObject.mainRigidbody.linearVelocity = Vector3.zero;
}
} else {
grabbedObjectList.RemoveAt (k);
}
}
} else {
carryingObjects = false;
}
}
}
public void grabCloseObjects ()
{
//if the player has not grabbedObjects, store them
if (grabbedObjectList.Count == 0) {
int ignoreRaycastLayerIndex = LayerMask.NameToLayer ("Ignore Raycast");
//check in a radius, the close objects which can be grabbed
Collider [] objects = Physics.OverlapSphere (carryObjectsTransform.position + transform.up, grabRadius, layerToDetectObjects);
foreach (Collider currentCollider in objects) {
checkObjectToGrab (currentCollider, ignoreRaycastLayerIndex);
}
//if there are not any object close to the player, cancel
if (grabbedObjectList.Count > 0) {
carryingObjects = true;
lastTimeObjectsGrabbed = Time.time;
eventOnGrabObject.Invoke ();
}
}
}
public void grabSingleObject ()
{
if (grabbedObjectList.Count == 0) {
bool surfaceFound = false;
if (Physics.Raycast (mainCameraTransform.position, mainCameraTransform.forward, out hit, Mathf.Infinity, layerToDamage)) {
if (hit.collider != mainPlayerCollider) {
surfaceFound = true;
} else {
if (Physics.Raycast (hit.point + mainCameraTransform.forward, mainCameraTransform.forward, out hit, Mathf.Infinity, layerToDamage)) {
surfaceFound = true;
}
}
}
if (surfaceFound) {
int ignoreRaycastLayerIndex = LayerMask.NameToLayer ("Ignore Raycast");
checkObjectToGrab (hit.collider, ignoreRaycastLayerIndex);
//if there are not any object close to the player, cancel
if (grabbedObjectList.Count > 0) {
carryingObjects = true;
lastTimeObjectsGrabbed = Time.time;
eventOnGrabObject.Invoke ();
}
}
}
}
void checkObjectToGrab (Collider currentCollider, int ignoreRaycastLayerIndex)
{
Rigidbody currentRigidbody = currentCollider.GetComponent<Rigidbody> ();
if (ableToGrabTags.Contains (currentCollider.tag) && currentRigidbody != null) {
if (currentRigidbody.isKinematic) {
currentRigidbody.isKinematic = false;
}
grabbedObject newGrabbedObject = new grabbedObject ();
//removed tag and layer after store them, so the camera can still use raycast properly
GameObject currentObject = currentCollider.gameObject;
newGrabbedObject.objectToMove = currentObject;
newGrabbedObject.objectTag = currentObject.tag;
newGrabbedObject.objectLayer = currentObject.layer;
newGrabbedObject.mainRigidbody = currentRigidbody;
newGrabbedObject.objectCollider = currentCollider;
if (useRemoteEventOnObjectsFound) {
remoteEventSystem currentRemoteEventSystem = currentObject.GetComponent<remoteEventSystem> ();
if (currentRemoteEventSystem != null) {
for (int i = 0; i < remoteEventNameListOnGrabObject.Count; i++) {
currentRemoteEventSystem.callRemoteEvent (remoteEventNameListOnGrabObject [i]);
}
}
}
currentObject.tag = "Untagged";
currentObject.layer = ignoreRaycastLayerIndex;
currentRigidbody.useGravity = false;
//get the distance from every object to left and right side of the player, to set every side as parent of every object
//disable collisions between the player and the objects, to avoid issues
Physics.IgnoreCollision (currentCollider, mainPlayerCollider, true);
float distance = Mathf.Infinity;
for (int k = 0; k < carryObjectsTransformFirstPersonList.Count; k++) {
float currentDistance = GKC_Utils.distance (currentObject.transform.position, carryObjectsTransformFirstPersonList [k].position);
if (currentDistance < distance) {
distance = currentDistance;
closestCarryObjecsTransformFirstPerson = carryObjectsTransformFirstPersonList [k];
}
}
if (closestCarryObjecsTransformFirstPerson != null) {
currentObject.transform.SetParent (closestCarryObjecsTransformFirstPerson);
newGrabbedObject.objectToFollowFirstPerson = closestCarryObjecsTransformFirstPerson;
closestCarryObjecsTransformFirstPerson = null;
}
distance = Mathf.Infinity;
for (int k = 0; k < carryObjectsTransformThirdPersonList.Count; k++) {
float currentDistance = GKC_Utils.distance (currentObject.transform.position, carryObjectsTransformThirdPersonList [k].position);
if (currentDistance < distance) {
distance = currentDistance;
closestCarryObjecsTransformThirdPerson = carryObjectsTransformThirdPersonList [k];
}
}
if (closestCarryObjecsTransformThirdPerson != null) {
currentObject.transform.SetParent (closestCarryObjecsTransformThirdPerson);
newGrabbedObject.objectToFollowThirdPerson = closestCarryObjecsTransformThirdPerson;
closestCarryObjecsTransformThirdPerson = null;
}
//if any object grabbed has its own gravity, paused the script to move the object properly
artificialObjectGravity currentArtificialObjectGravity = currentObject.GetComponent<artificialObjectGravity> ();
if (currentArtificialObjectGravity != null) {
currentArtificialObjectGravity.setActiveState (false);
}
grabObjectProperties currentGrabObjectProperties = currentObject.GetComponent<grabObjectProperties> ();
if (currentGrabObjectProperties != null) {
currentGrabObjectProperties.checkEventsOnGrabObject ();
}
grabbedObjectState currentGrabbedObjectState = currentObject.GetComponent<grabbedObjectState> ();
if (currentGrabbedObjectState == null) {
currentGrabbedObjectState = currentObject.AddComponent<grabbedObjectState> ();
}
objectToPlaceSystem currentObjectToPlaceSystem = currentObject.GetComponent<objectToPlaceSystem> ();
if (currentObjectToPlaceSystem != null) {
currentObjectToPlaceSystem.setObjectInGrabbedState (true);
}
//if any object is pickable and is inside an opened chest, activate its trigger or if it has been grabbed by the player, remove of the list
pickUpObject currentPickUpObject = currentObject.GetComponent<pickUpObject> ();
if (currentPickUpObject != null) {
currentPickUpObject.activateObjectTrigger ();
}
deviceStringAction currentDeviceStringAction = currentObject.GetComponentInChildren<deviceStringAction> ();
if (currentDeviceStringAction != null) {
currentDeviceStringAction.setIconEnabledState (false);
}
if (currentGrabbedObjectState != null) {
currentGrabbedObjectState.setCurrentHolder (gameObject);
currentGrabbedObjectState.setGrabbedState (true);
}
grabbedObjectList.Add (newGrabbedObject);
}
}
//drop or throw the current grabbed objects
public void dropObjects ()
{
//get the point at which the camera is looking, to throw the objects in that direction
Vector3 hitDirection = Vector3.zero;
bool surfaceFound = false;
if (Physics.Raycast (mainCameraTransform.position, mainCameraTransform.forward, out hit, Mathf.Infinity, layerToDamage)) {
if (hit.collider != mainPlayerCollider) {
surfaceFound = true;
} else {
if (Physics.Raycast (hit.point + mainCameraTransform.forward, mainCameraTransform.forward, out hit, Mathf.Infinity, layerToDamage)) {
surfaceFound = true;
}
}
}
if (surfaceFound) {
hitDirection = hit.point;
}
for (int j = 0; j < grabbedObjectList.Count; j++) {
dropObject (grabbedObjectList [j], hitDirection);
}
carryingObjects = false;
grabbedObjectList.Clear ();
mainOtherPowers.enableOrDisablePowerCursor (false);
if (slider != null) {
if (slider.gameObject.activeSelf) {
slider.gameObject.SetActive (false);
}
slider.value = 0;
}
}
public void addForceToLaunchObjects ()
{
if (Time.time > waitTimeToDropObjects + lastTimeObjectsGrabbed) {
if (currentForceToLaunchObjects < maxForceToLaunchObjects) {
//enable the power slider in the center of the screen
currentForceToLaunchObjects += Time.deltaTime * addForceToLaunchObjectsSpeed;
if (currentForceToLaunchObjects > minForceToLaunchObjects) {
if (slider != null) {
slider.value = currentForceToLaunchObjects;
if (!slider.gameObject.activeSelf) {
slider.gameObject.SetActive (true);
}
}
mainOtherPowers.enableOrDisablePowerCursor (true);
}
}
}
}
public void dropObject (grabbedObject currentGrabbedObject, Vector3 launchDirection)
{
GameObject currentObject = currentGrabbedObject.objectToMove;
Rigidbody currentRigidbody = currentGrabbedObject.mainRigidbody;
if (useRemoteEventOnObjectsFound) {
remoteEventSystem currentRemoteEventSystem = currentObject.GetComponent<remoteEventSystem> ();
if (currentRemoteEventSystem != null) {
for (int i = 0; i < remoteEventNameListOnDropObject.Count; i++) {
currentRemoteEventSystem.callRemoteEvent (remoteEventNameListOnDropObject [i]);
}
}
}
currentObject.transform.SetParent (null);
currentObject.tag = currentGrabbedObject.objectTag;
currentObject.layer = currentGrabbedObject.objectLayer;
//drop the objects, because the grab objects button has been pressed quickly
if (currentForceToLaunchObjects < minForceToLaunchObjects) {
Physics.IgnoreCollision (currentGrabbedObject.objectCollider, mainPlayerCollider, false);
}
//launch the objects according to the amount of time that the player has held the buttton
if (currentForceToLaunchObjects > minForceToLaunchObjects) {
//if the objects are launched, add the script launchedObject, to damage any enemy that the object would touch
launchedObjects currentLaunchedObjects = currentObject.AddComponent<launchedObjects> ();
currentLaunchedObjects.setCurrentPlayerAndCollider (gameObject, mainPlayerCollider);
if (setCheckOnTriggerEnterEnabledState) {
currentLaunchedObjects.setOnTriggerInfoCheckState (checkOnTriggerEnterEnabled, layermaskToCheckOnTriggerEnter);
}
if (setUseCustomDamageAmountState){
currentLaunchedObjects.setUseCustomDamageAmountValues (useCustomDamageAmount, customDamageAmount);
}
//if there are any collider in from of the camera, use the hit point, else, use the camera direciton
if (launchDirection != Vector3.zero) {
Vector3 throwDirection = launchDirection - currentObject.transform.position;
throwDirection = throwDirection / throwDirection.magnitude;
currentRigidbody.AddForce (throwDirection * currentForceToLaunchObjects * currentRigidbody.mass);
if (showGizmo) {
Debug.DrawRay (currentObject.transform.position, throwDirection * 10, Color.red, 4);
}
} else {
currentRigidbody.AddForce (mainCameraTransform.TransformDirection (Vector3.forward) * currentForceToLaunchObjects * currentRigidbody.mass);
if (showGizmo) {
Debug.DrawRay (currentObject.transform.position, mainCameraTransform.TransformDirection (Vector3.forward) * 10, Color.red, 4);
}
}
}
//set again the custom gravity of the object
artificialObjectGravity currentArtificialObjectGravity = currentObject.GetComponent<artificialObjectGravity> ();
if (currentArtificialObjectGravity != null) {
currentArtificialObjectGravity.setActiveState (true);
}
grabObjectProperties currentGrabObjectProperties = currentObject.GetComponent<grabObjectProperties> ();
if (currentGrabObjectProperties != null) {
currentGrabObjectProperties.checkEventsOnDropObject ();
}
deviceStringAction currentDeviceStringAction = currentObject.GetComponentInChildren<deviceStringAction> ();
if (currentDeviceStringAction != null) {
currentDeviceStringAction.setIconEnabledState (true);
}
objectToPlaceSystem currentObjectToPlaceSystem = currentObject.GetComponent<objectToPlaceSystem> ();
if (currentObjectToPlaceSystem != null) {
currentObjectToPlaceSystem.setObjectInGrabbedState (false);
}
grabbedObjectState currentGrabbedObjectState = currentObject.GetComponent<grabbedObjectState> ();
if (currentGrabbedObjectState != null) {
bool currentObjectWasInsideGravityRoom = currentGrabbedObjectState.isInsideZeroGravityRoom ();
currentGrabbedObjectState.checkGravityRoomState ();
currentGrabbedObjectState.setGrabbedState (false);
if (!currentObjectWasInsideGravityRoom) {
currentGrabbedObjectState.removeGrabbedObjectComponent ();
currentRigidbody.useGravity = true;
}
}
if (currentArtificialObjectGravity != null) {
currentRigidbody.useGravity = false;
}
}
public void checkIfDropObject (GameObject objectToCheck)
{
for (int j = 0; j < grabbedObjectList.Count; j++) {
if (grabbedObjectList [j].objectToMove == objectToCheck) {
dropObject (grabbedObjectList [j], Vector3.zero);
grabbedObjectList [j].objectToMove = null;
return;
}
}
}
public void setGrabObjectsEnabledState (bool state)
{
grabObjectsEnabled = state;
}
public void inputGrabObjects ()
{
if (!playerCurrentlyBusy) {
if (!carryingObjects && canMove && grabObjectsEnabled && !grabObjectsManager.isCarryingPhysicalObject ()) {
if (useCarryObjectsAnimation) {
if (carryObjectsTransformAnimation != null) {
carryObjectsTransformAnimation.Play (carryObjectsAnimationName);
}
}
lastTimeObjectsGrabbed = 0;
if (grabSingleObjectOnCameraView) {
grabSingleObject ();
} else {
grabCloseObjects ();
}
currentForceToLaunchObjects = 0;
}
}
}
public void inputHoldToLaunchObjects ()
{
//the objects can be dropped or launched, according to the duration of the key press, in the camera direction
if (!playerCurrentlyBusy && carryingObjects && canMove) {
addForceToLaunchObjects ();
}
}
public void inputReleaseToLaunchObjects ()
{
//drop or thrown the objects
if (!playerCurrentlyBusy && carryingObjects && canMove) {
if (Time.time > waitTimeToDropObjects + lastTimeObjectsGrabbed) {
dropObjects ();
if (useEventsOnThrowObjects) {
if (currentForceToLaunchObjects > minForceToLaunchObjects) {
eventOnThrowObjects.Invoke ();
} else {
eventOnDropObjects.Invoke ();
}
}
}
}
}
[System.Serializable]
public class grabbedObject
{
public GameObject objectToMove;
public Transform objectToFollowFirstPerson;
public Transform objectToFollowThirdPerson;
public string objectTag;
public int objectLayer;
public Rigidbody mainRigidbody;
public Collider objectCollider;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: ab6e5c3e3074aeb468359c52eb655e3d
timeCreated: 1581425172
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/Grab Objects/grabObjectsPowerSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: e4943cb9f5119774f8e8d8d1d7aeb74e
timeCreated: 1703835081
licenseType: Store
DefaultImporter:
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/Grab Objects/grabPhysicalObjectMeleeAttackSystem.cs.bak
uploadId: 814740

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: d0b10a204217e6f4abaab7c892247198
timeCreated: 1592190499
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/Grab Objects/grabPhysicalObjectMeleeAttackSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,985 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class grabPhysicalObjectSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool grabObjectPhysically = true;
public string objectName;
public LayerMask layerForUsers;
public Vector3 colliderScale;
public Vector3 colliderOffset;
public string tagForObjectWhenActive;
public string tagForObjectWhenInactive;
public bool carryObjectOutOfPlayerBody;
public bool disableObjectColliderWhileGrabbed;
[Space]
public bool ignoreToGrabPhysicallyIfPickedWithAimingMode;
[Space]
[Header ("Physics Settings")]
[Space]
public bool setRigidbodyMassValue;
public float rigidbodyMassValue = 1;
public bool setCustomLayerOnCollidersOnGrab;
public string customLayerOnCollidersOnGrab;
public bool useCustomRigidbodiesParent;
public Transform customRigidbodiesParent;
[Space]
[Header ("Grab Object Animation Settings")]
[Space]
public bool changeAnimationSpeed;
[Range (0, 1)] public float animationSpeed = 1;
public bool setNewMovementTreeID;
public int newMovementTreeID;
public bool applyAnimatorVelocityWithoutMoving;
public bool disableJumpOnGrabbedObject;
public bool disableRunOnGrabbedObject;
public bool disableCrouchOnGrabbedObjet;
[Space]
[Header ("Grab Object Settings")]
[Space]
public bool checkViewToGrabObject;
public bool canBeGrabbedOnFirstPerson = true;
public bool canBeGrabbedOnThirdPerson = true;
[Space]
[Header ("Transform Reference Settings")]
[Space]
public Transform referencePosition;
public bool useReferencePositionForEveryView;
public Transform referencePositionThirdPerson;
public Transform referencePositionFirstPerson;
public Transform referencePositionFBA;
public Transform referencePositionToKeepObject;
[Space]
[Header ("Mount Point Settings")]
[Space]
public bool useBoneToKeepObject;
public HumanBodyBones boneToKeepObject;
public bool useMountPointToKeepObject;
public string mountPointTokeepObjectName;
[Space]
[Header ("Generic Mode Settings")]
[Space]
public bool canBeGrabbedOnGenericMode;
public string mountPointNameToCarryOnGenericMode = "Mouth";
public bool setCustomObjectScaleOnGenericMode;
public Vector3 customObjectScaleOnGenericMode;
[Space]
[Header ("IK Settings")]
[Space]
public bool IKSystemEnabled = true;
public bool useRightHand = true;
public bool useLeftHand = true;
public Transform rightHandPosition;
public Transform lefHandPosition;
public bool useRightElbow;
public bool useLeftElbow;
public Transform rightElbowPosition;
public Transform lefElbowPosition;
[Space]
[Header ("Hands Settings")]
[Space]
public bool useAnimationGrabbingHand;
public int rightGrabbingHandID;
public int leftGrabbingHandID;
[Space]
[Header ("Grab Object Parent Settings")]
[Space]
public bool useRightHandForObjectParent = true;
[Space]
[Header ("Kinematic List Settings")]
[Space]
public bool setExtraListKinematic;
public List<Rigidbody> extraListKinematic = new List<Rigidbody> ();
[Space]
[Header ("Melee Weapons Settings")]
[Space]
public bool useMeleeAttackSystem;
public grabPhysicalObjectMeleeAttackSystem mainGrabPhysicalObjectMeleeAttackSystem;
[Space]
[Header ("Other Settings")]
[Space]
public bool enableTransparencyOnFBA;
[Space]
public bool useThrowAnimationOnCharacterEnabled;
public string throwAnimationOneHand = "Throw Physical Object One Hand";
public string throwAnimationTwoHands = "Throw Physical Object Two Hands";
public bool useDelayToThrowObjectDuringAnimation;
public float delayToThrowObjectDuringAnimation;
public bool ignoreShowObjectNameOnGrabObjectsSystem;
[Space]
[Header ("Extra Collider Settings")]
[Space]
public bool objectUsesExtraColliderList;
public List<Collider> extraColliderList = new List<Collider> ();
public bool checkExtraCollidersInParent;
public Transform extraCollidersParent;
[Space]
[Header ("Debug")]
[Space]
public bool objectGrabed;
public bool objectIsCharacter;
public GameObject character;
public Transform characterBody;
public bool keepGrabbedObjectState;
public List<grabObjects> grabObjectsList = new List<grabObjects> ();
public Transform currentObjectParent;
[Space]
[Header ("Events Settings")]
[Space]
public bool useEventsOnGrabDrop;
public UnityEvent eventOnGrab;
public UnityEvent eventOnDrop;
[Space]
[Header ("Remote Event Settings")]
[Space]
public bool useRemoteEventOnObjectsFound;
public List<string> remoteEventNameListOnStart = new List<string> ();
public List<string> remoteEventNameListOnEnd = new List<string> ();
[Space]
[Header ("Grab Object Type Settings")]
[Space]
public bool objectMeshInsideMainParent;
public Transform objectMeshMainParent;
public bool useMeshCollider;
public bool useBoxCollider;
[Space]
[Header ("Gizmo Settings")]
[Space]
public bool showGizmo;
public Color gizmoColor = Color.red;
[Space]
[Header ("Components")]
[Space]
public GameObject objectToGrabParent;
public Collider grabObjectTrigger;
public Collider mainCollider;
public Rigidbody mainRigidbody;
grabObjects grabObjectsManager;
GameObject currentUser;
grabObjects currentGrabObjectDetected;
List<Rigidbody> rigidbodyList = new List<Rigidbody> ();
List<float> rigidbodyMassList = new List<float> ();
List<int> layerMaskList = new List<int> ();
Vector3 lastPositionBeforeGrabbed;
Quaternion lastRotationBeforeGrabbed;
Vector3 lastPositionBeforeDropped;
Quaternion lastRotationBeforeDropped;
Vector3 originalScale = -Vector3.one;
void Start ()
{
assignObjectToGrabParentIfNull ();
}
public void assignObjectToGrabParentIfNull ()
{
if (objectToGrabParent == null) {
objectToGrabParent = gameObject;
}
}
public void setRigidbodyList ()
{
if (rigidbodyList.Count == 0) {
assignObjectToGrabParentIfNull ();
Transform currentRigidbodiesParent = objectToGrabParent.transform;
if (useCustomRigidbodiesParent) {
currentRigidbodiesParent = customRigidbodiesParent;
}
Component [] components = currentRigidbodiesParent.GetComponentsInChildren (typeof (Rigidbody));
foreach (Rigidbody child in components) {
rigidbodyMassList.Add (child.mass);
rigidbodyList.Add (child);
layerMaskList.Add (child.gameObject.layer);
}
}
}
public void grabObject (GameObject currentPlayer)
{
if (objectGrabed) {
return;
}
//print ("grab object");
objectGrabed = true;
grabObjectsManager = currentPlayer.GetComponent<grabObjects> ();
setGrabObjectTriggerState (false);
assignObjectToGrabParentIfNull ();
lastPositionBeforeGrabbed = objectToGrabParent.transform.position;
lastRotationBeforeGrabbed = objectToGrabParent.transform.rotation;
grabPhysicalObjectInfo newGrabPhysicalObjectInfo = new grabPhysicalObjectInfo ();
newGrabPhysicalObjectInfo.objectToGrab = objectToGrabParent;
newGrabPhysicalObjectInfo.IKSystemEnabled = IKSystemEnabled;
newGrabPhysicalObjectInfo.changeAnimationSpeed = changeAnimationSpeed;
newGrabPhysicalObjectInfo.animationSpeed = animationSpeed;
newGrabPhysicalObjectInfo.setNewMovementTreeID = setNewMovementTreeID;
newGrabPhysicalObjectInfo.newMovementTreeID = newMovementTreeID;
newGrabPhysicalObjectInfo.applyAnimatorVelocityWithoutMoving = applyAnimatorVelocityWithoutMoving;
newGrabPhysicalObjectInfo.disableJumpOnGrabbedObject = disableJumpOnGrabbedObject;
newGrabPhysicalObjectInfo.disableRunOnGrabbedObject = disableRunOnGrabbedObject;
newGrabPhysicalObjectInfo.disableCrouchOnGrabbedObjet = disableCrouchOnGrabbedObjet;
newGrabPhysicalObjectInfo.rightHandPosition = rightHandPosition;
newGrabPhysicalObjectInfo.lefHandPosition = lefHandPosition;
newGrabPhysicalObjectInfo.useRightHand = useRightHand;
newGrabPhysicalObjectInfo.useLeftHand = useLeftHand;
newGrabPhysicalObjectInfo.useRightElbow = useRightElbow;
newGrabPhysicalObjectInfo.useLeftElbow = useLeftElbow;
newGrabPhysicalObjectInfo.rightElbowPosition = rightElbowPosition;
newGrabPhysicalObjectInfo.lefElbowPosition = lefElbowPosition;
newGrabPhysicalObjectInfo.useAnimationGrabbingHand = useAnimationGrabbingHand;
newGrabPhysicalObjectInfo.rightGrabbingHandID = rightGrabbingHandID;
newGrabPhysicalObjectInfo.leftGrabbingHandID = leftGrabbingHandID;
newGrabPhysicalObjectInfo.useRightHandForObjectParent = useRightHandForObjectParent;
grabObjectsManager.grabPhysicalObject (newGrabPhysicalObjectInfo);
for (int i = 0; i < grabObjectsList.Count; i++) {
if (grabObjectsList [i] != grabObjectsManager) {
grabObjectsList [i].removeCurrentPhysicalObjectToGrabFound (objectToGrabParent);
}
}
if (setRigidbodyMassValue || setCustomLayerOnCollidersOnGrab) {
setRigidbodyList ();
string customLayerName = "Ignore Raycast";
if (setCustomLayerOnCollidersOnGrab) {
customLayerName = customLayerOnCollidersOnGrab;
}
int ignoreRaycastLayerIndex = LayerMask.NameToLayer (customLayerName);
for (int i = 0; i < rigidbodyList.Count; i++) {
if (rigidbodyMassValue >= 0) {
rigidbodyList [i].mass = rigidbodyMassValue;
}
rigidbodyList [i].gameObject.layer = ignoreRaycastLayerIndex;
}
}
if (setExtraListKinematic) {
for (int i = 0; i < extraListKinematic.Count; i++) {
if (extraListKinematic [i] != null) {
extraListKinematic [i].isKinematic = true;
}
}
}
if (objectIsCharacter) {
if (character != null) {
ragdollActivator currentRagdollActivator = character.GetComponent<ragdollActivator> ();
if (currentRagdollActivator != null) {
currentRagdollActivator.setCheckGetUpPausedState (true);
}
}
}
checkEventsOnGrabDrop (true);
checkRemoteEvents (true);
if (disableObjectColliderWhileGrabbed) {
setMainColliderEnabledState (false);
}
}
public void dropObject ()
{
//print ("drop object");
objectGrabed = false;
lastPositionBeforeDropped = objectToGrabParent.transform.position;
lastRotationBeforeDropped = objectToGrabParent.transform.rotation;
if (grabObjectsManager != null) {
grabObjectsManager.dropPhysicalObject ();
}
grabObjectsManager = null;
setGrabObjectTriggerState (true);
if (setExtraListKinematic) {
for (int i = 0; i < extraListKinematic.Count; i++) {
if (extraListKinematic [i] != null) {
extraListKinematic [i].isKinematic = false;
}
}
}
if (setRigidbodyMassValue || setCustomLayerOnCollidersOnGrab) {
for (int i = 0; i < rigidbodyList.Count; i++) {
rigidbodyList [i].mass = rigidbodyMassList [i];
rigidbodyList [i].gameObject.layer = layerMaskList [i];
}
}
if (objectIsCharacter) {
assignObjectToGrabParentIfNull ();
if (character != null) {
ragdollActivator currentRagdollActivator = character.GetComponent<ragdollActivator> ();
if (currentRagdollActivator != null) {
currentRagdollActivator.setCheckGetUpPausedState (false);
if (characterBody == null) {
characterBody = currentRagdollActivator.characterBody.transform;
}
}
}
if (characterBody != null) {
characterBody.transform.position = objectToGrabParent.transform.position;
}
objectToGrabParent.transform.SetParent (characterBody);
}
checkEventsOnGrabDrop (false);
checkRemoteEvents (false);
if (disableObjectColliderWhileGrabbed) {
setMainColliderEnabledState (true);
}
keepGrabbedObjectState = false;
currentObjectParent = null;
}
public void checkParentAssignedState ()
{
checkNewParentAssignedState (objectToGrabParent.transform.parent);
}
public void checkNewParentAssignedState (Transform newParent)
{
}
public bool isUseReferencePositionForEveryViewActive ()
{
return useReferencePositionForEveryView;
}
public Transform getReferencePositionThirdPerson ()
{
return referencePositionThirdPerson;
}
public Transform getReferencePositionFirstPerson ()
{
return referencePositionFirstPerson;
}
public Transform getReferencePositionFBA ()
{
return referencePositionFBA;
}
public Transform getReferencePosition ()
{
return referencePosition;
}
public string getObjectName ()
{
if (objectName == "") {
objectName = gameObject.name;
}
return objectName;
}
public bool isIgnoreShowObjectNameOnGrabObjectsSystemActive ()
{
return ignoreShowObjectNameOnGrabObjectsSystem;
}
public bool isCanBeGrabbedOnGenericModeEnabled ()
{
return canBeGrabbedOnGenericMode;
}
public bool isIgnoreToGrabPhysicallyIfPickedWithAimingModeActive ()
{
return ignoreToGrabPhysicallyIfPickedWithAimingMode;
}
void OnTriggerEnter (Collider col)
{
checkTriggerInfo (col, true);
}
void OnTriggerExit (Collider col)
{
checkTriggerInfo (col, false);
}
public void checkTriggerInfo (Collider col, bool isEnter)
{
if (objectGrabed) {
return;
}
if ((1 << col.gameObject.layer & layerForUsers.value) == 1 << col.gameObject.layer) {
//if the player is entering in the trigger
currentGrabObjectDetected = col.gameObject.GetComponent<grabObjects> ();
if (currentGrabObjectDetected != null) {
assignObjectToGrabParentIfNull ();
if (isEnter) {
if (!currentGrabObjectDetected.isGrabObjectsPhysicallyEnabled ()) {
return;
}
currentUser = col.gameObject;
if (grabObjectPhysically) {
if (objectIsCharacter) {
if (character == currentUser) {
return;
}
}
grabObjectsList.Add (currentGrabObjectDetected);
currentGrabObjectDetected.addCurrentPhysicalObjectToGrabFound (objectToGrabParent);
}
} else {
if (objectToGrabParent != null) {
currentGrabObjectDetected.removeCurrentPhysicalObjectToGrabFound (objectToGrabParent);
}
grabObjectsList.Remove (currentGrabObjectDetected);
}
}
}
}
public void removeAllGrabObjectsFound ()
{
assignObjectToGrabParentIfNull ();
for (int i = grabObjectsList.Count - 1; i >= 0; i--) {
if (grabObjectsList [i].isCarryingPhysicalObject () && grabObjectsList [i].getCurrentPhysicalObjectGrabbed () != null &&
grabObjectsList [i].getCurrentPhysicalObjectGrabbed () == objectToGrabParent) {
grabObjectsList [i].dropObject ();
}
grabObjectsList [i].removeCurrentPhysicalObjectToGrabFound (objectToGrabParent);
grabObjectsList.RemoveAt (i);
}
}
public void setCurrentPlayer (GameObject newPlayer)
{
checkTriggerInfo (newPlayer.GetComponent<Collider> (), true);
}
public bool isGrabObjectPhysicallyEnabled ()
{
return grabObjectPhysically;
}
public bool isCanBeGrabbedOnFirstPersonEnabled ()
{
return canBeGrabbedOnFirstPerson;
}
public bool isCanBeGrabbedOnThirdPersonEnabled ()
{
return canBeGrabbedOnThirdPerson;
}
public void disableGrabPhysicalObject ()
{
grabObjectPhysically = false;
if (currentUser != null) {
assignObjectToGrabParentIfNull ();
currentUser.GetComponent<grabObjects> ().removeCurrentPhysicalObjectToGrabFound (objectToGrabParent);
}
}
public void setGrabObjectPhysicallyEnabledState (bool state)
{
grabObjectPhysically = state;
}
public void setGrabObjectPhysicallyEnabledStateFromEditor (bool state)
{
setGrabObjectPhysicallyEnabledState (state);
updateComponent ();
}
public void setMainColliderEnabledState (bool state)
{
if (mainCollider != null) {
mainCollider.enabled = state;
}
}
public void setGrabObjectTriggerState (bool state)
{
if (grabObjectTrigger != null) {
grabObjectTrigger.enabled = state;
}
}
public void setGrabObjectTriggerStateFromEditor (bool state)
{
setGrabObjectTriggerState (state);
updateComponent ();
}
public void setCharacterBody (Transform newCharacterBody)
{
characterBody = newCharacterBody;
updateComponent ();
}
public void setCharacter (GameObject newCharacter)
{
character = newCharacter;
updateComponent ();
}
public void setObjectToGrabParent (GameObject newObjectToGrabParent)
{
objectToGrabParent = newObjectToGrabParent;
updateComponent ();
}
public void setActiveOrInactiveObjectState (bool state)
{
if (state) {
if (tagForObjectWhenActive == "") {
tagForObjectWhenActive = "box";
}
objectToGrabParent.tag = tagForObjectWhenActive;
} else {
if (tagForObjectWhenInactive == "") {
tagForObjectWhenInactive = "Untagged";
}
objectToGrabParent.tag = tagForObjectWhenInactive;
}
}
public void checkEventsOnGrabDrop (bool state)
{
if (useEventsOnGrabDrop) {
if (state) {
eventOnGrab.Invoke ();
} else {
eventOnDrop.Invoke ();
}
}
}
public void disableGrabPhysicalObjectComponent ()
{
removeAllGrabObjectsFound ();
setGrabObjectTriggerState (false);
setActiveOrInactiveObjectState (false);
}
public bool isUseRightHandActive ()
{
return useRightHand;
}
public bool isUseLeftHandActive ()
{
return useLeftHand;
}
public bool hasObjectMeleeAttackSystem ()
{
return useMeleeAttackSystem;
}
public grabPhysicalObjectMeleeAttackSystem getMainGrabPhysicalObjectMeleeAttackSystem ()
{
return mainGrabPhysicalObjectMeleeAttackSystem;
}
public void activateReturnProjectilesOnContact ()
{
if (grabObjectsManager != null) {
grabObjectsManager.activateReturnProjectilesOnContact ();
}
}
public void checkRemoteEvents (bool state)
{
if (state) {
checkRemoteEventOnStart ();
} else {
checkRemoteEventOnEnd ();
}
}
public void checkRemoteEventOnStart ()
{
if (useRemoteEventOnObjectsFound) {
if (currentUser != null) {
remoteEventSystem currentRemoteEventSystem = currentUser.GetComponent<remoteEventSystem> ();
if (currentRemoteEventSystem != null) {
for (int i = 0; i < remoteEventNameListOnStart.Count; i++) {
currentRemoteEventSystem.callRemoteEvent (remoteEventNameListOnStart [i]);
}
}
}
}
}
public void checkRemoteEventOnEnd ()
{
if (useRemoteEventOnObjectsFound) {
if (currentUser != null) {
remoteEventSystem currentRemoteEventSystem = currentUser.GetComponent<remoteEventSystem> ();
if (currentRemoteEventSystem != null) {
for (int i = 0; i < remoteEventNameListOnEnd.Count; i++) {
currentRemoteEventSystem.callRemoteEvent (remoteEventNameListOnEnd [i]);
}
}
}
}
}
public void setKeepOrCarryGrabbebObjectState (bool state)
{
if (objectGrabed) {
keepGrabbedObjectState = state;
if (useMeleeAttackSystem) {
mainGrabPhysicalObjectMeleeAttackSystem.setKeepOrCarryGrabbebObjectState (state);
}
}
}
public void assignObjectParent (Transform newParent)
{
currentObjectParent = newParent;
}
public Transform getCurrentObjectParent ()
{
return currentObjectParent;
}
public Vector3 getLastPositionBeforeGrabbed ()
{
return lastPositionBeforeGrabbed;
}
public Quaternion getLastRotationBeforeGrabbed ()
{
return lastRotationBeforeGrabbed;
}
public Vector3 getLastPositionBeforeDropped ()
{
return lastPositionBeforeDropped;
}
public Quaternion getLastRotationBeforeDropped ()
{
return lastRotationBeforeDropped;
}
Transform lastParentAssigned;
public void setLastParentAssigned (Transform newParent)
{
lastParentAssigned = newParent;
}
public Transform getLastParentAssigned ()
{
return lastParentAssigned;
}
public void grabPhysicalObjectExternally (GameObject currentPlayer)
{
if (currentPlayer == null) {
return;
}
GKC_Utils.grabPhysicalObjectExternally (currentPlayer, gameObject);
}
public Rigidbody getMainRigidbody ()
{
if (mainRigidbody == null) {
return objectToGrabParent.GetComponent<Rigidbody> ();
}
return mainRigidbody;
}
public void setCustomScale (Vector3 newValue)
{
if (originalScale == -Vector3.one) {
originalScale = transform.localScale;
}
transform.localScale = newValue;
}
public void setOriginalScale ()
{
if (originalScale != -Vector3.one) {
setCustomScale (originalScale);
}
}
public List<Collider> getExtraColliderList ()
{
if (objectUsesExtraColliderList) {
List<Collider> newColliderList = new List<Collider> ();
if (extraColliderList.Count > 0) {
newColliderList.AddRange (extraColliderList);
}
if (checkExtraCollidersInParent) {
Component [] components = extraCollidersParent.GetComponentsInChildren (typeof (Collider));
int componentsLength = components.Length;
for (int i = 0; i < componentsLength; i++) {
Collider currentChildCollider = components [i] as Collider;
if (!currentChildCollider.isTrigger) {
newColliderList.Add (currentChildCollider);
}
}
}
if (newColliderList.Count > 0) {
return newColliderList;
}
}
return null;
}
public bool getObjectUsesExtraColliderListState ()
{
return objectUsesExtraColliderList;
}
//EDITOR FUNCTIONS
void updateComponent ()
{
GKC_Utils.updateComponent (this);
}
#if UNITY_EDITOR
void OnDrawGizmos ()
{
if (!showGizmo) {
return;
}
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
DrawGizmos ();
}
}
void OnDrawGizmosSelected ()
{
DrawGizmos ();
}
void DrawGizmos ()
{
if (showGizmo) {
GKC_Utils.drawRectangleGizmo (transform.position, transform.rotation, colliderOffset, colliderScale, gizmoColor);
if (rightHandPosition) {
Gizmos.DrawSphere (rightHandPosition.position, 0.2f);
}
if (lefHandPosition) {
Gizmos.DrawSphere (lefHandPosition.position, 0.2f);
}
}
}
#endif
[System.Serializable]
public class grabPhysicalObjectInfo
{
public GameObject objectToGrab;
public bool IKSystemEnabled;
public bool changeAnimationSpeed;
public float animationSpeed;
public bool setNewMovementTreeID;
public int newMovementTreeID;
public bool applyAnimatorVelocityWithoutMoving;
public bool disableJumpOnGrabbedObject;
public bool disableRunOnGrabbedObject;
public bool disableCrouchOnGrabbedObjet;
public Transform rightHandPosition;
public Transform lefHandPosition;
public bool useRightHand;
public bool useLeftHand;
public bool useRightElbow;
public bool useLeftElbow;
public Transform rightElbowPosition;
public Transform lefElbowPosition;
public bool useRightHandForObjectParent;
public bool useAnimationGrabbingHand;
public int rightGrabbingHandID;
public int leftGrabbingHandID;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 91f1353fcdf749e4097ef6bcbb87fcc8
timeCreated: 1538825314
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/Grab Objects/grabPhysicalObjectSystem.cs
uploadId: 814740

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: e00458e9b8f97744e9842c0a560b0248
timeCreated: 1592189995
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/Grab Objects/grabbedObjectMeleeAttackSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,110 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class grabbedObjectState : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool removeComponentOnDropObject = true;
[Space]
[Header ("Debug")]
[Space]
public bool insideZeroGravityRoom;
public bool grabbed;
public bool carryingObjectPhysically;
public GameObject currentHolder;
[Space]
[Header ("Event Settings")]
[Space]
public bool useEventsOnGrabbedState;
public UnityEvent eventOnGrabObject;
public UnityEvent eventOnDropObject;
[Space]
[Header ("Components")]
[Space]
public zeroGravityRoomSystem currentZeroGravityRoom;
public void setGrabbedState (bool state)
{
grabbed = state;
if (useEventsOnGrabbedState) {
if (grabbed) {
eventOnGrabObject.Invoke ();
} else {
eventOnDropObject.Invoke ();
}
}
}
public bool isGrabbed ()
{
return grabbed;
}
public void setCurrentHolder (GameObject current)
{
currentHolder = current;
}
public GameObject getCurrentHolder ()
{
return currentHolder;
}
public void setInsideZeroGravityRoomState (bool state)
{
insideZeroGravityRoom = state;
}
public bool isInsideZeroGravityRoom ()
{
return insideZeroGravityRoom;
}
public void setCurrentZeroGravityRoom (zeroGravityRoomSystem gravityRoom)
{
currentZeroGravityRoom = gravityRoom;
}
public zeroGravityRoomSystem getCurrentZeroGravityRoom ()
{
return currentZeroGravityRoom;
}
public void checkGravityRoomState ()
{
if (insideZeroGravityRoom) {
currentZeroGravityRoom.setObjectInsideState (gameObject);
}
}
public void setCarryingObjectPhysicallyState (bool state)
{
carryingObjectPhysically = state;
}
public bool isCarryingObjectPhysically ()
{
return carryingObjectPhysically;
}
public void removeGrabbedObjectComponent ()
{
if (removeComponentOnDropObject) {
Destroy (this);
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 954ba14e89980b34facff3e7b8c97e76
timeCreated: 1516496212
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/Grab Objects/grabbedObjectState.cs
uploadId: 814740

View File

@@ -0,0 +1,169 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class objectDistributorSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool distributorEnabled = true;
public GameObject objectToSpawn;
public bool useSpawnLimit;
public int spawnLimit;
public int currentUnitsAmount;
public bool useUnitsText;
public TextMesh unitsText;
public Transform positionToSpawn;
public string animationName;
[Space]
[Header ("Events Settings")]
[Space]
public UnityEvent eventOnOpenDistributor;
public UnityEvent eventOnCloseDistributor;
public UnityEvent eventOnEmptyUnits;
public bool useEventOnObjectInstatiated;
public eventParameters.eventToCallWithGameObject evenOnObjectInstantiated;
[Space]
[Header ("Debug")]
[Space]
public GameObject currentObjectSpawned;
public bool objectSpawned;
[Space]
[Header ("Components")]
[Space]
public Animation mainAnimation;
public Collider mainCollider;
public electronicDevice electronicDeviceManager;
GameObject currentPlayer;
usingDevicesSystem usingDevicesManager;
Coroutine playAnimationCoroutine;
void Start ()
{
if (useSpawnLimit) {
currentUnitsAmount = spawnLimit;
if (useUnitsText) {
unitsText.text = currentUnitsAmount.ToString ();
}
} else {
unitsText.gameObject.SetActive (false);
}
}
public void spawnObject ()
{
if (!distributorEnabled) {
return;
}
if (useSpawnLimit) {
currentUnitsAmount--;
if (useUnitsText) {
unitsText.text = currentUnitsAmount.ToString ();
}
}
stopDistributorCoroutine ();
playAnimationCoroutine = StartCoroutine (spawnObjectCoroutine ());
}
public void stopDistributorCoroutine ()
{
if (playAnimationCoroutine != null) {
StopCoroutine (playAnimationCoroutine);
}
}
IEnumerator spawnObjectCoroutine ()
{
objectSpawned = true;
//yield return new WaitForSeconds (0.1f);
removeDeviceFromList ();
mainCollider.enabled = false;
eventOnOpenDistributor.Invoke ();
currentObjectSpawned = (GameObject)Instantiate (objectToSpawn, positionToSpawn.position, positionToSpawn.rotation);
yield return new WaitForSeconds (0.01f);
if (useEventOnObjectInstatiated) {
evenOnObjectInstantiated.Invoke (currentObjectSpawned);
}
while (mainAnimation.IsPlaying (animationName)) {
yield return null;
}
}
public void OnTriggerExit (Collider col)
{
if (objectSpawned) {
if (col.gameObject == currentObjectSpawned) {
objectSpawned = false;
currentObjectSpawned = null;
stopDistributorCoroutine ();
playAnimationCoroutine = StartCoroutine (closeObjectDistributor ());
}
}
}
IEnumerator closeObjectDistributor ()
{
eventOnCloseDistributor.Invoke ();
while (mainAnimation.IsPlaying (animationName)) {
yield return null;
}
if (useSpawnLimit) {
if (currentUnitsAmount == 0) {
eventOnEmptyUnits.Invoke ();
removeDeviceFromList ();
mainCollider.enabled = false;
} else {
mainCollider.enabled = true;
}
} else {
mainCollider.enabled = true;
}
}
public void removeDeviceFromList ()
{
currentPlayer = electronicDeviceManager.getCurrentPlayer ();
if (currentPlayer != null) {
usingDevicesManager = currentPlayer.GetComponent<usingDevicesSystem> ();
usingDevicesManager.removeDeviceFromListExternalCall (electronicDeviceManager.gameObject);
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 5612b281ada50344f8435a7239f20862
timeCreated: 1539994856
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/Grab Objects/objectDistributorSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,853 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Events;
public class objectToPlaceSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool objectToPlacedEnabled = true;
public bool objectCanCallPlacedEvent = true;
public bool objectCanCallRemovedEvent = true;
public string objectName;
[Space]
[Header ("Secondary Object To Place Settings")]
[Space]
public bool useSecondaryObjectToPlaceConnected;
public objectToPlaceSystem secondaryObjectToPlaceSystem;
[Space]
[Header ("Connect To Others Objects To Place Settings")]
[Space]
public bool searchOtherObjectsToPlaceOnDropEnabled;
public string otherObjectsToPlaceOnDropName;
public Transform customPlaceToPutOtherObjectToPlaceTransform;
[Space]
public bool useOtherObjectsToPlaceOnDropNameList;
public List<otherObjectsToPlaceOnDropInfo> otherObjectsToPlaceOnDropInfoList = new List<otherObjectsToPlaceOnDropInfo> ();
[Space]
public float maxDistanceToSearchOtherObjectsToPlaceAround;
public bool useFindObjectsOnSceneForOtherObjectsToPlace;
public LayerMask layerToSearchOtherObjectsToPlaceAround;
public float radiusToSearchOtherObjectsToPlaceAround;
[Space]
[Header ("Search Objects On Drop Settings")]
[Space]
public bool searchPutObjectSystemsAroundOnDropEnabled;
public float maxDistanceToSearchPutObjectsSystemsAround;
public bool useFindObjectsOnScene;
public LayerMask layerToSearchPutObjectSystemsAround;
public float radiusToSearchPutObjectSystemsAround;
[Space]
[Header ("Other Settings")]
[Space]
public bool useCustomPlaceToPutObjectTransform;
public Transform customPlaceToPutObjectTransform;
[Space]
public bool checkNameOnPutObjectSystemToCallEvent;
public string nameOnPutObjectSystemToCallEvent;
[Space]
[Header ("Debug")]
[Space]
public bool showDebugPrint;
public bool objectInGrabbedState;
public bool objectPlaced;
[Space]
public bool secondaryObjectToPlaceConnectedState;
public bool connectedToOtherObjectToPlace;
public bool adjustingObjectToPlaceInProcess;
[Space]
public putObjectSystem currentPutObjectSystem;
public objectToPlaceSystem otherObjectToPlaceConnected;
[Space]
[Header ("Event Settings")]
[Space]
public bool useEventOnObjectPlacedStateChanged;
public UnityEvent eventOnObjectPlaced;
public UnityEvent eventOnObjectRemoved;
[Space]
public bool useEventOnConnectedToOtherObjectStateChanged;
public UnityEvent eventOnConnectedToOtherObject;
public UnityEvent eventOnDisconnectedToOtherObject;
public string getObjectName ()
{
return objectName;
}
public void assignPutObjectSystem (putObjectSystem putObjectSystemToAssign)
{
currentPutObjectSystem = putObjectSystemToAssign;
}
public void setObjectPlaceState (bool state)
{
objectPlaced = state;
}
public bool isObjectPlaced ()
{
return objectPlaced;
}
public bool isObjectInGrabbedState ()
{
return objectInGrabbedState;
}
public void setObjectToPlacedEnabledState (bool state)
{
objectToPlacedEnabled = state;
}
public bool isobjectToPlacedEnabled ()
{
return objectToPlacedEnabled;
}
public bool canObjectCanCallPlacedEvent ()
{
return objectCanCallPlacedEvent;
}
public bool canObjectCanCallRemovedEvent ()
{
return objectCanCallRemovedEvent;
}
public void setObjectCanCallPlacedEventState (bool state)
{
objectCanCallPlacedEvent = state;
}
public void setObjectCanCallRemovedEventState (bool state)
{
objectCanCallRemovedEvent = state;
}
public bool isUseCustomPlaceToPutObjectTransformActive ()
{
return useCustomPlaceToPutObjectTransform;
}
public Transform getCustomPlaceToPutObjectTransform ()
{
return customPlaceToPutObjectTransform;
}
public bool isUseSecondaryObjectToPlaceConnectedEnabled ()
{
return useSecondaryObjectToPlaceConnected;
}
public bool isSecondaryObjectToPlaceConnected ()
{
return secondaryObjectToPlaceConnectedState;
}
public string getOtherObjectsToPlaceOnDropName ()
{
return otherObjectsToPlaceOnDropName;
}
public bool isConnectedToOtherObjectToPlace ()
{
return connectedToOtherObjectToPlace;
}
public void setAdjustingObjectToPlaceInProcessState (bool state)
{
adjustingObjectToPlaceInProcess = state;
}
public bool isAdjustingObjectToPlaceInProcess ()
{
return adjustingObjectToPlaceInProcess;
}
public void removeObjectIfPlaced ()
{
if (objectPlaced) {
setObjectInGrabbedState (true);
objectInGrabbedState = false;
Rigidbody mainRigidbody = gameObject.GetComponent<Rigidbody> ();
if (mainRigidbody != null) {
mainRigidbody.isKinematic = false;
mainRigidbody.useGravity = true;
}
}
}
public void removeObjectIfConnectedToOtherObject ()
{
if (connectedToOtherObjectToPlace) {
setObjectInGrabbedState (true);
objectInGrabbedState = false;
Rigidbody mainRigidbody = gameObject.GetComponent<Rigidbody> ();
if (mainRigidbody != null) {
mainRigidbody.isKinematic = false;
mainRigidbody.useGravity = true;
}
}
}
public void setObjectInGrabbedState (bool state)
{
if (!objectToPlacedEnabled) {
return;
}
objectInGrabbedState = state;
if (objectInGrabbedState && objectPlaced) {
objectPlaced = false;
if (currentPutObjectSystem != null) {
currentPutObjectSystem.removePlacedObject ();
currentPutObjectSystem = null;
}
checkEventOnObjectPlacedStateChanged (false);
}
if (showDebugPrint) {
print (objectPlaced + " " + searchOtherObjectsToPlaceOnDropEnabled + " " +
objectInGrabbedState + " " + connectedToOtherObjectToPlace);
}
if (!objectPlaced) {
if (searchOtherObjectsToPlaceOnDropEnabled) {
if (objectInGrabbedState) {
loopCounter = 0;
if (connectedToOtherObjectToPlace) {
print ("connected to other object to place, disconnecting to grab");
setConnectedToOtherObjectToPlaceState (false, null);
connectedToOtherObjectToPlace = false;
}
//if (secondaryObjectToPlaceConnectedState) {
//print ("extreme is connected to something");
checkToSetStateOnSecondaryObjectToPlaceOnObjectPlaceStateChange (false, this);
//}
}
}
}
}
int loopCounter = 0;
public void checkToSetStateOnSecondaryObjectToPlaceOnObjectPlaceStateChange (bool state, objectToPlaceSystem originalObjectToPlace)
{
//if (showDebugPrint) {
//print ("checking state on secondary object on " + gameObject.name);
// }
loopCounter++;
if (loopCounter > 30) {
print ("infinite loop, stopping");
return;
}
//set the state on the extreme of this object and if that extreme has any device connnected
if (secondaryObjectToPlaceSystem.otherObjectToPlaceConnected != null) {
if (originalObjectToPlace != null && secondaryObjectToPlaceSystem.otherObjectToPlaceConnected == originalObjectToPlace) {
print ("loop detected, cable connected to itself, cancelling check");
} else {
secondaryObjectToPlaceSystem.otherObjectToPlaceConnected.checkEventsOnCurrentPutObjectSystemState (state);
secondaryObjectToPlaceSystem.otherObjectToPlaceConnected.
checkToSetStateOnSecondaryObjectToPlaceOnObjectPlaceStateChange (state, originalObjectToPlace);
}
} else {
if (secondaryObjectToPlaceSystem.isObjectPlaced ()) {
secondaryObjectToPlaceSystem.checkEventsOnCurrentPutObjectSystemState (state);
}
}
}
public void checkStateOnExtremesDisconnected ()
{
if (showDebugPrint) {
print ("connection between extremes broken, disabling connected state and can call events disabled");
}
if (objectPlaced) {
checkEventsOnCurrentPutObjectSystemState (false);
setObjectCanCallPlacedEventState (false);
setObjectCanCallRemovedEventState (false);
}
if (searchOtherObjectsToPlaceOnDropEnabled) {
checkToSetStateOnSecondaryObjectToPlaceOnObjectPlaceStateChange (false, null);
if (otherObjectToPlaceConnected != null) {
otherObjectToPlaceConnected.checkToSetStateOnSecondaryObjectToPlaceOnObjectPlaceStateChange (false, null);
}
if (secondaryObjectToPlaceSystem != null) {
secondaryObjectToPlaceSystem.setObjectCanCallPlacedEventState (false);
secondaryObjectToPlaceSystem.setObjectCanCallRemovedEventState (false);
}
}
}
public void checkStateOnExtremesOnObjectPlaced ()
{
if (objectPlaced && searchOtherObjectsToPlaceOnDropEnabled && objectCanCallPlacedEvent) {
if (showDebugPrint) {
print ("check extremes on object placed");
}
bool extremeOnecheckNameOnPutObjectSystemResult = false;
checkNameOnPutObjectSystemToCallEventResult (ref extremeOnecheckNameOnPutObjectSystemResult, null);
if (showDebugPrint) {
print ("extremes names check result " + extremeOnecheckNameOnPutObjectSystemResult);
}
if (extremeOnecheckNameOnPutObjectSystemResult) {
checkToSetStateOnSecondaryObjectToPlaceOnObjectPlaceStateChange (true, null);
}
}
}
public void checkNameOnPutObjectSystemToCallEventResult (ref bool result, objectToPlaceSystem originalObjectToPlace)
{
if (checkNameOnPutObjectSystemToCallEvent) {
if (objectPlaced) {
if (currentPutObjectSystem.getObjectName ().Equals (nameOnPutObjectSystemToCallEvent)) {
result = true;
}
}
if (!objectPlaced || !result) {
if (secondaryObjectToPlaceSystem.otherObjectToPlaceConnected != null) {
if (originalObjectToPlace != null && secondaryObjectToPlaceSystem.otherObjectToPlaceConnected == originalObjectToPlace) {
print ("loop detected, cable connected to itself, cancelling check");
result = false;
} else {
secondaryObjectToPlaceSystem.
otherObjectToPlaceConnected.checkNameOnPutObjectSystemToCallEventResult (ref result, originalObjectToPlace);
}
} else {
if (secondaryObjectToPlaceSystem.isObjectPlaced ()) {
if (secondaryObjectToPlaceSystem.currentPutObjectSystem.getObjectName ().Equals (secondaryObjectToPlaceSystem.nameOnPutObjectSystemToCallEvent)) {
result = true;
}
}
}
}
} else {
result = true;
}
if (showDebugPrint) {
print ("checking extreme on " + gameObject.name + " " + result);
}
}
public void checkIfExtremeConnected (ref bool result, bool ignoreIfThisObjectPlaced, objectToPlaceSystem originalObjectToPlace)
{
if (objectPlaced && !ignoreIfThisObjectPlaced) {
if (objectCanCallPlacedEvent) {
result = true;
}
} else {
if (secondaryObjectToPlaceSystem.otherObjectToPlaceConnected != null) {
if (originalObjectToPlace != null && secondaryObjectToPlaceSystem.otherObjectToPlaceConnected == originalObjectToPlace) {
print ("loop detected, cable connected to itself, cancelling check");
result = false;
} else {
secondaryObjectToPlaceSystem.otherObjectToPlaceConnected.checkIfExtremeConnected (ref result, ignoreIfThisObjectPlaced, originalObjectToPlace);
}
} else {
if (secondaryObjectToPlaceSystem.isObjectPlaced () && secondaryObjectToPlaceSystem.canObjectCanCallPlacedEvent ()) {
result = true;
}
}
}
if (showDebugPrint) {
print ("checking extreme on " + gameObject.name + " " + result);
}
}
public void setSecondaryObjectToPlaceConnectedState (bool state)
{
secondaryObjectToPlaceConnectedState = state;
checkEventsOnCurrentPutObjectSystemState (state);
}
public void checkEventsOnCurrentPutObjectSystemState (bool state)
{
if (currentPutObjectSystem != null) {
if (state) {
if (objectCanCallPlacedEvent) {
currentPutObjectSystem.checkEventsOnObjectPlacedOrRemoved (true);
}
} else {
if (objectCanCallRemovedEvent) {
currentPutObjectSystem.checkEventsOnObjectPlacedOrRemoved (false);
}
}
}
}
public void checkEventOnObjectPlacedStateChanged (bool state)
{
if (useEventOnObjectPlacedStateChanged) {
if (state) {
eventOnObjectPlaced.Invoke ();
} else {
eventOnObjectRemoved.Invoke ();
}
if (showDebugPrint) {
print ("check Event On Object Placed State Changed " + state + " " + gameObject.name);
}
}
}
public void checkEventOnConnectedToOtherObjectStateChanged (bool state)
{
if (useEventOnConnectedToOtherObjectStateChanged) {
if (state) {
eventOnConnectedToOtherObject.Invoke ();
} else {
eventOnDisconnectedToOtherObject.Invoke ();
}
if (showDebugPrint) {
print ("check Event On Connected To Ohter Object State Changed " + state + " " + gameObject.name);
}
}
}
public void setConnectedToOtherObjectToPlaceState (bool state, objectToPlaceSystem newObjectToPlaceSystem)
{
if (showDebugPrint) {
print ("setConnectedToOtherObjectToPlaceState " + connectedToOtherObjectToPlace);
}
connectedToOtherObjectToPlace = state;
if (connectedToOtherObjectToPlace) {
otherObjectToPlaceConnected = newObjectToPlaceSystem;
otherObjectToPlaceConnected.connectedToOtherObjectToPlace = true;
otherObjectToPlaceConnected.otherObjectToPlaceConnected = this;
Transform newParentTransform = getCustomPlaceToPutOtherObjectToPlaceTransform (otherObjectToPlaceConnected.getObjectName ());
otherObjectToPlaceConnected.transform.SetParent (newParentTransform);
otherObjectToPlaceConnected.transform.localPosition = Vector3.zero;
otherObjectToPlaceConnected.transform.localRotation = Quaternion.identity;
Rigidbody mainOtherObjectToPlaceConnectedRigidbody = otherObjectToPlaceConnected.gameObject.GetComponent<Rigidbody> ();
if (mainOtherObjectToPlaceConnectedRigidbody != null) {
mainOtherObjectToPlaceConnectedRigidbody.isKinematic = true;
}
//MAKE BOTH COLLIDERS TO IGNORE EACH OTHER
Collider mainOtherObjectToPlaceConnectedCollider = otherObjectToPlaceConnected.gameObject.GetComponent<Collider> ();
Collider mainCollider = gameObject.GetComponent<Collider> ();
if (mainOtherObjectToPlaceConnectedCollider != null && mainCollider != null) {
Physics.IgnoreCollision (mainOtherObjectToPlaceConnectedCollider, mainCollider, true);
}
//print ("check both extremes of each connection to send the event to call to enable");
//print ("it is needed to check if both extremes are connected fully");
bool extremeOneConnectedResult = false;
checkIfExtremeConnected (ref extremeOneConnectedResult, false, this);
bool extremeTwoConnectedResult = false;
otherObjectToPlaceConnected.checkIfExtremeConnected (ref extremeTwoConnectedResult, false, otherObjectToPlaceConnected);
if (showDebugPrint) {
print ("extremes connected result " + extremeOneConnectedResult + " " + extremeTwoConnectedResult);
}
bool extremeOnecheckNameOnPutObjectSystemResult = false;
checkNameOnPutObjectSystemToCallEventResult (ref extremeOnecheckNameOnPutObjectSystemResult, this);
bool extremeTwocheckNameOnPutObjectSystemResult = false;
otherObjectToPlaceConnected.checkNameOnPutObjectSystemToCallEventResult (ref extremeTwocheckNameOnPutObjectSystemResult
, otherObjectToPlaceConnected);
if (showDebugPrint) {
print ("extremes names check result " + extremeOnecheckNameOnPutObjectSystemResult + " " +
extremeTwocheckNameOnPutObjectSystemResult);
}
if (extremeOneConnectedResult && extremeTwoConnectedResult &&
(extremeOnecheckNameOnPutObjectSystemResult ||
extremeTwocheckNameOnPutObjectSystemResult)) {
checkToSetStateOnSecondaryObjectToPlaceOnObjectPlaceStateChange (true, null);
otherObjectToPlaceConnected.checkToSetStateOnSecondaryObjectToPlaceOnObjectPlaceStateChange (true, null);
if (showDebugPrint) {
print ("both extremes of loop connected");
}
}
checkEventOnConnectedToOtherObjectStateChanged (true);
otherObjectToPlaceConnected.checkEventOnConnectedToOtherObjectStateChanged (true);
} else {
if (otherObjectToPlaceConnected != null) {
//MAKE BOTH COLLIDERS TO IGNORE EACH OTHER
Collider mainOtherObjectToPlaceConnectedCollider = otherObjectToPlaceConnected.gameObject.GetComponent<Collider> ();
Collider mainCollider = gameObject.GetComponent<Collider> ();
if (mainOtherObjectToPlaceConnectedCollider != null && mainCollider != null) {
Physics.IgnoreCollision (mainOtherObjectToPlaceConnectedCollider, mainCollider, false);
}
otherObjectToPlaceConnected.connectedToOtherObjectToPlace = false;
if (showDebugPrint) {
print ("check both extremes of each connection to send the event to call to disable");
}
checkToSetStateOnSecondaryObjectToPlaceOnObjectPlaceStateChange (false, this);
otherObjectToPlaceConnected.checkToSetStateOnSecondaryObjectToPlaceOnObjectPlaceStateChange (false, otherObjectToPlaceConnected);
checkEventOnConnectedToOtherObjectStateChanged (false);
otherObjectToPlaceConnected.checkEventOnConnectedToOtherObjectStateChanged (false);
Rigidbody mainOtherObjectToPlaceConnectedRigidbody = otherObjectToPlaceConnected.gameObject.GetComponent<Rigidbody> ();
if (mainOtherObjectToPlaceConnectedRigidbody != null) {
mainOtherObjectToPlaceConnectedRigidbody.isKinematic = false;
}
otherObjectToPlaceConnected.otherObjectToPlaceConnected = null;
if (otherObjectToPlaceConnected.transform.IsChildOf (transform)) {
otherObjectToPlaceConnected.transform.SetParent (null);
} else if (transform.IsChildOf (otherObjectToPlaceConnected.transform)) {
transform.SetParent (null);
}
}
otherObjectToPlaceConnected = null;
}
}
public void checkObjectsAround ()
{
if (searchPutObjectSystemsAroundOnDropEnabled) {
float minDistance = Mathf.Infinity;
int putObjectSystemIndex = -1;
List<putObjectSystem> objectsLocatedList = new List<putObjectSystem> ();
if (useFindObjectsOnScene) {
List<putObjectSystem> putObjectSystemList = GKC_Utils.FindObjectsOfTypeAll<putObjectSystem> ();
int putObjectSystemListCount = putObjectSystemList.Count;
for (int i = 0; i < putObjectSystemListCount; i++) {
objectsLocatedList.Add (putObjectSystemList [i]);
}
} else {
Collider [] colliders = Physics.OverlapSphere (transform.position,
radiusToSearchPutObjectSystemsAround,
layerToSearchPutObjectSystemsAround);
if (colliders.Length == 0) {
if (showDebugPrint) {
print ("objects not found on radius");
}
} else {
if (showDebugPrint) {
print ("objects found on radius " + colliders.Length);
}
}
int collidersLength = colliders.Length;
for (int i = 0; i < collidersLength; i++) {
putObjectSystem temporalputObjectSystem = colliders [i].gameObject.GetComponent<putObjectSystem> ();
if (temporalputObjectSystem != null) {
objectsLocatedList.Add (temporalputObjectSystem);
}
}
}
int objectsLocatedListCount = objectsLocatedList.Count;
for (int i = 0; i < objectsLocatedListCount; i++) {
bool putObjectSystemLocatedResult = false;
if (objectsLocatedList [i].isPutObjectSystemEnabled ()) {
float currentDistance = GKC_Utils.distance (transform.position, objectsLocatedList [i].getPlaceToPutObjectPosition ());
if (maxDistanceToSearchPutObjectsSystemsAround == 0 || currentDistance < maxDistanceToSearchPutObjectsSystemsAround) {
if (currentDistance < minDistance) {
putObjectSystemLocatedResult = true;
minDistance = currentDistance;
}
}
if (showDebugPrint) {
print ("checking state on " + objectsLocatedList [i].name + " " +
putObjectSystemLocatedResult + " " + currentDistance);
}
}
if (putObjectSystemLocatedResult) {
putObjectSystemIndex = i;
}
}
if (putObjectSystemIndex > -1) {
if (showDebugPrint) {
print ("object found, connecting " + objectsLocatedList [putObjectSystemIndex].name);
}
objectsLocatedList [putObjectSystemIndex].placeObject (gameObject);
return;
} else {
if (showDebugPrint) {
print ("no objects found");
}
}
}
if (searchOtherObjectsToPlaceOnDropEnabled) {
float minDistance = Mathf.Infinity;
int otherObjectToPlaceIndex = -1;
List<objectToPlaceSystem> objectsLocatedList = new List<objectToPlaceSystem> ();
if (useFindObjectsOnSceneForOtherObjectsToPlace) {
List<objectToPlaceSystem> objectToPlaceSystemList = GKC_Utils.FindObjectsOfTypeAll<objectToPlaceSystem> ();
int objectToPlaceSystemListCount = objectToPlaceSystemList.Count;
for (int i = 0; i < objectToPlaceSystemListCount; i++) {
objectsLocatedList.Add (objectToPlaceSystemList [i]);
}
} else {
Collider [] colliders = Physics.OverlapSphere (transform.position,
radiusToSearchOtherObjectsToPlaceAround,
layerToSearchOtherObjectsToPlaceAround);
if (colliders.Length == 0) {
if (showDebugPrint) {
print ("objects not found on radius");
}
} else {
if (showDebugPrint) {
print ("objects found on radius " + colliders.Length);
}
}
int collidersLength = colliders.Length;
for (int i = 0; i < collidersLength; i++) {
objectToPlaceSystem temporalObjectToPlaceSystem = colliders [i].gameObject.GetComponent<objectToPlaceSystem> ();
if (temporalObjectToPlaceSystem != null) {
objectsLocatedList.Add (temporalObjectToPlaceSystem);
}
}
}
int objectsLocatedListCount = objectsLocatedList.Count;
for (int i = 0; i < objectsLocatedListCount; i++) {
bool objectToPlaceSystemResult = false;
bool canCheckElementResult = false;
if (objectsLocatedList [i].isobjectToPlacedEnabled () &&
!objectsLocatedList [i].isConnectedToOtherObjectToPlace () &&
objectsLocatedList [i] != this) {
if (objectsLocatedList [i].useOtherObjectsToPlaceOnDropNameList) {
canCheckElementResult = checkIfObjectNameIsCompatible (objectsLocatedList [i].getObjectName ());
} else {
if (objectsLocatedList [i].getObjectName ().Equals (otherObjectsToPlaceOnDropName)) {
canCheckElementResult = true;
}
}
}
if (canCheckElementResult) {
float currentDistance = GKC_Utils.distance (transform.position, objectsLocatedList [i].transform.position);
if (maxDistanceToSearchOtherObjectsToPlaceAround == 0 || currentDistance < maxDistanceToSearchPutObjectsSystemsAround) {
if (currentDistance < minDistance) {
objectToPlaceSystemResult = true;
minDistance = currentDistance;
}
}
if (showDebugPrint) {
print ("checking state on " + objectsLocatedList [i].name + " " +
objectToPlaceSystemResult + " " + currentDistance);
}
}
if (showDebugPrint) {
print ("result on " + objectsLocatedList [i].gameObject.name + " " +
otherObjectsToPlaceOnDropName + " " +
objectToPlaceSystemResult + " " +
objectsLocatedList [i].getObjectName ().Equals (otherObjectsToPlaceOnDropName));
}
if (objectToPlaceSystemResult) {
otherObjectToPlaceIndex = i;
}
}
if (otherObjectToPlaceIndex > -1) {
if (showDebugPrint) {
print ("object found, connecting " + objectsLocatedList [otherObjectToPlaceIndex].name);
}
objectsLocatedList [otherObjectToPlaceIndex].setConnectedToOtherObjectToPlaceState (true, this);
} else {
if (showDebugPrint) {
print ("no objects found");
}
}
}
}
public bool checkIfObjectNameIsCompatible (string nameToCheck)
{
if (useOtherObjectsToPlaceOnDropNameList) {
int currentIndex = otherObjectsToPlaceOnDropInfoList.FindIndex (s => s.Name.Equals (nameToCheck));
if (currentIndex > -1) {
return true;
} else {
return false;
}
}
return true;
}
public Transform getCustomPlaceToPutOtherObjectToPlaceTransform (string nameToCheck)
{
if (useOtherObjectsToPlaceOnDropNameList) {
int currentIndex = otherObjectsToPlaceOnDropInfoList.FindIndex (s => s.Name.Equals (nameToCheck));
if (currentIndex > -1) {
return otherObjectsToPlaceOnDropInfoList [currentIndex].customPlaceToPutOtherObjectToPlaceTransform;
}
}
return customPlaceToPutOtherObjectToPlaceTransform;
}
[System.Serializable]
public class otherObjectsToPlaceOnDropInfo
{
public string Name;
public Transform customPlaceToPutOtherObjectToPlaceTransform;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 9cbcceda1ae430e4f9db35bba8eab389
timeCreated: 1539906434
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/Grab Objects/objectToPlaceSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,413 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class outlineObjectSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool useOutlineEnabled = true;
public string shaderOutlineWidthName = "_Outline";
public string shaderOutlineColorName = "_OutlineColor";
[Space]
[Header ("Custom Outline Settings")]
[Space]
public bool useCustomOutlineValues;
public float customOutlineWidth = 0.05f;
public Color customOutlineColor = Color.yellow;
public bool useCustomShader;
public Shader customShader;
public float customActiveDuration = 2;
[Space]
[Header ("Transparency Settings")]
[Space]
public bool useTransparencyActive = true;
public bool transparencyActive;
public bool useCustomTransparencyValues;
public float customAlphaTransparency;
[Space]
[Header ("Others Settings")]
[Space]
public GameObject meshParent;
[Space]
[Space]
public bool ignoreParticles;
public bool ignoreLineRenderer;
[Space]
[Space]
public bool useMeshesToIgnore;
public List<Transform> meshesToIgnore = new List<Transform> ();
[Space]
[Space]
public bool useCustomMeshList;
public List<Transform> customMeshList = new List<Transform> ();
[Space]
[Header ("Debug")]
[Space]
public bool showDebugPrint;
public bool renderElementsStored;
public bool outlineActive;
public bool outlineTemporaryActive;
[Space]
[Header ("Render Parts Debug")]
[Space]
public List<Renderer> rendererParts = new List<Renderer> ();
List<Shader> originalShader = new List<Shader> ();
Shader currentOutlineShader;
float currentOutlineWidht;
Color currentOutlieColor;
List<Transform> objectsToIgnoreChildren = new List<Transform> ();
List<playerController> playerControllerList = new List<playerController> ();
bool meshesToIgnoreConfigured;
int shaderOutlineWidthID = -1;
int shaderOutlineColorID = -1;
Coroutine temporalStateCoroutine;
public void enableCustomOutlineStateTemporaly ()
{
if (gameObject.activeSelf) {
stopUpdateTemporalStateCoroutine ();
temporalStateCoroutine = StartCoroutine (updateTemporalStateCoroutine ());
}
}
public void stopUpdateTemporalStateCoroutine ()
{
if (temporalStateCoroutine != null) {
StopCoroutine (temporalStateCoroutine);
}
}
IEnumerator updateTemporalStateCoroutine ()
{
if (!outlineTemporaryActive) {
enableCustomOutlineState ();
}
outlineTemporaryActive = true;
yield return new WaitForSecondsRealtime (customActiveDuration);
disableCustomOutlineState ();
outlineTemporaryActive = false;
}
public void enableCustomOutlineState ()
{
setOutlineState (true, customShader, customOutlineWidth, customOutlineColor, null);
}
public void disableCustomOutlineState ()
{
setOutlineState (false, customShader, customOutlineWidth, customOutlineColor, null);
}
public void setOutlineState (bool state, Shader shaderToApply, float shaderOutlineWidth,
Color shaderOutlineColor, playerController newPlayerToCheck)
{
if (outlineActive == state) {
return;
}
outlineActive = state;
if (!useOutlineEnabled) {
return;
}
if (showDebugPrint) {
print ("setting outline active state " + outlineActive);
}
if (outlineActive) {
if (useCustomShader) {
shaderToApply = customShader;
}
storeRenderElements ();
if (shaderOutlineWidthID == -1) {
shaderOutlineWidthID = Shader.PropertyToID (shaderOutlineWidthName);
}
if (shaderOutlineColorID == -1) {
shaderOutlineColorID = Shader.PropertyToID (shaderOutlineColorName);
}
int rendererPartsCount = rendererParts.Count;
for (int i = 0; i < rendererPartsCount; i++) {
Renderer currentRenderer = rendererParts [i];
if (currentRenderer != null) {
int materialsLength = currentRenderer.materials.Length;
for (int j = 0; j < materialsLength; j++) {
Material currentMaterial = currentRenderer.materials [j];
currentMaterial.shader = shaderToApply;
if (useCustomOutlineValues) {
currentMaterial.SetFloat (shaderOutlineWidthID, customOutlineWidth);
currentMaterial.SetColor (shaderOutlineColorID, customOutlineColor);
} else {
currentMaterial.SetFloat (shaderOutlineWidthID, shaderOutlineWidth);
currentMaterial.SetColor (shaderOutlineColorID, shaderOutlineColor);
}
}
}
}
currentOutlineShader = shaderToApply;
currentOutlineWidht = shaderOutlineWidth;
currentOutlieColor = shaderOutlineColor;
if (newPlayerToCheck != null && !playerControllerList.Contains (newPlayerToCheck)) {
playerControllerList.Add (newPlayerToCheck);
}
} else {
if (newPlayerToCheck != null) {
if (playerControllerList.Contains (newPlayerToCheck)) {
playerControllerList.Remove (newPlayerToCheck);
}
}
if (playerControllerList.Count == 0) {
int rendererPartsCount = rendererParts.Count;
for (int i = 0; i < rendererPartsCount; i++) {
Renderer currentRenderer = rendererParts [i];
if (currentRenderer != null) {
int materialsLength = currentRenderer.materials.Length;
for (int j = 0; j < materialsLength; j++) {
Material currentMaterial = currentRenderer.materials [j];
currentMaterial.shader = originalShader [i];
}
}
}
}
}
}
public bool isOutlineActive ()
{
return outlineActive;
}
public GameObject getMeshParent ()
{
if (meshParent == null) {
meshParent = gameObject;
}
return meshParent;
}
public void storeRenderElements ()
{
if (meshParent == null) {
meshParent = gameObject;
}
if (useMeshesToIgnore && !meshesToIgnoreConfigured) {
int meshesToIgnoreCount = meshesToIgnore.Count;
for (int i = 0; i < meshesToIgnoreCount; i++) {
Transform currentMeshToIgnore = meshesToIgnore [i];
if (currentMeshToIgnore != null) {
Component[] childrens = currentMeshToIgnore.GetComponentsInChildren (typeof(Transform));
int childrensLength = childrens.Length;
for (int j = 0; j < childrensLength; j++) {
Transform child = childrens [j] as Transform;
objectsToIgnoreChildren.Add (child);
}
}
}
meshesToIgnoreConfigured = true;
}
if (!renderElementsStored) {
renderElementsStored = true;
Component[] components = meshParent.GetComponentsInChildren (typeof(Renderer));
int componentsLength = components.Length;
for (int j = 0; j < componentsLength; j++) {
Renderer child = components [j] as Renderer;
bool addObject = true;
if (useCustomMeshList) {
if (!customMeshList.Contains (child.transform)) {
addObject = false;
}
}
if (addObject) {
if (!ignoreParticles || !child.GetComponent<ParticleSystem> ()) {
if (!ignoreLineRenderer || !child.GetComponent<LineRenderer> ()) {
if (child.material.shader != null) {
if (!useMeshesToIgnore || !checkChildsObjectsToIgnore (child.transform)) {
rendererParts.Add (child);
int materialsLength = child.materials.Length;
for (int i = 0; i < materialsLength; i++) {
originalShader.Add (child.materials [i].shader);
}
}
}
}
}
}
}
}
}
public bool checkChildsObjectsToIgnore (Transform obj)
{
bool value = false;
if (meshesToIgnore.Contains (obj) || objectsToIgnoreChildren.Contains (obj)) {
value = true;
return value;
}
return value;
}
public void disableOutlineAndRemoveUsers ()
{
playerControllerList.Clear ();
setOutlineState (false, null, 0, Color.white, null);
useOutlineEnabled = false;
outlineActive = false;
transparencyActive = false;
useTransparencyActive = false;
}
public void setTransparencyState (bool state, Shader shaderToApply, float alphaTransparency)
{
if (state == transparencyActive) {
return;
}
transparencyActive = state;
if (!useTransparencyActive) {
return;
}
if (showDebugPrint) {
print ("setting transparency active state " + transparencyActive);
}
if (transparencyActive) {
storeRenderElements ();
int rendererPartsCount = rendererParts.Count;
for (int i = 0; i < rendererPartsCount; i++) {
Renderer currentRenderer = rendererParts [i];
if (currentRenderer != null) {
int materialsLength = currentRenderer.materials.Length;
for (int j = 0; j < materialsLength; j++) {
Material currentMaterial = currentRenderer.materials [j];
currentMaterial.shader = shaderToApply;
Color alpha = currentMaterial.color;
if (useCustomTransparencyValues) {
alpha.a = customAlphaTransparency;
} else {
alpha.a = alphaTransparency;
}
currentMaterial.color = alpha;
}
}
}
} else {
if (outlineActive) {
setOutlineState (true, currentOutlineShader, currentOutlineWidht, currentOutlieColor, null);
} else {
int rendererPartsCount = rendererParts.Count;
for (int i = 0; i < rendererPartsCount; i++) {
Renderer currentRenderer = rendererParts [i];
if (currentRenderer != null) {
int materialsLength = currentRenderer.materials.Length;
for (int j = 0; j < materialsLength; j++) {
currentRenderer.materials [j].shader = originalShader [i];
}
}
}
}
}
}
public bool isTransparencyActive ()
{
return transparencyActive;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 17ddab01b84015e4981a3f039ef51d7a
timeCreated: 1538999039
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/Grab Objects/outlineObjectSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,694 @@
using System.Collections;
using System.Collections.Generic;
using GameKitController.Audio;
using UnityEngine;
using UnityEngine.Events;
public class putObjectSystem : MonoBehaviour
{
public string objectName;
public bool putObjectSystemEnabled = true;
public bool ignoreTriggerEnterExitFunctionsEnabled;
public bool useCertainObjectToPlace;
public GameObject certainObjectToPlace;
public string objectNameToPlace;
public bool useObjectNameListToPlace;
public List<string> objectNameListToPlace = new List<string> ();
public Transform placeToPutObject;
public GameObject currentObjectPlaced;
public float placeObjectPositionSpeed;
public float placeObjectRotationSpeed;
public bool useRotationLimit;
public float maxUpRotationAngle = 30;
public float maxForwardRotationAngle = 30;
public bool usePositionLimit;
public float maxPositionDistance;
public bool needsOtherObjectPlacedBefore;
public int numberOfObjectsToPlaceBefore;
public bool disableObjectOnceIsPlaced;
public bool objectInsideTrigger;
public bool objectPlaced;
public bool waitToObjectPlacedToCallEvent;
public objectToPlaceSystem currentObjectToPlaceSystem;
public bool useLimitToCheckIfObjectRemoved;
public float minDistanceToRemoveObject;
public bool checkingIfObjectIsRemoved;
public float minWaitToPutSameObjectAgain = 0.7f;
public bool updateTriggerStateAfterWait;
public UnityEvent objectPlacedEvent;
public UnityEvent objectRemovedEvent;
public bool useSoundEffectOnObjectPlaced;
public AudioClip soundEffectOnObjectPlaced;
public AudioElement onObjectPlacedAudioElement;
public bool useSoundEffectOnObjectRemoved;
public AudioClip soundEffectOnObjectRemoved;
public AudioElement onObjectRemovedAudioElement;
public AudioSource mainAudioSource;
public Collider mainTrigger;
public bool destroyObjectOncePlaced;
public bool objectAdjustedToPlacePosition;
Coroutine placeObjectCoroutine;
int currentNumberObjectsPlaced;
bool objectInCorrectPosition;
bool objectInCorrectRotation;
bool movingObject;
float lastTimeObjectRemoved;
GameObject lastObjectPlaced;
Coroutine pauseCoroutine;
bool cancelPlaceObjectActive;
private void InitializeAudioElements ()
{
if (mainAudioSource != null) {
onObjectPlacedAudioElement.audioSource = mainAudioSource;
onObjectRemovedAudioElement.audioSource = mainAudioSource;
}
if (soundEffectOnObjectPlaced != null) {
onObjectPlacedAudioElement.clip = soundEffectOnObjectPlaced;
}
if (soundEffectOnObjectRemoved != null) {
onObjectRemovedAudioElement.clip = soundEffectOnObjectRemoved;
}
}
private void Start ()
{
InitializeAudioElements ();
}
void Update ()
{
if (objectInsideTrigger) {
if (!objectPlaced) {
if (useRotationLimit) {
float forwardAngle = Vector3.SignedAngle (transform.forward, currentObjectPlaced.transform.forward, transform.up);
float upAngle = Vector3.SignedAngle (transform.up, currentObjectPlaced.transform.up, transform.forward);
if (Mathf.Abs (forwardAngle) > maxForwardRotationAngle || Mathf.Abs (upAngle) > maxUpRotationAngle) {
objectInCorrectRotation = false;
} else {
objectInCorrectRotation = true;
}
}
if (usePositionLimit) {
float currentDistance = GKC_Utils.distance (currentObjectPlaced.transform.position, transform.position);
if (currentDistance <= maxPositionDistance) {
objectInCorrectPosition = true;
} else {
objectInCorrectPosition = false;
}
}
if (useRotationLimit && !objectInCorrectRotation) {
return;
}
if (usePositionLimit && !objectInCorrectPosition) {
return;
}
checkIfCanBePlaced (false);
} else {
if (checkingIfObjectIsRemoved) {
float currentDistance = GKC_Utils.distance (currentObjectPlaced.transform.position, placeToPutObject.position);
if (currentDistance > minDistanceToRemoveObject) {
removeObject ();
} else {
if (!currentObjectToPlaceSystem.isObjectInGrabbedState ()) {
checkIfCanBePlaced (true);
}
}
}
if (destroyObjectOncePlaced) {
if (objectAdjustedToPlacePosition) {
GameObject objectToDestroy = currentObjectPlaced;
removeObject ();
if (objectToDestroy != null) {
Destroy (objectToDestroy);
}
}
}
}
}
}
public void destroyCurrentObjectPlaced ()
{
if (objectAdjustedToPlacePosition) {
GameObject objectToDestroy = currentObjectPlaced;
removeObject ();
if (objectToDestroy != null) {
Destroy (objectToDestroy);
}
}
}
public void OnTriggerEnter (Collider col)
{
if (ignoreTriggerEnterExitFunctionsEnabled) {
return;
}
checkTriggerInfo (true, col.gameObject);
}
public void OnTriggerExit (Collider col)
{
if (ignoreTriggerEnterExitFunctionsEnabled) {
return;
}
checkTriggerInfo (false, col.gameObject);
}
public void checkTriggerInfo (bool isEnter, GameObject objectToCheck)
{
checkObjectToPlace (isEnter, objectToCheck);
}
public void placeObject (GameObject objectToCheck)
{
checkObjectToPlace (true, objectToCheck);
}
void checkObjectToPlace (bool isEnter, GameObject objectToCheck)
{
if (!putObjectSystemEnabled) {
return;
}
if (isEnter) {
if (!objectPlaced) {
objectToCheck = canBeDragged (objectToCheck);
if (objectToCheck != null) {
if (objectToCheck == lastObjectPlaced && Time.time < lastTimeObjectRemoved + minWaitToPutSameObjectAgain) {
if (updateTriggerStateAfterWait) {
pausePutObject ();
}
//print ("same object to soon, pausing");
return;
}
currentObjectPlaced = objectToCheck;
if (!useRotationLimit && !usePositionLimit) {
checkIfCanBePlaced (false);
}
objectInsideTrigger = true;
lastObjectPlaced = currentObjectPlaced;
if (cancelPlaceObjectActive) {
resetPlacedObjectValues ();
}
cancelPlaceObjectActive = false;
}
}
} else {
if (!objectPlaced) {
objectToCheck = canBeDragged (objectToCheck);
if (objectToCheck != null) {
currentObjectPlaced = null;
objectInsideTrigger = false;
lastTimeObjectRemoved = Time.time;
//print ("updating last time");
}
}
}
}
public void checkIfCanBePlaced (bool objectPlacedPreviously)
{
bool objectCanBePlaced = true;
if (needsOtherObjectPlacedBefore) {
if (numberOfObjectsToPlaceBefore != currentNumberObjectsPlaced) {
objectCanBePlaced = false;
}
}
if (objectCanBePlaced) {
Rigidbody mainRigidbody = currentObjectPlaced.GetComponent<Rigidbody> ();
if (mainRigidbody != null) {
mainRigidbody.isKinematic = true;
}
moveObjectToPlace (objectPlacedPreviously);
objectPlaced = true;
checkingIfObjectIsRemoved = false;
}
}
public GameObject canBeDragged (GameObject objectToCheck)
{
if (useCertainObjectToPlace) {
if (objectToCheck == certainObjectToPlace || objectToCheck.transform.IsChildOf (certainObjectToPlace.transform)) {
return objectToCheck;
}
} else {
currentObjectToPlaceSystem = objectToCheck.GetComponent<objectToPlaceSystem> ();
if (currentObjectToPlaceSystem != null) {
if (useObjectNameListToPlace) {
if (objectNameListToPlace.Contains (currentObjectToPlaceSystem.getObjectName ())) {
return objectToCheck;
}
} else {
if (objectNameToPlace == currentObjectToPlaceSystem.getObjectName ()) {
return objectToCheck;
}
}
}
}
return null;
}
public void moveObjectToPlace (bool objectPlacedPreviously)
{
stopMoveObjectToPlaceCoroutine ();
stopPausePutObjectCoroutine ();
placeObjectCoroutine = StartCoroutine (placeObjectIntoPosition (objectPlacedPreviously));
}
public void stopMoveObjectToPlaceCoroutine ()
{
if (placeObjectCoroutine != null) {
StopCoroutine (placeObjectCoroutine);
}
}
IEnumerator placeObjectIntoPosition (bool objectPlacedPreviously)
{
objectAdjustedToPlacePosition = false;
grabbedObjectState currentGrabbedObject = currentObjectPlaced.GetComponent<grabbedObjectState> ();
bool objectCanBePlaced = true;
if (currentGrabbedObject != null) {
objectCanBePlaced = GKC_Utils.checkIfObjectCanBePlaced (currentGrabbedObject.getCurrentHolder (), currentObjectPlaced);
if (!objectCanBePlaced) {
cancelPlaceObjectActive = true;
}
}
currentObjectToPlaceSystem.setAdjustingObjectToPlaceInProcessState (true);
if (objectCanBePlaced) {
bool objectCanCallPlacedEvent = currentObjectToPlaceSystem.canObjectCanCallPlacedEvent ();
if (!objectPlacedPreviously) {
if (useSoundEffectOnObjectPlaced && objectCanCallPlacedEvent) {
playSound (onObjectPlacedAudioElement);
}
}
if (currentGrabbedObject != null) {
GKC_Utils.dropObject (currentGrabbedObject.getCurrentHolder (), currentObjectPlaced);
}
Rigidbody mainRigidbody = currentObjectPlaced.GetComponent<Rigidbody> ();
if (mainRigidbody != null) {
mainRigidbody.isKinematic = true;
}
currentObjectToPlaceSystem.assignPutObjectSystem (this);
currentObjectToPlaceSystem.setObjectPlaceState (true);
currentObjectToPlaceSystem.checkEventOnObjectPlacedStateChanged (true);
if (disableObjectOnceIsPlaced) {
currentObjectToPlaceSystem.setObjectToPlacedEnabledState (false);
grabPhysicalObjectSystem currentGrabPhysicalObjectSystem = currentObjectPlaced.GetComponent<grabPhysicalObjectSystem> ();
if (currentGrabPhysicalObjectSystem != null) {
currentGrabPhysicalObjectSystem.disableGrabPhysicalObject ();
}
}
if (!objectPlacedPreviously) {
if (!waitToObjectPlacedToCallEvent && objectCanCallPlacedEvent) {
bool checkEventResult = false;
if (currentObjectToPlaceSystem.isUseSecondaryObjectToPlaceConnectedEnabled ()) {
//if (currentObjectToPlaceSystem.isSecondaryObjectToPlaceConnected ()) {
// checkEventResult = true;
//}
//if (currentObjectToPlaceSystem.isConnectedToOtherObjectToPlace () ||
// currentObjectToPlaceSystem.secondaryObjectToPlaceSystem.isConnectedToOtherObjectToPlace ()) {
// checkEventResult = true;
//}
bool extremeConnectedResult = false;
currentObjectToPlaceSystem.checkIfExtremeConnected (ref extremeConnectedResult, true, null);
//print ("check extremeConnectedResult on object placed " + extremeConnectedResult);
bool checkNameOnPutObjectSystemToCallEventResult = false;
currentObjectToPlaceSystem.checkNameOnPutObjectSystemToCallEventResult (ref checkNameOnPutObjectSystemToCallEventResult, null);
//print ("checkNameOnPutObjectSystemToCallEventResult " + checkNameOnPutObjectSystemToCallEventResult);
if (extremeConnectedResult && checkNameOnPutObjectSystemToCallEventResult) {
checkEventResult = true;
}
} else {
checkEventResult = true;
}
if (checkEventResult) {
checkEventsOnObjectPlacedOrRemoved (true);
}
}
}
currentObjectToPlaceSystem.checkStateOnExtremesOnObjectPlaced ();
Transform objectTransform = currentObjectPlaced.transform;
objectTransform.SetParent (placeToPutObject);
Vector3 targetPosition = Vector3.zero;
Quaternion targetRotation = Quaternion.identity;
if (currentObjectToPlaceSystem.isUseCustomPlaceToPutObjectTransformActive ()) {
Transform customPlaceToPutObjectTransform = currentObjectToPlaceSystem.getCustomPlaceToPutObjectTransform ();
targetPosition = customPlaceToPutObjectTransform.localPosition;
targetRotation = customPlaceToPutObjectTransform.localRotation;
}
float dist = GKC_Utils.distance (objectTransform.position, placeToPutObject.position);
float duration = dist / placeObjectPositionSpeed;
float t = 0;
float timePassed = 0;
float angleDifference = 0;
float positionDifference = 0;
bool targetReached = false;
while (!targetReached) {
t += Time.deltaTime / duration;
objectTransform.localPosition = Vector3.MoveTowards (objectTransform.localPosition, targetPosition, t);
objectTransform.localRotation = Quaternion.Lerp (objectTransform.localRotation, targetRotation, t);
timePassed += Time.deltaTime;
angleDifference = Quaternion.Angle (objectTransform.localRotation, targetRotation);
positionDifference = GKC_Utils.distance (objectTransform.localPosition, targetPosition);
if (timePassed > 3) {
targetReached = true;
}
if (positionDifference < 0.01f && angleDifference < 0.2f) {
targetReached = true;
}
yield return null;
}
if (!objectPlacedPreviously) {
if (waitToObjectPlacedToCallEvent && objectCanCallPlacedEvent) {
checkEventsOnObjectPlacedOrRemoved (false);
}
}
} else {
stopMoveObjectToPlaceCoroutine ();
resetPlacedObjectValues ();
}
objectAdjustedToPlacePosition = true;
currentObjectToPlaceSystem.setAdjustingObjectToPlaceInProcessState (false);
}
void resetPlacedObjectValues ()
{
objectPlaced = false;
currentObjectToPlaceSystem = null;
currentObjectPlaced = null;
objectInsideTrigger = false;
checkingIfObjectIsRemoved = false;
objectAdjustedToPlacePosition = false;
}
public void removePlacedObject ()
{
if (useLimitToCheckIfObjectRemoved) {
checkingIfObjectIsRemoved = true;
} else {
removeObject ();
}
}
public void dropCurrentObjectPlaced (bool reactivateObjectToUseOnPlaceSystem)
{
if (!putObjectSystemEnabled) {
return;
}
if (currentObjectToPlaceSystem == null) {
return;
}
Rigidbody currentRigidbody = currentObjectPlaced.GetComponent<Rigidbody> ();
if (reactivateObjectToUseOnPlaceSystem) {
currentObjectToPlaceSystem.setObjectToPlacedEnabledState (true);
currentObjectToPlaceSystem.setObjectPlaceState (false);
currentObjectToPlaceSystem.checkEventOnObjectPlacedStateChanged (false);
currentObjectToPlaceSystem.setAdjustingObjectToPlaceInProcessState (false);
}
grabPhysicalObjectSystem currentGrabPhysicalObjectSystem = currentObjectPlaced.GetComponent<grabPhysicalObjectSystem> ();
if (currentGrabPhysicalObjectSystem != null) {
currentGrabPhysicalObjectSystem.setGrabObjectPhysicallyEnabledState (true);
}
removeObject ();
if (currentRigidbody != null) {
currentRigidbody.isKinematic = false;
currentRigidbody.AddForce (placeToPutObject.forward * 10, ForceMode.Impulse);
}
}
public void removeObject ()
{
if (!putObjectSystemEnabled) {
return;
}
if (currentObjectToPlaceSystem == null) {
return;
}
bool objectCanCallRemovedEvent = currentObjectToPlaceSystem.canObjectCanCallRemovedEvent ();
if (objectCanCallRemovedEvent && useSoundEffectOnObjectRemoved) {
playSound (onObjectRemovedAudioElement);
}
stopMoveObjectToPlaceCoroutine ();
objectPlaced = false;
if (objectCanCallRemovedEvent) {
objectRemovedEvent.Invoke ();
}
currentObjectToPlaceSystem = null;
currentObjectPlaced.transform.SetParent (null);
currentObjectPlaced = null;
objectInsideTrigger = false;
checkingIfObjectIsRemoved = false;
objectAdjustedToPlacePosition = false;
}
public void checkEventsOnObjectPlacedOrRemoved (bool state)
{
//print ("checkEventsOnObjectPlacedOrRemoved " + state);
if (state) {
objectPlacedEvent.Invoke ();
} else {
objectRemovedEvent.Invoke ();
}
}
public void disableObjectPlacedFromGrab ()
{
if (currentObjectPlaced != null) {
currentObjectPlaced.tag = "Untagged";
}
}
public void increaseNumberObjectsPlaced ()
{
currentNumberObjectsPlaced++;
}
public void decreaseNumberObjectsPlaced ()
{
currentNumberObjectsPlaced--;
if (currentNumberObjectsPlaced < 0) {
currentNumberObjectsPlaced = 0;
}
}
public void resetNumberObjectsPlaced ()
{
if (placeObjectCoroutine != null) {
StopCoroutine (placeObjectCoroutine);
}
currentNumberObjectsPlaced = 0;
objectPlaced = false;
objectInsideTrigger = false;
objectAdjustedToPlacePosition = false;
}
public void playSound (AudioElement soundToPlay)
{
if (soundToPlay != null) {
AudioPlayer.PlayOneShot (soundToPlay, gameObject);
}
}
public void pausePutObject ()
{
stopPausePutObjectCoroutine ();
pauseCoroutine = StartCoroutine (pausePutObjectCoroutine ());
}
public void stopPausePutObjectCoroutine ()
{
if (pauseCoroutine != null) {
StopCoroutine (pauseCoroutine);
}
}
IEnumerator pausePutObjectCoroutine ()
{
yield return new WaitForSeconds (minWaitToPutSameObjectAgain);
if (mainTrigger == null) {
mainTrigger = GetComponent<Collider> ();
}
if (mainTrigger != null) {
mainTrigger.enabled = false;
mainTrigger.enabled = true;
}
}
public bool isPutObjectSystemEnabled ()
{
return putObjectSystemEnabled;
}
public string getObjectName ()
{
return objectName;
}
public Vector3 getPlaceToPutObjectPosition ()
{
if (placeToPutObject != null) {
return placeToPutObject.position;
}
return transform.position;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: d68299f88bf622b4f9439937be83c179
timeCreated: 1539905847
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/Grab Objects/putObjectSystem.cs
uploadId: 814740