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

View File

@@ -0,0 +1,204 @@
using System.Collections;
using System.Collections.Generic;
using GameKitController.Audio;
using UnityEngine;
using UnityEngine.Events;
public class pianoSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public int keyRotationAmount = 30;
public float keyRotationSpeed = 30;
[TextArea (1, 10)] public string songToPlay;
public float playRate = 0.3f;
public int songLineLength;
public float songLineDelay;
[Space]
[Header ("Key Info List Settings")]
[Space]
public List<keyInfo> keyInfoList = new List<keyInfo> ();
[Space]
[Header ("Debug")]
[Space]
public bool showDebugPrint;
public bool usingPiano;
[Space]
[Header ("Events Settings")]
[Space]
public bool useEventWhenAutoPlaySongEnds;
public UnityEvent eventWhenAutoPlaySongEnds;
[Space]
[Header ("Components")]
[Space]
public AudioSource mainAudioSource;
Coroutine playSongCoroutine;
bool mainAudioSourceLocated;
private void Start ()
{
if (mainAudioSource == null) {
mainAudioSource = GetComponent<AudioSource> ();
}
foreach (var keyInfo in keyInfoList) {
if (mainAudioSource != null) {
keyInfo.keySoundAudioElement.audioSource = mainAudioSource;
}
if (keyInfo.keySound != null) {
keyInfo.keySoundAudioElement.clip = keyInfo.keySound;
}
}
}
public void autoPlaySong ()
{
playSong (songToPlay);
}
public void playSong (string songNotes)
{
if (playSongCoroutine != null) {
StopCoroutine (playSongCoroutine);
}
playSongCoroutine = StartCoroutine (autoPlaySongCoroutine (songNotes));
}
IEnumerator autoPlaySongCoroutine (string songNotes)
{
yield return new WaitForSeconds (1);
int currentNumberOfNotes = 0;
string[] notes = songNotes.Split (' ', '\n');
if (showDebugPrint) {
print (notes.Length);
}
foreach (string letter in notes) {
if (showDebugPrint) {
print (letter);
}
checkPressedKey (letter);
currentNumberOfNotes++;
yield return new WaitForSeconds (playRate);
if (currentNumberOfNotes % songLineLength == 0) {
yield return new WaitForSeconds (songLineDelay);
}
}
if (useEventWhenAutoPlaySongEnds) {
if (eventWhenAutoPlaySongEnds.GetPersistentEventCount () > 0) {
eventWhenAutoPlaySongEnds.Invoke ();
}
}
yield return null;
}
public void checkPressedKey (string keyName)
{
if (!usingPiano) {
return;
}
for (int i = 0; i < keyInfoList.Count; i++) {
if (keyInfoList [i].keyName.Equals (keyName)) {
playSound (keyInfoList [i].keySoundAudioElement);
rotatePressedKey (keyInfoList [i]);
}
}
}
public void rotatePressedKey (keyInfo currentKeyInfo)
{
if (currentKeyInfo.keyPressCoroutine != null) {
StopCoroutine (currentKeyInfo.keyPressCoroutine);
}
currentKeyInfo.keyPressCoroutine = StartCoroutine (rotatePressedKeyCoroutine (currentKeyInfo));
}
IEnumerator rotatePressedKeyCoroutine (keyInfo currentKeyInfo)
{
Quaternion targetRotation = Quaternion.Euler (new Vector3 (-keyRotationAmount, 0, 0));
while (currentKeyInfo.keyTransform.localRotation != targetRotation) {
currentKeyInfo.keyTransform.localRotation = Quaternion.Slerp (currentKeyInfo.keyTransform.localRotation, targetRotation, Time.deltaTime * keyRotationSpeed);
yield return null;
}
targetRotation = Quaternion.identity;
while (currentKeyInfo.keyTransform.localRotation != targetRotation) {
currentKeyInfo.keyTransform.localRotation = Quaternion.Slerp (currentKeyInfo.keyTransform.localRotation, targetRotation, Time.deltaTime * keyRotationSpeed);
yield return null;
}
}
public void playSound (AudioElement clipSound)
{
if (clipSound != null) {
if (mainAudioSource != null) {
GKC_Utils.checkAudioSourcePitch (mainAudioSource);
}
AudioPlayer.PlayOneShot (clipSound, gameObject);
}
}
public void startOrStopUsingPiano ()
{
setUsingPianoState (!usingPiano);
}
public void setUsingPianoState (bool state)
{
usingPiano = state;
if (usingPiano) {
if (!mainAudioSourceLocated) {
//mainAudioSource = GetComponent<AudioSource> ();
mainAudioSourceLocated = mainAudioSource != null;
}
}
}
[System.Serializable]
public class keyInfo
{
public string keyName;
public AudioClip keySound;
public AudioElement keySoundAudioElement;
public Transform keyTransform;
public Coroutine keyPressCoroutine;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 02fec0e2760aaf9448386b7264f1df35
timeCreated: 1528121809
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/Puzzles/pianoSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,221 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class placeObjectSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public GameObject objectToPlace;
public bool needsOtherObjectPlacedBefore;
public int numberOfObjectsToPlaceBefore;
[Space]
[Header ("Placement Settings")]
[Space]
public bool useRotationLimit;
public float maxUpRotationAngle = 30;
public float maxForwardRotationAngle = 30;
public bool usePositionLimit;
public float maxPositionDistance;
public float placeObjectPositionSpeed;
public float placeObjectRotationSpeed;
[Space]
[Header ("Debug")]
[Space]
public bool objectPlaced;
public bool objectInsideTrigger;
public bool movingObject;
[Space]
public int currentNumberObjectsPlaced;
public bool objectInCorrectPosition;
public bool objectInCorrectRotation;
[Space]
[Header ("Event Settings")]
[Space]
public UnityEvent objectPlacedEvent;
[Space]
[Header ("Components")]
[Space]
public puzzleSystem puzzleManager;
Coroutine placeObjectCoroutine;
void Update ()
{
if (objectInsideTrigger && !objectPlaced) {
if (useRotationLimit) {
float forwardAngle = Vector3.SignedAngle (transform.forward, objectToPlace.transform.forward, transform.up);
float upAngle = Vector3.SignedAngle (transform.up, objectToPlace.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 (objectToPlace.transform.position, transform.position);
if (currentDistance <= maxPositionDistance) {
objectInCorrectPosition = true;
} else {
objectInCorrectPosition = false;
}
}
if (useRotationLimit && !objectInCorrectRotation) {
return;
}
if (usePositionLimit && !objectInCorrectPosition) {
return;
}
checkIfCanBePlaced ();
}
}
public void OnTriggerEnter (Collider col)
{
if (!objectPlaced) {
GameObject objectToCheck = canBeDragged (col.gameObject);
if (objectToCheck != null) {
if (!useRotationLimit && !usePositionLimit) {
checkIfCanBePlaced ();
}
objectInsideTrigger = true;
}
}
}
public void OnTriggerExit (Collider col)
{
if (!objectPlaced) {
GameObject objectToCheck = canBeDragged (col.gameObject);
if (objectToCheck != null) {
objectInsideTrigger = false;
}
}
}
public void checkIfCanBePlaced ()
{
bool objectCanBePlaced = true;
if (needsOtherObjectPlacedBefore) {
if (numberOfObjectsToPlaceBefore != currentNumberObjectsPlaced) {
objectCanBePlaced = false;
}
}
if (objectCanBePlaced) {
puzzleManager.checkIfObjectGrabbed (objectToPlace);
Rigidbody mainRigidbody = objectToPlace.GetComponent<Rigidbody> ();
if (mainRigidbody != null) {
mainRigidbody.isKinematic = true;
}
moveObjectToPlace ();
objectPlaced = true;
}
}
public GameObject canBeDragged (GameObject objectToCheck)
{
if (objectToPlace == objectToCheck) {
return objectToCheck;
}
if (objectToCheck.transform.IsChildOf (objectToPlace.transform)) {
return objectToPlace;
}
return null;
}
public void moveObjectToPlace ()
{
if (placeObjectCoroutine != null) {
StopCoroutine (placeObjectCoroutine);
}
movingObject = false;
placeObjectCoroutine = StartCoroutine (placeObjectIntoPosition ());
}
IEnumerator placeObjectIntoPosition ()
{
movingObject = true;
float dist = GKC_Utils.distance (objectToPlace.transform.position, transform.position);
float duration = dist / placeObjectPositionSpeed;
float t = 0;
float timePassed = 0;
while ((t < 1 || objectToPlace.transform.position != transform.position || objectToPlace.transform.rotation != transform.rotation) && timePassed < 3) {
t += Time.deltaTime / duration;
objectToPlace.transform.position = Vector3.MoveTowards (objectToPlace.transform.position, transform.position, t);
objectToPlace.transform.rotation = Quaternion.Slerp (objectToPlace.transform.rotation, transform.rotation, t);
timePassed += Time.deltaTime;
yield return null;
}
if (objectPlacedEvent.GetPersistentEventCount () > 0) {
objectPlacedEvent.Invoke ();
}
movingObject = false;
}
public void increaseNumberObjectsPlaced ()
{
currentNumberObjectsPlaced++;
}
public void resetNumberObjectsPlaced ()
{
if (placeObjectCoroutine != null) {
StopCoroutine (placeObjectCoroutine);
}
movingObject = false;
currentNumberObjectsPlaced = 0;
objectPlaced = false;
objectInsideTrigger = false;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 05fa75789d9f9b0468f7169c0832fa47
timeCreated: 1526075844
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/Puzzles/placeObjectSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,216 @@
using System.Collections;
using System.Collections.Generic;
using GameKitController.Audio;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
public class pressObjectsInOrderSystem : MonoBehaviour
{
public List<positionInfo> positionInfoList = new List<positionInfo> ();
public bool allPositionsPressed;
public int correctPressedIndex;
public bool useIncorrectOrderSound;
public AudioClip incorrectOrderSound;
public AudioElement incorrectOrderAudioElement;
public bool usingPressedObjectSystem;
public LayerMask pressObjectsLayer;
public bool pressObjectsWhileMousePressed;
public UnityEvent allPositionsPressedEvent;
public Camera mainCamera;
public AudioSource mainAudioSource;
bool touchPlatform;
Touch currentTouch;
bool touching;
GameObject currentObjectPressed;
GameObject previousObjectPressed;
RaycastHit hit;
bool mainCameraLocated;
Ray ray;
Coroutine updateCoroutine;
private void Start ()
{
if (mainAudioSource == null) {
mainAudioSource = GetComponent<AudioSource> ();
}
if (mainAudioSource != null) {
incorrectOrderAudioElement.audioSource = mainAudioSource;
}
if (incorrectOrderSound != null) {
incorrectOrderAudioElement.clip = incorrectOrderSound;
}
}
IEnumerator mainUpdateCoroutine ()
{
var waitTime = new WaitForFixedUpdate ();
while (true) {
if (usingPressedObjectSystem && pressObjectsWhileMousePressed && mainCameraLocated) {
//meter lo de touch aqui para llamar mientras se tenga pulsado el raton, distinguiendo que sea un nuevo objeto
int touchCount = Input.touchCount;
if (!touchPlatform) {
touchCount++;
}
for (int i = 0; i < touchCount; i++) {
if (!touchPlatform) {
currentTouch = touchJoystick.convertMouseIntoFinger ();
} else {
currentTouch = Input.GetTouch (i);
}
if (currentTouch.phase == TouchPhase.Began) {
touching = true;
ray = mainCamera.ScreenPointToRay (currentTouch.position);
if (Physics.Raycast (ray, out hit, Mathf.Infinity, pressObjectsLayer)) {
currentObjectPressed = hit.collider.gameObject;
if (currentObjectPressed != previousObjectPressed) {
previousObjectPressed = currentObjectPressed;
}
}
}
if ((currentTouch.phase == TouchPhase.Stationary || currentTouch.phase == TouchPhase.Moved) && touching) {
ray = mainCamera.ScreenPointToRay (currentTouch.position);
if (Physics.Raycast (ray, out hit, Mathf.Infinity, pressObjectsLayer)) {
currentObjectPressed = hit.collider.gameObject;
if (currentObjectPressed != previousObjectPressed) {
previousObjectPressed = currentObjectPressed;
EventTrigger currentEventTrigger = currentObjectPressed.GetComponent<EventTrigger> ();
if (currentEventTrigger != null) {
var pointer = new PointerEventData (EventSystem.current);
ExecuteEvents.Execute (currentObjectPressed, pointer, ExecuteEvents.pointerEnterHandler);
ExecuteEvents.Execute (currentObjectPressed, pointer, ExecuteEvents.pointerDownHandler);
}
}
}
}
if (currentTouch.phase == TouchPhase.Ended) {
touching = false;
}
}
}
yield return waitTime;
}
}
public void checkPressedPosition (string positionName)
{
if (!usingPressedObjectSystem) {
return;
}
if (allPositionsPressed) {
return;
}
if (correctPressedIndex < positionInfoList.Count) {
positionInfo currentPosition = positionInfoList [correctPressedIndex];
if (currentPosition.positionName.Equals (positionName)) {
currentPosition.positionActive = true;
if (currentPosition.usePositionEvent) {
if (currentPosition.positionEvent.GetPersistentEventCount () > 0) {
currentPosition.positionEvent.Invoke ();
}
}
correctPressedIndex++;
if (correctPressedIndex == positionInfoList.Count) {
if (allPositionsPressedEvent.GetPersistentEventCount () > 0) {
allPositionsPressedEvent.Invoke ();
}
allPositionsPressed = true;
}
} else {
resetPressedObjects ();
if (useIncorrectOrderSound) {
if (incorrectOrderAudioElement != null) {
AudioPlayer.PlayOneShot (incorrectOrderAudioElement, gameObject);
}
}
}
}
}
public void resetPressedObjects ()
{
correctPressedIndex = 0;
for (int i = 0; i < positionInfoList.Count; i++) {
positionInfoList [i].positionActive = false;
}
}
public void startOrStopPressedObjectSystem ()
{
setUsingPressedObjectSystemState (!usingPressedObjectSystem);
}
public void setUsingPressedObjectSystemState (bool state)
{
usingPressedObjectSystem = state;
stopUpdateCoroutine ();
if (usingPressedObjectSystem) {
updateCoroutine = StartCoroutine (mainUpdateCoroutine ());
touchPlatform = touchJoystick.checkTouchPlatform ();
if (!mainCameraLocated) {
mainCamera = GKC_Utils.findMainPlayerCameraComponentOnScene ();
if (mainCamera != null) {
mainCameraLocated = true;
}
}
}
}
public void stopUpdateCoroutine ()
{
if (updateCoroutine != null) {
StopCoroutine (updateCoroutine);
}
}
[System.Serializable]
public class positionInfo
{
public string positionName;
public bool usePositionEvent;
public UnityEvent positionEvent;
public bool positionActive;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 766030f5d5a02184c940b015ee76331c
timeCreated: 1528120455
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/Puzzles/pressObjectsInOrderSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,806 @@
using System.Collections;
using System.Collections.Generic;
using GameKitController.Audio;
using UnityEngine;
using UnityEngine.Events;
public class puzzleSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool respawnDragableElements;
public bool respawnDragableElementsInOriginalPosition;
public Transform respawnPosition;
public float dragVelocity = 8;
public LayerMask layer;
public float maxRaycastDistance;
[Space]
public bool checkIfObjectsToFarFromPuzzleZone;
public float maxDistanceFromPuzzleZone;
[Space]
public float changeHoldDistanceSpeed = 2;
public bool useColliderMaterialWhileGrabbed;
public PhysicsMaterial grabbedColliderMaterial;
[Space]
[Header ("Dragable Elements Settings")]
[Space]
public List<GameObject> dragableElements = new List<GameObject> ();
[Space]
[Header ("Object ROtation Settings")]
[Space]
public bool freezeRotationWhenGrabbed;
public bool objectCanBeRotated;
public float rotateSpeed;
public bool horizontalRotationEnabled = true;
public bool verticalRotationEnabled = true;
public bool rotateToCameraInFixedPosition;
public float rotationSpeed;
[Space]
[Header ("Puzzle Settings")]
[Space]
public bool resetObjectsWhenStopUse;
public bool canResetObjectsWhileUsing;
public int numberObjectsToPlace;
public bool disableObjectActionAfterResolve;
public bool disableObjectTriggerAfterResolve;
public float waitDelayToStopUsePuzzleAfterResolve;
[Space]
[Header ("Camera Rotation Settings")]
[Space]
public bool rotateAroundPointEnabled;
public float rotateAroundPointSpeed;
public Transform rotationPointPivot;
public Transform rotationPointCamera;
public Transform cameraPosition;
public bool useVerticalRotationLimit;
public bool useHorizontalRotationLimit;
public Vector2 verticalRotationLimit = new Vector2 (-90, 90);
public Vector2 horizontalRotationLimit = new Vector2 (-90, 90);
[Space]
[Header ("Action Screen Settings")]
[Space]
public bool activateActionScreen = true;
public string actionScreenName = "Use Puzzle System";
public bool useMeshTextForClues;
public GameObject meshTextGameObject;
[Space]
[Header ("Sound Settings")]
[Space]
public bool usePuzzleSolvedSound;
public AudioClip puzzleSolvedSound;
public AudioElement puzzleSolvedAudioElement;
[Space]
[Header ("Debug")]
[Space]
public bool showDebugPrint;
public bool puzzleSolved;
public bool usingPuzzle;
public int currentNumberObjectsPlaced;
public bool touching;
public bool movingObject;
public GameObject currentGrabbedObject;
[Space]
[Header ("Events Settings")]
[Space]
public bool useEventOnResetPuzzle;
public UnityEvent resetPuzzleEvent;
public UnityEvent puzzleSolvedEvent;
public bool useEventAfterResolveDelay;
public UnityEvent eventAfterResolveDelay;
[Space]
[Header ("Components")]
[Space]
public electronicDevice electronicDeviceManager;
public deviceStringAction deviceStringActionManager;
public AudioSource mainAudioSource;
public Collider mainCollider;
[Space]
[Header ("Gizmo Settings")]
[Space]
public bool showGizmo;
public Color gizmoColor;
public float gizmoRadius = 0.1f;
public float gizmoArrowLength = 1;
public float gizmoArrowLineLength = 2.5f;
public float gizmoArrowAngle = 20;
public Color gizmoArrowColor = Color.white;
Vector3 respawnPositionValue;
GameObject currentDragableElement;
playerInputManager playerInput;
GameObject currentPlayer;
bool touchPlatform;
Touch currentTouch;
Rigidbody currentGrabbedObjectRigidbody;
Camera mainCamera;
Transform mainCameraTransform;
RaycastHit hit;
float currentDistanceGrabbedObject;
Vector3 touchPosition;
Vector3 nextPosition;
Vector3 currentPosition;
bool rotatingObject;
bool increaseHoldObjectDistance;
bool decreaseHoldObjectDistance;
Quaternion originalRotationPointPivotRotation;
Quaternion oriinalRotationPointCameraRotation;
Collider grabbedObjectCollider;
PhysicsMaterial originalGrabbedColliderMaterial;
Vector2 lookAngle;
float lastTimeMouseWheelUsed;
bool mouseWheelUsedPreviously;
List<grabableObjectsInfo> grabableObjectsInfoList = new List<grabableObjectsInfo> ();
Coroutine resetObjectRotationCoroutine;
puzzleSystemPlayerManagement puzzleSystemPlayerManager;
Vector2 axisValues;
private void InitializeAudioElements ()
{
if (mainAudioSource == null) {
mainAudioSource = GetComponent<AudioSource> ();
}
if (mainAudioSource != null) {
puzzleSolvedAudioElement.audioSource = mainAudioSource;
}
if (puzzleSolvedSound != null) {
puzzleSolvedAudioElement.clip = puzzleSolvedSound;
}
}
void Start ()
{
if (electronicDeviceManager == null) {
electronicDeviceManager = GetComponent<electronicDevice> ();
}
touchPlatform = touchJoystick.checkTouchPlatform ();
if (resetObjectsWhenStopUse) {
for (int i = 0; i < dragableElements.Count; i++) {
grabableObjectsInfo newGrabableObjectsInfo = new grabableObjectsInfo ();
newGrabableObjectsInfo.grabableGameObject = dragableElements [i];
newGrabableObjectsInfo.grabableTransform = dragableElements [i].transform;
newGrabableObjectsInfo.originalPosition = dragableElements [i].transform.position;
newGrabableObjectsInfo.originalRotation = dragableElements [i].transform.rotation;
grabableObjectsInfoList.Add (newGrabableObjectsInfo);
}
}
originalRotationPointPivotRotation = rotationPointPivot.localRotation;
oriinalRotationPointCameraRotation = rotationPointCamera.localRotation;
if (deviceStringActionManager == null) {
deviceStringActionManager = GetComponent<deviceStringAction> ();
}
InitializeAudioElements ();
if (respawnPosition != null) {
respawnPositionValue = respawnPosition.position;
}
}
void Update ()
{
if (usingPuzzle) {
int touchCount = Input.touchCount;
if (!touchPlatform) {
touchCount++;
}
for (int i = 0; i < touchCount; i++) {
if (!touchPlatform) {
currentTouch = touchJoystick.convertMouseIntoFinger ();
} else {
currentTouch = Input.GetTouch (i);
}
if (currentTouch.phase == TouchPhase.Began && !touching) {
Ray ray = mainCamera.ScreenPointToRay (currentTouch.position);
if (Physics.Raycast (ray, out hit, maxRaycastDistance, layer)) {
GameObject objectToCheck = canBeDragged (hit.collider.gameObject);
if (objectToCheck != null) {
touching = true;
currentGrabbedObject = objectToCheck;
currentGrabbedObjectRigidbody = currentGrabbedObject.GetComponent<Rigidbody> ();
currentGrabbedObjectRigidbody.linearVelocity = Vector3.zero;
currentDistanceGrabbedObject = mainCameraTransform.InverseTransformDirection (currentGrabbedObject.transform.position - mainCameraTransform.position).z;
grabbedObjectCollider = currentGrabbedObject.GetComponent<Collider> ();
if (freezeRotationWhenGrabbed) {
currentGrabbedObjectRigidbody.freezeRotation = true;
}
if (useColliderMaterialWhileGrabbed && grabbedObjectCollider != null) {
originalGrabbedColliderMaterial = grabbedObjectCollider.material;
grabbedObjectCollider.material = grabbedColliderMaterial;
}
if (showDebugPrint) {
print ("object detected " + objectToCheck.name);
}
} else {
if (showDebugPrint) {
print ("object not detected ");
}
}
}
}
if ((currentTouch.phase == TouchPhase.Stationary || currentTouch.phase == TouchPhase.Moved) && currentGrabbedObject != null) {
movingObject = true;
touchPosition = mainCamera.ScreenToWorldPoint (new Vector3 (currentTouch.position.x, currentTouch.position.y, currentDistanceGrabbedObject));
nextPosition = touchPosition;
currentPosition = currentGrabbedObject.transform.position;
currentGrabbedObjectRigidbody.linearVelocity = (nextPosition - currentPosition) * dragVelocity;
if (rotatingObject) {
if (horizontalRotationEnabled) {
currentGrabbedObject.transform.Rotate (0, -rotateSpeed * playerInput.getPlayerMovementAxis ().x, 0);
}
if (verticalRotationEnabled) {
currentGrabbedObject.transform.Rotate (rotateSpeed * playerInput.getPlayerMovementAxis ().y, 0, 0);
}
if (showDebugPrint) {
print ("rotating object");
}
} else {
if (rotateToCameraInFixedPosition) {
Quaternion direction = Quaternion.LookRotation (mainCameraTransform.forward);
currentGrabbedObject.transform.rotation = Quaternion.Slerp (currentGrabbedObject.transform.rotation, direction, Time.deltaTime * rotationSpeed);
}
}
if (mouseWheelUsedPreviously && Time.time > lastTimeMouseWheelUsed + 0.1f) {
increaseHoldObjectDistance = false;
decreaseHoldObjectDistance = false;
mouseWheelUsedPreviously = false;
}
if (increaseHoldObjectDistance) {
currentDistanceGrabbedObject += Time.deltaTime * changeHoldDistanceSpeed;
}
if (decreaseHoldObjectDistance) {
currentDistanceGrabbedObject -= Time.deltaTime * changeHoldDistanceSpeed;
}
if (showDebugPrint) {
print ("moving object");
}
}
if (currentTouch.phase == TouchPhase.Ended && touching) {
dropObject ();
}
}
if (rotateAroundPointEnabled && !rotatingObject) {
axisValues = playerInput.getPlayerMovementAxis ();
lookAngle.x -= axisValues.x * rotateAroundPointSpeed;
lookAngle.y += axisValues.y * rotateAroundPointSpeed;
if (useVerticalRotationLimit) {
lookAngle.y = Mathf.Clamp (lookAngle.y, verticalRotationLimit.x, verticalRotationLimit.y);
} else {
if (lookAngle.y > 360 || lookAngle.y < -360) {
lookAngle.y = 0;
}
}
if (useHorizontalRotationLimit) {
lookAngle.x = Mathf.Clamp (lookAngle.x, horizontalRotationLimit.x, horizontalRotationLimit.y);
} else {
if (lookAngle.x > 360 || lookAngle.x < -360) {
lookAngle.x = 0;
}
}
rotationPointPivot.localRotation = Quaternion.Euler (0, lookAngle.x, 0);
rotationPointCamera.localRotation = Quaternion.Euler (lookAngle.y, 0, 0);
}
if (checkIfObjectsToFarFromPuzzleZone) {
int grabableObjectsInfoListCount = grabableObjectsInfoList.Count;
for (int i = 0; i < grabableObjectsInfoListCount; i++) {
float currentDistance = GKC_Utils.distance (grabableObjectsInfoList [i].grabableTransform.position, respawnPositionValue);
if (currentDistance > maxDistanceFromPuzzleZone) {
if (respawnDragableElements) {
if (showDebugPrint) {
print ("object too far from zone " + grabableObjectsInfoList [i].grabableGameObject.name);
}
setObjectBackToPuzzleZone (grabableObjectsInfoList [i].grabableGameObject);
}
}
}
}
}
}
public void resetObjects ()
{
for (int i = 0; i < grabableObjectsInfoList.Count; i++) {
grabableObjectsInfoList [i].grabableTransform.position = grabableObjectsInfoList [i].originalPosition;
grabableObjectsInfoList [i].grabableTransform.rotation = grabableObjectsInfoList [i].originalRotation;
Rigidbody currentRigidbody = grabableObjectsInfoList [i].grabableGameObject.GetComponent<Rigidbody> ();
if (currentRigidbody != null) {
currentRigidbody.isKinematic = false;
}
}
resetNumberObjectsPlaced ();
if (useEventOnResetPuzzle) {
if (resetPuzzleEvent.GetPersistentEventCount () > 0) {
resetPuzzleEvent.Invoke ();
}
}
}
public void OnTriggerExit (Collider col)
{
if (respawnDragableElements && respawnPosition != null) {
if (showDebugPrint) {
print ("checking if object exits trigger " + col.gameObject.name);
}
setObjectBackToPuzzleZone (col.gameObject);
}
}
void setObjectBackToPuzzleZone (GameObject newObject)
{
GameObject objectToCheck = canBeDragged (newObject);
if (objectToCheck != null) {
if (showDebugPrint) {
print ("checking if object exits trigger " + objectToCheck.name + " " + newObject.name);
}
currentDragableElement = objectToCheck;
if (currentDragableElement == currentGrabbedObject) {
dropObject ();
}
Component [] ColliderList = currentDragableElement.GetComponentsInChildren (typeof (Collider));
foreach (Collider child in ColliderList) {
if (!child.isTrigger) {
child.enabled = false;
}
}
Rigidbody currentRigidbody = currentDragableElement.GetComponent<Rigidbody> ();
if (currentRigidbody != null) {
currentRigidbody.isKinematic = true;
}
if (respawnDragableElementsInOriginalPosition) {
for (int i = 0; i < grabableObjectsInfoList.Count; i++) {
if (grabableObjectsInfoList [i].grabableGameObject == currentDragableElement) {
grabableObjectsInfoList [i].grabableTransform.position = grabableObjectsInfoList [i].originalPosition;
grabableObjectsInfoList [i].grabableTransform.rotation = grabableObjectsInfoList [i].originalRotation;
}
}
} else {
currentDragableElement.transform.position = respawnPosition.position;
currentDragableElement.transform.rotation = respawnPosition.rotation;
}
if (currentRigidbody != null) {
currentRigidbody.isKinematic = false;
}
foreach (Collider child in ColliderList) {
if (!child.isTrigger) {
child.enabled = true;
}
}
}
}
public GameObject canBeDragged (GameObject objectToCheck)
{
if (dragableElements.Contains (objectToCheck)) {
return objectToCheck;
}
for (int i = 0; i < dragableElements.Count; i++) {
if (objectToCheck.transform.IsChildOf (dragableElements [i].transform)) {
return dragableElements [i];
}
}
return null;
}
public void dropObject ()
{
if (resetObjectRotationCoroutine != null) {
StopCoroutine (resetObjectRotationCoroutine);
}
currentGrabbedObjectRigidbody.freezeRotation = false;
if (useColliderMaterialWhileGrabbed && grabbedObjectCollider != null) {
grabbedObjectCollider.material = originalGrabbedColliderMaterial;
}
touching = false;
movingObject = false;
currentGrabbedObject = null;
rotatingObject = false;
increaseHoldObjectDistance = false;
decreaseHoldObjectDistance = false;
currentGrabbedObjectRigidbody = null;
}
public void checkIfObjectGrabbed (GameObject objectToCheck)
{
if (currentGrabbedObject == objectToCheck) {
dropObject ();
}
}
public void startOrStopPuzzle ()
{
usingPuzzle = !usingPuzzle;
if (usingPuzzle) {
setCurrentPlayer (electronicDeviceManager.getCurrentPlayer ());
} else {
if (resetObjectsWhenStopUse && !puzzleSolved) {
resetObjects ();
}
rotationPointPivot.localRotation = originalRotationPointPivotRotation;
rotationPointCamera.localRotation = oriinalRotationPointCameraRotation;
lookAngle = Vector3.zero;
}
if (puzzleSystemPlayerManager != null) {
puzzleSystemPlayerManager.setUsingPuzzleState (usingPuzzle);
}
if (activateActionScreen) {
playerInput.enableOrDisableActionScreen (actionScreenName, usingPuzzle);
}
if (useMeshTextForClues) {
if (meshTextGameObject != null) {
meshTextGameObject.SetActive (usingPuzzle);
}
}
setMainColliderTriggerEnabledState (!usingPuzzle);
}
public void setCurrentPlayer (GameObject player)
{
currentPlayer = player;
if (currentPlayer != null) {
playerComponentsManager mainPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
puzzleSystemPlayerManager = mainPlayerComponentsManager.getPuzzleSystemPlayerManagement ();
mainCamera = mainPlayerComponentsManager.getPlayerCamera ().getMainCamera ();
mainCameraTransform = mainCamera.transform;
playerInput = mainPlayerComponentsManager.getPlayerInputManager ();
puzzleSystemPlayerManager.setcurrentPuzzleSystem (this);
}
}
public void increaseNumberObjectsPlaced ()
{
currentNumberObjectsPlaced++;
if (currentNumberObjectsPlaced == numberObjectsToPlace) {
solvePuzzle ();
}
}
public void resetNumberObjectsPlaced ()
{
currentNumberObjectsPlaced = 0;
}
public void solvePuzzle ()
{
if (puzzleSolvedEvent.GetPersistentEventCount () > 0) {
puzzleSolvedEvent.Invoke ();
}
puzzleSolved = true;
if (disableObjectActionAfterResolve) {
deviceStringActionManager.showIcon = false;
removeDeviceFromList ();
StartCoroutine (waitingAfterUnlock ());
}
if (disableObjectTriggerAfterResolve) {
setMainColliderTriggerEnabledState (false);
}
if (usePuzzleSolvedSound) {
playSound (puzzleSolvedAudioElement);
}
}
public void setMainColliderTriggerEnabledState (bool state)
{
if (mainCollider != null) {
if (disableObjectTriggerAfterResolve) {
if (puzzleSolved) {
if (state) {
return;
}
}
}
mainCollider.enabled = state;
}
}
public void resetCurrentObjectRotation ()
{
if (resetObjectRotationCoroutine != null) {
StopCoroutine (resetObjectRotationCoroutine);
}
resetObjectRotationCoroutine = StartCoroutine (resetCurrenObjectRotationCoroutine ());
}
IEnumerator resetCurrenObjectRotationCoroutine ()
{
if (showDebugPrint) {
print ("reset current object rotation start");
}
GameObject objectToRotate = currentGrabbedObject;
Quaternion targetRotation = Quaternion.identity;
for (int i = 0; i < grabableObjectsInfoList.Count; i++) {
if (grabableObjectsInfoList [i].grabableGameObject == objectToRotate) {
targetRotation = grabableObjectsInfoList [i].originalRotation;
}
}
float timePassed = 0;
while (objectToRotate.transform.rotation != targetRotation || timePassed < 3) {
objectToRotate.transform.rotation = Quaternion.Slerp (objectToRotate.transform.rotation, targetRotation, Time.deltaTime * rotateSpeed);
timePassed += Time.deltaTime;
yield return null;
}
if (showDebugPrint) {
print ("reset current object rotation end");
}
}
public void removeDeviceFromList ()
{
if (currentPlayer != null) {
currentPlayer.GetComponent<usingDevicesSystem> ().removeDeviceFromListExternalCall (gameObject);
}
}
public void playSound (AudioElement soundEffect)
{
if (soundEffect != null) {
if (mainAudioSource != null)
GKC_Utils.checkAudioSourcePitch (mainAudioSource);
AudioPlayer.PlayOneShot (soundEffect, gameObject);
}
}
IEnumerator waitingAfterUnlock ()
{
yield return new WaitForSeconds (waitDelayToStopUsePuzzleAfterResolve);
if (useEventAfterResolveDelay) {
eventAfterResolveDelay.Invoke ();
}
electronicDeviceManager.stopUsindDevice ();
yield return null;
}
//CALL INPUT FUNCTIONS
public void inputSetRotateObjectState (bool state)
{
if (usingPuzzle && objectCanBeRotated && currentGrabbedObjectRigidbody != null) {
if (state) {
rotatingObject = true;
currentGrabbedObjectRigidbody.freezeRotation = true;
} else {
rotatingObject = false;
currentGrabbedObjectRigidbody.freezeRotation = false;
}
}
}
public void inputIncreaseObjectHolDistanceByButton (bool state)
{
if (usingPuzzle && movingObject) {
if (state) {
increaseHoldObjectDistance = true;
} else {
increaseHoldObjectDistance = false;
}
}
}
public void inputDecreaseObjectHolDistanceByButton (bool state)
{
if (usingPuzzle && movingObject) {
if (state) {
decreaseHoldObjectDistance = true;
} else {
decreaseHoldObjectDistance = false;
}
}
}
public void inputSetObjectHolDistanceByMouseWheel (bool state)
{
if (usingPuzzle && movingObject) {
if (state) {
lastTimeMouseWheelUsed = Time.time;
increaseHoldObjectDistance = true;
mouseWheelUsedPreviously = true;
} else {
lastTimeMouseWheelUsed = Time.time;
decreaseHoldObjectDistance = true;
mouseWheelUsedPreviously = true;
}
}
}
public void inputResetPuzzle ()
{
if (usingPuzzle && canResetObjectsWhileUsing && !puzzleSolved) {
if (currentGrabbedObject == null) {
resetObjects ();
} else {
resetCurrentObjectRotation ();
}
}
}
void OnDrawGizmos ()
{
if (!showGizmo) {
return;
}
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
DrawGizmos ();
}
}
void OnDrawGizmosSelected ()
{
DrawGizmos ();
}
//draw the pivot and the final positions of every door
void DrawGizmos ()
{
if (showGizmo) {
Gizmos.color = gizmoColor;
Gizmos.DrawLine (transform.position, rotationPointPivot.position);
Gizmos.DrawLine (rotationPointPivot.position, rotationPointCamera.position);
Gizmos.DrawLine (rotationPointPivot.position, cameraPosition.position);
Gizmos.DrawSphere (transform.position, gizmoRadius);
Gizmos.DrawSphere (rotationPointPivot.position, gizmoRadius);
Gizmos.DrawSphere (rotationPointCamera.position, gizmoRadius);
Gizmos.DrawSphere (cameraPosition.position, gizmoRadius);
Gizmos.color = Color.green;
GKC_Utils.drawGizmoArrow (cameraPosition.position, cameraPosition.forward * gizmoArrowLineLength, gizmoArrowColor, gizmoArrowLength, gizmoArrowAngle);
}
}
[System.Serializable]
public class grabableObjectsInfo
{
public GameObject grabableGameObject;
public Transform grabableTransform;
public Vector3 originalPosition;
public Quaternion originalRotation;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 9294ff4869a51dc4580c447c45eaf40e
timeCreated: 1524544603
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/Puzzles/puzzleSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,101 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class puzzleSystemPlayerManagement : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool usingPuzzle;
[Space]
[Header ("Events Settings")]
[Space]
public bool useEventsOnStateChange;
public UnityEvent evenOnStateEnabled;
public UnityEvent eventOnStateDisabled;
puzzleSystem currentPuzzleSystem;
public void setcurrentPuzzleSystem (puzzleSystem newPuzzleObject)
{
currentPuzzleSystem = newPuzzleObject;
}
public void setUsingPuzzleState (bool state)
{
usingPuzzle = state;
checkEventsOnStateChange (usingPuzzle);
}
//CALL INPUT FUNCTIONS TO CURRENT PUZZLE SYSTEM
public void puzzleObjectInputSetRotateObjectState (bool state)
{
if (!usingPuzzle) {
return;
}
if (currentPuzzleSystem != null) {
currentPuzzleSystem.inputSetRotateObjectState (state);
}
}
public void puzzleObjectInputIncreaseObjectHolDistanceByButton (bool state)
{
if (!usingPuzzle) {
return;
}
if (currentPuzzleSystem != null) {
currentPuzzleSystem.inputIncreaseObjectHolDistanceByButton (state);
}
}
public void puzzleObjectInputDecreaseObjectHolDistanceByButton (bool state)
{
if (!usingPuzzle) {
return;
}
if (currentPuzzleSystem != null) {
currentPuzzleSystem.inputDecreaseObjectHolDistanceByButton (state);
}
}
public void puzzleObjectInputSetObjectHolDistanceByMouseWheel (bool state)
{
if (!usingPuzzle) {
return;
}
if (currentPuzzleSystem != null) {
currentPuzzleSystem.inputSetObjectHolDistanceByMouseWheel (state);
}
}
public void puzzleObjectInputResetPuzzle ()
{
if (!usingPuzzle) {
return;
}
if (currentPuzzleSystem != null) {
currentPuzzleSystem.inputResetPuzzle ();
}
}
public void checkEventsOnStateChange (bool state)
{
if (useEventsOnStateChange) {
if (state) {
evenOnStateEnabled.Invoke ();
} else {
eventOnStateDisabled.Invoke ();
}
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 5940f3823f60a074a8c36da598c1ae16
timeCreated: 1548654917
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/Puzzles/puzzleSystemPlayerManagement.cs
uploadId: 814740