add ckg
plantilla base para movimiento básico
This commit is contained in:
@@ -0,0 +1,433 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using System;
|
||||
using UnityEngine.UI;
|
||||
using System.Linq;
|
||||
|
||||
public class cameraCaptureSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useScreenResolution;
|
||||
public Vector2 captureResolution;
|
||||
|
||||
public Color disableButtonsColor;
|
||||
public Color originalColor;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool galleryOpened;
|
||||
public int currentCaptureIndex;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public ScrollRect captureListScrollRect;
|
||||
public GameObject captureSlotPrefab;
|
||||
public Scrollbar scrollBar;
|
||||
|
||||
public GameObject expandedCaptureMenu;
|
||||
public RawImage expandedCaptureImage;
|
||||
|
||||
public Image expandButton;
|
||||
public Image deleteButton;
|
||||
|
||||
public Camera customCameraForEditorCaptures;
|
||||
|
||||
|
||||
bool useRelativePath;
|
||||
|
||||
string captureFolderName;
|
||||
|
||||
string captureFileName;
|
||||
|
||||
string currentSaveDataPath;
|
||||
bool canDelete;
|
||||
bool canExpand;
|
||||
|
||||
List<captureButtonInfo> captureList = new List<captureButtonInfo> ();
|
||||
int previousCaptureAmountInFolder;
|
||||
const string glyphs = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
bool checkSettingsInitialized;
|
||||
|
||||
gameManager gameSystemManager;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (captureSlotPrefab.activeSelf) {
|
||||
captureSlotPrefab.SetActive (false);
|
||||
}
|
||||
|
||||
changeButtonsColor (false, false);
|
||||
|
||||
if (expandedCaptureMenu.activeSelf) {
|
||||
expandedCaptureMenu.SetActive (false);
|
||||
}
|
||||
|
||||
setMainSettings ();
|
||||
}
|
||||
|
||||
public void setMainSettings ()
|
||||
{
|
||||
bool mainGameManagerLocated = gameSystemManager != null;
|
||||
|
||||
if (!mainGameManagerLocated) {
|
||||
gameSystemManager = gameManager.Instance;
|
||||
|
||||
mainGameManagerLocated = gameSystemManager != null;
|
||||
}
|
||||
|
||||
if (!mainGameManagerLocated) {
|
||||
gameSystemManager = FindObjectOfType<gameManager> ();
|
||||
|
||||
gameSystemManager.getComponentInstanceOnApplicationPlaying ();
|
||||
}
|
||||
|
||||
useRelativePath = gameSystemManager.useRelativePath;
|
||||
|
||||
captureFolderName = gameSystemManager.getSaveCaptureFolder ();
|
||||
|
||||
captureFileName = gameSystemManager.getSaveCaptureFileName ();
|
||||
}
|
||||
|
||||
public void checkSettings ()
|
||||
{
|
||||
if (!checkSettingsInitialized) {
|
||||
currentSaveDataPath = getDataPath ();
|
||||
checkSettingsInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void loadCaptures ()
|
||||
{
|
||||
checkSettings ();
|
||||
|
||||
int numberOfFiles = 0;
|
||||
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo (currentSaveDataPath);
|
||||
var fileInfo = dir.GetFiles ().OrderBy (p => p.CreationTime).ToArray ();
|
||||
|
||||
//if the number of pictures has changed, reload these elements
|
||||
if (previousCaptureAmountInFolder != fileInfo.Length) {
|
||||
previousCaptureAmountInFolder = fileInfo.Length;
|
||||
|
||||
for (int i = 0; i < captureList.Count; i++) {
|
||||
Destroy (captureList [i].slotGameObject);
|
||||
}
|
||||
|
||||
captureList.Clear ();
|
||||
|
||||
foreach (FileInfo file in fileInfo) {
|
||||
|
||||
#if !UNITY_WEBPLAYER
|
||||
string currentDataFile = currentSaveDataPath + file.Name;
|
||||
|
||||
if (File.Exists (currentDataFile)) {
|
||||
|
||||
byte[] bytes = File.ReadAllBytes (currentDataFile);
|
||||
|
||||
Texture2D texture = new Texture2D ((int)captureResolution.x, (int)captureResolution.y);
|
||||
|
||||
texture.filterMode = FilterMode.Trilinear;
|
||||
|
||||
texture.LoadImage (bytes);
|
||||
|
||||
addCaptureSlot (numberOfFiles, file.Name);
|
||||
|
||||
captureList [numberOfFiles].capture.texture = texture;
|
||||
|
||||
numberOfFiles++;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
captureListScrollRect.verticalNormalizedPosition = 0.5f;
|
||||
scrollBar.value = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void getSaveButtonSelected (Button button)
|
||||
{
|
||||
currentCaptureIndex = -1;
|
||||
|
||||
bool delete = false;
|
||||
bool expand = false;
|
||||
|
||||
for (int i = 0; i < captureList.Count; i++) {
|
||||
if (captureList [i].button == button) {
|
||||
currentCaptureIndex = i;
|
||||
delete = true;
|
||||
expand = true;
|
||||
}
|
||||
}
|
||||
|
||||
changeButtonsColor (delete, expand);
|
||||
}
|
||||
|
||||
public void addCaptureSlot (int index, string fileName)
|
||||
{
|
||||
GameObject newSlotPrefab = (GameObject)Instantiate (captureSlotPrefab, captureSlotPrefab.transform.position,
|
||||
captureSlotPrefab.transform.rotation, captureSlotPrefab.transform.parent);
|
||||
|
||||
if (!newSlotPrefab.activeSelf) {
|
||||
newSlotPrefab.SetActive (true);
|
||||
}
|
||||
|
||||
newSlotPrefab.transform.localScale = Vector3.one;
|
||||
|
||||
newSlotPrefab.name = "Capture Slot " + (index + 1);
|
||||
|
||||
captureSlot newCaptureSlot = newSlotPrefab.GetComponent<captureSlot> ();
|
||||
|
||||
newCaptureSlot.captureInfo.fileName = fileName;
|
||||
|
||||
captureList.Add (newCaptureSlot.captureInfo);
|
||||
}
|
||||
|
||||
public void changeButtonsColor (bool delete, bool expand)
|
||||
{
|
||||
if (delete) {
|
||||
deleteButton.color = originalColor;
|
||||
} else {
|
||||
deleteButton.color = disableButtonsColor;
|
||||
}
|
||||
|
||||
if (expand) {
|
||||
expandButton.color = originalColor;
|
||||
} else {
|
||||
expandButton.color = disableButtonsColor;
|
||||
}
|
||||
|
||||
canDelete = delete;
|
||||
|
||||
canExpand = expand;
|
||||
}
|
||||
|
||||
public void openCaptureGallery ()
|
||||
{
|
||||
openOrCloseCapturesGallery (true);
|
||||
}
|
||||
|
||||
public void closeCaptureGallery ()
|
||||
{
|
||||
openOrCloseCapturesGallery (false);
|
||||
}
|
||||
|
||||
public void openOrCloseCapturesGallery (bool state)
|
||||
{
|
||||
galleryOpened = state;
|
||||
|
||||
if (galleryOpened) {
|
||||
loadCaptures ();
|
||||
} else {
|
||||
changeButtonsColor (false, false);
|
||||
|
||||
expandedCaptureMenu.SetActive (false);
|
||||
}
|
||||
}
|
||||
|
||||
public string getDataPath ()
|
||||
{
|
||||
string dataPath = "";
|
||||
|
||||
if (useRelativePath) {
|
||||
dataPath = captureFolderName;
|
||||
} else {
|
||||
dataPath = Application.persistentDataPath + "/" + captureFolderName;
|
||||
}
|
||||
|
||||
if (!Directory.Exists (dataPath)) {
|
||||
Directory.CreateDirectory (dataPath);
|
||||
}
|
||||
|
||||
dataPath += "/";
|
||||
|
||||
return dataPath;
|
||||
}
|
||||
|
||||
public void takeCapture (Camera currentCamera)
|
||||
{
|
||||
checkSettings ();
|
||||
|
||||
// get the camera's render texture
|
||||
RenderTexture previousRenderTexture = currentCamera.targetTexture;
|
||||
|
||||
Vector2 currentResolution = captureResolution;
|
||||
|
||||
if (useScreenResolution) {
|
||||
currentResolution = new Vector2 (Screen.currentResolution.width, Screen.currentResolution.height);
|
||||
}
|
||||
|
||||
currentCamera.targetTexture = new RenderTexture ((int)currentResolution.x, (int)currentResolution.y, 24);
|
||||
|
||||
RenderTexture rendText = RenderTexture.active;
|
||||
RenderTexture.active = currentCamera.targetTexture;
|
||||
|
||||
//render the texture
|
||||
currentCamera.Render ();
|
||||
|
||||
//create a new Texture2D with the camera's texture, using its height and width
|
||||
Texture2D cameraImage = new Texture2D ((int)currentResolution.x, (int)currentResolution.y, TextureFormat.RGB24, false);
|
||||
cameraImage.ReadPixels (new Rect (0, 0, (int)currentResolution.x, (int)currentResolution.y), 0, 0);
|
||||
cameraImage.Apply ();
|
||||
|
||||
RenderTexture.active = rendText;
|
||||
//store the texture into a .PNG file
|
||||
|
||||
#if !UNITY_WEBPLAYER
|
||||
byte[] bytes = cameraImage.EncodeToPNG ();
|
||||
|
||||
int numberOfFiles = 0;
|
||||
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo (currentSaveDataPath);
|
||||
if (dir.Exists) {
|
||||
numberOfFiles = dir.GetFiles ().Length;
|
||||
}
|
||||
|
||||
currentCamera.targetTexture = previousRenderTexture;
|
||||
RenderTexture.active = currentCamera.targetTexture;
|
||||
|
||||
string randomString = "";
|
||||
|
||||
int charAmount = UnityEngine.Random.Range (10, 20); //set those to the minimum and maximum length of your string
|
||||
for (int i = 0; i < charAmount; i++) {
|
||||
randomString += glyphs [UnityEngine.Random.Range (0, glyphs.Length)];
|
||||
}
|
||||
|
||||
if (File.Exists (currentSaveDataPath + captureFileName + "_" + randomString + ".png")) {
|
||||
randomString += glyphs [UnityEngine.Random.Range (0, glyphs.Length)];
|
||||
}
|
||||
//save the encoded image to a file
|
||||
System.IO.File.WriteAllBytes (currentSaveDataPath + (captureFileName + "_" + randomString + ".png"), bytes);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void takeCaptureWithCameraEditor ()
|
||||
{
|
||||
setMainSettings ();
|
||||
|
||||
takeCapture (customCameraForEditorCaptures);
|
||||
}
|
||||
|
||||
public void deleteCapture ()
|
||||
{
|
||||
checkSettings ();
|
||||
|
||||
if (currentCaptureIndex != -1 && canDelete) {
|
||||
|
||||
string fileName = captureList [currentCaptureIndex].fileName;
|
||||
|
||||
if (File.Exists (currentSaveDataPath + fileName)) {
|
||||
File.Delete (currentSaveDataPath + fileName);
|
||||
}
|
||||
|
||||
destroyCaptureSlot (currentCaptureIndex);
|
||||
|
||||
currentCaptureIndex = -1;
|
||||
|
||||
changeButtonsColor (false, false);
|
||||
|
||||
captureListScrollRect.verticalNormalizedPosition = 0.5f;
|
||||
|
||||
scrollBar.value = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteExpandedCapture ()
|
||||
{
|
||||
checkSettings ();
|
||||
|
||||
print (currentCaptureIndex);
|
||||
|
||||
if (currentCaptureIndex != -1) {
|
||||
|
||||
string fileName = captureList [currentCaptureIndex].fileName;
|
||||
|
||||
if (File.Exists (currentSaveDataPath + fileName)) {
|
||||
File.Delete (currentSaveDataPath + fileName);
|
||||
}
|
||||
|
||||
destroyCaptureSlot (currentCaptureIndex);
|
||||
|
||||
if (captureList.Count > 0) {
|
||||
if ((currentCaptureIndex + 1) < captureList.Count) {
|
||||
expandNextCapture ();
|
||||
} else {
|
||||
expandPreviousCapture ();
|
||||
}
|
||||
} else {
|
||||
expandedCaptureMenu.SetActive (false);
|
||||
closeExpandCaptureMenu ();
|
||||
}
|
||||
|
||||
captureListScrollRect.verticalNormalizedPosition = 0.5f;
|
||||
|
||||
scrollBar.value = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void expandCapture ()
|
||||
{
|
||||
if (currentCaptureIndex != -1 && canExpand) {
|
||||
expandedCaptureMenu.SetActive (true);
|
||||
|
||||
expandedCaptureImage.texture = captureList [currentCaptureIndex].capture.texture;
|
||||
}
|
||||
}
|
||||
|
||||
public void expandNextCapture ()
|
||||
{
|
||||
if (galleryOpened) {
|
||||
currentCaptureIndex++;
|
||||
|
||||
if (currentCaptureIndex >= captureList.Count) {
|
||||
currentCaptureIndex = 0;
|
||||
}
|
||||
|
||||
expandedCaptureImage.texture = captureList [currentCaptureIndex].capture.texture;
|
||||
}
|
||||
}
|
||||
|
||||
public void expandPreviousCapture ()
|
||||
{
|
||||
if (galleryOpened) {
|
||||
currentCaptureIndex--;
|
||||
|
||||
if (currentCaptureIndex < 0) {
|
||||
currentCaptureIndex = captureList.Count - 1;
|
||||
}
|
||||
|
||||
expandedCaptureImage.texture = captureList [currentCaptureIndex].capture.texture;
|
||||
}
|
||||
}
|
||||
|
||||
public void closeExpandCaptureMenu ()
|
||||
{
|
||||
changeButtonsColor (false, false);
|
||||
}
|
||||
|
||||
public void destroyCaptureSlot (int slotIndex)
|
||||
{
|
||||
Destroy (captureList [slotIndex].slotGameObject);
|
||||
|
||||
captureList.RemoveAt (slotIndex);
|
||||
}
|
||||
|
||||
public void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class captureButtonInfo
|
||||
{
|
||||
public GameObject slotGameObject;
|
||||
public Button button;
|
||||
public RawImage capture;
|
||||
public string fileName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba13183ca4c9840419119ab4d6f0c085
|
||||
timeCreated: 1524526324
|
||||
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/Camera/Captures/cameraCaptureSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,348 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using GameKitController.Audio;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class cameraPerspectiveSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public List<GameObject> objectToLookList = new List<GameObject> ();
|
||||
public float maxDistance;
|
||||
public float maxAngle;
|
||||
|
||||
public float proximitySoundRate;
|
||||
public float maxPitchValue = 3;
|
||||
|
||||
public LayerMask layerForUsers;
|
||||
|
||||
public bool activateObjectOnCapture;
|
||||
public List<GameObject> objectToActiveList = new List<GameObject> ();
|
||||
|
||||
public bool disableObjectOnCapture;
|
||||
public List<GameObject> objectToDisableList = new List<GameObject> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Sounds Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useCaptureSound;
|
||||
public AudioClip captureSound;
|
||||
public AudioElement captureAudioElement;
|
||||
|
||||
public bool useProximitySound;
|
||||
public AudioClip proximitySound;
|
||||
public AudioElement proximityAudioElement;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
public bool captureTakenCorrectly;
|
||||
public bool playerInside;
|
||||
|
||||
[Space]
|
||||
[Header ("Event Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventFunction;
|
||||
public UnityEvent eventFunction = new UnityEvent ();
|
||||
|
||||
[Space]
|
||||
[Header ("Gizmo Settings")]
|
||||
[Space]
|
||||
|
||||
public bool showGizmo;
|
||||
public float gizmoArrowLength = 1;
|
||||
public float gizmoArrowAngle = 20;
|
||||
public Color gizmoArrowColor = Color.white;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Transform positionToStay;
|
||||
public Transform positionToLook;
|
||||
|
||||
public AudioSource bipAudioSource;
|
||||
public AudioSource captureAudioSource;
|
||||
|
||||
GameObject currentPlayer;
|
||||
smartphoneDevice smartphoneDeviceManager;
|
||||
float lastTimePlayed;
|
||||
float triggerDistance;
|
||||
float distancePercentage = 1;
|
||||
float soundRate;
|
||||
|
||||
Vector3 screenPoint;
|
||||
|
||||
bool usingScreenSpaceCamera;
|
||||
|
||||
bool targetOnScreen;
|
||||
|
||||
playerComponentsManager mainPlayerComponentsManager;
|
||||
|
||||
float screenWidth;
|
||||
float screenHeight;
|
||||
|
||||
Coroutine updateCoroutine;
|
||||
|
||||
|
||||
private void InitializeAudioElements ()
|
||||
{
|
||||
if (proximitySound != null) {
|
||||
proximityAudioElement.clip = proximitySound;
|
||||
}
|
||||
|
||||
if (bipAudioSource != null) {
|
||||
proximityAudioElement.audioSource = bipAudioSource;
|
||||
}
|
||||
|
||||
if (captureSound != null) {
|
||||
captureAudioElement.clip = captureSound;
|
||||
}
|
||||
|
||||
if (captureAudioSource != null) {
|
||||
captureAudioElement.audioSource = captureAudioSource;
|
||||
}
|
||||
}
|
||||
|
||||
private void Start ()
|
||||
{
|
||||
InitializeAudioElements ();
|
||||
}
|
||||
|
||||
public void stopUpdateCoroutine ()
|
||||
{
|
||||
if (updateCoroutine != null) {
|
||||
StopCoroutine (updateCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator updateSystemCoroutine ()
|
||||
{
|
||||
var waitTime = new WaitForFixedUpdate ();
|
||||
|
||||
while (true) {
|
||||
updateSystem ();
|
||||
|
||||
yield return waitTime;
|
||||
}
|
||||
}
|
||||
|
||||
void updateSystem ()
|
||||
{
|
||||
if (!captureTakenCorrectly) {
|
||||
if (playerInside && useProximitySound) {
|
||||
if (Time.time > lastTimePlayed + soundRate) {
|
||||
float currentDistance = GKC_Utils.distance (currentPlayer.transform.position, positionToStay.position);
|
||||
|
||||
distancePercentage = currentDistance / triggerDistance;
|
||||
|
||||
float pitchValue = 1 + ((1 - distancePercentage) * (maxPitchValue - 1));
|
||||
|
||||
if (pitchValue <= 0) {
|
||||
pitchValue = 0.1f;
|
||||
}
|
||||
|
||||
if (pitchValue > maxPitchValue) {
|
||||
pitchValue = maxPitchValue;
|
||||
}
|
||||
|
||||
bipAudioSource.pitch = pitchValue;
|
||||
|
||||
AudioPlayer.PlayOneShot (proximityAudioElement, gameObject);
|
||||
|
||||
lastTimePlayed = Time.time;
|
||||
|
||||
soundRate = distancePercentage;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void checkCurrentPlayerPosition (Transform playerPosition, Transform cameraTransform, Camera deviceCamera)
|
||||
{
|
||||
if (captureTakenCorrectly) {
|
||||
return;
|
||||
}
|
||||
|
||||
float currentDistance = GKC_Utils.distance (playerPosition.position, positionToStay.position);
|
||||
|
||||
if (currentDistance <= maxDistance) {
|
||||
|
||||
Vector3 targetDir = positionToLook.position - cameraTransform.position;
|
||||
targetDir = targetDir.normalized;
|
||||
|
||||
float dot = Vector3.Dot (targetDir, cameraTransform.forward);
|
||||
float currentAngleZ = Mathf.Acos (dot) * Mathf.Rad2Deg;
|
||||
|
||||
if (Mathf.Abs (currentAngleZ) < maxAngle) {
|
||||
bool allObjectsInCamera = true;
|
||||
|
||||
if (!usingScreenSpaceCamera) {
|
||||
screenWidth = Screen.width;
|
||||
screenHeight = Screen.height;
|
||||
}
|
||||
|
||||
for (int i = 0; i < objectToLookList.Count; i++) {
|
||||
if (usingScreenSpaceCamera) {
|
||||
screenPoint = deviceCamera.WorldToViewportPoint (objectToLookList [i].transform.position);
|
||||
targetOnScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;
|
||||
} else {
|
||||
screenPoint = deviceCamera.WorldToScreenPoint (objectToLookList [i].transform.position);
|
||||
targetOnScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < screenWidth && screenPoint.y > 0 && screenPoint.y < screenHeight;
|
||||
}
|
||||
|
||||
if (!targetOnScreen) {
|
||||
allObjectsInCamera = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (allObjectsInCamera) {
|
||||
playSound ();
|
||||
|
||||
if (activateObjectOnCapture) {
|
||||
for (int i = 0; i < objectToActiveList.Count; i++) {
|
||||
if (!objectToActiveList [i].activeSelf) {
|
||||
objectToActiveList [i].SetActive (true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (disableObjectOnCapture) {
|
||||
for (int i = 0; i < objectToDisableList.Count; i++) {
|
||||
if (objectToDisableList [i].activeSelf) {
|
||||
objectToDisableList [i].SetActive (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (useEventFunction) {
|
||||
if (eventFunction.GetPersistentEventCount () > 0) {
|
||||
eventFunction.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
captureTakenCorrectly = true;
|
||||
|
||||
if (smartphoneDeviceManager != null) {
|
||||
smartphoneDeviceManager.removeCurrentPerspectiveSystem ();
|
||||
}
|
||||
|
||||
stopUpdateCoroutine ();
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("capture done correctly");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void playSound ()
|
||||
{
|
||||
if (useCaptureSound) {
|
||||
GKC_Utils.checkAudioSourcePitch (captureAudioSource);
|
||||
|
||||
AudioPlayer.PlayOneShot (captureAudioElement, gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
//check when the player enters or exits of the trigger in the device
|
||||
void OnTriggerEnter (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, true);
|
||||
}
|
||||
|
||||
void OnTriggerExit (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, false);
|
||||
}
|
||||
|
||||
public void checkTriggerInfo (Collider col, bool isEnter)
|
||||
{
|
||||
if ((1 << col.gameObject.layer & layerForUsers.value) == 1 << col.gameObject.layer) {
|
||||
//if the player is entering in the trigger
|
||||
if (isEnter) {
|
||||
if (playerInside) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentPlayer = col.gameObject;
|
||||
|
||||
mainPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
smartphoneDeviceManager = currentPlayer.GetComponentInChildren<smartphoneDevice> ();
|
||||
|
||||
if (smartphoneDeviceManager == null) {
|
||||
smartphoneDeviceManager = mainPlayerComponentsManager.getPlayerCamera ().gameObject.GetComponentInChildren<smartphoneDevice> ();
|
||||
}
|
||||
|
||||
if (smartphoneDeviceManager != null) {
|
||||
smartphoneDeviceManager.setCurrentPerspectiveSystem (this);
|
||||
}
|
||||
|
||||
usingScreenSpaceCamera = mainPlayerComponentsManager.getPlayerCamera ().isUsingScreenSpaceCamera ();
|
||||
|
||||
playerInside = true;
|
||||
triggerDistance = GKC_Utils.distance (currentPlayer.transform.position, positionToStay.position);
|
||||
bipAudioSource.pitch = 1;
|
||||
|
||||
updateCoroutine = StartCoroutine (updateSystemCoroutine ());
|
||||
|
||||
} else {
|
||||
//if the player is leaving the trigger
|
||||
|
||||
//if the player is the same that was using the device, the device can be used again
|
||||
if (col.gameObject == currentPlayer) {
|
||||
currentPlayer = null;
|
||||
playerInside = false;
|
||||
|
||||
stopUpdateCoroutine ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
if (positionToStay != null && positionToLook != null) {
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawSphere (positionToStay.position, 0.3f);
|
||||
Gizmos.DrawSphere (positionToLook.position, 0.3f);
|
||||
|
||||
Gizmos.DrawLine (positionToStay.position, positionToLook.position);
|
||||
|
||||
Vector3 direction = positionToLook.position - positionToStay.position;
|
||||
direction = direction / direction.magnitude;
|
||||
float distance = GKC_Utils.distance (positionToLook.position, positionToStay.position);
|
||||
GKC_Utils.drawGizmoArrow (positionToStay.position, direction * distance, gizmoArrowColor, gizmoArrowLength, gizmoArrowAngle);
|
||||
|
||||
positionToLook.rotation = Quaternion.LookRotation (direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca643d6e5129ef3488204dd42db3b54c
|
||||
timeCreated: 1524617233
|
||||
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/Camera/Captures/cameraPerspectiveSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class captureSlot : MonoBehaviour {
|
||||
|
||||
public cameraCaptureSystem.captureButtonInfo captureInfo;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 914fc1745b4a8c749ae64b54f449e2eb
|
||||
timeCreated: 1524534914
|
||||
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/Camera/Captures/captureSlot.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,97 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class remoteEventOnCameraCaptureSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool checkObjectFoundOnCaptureEnabled = true;
|
||||
|
||||
public LayerMask layermaskToUse;
|
||||
|
||||
public float maxRaycastDistance = 20;
|
||||
|
||||
public bool sendObjectOnSurfaceDetected;
|
||||
public GameObject objectToSendOnSurfaceDetected;
|
||||
|
||||
[Space]
|
||||
[Header ("Raycast Detection Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useCapsuleRaycast;
|
||||
|
||||
public float capsuleCastRadius;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Transform cameraTransform;
|
||||
|
||||
|
||||
RaycastHit hit;
|
||||
|
||||
RaycastHit[] hits;
|
||||
|
||||
public void checkCapture ()
|
||||
{
|
||||
if (checkObjectFoundOnCaptureEnabled) {
|
||||
if (Physics.Raycast (cameraTransform.position, cameraTransform.forward, out hit, maxRaycastDistance, layermaskToUse)) {
|
||||
if (useCapsuleRaycast) {
|
||||
|
||||
Vector3 currentRayOriginPosition = cameraTransform.position;
|
||||
|
||||
Vector3 currentRayTargetPosition = hit.point;
|
||||
|
||||
float distanceToTarget = GKC_Utils.distance (currentRayOriginPosition, currentRayTargetPosition);
|
||||
Vector3 rayDirection = currentRayOriginPosition - currentRayTargetPosition;
|
||||
rayDirection = rayDirection / rayDirection.magnitude;
|
||||
|
||||
Debug.DrawLine (currentRayTargetPosition, (rayDirection * distanceToTarget) + currentRayTargetPosition, Color.red, 2);
|
||||
|
||||
Vector3 point1 = currentRayOriginPosition - rayDirection * capsuleCastRadius;
|
||||
Vector3 point2 = currentRayTargetPosition + rayDirection * capsuleCastRadius;
|
||||
|
||||
hits = Physics.CapsuleCastAll (point1, point2, capsuleCastRadius, rayDirection, 0, layermaskToUse);
|
||||
|
||||
for (int i = 0; i < hits.Length; i++) {
|
||||
GameObject currentSurfaceGameObjectFound = hits [i].collider.gameObject;
|
||||
|
||||
checkObjectDetected (currentSurfaceGameObjectFound);
|
||||
}
|
||||
} else {
|
||||
checkObjectDetected (hit.collider.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void checkObjectDetected (GameObject objectDetected)
|
||||
{
|
||||
GameObject character = applyDamage.getCharacterOrVehicle (objectDetected);
|
||||
|
||||
if (character != null) {
|
||||
objectDetected = character;
|
||||
}
|
||||
|
||||
if (objectDetected != null) {
|
||||
|
||||
eventObjectFoundOnCaptureSystem currentEventObjectFoundOnCaptureSystem = objectDetected.GetComponent<eventObjectFoundOnCaptureSystem> ();
|
||||
|
||||
if (currentEventObjectFoundOnCaptureSystem != null) {
|
||||
currentEventObjectFoundOnCaptureSystem.callEventOnCapture ();
|
||||
|
||||
if (sendObjectOnSurfaceDetected) {
|
||||
currentEventObjectFoundOnCaptureSystem.callEventOnCaptureWithGameObject (objectToSendOnSurfaceDetected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setNewCameraTransform (Transform newCamera)
|
||||
{
|
||||
cameraTransform = newCamera;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9928dabe8e0adf4b92f357a3d6e15cb
|
||||
timeCreated: 1603953704
|
||||
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/Camera/Captures/remoteEventOnCameraCaptureSystem.cs
|
||||
uploadId: 814740
|
||||
Reference in New Issue
Block a user