add ckg
plantilla base para movimiento básico
This commit is contained in:
9
Assets/Game Kit Controller/Scripts/Devices/Radio.meta
Normal file
9
Assets/Game Kit Controller/Scripts/Devices/Radio.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9ae4caf0fe289e4a8ce88e6f7f6019b
|
||||
folderAsset: yes
|
||||
timeCreated: 1538636083
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
438
Assets/Game Kit Controller/Scripts/Devices/Radio/radioSystem.cs
Normal file
438
Assets/Game Kit Controller/Scripts/Devices/Radio/radioSystem.cs
Normal file
@@ -0,0 +1,438 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine.UI;
|
||||
using System;
|
||||
using GameKitController.Audio;
|
||||
|
||||
public class radioSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public float radioVolume;
|
||||
|
||||
public bool playSongsOnStart;
|
||||
|
||||
public bool playSongsOnActive;
|
||||
|
||||
public bool playSongsRandomly;
|
||||
public bool repeatList;
|
||||
|
||||
public string mainManagerName = "Songs Manager";
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool playingSong;
|
||||
public bool songPaused;
|
||||
public float currentSongLength;
|
||||
|
||||
public bool radioActive;
|
||||
|
||||
public bool movingSongLenghtSlider;
|
||||
|
||||
public List<AudioClip> clips = new List<AudioClip> ();
|
||||
public List<AudioElement> audioElements = new List<AudioElement> ();
|
||||
|
||||
public int currentIndex = 0;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Scrollbar volumeScrollbar;
|
||||
|
||||
public Text currentSongNameText;
|
||||
|
||||
public Slider songLenghtSlider;
|
||||
|
||||
public GameObject playButton;
|
||||
public GameObject pauseButton;
|
||||
|
||||
public GameObject songListContent;
|
||||
public GameObject songListElementParent;
|
||||
public GameObject songListElement;
|
||||
|
||||
public AudioSource source;
|
||||
|
||||
public songsManager mainSongsManager;
|
||||
|
||||
|
||||
bool songsLoaded;
|
||||
|
||||
bool radioCanBeUsed = true;
|
||||
|
||||
public AudioElement _currentSongAudioElement = new AudioElement ();
|
||||
|
||||
bool _currentSongAudioElementAssigned;
|
||||
|
||||
|
||||
private void InitializeAudioElements ()
|
||||
{
|
||||
if (source == null) {
|
||||
source = gameObject.AddComponent<AudioSource> ();
|
||||
}
|
||||
|
||||
if (clips != null && clips.Count > 0) {
|
||||
audioElements = new List<AudioElement> ();
|
||||
|
||||
foreach (var clip in clips) {
|
||||
audioElements.Add (new AudioElement { clip = clip });
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var audioElement in audioElements) {
|
||||
if (source != null) {
|
||||
audioElement.audioSource = source;
|
||||
}
|
||||
}
|
||||
|
||||
if (source != null) {
|
||||
_currentSongAudioElement.audioSource = source;
|
||||
|
||||
_currentSongAudioElementAssigned = _currentSongAudioElement.audioSource != null;
|
||||
}
|
||||
}
|
||||
|
||||
void Start ()
|
||||
{
|
||||
songListElement.SetActive (false);
|
||||
|
||||
InitializeAudioElements ();
|
||||
|
||||
volumeScrollbar.value = radioVolume;
|
||||
|
||||
bool mainSongsManagerLocated = mainSongsManager != null;
|
||||
|
||||
if (!mainSongsManagerLocated) {
|
||||
mainSongsManager = songsManager.Instance;
|
||||
|
||||
mainSongsManagerLocated = mainSongsManager != null;
|
||||
}
|
||||
|
||||
if (!mainSongsManagerLocated) {
|
||||
GKC_Utils.instantiateMainManagerOnSceneWithTypeOnApplicationPlaying (songsManager.getMainManagerName (), typeof(songsManager), true);
|
||||
|
||||
mainSongsManager = songsManager.Instance;
|
||||
|
||||
mainSongsManagerLocated = mainSongsManager != null;
|
||||
}
|
||||
|
||||
if (!mainSongsManagerLocated) {
|
||||
|
||||
mainSongsManager = FindObjectOfType<songsManager> ();
|
||||
|
||||
mainSongsManagerLocated = mainSongsManager != null;
|
||||
}
|
||||
|
||||
if (!mainSongsManagerLocated) {
|
||||
radioCanBeUsed = false;
|
||||
}
|
||||
|
||||
currentSongNameText.text = "...";
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (!radioCanBeUsed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (radioActive) {
|
||||
if (playingSong) {
|
||||
if (!movingSongLenghtSlider) {
|
||||
songLenghtSlider.value = _currentSongAudioElement.audioSource.time / currentSongLength;
|
||||
}
|
||||
|
||||
if (!songPaused) {
|
||||
if ((_currentSongAudioElement.audioSource.time / currentSongLength) > 0.99f) {
|
||||
if (currentIndex == audioElements.Count - 1) {
|
||||
if (repeatList) {
|
||||
setNextSong ();
|
||||
} else {
|
||||
stopCurrentSong ();
|
||||
|
||||
currentIndex = 0;
|
||||
|
||||
setPlayPauseButtonState (true);
|
||||
}
|
||||
} else {
|
||||
if (playSongsRandomly) {
|
||||
setRandomSong ();
|
||||
} else {
|
||||
setNextSong ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!songsLoaded) {
|
||||
if (mainSongsManager.allSongsLoaded ()) {
|
||||
getSongsList ();
|
||||
|
||||
songsLoaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (playSongsOnStart) {
|
||||
if (songsLoaded) {
|
||||
setRadioActiveState (true);
|
||||
|
||||
playSongsOnStart = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void playCurrentSong ()
|
||||
{
|
||||
if (playingSong) {
|
||||
if (_currentSongAudioElementAssigned) {
|
||||
AudioPlayer.Play (_currentSongAudioElement, gameObject);
|
||||
|
||||
currentSongLength = _currentSongAudioElement.clip.length;
|
||||
|
||||
songLenghtSlider.value = _currentSongAudioElement.audioSource.time / currentSongLength;
|
||||
}
|
||||
} else {
|
||||
PlayCurrent ();
|
||||
}
|
||||
|
||||
songPaused = false;
|
||||
}
|
||||
|
||||
public void stopCurrentSong ()
|
||||
{
|
||||
if (_currentSongAudioElementAssigned) {
|
||||
AudioPlayer.Stop (_currentSongAudioElement, gameObject);
|
||||
}
|
||||
|
||||
playingSong = false;
|
||||
|
||||
songLenghtSlider.value = 0;
|
||||
}
|
||||
|
||||
public void pauseCurrentSong ()
|
||||
{
|
||||
songPaused = true;
|
||||
|
||||
if (_currentSongAudioElementAssigned) {
|
||||
AudioPlayer.Pause (_currentSongAudioElement, gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void setNextSong ()
|
||||
{
|
||||
if (audioElements.Count == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (playSongsRandomly) {
|
||||
setRandomSongIndex ();
|
||||
} else {
|
||||
currentIndex = (currentIndex + 1) % audioElements.Count;
|
||||
}
|
||||
|
||||
setPlayPauseButtonState (false);
|
||||
|
||||
PlayCurrent ();
|
||||
}
|
||||
|
||||
public void setPreviousSong ()
|
||||
{
|
||||
if (audioElements.Count == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (playSongsRandomly) {
|
||||
setRandomSongIndex ();
|
||||
} else {
|
||||
currentIndex--;
|
||||
if (currentIndex < 0) {
|
||||
currentIndex = audioElements.Count - 1;
|
||||
}
|
||||
}
|
||||
|
||||
setPlayPauseButtonState (false);
|
||||
|
||||
PlayCurrent ();
|
||||
}
|
||||
|
||||
public void setRandomSong ()
|
||||
{
|
||||
setRandomSongIndex ();
|
||||
|
||||
PlayCurrent ();
|
||||
}
|
||||
|
||||
public void setRandomSongIndex ()
|
||||
{
|
||||
int nextIndex = 0;
|
||||
|
||||
int loop = 0;
|
||||
|
||||
while (nextIndex == currentIndex) {
|
||||
nextIndex = (int)UnityEngine.Random.Range (0, audioElements.Count);
|
||||
|
||||
loop++;
|
||||
|
||||
if (loop > 100) {
|
||||
print ("loop error");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
currentIndex = nextIndex;
|
||||
}
|
||||
|
||||
public void setRadioVolume ()
|
||||
{
|
||||
radioVolume = volumeScrollbar.value;
|
||||
|
||||
if (_currentSongAudioElementAssigned) {
|
||||
_currentSongAudioElement.audioSource.volume = radioVolume;
|
||||
}
|
||||
}
|
||||
|
||||
void PlayCurrent ()
|
||||
{
|
||||
if (audioElements.Count <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_currentSongAudioElementAssigned) {
|
||||
_currentSongAudioElement = audioElements [currentIndex];
|
||||
|
||||
_currentSongAudioElement.audioSource = source;
|
||||
|
||||
_currentSongAudioElement.audioSource.time = 0;
|
||||
|
||||
AudioPlayer.Play (_currentSongAudioElement, gameObject);
|
||||
|
||||
string songName = audioElements [currentIndex].clip.name;
|
||||
|
||||
int extensionIndex = songName.IndexOf (".");
|
||||
|
||||
if (extensionIndex > -1) {
|
||||
songName = songName.Substring (0, extensionIndex);
|
||||
}
|
||||
|
||||
currentSongNameText.text = songName;
|
||||
|
||||
playingSong = true;
|
||||
|
||||
currentSongLength = _currentSongAudioElement.clip.length;
|
||||
|
||||
songLenghtSlider.value = _currentSongAudioElement.audioSource.time / currentSongLength;
|
||||
}
|
||||
}
|
||||
|
||||
public void setPlaySongsRandomlyState (bool state)
|
||||
{
|
||||
playSongsRandomly = state;
|
||||
}
|
||||
|
||||
public void setRepeatListState (bool state)
|
||||
{
|
||||
repeatList = state;
|
||||
}
|
||||
|
||||
public void setMovingSongLenghtSliderState (bool state)
|
||||
{
|
||||
if (playingSong) {
|
||||
movingSongLenghtSlider = state;
|
||||
}
|
||||
}
|
||||
|
||||
public void setSongPart ()
|
||||
{
|
||||
if (playingSong) {
|
||||
if (_currentSongAudioElementAssigned) {
|
||||
_currentSongAudioElement.audioSource.time = _currentSongAudioElement.clip.length * songLenghtSlider.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setRadioActiveState (bool state)
|
||||
{
|
||||
radioActive = state;
|
||||
|
||||
if (radioActive) {
|
||||
if (playSongsOnActive) {
|
||||
if (playSongsRandomly) {
|
||||
setRandomSongIndex ();
|
||||
}
|
||||
|
||||
PlayCurrent ();
|
||||
|
||||
setPlayPauseButtonState (false);
|
||||
}
|
||||
} else {
|
||||
if (playingSong) {
|
||||
stopCurrentSong ();
|
||||
|
||||
setPlayPauseButtonState (true);
|
||||
}
|
||||
|
||||
songListContent.SetActive (false);
|
||||
}
|
||||
}
|
||||
|
||||
public void setOnlyRadioActiveState (bool state)
|
||||
{
|
||||
radioActive = state;
|
||||
}
|
||||
|
||||
public void setPlayPauseButtonState (bool state)
|
||||
{
|
||||
playButton.SetActive (state);
|
||||
|
||||
pauseButton.SetActive (!state);
|
||||
}
|
||||
|
||||
public void selectSongOnList (GameObject songButtonPressed)
|
||||
{
|
||||
string songNameToCheck = songButtonPressed.GetComponentInChildren<Text> ().text;
|
||||
|
||||
for (int i = 0; i < audioElements.Count; i++) {
|
||||
if (audioElements [i].clip.name.Contains (songNameToCheck)) {
|
||||
currentIndex = i;
|
||||
|
||||
PlayCurrent ();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void getSongsList ()
|
||||
{
|
||||
//print (mainSongsManager.getSongsList ().Count);
|
||||
audioElements = mainSongsManager.getSongsList ();
|
||||
|
||||
for (int i = 0; i < audioElements.Count; i++) {
|
||||
string songName = audioElements [i].clip.name;
|
||||
|
||||
int extensionIndex = songName.IndexOf (".");
|
||||
|
||||
if (extensionIndex > -1) {
|
||||
songName = songName.Substring (0, extensionIndex);
|
||||
}
|
||||
|
||||
GameObject newSongListElement = (GameObject)Instantiate (songListElement, Vector3.zero, songListElement.transform.rotation);
|
||||
newSongListElement.SetActive (true);
|
||||
newSongListElement.transform.SetParent (songListElementParent.transform);
|
||||
newSongListElement.transform.localScale = Vector3.one;
|
||||
newSongListElement.transform.localPosition = Vector3.zero;
|
||||
newSongListElement.name = "Song List Element (" + songName + ")";
|
||||
|
||||
newSongListElement.GetComponentInChildren<Text> ().text = songName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e568e1cbf66712543b01a2006f479ff8
|
||||
timeCreated: 1530480668
|
||||
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/Devices/Radio/radioSystem.cs
|
||||
uploadId: 814740
|
||||
231
Assets/Game Kit Controller/Scripts/Devices/Radio/songsManager.cs
Normal file
231
Assets/Game Kit Controller/Scripts/Devices/Radio/songsManager.cs
Normal file
@@ -0,0 +1,231 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine.UI;
|
||||
using System;
|
||||
using GameKitController.Audio;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
public class songsManager : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool loadSoundsInFolderEnabled = true;
|
||||
|
||||
public string absolutePathBuild = ".";
|
||||
|
||||
public string absolutePathEditor = "Music";
|
||||
|
||||
public List<string> validExtensions = new List<string> { ".ogg", ".wav" };
|
||||
|
||||
[Space]
|
||||
[Header ("Internal Songs List")]
|
||||
[Space]
|
||||
|
||||
public bool useInternalSongsList;
|
||||
public List<AudioClip> internalClips = new List<AudioClip> ();
|
||||
public List<AudioElement> internalAudioElements = new List<AudioElement> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
public bool songsLoaded;
|
||||
|
||||
public List<AudioClip> clips = new List<AudioClip> ();
|
||||
public List<AudioElement> audioElements = new List<AudioElement> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public gameManager gameSystemManager;
|
||||
|
||||
string absolutePath;
|
||||
|
||||
int numberOfSongs;
|
||||
|
||||
|
||||
public const string mainManagerName = "Songs Manager";
|
||||
|
||||
public static string getMainManagerName ()
|
||||
{
|
||||
return mainManagerName;
|
||||
}
|
||||
|
||||
private static songsManager _songsManagerInstance;
|
||||
|
||||
public static songsManager Instance { get { return _songsManagerInstance; } }
|
||||
|
||||
bool instanceInitialized;
|
||||
|
||||
|
||||
public void getComponentInstance ()
|
||||
{
|
||||
if (instanceInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_songsManagerInstance != null && _songsManagerInstance != this) {
|
||||
Destroy (this.gameObject);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_songsManagerInstance = this;
|
||||
|
||||
instanceInitialized = true;
|
||||
}
|
||||
|
||||
void Awake ()
|
||||
{
|
||||
getComponentInstance ();
|
||||
}
|
||||
|
||||
|
||||
void Start ()
|
||||
{
|
||||
InitializeAudioElements ();
|
||||
|
||||
bool mainGameManagerLocated = gameSystemManager != null;
|
||||
|
||||
if (!mainGameManagerLocated) {
|
||||
gameSystemManager = gameManager.Instance;
|
||||
|
||||
mainGameManagerLocated = gameSystemManager != null;
|
||||
}
|
||||
|
||||
if (!mainGameManagerLocated) {
|
||||
gameSystemManager = FindObjectOfType<gameManager> ();
|
||||
|
||||
gameSystemManager.getComponentInstanceOnApplicationPlaying ();
|
||||
|
||||
mainGameManagerLocated = gameSystemManager != null;
|
||||
}
|
||||
|
||||
if (mainGameManagerLocated) {
|
||||
if (gameSystemManager.isLoadGameEnabled () || loadSoundsInFolderEnabled) {
|
||||
if (Application.isEditor) {
|
||||
absolutePath = absolutePathEditor;
|
||||
} else {
|
||||
absolutePath = absolutePathBuild;
|
||||
}
|
||||
|
||||
ReloadSounds ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeAudioElements ()
|
||||
{
|
||||
if (clips != null && clips.Count > 0) {
|
||||
audioElements = new List<AudioElement> ();
|
||||
|
||||
foreach (var clip in clips) {
|
||||
audioElements.Add (new AudioElement { clip = clip });
|
||||
}
|
||||
}
|
||||
|
||||
if (internalClips != null && internalClips.Count > 0) {
|
||||
internalAudioElements = new List<AudioElement> ();
|
||||
|
||||
foreach (var clip in internalClips) {
|
||||
internalAudioElements.Add (new AudioElement { clip = clip });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<AudioElement> getSongsList ()
|
||||
{
|
||||
return audioElements;
|
||||
}
|
||||
|
||||
void ReloadSounds ()
|
||||
{
|
||||
audioElements.Clear ();
|
||||
|
||||
if (Directory.Exists (absolutePath)) {
|
||||
//print ("directory found");
|
||||
absolutePath += "/";
|
||||
|
||||
// get all valid files
|
||||
System.IO.DirectoryInfo info = new System.IO.DirectoryInfo (absolutePath);
|
||||
var fileInfo = info.GetFiles ()
|
||||
.Where (f => IsValidFileType (f.Name))
|
||||
.ToArray ();
|
||||
|
||||
numberOfSongs = fileInfo.Length;
|
||||
|
||||
if (useInternalSongsList) {
|
||||
numberOfSongs += internalAudioElements.Count;
|
||||
}
|
||||
|
||||
foreach (FileInfo s in fileInfo) {
|
||||
StartCoroutine (LoadFile (s.FullName));
|
||||
}
|
||||
} else {
|
||||
if (showDebugPrint) {
|
||||
print ("Directory with song files doesn't exist. If you want to use the radio system, place some .wav files on the folder " + absolutePathEditor + " inside the project folder.");
|
||||
}
|
||||
}
|
||||
|
||||
if (useInternalSongsList) {
|
||||
audioElements.AddRange (internalAudioElements);
|
||||
}
|
||||
}
|
||||
|
||||
bool IsValidFileType (string fileName)
|
||||
{
|
||||
return validExtensions.Contains (Path.GetExtension (fileName));
|
||||
// Alternatively, you could go fileName.SubString(fileName.LastIndexOf('.') + 1); that way you don't need the '.' when you add your extensions
|
||||
}
|
||||
|
||||
IEnumerator LoadFile (string path)
|
||||
{
|
||||
using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip ("file://" + path, AudioType.WAV)) {
|
||||
yield return www.SendWebRequest ();
|
||||
|
||||
if (www.error != null) {
|
||||
print ("some issue happening when trying to load file " + path);
|
||||
} else {
|
||||
AudioClip clip = DownloadHandlerAudioClip.GetContent (www);
|
||||
|
||||
clip.name = Path.GetFileName (path);
|
||||
|
||||
audioElements.Add (new AudioElement { clip = clip });
|
||||
|
||||
if (audioElements.Count == numberOfSongs) {
|
||||
songsLoaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//WWW www = new WWW ("file://" + path);
|
||||
//// print ("loading " + path);
|
||||
|
||||
//AudioClip clip = www.GetAudioClip (false);
|
||||
|
||||
//while (clip.loadState != AudioDataLoadState.Loaded) {
|
||||
// yield return www;
|
||||
//}
|
||||
|
||||
////print ("done loading");
|
||||
//clip.name = Path.GetFileName (path);
|
||||
|
||||
//audioElements.Add (new AudioElement { clip = clip });
|
||||
|
||||
//if (audioElements.Count == numberOfSongs) {
|
||||
// songsLoaded = true;
|
||||
//}
|
||||
}
|
||||
|
||||
public bool allSongsLoaded ()
|
||||
{
|
||||
return songsLoaded;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1344dbec6d5e14b4cb12f397ce539e24
|
||||
timeCreated: 1531189848
|
||||
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/Devices/Radio/songsManager.cs
|
||||
uploadId: 814740
|
||||
586
Assets/Game Kit Controller/Scripts/Devices/accessTerminal.cs
Normal file
586
Assets/Game Kit Controller/Scripts/Devices/accessTerminal.cs
Normal file
@@ -0,0 +1,586 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
using System.Reflection;
|
||||
using GameKitController.Audio;
|
||||
|
||||
public class accessTerminal : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public string code;
|
||||
|
||||
public LayerMask layer;
|
||||
public Color unlockedColor;
|
||||
public Color lockedColor;
|
||||
|
||||
public bool allowToUseKeyboard;
|
||||
public bool useMoveCameraToDevice;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public bool unlockThisTerminal;
|
||||
public bool disableCodeScreenAfterUnlock;
|
||||
|
||||
public float waitDelayAfterUnlock;
|
||||
|
||||
public bool setLockedStateTextEnabled = true;
|
||||
|
||||
public bool allowToToggleLockedState;
|
||||
|
||||
[Space]
|
||||
[Header ("Text Settings")]
|
||||
[Space]
|
||||
|
||||
public string backgroundPanelName = "terminal";
|
||||
|
||||
public string unlockedStateString = "Unlocked";
|
||||
public string lockedStateString = "Locked";
|
||||
|
||||
[Space]
|
||||
[Header ("Sound Settings")]
|
||||
[Space]
|
||||
|
||||
public AudioClip wrongPassSound;
|
||||
public AudioElement wrongPassAudioElement;
|
||||
public AudioClip corretPassSound;
|
||||
public AudioElement corretPassAudioElement;
|
||||
public AudioClip keyPressSound;
|
||||
public AudioElement keyPressAudioElement;
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventOnDeviceUnlocked;
|
||||
public UnityEvent eventOnDeviceUnlocked;
|
||||
|
||||
public bool useEventOnDeviceLocked;
|
||||
public UnityEvent eventOnDeviceLocked;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool usingDevice;
|
||||
|
||||
public bool unlocked;
|
||||
public bool locked;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public RectTransform pointer;
|
||||
public GameObject keys;
|
||||
public Text currectCode;
|
||||
public Text stateText;
|
||||
|
||||
public Image wallPaper;
|
||||
|
||||
public GameObject hackPanel;
|
||||
public GameObject hackActiveButton;
|
||||
|
||||
public GameObject codeScreen;
|
||||
public GameObject unlockedScreen;
|
||||
|
||||
public AudioSource audioSource;
|
||||
public electronicDevice deviceManager;
|
||||
public hackTerminal hackTerminalManager;
|
||||
|
||||
public gameManager mainGameManager;
|
||||
|
||||
List<Image> keysList = new List<Image> ();
|
||||
readonly List<RaycastResult> captureRaycastResults = new List<RaycastResult> ();
|
||||
|
||||
int totalKeysPressed = 0;
|
||||
|
||||
int length;
|
||||
bool changedColor;
|
||||
bool checkPressedButton;
|
||||
bool touchPlatform;
|
||||
RaycastHit hit;
|
||||
GameObject currentCaptured;
|
||||
Touch currentTouch;
|
||||
|
||||
GameObject currentPlayer;
|
||||
Camera mainCamera;
|
||||
|
||||
bool hackingTerminal;
|
||||
|
||||
bool keysInitialized;
|
||||
|
||||
Coroutine mainCoroutine;
|
||||
|
||||
|
||||
private void InitializeAudioElements ()
|
||||
{
|
||||
if (audioSource == null) {
|
||||
audioSource = GetComponent<AudioSource> ();
|
||||
}
|
||||
|
||||
if (audioSource != null) {
|
||||
wrongPassAudioElement.audioSource = audioSource;
|
||||
corretPassAudioElement.audioSource = audioSource;
|
||||
keyPressAudioElement.audioSource = audioSource;
|
||||
}
|
||||
|
||||
if (wrongPassSound != null) {
|
||||
wrongPassAudioElement.clip = wrongPassSound;
|
||||
}
|
||||
|
||||
if (corretPassSound != null) {
|
||||
corretPassAudioElement.clip = corretPassSound;
|
||||
}
|
||||
|
||||
if (keyPressSound != null) {
|
||||
keyPressAudioElement.clip = keyPressSound;
|
||||
}
|
||||
}
|
||||
|
||||
void initializeKeysElements ()
|
||||
{
|
||||
if (!keysInitialized) {
|
||||
Component[] components = keys.GetComponentsInChildren (typeof(Image));
|
||||
|
||||
foreach (Image child in components) {
|
||||
int n;
|
||||
|
||||
if (int.TryParse (child.name, out n)) {
|
||||
keysList.Add (child);
|
||||
}
|
||||
}
|
||||
|
||||
//set the current code to 0 according to the length of the real code
|
||||
currectCode.text = "";
|
||||
|
||||
length = code.Length;
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
currectCode.text += "0";
|
||||
}
|
||||
|
||||
keysInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Start ()
|
||||
{
|
||||
//get all the keys inside the keys gameobject, checking the name of every object, comparing if it is a number from 0 to 9
|
||||
touchPlatform = touchJoystick.checkTouchPlatform ();
|
||||
|
||||
if (hackPanel != null) {
|
||||
if (hackTerminalManager == null) {
|
||||
hackTerminalManager = hackPanel.GetComponent<hackTerminal> ();
|
||||
}
|
||||
|
||||
//hackActiveButton.SetActive (true);
|
||||
if (useMoveCameraToDevice) {
|
||||
hackTerminalManager.hasMoveCameraToDevice ();
|
||||
}
|
||||
}
|
||||
|
||||
InitializeAudioElements ();
|
||||
|
||||
if (deviceManager == null) {
|
||||
deviceManager = GetComponent<electronicDevice> ();
|
||||
}
|
||||
|
||||
bool mainGameManagerLocated = mainGameManager != null;
|
||||
|
||||
if (!mainGameManagerLocated) {
|
||||
mainGameManager = gameManager.Instance;
|
||||
|
||||
mainGameManagerLocated = mainGameManager != null;
|
||||
}
|
||||
|
||||
if (!mainGameManagerLocated) {
|
||||
mainGameManager = FindObjectOfType<gameManager> ();
|
||||
|
||||
mainGameManager.getComponentInstanceOnApplicationPlaying ();
|
||||
}
|
||||
}
|
||||
|
||||
public void stopUpdateCoroutine ()
|
||||
{
|
||||
if (mainCoroutine != null) {
|
||||
StopCoroutine (mainCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator updateCoroutine ()
|
||||
{
|
||||
// var waitTime = new WaitForFixedUpdate ();
|
||||
|
||||
var waitTime = new WaitForSecondsRealtime (0.00001f);
|
||||
|
||||
while (true) {
|
||||
updateState ();
|
||||
|
||||
yield return waitTime;
|
||||
}
|
||||
}
|
||||
|
||||
void updateState ()
|
||||
{
|
||||
//if the terminal still locked, and the player is using it
|
||||
if (usingDevice) {
|
||||
bool checkInputStateResult = false;
|
||||
|
||||
if (!unlocked) {
|
||||
checkInputStateResult = true;
|
||||
}
|
||||
|
||||
if (allowToToggleLockedState && !locked) {
|
||||
checkInputStateResult = true;
|
||||
}
|
||||
|
||||
if (checkInputStateResult) {
|
||||
if (!mainGameManager.isGamePaused ()) {
|
||||
//use the center of the camera as mouse, checking also the touch input
|
||||
int touchCount = Input.touchCount;
|
||||
if (!touchPlatform) {
|
||||
touchCount++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < touchCount; i++) {
|
||||
if (!touchPlatform) {
|
||||
currentTouch = touchJoystick.convertMouseIntoFinger ();
|
||||
} else {
|
||||
currentTouch = Input.GetTouch (i);
|
||||
}
|
||||
|
||||
//get a list with all the objects under the center of the screen of the finger tap
|
||||
captureRaycastResults.Clear ();
|
||||
PointerEventData p = new PointerEventData (EventSystem.current);
|
||||
p.position = currentTouch.position;
|
||||
p.clickCount = i;
|
||||
p.dragging = false;
|
||||
EventSystem.current.RaycastAll (p, captureRaycastResults);
|
||||
|
||||
foreach (RaycastResult r in captureRaycastResults) {
|
||||
currentCaptured = r.gameObject;
|
||||
//if the center of the camera is looking at the screen, move the cursor image inside it
|
||||
if (currentCaptured.name.Equals (backgroundPanelName)) {
|
||||
if (Physics.Raycast (mainCamera.ScreenPointToRay (currentTouch.position), out hit, Mathf.Infinity, layer)) {
|
||||
if (!hit.collider.isTrigger) {
|
||||
pointer.gameObject.transform.position = hit.point;
|
||||
Debug.DrawLine (mainCamera.transform.position, hit.point, Color.green, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
//check the current number key pressed with the finger
|
||||
if (currentTouch.phase == TouchPhase.Began) {
|
||||
checkButton (currentCaptured);
|
||||
}
|
||||
|
||||
//check the current number key preesed with the interaction button in the keyboard
|
||||
if (checkPressedButton) {
|
||||
checkButton (currentCaptured);
|
||||
}
|
||||
}
|
||||
|
||||
if (checkPressedButton) {
|
||||
checkPressedButton = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (allowToUseKeyboard) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (Input.GetKeyDown ("" + i)) {
|
||||
checkNumber (i.ToString ());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if the device is unlocked, change the color of the interface for the unlocked color
|
||||
if (unlocked) {
|
||||
if (!changedColor) {
|
||||
setPanelColor (unlockedColor);
|
||||
}
|
||||
}
|
||||
|
||||
if (locked) {
|
||||
if (!changedColor) {
|
||||
setPanelColor (lockedColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setPanelColor (Color newColor)
|
||||
{
|
||||
if (!changedColor) {
|
||||
wallPaper.color = Vector4.MoveTowards (wallPaper.color, newColor, Time.deltaTime * 3);
|
||||
stateText.color = Vector4.MoveTowards (stateText.color, newColor, Time.deltaTime * 3);
|
||||
|
||||
if (wallPaper.color == newColor && stateText.color == newColor) {
|
||||
changedColor = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void pressButtonOnScreen ()
|
||||
{
|
||||
checkPressedButton = true;
|
||||
}
|
||||
|
||||
//this function is called when the interaction button in the keyboard is pressed, so in pc, the code is written by aiming the center of the camera to
|
||||
//every number and pressing the interaction button. In touch devices, the code is written by tapping with the finger every key number directly
|
||||
public void activateTerminal ()
|
||||
{
|
||||
usingDevice = !usingDevice;
|
||||
|
||||
stopUpdateCoroutine ();
|
||||
|
||||
totalKeysPressed = 0;
|
||||
|
||||
initializeKeysElements ();
|
||||
|
||||
if (usingDevice) {
|
||||
getCurrentUser ();
|
||||
|
||||
mainCoroutine = StartCoroutine (updateCoroutine ());
|
||||
} else {
|
||||
if (hackingTerminal) {
|
||||
hackTerminalManager.stopHacking ();
|
||||
|
||||
hackingTerminal = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void enableTerminal ()
|
||||
{
|
||||
usingDevice = true;
|
||||
|
||||
mainCoroutine = StartCoroutine (updateCoroutine ());
|
||||
|
||||
initializeKeysElements ();
|
||||
|
||||
totalKeysPressed = 0;
|
||||
|
||||
getCurrentUser ();
|
||||
}
|
||||
|
||||
public void disableTerminal ()
|
||||
{
|
||||
usingDevice = false;
|
||||
|
||||
stopUpdateCoroutine ();
|
||||
|
||||
if (hackingTerminal) {
|
||||
hackTerminalManager.stopHacking ();
|
||||
|
||||
hackingTerminal = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void getCurrentUser ()
|
||||
{
|
||||
currentPlayer = deviceManager.getCurrentPlayer ();
|
||||
|
||||
if (currentPlayer != null) {
|
||||
mainCamera = currentPlayer.GetComponent<playerController> ().getPlayerCameraManager ().getMainCamera ();
|
||||
}
|
||||
}
|
||||
|
||||
//the currentCaptured is checked, to write the value of the number key in the screen device
|
||||
void checkButton (GameObject button)
|
||||
{
|
||||
Image currentImage = button.GetComponent<Image> ();
|
||||
|
||||
if (currentImage != null) {
|
||||
//check if the currentCaptured is a key number
|
||||
if (keysList.Contains (currentImage)) {
|
||||
checkNumber (currentImage.name);
|
||||
} else {
|
||||
if (hackActiveButton) {
|
||||
if (button == hackActiveButton) {
|
||||
if (hackTerminalManager != null) {
|
||||
hackTerminalManager.activeHack ();
|
||||
|
||||
hackingTerminal = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void checkNumber (string numberString)
|
||||
{
|
||||
//reset the code in the screen
|
||||
if (totalKeysPressed == 0) {
|
||||
currectCode.text = "";
|
||||
}
|
||||
|
||||
//add the current key number pressed to the code
|
||||
currectCode.text += numberString;
|
||||
|
||||
totalKeysPressed++;
|
||||
|
||||
//play the key press sound
|
||||
AudioPlayer.PlayOneShot (keyPressAudioElement, gameObject);
|
||||
|
||||
//if the player has pressed the an amount of key numbers equal to the lenght of the code, check if it is correct
|
||||
if (totalKeysPressed == length) {
|
||||
//if it is equal, then call the object to unlock, play the corret pass sound, and disable this terminal
|
||||
if (currectCode.text == code) {
|
||||
if (allowToToggleLockedState) {
|
||||
if (unlocked) {
|
||||
setLockedState (false);
|
||||
} else {
|
||||
setLockedState (true);
|
||||
}
|
||||
} else {
|
||||
setLockedState (true);
|
||||
}
|
||||
}
|
||||
//else, reset the terminal, and try again
|
||||
else {
|
||||
AudioPlayer.PlayOneShot (wrongPassAudioElement, gameObject);
|
||||
|
||||
totalKeysPressed = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setLockedState (bool state)
|
||||
{
|
||||
if (state) {
|
||||
AudioPlayer.PlayOneShot (corretPassAudioElement, gameObject);
|
||||
|
||||
if (setLockedStateTextEnabled) {
|
||||
stateText.text = unlockedStateString;
|
||||
}
|
||||
|
||||
changedColor = false;
|
||||
|
||||
unlocked = true;
|
||||
|
||||
locked = false;
|
||||
|
||||
if (!unlockThisTerminal) {
|
||||
deviceManager.unlockObject ();
|
||||
|
||||
StartCoroutine (waitingAfterUnlock ());
|
||||
}
|
||||
|
||||
if (hackPanel != null) {
|
||||
hackTerminalManager.moveHackTerminal (false);
|
||||
|
||||
hackingTerminal = false;
|
||||
}
|
||||
|
||||
if (disableCodeScreenAfterUnlock) {
|
||||
codeScreen.SetActive (false);
|
||||
|
||||
unlockedScreen.SetActive (true);
|
||||
}
|
||||
|
||||
checkEventOnLockedStateChange (true);
|
||||
} else {
|
||||
AudioPlayer.PlayOneShot (corretPassAudioElement, gameObject);
|
||||
|
||||
if (setLockedStateTextEnabled) {
|
||||
stateText.text = lockedStateString;
|
||||
}
|
||||
|
||||
changedColor = false;
|
||||
|
||||
unlocked = false;
|
||||
|
||||
locked = true;
|
||||
|
||||
checkEventOnLockedStateChange (false);
|
||||
}
|
||||
}
|
||||
|
||||
void checkEventOnLockedStateChange (bool state)
|
||||
{
|
||||
if (state) {
|
||||
if (useEventOnDeviceUnlocked) {
|
||||
eventOnDeviceUnlocked.Invoke ();
|
||||
}
|
||||
|
||||
} else {
|
||||
if (useEventOnDeviceLocked) {
|
||||
eventOnDeviceLocked.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setLockState (Scrollbar info)
|
||||
{
|
||||
if (info.value == 0) {
|
||||
deviceManager.lockObject ();
|
||||
|
||||
if (info.value > 0) {
|
||||
info.value = 0;
|
||||
}
|
||||
} else if (info.value == 1) {
|
||||
deviceManager.unlockObject ();
|
||||
|
||||
if (info.value < 1) {
|
||||
info.value = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator waitingAfterUnlock ()
|
||||
{
|
||||
yield return new WaitForSeconds (waitDelayAfterUnlock);
|
||||
|
||||
deviceManager.stopUsindDevice ();
|
||||
|
||||
if (usingDevice) {
|
||||
activateTerminal ();
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
public void showPasswordOnHackPanel ()
|
||||
{
|
||||
hackTerminalManager.setTextContent (code);
|
||||
}
|
||||
|
||||
public void unlockAccessTerminal ()
|
||||
{
|
||||
currectCode.text = "";
|
||||
|
||||
totalKeysPressed = code.Length - 1;
|
||||
|
||||
checkNumber (code);
|
||||
}
|
||||
|
||||
public void activateHackButton ()
|
||||
{
|
||||
if (hackActiveButton != null) {
|
||||
hackActiveButton.SetActive (true);
|
||||
}
|
||||
}
|
||||
|
||||
public void setNewCode (string newCode)
|
||||
{
|
||||
code = newCode;
|
||||
|
||||
currectCode.text = "";
|
||||
|
||||
length = code.Length;
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
currectCode.text += "0";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8805623004adad4468af0ab9716d9d9d
|
||||
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/Devices/accessTerminal.cs
|
||||
uploadId: 814740
|
||||
487
Assets/Game Kit Controller/Scripts/Devices/closetSystem.cs
Normal file
487
Assets/Game Kit Controller/Scripts/Devices/closetSystem.cs
Normal file
@@ -0,0 +1,487 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using GameKitController.Audio;
|
||||
using UnityEngine;
|
||||
|
||||
public class closetSystem : MonoBehaviour
|
||||
{
|
||||
public List<closetDoorInfo> closetDoorList = new List<closetDoorInfo> ();
|
||||
|
||||
public doorOpenType openType;
|
||||
|
||||
public enum doorOpenType
|
||||
{
|
||||
translate,
|
||||
rotate
|
||||
}
|
||||
|
||||
public bool useSounds;
|
||||
|
||||
public bool showGizmo;
|
||||
public float gizmoRadius;
|
||||
public float gizmoArrowLength = 1;
|
||||
public float gizmoArrowLineLength = 2.5f;
|
||||
public float gizmoArrowAngle = 20;
|
||||
public Color gizmoArrowColor = Color.white;
|
||||
public Color gizmoLabelColor = Color.black;
|
||||
|
||||
int numberOfDoors;
|
||||
GameObject currentPlayer;
|
||||
usingDevicesSystem currentUsingDevicesSystem;
|
||||
|
||||
GameObject objectToAddToCloset;
|
||||
GameObject objectToRemoveFromCloset;
|
||||
|
||||
bool objectsToSpawnChecked;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
for (int i = 0; i < closetDoorList.Count; i++) {
|
||||
closetDoorList [i].originalPosition = closetDoorList [i].doorTransform.position;
|
||||
closetDoorList [i].originalRotation = closetDoorList [i].doorTransform.rotation;
|
||||
closetDoorList [i].deviceStringActionManager = closetDoorList [i].doorTransform.GetComponentInChildren<deviceStringAction> ();
|
||||
|
||||
if (useSounds) {
|
||||
closetDoorList [i].InitializeAudioElements ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void changeDoorOpenCloseState (Transform currentDoor)
|
||||
{
|
||||
int doorIndex = -1;
|
||||
|
||||
for (int i = 0; i < closetDoorList.Count; i++) {
|
||||
if (closetDoorList [i].doorTransform == currentDoor) {
|
||||
doorIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (doorIndex > -1) {
|
||||
closetDoorInfo currentDoorInfo = closetDoorList [doorIndex];
|
||||
//stop the coroutine to translate the camera and call it again
|
||||
if (currentDoorInfo.doorMovement != null) {
|
||||
StopCoroutine (currentDoorInfo.doorMovement);
|
||||
}
|
||||
|
||||
currentDoorInfo.doorMovement = StartCoroutine (openOrCloseDoorCoroutine (currentDoorInfo));
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator openOrCloseDoorCoroutine (closetDoorInfo currentDoorInfo)
|
||||
{
|
||||
Vector3 targetPosition = currentDoorInfo.originalPosition;
|
||||
Quaternion targetRotation = currentDoorInfo.originalRotation;
|
||||
|
||||
if (currentDoorInfo.useCloseRotationTransform) {
|
||||
targetRotation = currentDoorInfo.closeRotationTransform.rotation;
|
||||
}
|
||||
|
||||
bool openingDoor = false;
|
||||
|
||||
if (!currentDoorInfo.opened) {
|
||||
if (openType == doorOpenType.translate) {
|
||||
targetPosition = currentDoorInfo.openedPosition.position;
|
||||
}
|
||||
|
||||
if (openType == doorOpenType.rotate) {
|
||||
targetRotation = currentDoorInfo.rotatedPosition.rotation;
|
||||
}
|
||||
|
||||
openingDoor = true;
|
||||
}
|
||||
|
||||
if (useSounds) {
|
||||
GKC_Utils.checkAudioSourcePitch (currentDoorInfo.mainAudioSource);
|
||||
|
||||
if (openingDoor) {
|
||||
AudioPlayer.PlayOneShot (currentDoorInfo.openAudioElement, gameObject);
|
||||
} else {
|
||||
AudioPlayer.PlayOneShot (currentDoorInfo.closeAudioElement, gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
if (openingDoor) {
|
||||
spawnObjectsOnPlace (currentDoorInfo);
|
||||
|
||||
for (int j = 0; j < currentDoorInfo.objectsInDoor.Count; j++) {
|
||||
if (currentDoorInfo.objectsInDoor [j] != null) {
|
||||
if (currentDoorInfo.objectsInDoor [j].activeSelf != true) {
|
||||
currentDoorInfo.objectsInDoor [j].SetActive (true);
|
||||
}
|
||||
} else {
|
||||
currentDoorInfo.objectsInDoor.RemoveAt (j);
|
||||
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!currentDoorInfo.onlyOneDoor) {
|
||||
for (int i = 0; i < currentDoorInfo.othersDoors.Count; i++) {
|
||||
for (int j = 0; j < closetDoorList.Count; j++) {
|
||||
if (closetDoorList [j].doorTransform == currentDoorInfo.othersDoors [i]) {
|
||||
|
||||
spawnObjectsOnPlace (closetDoorList [j]);
|
||||
|
||||
for (int k = 0; k < closetDoorList [j].objectsInDoor.Count; k++) {
|
||||
if (closetDoorList [j].objectsInDoor [k] != null) {
|
||||
if (closetDoorList [j].objectsInDoor [k].activeSelf != true) {
|
||||
closetDoorList [j].objectsInDoor [k].SetActive (true);
|
||||
}
|
||||
} else {
|
||||
closetDoorList [j].objectsInDoor.RemoveAt (k);
|
||||
|
||||
k = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((currentDoorInfo.canBeOpened && openingDoor) || (currentDoorInfo.canBeClosed && !openingDoor)) {
|
||||
if (currentDoorInfo.deviceStringActionManager != null) {
|
||||
currentDoorInfo.deviceStringActionManager.changeActionName (openingDoor);
|
||||
}
|
||||
|
||||
if (openType == doorOpenType.translate) {
|
||||
float dist = GKC_Utils.distance (currentDoorInfo.doorTransform.position, targetPosition);
|
||||
float duration = dist / currentDoorInfo.openSpeed;
|
||||
float t = 0;
|
||||
|
||||
Vector3 currentDoorPosition = currentDoorInfo.doorTransform.position;
|
||||
|
||||
while (t < 1) {
|
||||
t += Time.deltaTime / duration;
|
||||
|
||||
currentDoorInfo.doorTransform.position = Vector3.Slerp (currentDoorPosition, targetPosition, t);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (openType == doorOpenType.rotate) {
|
||||
float t = 0;
|
||||
|
||||
Quaternion currentDoorRotation = currentDoorInfo.doorTransform.rotation;
|
||||
|
||||
while (t < 1 && currentDoorInfo.doorTransform.rotation != targetRotation) {
|
||||
t += Time.deltaTime * currentDoorInfo.openSpeed;
|
||||
|
||||
currentDoorInfo.doorTransform.rotation = Quaternion.Slerp (currentDoorRotation, targetRotation, t);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (openingDoor) {
|
||||
currentDoorInfo.opened = true;
|
||||
currentDoorInfo.closed = false;
|
||||
} else {
|
||||
currentDoorInfo.opened = false;
|
||||
currentDoorInfo.closed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!openingDoor) {
|
||||
bool totallyClosed = false;
|
||||
|
||||
if (currentDoorInfo.onlyOneDoor) {
|
||||
totallyClosed = true;
|
||||
} else {
|
||||
numberOfDoors = 1;
|
||||
|
||||
for (int j = 0; j < currentDoorInfo.othersDoors.Count; j++) {
|
||||
for (int i = 0; i < closetDoorList.Count; i++) {
|
||||
if (closetDoorList [i].doorTransform == currentDoorInfo.othersDoors [j] && closetDoorList [i].closed) {
|
||||
numberOfDoors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (numberOfDoors == closetDoorList.Count) {
|
||||
totallyClosed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// print ("is closed: " + totallyClosed);
|
||||
|
||||
if (totallyClosed) {
|
||||
//only disable these objects if they still inside the closet
|
||||
//also, other objects placed inside must be disabled
|
||||
if (currentDoorInfo.onlyOneDoor) {
|
||||
for (int j = 0; j < currentDoorInfo.objectsInDoor.Count; j++) {
|
||||
if (currentDoorInfo.objectsInDoor [j] != null) {
|
||||
removeDeviceFromList (currentDoorInfo.objectsInDoor [j]);
|
||||
|
||||
if (currentDoorInfo.objectsInDoor [j].activeSelf != false) {
|
||||
currentDoorInfo.objectsInDoor [j].SetActive (false);
|
||||
}
|
||||
} else {
|
||||
currentDoorInfo.objectsInDoor.RemoveAt (j);
|
||||
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < closetDoorList.Count; i++) {
|
||||
for (int j = 0; j < closetDoorList [i].objectsInDoor.Count; j++) {
|
||||
if (closetDoorList [i].objectsInDoor [j] != null) {
|
||||
// print (closetDoorList [i].objectsInDoor [j].name);
|
||||
|
||||
removeDeviceFromList (closetDoorList [i].objectsInDoor [j]);
|
||||
|
||||
if (closetDoorList [i].objectsInDoor [j].activeSelf != false) {
|
||||
closetDoorList [i].objectsInDoor [j].SetActive (false);
|
||||
}
|
||||
} else {
|
||||
closetDoorList [i].objectsInDoor.RemoveAt (j);
|
||||
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void spawnObjectsOnPlace (closetDoorInfo currentDoorInfo)
|
||||
{
|
||||
if (currentDoorInfo.spawnObjectsInsideAtStart && !currentDoorInfo.objectsInsideSpawned) {
|
||||
for (int j = 0; j < currentDoorInfo.objectToSpawInfoList.Count; j++) {
|
||||
GameObject newObject = (GameObject)Instantiate (currentDoorInfo.objectToSpawInfoList [j].objectToSpawn,
|
||||
currentDoorInfo.objectToSpawInfoList [j].positionToSpawn.position,
|
||||
currentDoorInfo.objectToSpawInfoList [j].positionToSpawn.rotation);
|
||||
|
||||
newObject.transform.SetParent (currentDoorInfo.objectToSpawInfoList [j].positionToSpawn);
|
||||
|
||||
currentDoorInfo.objectsInDoor.Add (newObject);
|
||||
}
|
||||
|
||||
currentDoorInfo.objectsInsideSpawned = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentPlayer (GameObject player)
|
||||
{
|
||||
currentPlayer = player;
|
||||
|
||||
if (currentPlayer != null) {
|
||||
currentUsingDevicesSystem = currentPlayer.GetComponent<usingDevicesSystem> ();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeDeviceFromList (GameObject objecToRemove)
|
||||
{
|
||||
if (currentPlayer != null) {
|
||||
currentUsingDevicesSystem.removeDeviceFromListUsingParent (objecToRemove);
|
||||
}
|
||||
}
|
||||
|
||||
public void setObjectToAddToCloset (GameObject objectToAdd)
|
||||
{
|
||||
objectToAddToCloset = objectToAdd;
|
||||
}
|
||||
|
||||
public void setObjectToRemoveFromCloset (GameObject objectToRemove)
|
||||
{
|
||||
objectToRemoveFromCloset = objectToRemove;
|
||||
}
|
||||
|
||||
|
||||
public void addObjectToCloset (Transform doorToAdd)
|
||||
{
|
||||
simpleActionButton currentSimpleActionButton = objectToAddToCloset.GetComponent<simpleActionButton> ();
|
||||
|
||||
if (currentSimpleActionButton != null) {
|
||||
|
||||
GameObject currentObjectToAdd = currentSimpleActionButton.objectToActive;
|
||||
|
||||
for (int i = 0; i < closetDoorList.Count; i++) {
|
||||
for (int j = 0; j < closetDoorList [i].objectsInDoor.Count; j++) {
|
||||
if (closetDoorList [i].objectsInDoor.Contains (currentObjectToAdd)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < closetDoorList.Count; i++) {
|
||||
if (closetDoorList [i].doorTransform == doorToAdd && closetDoorList [i].opened) {
|
||||
if (!closetDoorList [i].objectsInDoor.Contains (currentObjectToAdd)) {
|
||||
closetDoorList [i].objectsInDoor.Add (currentObjectToAdd);
|
||||
|
||||
if (openType == doorOpenType.translate) {
|
||||
currentObjectToAdd.transform.SetParent (closetDoorList [i].doorTransform);
|
||||
} else {
|
||||
currentObjectToAdd.transform.SetParent (transform);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeObjectFromCloset (Transform doorToAdd)
|
||||
{
|
||||
GameObject currentObjectToAdd = objectToRemoveFromCloset.GetComponent<simpleActionButton> ().objectToActive;
|
||||
|
||||
for (int i = 0; i < closetDoorList.Count; i++) {
|
||||
if (closetDoorList [i].doorTransform == doorToAdd) {
|
||||
if (closetDoorList [i].objectsInDoor.Contains (currentObjectToAdd)) {
|
||||
closetDoorList [i].objectsInDoor.Remove (currentObjectToAdd);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addNewDoor ()
|
||||
{
|
||||
closetDoorInfo newClosetDoorInfo = new closetDoorInfo ();
|
||||
|
||||
newClosetDoorInfo.Name = "New Door";
|
||||
|
||||
closetDoorList.Add (newClosetDoorInfo);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
}
|
||||
|
||||
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) {
|
||||
for (int i = 0; i < closetDoorList.Count; i++) {
|
||||
if (closetDoorList [i].doorTransform != null) {
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawSphere (closetDoorList [i].doorTransform.position, gizmoRadius);
|
||||
|
||||
if (openType == doorOpenType.translate) {
|
||||
if (closetDoorList [i].openedPosition != null) {
|
||||
Gizmos.color = Color.green;
|
||||
|
||||
Gizmos.DrawSphere (closetDoorList [i].openedPosition.position, gizmoRadius);
|
||||
|
||||
Gizmos.color = Color.white;
|
||||
|
||||
Gizmos.DrawLine (closetDoorList [i].doorTransform.position, closetDoorList [i].openedPosition.position);
|
||||
}
|
||||
}
|
||||
|
||||
if (openType == doorOpenType.rotate) {
|
||||
if (closetDoorList [i].rotatedPosition != null) {
|
||||
Gizmos.color = Color.green;
|
||||
|
||||
GKC_Utils.drawGizmoArrow (closetDoorList [i].rotatedPosition.position, closetDoorList [i].rotatedPosition.right * gizmoArrowLineLength,
|
||||
gizmoArrowColor, gizmoArrowLength, gizmoArrowAngle);
|
||||
|
||||
Gizmos.color = Color.white;
|
||||
Gizmos.DrawLine (closetDoorList [i].doorTransform.position, closetDoorList [i].rotatedPosition.position);
|
||||
}
|
||||
|
||||
if (closetDoorList [i].useCloseRotationTransform) {
|
||||
Gizmos.color = Color.green;
|
||||
|
||||
GKC_Utils.drawGizmoArrow (closetDoorList [i].closeRotationTransform.position, closetDoorList [i].closeRotationTransform.right * gizmoArrowLineLength,
|
||||
gizmoArrowColor, gizmoArrowLength, gizmoArrowAngle);
|
||||
|
||||
Gizmos.color = Color.white;
|
||||
|
||||
Gizmos.DrawLine (closetDoorList [i].doorTransform.position, closetDoorList [i].closeRotationTransform.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class closetDoorInfo
|
||||
{
|
||||
public string Name;
|
||||
public float openSpeed;
|
||||
public Transform doorTransform;
|
||||
public Transform openedPosition;
|
||||
public Transform rotatedPosition;
|
||||
|
||||
public bool canBeOpened = true;
|
||||
public bool canBeClosed = true;
|
||||
public bool opened;
|
||||
public bool closed;
|
||||
|
||||
public List<GameObject> objectsInDoor = new List<GameObject> ();
|
||||
|
||||
public bool spawnObjectsInsideAtStart;
|
||||
public List<objectToSpawInfo> objectToSpawInfoList = new List<objectToSpawInfo> ();
|
||||
public bool objectsInsideSpawned;
|
||||
|
||||
public bool onlyOneDoor;
|
||||
public List<Transform> othersDoors = new List<Transform> ();
|
||||
|
||||
public AudioClip openSound;
|
||||
public AudioElement openAudioElement;
|
||||
public AudioClip closeSound;
|
||||
public AudioElement closeAudioElement;
|
||||
|
||||
public bool useCloseRotationTransform;
|
||||
public Transform closeRotationTransform;
|
||||
[HideInInspector] public AudioSource mainAudioSource;
|
||||
|
||||
[HideInInspector] public Vector3 originalPosition;
|
||||
[HideInInspector] public Quaternion originalRotation;
|
||||
|
||||
[HideInInspector] public Coroutine doorMovement;
|
||||
|
||||
[HideInInspector] public deviceStringAction deviceStringActionManager;
|
||||
|
||||
public void InitializeAudioElements ()
|
||||
{
|
||||
mainAudioSource = doorTransform.GetComponent<AudioSource> ();
|
||||
|
||||
if (openSound != null) {
|
||||
openAudioElement.clip = openSound;
|
||||
}
|
||||
|
||||
if (closeSound != null) {
|
||||
closeAudioElement.clip = closeSound;
|
||||
}
|
||||
|
||||
if (mainAudioSource != null) {
|
||||
openAudioElement.audioSource = mainAudioSource;
|
||||
closeAudioElement.audioSource = mainAudioSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class objectToSpawInfo
|
||||
{
|
||||
public GameObject objectToSpawn;
|
||||
public Transform positionToSpawn;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bed302ac73652014fa33826c49322aab
|
||||
timeCreated: 1523072904
|
||||
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/Devices/closetSystem.cs
|
||||
uploadId: 814740
|
||||
443
Assets/Game Kit Controller/Scripts/Devices/computerDevice.cs
Normal file
443
Assets/Game Kit Controller/Scripts/Devices/computerDevice.cs
Normal file
@@ -0,0 +1,443 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
using System.Reflection;
|
||||
using GameKitController.Audio;
|
||||
|
||||
public class computerDevice : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool locked;
|
||||
|
||||
public string code;
|
||||
|
||||
public Color unlockedColor;
|
||||
|
||||
public int numberLetterToStartToMovePasswordText;
|
||||
public float passwordTextMoveDistacePerLetter;
|
||||
public bool allowToUseKeyboard;
|
||||
|
||||
public bool disableUseDeviceActionButton;
|
||||
|
||||
[Space]
|
||||
[Header ("Sound Settings")]
|
||||
[Space]
|
||||
|
||||
public AudioClip wrongPassSound;
|
||||
public AudioElement wrongPassAudioElement;
|
||||
public AudioClip corretPassSound;
|
||||
public AudioElement corretPassAudioElement;
|
||||
public AudioClip keyPressSound;
|
||||
public AudioElement keyPressAudioElement;
|
||||
|
||||
[Space]
|
||||
[Header ("Allowed Key List Settings")]
|
||||
[Space]
|
||||
|
||||
public List<string> allowedKeysList = new List<string> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Text Settings")]
|
||||
[Space]
|
||||
|
||||
public string passwordText = "Password";
|
||||
public string unlockedText = "Unlocked";
|
||||
|
||||
public string leftShiftKey = "leftshift";
|
||||
|
||||
public string numberKey = "alpha";
|
||||
public string spaceKey = "space";
|
||||
public string deleteKey = "delete";
|
||||
public string backSpaceKey = "backspace";
|
||||
public string enterKey = "enter";
|
||||
public string returnKey = "return";
|
||||
public string capsLockKey = "capslock";
|
||||
|
||||
|
||||
[Space]
|
||||
[Header ("Debug Settings")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
public bool usingDevice;
|
||||
public bool printKeysPressed;
|
||||
|
||||
public List<Image> keysList = new List<Image> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventOnComputerUnlocked;
|
||||
public UnityEvent eventOnComputerUnlocked;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public GameObject keyboard;
|
||||
public Text currentCode;
|
||||
public Text stateText;
|
||||
public GameObject computerLockedContent;
|
||||
public GameObject computerUnlockedContent;
|
||||
public Image wallPaper;
|
||||
|
||||
public AudioSource audioSource;
|
||||
public electronicDevice deviceManager;
|
||||
|
||||
public inputManager input;
|
||||
|
||||
readonly List<RaycastResult> captureRaycastResults = new List<RaycastResult> ();
|
||||
int totalKeysPressed = 0;
|
||||
bool changeScreen;
|
||||
bool unlocked;
|
||||
bool changedColor;
|
||||
bool touchPlatform;
|
||||
GameObject currentCaptured;
|
||||
Touch currentTouch;
|
||||
|
||||
string currentKeyPressed;
|
||||
bool letterAdded;
|
||||
Vector3 originalCurrentCodePosition;
|
||||
string originalKeyPressed;
|
||||
bool capsLockActivated;
|
||||
|
||||
GameObject currentPlayer;
|
||||
usingDevicesSystem usingDevicesManager;
|
||||
float lastTimeComputerActive;
|
||||
|
||||
RectTransform currentCodeRectTransform;
|
||||
|
||||
|
||||
private void InitializeAudioElements ()
|
||||
{
|
||||
if (audioSource == null) {
|
||||
audioSource = GetComponent<AudioSource> ();
|
||||
}
|
||||
|
||||
if (audioSource != null) {
|
||||
wrongPassAudioElement.audioSource = audioSource;
|
||||
corretPassAudioElement.audioSource = audioSource;
|
||||
keyPressAudioElement.audioSource = audioSource;
|
||||
}
|
||||
|
||||
if (wrongPassSound != null) {
|
||||
wrongPassAudioElement.clip = wrongPassSound;
|
||||
}
|
||||
|
||||
if (corretPassSound != null) {
|
||||
corretPassAudioElement.clip = corretPassSound;
|
||||
}
|
||||
|
||||
if (keyPressSound != null) {
|
||||
keyPressAudioElement.clip = keyPressSound;
|
||||
}
|
||||
}
|
||||
|
||||
void Start ()
|
||||
{
|
||||
//get all the keys button in the keyboard and store them in a list
|
||||
if (keyboard != null) {
|
||||
Component[] components = keyboard.GetComponentsInChildren (typeof(Image));
|
||||
foreach (Image child in components) {
|
||||
keysList.Add (child);
|
||||
}
|
||||
}
|
||||
|
||||
touchPlatform = touchJoystick.checkTouchPlatform ();
|
||||
|
||||
if (!locked) {
|
||||
if (computerLockedContent != null) {
|
||||
computerLockedContent.SetActive (false);
|
||||
}
|
||||
|
||||
if (computerUnlockedContent != null) {
|
||||
computerUnlockedContent.SetActive (true);
|
||||
}
|
||||
}
|
||||
|
||||
InitializeAudioElements ();
|
||||
|
||||
if (deviceManager == null) {
|
||||
deviceManager = GetComponent<electronicDevice> ();
|
||||
}
|
||||
|
||||
bool inputManagerLocated = input != null;
|
||||
|
||||
if (!inputManagerLocated) {
|
||||
input = inputManager.Instance;
|
||||
|
||||
inputManagerLocated = input != null;
|
||||
}
|
||||
|
||||
if (!inputManagerLocated) {
|
||||
input = FindObjectOfType<inputManager> ();
|
||||
|
||||
input.getComponentInstanceOnApplicationPlaying ();
|
||||
|
||||
inputManagerLocated = input != null;
|
||||
}
|
||||
|
||||
if (currentCode != null) {
|
||||
currentCodeRectTransform = currentCode.GetComponent<RectTransform> ();
|
||||
|
||||
originalCurrentCodePosition = currentCodeRectTransform.localPosition;
|
||||
}
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
//if the computer is locked and the player is inside its trigger
|
||||
if (!unlocked && usingDevice && locked) {
|
||||
//get all the input touchs, including the mouse
|
||||
int touchCount = Input.touchCount;
|
||||
if (!touchPlatform) {
|
||||
touchCount++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < touchCount; i++) {
|
||||
if (!touchPlatform) {
|
||||
currentTouch = touchJoystick.convertMouseIntoFinger ();
|
||||
} else {
|
||||
currentTouch = Input.GetTouch (i);
|
||||
}
|
||||
|
||||
//get a list with all the objects under mouse or the finger tap
|
||||
captureRaycastResults.Clear ();
|
||||
PointerEventData p = new PointerEventData (EventSystem.current);
|
||||
p.position = currentTouch.position;
|
||||
p.clickCount = i;
|
||||
p.dragging = false;
|
||||
EventSystem.current.RaycastAll (p, captureRaycastResults);
|
||||
foreach (RaycastResult r in captureRaycastResults) {
|
||||
currentCaptured = r.gameObject;
|
||||
//check the current key pressed with the finger
|
||||
if (currentTouch.phase == TouchPhase.Began) {
|
||||
checkButton (currentCaptured);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Time.time > lastTimeComputerActive + 0.3f) {
|
||||
if (allowToUseKeyboard) {
|
||||
currentKeyPressed = input.getKeyPressed (inputManager.buttonType.getKeyDown, false);
|
||||
|
||||
if (currentKeyPressed != "") {
|
||||
checkKeyPressed (currentKeyPressed);
|
||||
}
|
||||
|
||||
currentKeyPressed = input.getKeyPressed (inputManager.buttonType.getKeyUp, false);
|
||||
|
||||
if (currentKeyPressed.ToLower () == leftShiftKey) {
|
||||
capsLockActivated = !capsLockActivated;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if the device is unlocked, change the color of the interface for the unlocked color
|
||||
if (unlocked) {
|
||||
if (!changedColor) {
|
||||
wallPaper.color = Vector4.MoveTowards (wallPaper.color, unlockedColor, Time.deltaTime * 3);
|
||||
stateText.color = Vector4.MoveTowards (stateText.color, unlockedColor, Time.deltaTime * 3);
|
||||
|
||||
if (wallPaper.color == unlockedColor && stateText.color == unlockedColor) {
|
||||
changedColor = true;
|
||||
}
|
||||
} else {
|
||||
//change the password screen for the unlocked screen
|
||||
if (changeScreen) {
|
||||
computerLockedContent.SetActive (false);
|
||||
computerUnlockedContent.SetActive (true);
|
||||
changeScreen = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//activate the device
|
||||
public void activateComputer ()
|
||||
{
|
||||
usingDevice = !usingDevice;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("Setting using computer state " + usingDevice);
|
||||
}
|
||||
|
||||
if (disableUseDeviceActionButton) {
|
||||
if (currentPlayer == null) {
|
||||
currentPlayer = deviceManager.getCurrentPlayer ();
|
||||
|
||||
usingDevicesManager = currentPlayer.GetComponent<usingDevicesSystem> ();
|
||||
}
|
||||
|
||||
if (currentPlayer != null) {
|
||||
usingDevicesManager.setUseDeviceButtonEnabledState (!usingDevice);
|
||||
}
|
||||
}
|
||||
|
||||
if (usingDevice) {
|
||||
lastTimeComputerActive = Time.time;
|
||||
}
|
||||
}
|
||||
|
||||
//the currentCaptured is checked, to write the value of the key in the screen device
|
||||
void checkButton (GameObject button)
|
||||
{
|
||||
Image currentImage = button.GetComponent<Image> ();
|
||||
|
||||
if (currentImage != null) {
|
||||
//check if the currentCaptured is a key number
|
||||
if (keysList.Contains (currentImage)) {
|
||||
checkKeyPressed (button.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void checkKeyPressed (string keyPressed)
|
||||
{
|
||||
originalKeyPressed = keyPressed;
|
||||
|
||||
keyPressed = keyPressed.ToLower ();
|
||||
|
||||
if (!allowedKeysList.Contains (keyPressed)) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool checkPass = false;
|
||||
|
||||
letterAdded = true;
|
||||
|
||||
if (printKeysPressed) {
|
||||
if (showDebugPrint) {
|
||||
print (keyPressed);
|
||||
}
|
||||
}
|
||||
|
||||
//reset the password in the screen
|
||||
if (totalKeysPressed == 0) {
|
||||
currentCode.text = "";
|
||||
}
|
||||
|
||||
if (keyPressed.Contains (numberKey)) {
|
||||
if (showDebugPrint) {
|
||||
print (keyPressed);
|
||||
}
|
||||
|
||||
keyPressed = keyPressed.Substring (keyPressed.Length - 1);
|
||||
originalKeyPressed = keyPressed;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print (keyPressed);
|
||||
}
|
||||
}
|
||||
|
||||
//add the an space
|
||||
if (keyPressed == spaceKey) {
|
||||
currentCode.text += " ";
|
||||
}
|
||||
|
||||
//delete the last character
|
||||
else if (keyPressed == deleteKey || keyPressed == backSpaceKey) {
|
||||
if (currentCode.text.Length > 0) {
|
||||
currentCode.text = currentCode.text.Remove (currentCode.text.Length - 1);
|
||||
|
||||
letterAdded = false;
|
||||
}
|
||||
}
|
||||
|
||||
//check the current word added
|
||||
else if (keyPressed == enterKey || keyPressed == returnKey) {
|
||||
checkPass = true;
|
||||
}
|
||||
|
||||
//check if the caps are being using
|
||||
else if (keyPressed == capsLockKey || keyPressed == leftShiftKey) {
|
||||
capsLockActivated = !capsLockActivated;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//add the current key pressed to the password
|
||||
else {
|
||||
if (capsLockActivated) {
|
||||
originalKeyPressed = originalKeyPressed.ToUpper ();
|
||||
} else {
|
||||
originalKeyPressed = originalKeyPressed.ToLower ();
|
||||
}
|
||||
|
||||
currentCode.text += originalKeyPressed;
|
||||
}
|
||||
|
||||
totalKeysPressed = currentCode.text.Length;
|
||||
|
||||
//play the key press sound
|
||||
playSound (keyPressAudioElement);
|
||||
|
||||
//the enter key has been pressed, so check if the current text written is the correct password
|
||||
if (checkPass) {
|
||||
if (currentCode.text == code) {
|
||||
enableAccessToCompturer ();
|
||||
}
|
||||
//else, reset the terminal, and try again
|
||||
else {
|
||||
playSound (wrongPassAudioElement);
|
||||
|
||||
currentCode.text = passwordText;
|
||||
|
||||
totalKeysPressed = 0;
|
||||
|
||||
currentCodeRectTransform.localPosition = originalCurrentCodePosition;
|
||||
}
|
||||
} else if (totalKeysPressed > numberLetterToStartToMovePasswordText) {
|
||||
if (letterAdded) {
|
||||
currentCodeRectTransform.localPosition -= new Vector3 (passwordTextMoveDistacePerLetter, 0, 0);
|
||||
} else {
|
||||
currentCodeRectTransform.localPosition += new Vector3 (passwordTextMoveDistacePerLetter, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if the object to unlock is this device, change the screen
|
||||
public void unlockComputer ()
|
||||
{
|
||||
changeScreen = true;
|
||||
}
|
||||
|
||||
public void enableAccessToCompturer ()
|
||||
{
|
||||
//if it is equal, then call the object to unlock and play the corret pass sound
|
||||
playSound (corretPassAudioElement);
|
||||
|
||||
stateText.text = unlockedText;
|
||||
|
||||
unlocked = true;
|
||||
|
||||
//the object to unlock can be also this terminal, to see more content inside it
|
||||
deviceManager.unlockObject ();
|
||||
|
||||
if (useEventOnComputerUnlocked) {
|
||||
eventOnComputerUnlocked.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
public void unlockComputerWithUsb ()
|
||||
{
|
||||
unlockComputer ();
|
||||
|
||||
enableAccessToCompturer ();
|
||||
}
|
||||
|
||||
public void playSound (AudioElement clipToPlay)
|
||||
{
|
||||
if (clipToPlay != null) {
|
||||
AudioPlayer.PlayOneShot (clipToPlay, gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
fileFormatVersion: 2
|
||||
guid: defce520015771f4394de82db1cb7cb6
|
||||
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/Devices/computerDevice.cs
|
||||
uploadId: 814740
|
||||
252
Assets/Game Kit Controller/Scripts/Devices/deviceStringAction.cs
Normal file
252
Assets/Game Kit Controller/Scripts/Devices/deviceStringAction.cs
Normal file
@@ -0,0 +1,252 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class deviceStringAction : MonoBehaviour
|
||||
{
|
||||
public string deviceName;
|
||||
public string deviceAction;
|
||||
|
||||
public bool useMultipleInteraction;
|
||||
public List<string> multipleInteractionNameList = new List<string> ();
|
||||
|
||||
public string secondaryDeviceAction;
|
||||
public bool reloadDeviceActionOnPress;
|
||||
public bool hideIconOnPress;
|
||||
public bool disableIconOnPress;
|
||||
public bool showIcon;
|
||||
public bool showTouchIconButton;
|
||||
|
||||
public bool hideIconOnUseDevice;
|
||||
public bool showIconOnStopUseDevice;
|
||||
|
||||
public bool useTransformForStringAction;
|
||||
public Transform transformForStringAction;
|
||||
|
||||
public bool useSeparatedTransformForEveryView;
|
||||
public Transform transformForThirdPerson;
|
||||
public Transform transformForFirstPerson;
|
||||
|
||||
public bool useLocalOffset = true;
|
||||
public float actionOffset = 1;
|
||||
|
||||
public bool setUsingDeviceState;
|
||||
|
||||
public bool setTextFontSizeActive;
|
||||
public int textFontSize = 17;
|
||||
|
||||
public bool iconEnabled = true;
|
||||
|
||||
public bool useRaycastToDetectDeviceParts;
|
||||
|
||||
bool showingSecondaryAction;
|
||||
|
||||
string currentDeviceAction;
|
||||
|
||||
public bool usingDevice;
|
||||
|
||||
public bool useCustomMinDistanceToUseDevice;
|
||||
public float customMinDistanceToUseDevice;
|
||||
|
||||
public bool ignoreDistanceToDevice;
|
||||
|
||||
public bool useCustomMinAngleToUse;
|
||||
public float customMinAngleToUseDevice;
|
||||
public bool useRelativeDirectionBetweenPlayerAndObject;
|
||||
|
||||
public bool removeDeviceFromPlayerListOnMaxDistance;
|
||||
public float maxDistanceToRemoveDeviceFromPlayerList;
|
||||
|
||||
public bool useCustomIconButtonInfo;
|
||||
public string customIconButtonInfoName;
|
||||
|
||||
public bool ignoreUseOnlyDeviceIfVisibleOnCamera = true;
|
||||
|
||||
public bool useCustomDeviceTransformPosition;
|
||||
public Transform customDeviceTransformPosition;
|
||||
|
||||
public bool useFixedDeviceIconPosition;
|
||||
|
||||
public bool checkIfObstacleBetweenDeviceAndPlayer;
|
||||
|
||||
public bool showIconTexture;
|
||||
public Texture iconTexture;
|
||||
|
||||
public bool useObjectDescription;
|
||||
[TextArea (5, 20)] public string objectDescription;
|
||||
public int descriptionFontSize = 14;
|
||||
|
||||
public bool showObjectAmount;
|
||||
public int objectAmount;
|
||||
|
||||
public bool useHoldInteractionButton;
|
||||
public float holdInteractionButtonDuration;
|
||||
|
||||
public bool useMaxDistanceToCameraCenter;
|
||||
public float maxDistanceToCameraCenter;
|
||||
|
||||
//GIZMO ELEMENTS
|
||||
public bool showGizmo;
|
||||
public Color gizmoLabelColor = Color.green;
|
||||
public Color gizmoColor = Color.white;
|
||||
public float gizmoRadius = 0.3f;
|
||||
|
||||
//just a string to set the action made by the device which has this script
|
||||
//the option disableIconOnPress allows to remove the icon of the action once it is done
|
||||
//the option showIcon allows to show the icon or not when the player is inside the device trigger
|
||||
//the option showTouchIconButton allows to show the touch button to use devices
|
||||
|
||||
void Start ()
|
||||
{
|
||||
currentDeviceAction = deviceAction;
|
||||
}
|
||||
|
||||
|
||||
public Transform getRegularTransformForIcon ()
|
||||
{
|
||||
if (useTransformForStringAction && transformForStringAction != null) {
|
||||
return transformForStringAction;
|
||||
} else {
|
||||
return transform;
|
||||
}
|
||||
}
|
||||
|
||||
public bool useSeparatedTransformForEveryViewEnabled ()
|
||||
{
|
||||
return useTransformForStringAction && useSeparatedTransformForEveryView;
|
||||
}
|
||||
|
||||
public Transform getTransformForIconThirdPerson ()
|
||||
{
|
||||
return transformForThirdPerson;
|
||||
}
|
||||
|
||||
public Transform getTransformForIconFirstPerson ()
|
||||
{
|
||||
return transformForFirstPerson;
|
||||
}
|
||||
|
||||
public void setIconEnabledState (bool state)
|
||||
{
|
||||
iconEnabled = state;
|
||||
}
|
||||
|
||||
public void enableIcon ()
|
||||
{
|
||||
setIconEnabledState (true);
|
||||
}
|
||||
|
||||
public void disableIcon ()
|
||||
{
|
||||
setIconEnabledState (false);
|
||||
}
|
||||
|
||||
public string getDeviceAction ()
|
||||
{
|
||||
return currentDeviceAction;
|
||||
}
|
||||
|
||||
public void setDeviceAction (string newDeviceAction)
|
||||
{
|
||||
deviceAction = newDeviceAction;
|
||||
|
||||
currentDeviceAction = deviceAction;
|
||||
}
|
||||
|
||||
public void changeActionName (bool state)
|
||||
{
|
||||
showingSecondaryAction = state;
|
||||
|
||||
if (showingSecondaryAction && secondaryDeviceAction.Length > 0) {
|
||||
currentDeviceAction = secondaryDeviceAction;
|
||||
} else {
|
||||
currentDeviceAction = deviceAction;
|
||||
}
|
||||
}
|
||||
|
||||
public void toggleActionName ()
|
||||
{
|
||||
changeActionName (!showingSecondaryAction);
|
||||
}
|
||||
|
||||
public void checkSetUsingDeviceState ()
|
||||
{
|
||||
checkSetUsingDeviceState (!usingDevice);
|
||||
}
|
||||
|
||||
public void checkSetUsingDeviceState (bool state)
|
||||
{
|
||||
if (setUsingDeviceState) {
|
||||
usingDevice = state;
|
||||
}
|
||||
}
|
||||
|
||||
public string getDeviceName ()
|
||||
{
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
public void setNewDeviceName (string newName)
|
||||
{
|
||||
deviceName = newName;
|
||||
}
|
||||
|
||||
public int getTextFontSize ()
|
||||
{
|
||||
if (setTextFontSizeActive) {
|
||||
return textFontSize;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void OnDrawGizmos ()
|
||||
{
|
||||
if (!showGizmo) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
|
||||
DrawGizmos ();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected ()
|
||||
{
|
||||
DrawGizmos ();
|
||||
}
|
||||
|
||||
void DrawGizmos ()
|
||||
{
|
||||
if (showGizmo) {
|
||||
Gizmos.color = gizmoColor;
|
||||
|
||||
Vector3 gizmoPosition = transform.position + transform.up * actionOffset;
|
||||
|
||||
if (useTransformForStringAction) {
|
||||
if (useSeparatedTransformForEveryView) {
|
||||
if (transformForThirdPerson != null) {
|
||||
Gizmos.color = Color.white;
|
||||
gizmoPosition = transformForThirdPerson.position;
|
||||
Gizmos.DrawSphere (gizmoPosition, gizmoRadius);
|
||||
}
|
||||
|
||||
if (transformForFirstPerson != null) {
|
||||
Gizmos.color = Color.yellow;
|
||||
gizmoPosition = transformForFirstPerson.position;
|
||||
Gizmos.DrawSphere (gizmoPosition, gizmoRadius);
|
||||
}
|
||||
} else {
|
||||
if (transformForStringAction != null) {
|
||||
gizmoPosition = transformForStringAction.position;
|
||||
Gizmos.DrawSphere (gizmoPosition, gizmoRadius);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Gizmos.DrawSphere (gizmoPosition, gizmoRadius);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 80fe7bfbecac2ee4895bd133d0b782df
|
||||
timeCreated: 1464659035
|
||||
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/Devices/deviceStringAction.cs
|
||||
uploadId: 814740
|
||||
784
Assets/Game Kit Controller/Scripts/Devices/doorSystem.cs
Normal file
784
Assets/Game Kit Controller/Scripts/Devices/doorSystem.cs
Normal file
@@ -0,0 +1,784 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using GameKitController.Audio;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class doorSystem : MonoBehaviour
|
||||
{
|
||||
public List<singleDoorInfo> doorsInfo = new List<singleDoorInfo> ();
|
||||
public List<string> tagListToOpen = new List<string> ();
|
||||
public doorMovementType movementType;
|
||||
public AudioClip openSound;
|
||||
public AudioElement openSoundAudioElement;
|
||||
public AudioClip closeSound;
|
||||
public AudioElement closeSoundAudioElement;
|
||||
public doorType doorTypeInfo;
|
||||
public doorCurrentState doorState;
|
||||
|
||||
public bool locked;
|
||||
public bool openDoorWhenUnlocked = true;
|
||||
public bool useSoundOnUnlock;
|
||||
public AudioClip unlockSound;
|
||||
public AudioElement unlockSoundAudioElement;
|
||||
public AudioSource unlockAudioSource;
|
||||
|
||||
public float openSpeed;
|
||||
public GameObject hologram;
|
||||
public bool closeAfterTime;
|
||||
public float timeToClose;
|
||||
|
||||
public bool showGizmo;
|
||||
public float gizmoArrowLength = 1;
|
||||
public float gizmoArrowLineLength = 2.5f;
|
||||
public float gizmoArrowAngle = 20;
|
||||
public Color gizmoArrowColor = Color.white;
|
||||
public bool rotateInBothDirections;
|
||||
|
||||
public string animationName;
|
||||
|
||||
public int animationSpeed = 1;
|
||||
|
||||
public bool closeDoorOnTriggerExit = true;
|
||||
|
||||
//set if the door is rotated or translated
|
||||
public enum doorMovementType
|
||||
{
|
||||
translate,
|
||||
rotate,
|
||||
animation
|
||||
}
|
||||
|
||||
//set how the door is opened, using triggers, a button close to the door, using a hologram to press the interaction button close to the door
|
||||
//and by shooting the door
|
||||
public enum doorType
|
||||
{
|
||||
trigger,
|
||||
button,
|
||||
hologram,
|
||||
shoot
|
||||
}
|
||||
|
||||
//set the initial state of the door, opened or closed
|
||||
public enum doorCurrentState
|
||||
{
|
||||
closed,
|
||||
opened
|
||||
}
|
||||
|
||||
public Transform currentPlayerTransform;
|
||||
|
||||
public bool useEventOnOpenAndClose;
|
||||
public UnityEvent openEvent;
|
||||
public UnityEvent closeEvent;
|
||||
|
||||
public bool useEventOnUnlockDoor;
|
||||
public UnityEvent evenOnUnlockDoor;
|
||||
|
||||
public bool useEventOnLockDoor;
|
||||
public UnityEvent eventOnLockDoor;
|
||||
|
||||
public bool useEventOnDoorFound;
|
||||
public UnityEvent eventOnLockedDoorFound;
|
||||
public UnityEvent eventOnUnlockedDoorFound;
|
||||
|
||||
public AudioSource soundSource;
|
||||
public mapObjectInformation mapObjectInformationManager;
|
||||
public Animation mainAnimation;
|
||||
public hologramDoor hologramDoorManager;
|
||||
public deviceStringAction deviceStringActionManager;
|
||||
|
||||
public bool setMapIconsOnDoor = true;
|
||||
|
||||
public bool moving;
|
||||
|
||||
bool doorFound;
|
||||
|
||||
bool enter;
|
||||
bool exit;
|
||||
|
||||
int doorsNumber;
|
||||
int doorsInPosition = 0;
|
||||
|
||||
int i;
|
||||
|
||||
float lastTimeOpened;
|
||||
Coroutine lockStateCoroutine;
|
||||
|
||||
bool disableDoorOpenCloseAction;
|
||||
|
||||
float originalOpenSpeed;
|
||||
|
||||
List<GameObject> characterList = new List<GameObject> ();
|
||||
|
||||
bool charactersInside;
|
||||
|
||||
private void InitializeAudioElements ()
|
||||
{
|
||||
if (soundSource == null) {
|
||||
soundSource = GetComponent<AudioSource> ();
|
||||
}
|
||||
|
||||
if (soundSource != null) {
|
||||
openSoundAudioElement.audioSource = soundSource;
|
||||
closeSoundAudioElement.audioSource = soundSource;
|
||||
}
|
||||
|
||||
if (unlockAudioSource != null) {
|
||||
unlockSoundAudioElement.audioSource = unlockAudioSource;
|
||||
}
|
||||
|
||||
if (openSound != null) {
|
||||
openSoundAudioElement.clip = openSound;
|
||||
}
|
||||
|
||||
if (closeSound != null) {
|
||||
closeSoundAudioElement.clip = closeSound;
|
||||
}
|
||||
|
||||
if (unlockSound != null) {
|
||||
unlockSoundAudioElement.clip = unlockSound;
|
||||
}
|
||||
}
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (movementType == doorMovementType.animation) {
|
||||
if (mainAnimation == null) {
|
||||
mainAnimation = GetComponent<Animation> ();
|
||||
}
|
||||
} else {
|
||||
//get the original rotation and position of every panel of the door
|
||||
for (i = 0; i < doorsInfo.Count; i++) {
|
||||
doorsInfo [i].originalPosition = doorsInfo [i].doorMesh.transform.localPosition;
|
||||
doorsInfo [i].originalRotation = doorsInfo [i].doorMesh.transform.localRotation;
|
||||
|
||||
if (doorsInfo [i].openedPosition != null) {
|
||||
doorsInfo [i].openedPositionFound = true;
|
||||
}
|
||||
|
||||
if (doorsInfo [i].rotatedPosition != null) {
|
||||
doorsInfo [i].rotatedPositionFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
//total number of panels
|
||||
doorsNumber = doorsInfo.Count;
|
||||
}
|
||||
|
||||
if (hologram != null) {
|
||||
if (hologramDoorManager == null) {
|
||||
hologramDoorManager = hologram.GetComponent<hologramDoor> ();
|
||||
}
|
||||
}
|
||||
|
||||
if (doorState == doorCurrentState.opened) {
|
||||
for (i = 0; i < doorsInfo.Count; i++) {
|
||||
if (movementType == doorMovementType.translate) {
|
||||
if (doorsInfo [i].openedPositionFound) {
|
||||
doorsInfo [i].doorMesh.transform.localPosition = doorsInfo [i].openedPosition.transform.localPosition;
|
||||
}
|
||||
} else {
|
||||
if (doorsInfo [i].rotatedPositionFound) {
|
||||
doorsInfo [i].doorMesh.transform.localRotation = doorsInfo [i].rotatedPosition.transform.localRotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InitializeAudioElements ();
|
||||
|
||||
if (mapObjectInformationManager == null) {
|
||||
mapObjectInformationManager = GetComponent<mapObjectInformation> ();
|
||||
}
|
||||
|
||||
if (deviceStringActionManager == null) {
|
||||
deviceStringActionManager = GetComponent<deviceStringAction> ();
|
||||
}
|
||||
|
||||
originalOpenSpeed = openSpeed;
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
//if the player enters or exits the door, move the door
|
||||
if ((enter || exit)) {
|
||||
moving = true;
|
||||
|
||||
if (movementType == doorMovementType.animation) {
|
||||
if (!mainAnimation.IsPlaying (animationName)) {
|
||||
setDoorState ();
|
||||
}
|
||||
} else {
|
||||
//for every panel in the door
|
||||
doorsInPosition = 0;
|
||||
|
||||
for (i = 0; i < doorsInfo.Count; i++) {
|
||||
//if the panels are translated, then
|
||||
if (movementType == doorMovementType.translate) {
|
||||
//if the curren position of the panel is different from the target position, then
|
||||
if (doorsInfo [i].doorMesh.transform.localPosition != doorsInfo [i].currentTargetPosition) {
|
||||
//translate the panel
|
||||
doorsInfo [i].doorMesh.transform.localPosition =
|
||||
Vector3.MoveTowards (doorsInfo [i].doorMesh.transform.localPosition, doorsInfo [i].currentTargetPosition, Time.deltaTime * openSpeed);
|
||||
}
|
||||
//if the panel has reached its target position, then
|
||||
else {
|
||||
doorsInfo [i].doorMesh.transform.localPosition = doorsInfo [i].currentTargetPosition;
|
||||
|
||||
//increase the number of panels that are in its target position
|
||||
doorsInPosition++;
|
||||
}
|
||||
}
|
||||
//if the panels are rotated, then
|
||||
else {
|
||||
//if the curren rotation of the panel is different from the target rotation, then
|
||||
if (doorsInfo [i].doorMesh.transform.localRotation != doorsInfo [i].currentTargetRotation) {
|
||||
//rotate from its current rotation to the target rotation
|
||||
doorsInfo [i].doorMesh.transform.localRotation = Quaternion.RotateTowards (doorsInfo [i].doorMesh.transform.localRotation,
|
||||
doorsInfo [i].currentTargetRotation, Time.deltaTime * openSpeed * 10);
|
||||
}
|
||||
//if the panel has reached its target rotation, then
|
||||
else {
|
||||
//increase the number of panels that are in its target rotation
|
||||
doorsInPosition++;
|
||||
|
||||
if (exit) {
|
||||
doorsInfo [i].doorMesh.transform.localRotation = Quaternion.identity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if all the panels in the door are in its target position/rotation
|
||||
if (doorsInPosition == doorsNumber) {
|
||||
setDoorState ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (closeAfterTime) {
|
||||
if (doorState == doorCurrentState.opened && !exit && !enter && !moving) {
|
||||
if (Time.time > lastTimeOpened + timeToClose) {
|
||||
changeDoorsStateByButton ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setDoorState ()
|
||||
{
|
||||
//if the door was opening, then the door is opened
|
||||
if (enter) {
|
||||
doorState = doorCurrentState.opened;
|
||||
lastTimeOpened = Time.time;
|
||||
}
|
||||
|
||||
//if the door was closing, then the door is closed
|
||||
if (exit) {
|
||||
doorState = doorCurrentState.closed;
|
||||
}
|
||||
|
||||
//reset the parameters
|
||||
enter = false;
|
||||
exit = false;
|
||||
doorsInPosition = 0;
|
||||
moving = false;
|
||||
}
|
||||
|
||||
//if the door was unlocked, locked it
|
||||
public void lockDoor ()
|
||||
{
|
||||
if (lockStateCoroutine != null) {
|
||||
StopCoroutine (lockStateCoroutine);
|
||||
}
|
||||
|
||||
lockStateCoroutine = StartCoroutine (lockDoorCoroutine ());
|
||||
}
|
||||
|
||||
IEnumerator lockDoorCoroutine ()
|
||||
{
|
||||
yield return new WaitForSeconds (0.01f);
|
||||
|
||||
if (locked) {
|
||||
StopCoroutine (lockStateCoroutine);
|
||||
}
|
||||
|
||||
if (doorState == doorCurrentState.opened || (doorState == doorCurrentState.closed && moving)) {
|
||||
closeDoors ();
|
||||
}
|
||||
|
||||
//if the door is not a hologram type, then close the door
|
||||
if (doorTypeInfo != doorType.hologram && doorTypeInfo != doorType.button) {
|
||||
|
||||
} else {
|
||||
//else, lock the hologram, so the door is closed
|
||||
if (hologramDoorManager != null) {
|
||||
hologramDoorManager.lockHologram ();
|
||||
}
|
||||
}
|
||||
|
||||
if (useEventOnLockDoor) {
|
||||
eventOnLockDoor.Invoke ();
|
||||
}
|
||||
|
||||
if (setMapIconsOnDoor && mapObjectInformationManager != null) {
|
||||
mapObjectInformationManager.addMapObject ("Locked Door");
|
||||
}
|
||||
|
||||
locked = true;
|
||||
}
|
||||
|
||||
//if the door was locked, unlocked it
|
||||
public void unlockDoor ()
|
||||
{
|
||||
if (lockStateCoroutine != null) {
|
||||
StopCoroutine (lockStateCoroutine);
|
||||
}
|
||||
|
||||
lockStateCoroutine = StartCoroutine (unlockDoorCoroutine ());
|
||||
}
|
||||
|
||||
IEnumerator unlockDoorCoroutine ()
|
||||
{
|
||||
yield return new WaitForSeconds (0.01f);
|
||||
|
||||
if (!locked) {
|
||||
StopCoroutine (lockStateCoroutine);
|
||||
}
|
||||
|
||||
locked = false;
|
||||
|
||||
//if the door is not a hologram type, then open the door
|
||||
if (doorTypeInfo != doorType.hologram) {
|
||||
if (openDoorWhenUnlocked) {
|
||||
changeDoorsStateByButton ();
|
||||
}
|
||||
} else {
|
||||
//else, unlock the hologram, so the door can be opened when the hologram is used
|
||||
if (hologramDoorManager != null) {
|
||||
hologramDoorManager.unlockHologram ();
|
||||
}
|
||||
}
|
||||
|
||||
if (setMapIconsOnDoor && mapObjectInformationManager) {
|
||||
mapObjectInformationManager.addMapObject ("Unlocked Door");
|
||||
}
|
||||
|
||||
if (useSoundOnUnlock) {
|
||||
if (unlockSoundAudioElement != null) {
|
||||
AudioPlayer.PlayOneShot (unlockSoundAudioElement, gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
if (useEventOnUnlockDoor) {
|
||||
evenOnUnlockDoor.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
public bool isDisableDoorOpenCloseActionActive ()
|
||||
{
|
||||
return disableDoorOpenCloseAction;
|
||||
}
|
||||
|
||||
public void setEnableDisableDoorOpenCloseActionValue (bool state)
|
||||
{
|
||||
disableDoorOpenCloseAction = state;
|
||||
}
|
||||
|
||||
public void openOrCloseElevatorDoor ()
|
||||
{
|
||||
if (hologramDoorManager != null) {
|
||||
hologramDoorManager.openHologramDoorByExternalInput ();
|
||||
} else {
|
||||
changeDoorsStateByButton ();
|
||||
}
|
||||
}
|
||||
|
||||
//a button to open the door calls this function, so
|
||||
public void changeDoorsStateByButton ()
|
||||
{
|
||||
if (disableDoorOpenCloseAction) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (moving) {
|
||||
return;
|
||||
}
|
||||
|
||||
//if the door is opened, close it
|
||||
// && !moving
|
||||
if (doorState == doorCurrentState.opened) {
|
||||
closeDoors ();
|
||||
}
|
||||
|
||||
//if the door is closed, open it
|
||||
if (doorState == doorCurrentState.closed) {
|
||||
openDoors ();
|
||||
}
|
||||
}
|
||||
|
||||
public void openDoorsIfClosed ()
|
||||
{
|
||||
if (moving) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (doorState == doorCurrentState.closed) {
|
||||
openDoors ();
|
||||
}
|
||||
}
|
||||
|
||||
public void closeDoorsIfOpened ()
|
||||
{
|
||||
if (moving) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (doorState == doorCurrentState.opened) {
|
||||
closeDoors ();
|
||||
}
|
||||
}
|
||||
|
||||
//open the doors
|
||||
public void openDoors ()
|
||||
{
|
||||
if (disableDoorOpenCloseAction) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!locked) {
|
||||
|
||||
enter = true;
|
||||
exit = false;
|
||||
|
||||
setDeviceStringActionState (true);
|
||||
|
||||
if (movementType == doorMovementType.animation) {
|
||||
playDoorAnimation (true);
|
||||
} else {
|
||||
bool rotateForward = true;
|
||||
|
||||
if (currentPlayerTransform != null) {
|
||||
if (rotateInBothDirections) {
|
||||
float dot = Vector3.Dot (transform.forward, (currentPlayerTransform.position - transform.position).normalized);
|
||||
|
||||
if (dot > 0) {
|
||||
rotateForward = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//for every panel in the door, set that their target rotation/position are their opened/rotated positions
|
||||
for (i = 0; i < doorsInfo.Count; i++) {
|
||||
if (movementType == doorMovementType.translate) {
|
||||
if (doorsInfo [i].openedPositionFound) {
|
||||
doorsInfo [i].currentTargetPosition = doorsInfo [i].openedPosition.transform.localPosition;
|
||||
}
|
||||
} else {
|
||||
if (doorsInfo [i].rotatedPositionFound) {
|
||||
if (rotateForward) {
|
||||
doorsInfo [i].currentTargetRotation = doorsInfo [i].rotatedPosition.transform.localRotation;
|
||||
} else {
|
||||
doorsInfo [i].currentTargetRotation = Quaternion.Euler ((-1) * doorsInfo [i].rotatedPosition.transform.localEulerAngles);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//play the open sound
|
||||
playSound (openSoundAudioElement);
|
||||
|
||||
if (useEventOnOpenAndClose) {
|
||||
if (openEvent.GetPersistentEventCount () > 0) {
|
||||
openEvent.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//close the doors
|
||||
public void closeDoors ()
|
||||
{
|
||||
if (disableDoorOpenCloseAction) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!locked) {
|
||||
|
||||
enter = false;
|
||||
exit = true;
|
||||
|
||||
setDeviceStringActionState (false);
|
||||
|
||||
if (movementType == doorMovementType.animation) {
|
||||
playDoorAnimation (false);
|
||||
} else {
|
||||
//for every panel in the door, set that their target rotation/position are their original positions/rotations
|
||||
for (i = 0; i < doorsInfo.Count; i++) {
|
||||
if (movementType == doorMovementType.translate) {
|
||||
doorsInfo [i].currentTargetPosition = doorsInfo [i].originalPosition;
|
||||
} else {
|
||||
doorsInfo [i].currentTargetRotation = doorsInfo [i].originalRotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//play the close sound
|
||||
playSound (closeSoundAudioElement);
|
||||
|
||||
if (useEventOnOpenAndClose) {
|
||||
if (closeEvent.GetPersistentEventCount () > 0) {
|
||||
closeEvent.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void playSound (AudioElement clipSound)
|
||||
{
|
||||
AudioPlayer.PlayOneShot (clipSound, gameObject);
|
||||
}
|
||||
|
||||
public void setDeviceStringActionState (bool state)
|
||||
{
|
||||
if (deviceStringActionManager != null) {
|
||||
deviceStringActionManager.changeActionName (state);
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerEnter (Collider col)
|
||||
{
|
||||
//the player has entered in the door trigger, check if this door is a trigger door or a hologram door opened
|
||||
if (checkIfTagCanOpen (col.GetComponent<Collider> ().tag)) {
|
||||
|
||||
currentPlayerTransform = col.gameObject.transform;
|
||||
|
||||
if (!characterList.Contains (col.gameObject)) {
|
||||
characterList.Add (col.gameObject);
|
||||
|
||||
GKC_Utils.removeNullGameObjectsFromList (characterList);
|
||||
|
||||
if (characterList.Count > 0) {
|
||||
charactersInside = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ((doorTypeInfo == doorType.trigger && (doorState == doorCurrentState.closed || moving) ||
|
||||
(doorTypeInfo == doorType.hologram && doorState == doorCurrentState.closed &&
|
||||
hologramDoorManager != null && hologramDoorManager.openOnTrigger))) {
|
||||
|
||||
openDoors ();
|
||||
}
|
||||
|
||||
if (useEventOnDoorFound && !doorFound) {
|
||||
if (locked) {
|
||||
eventOnLockedDoorFound.Invoke ();
|
||||
} else {
|
||||
eventOnUnlockedDoorFound.Invoke ();
|
||||
}
|
||||
|
||||
doorFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit (Collider col)
|
||||
{
|
||||
//the player has gone of the door trigger, check if this door is a trigger door, a shoot door, or a hologram door and it is opened, to close it
|
||||
if (checkIfTagCanOpen (col.GetComponent<Collider> ().tag)) {
|
||||
bool canCloseDoors = false;
|
||||
|
||||
if (characterList.Contains (col.gameObject)) {
|
||||
characterList.Remove (col.gameObject);
|
||||
|
||||
GKC_Utils.removeNullGameObjectsFromList (characterList);
|
||||
|
||||
if (characterList.Count == 0) {
|
||||
charactersInside = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!charactersInside) {
|
||||
if (doorTypeInfo == doorType.trigger && closeDoorOnTriggerExit) {
|
||||
canCloseDoors = true;
|
||||
}
|
||||
|
||||
if (doorTypeInfo == doorType.shoot && doorState == doorCurrentState.opened) {
|
||||
canCloseDoors = true;
|
||||
}
|
||||
|
||||
if (doorTypeInfo == doorType.hologram && doorState == doorCurrentState.opened && closeDoorOnTriggerExit) {
|
||||
canCloseDoors = true;
|
||||
}
|
||||
|
||||
if (canCloseDoors) {
|
||||
closeDoors ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//the player has shooted this door, so
|
||||
public void doorsShooted (GameObject projectile)
|
||||
{
|
||||
//check if the object is a player's projectile
|
||||
if (projectile.GetComponent<projectileSystem> () != null) {
|
||||
//and if the door is closed and a shoot type
|
||||
if (doorTypeInfo == doorType.shoot) {
|
||||
if (doorState == doorCurrentState.closed && !moving) {
|
||||
//then, open the door
|
||||
openDoors ();
|
||||
} else if (doorState == doorCurrentState.opened) {
|
||||
if (moving) {
|
||||
//then, open the door
|
||||
openDoors ();
|
||||
} else {
|
||||
lastTimeOpened = Time.time;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool checkIfTagCanOpen (string tagToCheck)
|
||||
{
|
||||
if (tagListToOpen.Contains (tagToCheck)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool doorIsMoving ()
|
||||
{
|
||||
return moving;
|
||||
}
|
||||
|
||||
public void playDoorAnimation (bool playForward)
|
||||
{
|
||||
if (mainAnimation != null) {
|
||||
if (animationSpeed == 0) {
|
||||
animationSpeed = 1;
|
||||
}
|
||||
|
||||
if (playForward) {
|
||||
mainAnimation [animationName].speed = animationSpeed;
|
||||
|
||||
mainAnimation.CrossFade (animationName);
|
||||
} else {
|
||||
mainAnimation [animationName].speed = -animationSpeed;
|
||||
|
||||
if (!mainAnimation.IsPlaying (animationName)) {
|
||||
mainAnimation [animationName].time = mainAnimation [animationName].length;
|
||||
mainAnimation.Play (animationName);
|
||||
} else {
|
||||
mainAnimation.CrossFade (animationName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool isDoorOpened ()
|
||||
{
|
||||
return doorState == doorCurrentState.opened && !moving;
|
||||
}
|
||||
|
||||
public bool isDoorClosed ()
|
||||
{
|
||||
return doorState == doorCurrentState.closed && !moving;
|
||||
}
|
||||
|
||||
public bool isDoorOpening ()
|
||||
{
|
||||
return doorState == doorCurrentState.opened && moving;
|
||||
}
|
||||
|
||||
public bool isDoorClosing ()
|
||||
{
|
||||
return doorState == doorCurrentState.closed && moving;
|
||||
}
|
||||
|
||||
public void setReducedVelocity (float newValue)
|
||||
{
|
||||
openSpeed = newValue;
|
||||
}
|
||||
|
||||
public void setNormalVelocity ()
|
||||
{
|
||||
setReducedVelocity (originalOpenSpeed);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void OnDrawGizmos ()
|
||||
{
|
||||
if (!showGizmo) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
|
||||
DrawGizmos ();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected ()
|
||||
{
|
||||
DrawGizmos ();
|
||||
}
|
||||
|
||||
//draw the pivot and the final positions of every door
|
||||
void DrawGizmos ()
|
||||
{
|
||||
if (showGizmo) {
|
||||
if (movementType != doorMovementType.animation) {
|
||||
for (i = 0; i < doorsInfo.Count; i++) {
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawSphere (doorsInfo [i].doorMesh.transform.position, 0.3f);
|
||||
|
||||
if (movementType == doorMovementType.translate) {
|
||||
if (doorsInfo [i].openedPosition != null) {
|
||||
Gizmos.color = Color.green;
|
||||
|
||||
Gizmos.DrawSphere (doorsInfo [i].openedPosition.transform.position, 0.3f);
|
||||
|
||||
Gizmos.color = Color.white;
|
||||
Gizmos.DrawLine (doorsInfo [i].doorMesh.transform.position, doorsInfo [i].openedPosition.transform.position);
|
||||
}
|
||||
}
|
||||
|
||||
if (movementType == doorMovementType.rotate) {
|
||||
if (doorsInfo [i].rotatedPosition != null) {
|
||||
Gizmos.color = Color.green;
|
||||
|
||||
GKC_Utils.drawGizmoArrow (doorsInfo [i].rotatedPosition.transform.position, doorsInfo [i].rotatedPosition.transform.right * gizmoArrowLineLength,
|
||||
gizmoArrowColor, gizmoArrowLength, gizmoArrowAngle);
|
||||
|
||||
Gizmos.color = Color.white;
|
||||
Gizmos.DrawLine (doorsInfo [i].doorMesh.transform.position, doorsInfo [i].rotatedPosition.transform.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//a clas to store every panel that make the door, the position to move when is opened or the object which has the rotation that the door has to make
|
||||
//and fields to store the current and original rotation and position
|
||||
[System.Serializable]
|
||||
public class singleDoorInfo
|
||||
{
|
||||
public GameObject doorMesh;
|
||||
public GameObject openedPosition;
|
||||
public bool openedPositionFound;
|
||||
|
||||
public GameObject rotatedPosition;
|
||||
public bool rotatedPositionFound;
|
||||
|
||||
public Vector3 originalPosition;
|
||||
public Quaternion originalRotation;
|
||||
public Vector3 currentTargetPosition;
|
||||
public Quaternion currentTargetRotation;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5630ff8dfbef46343b625e10c6f5d5ca
|
||||
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/Devices/doorSystem.cs
|
||||
uploadId: 814740
|
||||
504
Assets/Game Kit Controller/Scripts/Devices/electronicDevice.cs
Normal file
504
Assets/Game Kit Controller/Scripts/Devices/electronicDevice.cs
Normal file
@@ -0,0 +1,504 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class electronicDevice : MonoBehaviour
|
||||
{
|
||||
public string playerTag = "Player";
|
||||
|
||||
public bool useOnlyForTrigger;
|
||||
public string functionToSetPlayer;
|
||||
|
||||
public bool activateDeviceOnTriggerEnter;
|
||||
|
||||
public bool useFreeInteraction;
|
||||
public bool useFreeInteractionEvent;
|
||||
public UnityEvent freeInteractionEvent;
|
||||
|
||||
public bool useMoveCameraToDevice;
|
||||
public bool disableDeviceWhenStopUsing;
|
||||
public bool stopUsingDeviceWhenUnlock;
|
||||
public bool disableAndRemoveDeviceWhenUnlock;
|
||||
public UnityEvent functionToUseDevice = new UnityEvent ();
|
||||
public bool usingDevice;
|
||||
//public LayerMask layerForUsers;
|
||||
|
||||
public UnityEvent unlockFunctionCall = new UnityEvent ();
|
||||
public UnityEvent lockFunctionCall = new UnityEvent ();
|
||||
public GameObject currentPlayer;
|
||||
|
||||
public bool activateEventOnTriggerStay;
|
||||
public UnityEvent triggerStayEvent = new UnityEvent ();
|
||||
public float eventOnTriggerStayRate;
|
||||
public bool activateEventOnTriggerEnter;
|
||||
public UnityEvent triggerEnterEvent = new UnityEvent ();
|
||||
public bool activateEventOnTriggerExit;
|
||||
public UnityEvent triggerExitEvent = new UnityEvent ();
|
||||
|
||||
public bool sendPlayerOnTriggerEnter;
|
||||
public eventParameters.eventToCallWithGameObject eventToSendPlayerOnTriggerEnter;
|
||||
public bool sendPlayerOnTriggerExit;
|
||||
public eventParameters.eventToCallWithGameObject eventToSendPlayerOnTriggerExit;
|
||||
|
||||
public bool activateEventIfUnableToUseDevice;
|
||||
public UnityEvent unableToUseDeviceEvent = new UnityEvent ();
|
||||
|
||||
public bool sendCurrentPlayerOnEvent;
|
||||
public eventParameters.eventToCallWithGameObject setCurrentPlayerEvent;
|
||||
|
||||
public bool useEventOnStartUsingDevice;
|
||||
public bool useEventOnStopUsingDevice;
|
||||
public UnityEvent eventOnStartUsingDevice;
|
||||
public UnityEvent eventOnStopUsingDevice;
|
||||
|
||||
public bool deviceCanBeUsed = true;
|
||||
|
||||
public bool playerInside;
|
||||
|
||||
float lastTimeEventOnTriggerStay;
|
||||
|
||||
public moveCameraToDevice cameraMovementManager;
|
||||
public moveDeviceToCamera deviceMovementManager;
|
||||
|
||||
public bool disableDeviceInteractionAfterUsingOnce;
|
||||
|
||||
|
||||
public bool useConditionSystemToStartDevice;
|
||||
|
||||
public GKCConditionInfo mainGKCConditionInfoToStartDevice;
|
||||
|
||||
public bool useConditionSystemToStopDevice;
|
||||
|
||||
public GKCConditionInfo mainGKCConditionInfoToStopDevice;
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
|
||||
List<GameObject> playerFoundList = new List<GameObject> ();
|
||||
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (cameraMovementManager == null) {
|
||||
cameraMovementManager = GetComponent<moveCameraToDevice> ();
|
||||
}
|
||||
|
||||
if (deviceMovementManager == null) {
|
||||
deviceMovementManager = GetComponent<moveDeviceToCamera> ();
|
||||
}
|
||||
|
||||
//layerForUsers = LayerMask.NameToLayer("player") << 0;
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (playerInside && activateEventOnTriggerStay) {
|
||||
if (Time.time > lastTimeEventOnTriggerStay + eventOnTriggerStayRate) {
|
||||
triggerStayEvent.Invoke ();
|
||||
lastTimeEventOnTriggerStay = Time.time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void activateDevice ()
|
||||
{
|
||||
if (showDebugPrint) {
|
||||
print ("checking to activateDevice");
|
||||
}
|
||||
|
||||
if (!deviceCanBeUsed) {
|
||||
if (activateEventIfUnableToUseDevice) {
|
||||
if (unableToUseDeviceEvent.GetPersistentEventCount () > 0) {
|
||||
unableToUseDeviceEvent.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("cancel");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (useConditionSystemToStartDevice) {
|
||||
if (!usingDevice) {
|
||||
if (mainGKCConditionInfoToStartDevice != null) {
|
||||
if (!mainGKCConditionInfoToStartDevice.checkIfConditionCompleteAndReturnResult ()) {
|
||||
if (showDebugPrint) {
|
||||
print ("cancel");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (useConditionSystemToStopDevice) {
|
||||
if (usingDevice) {
|
||||
if (mainGKCConditionInfoToStopDevice != null) {
|
||||
if (!mainGKCConditionInfoToStopDevice.checkIfConditionCompleteAndReturnResult ()) {
|
||||
if (showDebugPrint) {
|
||||
print ("cancel");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!useOnlyForTrigger) {
|
||||
if (usingDevice && !useMoveCameraToDevice && !useFreeInteraction) {
|
||||
if (showDebugPrint) {
|
||||
print ("cancel");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (useFreeInteraction && usingDevice) {
|
||||
if (useFreeInteractionEvent) {
|
||||
freeInteractionEvent.Invoke ();
|
||||
}
|
||||
} else {
|
||||
setDeviceState (!usingDevice);
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("calling to activate device state " + usingDevice);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDeviceState (bool state)
|
||||
{
|
||||
usingDevice = state;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("setDeviceState " + usingDevice);
|
||||
}
|
||||
|
||||
if (!useOnlyForTrigger) {
|
||||
if (useMoveCameraToDevice) {
|
||||
moveCamera (usingDevice);
|
||||
}
|
||||
}
|
||||
|
||||
functionToUseDevice.Invoke ();
|
||||
|
||||
if (usingDevice) {
|
||||
if (useEventOnStartUsingDevice) {
|
||||
eventOnStartUsingDevice.Invoke ();
|
||||
}
|
||||
} else {
|
||||
if (useEventOnStopUsingDevice) {
|
||||
eventOnStopUsingDevice.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
if (!usingDevice) {
|
||||
if (disableDeviceInteractionAfterUsingOnce) {
|
||||
removeDeviceFromList ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void moveCamera (bool state)
|
||||
{
|
||||
if (cameraMovementManager != null) {
|
||||
cameraMovementManager.moveCamera (usingDevice);
|
||||
}
|
||||
|
||||
if (deviceMovementManager != null) {
|
||||
deviceMovementManager.moveCamera (usingDevice);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentUser (GameObject newPlayer)
|
||||
{
|
||||
if (!usingDevice) {
|
||||
currentPlayer = newPlayer;
|
||||
|
||||
if (cameraMovementManager != null) {
|
||||
cameraMovementManager.setCurrentPlayer (currentPlayer);
|
||||
}
|
||||
|
||||
if (deviceMovementManager != null) {
|
||||
deviceMovementManager.setCurrentPlayer (currentPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setPlayerManually (GameObject newPlayer)
|
||||
{
|
||||
if (newPlayer != null) {
|
||||
Collider newPlayerCollider = newPlayer.GetComponent<Collider> ();
|
||||
|
||||
if (newPlayerCollider != null) {
|
||||
checkTriggerInfo (newPlayerCollider, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//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
|
||||
//print (isEnter + " " + col.name + " " + col.CompareTag (playerTag) + col.gameObject.name);
|
||||
|
||||
//if (currentPlayer != null) {
|
||||
// print ((currentPlayer == col.gameObject) + " " + (col.transform.IsChildOf (currentPlayer.transform)));
|
||||
//}
|
||||
|
||||
if (isEnter) {
|
||||
//if the device is already being used, return
|
||||
if (usingDevice) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (col.CompareTag (playerTag)) {
|
||||
|
||||
bool isNewPayerFound = false;
|
||||
|
||||
if (!playerFoundList.Contains (col.gameObject)) {
|
||||
playerFoundList.Add (col.gameObject);
|
||||
|
||||
isNewPayerFound = true;
|
||||
}
|
||||
|
||||
currentPlayer = col.gameObject;
|
||||
|
||||
if (useOnlyForTrigger || !useMoveCameraToDevice) {
|
||||
|
||||
if (cameraMovementManager != null) {
|
||||
cameraMovementManager.setCurrentPlayer (currentPlayer);
|
||||
}
|
||||
|
||||
if (deviceMovementManager != null) {
|
||||
deviceMovementManager.setCurrentPlayer (currentPlayer);
|
||||
}
|
||||
|
||||
if (useOnlyForTrigger) {
|
||||
if (functionToSetPlayer != "") {
|
||||
SendMessage (functionToSetPlayer, currentPlayer, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
} else {
|
||||
if (!useMoveCameraToDevice) {
|
||||
setDeviceState (true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sendCurrentPlayerOnEvent) {
|
||||
setCurrentPlayerEvent.Invoke (col.gameObject);
|
||||
}
|
||||
|
||||
if (activateEventOnTriggerEnter) {
|
||||
triggerEnterEvent.Invoke ();
|
||||
}
|
||||
|
||||
if (sendPlayerOnTriggerEnter) {
|
||||
eventToSendPlayerOnTriggerEnter.Invoke (col.gameObject);
|
||||
}
|
||||
|
||||
playerInside = true;
|
||||
|
||||
if (activateDeviceOnTriggerEnter && isNewPayerFound) {
|
||||
usingDevicesSystem currentUsingDevicesSystem = col.gameObject.GetComponent<usingDevicesSystem> ();
|
||||
|
||||
if (currentUsingDevicesSystem != null) {
|
||||
currentUsingDevicesSystem.useCurrentDevice (gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ((usingDevice && !useFreeInteraction) || (useFreeInteraction && currentPlayer != col.gameObject)) {
|
||||
return;
|
||||
}
|
||||
|
||||
//if the player is leaving the trigger
|
||||
if (col.CompareTag (playerTag)) {
|
||||
//if the player is the same that was using the device, the device can be used again
|
||||
if (playerFoundList.Contains (col.gameObject)) {
|
||||
playerFoundList.Remove (col.gameObject);
|
||||
}
|
||||
|
||||
if (playerFoundList.Count == 0) {
|
||||
currentPlayer = null;
|
||||
|
||||
if (useOnlyForTrigger) {
|
||||
usingDevice = false;
|
||||
} else {
|
||||
if (!useMoveCameraToDevice || disableDeviceWhenStopUsing) {
|
||||
setDeviceState (false);
|
||||
}
|
||||
}
|
||||
|
||||
if (activateEventOnTriggerExit) {
|
||||
triggerExitEvent.Invoke ();
|
||||
}
|
||||
|
||||
if (sendPlayerOnTriggerExit) {
|
||||
eventToSendPlayerOnTriggerExit.Invoke (col.gameObject);
|
||||
}
|
||||
|
||||
playerInside = false;
|
||||
|
||||
lastTimeEventOnTriggerStay = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setUsingDeviceState (bool state)
|
||||
{
|
||||
usingDevice = state;
|
||||
}
|
||||
|
||||
public GameObject getCurrentPlayer ()
|
||||
{
|
||||
return currentPlayer;
|
||||
}
|
||||
|
||||
public void unlockObject ()
|
||||
{
|
||||
if (unlockFunctionCall.GetPersistentEventCount () > 0) {
|
||||
unlockFunctionCall.Invoke ();
|
||||
}
|
||||
|
||||
if (disableAndRemoveDeviceWhenUnlock) {
|
||||
removeDeviceFromList ();
|
||||
}
|
||||
}
|
||||
|
||||
public void lockObject ()
|
||||
{
|
||||
if (lockFunctionCall.GetPersistentEventCount () > 0) {
|
||||
lockFunctionCall.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeDeviceFromListWithoutDisablingDevice ()
|
||||
{
|
||||
if (playerFoundList.Count > 0) {
|
||||
for (int i = 0; i < playerFoundList.Count; i++) {
|
||||
playerFoundList [i].GetComponent<usingDevicesSystem> ().removeDeviceFromList (gameObject);
|
||||
}
|
||||
|
||||
//playerFoundList.Clear ();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void clearDeviceList ()
|
||||
{
|
||||
if (playerFoundList.Count > 0) {
|
||||
for (int i = 0; i < playerFoundList.Count; i++) {
|
||||
playerFoundList [i].GetComponent<usingDevicesSystem> ().clearDeviceList ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addDeviceToList ()
|
||||
{
|
||||
if (playerFoundList.Count > 0) {
|
||||
for (int i = 0; i < playerFoundList.Count; i++) {
|
||||
playerFoundList [i].GetComponent<usingDevicesSystem> ().addDeviceToListIfNotAlreadyIncluded (gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeDeviceFromList ()
|
||||
{
|
||||
if (playerFoundList.Count > 0) {
|
||||
for (int i = 0; i < playerFoundList.Count; i++) {
|
||||
playerFoundList [i].GetComponent<usingDevicesSystem> ().removeDeviceFromList (gameObject);
|
||||
}
|
||||
|
||||
gameObject.tag = "Untagged";
|
||||
|
||||
//playerFoundList.Clear ();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeDeviceFromListOnAllPlayersOnSceneWithoutDisablingDevice ()
|
||||
{
|
||||
GKC_Utils.removeDeviceFromListOnAllPlayersOnSceneWithoutDisablingDevice (gameObject);
|
||||
}
|
||||
|
||||
public void removeDeviceFromListExternalCall ()
|
||||
{
|
||||
if (playerFoundList.Count > 0) {
|
||||
for (int i = 0; i < playerFoundList.Count; i++) {
|
||||
playerFoundList [i].GetComponent<usingDevicesSystem> ().removeDeviceFromListExternalCall (gameObject);
|
||||
}
|
||||
|
||||
gameObject.tag = "Untagged";
|
||||
|
||||
//playerFoundList.Clear ();
|
||||
}
|
||||
}
|
||||
|
||||
public void stopUsindDevice ()
|
||||
{
|
||||
if (stopUsingDeviceWhenUnlock) {
|
||||
setDeviceState (false);
|
||||
}
|
||||
}
|
||||
|
||||
public void stopUseDeviceToPlayer ()
|
||||
{
|
||||
if (currentPlayer != null) {
|
||||
currentPlayer.GetComponent<usingDevicesSystem> ().useDevice ();
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadDeviceStringActionOnPlayer ()
|
||||
{
|
||||
if (playerFoundList.Count > 0) {
|
||||
for (int i = 0; i < playerFoundList.Count; i++) {
|
||||
playerFoundList [i].GetComponent<usingDevicesSystem> ().reloadDeviceStringActionOnPlayer (gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setDeviceCanBeUsedState (bool state)
|
||||
{
|
||||
deviceCanBeUsed = state;
|
||||
}
|
||||
|
||||
public void cancelUseElectronicDevice ()
|
||||
{
|
||||
if (usingDevice) {
|
||||
activateDevice ();
|
||||
}
|
||||
}
|
||||
|
||||
public void useDeviceObjectExternally (GameObject currentPlayer)
|
||||
{
|
||||
GKC_Utils.useDeviceObjectExternally (currentPlayer, gameObject);
|
||||
}
|
||||
|
||||
public void useDeviceObjectExternallyForCharacterInside ()
|
||||
{
|
||||
if (currentPlayer != null) {
|
||||
GKC_Utils.useDeviceObjectExternally (currentPlayer, gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be8030885d591eb408518d093fad5d5b
|
||||
timeCreated: 1509817787
|
||||
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/Devices/electronicDevice.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,73 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class elevatorFloorsPanel : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public GameObject elevator;
|
||||
public GameObject floorButton;
|
||||
public RectTransform floorListContent;
|
||||
public elevatorSystem elevatorManager;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public List<GameObject> floorButtonList = new List<GameObject> ();
|
||||
|
||||
int i;
|
||||
bool usingPanel;
|
||||
electronicDevice deviceManager;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (elevatorManager == null) {
|
||||
elevatorManager = elevator.GetComponent<elevatorSystem> ();
|
||||
}
|
||||
|
||||
int floorsAmount = elevatorManager.floors.Count;
|
||||
|
||||
for (i = 0; i < floorsAmount; i++) {
|
||||
GameObject newIconButton = (GameObject)Instantiate (floorButton, Vector3.zero, floorButton.transform.rotation);
|
||||
newIconButton.transform.SetParent (floorListContent.transform);
|
||||
newIconButton.transform.localScale = Vector3.one;
|
||||
newIconButton.transform.localPosition = Vector3.zero;
|
||||
|
||||
newIconButton.transform.GetComponentInChildren<Text> ().text = elevatorManager.floors [i].floorNumber.ToString ();
|
||||
newIconButton.name = "Floor - " + (i + 1);
|
||||
|
||||
floorButtonList.Add (newIconButton);
|
||||
}
|
||||
|
||||
floorButton.SetActive (false);
|
||||
|
||||
deviceManager = GetComponent<electronicDevice> ();
|
||||
}
|
||||
|
||||
//activate the device
|
||||
public void activateElevatorFloorPanel ()
|
||||
{
|
||||
usingPanel = !usingPanel;
|
||||
}
|
||||
|
||||
public void goToFloor (Button button)
|
||||
{
|
||||
int index = -1;
|
||||
|
||||
for (i = 0; i < floorButtonList.Count; i++) {
|
||||
if (floorButtonList [i] == button.gameObject) {
|
||||
index = i;
|
||||
|
||||
if (elevatorManager.goToNumberFloor (index)) {
|
||||
deviceManager.setDeviceState (false);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66c5c7dd63148ac4e89e671481de8ca6
|
||||
timeCreated: 1473292627
|
||||
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/Devices/elevatorFloorsPanel.cs
|
||||
uploadId: 814740
|
||||
653
Assets/Game Kit Controller/Scripts/Devices/elevatorSystem.cs
Normal file
653
Assets/Game Kit Controller/Scripts/Devices/elevatorSystem.cs
Normal file
@@ -0,0 +1,653 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class elevatorSystem : MonoBehaviour
|
||||
{
|
||||
public bool elevatorSystemEnabled = true;
|
||||
|
||||
public List<floorInfo> floors = new List<floorInfo> ();
|
||||
public int currentFloor;
|
||||
public float elevatorSpeed = 20;
|
||||
|
||||
public List<string> tagToCheckToMove = new List<string> ();
|
||||
|
||||
public bool canUseElevatorButtonsWithoutPlayerInside;
|
||||
|
||||
public bool hasInsideElevatorDoor;
|
||||
public GameObject insideElevatorDoor;
|
||||
public GameObject elevatorSwitchPrefab;
|
||||
public bool addSwitchInNewFloors;
|
||||
public GameObject elevatorDoorPrefab;
|
||||
public bool addDoorInNewFloors;
|
||||
public bool moving;
|
||||
public bool doorsClosed = true;
|
||||
|
||||
public float floorHeight = 5;
|
||||
|
||||
public bool changeIconFloorWhenMoving;
|
||||
|
||||
public bool showGizmo;
|
||||
public Color gizmoLabelColor;
|
||||
|
||||
public bool useEventsOnMoveStartAndEnd;
|
||||
public UnityEvent eventOnMoveStart;
|
||||
public UnityEvent eventOnMoveEnd;
|
||||
|
||||
int currentDirectionToMove = 1;
|
||||
|
||||
bool anyPlayerInsideElevator;
|
||||
|
||||
int i;
|
||||
bool lockedElevator;
|
||||
bool closingDoors;
|
||||
Coroutine elevatorMovement;
|
||||
mapObjectInformation mapObjectInformationManager;
|
||||
|
||||
public List<passengersInfo> passengersInfoList = new List<passengersInfo> ();
|
||||
|
||||
List<GameObject> regularObjectsList = new List<GameObject> ();
|
||||
|
||||
int previousFloorIndex;
|
||||
|
||||
doorSystem insideElevatorDoorSystem;
|
||||
|
||||
bool allDoorsClosed;
|
||||
|
||||
floorInfo currentFloorInfo;
|
||||
|
||||
bool insideElevatorDoorLocated;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (mapObjectInformationManager == null) {
|
||||
mapObjectInformationManager = GetComponent<mapObjectInformation> ();
|
||||
}
|
||||
|
||||
if (insideElevatorDoor != null) {
|
||||
insideElevatorDoorSystem = insideElevatorDoor.GetComponent<doorSystem> ();
|
||||
|
||||
insideElevatorDoorLocated = insideElevatorDoorSystem != null;
|
||||
}
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
//check if there is doors in the elevator to close them and start the elevator movement when they are closed
|
||||
if (closingDoors) {
|
||||
if (insideElevatorDoorLocated || floors [previousFloorIndex].outsideElevatorDoorLocated) {
|
||||
allDoorsClosed = false;
|
||||
|
||||
//print (!insideElevatorDoorSystem + " " + insideElevatorDoorSystem.isDoorClosed ());
|
||||
|
||||
// print (!floors [previousFloorIndex].outsideElevatorDoorSystem + " " + floors [previousFloorIndex].outsideElevatorDoorSystem.isDoorClosed ());
|
||||
|
||||
if ((!insideElevatorDoorLocated || insideElevatorDoorSystem.isDoorClosed ()) &&
|
||||
(!floors [previousFloorIndex].outsideElevatorDoorLocated || floors [previousFloorIndex].outsideElevatorDoorSystem.isDoorClosed ())) {
|
||||
allDoorsClosed = true;
|
||||
}
|
||||
|
||||
if (allDoorsClosed) {
|
||||
closingDoors = false;
|
||||
|
||||
checkElevatorMovement ();
|
||||
}
|
||||
} else {
|
||||
closingDoors = false;
|
||||
|
||||
checkElevatorMovement ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//the player has press the button move up, so increase the current floor count
|
||||
public void nextFloor ()
|
||||
{
|
||||
if (!elevatorSystemEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
getFloorNumberToMove (1);
|
||||
}
|
||||
|
||||
//the player has press the button move down, so decrease the current floor count
|
||||
public void previousFloor ()
|
||||
{
|
||||
if (!elevatorSystemEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
getFloorNumberToMove (-1);
|
||||
}
|
||||
|
||||
public void moveBetweenTwoPositions ()
|
||||
{
|
||||
if (!elevatorSystemEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
getFloorNumberToMove (currentDirectionToMove);
|
||||
|
||||
currentDirectionToMove *= -1;
|
||||
}
|
||||
|
||||
//move to the floor, according to the direction selected by the player
|
||||
void getFloorNumberToMove (int direction)
|
||||
{
|
||||
//if the player is inside the elevator and it is not moving, then
|
||||
if ((anyPlayerInsideElevator || canUseElevatorButtonsWithoutPlayerInside) && !moving) {
|
||||
//change the current floor to the next or the previous
|
||||
int floorIndex = currentFloor + direction;
|
||||
|
||||
//check that the floor exists, and start to move the elevator to that floor position
|
||||
if (floorIndex < floors.Count && floorIndex >= 0) {
|
||||
openOrCloseElevatorDoors ();
|
||||
|
||||
previousFloorIndex = currentFloor;
|
||||
|
||||
currentFloor = floorIndex;
|
||||
|
||||
checkIfInsideElevatorDoorSystem ();
|
||||
|
||||
closingDoors = true;
|
||||
|
||||
setAllPlayersParent (transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void checkIfInsideElevatorDoorSystem ()
|
||||
{
|
||||
if (floors [currentFloor].outsideElevatorDoor != null) {
|
||||
if (!floors [currentFloor].outsideElevatorDoorLocated) {
|
||||
floors [currentFloor].outsideElevatorDoorSystem = floors [currentFloor].outsideElevatorDoor.GetComponent<doorSystem> ();
|
||||
|
||||
floors [currentFloor].outsideElevatorDoorLocated = floors [currentFloor].outsideElevatorDoorSystem != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//move to the floor, according to the direction selected by the player
|
||||
public bool goToNumberFloor (int floorNumber)
|
||||
{
|
||||
if (!elevatorSystemEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool canMoveToFloor = false;
|
||||
|
||||
//if the player is inside the elevator and it is not moving, then
|
||||
if ((anyPlayerInsideElevator || canUseElevatorButtonsWithoutPlayerInside) && !moving) {
|
||||
//check that the floor exists, and start to move the elevator to that floor position
|
||||
if (floorNumber < floors.Count && floorNumber >= 0 && floorNumber != currentFloor) {
|
||||
openOrCloseElevatorDoors ();
|
||||
|
||||
previousFloorIndex = currentFloor;
|
||||
|
||||
currentFloor = floorNumber;
|
||||
|
||||
checkIfInsideElevatorDoorSystem ();
|
||||
|
||||
closingDoors = true;
|
||||
|
||||
setAllPlayersParent (transform);
|
||||
|
||||
canMoveToFloor = true;
|
||||
}
|
||||
}
|
||||
|
||||
return canMoveToFloor;
|
||||
}
|
||||
|
||||
//when a elevator button is pressed, move the elevator to that floor
|
||||
public void callElevator (GameObject button)
|
||||
{
|
||||
if (!elevatorSystemEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (moving) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < floors.Count; i++) {
|
||||
if (floors [i].floorButton == button) {
|
||||
|
||||
lockedElevator = false;
|
||||
|
||||
if (floors [currentFloor].outsideElevatorDoor != null) {
|
||||
checkIfInsideElevatorDoorSystem ();
|
||||
|
||||
if (floors [currentFloor].outsideElevatorDoorSystem.locked) {
|
||||
lockedElevator = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!lockedElevator) {
|
||||
if (currentFloor != i) {
|
||||
if (!doorsClosed) {
|
||||
openOrCloseElevatorDoors ();
|
||||
}
|
||||
|
||||
previousFloorIndex = currentFloor;
|
||||
|
||||
currentFloor = i;
|
||||
|
||||
checkIfInsideElevatorDoorSystem ();
|
||||
|
||||
closingDoors = true;
|
||||
} else {
|
||||
openOrCloseElevatorDoors ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//open or close the inside and outside doors of the elevator if the elevator has every of this doors
|
||||
void openOrCloseElevatorDoors ()
|
||||
{
|
||||
if (insideElevatorDoor != null) {
|
||||
if (insideElevatorDoorSystem.doorState == doorSystem.doorCurrentState.closed) {
|
||||
doorsClosed = false;
|
||||
} else {
|
||||
doorsClosed = true;
|
||||
}
|
||||
|
||||
insideElevatorDoorSystem.changeDoorsStateByButton ();
|
||||
}
|
||||
|
||||
if (floors [currentFloor].outsideElevatorDoor != null) {
|
||||
checkIfInsideElevatorDoorSystem ();
|
||||
|
||||
floors [currentFloor].outsideElevatorDoorSystem.openOrCloseElevatorDoor ();
|
||||
}
|
||||
}
|
||||
|
||||
//stop the current elevator movement and start it again
|
||||
void checkElevatorMovement ()
|
||||
{
|
||||
if (elevatorMovement != null) {
|
||||
StopCoroutine (elevatorMovement);
|
||||
}
|
||||
|
||||
elevatorMovement = StartCoroutine (moveElevator ());
|
||||
}
|
||||
|
||||
IEnumerator moveElevator ()
|
||||
{
|
||||
moving = true;
|
||||
|
||||
currentFloorInfo = floors [currentFloor];
|
||||
|
||||
//move the elevator from its position to the currentfloor
|
||||
Vector3 currentElevatorPosition = transform.localPosition;
|
||||
|
||||
Vector3 targetPosition = currentFloorInfo.floorPosition.localPosition;
|
||||
Quaternion targetRotation = currentFloorInfo.floorPosition.localRotation;
|
||||
|
||||
bool rotateElevator = false;
|
||||
|
||||
if (targetRotation != Quaternion.identity || transform.localRotation != Quaternion.identity) {
|
||||
rotateElevator = true;
|
||||
}
|
||||
|
||||
float dist = GKC_Utils.distance (transform.position, currentFloorInfo.floorPosition.position);
|
||||
|
||||
// calculate the movement duration
|
||||
float duration = dist / elevatorSpeed;
|
||||
float t = 0;
|
||||
|
||||
bool targetReached = false;
|
||||
|
||||
float angleDifference = 0;
|
||||
|
||||
float movementTimer = 0;
|
||||
|
||||
float distanceToTarget = 0;
|
||||
|
||||
checkEventsOnMove (true);
|
||||
|
||||
if (currentFloorInfo.useEventsOnMoveStartAndEnd) {
|
||||
currentFloorInfo.eventOnMoveStart.Invoke ();
|
||||
}
|
||||
|
||||
while (!targetReached) {
|
||||
t += Time.deltaTime / duration;
|
||||
|
||||
transform.localPosition = Vector3.Lerp (currentElevatorPosition, targetPosition, t);
|
||||
|
||||
if (rotateElevator) {
|
||||
transform.localRotation = Quaternion.Lerp (transform.localRotation, targetRotation, t);
|
||||
}
|
||||
|
||||
angleDifference = Quaternion.Angle (transform.localRotation, targetRotation);
|
||||
|
||||
movementTimer += Time.deltaTime;
|
||||
|
||||
dist = GKC_Utils.distance (transform.localPosition, targetPosition);
|
||||
|
||||
distanceToTarget = GKC_Utils.distance (transform.localPosition, targetPosition);
|
||||
|
||||
if ((dist < 0.02f && angleDifference < 0.02f && distanceToTarget < 0.02f) || movementTimer > (duration + 0.5f)) {
|
||||
targetReached = true;
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
//if the elevator reachs the correct floor, stop its movement, and deattach the player of its childs
|
||||
moving = false;
|
||||
|
||||
setAllPlayersParent (null);
|
||||
|
||||
openOrCloseElevatorDoors ();
|
||||
|
||||
if (changeIconFloorWhenMoving) {
|
||||
if (mapObjectInformationManager != null) {
|
||||
mapObjectInformationManager.changeMapObjectIconFloorByPosition ();
|
||||
}
|
||||
}
|
||||
|
||||
checkEventsOnMove (false);
|
||||
|
||||
if (currentFloorInfo.useEventsOnMoveStartAndEnd) {
|
||||
currentFloorInfo.eventOnMoveEnd.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerEnter (Collider col)
|
||||
{
|
||||
//the player has entered in the elevator trigger, stored it and set the evelator as his parent
|
||||
if (col.CompareTag ("Player")) {
|
||||
addPassenger (col.gameObject.transform);
|
||||
|
||||
if (passengersInfoList.Count > 0) {
|
||||
anyPlayerInsideElevator = true;
|
||||
}
|
||||
|
||||
setPlayerParent (transform, col.gameObject.transform);
|
||||
} else if (tagToCheckToMove.Contains (col.gameObject.tag)) {
|
||||
if (!regularObjectsList.Contains (col.gameObject)) {
|
||||
col.gameObject.transform.SetParent (transform);
|
||||
|
||||
regularObjectsList.Add (col.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit (Collider col)
|
||||
{
|
||||
//the player has gone of the elevator trigger, remove the parent from the player
|
||||
if (col.CompareTag ("Player")) {
|
||||
|
||||
setPlayerParent (null, col.gameObject.transform);
|
||||
|
||||
removePassenger (col.gameObject.transform);
|
||||
|
||||
if (passengersInfoList.Count == 0) {
|
||||
anyPlayerInsideElevator = false;
|
||||
}
|
||||
|
||||
if (!doorsClosed) {
|
||||
openOrCloseElevatorDoors ();
|
||||
}
|
||||
} else if (tagToCheckToMove.Contains (col.gameObject.tag)) {
|
||||
if (regularObjectsList.Contains (col.gameObject)) {
|
||||
col.gameObject.transform.SetParent (null);
|
||||
|
||||
regularObjectsList.Remove (col.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//attach and disattch the player and the camera inside the elevator
|
||||
void setPlayerParent (Transform father, Transform newPassenger)
|
||||
{
|
||||
bool passengerFound = false;
|
||||
|
||||
passengersInfo newPassengersInfo = new passengersInfo ();
|
||||
|
||||
for (i = 0; i < passengersInfoList.Count; i++) {
|
||||
if (passengersInfoList [i].playerTransform == newPassenger && !passengerFound) {
|
||||
newPassengersInfo = passengersInfoList [i];
|
||||
passengerFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (passengerFound) {
|
||||
newPassengersInfo.playerControllerManager.setPlayerAndCameraAndFBAPivotTransformParent (father);
|
||||
|
||||
newPassengersInfo.playerControllerManager.setMovingOnPlatformActiveState (father != null);
|
||||
}
|
||||
}
|
||||
|
||||
void setAllPlayersParent (Transform father)
|
||||
{
|
||||
for (i = 0; i < passengersInfoList.Count; i++) {
|
||||
passengersInfoList [i].playerControllerManager.setPlayerAndCameraAndFBAPivotTransformParent (father);
|
||||
|
||||
passengersInfoList [i].playerControllerManager.setMovingOnPlatformActiveState (father != null);
|
||||
}
|
||||
}
|
||||
|
||||
public void addPassenger (Transform newPassenger)
|
||||
{
|
||||
bool passengerFound = false;
|
||||
for (i = 0; i < passengersInfoList.Count; i++) {
|
||||
if (passengersInfoList [i].playerTransform == newPassenger && !passengerFound) {
|
||||
passengerFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!passengerFound) {
|
||||
passengersInfo newPassengersInfo = new passengersInfo ();
|
||||
|
||||
newPassengersInfo.playerTransform = newPassenger;
|
||||
|
||||
newPassengersInfo.playerControllerManager = newPassenger.GetComponent<playerController> ();
|
||||
|
||||
passengersInfoList.Add (newPassengersInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void removePassenger (Transform newPassenger)
|
||||
{
|
||||
for (i = 0; i < passengersInfoList.Count; i++) {
|
||||
if (passengersInfoList [i].playerTransform == newPassenger) {
|
||||
passengersInfoList.RemoveAt (i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setElevatorSystemEnabledState (bool state)
|
||||
{
|
||||
elevatorSystemEnabled = state;
|
||||
}
|
||||
|
||||
//add a new floor, with a switch and a door, if they are enabled to add them
|
||||
public void addNewFloor ()
|
||||
{
|
||||
floorInfo newFloorInfo = new floorInfo ();
|
||||
|
||||
GameObject newFloor = new GameObject ();
|
||||
|
||||
newFloor.transform.SetParent (transform.parent);
|
||||
newFloor.transform.localRotation = Quaternion.identity;
|
||||
|
||||
Vector3 newFloorLocalposition = Vector3.zero;
|
||||
|
||||
if (floors.Count > 0) {
|
||||
newFloorLocalposition = floors [floors.Count - 1].floorPosition.position + floors [floors.Count - 1].floorPosition.up * floorHeight;
|
||||
}
|
||||
|
||||
newFloor.transform.position = newFloorLocalposition;
|
||||
newFloor.name = "Floor " + floors.Count;
|
||||
|
||||
newFloorInfo.name = newFloor.name;
|
||||
newFloorInfo.floorNumber = floors.Count;
|
||||
newFloorInfo.floorPosition = newFloor.transform;
|
||||
|
||||
if (addSwitchInNewFloors) {
|
||||
newFloorInfo.hasFloorButton = true;
|
||||
}
|
||||
|
||||
if (addDoorInNewFloors) {
|
||||
newFloorInfo.hasOutSideElevatorDoor = true;
|
||||
}
|
||||
|
||||
//add a switch
|
||||
if (addSwitchInNewFloors) {
|
||||
GameObject newSwitch = (GameObject)Instantiate (elevatorSwitchPrefab, Vector3.zero, Quaternion.identity);
|
||||
newSwitch.transform.SetParent (transform.parent);
|
||||
newSwitch.transform.position = newFloorLocalposition + transform.forward * 6 - transform.right * 5;
|
||||
newSwitch.name = "Elevator Switch " + floors.Count;
|
||||
|
||||
newFloorInfo.floorButton = newSwitch;
|
||||
newSwitch.transform.SetParent (newFloor.transform);
|
||||
|
||||
simpleSwitch currentSimpleSwitch = newSwitch.GetComponent<simpleSwitch> ();
|
||||
currentSimpleSwitch.objectToActive = gameObject;
|
||||
|
||||
GKC_Utils.updateComponent (currentSimpleSwitch);
|
||||
}
|
||||
|
||||
//add a door
|
||||
if (addDoorInNewFloors) {
|
||||
GameObject newDoor = (GameObject)Instantiate (elevatorDoorPrefab, Vector3.zero, Quaternion.identity);
|
||||
newDoor.transform.SetParent (transform.parent);
|
||||
newDoor.transform.position = newFloorLocalposition + transform.forward * 5;
|
||||
|
||||
newDoor.name = "Elevator Door " + floors.Count;
|
||||
newFloorInfo.outsideElevatorDoor = newDoor;
|
||||
newDoor.transform.SetParent (newFloor.transform);
|
||||
}
|
||||
|
||||
floors.Add (newFloorInfo);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void removeFloor (int floorIndex)
|
||||
{
|
||||
if (floors [floorIndex].floorPosition != null) {
|
||||
DestroyImmediate (floors [floorIndex].floorPosition.gameObject);
|
||||
}
|
||||
|
||||
floors.RemoveAt (floorIndex);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void removeAllFloors ()
|
||||
{
|
||||
for (i = 0; i < floors.Count; i++) {
|
||||
DestroyImmediate (floors [i].floorPosition.gameObject);
|
||||
}
|
||||
|
||||
floors.Clear ();
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void checkEventsOnMove (bool state)
|
||||
{
|
||||
if (useEventsOnMoveStartAndEnd) {
|
||||
if (state) {
|
||||
eventOnMoveStart.Invoke ();
|
||||
} else {
|
||||
eventOnMoveEnd.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
}
|
||||
|
||||
//draw every floor position and a line between floors
|
||||
#if UNITY_EDITOR
|
||||
void OnDrawGizmos ()
|
||||
{
|
||||
if (!showGizmo) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
|
||||
DrawGizmos ();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected ()
|
||||
{
|
||||
DrawGizmos ();
|
||||
}
|
||||
|
||||
//draw the pivot and the final positions of every door
|
||||
void DrawGizmos ()
|
||||
{
|
||||
if (showGizmo) {
|
||||
if (!Application.isPlaying) {
|
||||
for (i = 0; i < floors.Count; i++) {
|
||||
if (floors [i].floorPosition != null) {
|
||||
Gizmos.color = Color.yellow;
|
||||
|
||||
if (floors [i].floorNumber == currentFloor) {
|
||||
Gizmos.color = Color.red;
|
||||
}
|
||||
|
||||
Gizmos.DrawSphere (floors [i].floorPosition.position, 0.6f);
|
||||
|
||||
if (i + 1 < floors.Count && floors [i + 1].floorPosition != null) {
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawLine (floors [i].floorPosition.position, floors [i + 1].floorPosition.position);
|
||||
}
|
||||
|
||||
if (floors [i].floorButton != null) {
|
||||
Gizmos.color = Color.blue;
|
||||
Gizmos.DrawLine (floors [i].floorButton.transform.position, floors [i].floorPosition.position);
|
||||
|
||||
Gizmos.color = Color.green;
|
||||
Gizmos.DrawSphere (floors [i].floorButton.transform.position, 0.3f);
|
||||
|
||||
if (floors [i].outsideElevatorDoor) {
|
||||
Gizmos.color = Color.white;
|
||||
Gizmos.DrawLine (floors [i].floorButton.transform.position, floors [i].outsideElevatorDoor.transform.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
[System.Serializable]
|
||||
public class floorInfo
|
||||
{
|
||||
public string name;
|
||||
public int floorNumber;
|
||||
public Transform floorPosition;
|
||||
public bool hasFloorButton;
|
||||
public GameObject floorButton;
|
||||
public bool hasOutSideElevatorDoor;
|
||||
public GameObject outsideElevatorDoor;
|
||||
|
||||
public doorSystem outsideElevatorDoorSystem;
|
||||
|
||||
public bool outsideElevatorDoorLocated;
|
||||
|
||||
public bool useEventsOnMoveStartAndEnd;
|
||||
public UnityEvent eventOnMoveStart;
|
||||
public UnityEvent eventOnMoveEnd;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class passengersInfo
|
||||
{
|
||||
public Transform playerTransform;
|
||||
public playerController playerControllerManager;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f83aa9c09aff20049a4b5c0f91ad531a
|
||||
timeCreated: 1465501545
|
||||
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/Devices/elevatorSystem.cs
|
||||
uploadId: 814740
|
||||
91
Assets/Game Kit Controller/Scripts/Devices/enemyHackPanel.cs
Normal file
91
Assets/Game Kit Controller/Scripts/Devices/enemyHackPanel.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class enemyHackPanel : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public GameObject hackPanel;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool usingDevice;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public hackTerminal hackTerinalManager;
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public UnityEvent startHackFunction = new UnityEvent ();
|
||||
public UnityEvent correctHackedlyFunction = new UnityEvent ();
|
||||
public UnityEvent incorrectlyHackedFunction = new UnityEvent ();
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (hackTerinalManager == null) {
|
||||
hackTerinalManager = hackPanel.GetComponent<hackTerminal> ();
|
||||
}
|
||||
}
|
||||
|
||||
//activates a function to activate the hacking of a turret, but it can be used to any other type of device
|
||||
public void activateHackPanel (bool state)
|
||||
{
|
||||
usingDevice = state;
|
||||
|
||||
if (usingDevice) {
|
||||
if (startHackFunction.GetPersistentEventCount () > 0) {
|
||||
startHackFunction.Invoke ();
|
||||
}
|
||||
|
||||
hackTerinalManager.activeHack ();
|
||||
} else {
|
||||
hackTerinalManager.stopHacking ();
|
||||
}
|
||||
}
|
||||
|
||||
public void setCorrectlyHackedState ()
|
||||
{
|
||||
setHackResult (true);
|
||||
}
|
||||
|
||||
public void setIncorrectlyHackedState ()
|
||||
{
|
||||
setHackResult (false);
|
||||
}
|
||||
|
||||
//send the hack result to the enemy
|
||||
public void setHackResult (bool state)
|
||||
{
|
||||
if (state) {
|
||||
if (correctHackedlyFunction.GetPersistentEventCount () > 0) {
|
||||
correctHackedlyFunction.Invoke ();
|
||||
}
|
||||
} else {
|
||||
if (incorrectlyHackedFunction.GetPersistentEventCount () > 0) {
|
||||
incorrectlyHackedFunction.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//close the hack panel once the enemy has been hacked
|
||||
public void disablePanelHack ()
|
||||
{
|
||||
StartCoroutine (disablePanelHackCoroutine ());
|
||||
}
|
||||
|
||||
IEnumerator disablePanelHackCoroutine ()
|
||||
{
|
||||
yield return new WaitForSeconds (1);
|
||||
|
||||
hackTerinalManager.moveHackTerminal (false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c363a3fc19a246e4c9638dfaae7f8ce1
|
||||
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/Devices/enemyHackPanel.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,492 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using System.Collections.Generic;
|
||||
using GameKitController.Audio;
|
||||
|
||||
public class examineObjectSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool objectCanBeRotated;
|
||||
public float rotationSpeed;
|
||||
|
||||
public bool horizontalRotationEnabled = true;
|
||||
public bool verticalRotationEnabled = true;
|
||||
|
||||
public bool zoomCanBeUsed;
|
||||
public bool rotationEnabled = true;
|
||||
|
||||
public bool activateActionScreen = true;
|
||||
public string actionScreenName = "Examine Object";
|
||||
|
||||
public bool useExamineMessage;
|
||||
[TextArea (1, 10)] public string examineMessage;
|
||||
|
||||
[Space]
|
||||
[Header ("Press Positions Settings")]
|
||||
[Space]
|
||||
|
||||
public bool pressPlacesInOrder;
|
||||
public int currentPlacePressedIndex;
|
||||
public bool useIncorrectPlacePressedMessage;
|
||||
[TextArea (1, 10)] public string incorrectPlacePressedMessage;
|
||||
public float incorrectPlacePressedMessageDuration;
|
||||
|
||||
[Space]
|
||||
[Header ("Canvas Settings")]
|
||||
[Space]
|
||||
|
||||
public bool objectUsesCanvas;
|
||||
public Canvas mainCanvas;
|
||||
public bool useTriggerOnTopOfCanvas;
|
||||
public GameObject triggerOnTopOfCanvas;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
public bool usingDevice;
|
||||
public GameObject currentPlayer;
|
||||
|
||||
public bool rotationPaused;
|
||||
|
||||
[Space]
|
||||
[Header ("Examine Place List")]
|
||||
[Space]
|
||||
|
||||
public List<examinePlaceInfo> examinePlaceList = new List<examinePlaceInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useSecundaryCancelExamineFunction;
|
||||
public UnityEvent secundaryCancelExamineFunction = new UnityEvent ();
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Transform objectTransform;
|
||||
|
||||
public moveDeviceToCamera moveDeviceToCameraManager;
|
||||
public electronicDevice electronicDeviceManager;
|
||||
public Collider mainCollider;
|
||||
public AudioSource mainAudioSource;
|
||||
|
||||
|
||||
playerInputManager playerInput;
|
||||
bool touchPlatform;
|
||||
Touch currentTouch;
|
||||
bool touching;
|
||||
|
||||
usingDevicesSystem usingDevicesManager;
|
||||
examineObjectSystemPlayerManagement examineObjectSystemPlayerManager;
|
||||
Camera deviceCamera;
|
||||
playerComponentsManager mainPlayerComponentsManager;
|
||||
|
||||
bool showingMessage;
|
||||
|
||||
Ray ray;
|
||||
RaycastHit hit;
|
||||
|
||||
|
||||
private void InitializeAudioElements ()
|
||||
{
|
||||
if (mainAudioSource == null) {
|
||||
mainAudioSource = GetComponent<AudioSource> ();
|
||||
}
|
||||
|
||||
foreach (var examinePlaceInfo in examinePlaceList) {
|
||||
examinePlaceInfo.InitializeAudioElements ();
|
||||
|
||||
if (mainAudioSource != null) {
|
||||
examinePlaceInfo.soundOnPressAudioElement.audioSource = mainAudioSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Start ()
|
||||
{
|
||||
touchPlatform = touchJoystick.checkTouchPlatform ();
|
||||
|
||||
if (moveDeviceToCameraManager == null) {
|
||||
moveDeviceToCameraManager = GetComponent<moveDeviceToCamera> ();
|
||||
}
|
||||
|
||||
if (objectTransform == null) {
|
||||
objectTransform = transform;
|
||||
}
|
||||
|
||||
if (electronicDeviceManager == null) {
|
||||
electronicDeviceManager = GetComponent<electronicDevice> ();
|
||||
}
|
||||
|
||||
if (mainCollider == null) {
|
||||
mainCollider = GetComponent<Collider> ();
|
||||
}
|
||||
|
||||
InitializeAudioElements ();
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (usingDevice) {
|
||||
if (objectCanBeRotated && rotationEnabled && !rotationPaused) {
|
||||
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;
|
||||
|
||||
if (objectUsesCanvas && useTriggerOnTopOfCanvas) {
|
||||
ray = deviceCamera.ScreenPointToRay (currentTouch.position);
|
||||
if (Physics.Raycast (ray, out hit, 20)) {
|
||||
if (hit.collider.gameObject == triggerOnTopOfCanvas) {
|
||||
touching = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (currentTouch.phase == TouchPhase.Ended) {
|
||||
touching = false;
|
||||
}
|
||||
|
||||
bool canRotateObject = false;
|
||||
|
||||
if (touching && (currentTouch.phase == TouchPhase.Moved || currentTouch.phase == TouchPhase.Stationary)) {
|
||||
canRotateObject = true;
|
||||
}
|
||||
|
||||
if (!canRotateObject) {
|
||||
if (playerInput.isUsingGamepad ()) {
|
||||
canRotateObject = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (canRotateObject) {
|
||||
if (horizontalRotationEnabled) {
|
||||
objectTransform.Rotate (deviceCamera.transform.up, -Mathf.Deg2Rad * rotationSpeed * playerInput.getPlayerMouseAxis ().x * 10, Space.World);
|
||||
}
|
||||
|
||||
if (verticalRotationEnabled) {
|
||||
objectTransform.Rotate (deviceCamera.transform.right, Mathf.Deg2Rad * rotationSpeed * playerInput.getPlayerMouseAxis ().y * 10, Space.World);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void showExamineMessage (bool state)
|
||||
{
|
||||
showingMessage = state;
|
||||
|
||||
getPlayerComponents ();
|
||||
|
||||
if (showingMessage) {
|
||||
usingDevicesManager.checkShowObjectMessage (examineMessage, 0);
|
||||
} else {
|
||||
usingDevicesManager.stopShowObjectMessage ();
|
||||
}
|
||||
}
|
||||
|
||||
public void stopExamineDevice ()
|
||||
{
|
||||
if (usingDevicesManager != null) {
|
||||
usingDevicesManager.useDevice ();
|
||||
}
|
||||
}
|
||||
|
||||
public void disableAndRemoveExamineDevice ()
|
||||
{
|
||||
if (usingDevicesManager != null) {
|
||||
moveDeviceToCameraManager.setIgnoreDeviceTriggerEnabledState (true);
|
||||
|
||||
mainCollider.enabled = false;
|
||||
|
||||
usingDevicesManager.removeDeviceFromListExternalCall (gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void cancelExamine ()
|
||||
{
|
||||
if (secundaryCancelExamineFunction.GetPersistentEventCount () > 0) {
|
||||
secundaryCancelExamineFunction.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
public void pauseOrResumePlayerInteractionButton (bool state)
|
||||
{
|
||||
if (usingDevicesManager != null) {
|
||||
usingDevicesManager.setUseDeviceButtonEnabledState (!state);
|
||||
}
|
||||
}
|
||||
|
||||
//enable or disable the device
|
||||
public void examineDevice ()
|
||||
{
|
||||
usingDevice = !usingDevice;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("examineDevice " + usingDevice);
|
||||
}
|
||||
|
||||
if (usingDevice) {
|
||||
getPlayerComponents ();
|
||||
} else {
|
||||
showExamineMessage (false);
|
||||
}
|
||||
|
||||
if (activateActionScreen) {
|
||||
playerInput.enableOrDisableActionScreen (actionScreenName, usingDevice);
|
||||
}
|
||||
|
||||
if (examineObjectSystemPlayerManager != null) {
|
||||
examineObjectSystemPlayerManager.setExaminingObjectState (usingDevice);
|
||||
}
|
||||
|
||||
if (!usingDevice) {
|
||||
rotationPaused = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setExamineDeviceState (bool state)
|
||||
{
|
||||
usingDevice = state;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("setExamineDeviceState " + usingDevice);
|
||||
}
|
||||
|
||||
if (!usingDevice) {
|
||||
touching = false;
|
||||
}
|
||||
|
||||
if (examineObjectSystemPlayerManager != null) {
|
||||
examineObjectSystemPlayerManager.setExaminingObjectState (usingDevice);
|
||||
}
|
||||
|
||||
if (!usingDevice) {
|
||||
rotationPaused = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setRotationState (bool state)
|
||||
{
|
||||
rotationPaused = !state;
|
||||
}
|
||||
|
||||
public void getPlayerComponents ()
|
||||
{
|
||||
currentPlayer = electronicDeviceManager.getCurrentPlayer ();
|
||||
|
||||
if (currentPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
usingDevicesManager = mainPlayerComponentsManager.getUsingDevicesSystem ();
|
||||
|
||||
playerInput = mainPlayerComponentsManager.getPlayerInputManager ();
|
||||
|
||||
examineObjectSystemPlayerManager = mainPlayerComponentsManager.getExamineObjectSystemPlayerManagement ();
|
||||
|
||||
examineObjectSystemPlayerManager.setcurrentExanimeObject (this);
|
||||
|
||||
deviceCamera = usingDevicesManager.getExaminateDevicesCamera ();
|
||||
|
||||
if (objectUsesCanvas) {
|
||||
mainCanvas.worldCamera = deviceCamera;
|
||||
}
|
||||
}
|
||||
|
||||
public void checkExaminePlaceInfo (Transform examinePlaceToCheck)
|
||||
{
|
||||
for (int i = 0; i < examinePlaceList.Count; i++) {
|
||||
if (!examinePlaceList [i].elementPlaceDisabled && examinePlaceList [i].examinePlaceTransform == examinePlaceToCheck) {
|
||||
|
||||
if (pressPlacesInOrder) {
|
||||
if (i == currentPlacePressedIndex) {
|
||||
currentPlacePressedIndex++;
|
||||
} else {
|
||||
currentPlacePressedIndex = 0;
|
||||
|
||||
if (useIncorrectPlacePressedMessage) {
|
||||
usingDevicesManager.checkShowObjectMessage (incorrectPlacePressedMessage, incorrectPlacePressedMessageDuration);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (examinePlaceList [i].showMessageOnPress) {
|
||||
usingDevicesManager.checkShowObjectMessage (examinePlaceList [i].messageOnPress, examinePlaceList [i].messageDuration);
|
||||
}
|
||||
|
||||
if (examinePlaceList [i].stopUseObjectOnPress) {
|
||||
usingDevicesManager.useDevice ();
|
||||
}
|
||||
|
||||
if (examinePlaceList [i].disableObjectInteractionOnPress) {
|
||||
moveDeviceToCameraManager.setIgnoreDeviceTriggerEnabledState (true);
|
||||
|
||||
mainCollider.enabled = false;
|
||||
|
||||
if (examinePlaceList [i].removeObjectFromDevicesList) {
|
||||
usingDevicesManager.removeDeviceFromListExternalCall (gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
if (examinePlaceList [i].useEventOnPress) {
|
||||
if (examinePlaceList [i].sendPlayerOnEvent) {
|
||||
examinePlaceList [i].eventToSendPlayer.Invoke (currentPlayer);
|
||||
}
|
||||
|
||||
examinePlaceList [i].eventOnPress.Invoke ();
|
||||
}
|
||||
|
||||
if (examinePlaceList [i].resumePlayerInteractionButtonOnPress) {
|
||||
usingDevicesManager.setUseDeviceButtonEnabledState (true);
|
||||
}
|
||||
|
||||
if (examinePlaceList [i].pausePlayerInteractionButtonOnPress) {
|
||||
usingDevicesManager.setUseDeviceButtonEnabledState (false);
|
||||
}
|
||||
|
||||
if (examinePlaceList [i].disableElementPlaceAfterPress) {
|
||||
examinePlaceList [i].elementPlaceDisabled = true;
|
||||
}
|
||||
|
||||
if (examinePlaceList [i].useSoundOnPress) {
|
||||
if (examinePlaceList [i].soundOnPressAudioElement != null) {
|
||||
AudioPlayer.PlayOneShot (examinePlaceList [i].soundOnPressAudioElement, gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setExaminePlaceEnabledState (Transform examinePlaceToCheck)
|
||||
{
|
||||
for (int i = 0; i < examinePlaceList.Count; i++) {
|
||||
if (examinePlaceList [i].examinePlaceTransform == examinePlaceToCheck) {
|
||||
examinePlaceList [i].elementPlaceDisabled = true;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//CALL INPUT FUNCTIONS
|
||||
public void inputSetZoomValue (bool state)
|
||||
{
|
||||
if (usingDevice && objectCanBeRotated && rotationEnabled && !rotationPaused) {
|
||||
|
||||
if (zoomCanBeUsed) {
|
||||
if (state) {
|
||||
moveDeviceToCameraManager.changeDeviceZoom (true);
|
||||
} else {
|
||||
moveDeviceToCameraManager.changeDeviceZoom (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void inputResetRotation ()
|
||||
{
|
||||
if (usingDevice && objectCanBeRotated && rotationEnabled && !rotationPaused) {
|
||||
|
||||
if (zoomCanBeUsed) {
|
||||
|
||||
moveDeviceToCameraManager.resetRotation ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void inputResetRotationAndPosition ()
|
||||
{
|
||||
if (usingDevice && objectCanBeRotated && rotationEnabled && !rotationPaused) {
|
||||
|
||||
if (zoomCanBeUsed) {
|
||||
|
||||
moveDeviceToCameraManager.resetRotationAndPosition ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void inputCancelExamine ()
|
||||
{
|
||||
if (usingDevice) {
|
||||
if (useSecundaryCancelExamineFunction) {
|
||||
cancelExamine ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void inputCheckIfMessage ()
|
||||
{
|
||||
if (usingDevice) {
|
||||
if (useExamineMessage) {
|
||||
showExamineMessage (!showingMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class examinePlaceInfo
|
||||
{
|
||||
public string Name;
|
||||
|
||||
public Transform examinePlaceTransform;
|
||||
|
||||
public bool showMessageOnPress;
|
||||
[TextArea (1, 10)] public string messageOnPress;
|
||||
public float messageDuration;
|
||||
|
||||
public bool useEventOnPress;
|
||||
public UnityEvent eventOnPress;
|
||||
|
||||
public bool sendPlayerOnEvent;
|
||||
public eventParameters.eventToCallWithGameObject eventToSendPlayer;
|
||||
|
||||
public bool stopUseObjectOnPress;
|
||||
public bool disableObjectInteractionOnPress;
|
||||
public bool removeObjectFromDevicesList;
|
||||
|
||||
public bool resumePlayerInteractionButtonOnPress;
|
||||
public bool pausePlayerInteractionButtonOnPress;
|
||||
|
||||
public bool disableElementPlaceAfterPress;
|
||||
|
||||
public bool elementPlaceDisabled;
|
||||
|
||||
public bool useSoundOnPress;
|
||||
public AudioClip soundOnPress;
|
||||
public AudioElement soundOnPressAudioElement;
|
||||
|
||||
public void InitializeAudioElements ()
|
||||
{
|
||||
if (soundOnPress != null) {
|
||||
soundOnPressAudioElement.clip = soundOnPress;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f6bc73962c959a841adaa6f82613b3ea
|
||||
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/Devices/examineObjectSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,121 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class examineObjectSystemPlayerManagement : MonoBehaviour
|
||||
{
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
public bool examiningObject;
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventsOnStateChange;
|
||||
public UnityEvent evenOnStateEnabled;
|
||||
public UnityEvent eventOnStateDisabled;
|
||||
|
||||
examineObjectSystem currentExanimeObject;
|
||||
|
||||
float lastTimeExaminingObject = 0;
|
||||
|
||||
public void setExaminingObjectState (bool state)
|
||||
{
|
||||
examiningObject = state;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("Setting examine object state " + state);
|
||||
}
|
||||
|
||||
if (examiningObject) {
|
||||
lastTimeExaminingObject = Time.time;
|
||||
} else {
|
||||
lastTimeExaminingObject = 0;
|
||||
}
|
||||
|
||||
checkEventsOnStateChange (examiningObject);
|
||||
}
|
||||
|
||||
public void setcurrentExanimeObject (examineObjectSystem newExamineObject)
|
||||
{
|
||||
currentExanimeObject = newExamineObject;
|
||||
}
|
||||
|
||||
//CALL INPUT FUNCTIONS TO EXAMINE OBJECTS
|
||||
public void examineObjectInputSetZoomValue (bool value)
|
||||
{
|
||||
if (!examiningObject) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentExanimeObject != null) {
|
||||
currentExanimeObject.inputSetZoomValue (value);
|
||||
}
|
||||
}
|
||||
|
||||
public void examineObjectInputResetRotation ()
|
||||
{
|
||||
if (!examiningObject) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentExanimeObject != null) {
|
||||
currentExanimeObject.inputResetRotation ();
|
||||
}
|
||||
}
|
||||
|
||||
public void examineObjectInputResetRotationAndPosition ()
|
||||
{
|
||||
if (!examiningObject) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentExanimeObject != null) {
|
||||
currentExanimeObject.inputResetRotationAndPosition ();
|
||||
}
|
||||
}
|
||||
|
||||
public void examineObjectInputCancelExamine ()
|
||||
{
|
||||
if (!examiningObject) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (lastTimeExaminingObject > 0) {
|
||||
if (Time.time < lastTimeExaminingObject + 0.4f) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentExanimeObject != null) {
|
||||
currentExanimeObject.inputCancelExamine ();
|
||||
}
|
||||
}
|
||||
|
||||
public void examineObjectInputCheckIfMessage ()
|
||||
{
|
||||
if (!examiningObject) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentExanimeObject != null) {
|
||||
currentExanimeObject.inputCheckIfMessage ();
|
||||
}
|
||||
}
|
||||
|
||||
public void checkEventsOnStateChange (bool state)
|
||||
{
|
||||
if (useEventsOnStateChange) {
|
||||
if (state) {
|
||||
evenOnStateEnabled.Invoke ();
|
||||
} else {
|
||||
eventOnStateDisabled.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eca2273e7ce96914c8fbb62d6e030eb4
|
||||
timeCreated: 1548656446
|
||||
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/Devices/examineObjectSystemPlayerManagement.cs
|
||||
uploadId: 814740
|
||||
141
Assets/Game Kit Controller/Scripts/Devices/fallingPlatform.cs
Normal file
141
Assets/Game Kit Controller/Scripts/Devices/fallingPlatform.cs
Normal file
@@ -0,0 +1,141 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class fallingPlatform : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public float movementSpeed;
|
||||
public bool fallInTouch;
|
||||
public bool fallInTime;
|
||||
public float fallDelay;
|
||||
public bool resetDelayInExit;
|
||||
public float timeToBackInPosition;
|
||||
public float extraForceInFall;
|
||||
|
||||
public bool keepFallCheckOnFirstContact;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Rigidbody mainRigidbody;
|
||||
|
||||
bool inside;
|
||||
bool platformFallen;
|
||||
bool movePlatformToPosition;
|
||||
float timeOnPlatform;
|
||||
float fallenTime;
|
||||
Vector3 originalPosition;
|
||||
Quaternion originalRotation;
|
||||
|
||||
bool checkingToFallPlatform;
|
||||
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (mainRigidbody == null) {
|
||||
mainRigidbody = GetComponent<Rigidbody> ();
|
||||
}
|
||||
|
||||
originalPosition = transform.position;
|
||||
originalRotation = transform.rotation;
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (!movePlatformToPosition) {
|
||||
if (platformFallen && mainRigidbody.linearVelocity.magnitude < 1) {
|
||||
fallenTime += Time.deltaTime;
|
||||
|
||||
if (fallenTime > timeToBackInPosition) {
|
||||
StartCoroutine (moveToOriginalPosition ());
|
||||
|
||||
}
|
||||
} else {
|
||||
bool checkingToFall = false;
|
||||
|
||||
if (inside) {
|
||||
checkingToFall = true;
|
||||
} else {
|
||||
if (keepFallCheckOnFirstContact && checkingToFallPlatform) {
|
||||
checkingToFall = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (checkingToFall) {
|
||||
if (fallInTouch) {
|
||||
mainRigidbody.isKinematic = false;
|
||||
|
||||
mainRigidbody.AddForce (-transform.up * extraForceInFall);
|
||||
|
||||
platformFallen = true;
|
||||
fallenTime = 0;
|
||||
inside = false;
|
||||
|
||||
checkingToFallPlatform = false;
|
||||
}
|
||||
|
||||
if (fallInTime) {
|
||||
timeOnPlatform += Time.deltaTime;
|
||||
|
||||
if (timeOnPlatform > fallDelay) {
|
||||
mainRigidbody.isKinematic = false;
|
||||
|
||||
mainRigidbody.AddForce (-transform.up * extraForceInFall);
|
||||
|
||||
platformFallen = true;
|
||||
fallenTime = 0;
|
||||
inside = false;
|
||||
|
||||
checkingToFallPlatform = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter (Collision col)
|
||||
{
|
||||
if (col.gameObject.CompareTag ("Player") && !inside && !platformFallen) {
|
||||
inside = true;
|
||||
|
||||
if (!checkingToFallPlatform) {
|
||||
timeOnPlatform = 0;
|
||||
}
|
||||
|
||||
checkingToFallPlatform = true;
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionExit (Collision col)
|
||||
{
|
||||
if (col.gameObject.CompareTag ("Player") && inside) {
|
||||
inside = false;
|
||||
|
||||
if (resetDelayInExit) {
|
||||
timeOnPlatform = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator moveToOriginalPosition ()
|
||||
{
|
||||
platformFallen = false;
|
||||
|
||||
mainRigidbody.isKinematic = true;
|
||||
|
||||
movePlatformToPosition = true;
|
||||
|
||||
while (GKC_Utils.distance (transform.position, originalPosition) > .01f) {
|
||||
transform.position = Vector3.MoveTowards (transform.position, originalPosition, Time.deltaTime * movementSpeed);
|
||||
transform.rotation = Quaternion.Slerp (transform.rotation, originalRotation, Time.deltaTime * movementSpeed);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
movePlatformToPosition = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38a987fa8fca2844b86b2cd7fff09528
|
||||
timeCreated: 1473960033
|
||||
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/Devices/fallingPlatform.cs
|
||||
uploadId: 814740
|
||||
601
Assets/Game Kit Controller/Scripts/Devices/hackTerminal.cs
Normal file
601
Assets/Game Kit Controller/Scripts/Devices/hackTerminal.cs
Normal file
@@ -0,0 +1,601 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
|
||||
using System.Reflection;
|
||||
|
||||
[Serializable]
|
||||
public class hackTerminal : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool resetAfterIncorrectHack;
|
||||
|
||||
public float timerSpeed = 10;
|
||||
public float typeTime;
|
||||
public float minSwipeDist = 50;
|
||||
|
||||
public string hackingAnimation;
|
||||
public GameObject electronicDeviceGameObject;
|
||||
|
||||
public float hackTerminalMovementSpeed = 2;
|
||||
public Transform hackTerminalTargetTransform;
|
||||
|
||||
public Texture[] icons;
|
||||
|
||||
[Space]
|
||||
[Header ("Event Settings")]
|
||||
[Space]
|
||||
|
||||
public UnityEvent correctHackedlyFunction = new UnityEvent ();
|
||||
public UnityEvent incorrectlyHackedFunction = new UnityEvent ();
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool usingPanel;
|
||||
|
||||
public bool showGizmo;
|
||||
|
||||
[Space]
|
||||
[Header ("Components and UI Elements")]
|
||||
[Space]
|
||||
|
||||
public GameObject hackHud;
|
||||
public GameObject hackText;
|
||||
public GameObject content;
|
||||
public GameObject objectToHack;
|
||||
|
||||
public Image backGround;
|
||||
public Text currentPasswordText;
|
||||
public Color hackedColor;
|
||||
public Slider timeSlider;
|
||||
|
||||
Vector3 originalHackTerminalPosition;
|
||||
Quaternion originalHackTerminalRotation;
|
||||
Coroutine hackTerminalMovementCoroutine;
|
||||
bool hackTerminalMoving;
|
||||
Vector3 hackTerminalTargetPosition;
|
||||
Quaternion hackTerminaTargetRotation;
|
||||
|
||||
List<int> order = new List<int> ();
|
||||
List<RawImage> iconsImage = new List<RawImage> ();
|
||||
int currentButtonIndex = 0;
|
||||
int i;
|
||||
int j;
|
||||
float hackTimer;
|
||||
float typeRate;
|
||||
float time;
|
||||
float characterChangeRate = 0.1f;
|
||||
float characterTime;
|
||||
bool checkHackState;
|
||||
bool disableHud;
|
||||
bool swiping;
|
||||
bool touchPlatform;
|
||||
bool hackTerminalOpened;
|
||||
bool hackTextComplete;
|
||||
bool setSliderToZero;
|
||||
bool changeColor;
|
||||
bool hacked;
|
||||
bool panelClosed;
|
||||
|
||||
String finalText;
|
||||
string randomCharacter;
|
||||
Color alpha;
|
||||
RaycastHit hit;
|
||||
Vector3 swipeStartPos;
|
||||
Vector3 swipeFinalPos;
|
||||
Touch currentTouch;
|
||||
Animation hackHudAnimation;
|
||||
moveCameraToDevice cameraMovementManager;
|
||||
|
||||
playerInputManager playerInput;
|
||||
|
||||
bool keyPressed;
|
||||
|
||||
//the hack system has been changed from the player to an independent script, so like this, can be used in any type of device to hack it.
|
||||
void Start ()
|
||||
{
|
||||
alpha = Color.white;
|
||||
alpha.a = 0.5f;
|
||||
|
||||
getElements ();
|
||||
|
||||
touchPlatform = touchJoystick.checkTouchPlatform ();
|
||||
|
||||
if (currentPasswordText != null) {
|
||||
currentPasswordText.text = "";
|
||||
|
||||
int length = objectToHack.GetComponent<accessTerminal> ().code.Length;
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
currentPasswordText.text += "#";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
content.SetActive (false);
|
||||
|
||||
hackHudAnimation = hackHud.GetComponent<Animation> ();
|
||||
|
||||
getCameraMovementManager ();
|
||||
|
||||
originalHackTerminalPosition = content.transform.localPosition;
|
||||
originalHackTerminalRotation = content.transform.localRotation;
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
//if the player is hacking a device, check if the WASD keys are pressed, to compare if the current key direction to press matches with the arrow direction
|
||||
if (checkHackState && !hackHudAnimation.IsPlaying (hackingAnimation)) {
|
||||
//in PC, the control use the key directions to hack the turret
|
||||
Vector2 movementInput = playerInput.getPlayerRawMovementAxis ();
|
||||
|
||||
if (keyPressed) {
|
||||
if (movementInput == Vector2.zero) {
|
||||
keyPressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!keyPressed) {
|
||||
if (movementInput.x < 0 || Input.GetKeyDown (KeyCode.LeftArrow)) {
|
||||
checkButton (0);
|
||||
|
||||
keyPressed = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (movementInput.x > 0 || Input.GetKeyDown (KeyCode.RightArrow)) {
|
||||
checkButton (1);
|
||||
|
||||
keyPressed = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (movementInput.y > 0 || Input.GetKeyDown (KeyCode.UpArrow)) {
|
||||
checkButton (2);
|
||||
|
||||
keyPressed = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (movementInput.y < 0 || Input.GetKeyDown (KeyCode.DownArrow)) {
|
||||
checkButton (3);
|
||||
|
||||
keyPressed = true;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//also, if the touch controls are enabled, check any swipe in the screen, and check the direction
|
||||
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 && !swiping) {
|
||||
swipeStartPos = currentTouch.position;
|
||||
swiping = true;
|
||||
}
|
||||
|
||||
if (currentTouch.phase == TouchPhase.Ended && swiping) {
|
||||
//get the start and the final position of the swipe to get the direction, left, right, vertical or horizontal
|
||||
swipeFinalPos = currentTouch.position;
|
||||
swiping = false;
|
||||
|
||||
Vector2 currentSwipe = new Vector2 (swipeFinalPos.x - swipeStartPos.x, swipeFinalPos.y - swipeStartPos.y);
|
||||
|
||||
if (currentSwipe.magnitude > minSwipeDist) {
|
||||
currentSwipe.Normalize ();
|
||||
if (Vector2.Dot (currentSwipe, GKC_Utils.swipeDirections.up) > 0.906f) {
|
||||
//print("up swipe");
|
||||
checkButton (2);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (Vector2.Dot (currentSwipe, GKC_Utils.swipeDirections.down) > 0.906f) {
|
||||
//print("down swipe");
|
||||
checkButton (3);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (Vector2.Dot (currentSwipe, GKC_Utils.swipeDirections.left) > 0.906f) {
|
||||
//print("left swipe");
|
||||
checkButton (0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (Vector2.Dot (currentSwipe, GKC_Utils.swipeDirections.right) > 0.906f) {
|
||||
//print("right swipe");
|
||||
checkButton (1);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//the player has a limit of time, if the time reachs the limit, the kack will fail
|
||||
hackTimer += Time.deltaTime * timerSpeed;
|
||||
|
||||
timeSlider.value = hackTimer;
|
||||
|
||||
if (hackTimer >= timeSlider.maxValue) {
|
||||
checkButton (-1);
|
||||
}
|
||||
}
|
||||
|
||||
//active the animation to close the hack HUD
|
||||
if (setSliderToZero) {
|
||||
|
||||
timeSlider.value -= Time.deltaTime * 15;
|
||||
|
||||
if (timeSlider.value == 0) {
|
||||
|
||||
setSliderToZero = false;
|
||||
|
||||
disableHud = true;
|
||||
|
||||
hackHudAnimation [hackingAnimation].speed = 1;
|
||||
hackHudAnimation.Play (hackingAnimation);
|
||||
}
|
||||
}
|
||||
|
||||
//disable all the components of the hack interface
|
||||
if (disableHud && !hackHudAnimation.IsPlaying (hackingAnimation)) {
|
||||
disableHud = false;
|
||||
usingPanel = false;
|
||||
}
|
||||
|
||||
//if the player ends the hacking, set a text in the HUD to show if he has successed or failed
|
||||
//also the text is displayed letter by letter with a random symbol before the real letter is set
|
||||
//for a hacking looking
|
||||
if (!hackTextComplete && hackHud.activeSelf) {
|
||||
if (Time.time - characterTime >= characterChangeRate) {
|
||||
randomCharacter = randomChar ();
|
||||
|
||||
characterTime = Time.time;
|
||||
}
|
||||
|
||||
hackText.GetComponent<Text> ().text = finalText.Substring (0, j) + randomCharacter;
|
||||
|
||||
if (Time.time - time >= typeRate) {
|
||||
j++;
|
||||
time = Time.time;
|
||||
}
|
||||
|
||||
bool isChar = false;
|
||||
|
||||
while (!isChar) {
|
||||
if ((j + 1) < finalText.Length) {
|
||||
if (finalText.Substring (j, 1) == " ") {
|
||||
j++;
|
||||
} else {
|
||||
isChar = true;
|
||||
}
|
||||
} else {
|
||||
isChar = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (hackText.GetComponent<Text> ().text.Length == finalText.Length + 1) {
|
||||
|
||||
hackText.GetComponent<Text> ().text = finalText;
|
||||
|
||||
j = 0;
|
||||
time = 0;
|
||||
|
||||
hackTextComplete = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changeColor) {
|
||||
backGround.color = Vector4.MoveTowards (backGround.color, hackedColor, Time.deltaTime * 3);
|
||||
|
||||
if (backGround.color == hackedColor) {
|
||||
changeColor = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (hacked && panelClosed && !hackTerminalMoving) {
|
||||
gameObject.SetActive (false);
|
||||
}
|
||||
}
|
||||
|
||||
//enable the hack system
|
||||
public void activeHack ()
|
||||
{
|
||||
if (!usingPanel && !hacked) {
|
||||
content.SetActive (true);
|
||||
|
||||
moveHackTerminal (true);
|
||||
|
||||
setCurrentPlayer ();
|
||||
|
||||
cameraMovementManager.moveCamera (true);
|
||||
|
||||
order.Clear ();
|
||||
|
||||
currentButtonIndex = 0;
|
||||
|
||||
hackHud.SetActive (true);
|
||||
|
||||
//play the hack interface animation to "open" it
|
||||
hackHudAnimation [hackingAnimation].speed = -1;
|
||||
hackHudAnimation [hackingAnimation].time = hackHudAnimation [hackingAnimation].length;
|
||||
hackHudAnimation.Play (hackingAnimation);
|
||||
|
||||
hackTimer = 0;
|
||||
setHackText ("Hacking...");
|
||||
hackTextComplete = false;
|
||||
timeSlider.value = 0;
|
||||
|
||||
//get a random value to every button. There are four arrow Rawimage, stored in a gameObject array, so the random number is the index in the array
|
||||
//the right order is an integer array, that will be compared to the pressed keys
|
||||
for (int k = 0; k < icons.Length; k++) {
|
||||
int randomNumber = UnityEngine.Random.Range (0, icons.Length - 1);
|
||||
|
||||
iconsImage [k].texture = icons [randomNumber];
|
||||
iconsImage [k].color = alpha;
|
||||
|
||||
order.Add (randomNumber);
|
||||
}
|
||||
|
||||
checkHackState = true;
|
||||
|
||||
usingPanel = true;
|
||||
}
|
||||
}
|
||||
|
||||
//disable hacking
|
||||
public void disableHack (bool state)
|
||||
{
|
||||
setSliderToZero = true;
|
||||
hackTextComplete = false;
|
||||
|
||||
if (state) {
|
||||
StartCoroutine (resetCameraPos ());
|
||||
} else {
|
||||
cameraMovementManager.moveCamera (false);
|
||||
}
|
||||
|
||||
currentButtonIndex = 0;
|
||||
checkHackState = false;
|
||||
}
|
||||
|
||||
//if the hack has failed or not, the camera is reset to its regular position in the camera player
|
||||
IEnumerator resetCameraPos ()
|
||||
{
|
||||
yield return new WaitForSeconds (1);
|
||||
|
||||
cameraMovementManager.moveCamera (false);
|
||||
}
|
||||
|
||||
//open or close the hack terminal in the object that uses it
|
||||
public void moveHackTerminal (bool state)
|
||||
{
|
||||
if (state) {
|
||||
if (!hackTerminalOpened) {
|
||||
hackTerminalTargetPosition = hackTerminalTargetTransform.localPosition;
|
||||
hackTerminaTargetRotation = hackTerminalTargetTransform.localRotation;
|
||||
|
||||
if (hackTerminalMovementCoroutine != null) {
|
||||
StopCoroutine (hackTerminalMovementCoroutine);
|
||||
}
|
||||
|
||||
hackTerminalMovementCoroutine = StartCoroutine (moveHackTerminalCoroutine ());
|
||||
|
||||
hackTerminalOpened = state;
|
||||
}
|
||||
} else {
|
||||
if (hackTerminalOpened) {
|
||||
hackTerminalTargetPosition = originalHackTerminalPosition;
|
||||
hackTerminaTargetRotation = originalHackTerminalRotation;
|
||||
|
||||
if (hackTerminalMovementCoroutine != null) {
|
||||
StopCoroutine (hackTerminalMovementCoroutine);
|
||||
}
|
||||
|
||||
hackTerminalMovementCoroutine = StartCoroutine (moveHackTerminalCoroutine ());
|
||||
|
||||
panelClosed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator moveHackTerminalCoroutine ()
|
||||
{
|
||||
hackTerminalMoving = true;
|
||||
|
||||
float t = 0;
|
||||
|
||||
while (t < 1) {
|
||||
//content.transform.position != hackTerminalTargetPosition && content.transform.rotation != hackTerminaTargetRotation) {
|
||||
t += Time.deltaTime;
|
||||
|
||||
content.transform.localPosition = Vector3.Lerp (content.transform.localPosition, hackTerminalTargetPosition, t);
|
||||
content.transform.localRotation = Quaternion.Slerp (content.transform.localRotation, hackTerminaTargetRotation, t);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
hackTerminalMoving = false;
|
||||
}
|
||||
|
||||
//get a random character
|
||||
string randomChar ()
|
||||
{
|
||||
byte value = (byte)UnityEngine.Random.Range (41f, 128f);
|
||||
string c = System.Text.Encoding.ASCII.GetString (new byte[]{ value });
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
//a button is pressed, so check if the button direction matches with the direction of the arrow
|
||||
void checkButton (int pressedButton)
|
||||
{
|
||||
if (order [currentButtonIndex] == pressedButton) {
|
||||
currentButtonIndex++;
|
||||
|
||||
iconsImage [currentButtonIndex - 1].color = Color.white;
|
||||
|
||||
//the buttons have been pressed in the correct order, so the device is hacked
|
||||
if (currentButtonIndex == icons.Length) {
|
||||
setHackText ("Hacked Successfully!");
|
||||
|
||||
if (correctHackedlyFunction.GetPersistentEventCount () > 0) {
|
||||
correctHackedlyFunction.Invoke ();
|
||||
}
|
||||
|
||||
disableHack (true);
|
||||
changeColor = true;
|
||||
hacked = true;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//incorrect order, activate alarm
|
||||
if (pressedButton == -1 || order [currentButtonIndex] != pressedButton) {
|
||||
incorretlyHacked ();
|
||||
}
|
||||
}
|
||||
|
||||
public void incorretlyHacked ()
|
||||
{
|
||||
setHackText ("Hack failed!");
|
||||
|
||||
if (incorrectlyHackedFunction.GetPersistentEventCount () > 0) {
|
||||
incorrectlyHackedFunction.Invoke ();
|
||||
}
|
||||
|
||||
if (resetAfterIncorrectHack) {
|
||||
disableHack (false);
|
||||
} else {
|
||||
disableHack (true);
|
||||
}
|
||||
}
|
||||
|
||||
public void stopHacking ()
|
||||
{
|
||||
setHackText ("Hack failed!");
|
||||
|
||||
if (incorrectlyHackedFunction.GetPersistentEventCount () > 0) {
|
||||
incorrectlyHackedFunction.Invoke ();
|
||||
}
|
||||
|
||||
setSliderToZero = true;
|
||||
hackTextComplete = false;
|
||||
currentButtonIndex = 0;
|
||||
checkHackState = false;
|
||||
|
||||
if (cameraMovementManager != null) {
|
||||
cameraMovementManager.stopMovement ();
|
||||
}
|
||||
}
|
||||
|
||||
void setHackText (string text)
|
||||
{
|
||||
finalText = text;
|
||||
hackText.GetComponent<Text> ().text = "";
|
||||
typeRate = typeTime / (float)finalText.Length;
|
||||
}
|
||||
|
||||
//get the rawimages inside the hack HUD
|
||||
void getElements ()
|
||||
{
|
||||
hackHud.gameObject.SetActive (true);
|
||||
|
||||
Component[] components = hackHud.transform.GetComponentsInChildren (typeof(RawImage));
|
||||
foreach (RawImage child in components) {
|
||||
iconsImage.Add (child);
|
||||
}
|
||||
|
||||
hackHud.gameObject.SetActive (false);
|
||||
}
|
||||
|
||||
public void hasMoveCameraToDevice ()
|
||||
{
|
||||
getCameraMovementManager ();
|
||||
|
||||
cameraMovementManager.hasSecondMoveCameraToDevice ();
|
||||
}
|
||||
|
||||
public void setCurrentPlayer ()
|
||||
{
|
||||
GameObject currentPlayer = electronicDeviceGameObject.GetComponent<electronicDevice> ().getCurrentPlayer ();
|
||||
|
||||
if (currentPlayer != null) {
|
||||
|
||||
playerInput = currentPlayer.GetComponent<playerInputManager> ();
|
||||
|
||||
cameraMovementManager.setCurrentPlayer (currentPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
public void getCameraMovementManager ()
|
||||
{
|
||||
if (cameraMovementManager == null) {
|
||||
cameraMovementManager = GetComponent<moveCameraToDevice> ();
|
||||
}
|
||||
}
|
||||
|
||||
public void setTextContent (string textContent)
|
||||
{
|
||||
if (currentPasswordText != null) {
|
||||
currentPasswordText.text = textContent;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmos ()
|
||||
{
|
||||
if (!showGizmo) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
|
||||
DrawGizmos ();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected ()
|
||||
{
|
||||
DrawGizmos ();
|
||||
}
|
||||
|
||||
void DrawGizmos ()
|
||||
{
|
||||
if (showGizmo) {
|
||||
if (content != null && hackTerminalTargetTransform != null) {
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawSphere (content.transform.position, 0.03f);
|
||||
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawSphere (hackTerminalTargetTransform.position, 0.03f);
|
||||
|
||||
Gizmos.color = Color.white;
|
||||
Gizmos.DrawLine (content.transform.position, hackTerminalTargetTransform.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e48ebaa793d87c64fa5bd68de801f102
|
||||
timeCreated: 1465179816
|
||||
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/Devices/hackTerminal.cs
|
||||
uploadId: 814740
|
||||
551
Assets/Game Kit Controller/Scripts/Devices/hologramDoor.cs
Normal file
551
Assets/Game Kit Controller/Scripts/Devices/hologramDoor.cs
Normal file
@@ -0,0 +1,551 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using GameKitController.Audio;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class hologramDoor : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public string unlockedText;
|
||||
public string lockedText;
|
||||
public string openText;
|
||||
public string hologramIdle;
|
||||
public string hologramInside;
|
||||
|
||||
public float fadeHologramSpeed = 4;
|
||||
|
||||
public float openDelay;
|
||||
public Color lockedColor;
|
||||
public GameObject doorToOpen;
|
||||
public bool openOnTrigger;
|
||||
|
||||
public List<string> tagListToOpen = new List<string> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Sounds Settings")]
|
||||
[Space]
|
||||
|
||||
public AudioClip enterSound;
|
||||
public AudioElement enterAudioElement;
|
||||
public AudioClip exitSound;
|
||||
public AudioElement exitAudioElement;
|
||||
public AudioClip lockedSound;
|
||||
public AudioElement lockedAudioElement;
|
||||
public AudioClip openSound;
|
||||
public AudioElement openAudioElement;
|
||||
|
||||
[Space]
|
||||
[Header ("Event Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventOnOpen;
|
||||
public UnityEvent eventOnOpen;
|
||||
|
||||
[Space]
|
||||
[Header ("Hologram Elements")]
|
||||
[Space]
|
||||
|
||||
public List<Text> hologramText = new List<Text> ();
|
||||
public List<GameObject> holograms = new List<GameObject> ();
|
||||
public List<GameObject> hologramCentralRing = new List<GameObject> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public doorSystem doorManager;
|
||||
public AudioSource audioSource;
|
||||
|
||||
List<Image> otherHologramParts = new List<Image> ();
|
||||
List<RawImage> hologramParts = new List<RawImage> ();
|
||||
List<Color> originalImageColors = new List<Color> ();
|
||||
List<Color> originalRawImageColors = new List<Color> ();
|
||||
|
||||
List<Animation> hologramsAnimations = new List<Animation> ();
|
||||
List<Animation> hologramsCentralRingAnimations = new List<Animation> ();
|
||||
|
||||
bool insidePlayed;
|
||||
public bool doorLocked;
|
||||
bool inside;
|
||||
bool openingDoor;
|
||||
bool hologramOccupied;
|
||||
string regularStateText;
|
||||
|
||||
Color newColor;
|
||||
|
||||
Coroutine openDoorCoroutine;
|
||||
Coroutine changeTransparencyCoroutine;
|
||||
Coroutine setHologramColorsCoroutine;
|
||||
|
||||
bool changingColors;
|
||||
|
||||
|
||||
private void InitializeAudioElements ()
|
||||
{
|
||||
if (audioSource == null) {
|
||||
audioSource = GetComponent<AudioSource> ();
|
||||
}
|
||||
|
||||
if (audioSource != null) {
|
||||
enterAudioElement.audioSource = audioSource;
|
||||
exitAudioElement.audioSource = audioSource;
|
||||
lockedAudioElement.audioSource = audioSource;
|
||||
openAudioElement.audioSource = audioSource;
|
||||
}
|
||||
|
||||
if (enterSound != null) {
|
||||
enterAudioElement.clip = enterSound;
|
||||
}
|
||||
|
||||
if (exitSound != null) {
|
||||
exitAudioElement.clip = exitSound;
|
||||
}
|
||||
|
||||
if (lockedSound != null) {
|
||||
lockedAudioElement.clip = lockedSound;
|
||||
}
|
||||
|
||||
if (openSound != null) {
|
||||
openAudioElement.clip = openSound;
|
||||
}
|
||||
}
|
||||
|
||||
void Start ()
|
||||
{
|
||||
//get the door system component of the door
|
||||
if (doorManager == null) {
|
||||
doorManager = doorToOpen.GetComponent<doorSystem> ();
|
||||
}
|
||||
|
||||
//get all the raw images components in the hologram
|
||||
for (int i = 0; i < holograms.Count; i++) {
|
||||
Component[] hologramsParts = holograms [i].GetComponentsInChildren (typeof(RawImage));
|
||||
foreach (RawImage child in hologramsParts) {
|
||||
//store the raw images
|
||||
hologramParts.Add (child);
|
||||
|
||||
//store the original color of every raw image
|
||||
originalRawImageColors.Add (child.color);
|
||||
|
||||
//for every color, add a locked color
|
||||
}
|
||||
|
||||
//store every animation component
|
||||
hologramsAnimations.Add (holograms [i].GetComponent<Animation> ());
|
||||
}
|
||||
|
||||
for (int i = 0; i < hologramCentralRing.Count; i++) {
|
||||
hologramsCentralRingAnimations.Add (hologramCentralRing [i].GetComponent<Animation> ());
|
||||
}
|
||||
|
||||
for (int i = 0; i < holograms.Count; i++) {
|
||||
//get the image components in the hologram
|
||||
Component[] hologramsParts = holograms [i].GetComponentsInChildren (typeof(Image));
|
||||
foreach (Image child in hologramsParts) {
|
||||
//store every component in the correct list
|
||||
otherHologramParts.Add (child);
|
||||
originalImageColors.Add (child.color);
|
||||
}
|
||||
}
|
||||
|
||||
//check if the door that uses the hologram is locked or not, to set the text info in the door
|
||||
string newText = "";
|
||||
|
||||
if (doorManager.locked) {
|
||||
doorLocked = true;
|
||||
newText = lockedText;
|
||||
|
||||
for (int i = 0; i < hologramParts.Count; i++) {
|
||||
hologramParts [i].color = lockedColor;
|
||||
}
|
||||
} else {
|
||||
newText = unlockedText;
|
||||
}
|
||||
|
||||
regularStateText = newText;
|
||||
|
||||
//set the text in the hologram
|
||||
setHologramText (regularStateText);
|
||||
|
||||
InitializeAudioElements ();
|
||||
|
||||
if (doorManager.isDoorOpened ()) {
|
||||
setHologramTransparencyAtOnce (true);
|
||||
}
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
//if the player is not inside, play the normal rotating animation
|
||||
if (!inside) {
|
||||
for (int i = 0; i < hologramsAnimations.Count; i++) {
|
||||
if (!hologramsAnimations [i].IsPlaying (hologramIdle)) {
|
||||
hologramsAnimations [i].Play (hologramIdle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if the player is inside the trigger, play the open? animation of the hologram and stop the rotating animation
|
||||
if (inside && !insidePlayed) {
|
||||
for (int i = 0; i < hologramsAnimations.Count; i++) {
|
||||
hologramsAnimations [i].Stop ();
|
||||
}
|
||||
|
||||
for (int i = 0; i < hologramsCentralRingAnimations.Count; i++) {
|
||||
hologramsCentralRingAnimations [i] [hologramInside].speed = 1;
|
||||
hologramsCentralRingAnimations [i].Play (hologramInside);
|
||||
}
|
||||
|
||||
insidePlayed = true;
|
||||
}
|
||||
|
||||
//if the door has been opened, and now it is closed and the player is not inside the trigger, set the alpha color of the hologram to its regular state
|
||||
if (openingDoor && doorManager.doorState == doorSystem.doorCurrentState.closed && !doorManager.doorIsMoving () && !inside) {
|
||||
openingDoor = false;
|
||||
startChangeTransparencyCoroutine (false);
|
||||
}
|
||||
}
|
||||
|
||||
//if the player is inside the trigger and press the activate device button, check that the door is not locked and it is closed
|
||||
public void activateDevice ()
|
||||
{
|
||||
openCurrentDoor ();
|
||||
}
|
||||
|
||||
public void openCurrentDoor ()
|
||||
{
|
||||
if (!doorLocked && doorManager.doorState == doorSystem.doorCurrentState.closed && !doorManager.doorIsMoving () && !hologramOccupied) {
|
||||
//fade the hologram colors and open the door
|
||||
AudioPlayer.PlayOneShot (openAudioElement, gameObject);
|
||||
|
||||
startChangeTransparencyCoroutine (true);
|
||||
|
||||
startOpenDoorCoroutine ();
|
||||
|
||||
if (useEventOnOpen) {
|
||||
eventOnOpen.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void startChangeTransparencyCoroutine (bool state)
|
||||
{
|
||||
stopChangeTransparency ();
|
||||
|
||||
stopSetHologramColors ();
|
||||
|
||||
changeTransparencyCoroutine = StartCoroutine (changeTransparency (state));
|
||||
}
|
||||
|
||||
public void stopChangeTransparency ()
|
||||
{
|
||||
if (changeTransparencyCoroutine != null) {
|
||||
StopCoroutine (changeTransparencyCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
//this fades and turns back the alpha value of the colors in the hologram, according to if the door is opening or closing
|
||||
IEnumerator changeTransparency (bool state)
|
||||
{
|
||||
if (changingColors) {
|
||||
|
||||
for (int i = 0; i < hologramParts.Count; i++) {
|
||||
hologramParts [i].color = originalRawImageColors [i];
|
||||
}
|
||||
|
||||
changingColors = false;
|
||||
}
|
||||
|
||||
hologramOccupied = true;
|
||||
|
||||
int mult = 1;
|
||||
if (state) {
|
||||
mult = -1;
|
||||
}
|
||||
|
||||
Color alpha = new Color ();
|
||||
|
||||
for (float t = 0; t < 1;) {
|
||||
t += Time.deltaTime * fadeHologramSpeed;
|
||||
|
||||
for (int i = 0; i < hologramParts.Count; i++) {
|
||||
alpha = hologramParts [i].color;
|
||||
alpha.a += Time.deltaTime * mult * 3;
|
||||
|
||||
alpha.a = Mathf.Clamp (alpha.a, 0, originalRawImageColors [i].a);
|
||||
|
||||
hologramParts [i].color = alpha;
|
||||
}
|
||||
|
||||
for (int i = 0; i < hologramText.Count; i++) {
|
||||
alpha = hologramText [i].color;
|
||||
alpha.a += Time.deltaTime * mult * 3;
|
||||
alpha.a = Mathf.Clamp01 (alpha.a);
|
||||
hologramText [i].color = alpha;
|
||||
}
|
||||
|
||||
for (int i = 0; i < otherHologramParts.Count; i++) {
|
||||
alpha = otherHologramParts [i].color;
|
||||
alpha.a += Time.deltaTime * mult * 3;
|
||||
|
||||
alpha.a = Mathf.Clamp (alpha.a, 0, originalImageColors [i].a);
|
||||
|
||||
otherHologramParts [i].color = alpha;
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
hologramOccupied = false;
|
||||
}
|
||||
|
||||
public void setHologramTransparencyAtOnce (bool state)
|
||||
{
|
||||
int mult = 1;
|
||||
if (state) {
|
||||
mult = -1;
|
||||
}
|
||||
|
||||
Color alpha = new Color ();
|
||||
|
||||
for (int i = 0; i < hologramParts.Count; i++) {
|
||||
alpha = hologramParts [i].color;
|
||||
alpha.a = mult;
|
||||
hologramParts [i].color = alpha;
|
||||
}
|
||||
|
||||
for (int i = 0; i < hologramText.Count; i++) {
|
||||
alpha = hologramText [i].color;
|
||||
alpha.a = mult;
|
||||
hologramText [i].color = alpha;
|
||||
}
|
||||
|
||||
for (int i = 0; i < otherHologramParts.Count; i++) {
|
||||
alpha = otherHologramParts [i].color;
|
||||
alpha.a = mult;
|
||||
otherHologramParts [i].color = alpha;
|
||||
}
|
||||
}
|
||||
|
||||
public void startSetHologramColorsCoroutine (bool useUnlockedColors)
|
||||
{
|
||||
stopSetHologramColors ();
|
||||
|
||||
setHologramColorsCoroutine = StartCoroutine (setHologramColors (useUnlockedColors));
|
||||
}
|
||||
|
||||
public void stopSetHologramColors ()
|
||||
{
|
||||
if (setHologramColorsCoroutine != null) {
|
||||
StopCoroutine (setHologramColorsCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
//if the door is unlocked with a pass device or other way, change the locked colors in the hologram for the original unlocked colors
|
||||
IEnumerator setHologramColors (bool useUnlockedColors)
|
||||
{
|
||||
changingColors = true;
|
||||
|
||||
Color alpha = new Color ();
|
||||
|
||||
for (float t = 0; t < 1;) {
|
||||
t += Time.deltaTime * fadeHologramSpeed;
|
||||
|
||||
for (int i = 0; i < hologramParts.Count; i++) {
|
||||
if (useUnlockedColors) {
|
||||
hologramParts [i].color = Color.Lerp (hologramParts [i].color, originalRawImageColors [i], t);
|
||||
} else {
|
||||
hologramParts [i].color = Color.Lerp (hologramParts [i].color, lockedColor, t);
|
||||
}
|
||||
}
|
||||
|
||||
if (!hologramOccupied) {
|
||||
for (int i = 0; i < hologramText.Count; i++) {
|
||||
alpha = hologramText [i].color;
|
||||
alpha.a += t;
|
||||
alpha.a = Mathf.Clamp01 (alpha.a);
|
||||
hologramText [i].color = alpha;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < otherHologramParts.Count; i++) {
|
||||
if (useUnlockedColors) {
|
||||
otherHologramParts [i].color = Color.Lerp (otherHologramParts [i].color, originalImageColors [i], t);
|
||||
} else {
|
||||
otherHologramParts [i].color = Color.Lerp (otherHologramParts [i].color, lockedColor, t);
|
||||
}
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
changingColors = false;
|
||||
}
|
||||
|
||||
//the door was locked and now it has been unlocked, to change the hologram colors
|
||||
public void unlockHologram ()
|
||||
{
|
||||
doorLocked = false;
|
||||
|
||||
regularStateText = unlockedText;
|
||||
|
||||
setHologramText (regularStateText);
|
||||
|
||||
startSetHologramColorsCoroutine (true);
|
||||
}
|
||||
|
||||
//the door was locked and now it has been unlocked, to change the hologram colors
|
||||
public void lockHologram ()
|
||||
{
|
||||
doorLocked = true;
|
||||
|
||||
regularStateText = lockedText;
|
||||
|
||||
setHologramText (regularStateText);
|
||||
|
||||
startSetHologramColorsCoroutine (false);
|
||||
}
|
||||
|
||||
public void startOpenDoorCoroutine ()
|
||||
{
|
||||
stopOpenDoor ();
|
||||
|
||||
openDoorCoroutine = StartCoroutine (openDoor ());
|
||||
}
|
||||
|
||||
public void stopOpenDoor ()
|
||||
{
|
||||
if (openDoorCoroutine != null) {
|
||||
StopCoroutine (openDoorCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
//wait a delay and then open the door
|
||||
IEnumerator openDoor ()
|
||||
{
|
||||
yield return new WaitForSeconds (openDelay);
|
||||
|
||||
doorManager.changeDoorsStateByButton ();
|
||||
|
||||
openingDoor = true;
|
||||
}
|
||||
|
||||
//chane the current text showed in the door, according to it is locked, unlocked or can be opened
|
||||
void setHologramText (string newState)
|
||||
{
|
||||
for (int i = 0; i < hologramText.Count; i++) {
|
||||
hologramText [i].text = newState;
|
||||
}
|
||||
}
|
||||
|
||||
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 the player is inside the hologram trigger
|
||||
if (checkIfTagCanOpen (col.tag)) {
|
||||
enteringDoor ();
|
||||
}
|
||||
} else {
|
||||
//if the player exits the hologram trigger
|
||||
if (checkIfTagCanOpen (col.tag)) {
|
||||
exitingDoor ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void enteringDoor ()
|
||||
{
|
||||
//if the door is unlocked, set the open? text in the hologram
|
||||
if (!doorLocked) {
|
||||
setHologramText (openText);
|
||||
}
|
||||
|
||||
inside = true;
|
||||
|
||||
//set an audio when the player enters in the hologram trigger
|
||||
if (!openingDoor && doorManager.doorState == doorSystem.doorCurrentState.closed && !doorManager.doorIsMoving ()) {
|
||||
if (doorLocked) {
|
||||
AudioPlayer.PlayOneShot (lockedAudioElement, gameObject);
|
||||
} else {
|
||||
AudioPlayer.PlayOneShot (enterAudioElement, gameObject);
|
||||
if (openOnTrigger) {
|
||||
openCurrentDoor ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void exitingDoor ()
|
||||
{
|
||||
if (doorManager.isDisableDoorOpenCloseActionActive ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//set the current state text in the hologram
|
||||
setHologramText (regularStateText);
|
||||
inside = false;
|
||||
|
||||
//stop the central ring animation and play it reverse and start the rotating animation again
|
||||
if (insidePlayed) {
|
||||
for (int i = 0; i < hologramsCentralRingAnimations.Count; i++) {
|
||||
hologramsCentralRingAnimations [i] [hologramInside].speed = -1;
|
||||
hologramsCentralRingAnimations [i] [hologramInside].time = hologramsCentralRingAnimations [i] [hologramInside].length;
|
||||
hologramsCentralRingAnimations [i].Play (hologramInside);
|
||||
}
|
||||
|
||||
for (int i = 0; i < hologramsAnimations.Count; i++) {
|
||||
hologramsAnimations [i] [hologramIdle].time = hologramsAnimations [i] [hologramIdle].length;
|
||||
hologramsAnimations [i].Play (hologramIdle);
|
||||
}
|
||||
insidePlayed = false;
|
||||
}
|
||||
|
||||
if (!openingDoor) {
|
||||
AudioPlayer.PlayOneShot (exitAudioElement, gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public bool checkIfTagCanOpen (string tagToCheck)
|
||||
{
|
||||
if (tagListToOpen.Contains (tagToCheck)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void openHologramDoorByExternalInput ()
|
||||
{
|
||||
if (doorManager.doorState == doorSystem.doorCurrentState.closed) {
|
||||
bool previousOpenOnTriggerValue = openOnTrigger;
|
||||
openOnTrigger = true;
|
||||
|
||||
enteringDoor ();
|
||||
|
||||
openOnTrigger = previousOpenOnTriggerValue;
|
||||
}
|
||||
|
||||
if (doorManager.doorState == doorSystem.doorCurrentState.opened) {
|
||||
exitingDoor ();
|
||||
|
||||
doorManager.changeDoorsStateByButton ();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37210cf82eb7f784b9e1f4a181cdf034
|
||||
timeCreated: 1465244177
|
||||
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/Devices/hologramDoor.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,197 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class interactionObjectMessage : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
[TextArea (3, 10)] public string message;
|
||||
public bool usingDevice;
|
||||
public List<string> tagToDetect = new List<string> ();
|
||||
public bool pausePlayerWhileReading;
|
||||
public bool pressSecondTimeToStopReading;
|
||||
public float showMessageTime;
|
||||
public bool moveCameraToPosition;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool messageRemoved;
|
||||
public bool interactionUsed;
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool callEventOnInteraction;
|
||||
public bool callEventOnEveryInteraction;
|
||||
public UnityEvent eventOnInteraction;
|
||||
public UnityEvent eventOnEndInteraction;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Collider mainCollider;
|
||||
public moveCameraToDevice cameraMovementManager;
|
||||
|
||||
GameObject currentPlayer;
|
||||
playerController currentPlayerControllerManager;
|
||||
menuPause pauseManager;
|
||||
usingDevicesSystem usingDevicesManager;
|
||||
float lastTimeUsed;
|
||||
|
||||
playerComponentsManager mainPlayerComponentsManager;
|
||||
|
||||
bool cameraMovementLocated;
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (usingDevice) {
|
||||
if ((!pausePlayerWhileReading || !pressSecondTimeToStopReading) && Time.time > lastTimeUsed + showMessageTime) {
|
||||
activateDevice ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void activateDevice ()
|
||||
{
|
||||
if (messageRemoved) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pressSecondTimeToStopReading && usingDevice && showMessageTime == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
usingDevice = !usingDevice;
|
||||
|
||||
if (pausePlayerWhileReading) {
|
||||
setDeviceState (usingDevice);
|
||||
}
|
||||
|
||||
checkCameraMovementLocated ();
|
||||
|
||||
if (moveCameraToPosition && cameraMovementLocated) {
|
||||
cameraMovementManager.moveCamera (usingDevice);
|
||||
}
|
||||
|
||||
if (usingDevice) {
|
||||
usingDevicesManager.checkShowObjectMessage (message, showMessageTime);
|
||||
|
||||
lastTimeUsed = Time.time;
|
||||
} else {
|
||||
if (showMessageTime == 0) {
|
||||
usingDevicesManager.stopShowObjectMessage ();
|
||||
}
|
||||
}
|
||||
|
||||
if (callEventOnInteraction) {
|
||||
if (callEventOnEveryInteraction) {
|
||||
if (usingDevice) {
|
||||
eventOnInteraction.Invoke ();
|
||||
} else {
|
||||
eventOnEndInteraction.Invoke ();
|
||||
}
|
||||
} else {
|
||||
if (!interactionUsed) {
|
||||
if (usingDevice) {
|
||||
eventOnInteraction.Invoke ();
|
||||
} else {
|
||||
eventOnEndInteraction.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
if (!usingDevice) {
|
||||
interactionUsed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void checkCameraMovementLocated ()
|
||||
{
|
||||
if (!cameraMovementLocated) {
|
||||
if (cameraMovementManager == null) {
|
||||
cameraMovementManager = GetComponent<moveCameraToDevice> ();
|
||||
|
||||
cameraMovementLocated = cameraMovementManager != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//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 the player is entering in the trigger
|
||||
if (isEnter) {
|
||||
//if the device is already being used, return
|
||||
if (usingDevice) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tagToDetect.Contains (col.tag)) {
|
||||
currentPlayer = col.gameObject;
|
||||
|
||||
mainPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
currentPlayerControllerManager = mainPlayerComponentsManager.getPlayerController ();
|
||||
|
||||
usingDevicesManager = mainPlayerComponentsManager.getUsingDevicesSystem ();
|
||||
|
||||
pauseManager = mainPlayerComponentsManager.getPauseManager ();
|
||||
|
||||
checkCameraMovementLocated ();
|
||||
|
||||
if (cameraMovementLocated) {
|
||||
cameraMovementManager.setCurrentPlayer (currentPlayer);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//if the player is leaving the trigger
|
||||
if (tagToDetect.Contains (col.tag)) {
|
||||
|
||||
//if the player is the same that was using the device, the device can be used again
|
||||
if (col.gameObject == currentPlayer) {
|
||||
currentPlayer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setDeviceState (bool state)
|
||||
{
|
||||
currentPlayerControllerManager.setUsingDeviceState (state);
|
||||
|
||||
pauseManager.usingDeviceState (state);
|
||||
|
||||
currentPlayerControllerManager.changeScriptState (!state);
|
||||
}
|
||||
|
||||
public void removeMessage ()
|
||||
{
|
||||
messageRemoved = true;
|
||||
|
||||
if (usingDevicesManager != null) {
|
||||
usingDevicesManager.removeDeviceFromListExternalCall (gameObject);
|
||||
}
|
||||
|
||||
if (mainCollider != null) {
|
||||
mainCollider.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a5c329b480ff82643b85852ec18ffcfd
|
||||
timeCreated: 1515970957
|
||||
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/Devices/interactionObjectMessage.cs
|
||||
uploadId: 814740
|
||||
293
Assets/Game Kit Controller/Scripts/Devices/jumpPlatform.cs
Normal file
293
Assets/Game Kit Controller/Scripts/Devices/jumpPlatform.cs
Normal file
@@ -0,0 +1,293 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class jumpPlatform : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool platformEnabled = true;
|
||||
public float jumpForce;
|
||||
|
||||
[Space]
|
||||
[Header ("Condition Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useWithPlayer;
|
||||
public bool useWithNPC;
|
||||
public bool useWithVehicles;
|
||||
public bool useWithAnyRigidbody;
|
||||
public bool useKeyToJumpWithPlayer;
|
||||
public bool useKeyToJumpWithVehicles;
|
||||
|
||||
[Space]
|
||||
|
||||
public string playerTag = "Player";
|
||||
public string friendTag = "friend";
|
||||
public string enemyTag = "enemy";
|
||||
public string vehicleTag = "vehicle";
|
||||
|
||||
[Space]
|
||||
[Header ("Parable Launch Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useParableLaunch;
|
||||
public Transform targetPosition;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public bool playJumpPlatformAnimation = true;
|
||||
public string platformAnimation;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public GameObject objectToImpulse;
|
||||
public List<GameObject> objectToImpulseList = new List<GameObject> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Remote Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useRemoteEventOnObjectsFound;
|
||||
public List<string> removeEventNameList = new List<string> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Animation mainAnimation;
|
||||
|
||||
|
||||
playerController playerControllerManager;
|
||||
grabbedObjectState currentGrabbedObject;
|
||||
|
||||
vehicleHUDManager currentVehicleHUDManager;
|
||||
Rigidbody currentRigidbody;
|
||||
parentAssignedSystem currentParentAssignedSystem;
|
||||
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (playJumpPlatformAnimation) {
|
||||
if (mainAnimation == null) {
|
||||
mainAnimation = GetComponent<Animation> ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (platformEnabled) {
|
||||
if (playJumpPlatformAnimation) {
|
||||
//play the platform animation
|
||||
mainAnimation.Play (platformAnimation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerEnter (Collider col)
|
||||
{
|
||||
if (!platformEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
//if the player is inside the trigger and the platform can be used with him, then
|
||||
if ((col.gameObject.CompareTag (playerTag) && useWithPlayer) ||
|
||||
(col.gameObject.CompareTag (friendTag) && useWithNPC) ||
|
||||
(col.gameObject.CompareTag (enemyTag) && useWithNPC)) {
|
||||
|
||||
objectToImpulse = col.gameObject;
|
||||
|
||||
if (objectToImpulseList.Contains (objectToImpulse)) {
|
||||
return;
|
||||
}
|
||||
|
||||
objectToImpulseList.Add (objectToImpulse);
|
||||
|
||||
playerControllerManager = objectToImpulse.GetComponent<playerController> ();
|
||||
|
||||
//if the player is not driving
|
||||
if (playerControllerManager != null) {
|
||||
if (!playerControllerManager.driving) {
|
||||
//the platform increase the jump force in the player, and only the jump button will make the player to jump
|
||||
if (useKeyToJumpWithPlayer) {
|
||||
playerControllerManager.useJumpPlatformWithKeyButton (true, jumpForce);
|
||||
} else {
|
||||
//else make the player to jump
|
||||
if (playerControllerManager.isPlayerOnFirstPerson ()) {
|
||||
objectToImpulse.GetComponent<playerStatesManager> ().checkPlayerStates (false, false, false, false, false, false, false, false);
|
||||
} else {
|
||||
objectToImpulse.GetComponent<playerStatesManager> ().checkPlayerStates ();
|
||||
}
|
||||
|
||||
Vector3 jumpDirection = jumpForce * transform.up;
|
||||
|
||||
if (useParableLaunch) {
|
||||
jumpDirection = getParableSpeed (objectToImpulse.transform.position, targetPosition.position) * jumpForce;
|
||||
|
||||
playerControllerManager.useJumpPlatform (jumpDirection, ForceMode.VelocityChange);
|
||||
} else {
|
||||
playerControllerManager.useJumpPlatform (jumpDirection, ForceMode.Impulse);
|
||||
}
|
||||
|
||||
if (useRemoteEventOnObjectsFound) {
|
||||
checkRemoteEventsOnObjectFound (objectToImpulse);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if any other rigidbody enters the trigger, then
|
||||
else {
|
||||
currentRigidbody = col.gameObject.GetComponent<Rigidbody> ();
|
||||
|
||||
if (currentRigidbody != null) {
|
||||
objectToImpulse = col.gameObject;
|
||||
} else {
|
||||
currentParentAssignedSystem = col.gameObject.GetComponent<parentAssignedSystem> ();
|
||||
|
||||
if (currentParentAssignedSystem != null) {
|
||||
objectToImpulse = currentParentAssignedSystem.getAssignedParent ();
|
||||
currentRigidbody = objectToImpulse.GetComponent<Rigidbody> ();
|
||||
}
|
||||
}
|
||||
|
||||
if (objectToImpulse == null) {
|
||||
objectToImpulse = applyDamage.getCharacterOrVehicle (col.gameObject);
|
||||
}
|
||||
|
||||
if (objectToImpulse != null) {
|
||||
if (objectToImpulseList.Contains (objectToImpulse)) {
|
||||
return;
|
||||
}
|
||||
|
||||
objectToImpulseList.Add (objectToImpulse);
|
||||
|
||||
//if the object is being carried by the player, make him drop it
|
||||
currentGrabbedObject = objectToImpulse.GetComponent<grabbedObjectState> ();
|
||||
|
||||
if (currentGrabbedObject != null) {
|
||||
GKC_Utils.dropObject (currentGrabbedObject.getCurrentHolder (), objectToImpulse);
|
||||
}
|
||||
|
||||
currentVehicleHUDManager = objectToImpulse.GetComponent<vehicleHUDManager> ();
|
||||
|
||||
//if a vehicle enters inside the trigger and the platform can be used with vehicles, then
|
||||
if (objectToImpulse.CompareTag (vehicleTag) && currentVehicleHUDManager != null && useWithVehicles) {
|
||||
//the platform increases the jump force in the vehicle, and only the jump button will make the vehicle to jump
|
||||
if (useKeyToJumpWithVehicles) {
|
||||
currentVehicleHUDManager.useJumpPlatformWithKeyButton (true, jumpForce);
|
||||
} else {
|
||||
//else make the vehicle to jump
|
||||
Vector3 jumpDirection = jumpForce * transform.up;
|
||||
|
||||
if (useParableLaunch) {
|
||||
jumpDirection = getParableSpeed (objectToImpulse.transform.position, targetPosition.position) * jumpForce;
|
||||
|
||||
print (jumpDirection);
|
||||
|
||||
currentVehicleHUDManager.useJumpPlatformParable (jumpDirection);
|
||||
} else {
|
||||
currentVehicleHUDManager.useJumpPlatform (jumpDirection);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//if any other type of rigidbody enters the trigger, then
|
||||
if (useWithAnyRigidbody) {
|
||||
//add force to that rigidbody
|
||||
Vector3 jumpDirection = transform.up * (jumpForce / 2) * currentRigidbody.mass;
|
||||
|
||||
if (useParableLaunch) {
|
||||
jumpDirection = getParableSpeed (objectToImpulse.transform.position, targetPosition.position) * jumpForce;
|
||||
|
||||
currentRigidbody.linearVelocity = Vector3.zero;
|
||||
|
||||
currentRigidbody.AddForce (jumpDirection, ForceMode.VelocityChange);
|
||||
} else {
|
||||
currentRigidbody.AddForce (jumpDirection, ForceMode.Impulse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (useRemoteEventOnObjectsFound) {
|
||||
checkRemoteEventsOnObjectFound (objectToImpulse);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit (Collider col)
|
||||
{
|
||||
//restore the original jump force in the player of the vehicle is the jump button is needed
|
||||
if (objectToImpulseList.Contains (objectToImpulse)) {
|
||||
if (objectToImpulse.CompareTag (playerTag)) {
|
||||
if (useKeyToJumpWithPlayer) {
|
||||
playerControllerManager.useJumpPlatformWithKeyButton (false, jumpForce);
|
||||
}
|
||||
} else if (objectToImpulse.CompareTag (vehicleTag)) {
|
||||
if (useKeyToJumpWithVehicles) {
|
||||
objectToImpulse.GetComponent<vehicleHUDManager> ().useJumpPlatformWithKeyButton (false, jumpForce);
|
||||
}
|
||||
}
|
||||
|
||||
objectToImpulseList.Remove (objectToImpulse);
|
||||
} else if (currentParentAssignedSystem != null && currentParentAssignedSystem.gameObject == col.gameObject) {
|
||||
objectToImpulseList.Remove (objectToImpulse);
|
||||
}
|
||||
|
||||
objectToImpulse = null;
|
||||
}
|
||||
|
||||
Vector3 getParableSpeed (Vector3 origin, Vector3 target)
|
||||
{
|
||||
//get the distance between positions
|
||||
Vector3 toTarget = target - origin;
|
||||
Vector3 toTargetXZ = toTarget;
|
||||
|
||||
//remove the Y axis value
|
||||
toTargetXZ -= transform.InverseTransformDirection (toTargetXZ).y * transform.up;
|
||||
float y = transform.InverseTransformDirection (toTarget).y;
|
||||
float xz = toTargetXZ.magnitude;
|
||||
|
||||
//get the velocity accoring to distance ang gravity
|
||||
float t = GKC_Utils.distance (origin, target) / 20;
|
||||
float v0y = y / t + 0.5f * Physics.gravity.magnitude * t;
|
||||
float v0xz = xz / t;
|
||||
|
||||
//create result vector for calculated starting speeds
|
||||
Vector3 result = toTargetXZ.normalized;
|
||||
|
||||
//get direction of xz but with magnitude 1
|
||||
result *= v0xz;
|
||||
|
||||
// set magnitude of xz to v0xz (starting speed in xz plane), setting the local Y value
|
||||
result -= transform.InverseTransformDirection (result).y * transform.up;
|
||||
result += transform.up * v0y;
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setPlatformEnabledState (bool state)
|
||||
{
|
||||
platformEnabled = state;
|
||||
}
|
||||
|
||||
void checkRemoteEventsOnObjectFound (GameObject objectDetected)
|
||||
{
|
||||
if (useRemoteEventOnObjectsFound) {
|
||||
remoteEventSystem currentRemoteEventSystem = objectDetected.GetComponent<remoteEventSystem> ();
|
||||
|
||||
if (currentRemoteEventSystem != null) {
|
||||
for (int i = 0; i < removeEventNameList.Count; i++) {
|
||||
|
||||
currentRemoteEventSystem.callRemoteEvent (removeEventNameList [i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43100d48540cca54b815cbbf66270ba8
|
||||
timeCreated: 1467899852
|
||||
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/Devices/jumpPlatform.cs
|
||||
uploadId: 814740
|
||||
77
Assets/Game Kit Controller/Scripts/Devices/laser.cs
Normal file
77
Assets/Game Kit Controller/Scripts/Devices/laser.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class laser : MonoBehaviour
|
||||
{
|
||||
[Header ("Laser Settings")]
|
||||
[Space]
|
||||
|
||||
public float scrollSpeed = 0.09f;
|
||||
public float pulseSpeed = 0.28f;
|
||||
public float noiseSize = 0.19f;
|
||||
public float maxWidth = 0.1f;
|
||||
public float minWidth = 0.2f;
|
||||
|
||||
public bool animateLaserEnabled = true;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public LineRenderer lRenderer;
|
||||
public Renderer mainRenderer;
|
||||
|
||||
[HideInInspector] public float aniDir;
|
||||
[HideInInspector] public float laserDistance;
|
||||
|
||||
float aniFactor;
|
||||
|
||||
void Awake ()
|
||||
{
|
||||
if (lRenderer == null) {
|
||||
lRenderer = GetComponent<LineRenderer> ();
|
||||
}
|
||||
|
||||
if (mainRenderer == null) {
|
||||
mainRenderer = GetComponent<Renderer> ();
|
||||
}
|
||||
}
|
||||
|
||||
public void animateLaser ()
|
||||
{
|
||||
if (animateLaserEnabled) {
|
||||
mainRenderer.material.mainTextureOffset += new Vector2 (Time.deltaTime * aniDir * scrollSpeed, 0);
|
||||
|
||||
aniFactor = Mathf.PingPong (Time.time * pulseSpeed, 1);
|
||||
aniFactor = Mathf.Max (minWidth, aniFactor) * maxWidth;
|
||||
|
||||
lRenderer.startWidth = aniFactor;
|
||||
lRenderer.endWidth = aniFactor;
|
||||
|
||||
mainRenderer.material.mainTextureScale = new Vector2 (0.1f * (laserDistance), mainRenderer.material.mainTextureScale.y);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator laserAnimation ()
|
||||
{
|
||||
//just a configuration to animate the laser beam
|
||||
aniDir = aniDir * 0.9f + Random.Range (0.5f, 1.5f) * 0.1f;
|
||||
|
||||
yield return null;
|
||||
|
||||
minWidth = minWidth * 0.8f + Random.Range (0.1f, 1) * 0.2f;
|
||||
|
||||
WaitForSeconds delay = new WaitForSeconds (1 + Random.value * 2 - 1);
|
||||
|
||||
yield return delay;
|
||||
}
|
||||
|
||||
public virtual void disableLaser ()
|
||||
{
|
||||
enabled = false;
|
||||
|
||||
if (lRenderer != null) {
|
||||
lRenderer.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Assets/Game Kit Controller/Scripts/Devices/laser.cs.meta
Normal file
19
Assets/Game Kit Controller/Scripts/Devices/laser.cs.meta
Normal file
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c875215a5f848d048bae4df7ab6c71a0
|
||||
timeCreated: 1515264856
|
||||
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/Devices/laser.cs
|
||||
uploadId: 814740
|
||||
112
Assets/Game Kit Controller/Scripts/Devices/laserConnector.cs
Normal file
112
Assets/Game Kit Controller/Scripts/Devices/laserConnector.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class laserConnector : laser
|
||||
{
|
||||
[Space]
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public LayerMask layer;
|
||||
GameObject currentLaser;
|
||||
GameObject cubeRefractionLaser;
|
||||
GameObject raycast;
|
||||
GameObject laser2;
|
||||
RaycastHit hit;
|
||||
GameObject receiver;
|
||||
|
||||
//the laser connector is activated when a laser device is deflected
|
||||
void Start ()
|
||||
{
|
||||
StartCoroutine (laserAnimation ());
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
//check if the laser connector hits a lasers receiver, or any other object to disable the laser connection
|
||||
if (Physics.Raycast (transform.position, transform.forward, out hit, Mathf.Infinity, layer)) {
|
||||
if (!hit.collider.GetComponent<laserReceiver> () && !hit.collider.GetComponent<refractionCube> ()) {
|
||||
disableRefractionState ();
|
||||
} else {
|
||||
if (laser2 == null && cubeRefractionLaser != null) {
|
||||
//get the laser inside the refraction cube
|
||||
laser2 = cubeRefractionLaser.transform.GetChild (0).gameObject;
|
||||
|
||||
if (!laser2.activeSelf) {
|
||||
laser2.SetActive (true);
|
||||
}
|
||||
|
||||
//set the color of the laser connector according to the laser beam deflected
|
||||
Renderer currentRenderer = laser2.GetComponent<Renderer> ();
|
||||
|
||||
if (currentRenderer != null) {
|
||||
currentRenderer.material.SetColor ("_TintColor", cubeRefractionLaser.GetComponent<Renderer> ().material.GetColor ("_Color"));
|
||||
}
|
||||
}
|
||||
|
||||
laserDistance = hit.distance;
|
||||
|
||||
if (receiver == null) {
|
||||
receiver = hit.collider.gameObject;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
laserDistance = 1000;
|
||||
}
|
||||
|
||||
//set the laser size according to the hit position
|
||||
lRenderer.SetPosition (1, (laserDistance * Vector3.forward));
|
||||
|
||||
animateLaser ();
|
||||
}
|
||||
|
||||
public void disableRefractionState ()
|
||||
{
|
||||
//if the player touchs the laser connector, disable the reflected laser
|
||||
if (laser2 != null) {
|
||||
if (laser2.activeSelf) {
|
||||
laser2.SetActive (false);
|
||||
|
||||
cubeRefractionLaser.GetComponent<refractionCube> ().setRefractingLaserState (false);
|
||||
|
||||
cubeRefractionLaser = null;
|
||||
|
||||
laser2 = null;
|
||||
}
|
||||
}
|
||||
|
||||
currentLaser.GetComponent<laserDevice> ().setAssignLaserState (false);
|
||||
|
||||
if (gameObject.activeSelf) {
|
||||
gameObject.SetActive (false);
|
||||
}
|
||||
|
||||
if (receiver != null) {
|
||||
laserReceiver currentLaserReceiver = receiver.GetComponent<laserReceiver> ();
|
||||
|
||||
if (currentLaserReceiver != null) {
|
||||
currentLaserReceiver.laserDisconnected ();
|
||||
}
|
||||
|
||||
receiver = null;
|
||||
}
|
||||
}
|
||||
|
||||
//set the color of the laser beam
|
||||
public void setColor ()
|
||||
{
|
||||
Color c = currentLaser.GetComponent<Renderer> ().material.GetColor ("_TintColor");
|
||||
|
||||
mainRenderer.material.SetColor ("_TintColor", c);
|
||||
}
|
||||
|
||||
public void setCurrentLaser (GameObject laser)
|
||||
{
|
||||
currentLaser = laser;
|
||||
}
|
||||
|
||||
public void setCubeRefractionLaser (GameObject cube)
|
||||
{
|
||||
cubeRefractionLaser = cube;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b12f62a9ebd6c14a8091cfc29a1747b
|
||||
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/Devices/laserConnector.cs
|
||||
uploadId: 814740
|
||||
270
Assets/Game Kit Controller/Scripts/Devices/laserDevice.cs
Normal file
270
Assets/Game Kit Controller/Scripts/Devices/laserDevice.cs
Normal file
@@ -0,0 +1,270 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class laserDevice : laser
|
||||
{
|
||||
[Space]
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public LayerMask layer;
|
||||
public bool enablePlayerShield = true;
|
||||
public bool assigned;
|
||||
public GameObject laserConnector;
|
||||
public laserType lasertype;
|
||||
public float damageAmount;
|
||||
public bool ignoreShield;
|
||||
|
||||
public int damageTypeID = -1;
|
||||
|
||||
public bool damageCanBeBlocked = true;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public bool canDamagePlayer;
|
||||
public bool canDamageCharacters;
|
||||
public bool canDamageVehicles;
|
||||
public bool canDamageEverything;
|
||||
public bool canKillWithOneHit;
|
||||
|
||||
public bool sendMessageOnContact;
|
||||
|
||||
public string shieldAbilityName = "Shield";
|
||||
|
||||
[Space]
|
||||
[Header ("Event Settings")]
|
||||
[Space]
|
||||
|
||||
public UnityEvent contantFunctions = new UnityEvent ();
|
||||
|
||||
GameObject currentPlayer;
|
||||
|
||||
playerShieldSystem currentPlayerShieldSystem;
|
||||
playerAbilitiesSystem currentPlayerAbilitiesSystem;
|
||||
|
||||
bool forceFieldEnabled;
|
||||
RaycastHit hit;
|
||||
Vector3 hitPointPosition;
|
||||
float rayDistance;
|
||||
float hitDistance;
|
||||
bool hittingSurface;
|
||||
bool damageCurrentSurface;
|
||||
bool laserEnabled = true;
|
||||
|
||||
public enum laserType
|
||||
{
|
||||
simple,
|
||||
refraction
|
||||
}
|
||||
|
||||
GameObject lastObjectDetected;
|
||||
|
||||
bool playerDetected;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
StartCoroutine (laserAnimation ());
|
||||
|
||||
//get the initial raycast distance
|
||||
rayDistance = Mathf.Infinity;
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (laserEnabled) {
|
||||
lRenderer.positionCount = 2;
|
||||
lRenderer.SetPosition (0, transform.position);
|
||||
|
||||
|
||||
|
||||
//check if the hitted object is the player, enabling or disabling his shield
|
||||
if (Physics.Raycast (transform.position, transform.forward, out hit, rayDistance, layer)) {
|
||||
//if the laser has been deflected, then check if any object collides with it, to disable all the other reflections of the laser
|
||||
hittingSurface = true;
|
||||
|
||||
laserDistance = hit.distance;
|
||||
hitPointPosition = hit.point;
|
||||
|
||||
if (hit.collider.gameObject != lastObjectDetected) {
|
||||
lastObjectDetected = hit.collider.gameObject;
|
||||
|
||||
if (sendMessageOnContact) {
|
||||
if (contantFunctions.GetPersistentEventCount () > 0) {
|
||||
contantFunctions.Invoke ();
|
||||
}
|
||||
}
|
||||
|
||||
playerDetected = hit.transform.CompareTag ("Player");
|
||||
}
|
||||
|
||||
} else {
|
||||
//the laser does not hit anything, so disable the shield if it was enabled
|
||||
hittingSurface = false;
|
||||
|
||||
playerDetected = false;
|
||||
}
|
||||
|
||||
if (hittingSurface) {
|
||||
|
||||
if (currentPlayer == null && playerDetected) {
|
||||
currentPlayer = hit.collider.gameObject;
|
||||
|
||||
playerComponentsManager currentPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
currentPlayerAbilitiesSystem = currentPlayerComponentsManager.getPlayerAbilitiesSystem ();
|
||||
|
||||
if (currentPlayerAbilitiesSystem != null) {
|
||||
currentPlayerShieldSystem = (playerShieldSystem)currentPlayerAbilitiesSystem.getAbilityByName (shieldAbilityName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (assigned) {
|
||||
forceFieldEnabled = false;
|
||||
|
||||
if (enablePlayerShield) {
|
||||
if (currentPlayerShieldSystem != null) {
|
||||
currentPlayerShieldSystem.deactivateLaserForceField ();
|
||||
}
|
||||
}
|
||||
|
||||
rayDistance = Mathf.Infinity;
|
||||
|
||||
laserConnector.GetComponent<laserConnector> ().disableRefractionState ();
|
||||
} else {
|
||||
///the laser touchs the player, active his shield and set the laser that is touching him
|
||||
if (playerDetected && !hit.collider.isTrigger && !forceFieldEnabled) {
|
||||
if (currentPlayerShieldSystem != null) {
|
||||
currentPlayerShieldSystem.setLaser (gameObject, lasertype);
|
||||
}
|
||||
|
||||
forceFieldEnabled = true;
|
||||
}
|
||||
|
||||
if (forceFieldEnabled) {
|
||||
hitDistance = hit.distance;
|
||||
//set the position where this laser is touching the player
|
||||
Vector3 position = hit.point;
|
||||
|
||||
if (enablePlayerShield) {
|
||||
if (currentPlayerShieldSystem != null) {
|
||||
currentPlayerShieldSystem.activateLaserForceField (position);
|
||||
}
|
||||
}
|
||||
|
||||
//the laser has stopped to touch the player, so deactivate the player's shield
|
||||
if (!playerDetected) {
|
||||
forceFieldEnabled = false;
|
||||
|
||||
if (enablePlayerShield) {
|
||||
if (currentPlayerShieldSystem != null) {
|
||||
currentPlayerShieldSystem.deactivateLaserForceField ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (canDamagePlayer && playerDetected) {
|
||||
damageCurrentSurface = true;
|
||||
}
|
||||
|
||||
if (canDamageCharacters) {
|
||||
if (applyDamage.isCharacter (hit.transform.gameObject)) {
|
||||
damageCurrentSurface = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (canDamageVehicles) {
|
||||
if (applyDamage.isVehicle (hit.transform.gameObject)) {
|
||||
damageCurrentSurface = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (canDamageEverything) {
|
||||
damageCurrentSurface = true;
|
||||
}
|
||||
|
||||
if (damageCurrentSurface) {
|
||||
if (canKillWithOneHit) {
|
||||
applyDamage.killCharacter (gameObject, hit.transform.gameObject, -transform.forward, hit.point, gameObject, false);
|
||||
} else {
|
||||
applyDamage.checkHealth (gameObject, hit.transform.gameObject, damageAmount, -transform.forward, hit.point,
|
||||
gameObject, true, true, ignoreShield, false, damageCanBeBlocked, false, -1, damageTypeID);
|
||||
}
|
||||
}
|
||||
|
||||
lRenderer.SetPosition (1, hitPointPosition);
|
||||
} else {
|
||||
if (!assigned) {
|
||||
if (forceFieldEnabled) {
|
||||
forceFieldEnabled = false;
|
||||
|
||||
if (enablePlayerShield) {
|
||||
if (currentPlayerShieldSystem != null) {
|
||||
currentPlayerShieldSystem.deactivateLaserForceField ();
|
||||
}
|
||||
}
|
||||
|
||||
//set to infinite the raycast distance again
|
||||
rayDistance = Mathf.Infinity;
|
||||
}
|
||||
|
||||
laserDistance = 1000;
|
||||
lRenderer.SetPosition (1, (transform.position + laserDistance * transform.forward));
|
||||
}
|
||||
}
|
||||
|
||||
animateLaser ();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisable ()
|
||||
{
|
||||
if (assigned) {
|
||||
forceFieldEnabled = false;
|
||||
|
||||
if (currentPlayer != null) {
|
||||
if (enablePlayerShield) {
|
||||
if (currentPlayerShieldSystem != null) {
|
||||
currentPlayerShieldSystem.deactivateLaserForceField ();
|
||||
}
|
||||
}
|
||||
|
||||
//set to infinite the raycast distance again
|
||||
rayDistance = Mathf.Infinity;
|
||||
|
||||
//disable the laser connector
|
||||
laserConnector.GetComponent<laserConnector> ().disableRefractionState ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//set the laser that it is touching the player, to assign it to the laser connector
|
||||
void assignLaser ()
|
||||
{
|
||||
assigned = true;
|
||||
rayDistance = hitDistance;
|
||||
|
||||
if (enablePlayerShield) {
|
||||
if (currentPlayerShieldSystem != null) {
|
||||
currentPlayerShieldSystem.deactivateLaserForceField ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setAssignLaserState (bool state)
|
||||
{
|
||||
assigned = state;
|
||||
}
|
||||
|
||||
public override void disableLaser ()
|
||||
{
|
||||
laserEnabled = false;
|
||||
lRenderer.enabled = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71d71a932d7931447acaaa45a87418d7
|
||||
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/Devices/laserDevice.cs
|
||||
uploadId: 814740
|
||||
52
Assets/Game Kit Controller/Scripts/Devices/laserReceiver.cs
Normal file
52
Assets/Game Kit Controller/Scripts/Devices/laserReceiver.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class laserReceiver : MonoBehaviour
|
||||
{
|
||||
public Color colorNeeded;
|
||||
public bool connected;
|
||||
public GameObject objectToConnect;
|
||||
public string activeFunctionName;
|
||||
|
||||
GameObject children;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
//get the cylinder inside the laser receiver, to set the color needed, so the player can see it
|
||||
if (transform.childCount > 0) {
|
||||
children = transform.GetChild (0).gameObject;
|
||||
children.GetComponent<Renderer> ().material.color = colorNeeded;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Update ()
|
||||
{
|
||||
//if the laser receiver is reached by the correct laser color, the cylinder rotates
|
||||
if (connected && children != null) {
|
||||
children.transform.Rotate (0, 100 * Time.deltaTime, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//the receiver has been reached by the correct laser color, so call the active function in the object to connect
|
||||
public void laserConnected (Color col)
|
||||
{
|
||||
if (col == colorNeeded) {
|
||||
connected = true;
|
||||
|
||||
if (objectToConnect != null) {
|
||||
objectToConnect.SendMessage (activeFunctionName, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//the laser has been disabled, so disable the object connected
|
||||
public void laserDisconnected ()
|
||||
{
|
||||
connected = false;
|
||||
|
||||
if (objectToConnect != null) {
|
||||
objectToConnect.SendMessage (activeFunctionName, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3cc1320d96fac5242aeafa8fecf87231
|
||||
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/Devices/laserReceiver.cs
|
||||
uploadId: 814740
|
||||
1610
Assets/Game Kit Controller/Scripts/Devices/lockedCameraSystem.cs
Normal file
1610
Assets/Game Kit Controller/Scripts/Devices/lockedCameraSystem.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04149c3a8b01aff48b1c9940d61a0cdf
|
||||
timeCreated: 1487705835
|
||||
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/Devices/lockedCameraSystem.cs
|
||||
uploadId: 814740
|
||||
11
Assets/Game Kit Controller/Scripts/Devices/movableDoor.cs
Normal file
11
Assets/Game Kit Controller/Scripts/Devices/movableDoor.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class movableDoor : MonoBehaviour
|
||||
{
|
||||
public float rotationSpeed;
|
||||
public Vector3 doorAxis;
|
||||
public Vector2 limitXAxis;
|
||||
public Vector2 limitYAxis;
|
||||
public Vector2 limitZAxis;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a8c4a69a19071cb43a65e1ab77d3e100
|
||||
timeCreated: 1466259903
|
||||
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/Devices/movableDoor.cs
|
||||
uploadId: 814740
|
||||
786
Assets/Game Kit Controller/Scripts/Devices/moveCameraToDevice.cs
Normal file
786
Assets/Game Kit Controller/Scripts/Devices/moveCameraToDevice.cs
Normal file
@@ -0,0 +1,786 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class moveCameraToDevice : MonoBehaviour
|
||||
{
|
||||
public bool cameraMovementActive = true;
|
||||
public GameObject cameraPosition;
|
||||
public bool smoothCameraMovement = true;
|
||||
|
||||
public bool useFixedLerpMovement = true;
|
||||
public float fixedLerpMovementSpeed = 2;
|
||||
|
||||
public float cameraMovementSpeedThirdPerson = 1;
|
||||
public float cameraMovementSpeedFirstPerson = 0.2f;
|
||||
|
||||
public bool secondMoveCameraToDevice;
|
||||
|
||||
public bool unlockCursor = true;
|
||||
|
||||
public bool ignoreHideCursorOnClick;
|
||||
|
||||
public bool setNewMouseCursorControllerSpeed;
|
||||
public float newMouseCursroControllerSpeed;
|
||||
|
||||
public bool disablePlayerMeshGameObject = true;
|
||||
public bool enablePlayerMeshGameObjectIfFirstPersonActive;
|
||||
|
||||
public bool ignoreFBAActiveIfDisablePlayerMesh;
|
||||
|
||||
public bool ignoreCameraPositionAdjusmentOnFBA;
|
||||
|
||||
public bool disableWeaponsCamera;
|
||||
public bool keepWeaponsIfCarrying;
|
||||
public bool drawWeaponsIfPreviouslyCarrying;
|
||||
public bool keepOnlyIfPlayerIsOnFirstPerson;
|
||||
public bool disableWeaponsDirectlyOnStart;
|
||||
bool carryingWeaponsPreviously;
|
||||
bool firstPersonActive;
|
||||
|
||||
public bool ignoreMeleeWeaponCheck;
|
||||
|
||||
public bool carryWeaponOnLowerPositionActive;
|
||||
|
||||
public bool setPlayerCameraRotationOnExit;
|
||||
public Transform playerPivotTransformThirdPerson;
|
||||
public Transform playerCameraTransformThirdPerson;
|
||||
public Transform playerPivotTransformFirstPerson;
|
||||
public Transform playerCameraTransformFirstPerson;
|
||||
|
||||
public bool alignPlayerWithCameraPositionOnStartUseDevice;
|
||||
|
||||
public bool alignPlayerWithCameraPositionOnStopUseDevice;
|
||||
|
||||
public bool alignPlayerWithCameraRotationOnStartUseDevice;
|
||||
|
||||
public bool alignPlayerWithCameraRotationOnStopUseDevice;
|
||||
|
||||
public Transform customAlignPlayerTransform;
|
||||
|
||||
public bool resetPlayerCameraDirection;
|
||||
|
||||
public bool disableSecondaryPlayerHUD = true;
|
||||
public bool disableAllPlayerHUD;
|
||||
public bool disableTouchControls;
|
||||
|
||||
public bool disableAllDynamicUIElements = true;
|
||||
|
||||
public bool disableInteractionTouchButtonOnUsingDevice;
|
||||
|
||||
public bool showGizmo;
|
||||
public float gizmoRadius = 0.1f;
|
||||
public Color gizmoLabelColor = Color.black;
|
||||
public float gizmoArrowLength = 0.3f;
|
||||
public float gizmoArrowLineLength = 0.5f;
|
||||
public float gizmoArrowAngle = 20;
|
||||
public Color gizmoArrowColor = Color.white;
|
||||
|
||||
Transform cameraParentTransform;
|
||||
Vector3 mainCameraTargetPosition;
|
||||
Quaternion mainCameraTargetRotation;
|
||||
Coroutine cameraState;
|
||||
bool deviceEnabled;
|
||||
Camera mainCamera;
|
||||
menuPause pauseManager;
|
||||
GameObject currentPlayer;
|
||||
playerController currentPlayerControllerManager;
|
||||
playerWeaponsManager weaponsManager;
|
||||
usingDevicesSystem usingDevicesManager;
|
||||
headBob headBobManager;
|
||||
grabObjects grabObjectsManager;
|
||||
footStepManager stepManager;
|
||||
playerCamera playerCameraManager;
|
||||
headTrack headTrackManager;
|
||||
|
||||
playerComponentsManager mainPlayerComponentsManager;
|
||||
|
||||
bool previouslyIconButtonActive;
|
||||
|
||||
bool movingCamera;
|
||||
|
||||
Coroutine headTrackTargetCoroutine;
|
||||
Transform headTrackTargeTransform;
|
||||
|
||||
//this function was placed in computer device, but now it can be added to any type of device when the player is using it,
|
||||
//to move the camera position and rotation in front of the device and place it again in its regular place when the player stops using the device
|
||||
|
||||
bool ignoreDisablePlayerMeshResult;
|
||||
|
||||
bool weaponCursorActiveSelfState;
|
||||
|
||||
|
||||
void Start ()
|
||||
{
|
||||
mainCameraTargetRotation = Quaternion.identity;
|
||||
mainCameraTargetPosition = Vector3.zero;
|
||||
}
|
||||
|
||||
public bool ignoreMoveCameraFunctionEnabled;
|
||||
|
||||
//activate the device
|
||||
public void moveCamera (bool state)
|
||||
{
|
||||
if (ignoreMoveCameraFunctionEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (deviceEnabled == state && !secondMoveCameraToDevice) {
|
||||
return;
|
||||
}
|
||||
|
||||
deviceEnabled = state;
|
||||
|
||||
if (deviceEnabled) {
|
||||
headBobManager.stopAllHeadbobMovements ();
|
||||
}
|
||||
|
||||
headBobManager.playOrPauseHeadBob (!state);
|
||||
|
||||
//if the player is using the computer, disable the player controller, the camera, and set the parent of the camera inside the computer,
|
||||
//to move to its view position
|
||||
|
||||
if (cameraPosition == null) {
|
||||
cameraPosition = gameObject;
|
||||
}
|
||||
|
||||
if (deviceEnabled) {
|
||||
if (playerCameraManager.isLeanActive ()) {
|
||||
playerCameraManager.checkResetLeanState (true);
|
||||
|
||||
playerCameraManager.removeLeanRotationFromPivotCameraTransform ();
|
||||
|
||||
playerCameraManager.updateFBAPivotCameraTransformValuesToMainPivotCameraTransform ();
|
||||
}
|
||||
|
||||
if (currentPlayerControllerManager.isPlayerRunning ()) {
|
||||
currentPlayerControllerManager.stopRun ();
|
||||
}
|
||||
|
||||
if (!secondMoveCameraToDevice) {
|
||||
//make the mouse cursor visible according to the action of the player
|
||||
currentPlayerControllerManager.setUsingDeviceState (deviceEnabled);
|
||||
|
||||
ignoreDisablePlayerMeshResult = false;
|
||||
|
||||
weaponsManager.setUsingDeviceState (deviceEnabled);
|
||||
|
||||
carryingWeaponsPreviously = weaponsManager.isUsingWeapons ();
|
||||
|
||||
bool playerShootingPreviously = weaponsManager.isCharacterShooting () ||
|
||||
weaponsManager.isReloadingWithAnimationActive ();
|
||||
|
||||
if (carryingWeaponsPreviously) {
|
||||
weaponsManager.stopShootingFireWeaponIfActiveWithoutChangingAimState ();
|
||||
|
||||
weaponsManager.cancelReloadIfActive ();
|
||||
|
||||
if (playerShootingPreviously) {
|
||||
ignoreDisablePlayerMeshResult = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (keepWeaponsIfCarrying) {
|
||||
firstPersonActive = currentPlayerControllerManager.isPlayerOnFirstPerson ();
|
||||
|
||||
if (!keepOnlyIfPlayerIsOnFirstPerson || firstPersonActive) {
|
||||
|
||||
if (carryingWeaponsPreviously) {
|
||||
if (disableWeaponsDirectlyOnStart) {
|
||||
weaponsManager.checkIfDisableCurrentWeapon ();
|
||||
} else {
|
||||
weaponsManager.checkIfKeepSingleOrDualWeapon ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
weaponCursorActiveSelfState = weaponsManager.getGeneralWeaponCursorActiveSelfState ();
|
||||
|
||||
if (weaponCursorActiveSelfState) {
|
||||
weaponsManager.enableOrDisableGeneralWeaponCursor (false);
|
||||
}
|
||||
|
||||
if (disableWeaponsCamera) {
|
||||
if (weaponsManager.carryingWeaponInFirstPerson) {
|
||||
weaponsManager.weaponsCamera.gameObject.SetActive (false);
|
||||
}
|
||||
}
|
||||
|
||||
pauseManager.usingDeviceState (deviceEnabled);
|
||||
currentPlayerControllerManager.changeScriptState (!deviceEnabled);
|
||||
|
||||
bool isFullBodyAwarenessActive = currentPlayerControllerManager.isFullBodyAwarenessActive () && !ignoreFBAActiveIfDisablePlayerMesh;
|
||||
|
||||
if (disablePlayerMeshGameObject && !isFullBodyAwarenessActive) {
|
||||
if (!ignoreDisablePlayerMeshResult) {
|
||||
currentPlayerControllerManager.getGravityCenter ().gameObject.SetActive (!deviceEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
if (enablePlayerMeshGameObjectIfFirstPersonActive) {
|
||||
if (firstPersonActive && !isFullBodyAwarenessActive) {
|
||||
currentPlayerControllerManager.setCharacterMeshGameObjectState (true);
|
||||
}
|
||||
}
|
||||
|
||||
stepManager.enableOrDisableFootStepsComponents (!deviceEnabled);
|
||||
|
||||
if (unlockCursor) {
|
||||
pauseManager.showOrHideCursor (deviceEnabled);
|
||||
}
|
||||
|
||||
pauseManager.changeCameraState (!deviceEnabled);
|
||||
}
|
||||
|
||||
if (!ignoreMeleeWeaponCheck) {
|
||||
grabObjectsManager.checkToDropObjectIfNotPhysicalWeaponElseKeepWeapon ();
|
||||
}
|
||||
|
||||
previouslyIconButtonActive = usingDevicesManager.getCurrentIconButtonState ();
|
||||
|
||||
if (disableInteractionTouchButtonOnUsingDevice) {
|
||||
usingDevicesManager.setIconButtonCanBeShownState (false);
|
||||
}
|
||||
|
||||
if (cameraMovementActive) {
|
||||
if (cameraParentTransform == null) {
|
||||
cameraParentTransform = mainCamera.transform.parent;
|
||||
mainCamera.transform.SetParent (cameraPosition.transform);
|
||||
}
|
||||
}
|
||||
|
||||
if (alignPlayerWithCameraPositionOnStartUseDevice) {
|
||||
Vector3 playerTargetPosition = Vector3.zero;
|
||||
|
||||
if (customAlignPlayerTransform != null) {
|
||||
playerTargetPosition =
|
||||
new Vector3 (customAlignPlayerTransform.position.x, currentPlayer.transform.position.y, customAlignPlayerTransform.position.z);
|
||||
} else {
|
||||
playerTargetPosition =
|
||||
new Vector3 (cameraPosition.transform.position.x, currentPlayer.transform.position.y, cameraPosition.transform.position.z);
|
||||
}
|
||||
|
||||
currentPlayer.transform.position = playerTargetPosition;
|
||||
|
||||
playerCameraManager.transform.position = currentPlayer.transform.position;
|
||||
}
|
||||
|
||||
if (alignPlayerWithCameraRotationOnStartUseDevice) {
|
||||
Vector3 playerTargetRotation = Vector3.zero;
|
||||
|
||||
if (customAlignPlayerTransform != null) {
|
||||
playerTargetRotation =
|
||||
new Vector3 (currentPlayer.transform.eulerAngles.x, customAlignPlayerTransform.eulerAngles.y, currentPlayer.transform.eulerAngles.z);
|
||||
} else {
|
||||
playerTargetRotation =
|
||||
new Vector3 (currentPlayer.transform.eulerAngles.x, cameraPosition.transform.eulerAngles.y, currentPlayer.transform.eulerAngles.z);
|
||||
}
|
||||
|
||||
currentPlayer.transform.eulerAngles = playerTargetRotation;
|
||||
|
||||
playerCameraManager.transform.eulerAngles = currentPlayer.transform.eulerAngles;
|
||||
}
|
||||
|
||||
if (resetPlayerCameraDirection) {
|
||||
playerCameraManager.setLookAngleValue (Vector2.zero);
|
||||
|
||||
playerCameraManager.resetCurrentCameraStateAtOnce ();
|
||||
|
||||
playerCameraManager.getPivotCameraTransform ().localRotation = Quaternion.identity;
|
||||
}
|
||||
} else {
|
||||
|
||||
//set player camera rotation when the player stops using the device
|
||||
if (setPlayerCameraRotationOnExit) {
|
||||
bool isFirstPersonActive = playerCameraManager.isFirstPersonActive ();
|
||||
|
||||
Vector3 pivotCameraRotation = Vector3.zero;
|
||||
Vector3 cameraRotation = Vector3.zero;
|
||||
|
||||
if (isFirstPersonActive) {
|
||||
cameraRotation = playerCameraTransformFirstPerson.eulerAngles;
|
||||
pivotCameraRotation = playerPivotTransformFirstPerson.localEulerAngles;
|
||||
} else {
|
||||
cameraRotation = playerCameraTransformThirdPerson.eulerAngles;
|
||||
pivotCameraRotation = playerPivotTransformThirdPerson.localEulerAngles;
|
||||
}
|
||||
|
||||
playerCameraManager.transform.eulerAngles = cameraRotation;
|
||||
playerCameraManager.getPivotCameraTransform ().localEulerAngles = pivotCameraRotation;
|
||||
|
||||
float newLookAngleValue = pivotCameraRotation.x;
|
||||
if (newLookAngleValue > 180) {
|
||||
newLookAngleValue -= 360;
|
||||
}
|
||||
playerCameraManager.setLookAngleValue (new Vector2 (0, newLookAngleValue));
|
||||
playerCameraManager.setCurrentCameraUpRotationValue (0);
|
||||
}
|
||||
|
||||
//if the player disconnect the computer, then enabled of its components and set the camera to its previous position inside the player
|
||||
if (!secondMoveCameraToDevice) {
|
||||
//make the mouse cursor visible according to the action of the player
|
||||
currentPlayerControllerManager.setUsingDeviceState (deviceEnabled);
|
||||
|
||||
pauseManager.usingDeviceState (deviceEnabled);
|
||||
currentPlayerControllerManager.changeScriptState (!deviceEnabled);
|
||||
|
||||
if (disableWeaponsCamera) {
|
||||
if (weaponsManager.carryingWeaponInFirstPerson) {
|
||||
weaponsManager.weaponsCamera.gameObject.SetActive (true);
|
||||
}
|
||||
}
|
||||
|
||||
bool isFullBodyAwarenessActive = currentPlayerControllerManager.isFullBodyAwarenessActive () && !ignoreFBAActiveIfDisablePlayerMesh;
|
||||
|
||||
if (disablePlayerMeshGameObject && !isFullBodyAwarenessActive) {
|
||||
if (!ignoreDisablePlayerMeshResult) {
|
||||
currentPlayerControllerManager.getGravityCenter ().gameObject.SetActive (!deviceEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
if (enablePlayerMeshGameObjectIfFirstPersonActive) {
|
||||
if (firstPersonActive && !isFullBodyAwarenessActive) {
|
||||
currentPlayerControllerManager.setCharacterMeshGameObjectState (false);
|
||||
}
|
||||
}
|
||||
|
||||
weaponsManager.setUsingDeviceState (deviceEnabled);
|
||||
|
||||
if (keepWeaponsIfCarrying) {
|
||||
if (!keepOnlyIfPlayerIsOnFirstPerson || firstPersonActive) {
|
||||
if (drawWeaponsIfPreviouslyCarrying && carryingWeaponsPreviously) {
|
||||
weaponsManager.checkIfDrawSingleOrDualWeapon ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (weaponCursorActiveSelfState) {
|
||||
weaponsManager.enableOrDisableGeneralWeaponCursor (true);
|
||||
}
|
||||
|
||||
stepManager.enableOrDisableFootStepsWithDelay (!deviceEnabled, 0);
|
||||
|
||||
if (unlockCursor) {
|
||||
pauseManager.showOrHideCursor (deviceEnabled);
|
||||
}
|
||||
|
||||
pauseManager.changeCameraState (!deviceEnabled);
|
||||
}
|
||||
|
||||
if (cameraMovementActive) {
|
||||
if (alignPlayerWithCameraPositionOnStopUseDevice) {
|
||||
Vector3 playerTargetPosition = Vector3.zero;
|
||||
|
||||
if (customAlignPlayerTransform != null) {
|
||||
playerTargetPosition =
|
||||
new Vector3 (customAlignPlayerTransform.position.x, currentPlayer.transform.position.y, customAlignPlayerTransform.position.z);
|
||||
|
||||
currentPlayer.transform.position = playerTargetPosition;
|
||||
} else {
|
||||
|
||||
float xPosition = currentPlayer.transform.InverseTransformPoint (mainCamera.transform.position).x;
|
||||
float zPosition = currentPlayer.transform.InverseTransformPoint (mainCamera.transform.position).z;
|
||||
|
||||
currentPlayer.transform.position += currentPlayer.transform.right * xPosition + currentPlayer.transform.forward * zPosition;
|
||||
}
|
||||
|
||||
playerCameraManager.transform.position = currentPlayer.transform.position;
|
||||
}
|
||||
|
||||
if (alignPlayerWithCameraRotationOnStopUseDevice) {
|
||||
Vector3 playerTargetRotation = Vector3.zero;
|
||||
|
||||
if (customAlignPlayerTransform != null) {
|
||||
playerTargetRotation =
|
||||
new Vector3 (currentPlayer.transform.eulerAngles.x, customAlignPlayerTransform.eulerAngles.y, currentPlayer.transform.eulerAngles.z);
|
||||
} else {
|
||||
playerTargetRotation =
|
||||
new Vector3 (currentPlayer.transform.eulerAngles.x, cameraPosition.transform.eulerAngles.y, currentPlayer.transform.eulerAngles.z);
|
||||
}
|
||||
|
||||
currentPlayer.transform.eulerAngles = playerTargetRotation;
|
||||
|
||||
playerCameraManager.transform.rotation = currentPlayer.transform.rotation;
|
||||
}
|
||||
|
||||
if (cameraParentTransform != null) {
|
||||
mainCamera.transform.SetParent (cameraParentTransform);
|
||||
cameraParentTransform = null;
|
||||
}
|
||||
}
|
||||
|
||||
usingDevicesManager.setIconButtonCanBeShownState (previouslyIconButtonActive);
|
||||
|
||||
usingDevicesManager.checkIfRemoveDeviceFromList ();
|
||||
}
|
||||
|
||||
if (disableAllDynamicUIElements) {
|
||||
pauseManager.enableOrDisableDynamicElementsOnScreen (!deviceEnabled);
|
||||
}
|
||||
|
||||
if (disableAllPlayerHUD) {
|
||||
pauseManager.enableOrDisablePlayerHUD (!deviceEnabled);
|
||||
} else {
|
||||
if (disableSecondaryPlayerHUD) {
|
||||
pauseManager.enableOrDisableSecondaryPlayerHUD (!deviceEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
if (disableTouchControls) {
|
||||
if (pauseManager.isUsingTouchControls ()) {
|
||||
pauseManager.enableOrDisableTouchControlsExternally (!deviceEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
if (cameraMovementActive) {
|
||||
if (smoothCameraMovement) {
|
||||
|
||||
//stop the coroutine to translate the camera and call it again
|
||||
if (cameraState != null) {
|
||||
StopCoroutine (cameraState);
|
||||
}
|
||||
|
||||
cameraState = StartCoroutine (adjustCamera ());
|
||||
|
||||
if (headTrackManager.useHeadTrackTarget) {
|
||||
headTrackTargeTransform = headTrackManager.getHeadTrackTargetTransform ();
|
||||
|
||||
if (headTrackTargetCoroutine != null) {
|
||||
StopCoroutine (headTrackTargetCoroutine);
|
||||
}
|
||||
|
||||
headTrackTargetCoroutine = StartCoroutine (adjustHeadTrackTarget ());
|
||||
}
|
||||
} else {
|
||||
mainCamera.transform.localRotation = mainCameraTargetRotation;
|
||||
mainCamera.transform.localPosition = mainCameraTargetPosition;
|
||||
|
||||
if (headTrackManager.useHeadTrackTarget) {
|
||||
headTrackTargeTransform = headTrackManager.getHeadTrackTargetTransform ();
|
||||
|
||||
if (deviceEnabled) {
|
||||
headTrackTargeTransform.SetParent (cameraPosition.transform);
|
||||
headTrackTargeTransform.localPosition = mainCameraTargetPosition;
|
||||
} else {
|
||||
headTrackTargeTransform.SetParent (headTrackManager.getHeadTrackTargetParent ());
|
||||
headTrackTargeTransform.localPosition = headTrackManager.getOriginalHeadTrackTargetPosition ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (unlockCursor) {
|
||||
pauseManager.showOrHideMouseCursorController (deviceEnabled);
|
||||
|
||||
if (setNewMouseCursorControllerSpeed) {
|
||||
if (deviceEnabled) {
|
||||
pauseManager.setMouseCursorControllerSpeedOnGameValue (newMouseCursroControllerSpeed);
|
||||
} else {
|
||||
pauseManager.setOriginalMouseCursorControllerSpeedOnGameValue ();
|
||||
}
|
||||
}
|
||||
|
||||
if (ignoreHideCursorOnClick) {
|
||||
pauseManager.setIgnoreHideCursorOnClickActiveState (deviceEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
pauseManager.checkEnableOrDisableTouchZoneList (!deviceEnabled);
|
||||
}
|
||||
|
||||
//move the camera from its position in player camera to a fix position for a proper looking of the computer and vice versa
|
||||
IEnumerator adjustCamera ()
|
||||
{
|
||||
movingCamera = true;
|
||||
|
||||
Transform mainCameraTransform = mainCamera.transform;
|
||||
|
||||
bool ignoreCameraPosition = false;
|
||||
|
||||
if (ignoreCameraPositionAdjusmentOnFBA) {
|
||||
if (currentPlayerControllerManager.isFullBodyAwarenessActive ()) {
|
||||
ignoreCameraPosition = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool useGlobalRotation = false;
|
||||
|
||||
Quaternion cameraRotationTarget = mainCameraTargetRotation;
|
||||
|
||||
if (deviceEnabled && ignoreCameraPosition) {
|
||||
cameraRotationTarget = Quaternion.LookRotation (cameraPosition.transform.forward);
|
||||
|
||||
useGlobalRotation = true;
|
||||
}
|
||||
|
||||
if (useFixedLerpMovement) {
|
||||
float i = 0;
|
||||
//store the current rotation of the camera
|
||||
Quaternion currentQ = mainCameraTransform.localRotation;
|
||||
|
||||
if (useGlobalRotation) {
|
||||
currentQ = mainCameraTransform.rotation;
|
||||
}
|
||||
|
||||
//store the current position of the camera
|
||||
Vector3 currentPos = mainCameraTransform.localPosition;
|
||||
|
||||
//translate position and rotation camera
|
||||
while (i < 1) {
|
||||
i += Time.deltaTime * fixedLerpMovementSpeed;
|
||||
|
||||
if (useGlobalRotation) {
|
||||
mainCameraTransform.rotation = Quaternion.Lerp (currentQ, cameraRotationTarget, i);
|
||||
} else {
|
||||
mainCameraTransform.localRotation = Quaternion.Lerp (currentQ, cameraRotationTarget, i);
|
||||
}
|
||||
|
||||
if (!ignoreCameraPosition) {
|
||||
mainCameraTransform.localPosition = Vector3.Lerp (currentPos, mainCameraTargetPosition, i);
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
} else {
|
||||
bool isFirstPersonActive = playerCameraManager.isFirstPersonActive ();
|
||||
|
||||
float currentCameraMovementSpeed = cameraMovementSpeedThirdPerson;
|
||||
|
||||
if (isFirstPersonActive) {
|
||||
currentCameraMovementSpeed = cameraMovementSpeedFirstPerson;
|
||||
}
|
||||
|
||||
float dist = GKC_Utils.distance (mainCameraTransform.localPosition, mainCameraTargetPosition);
|
||||
|
||||
float duration = dist / currentCameraMovementSpeed;
|
||||
|
||||
float t = 0;
|
||||
|
||||
float movementTimer = 0;
|
||||
|
||||
bool targetReached = false;
|
||||
|
||||
float angleDifference = 0;
|
||||
|
||||
float positionDifference = 0;
|
||||
|
||||
while (!targetReached) {
|
||||
t += Time.deltaTime / duration;
|
||||
|
||||
if (!ignoreCameraPosition) {
|
||||
mainCameraTransform.localPosition = Vector3.Lerp (mainCameraTransform.localPosition, mainCameraTargetPosition, t);
|
||||
}
|
||||
|
||||
if (useGlobalRotation) {
|
||||
mainCameraTransform.rotation = Quaternion.Lerp (mainCameraTransform.rotation, cameraRotationTarget, t);
|
||||
} else {
|
||||
mainCameraTransform.localRotation = Quaternion.Lerp (mainCameraTransform.localRotation, cameraRotationTarget, t);
|
||||
}
|
||||
|
||||
angleDifference = Quaternion.Angle (mainCameraTransform.localRotation, cameraRotationTarget);
|
||||
|
||||
positionDifference = GKC_Utils.distance (mainCameraTransform.localPosition, mainCameraTargetPosition);
|
||||
|
||||
movementTimer += Time.deltaTime;
|
||||
|
||||
if (ignoreCameraPosition) {
|
||||
if (angleDifference < 0.2f) {
|
||||
targetReached = true;
|
||||
}
|
||||
} else {
|
||||
if (positionDifference < 0.01f && angleDifference < 0.2f) {
|
||||
targetReached = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (movementTimer > (duration + 1)) {
|
||||
targetReached = true;
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
movingCamera = false;
|
||||
}
|
||||
|
||||
//move the camera from its position in player camera to a fix position for a proper looking of the computer and vice versa
|
||||
IEnumerator adjustHeadTrackTarget ()
|
||||
{
|
||||
Vector3 targetPosition = mainCameraTargetPosition;
|
||||
Quaternion targeRotation = Quaternion.identity;
|
||||
|
||||
headTrackTargeTransform.SetParent (cameraPosition.transform);
|
||||
|
||||
if (!deviceEnabled) {
|
||||
targetPosition = headTrackManager.getOriginalHeadTrackTargetPosition ();
|
||||
headTrackTargeTransform.SetParent (headTrackManager.getHeadTrackTargetParent ());
|
||||
}
|
||||
|
||||
if (useFixedLerpMovement) {
|
||||
float i = 0;
|
||||
//store the current rotation of the camera
|
||||
Quaternion currentQ = headTrackTargeTransform.localRotation;
|
||||
//store the current position of the camera
|
||||
Vector3 currentPos = headTrackTargeTransform.localPosition;
|
||||
|
||||
//translate position and rotation camera
|
||||
while (i < 1) {
|
||||
i += Time.deltaTime * fixedLerpMovementSpeed;
|
||||
|
||||
headTrackTargeTransform.localRotation = Quaternion.Lerp (currentQ, targeRotation, i);
|
||||
headTrackTargeTransform.localPosition = Vector3.Lerp (currentPos, targetPosition, i);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
} else {
|
||||
bool isFirstPersonActive = playerCameraManager.isFirstPersonActive ();
|
||||
|
||||
float currentCameraMovementSpeed = cameraMovementSpeedThirdPerson;
|
||||
|
||||
if (isFirstPersonActive) {
|
||||
currentCameraMovementSpeed = cameraMovementSpeedFirstPerson;
|
||||
}
|
||||
|
||||
float dist = GKC_Utils.distance (headTrackTargeTransform.localPosition, targetPosition);
|
||||
|
||||
float duration = dist / currentCameraMovementSpeed;
|
||||
|
||||
float t = 0;
|
||||
|
||||
float movementTimer = 0;
|
||||
|
||||
bool targetReached = false;
|
||||
|
||||
float angleDifference = 0;
|
||||
|
||||
float positionDifference = 0;
|
||||
|
||||
while (!targetReached) {
|
||||
t += Time.deltaTime / duration;
|
||||
|
||||
headTrackTargeTransform.localPosition = Vector3.Lerp (headTrackTargeTransform.localPosition, targetPosition, t);
|
||||
headTrackTargeTransform.localRotation = Quaternion.Lerp (headTrackTargeTransform.localRotation, targeRotation, t);
|
||||
|
||||
angleDifference = Quaternion.Angle (headTrackTargeTransform.localRotation, targeRotation);
|
||||
|
||||
positionDifference = GKC_Utils.distance (headTrackTargeTransform.localPosition, targetPosition);
|
||||
|
||||
movementTimer += Time.deltaTime;
|
||||
|
||||
if ((positionDifference < 0.01f && angleDifference < 0.2f) || movementTimer > (duration + 1)) {
|
||||
targetReached = true;
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void hasSecondMoveCameraToDevice ()
|
||||
{
|
||||
secondMoveCameraToDevice = true;
|
||||
}
|
||||
|
||||
public void setCurrentPlayer (GameObject player)
|
||||
{
|
||||
currentPlayer = player;
|
||||
|
||||
if (currentPlayer != null) {
|
||||
mainPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
currentPlayerControllerManager = mainPlayerComponentsManager.getPlayerController ();
|
||||
|
||||
playerCameraManager = mainPlayerComponentsManager.getPlayerCamera ();
|
||||
|
||||
mainCamera = playerCameraManager.getMainCamera ();
|
||||
|
||||
usingDevicesManager = mainPlayerComponentsManager.getUsingDevicesSystem ();
|
||||
|
||||
headBobManager = mainPlayerComponentsManager.getHeadBob ();
|
||||
|
||||
grabObjectsManager = mainPlayerComponentsManager.getGrabObjects ();
|
||||
|
||||
weaponsManager = mainPlayerComponentsManager.getPlayerWeaponsManager ();
|
||||
|
||||
stepManager = mainPlayerComponentsManager.getFootStepManager ();
|
||||
|
||||
headTrackManager = mainPlayerComponentsManager.getHeadTrack ();
|
||||
|
||||
pauseManager = mainPlayerComponentsManager.getPauseManager ();
|
||||
}
|
||||
}
|
||||
|
||||
public void enableFreeInteractionState ()
|
||||
{
|
||||
if (carryWeaponOnLowerPositionActive) {
|
||||
weaponsManager.setCarryWeaponInLowerPositionActiveState (true);
|
||||
|
||||
grabObjectsManager.enableOrDisableGeneralCursorFromExternalComponent (false);
|
||||
}
|
||||
}
|
||||
|
||||
public void disableFreeInteractionState ()
|
||||
{
|
||||
if (carryWeaponOnLowerPositionActive) {
|
||||
weaponsManager.setCarryWeaponInLowerPositionActiveState (false);
|
||||
|
||||
grabObjectsManager.enableOrDisableGeneralCursorFromExternalComponent (true);
|
||||
}
|
||||
}
|
||||
|
||||
public void stopMovement ()
|
||||
{
|
||||
if (cameraState != null) {
|
||||
StopCoroutine (cameraState);
|
||||
}
|
||||
|
||||
deviceEnabled = false;
|
||||
}
|
||||
|
||||
public bool isCameraMoving ()
|
||||
{
|
||||
return movingCamera;
|
||||
}
|
||||
|
||||
public void setCurrentPlayerUseDeviceButtonEnabledState (bool state)
|
||||
{
|
||||
if (usingDevicesManager != null) {
|
||||
usingDevicesManager.setUseDeviceButtonEnabledState (state);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void OnDrawGizmos ()
|
||||
{
|
||||
if (!showGizmo) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
|
||||
DrawGizmos ();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected ()
|
||||
{
|
||||
DrawGizmos ();
|
||||
}
|
||||
|
||||
void DrawGizmos ()
|
||||
{
|
||||
if (showGizmo) {
|
||||
if (cameraPosition != null) {
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawSphere (cameraPosition.transform.position, gizmoRadius);
|
||||
Gizmos.color = Color.white;
|
||||
Gizmos.DrawLine (cameraPosition.transform.position, transform.position);
|
||||
|
||||
Gizmos.color = Color.green;
|
||||
GKC_Utils.drawGizmoArrow (cameraPosition.transform.position, cameraPosition.transform.forward * gizmoArrowLineLength, gizmoArrowColor, gizmoArrowLength, gizmoArrowAngle);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9a8b31f995e2034892d0ff2804df26f
|
||||
timeCreated: 1465230531
|
||||
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/Devices/moveCameraToDevice.cs
|
||||
uploadId: 814740
|
||||
640
Assets/Game Kit Controller/Scripts/Devices/moveDeviceToCamera.cs
Normal file
640
Assets/Game Kit Controller/Scripts/Devices/moveDeviceToCamera.cs
Normal file
@@ -0,0 +1,640 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class moveDeviceToCamera : MonoBehaviour
|
||||
{
|
||||
public GameObject deviceGameObject;
|
||||
public float distanceFromCamera;
|
||||
|
||||
public bool rotateObjectOnCameraDirectionEnabled = true;
|
||||
|
||||
public bool smoothCameraMovement = true;
|
||||
|
||||
public bool useFixedLerpMovement = true;
|
||||
public float fixedLerpMovementSpeed = 2;
|
||||
|
||||
public float cameraMovementSpeedThirdPerson = 2;
|
||||
public float cameraMovementSpeedFirstPerson = 1;
|
||||
|
||||
public bool setNewMouseCursorControllerSpeed;
|
||||
public float newMouseCursroControllerSpeed;
|
||||
|
||||
public float maxZoomDistance;
|
||||
public float minZoomDistance;
|
||||
public float zoomSpeed;
|
||||
|
||||
public string layerToExaminateDevices;
|
||||
|
||||
public bool activateExaminateObjectSystem;
|
||||
|
||||
public bool objectHasActiveRigidbody;
|
||||
|
||||
public bool disablePlayerMeshGameObject = true;
|
||||
|
||||
public bool ignoreFBAActiveIfDisablePlayerMesh;
|
||||
|
||||
public bool keepWeaponsIfCarrying;
|
||||
public bool drawWeaponsIfPreviouslyCarrying;
|
||||
public bool keepOnlyIfPlayerIsOnFirstPerson;
|
||||
public bool disableWeaponsDirectlyOnStart;
|
||||
bool carryingWeaponsPreviously;
|
||||
bool firstPersonActive;
|
||||
|
||||
public Collider deviceTrigger;
|
||||
|
||||
public bool useListOfDisabledObjects;
|
||||
public List<GameObject> disabledObjectList = new List<GameObject> ();
|
||||
|
||||
public List<Collider> colliderListToDisable = new List<Collider> ();
|
||||
public List<Collider> colliderListButtons = new List<Collider> ();
|
||||
|
||||
public bool ignoreDeviceTriggerEnabled;
|
||||
|
||||
public bool useExamineDeviceCameraEnabled = true;
|
||||
|
||||
public bool useBlurUIPanel;
|
||||
|
||||
public bool disableSecondaryPlayerHUD = true;
|
||||
public bool disableAllPlayerHUD;
|
||||
|
||||
public examineObjectSystem examineObjectManager;
|
||||
public Rigidbody mainRigidbody;
|
||||
|
||||
public bool disableInteractionTouchButtonOnUsingDevice = true;
|
||||
|
||||
float originalDistanceFromCamera;
|
||||
|
||||
Vector3 devicePositionTarget;
|
||||
Quaternion deviceRotationTarget;
|
||||
|
||||
Transform originalDeviceParentTransform;
|
||||
Coroutine cameraState;
|
||||
|
||||
Transform deviceTransform;
|
||||
|
||||
bool deviceEnabled;
|
||||
Camera mainCamera;
|
||||
menuPause pauseManager;
|
||||
GameObject currentPlayer;
|
||||
playerController currentPlayerControllerManager;
|
||||
playerWeaponsManager weaponsManager;
|
||||
usingDevicesSystem usingDevicesManager;
|
||||
|
||||
bool previouslyIconButtonActive;
|
||||
|
||||
|
||||
Vector3 originalPosition;
|
||||
Quaternion originalRotation;
|
||||
List<layerInfo> layerList = new List<layerInfo> ();
|
||||
bool previouslyActivated;
|
||||
|
||||
headBob headBobManager;
|
||||
footStepManager stepManager;
|
||||
|
||||
bool originalKinematicValue;
|
||||
bool originalUseGravityValue;
|
||||
Collider playerCollider;
|
||||
|
||||
GameObject examineObjectRenderTexturePanel;
|
||||
Transform examineObjectBlurPanelParent;
|
||||
|
||||
playerComponentsManager mainPlayerComponentsManager;
|
||||
|
||||
bool ignoreObjectRotation = false;
|
||||
|
||||
public bool hideMouseCursorIfUsingGamepad;
|
||||
bool previousCursorVisibleState;
|
||||
|
||||
bool ignoreDisablePlayerMeshResult;
|
||||
|
||||
bool weaponCursorActiveSelfState;
|
||||
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (deviceGameObject == null) {
|
||||
deviceGameObject = gameObject;
|
||||
}
|
||||
|
||||
deviceTransform = deviceGameObject.transform;
|
||||
|
||||
originalPosition = deviceTransform.localPosition;
|
||||
originalRotation = deviceTransform.localRotation;
|
||||
|
||||
originalDeviceParentTransform = deviceTransform.parent;
|
||||
|
||||
setLayerList ();
|
||||
|
||||
originalDistanceFromCamera = distanceFromCamera;
|
||||
|
||||
if (activateExaminateObjectSystem) {
|
||||
if (examineObjectManager == null) {
|
||||
examineObjectManager = GetComponent<examineObjectSystem> ();
|
||||
}
|
||||
}
|
||||
|
||||
if (objectHasActiveRigidbody) {
|
||||
if (mainRigidbody == null) {
|
||||
mainRigidbody = deviceGameObject.GetComponent<Rigidbody> ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//activate the device
|
||||
public void moveCamera (bool state)
|
||||
{
|
||||
deviceEnabled = state;
|
||||
|
||||
if (deviceEnabled) {
|
||||
headBobManager.stopAllHeadbobMovements ();
|
||||
}
|
||||
|
||||
headBobManager.playOrPauseHeadBob (!state);
|
||||
|
||||
|
||||
//if the player is using the computer, disable the player controller, the camera, and set the parent of the camera inside the computer,
|
||||
//to move to its view position
|
||||
|
||||
if (deviceEnabled) {
|
||||
if (currentPlayerControllerManager.isPlayerRunning ()) {
|
||||
currentPlayerControllerManager.stopRun ();
|
||||
}
|
||||
|
||||
//make the mouse cursor visible according to the action of the player
|
||||
currentPlayerControllerManager.setUsingDeviceState (deviceEnabled);
|
||||
|
||||
ignoreDisablePlayerMeshResult = false;
|
||||
|
||||
weaponsManager.setUsingDeviceState (deviceEnabled);
|
||||
|
||||
carryingWeaponsPreviously = weaponsManager.isUsingWeapons ();
|
||||
|
||||
bool playerShootingPreviously = weaponsManager.isCharacterShooting () ||
|
||||
weaponsManager.isReloadingWithAnimationActive ();
|
||||
|
||||
if (carryingWeaponsPreviously) {
|
||||
weaponsManager.stopShootingFireWeaponIfActiveWithoutChangingAimState ();
|
||||
|
||||
weaponsManager.cancelReloadIfActive ();
|
||||
|
||||
if (playerShootingPreviously) {
|
||||
ignoreDisablePlayerMeshResult = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (keepWeaponsIfCarrying) {
|
||||
firstPersonActive = currentPlayerControllerManager.isPlayerOnFirstPerson ();
|
||||
|
||||
if (!keepOnlyIfPlayerIsOnFirstPerson || firstPersonActive) {
|
||||
|
||||
if (carryingWeaponsPreviously) {
|
||||
if (disableWeaponsDirectlyOnStart) {
|
||||
weaponsManager.checkIfDisableCurrentWeapon ();
|
||||
} else {
|
||||
weaponsManager.checkIfKeepSingleOrDualWeapon ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
weaponCursorActiveSelfState = weaponsManager.getGeneralWeaponCursorActiveSelfState ();
|
||||
|
||||
if (weaponCursorActiveSelfState) {
|
||||
weaponsManager.enableOrDisableGeneralWeaponCursor (false);
|
||||
}
|
||||
|
||||
pauseManager.usingDeviceState (deviceEnabled);
|
||||
|
||||
currentPlayerControllerManager.changeScriptState (!deviceEnabled);
|
||||
|
||||
if (disablePlayerMeshGameObject && (!currentPlayerControllerManager.isFullBodyAwarenessActive () || ignoreFBAActiveIfDisablePlayerMesh)) {
|
||||
if (!ignoreDisablePlayerMeshResult) {
|
||||
currentPlayerControllerManager.getGravityCenter ().gameObject.SetActive (!deviceEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
stepManager.enableOrDisableFootStepsComponents (!deviceEnabled);
|
||||
|
||||
pauseManager.showOrHideCursor (deviceEnabled);
|
||||
|
||||
if (hideMouseCursorIfUsingGamepad) {
|
||||
if (pauseManager.isUsingGamepad ()) {
|
||||
previousCursorVisibleState = menuPause.isCursorVisible ();
|
||||
|
||||
menuPause.setCursorVisibleState (false);
|
||||
}
|
||||
}
|
||||
|
||||
pauseManager.changeCameraState (!deviceEnabled);
|
||||
|
||||
previouslyIconButtonActive = usingDevicesManager.getCurrentIconButtonState ();
|
||||
|
||||
if (disableInteractionTouchButtonOnUsingDevice) {
|
||||
usingDevicesManager.setIconButtonCanBeShownState (false);
|
||||
}
|
||||
|
||||
distanceFromCamera = originalDistanceFromCamera;
|
||||
|
||||
if (objectHasActiveRigidbody) {
|
||||
deviceTransform.SetParent (null);
|
||||
|
||||
originalPosition = deviceTransform.localPosition;
|
||||
originalRotation = deviceTransform.localRotation;
|
||||
|
||||
originalDeviceParentTransform = null;
|
||||
}
|
||||
|
||||
deviceTransform.SetParent (mainCamera.transform);
|
||||
|
||||
devicePositionTarget = Vector3.zero + Vector3.forward * distanceFromCamera;
|
||||
deviceRotationTarget = Quaternion.identity;
|
||||
|
||||
setColliderListState (!deviceEnabled);
|
||||
|
||||
if (useExamineDeviceCameraEnabled) {
|
||||
setLayerListState (!deviceEnabled);
|
||||
|
||||
usingDevicesManager.setExamineteDevicesCameraState (deviceEnabled, useBlurUIPanel);
|
||||
}
|
||||
|
||||
previouslyActivated = true;
|
||||
|
||||
if (useBlurUIPanel) {
|
||||
examineObjectRenderTexturePanel.SetActive (true);
|
||||
|
||||
pauseManager.changeBlurUIPanelValue (true, examineObjectBlurPanelParent, true);
|
||||
}
|
||||
} else {
|
||||
//if the player disconnect the computer, then enabled of its components and set the camera to its previous position inside the player
|
||||
//make the mouse cursor visible according to the action of the player
|
||||
currentPlayerControllerManager.setUsingDeviceState (deviceEnabled);
|
||||
|
||||
pauseManager.usingDeviceState (deviceEnabled);
|
||||
|
||||
currentPlayerControllerManager.changeScriptState (!deviceEnabled);
|
||||
|
||||
weaponsManager.setUsingDeviceState (deviceEnabled);
|
||||
|
||||
if (keepWeaponsIfCarrying) {
|
||||
if (!keepOnlyIfPlayerIsOnFirstPerson || firstPersonActive) {
|
||||
if (drawWeaponsIfPreviouslyCarrying && carryingWeaponsPreviously) {
|
||||
weaponsManager.checkIfDrawSingleOrDualWeapon ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (weaponCursorActiveSelfState) {
|
||||
weaponsManager.enableOrDisableGeneralWeaponCursor (true);
|
||||
}
|
||||
|
||||
if (disablePlayerMeshGameObject &&
|
||||
(!currentPlayerControllerManager.isFullBodyAwarenessActive () || ignoreFBAActiveIfDisablePlayerMesh)) {
|
||||
if (!ignoreDisablePlayerMeshResult) {
|
||||
currentPlayerControllerManager.getGravityCenter ().gameObject.SetActive (!deviceEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
stepManager.enableOrDisableFootStepsWithDelay (!deviceEnabled, 0.5f);
|
||||
|
||||
if (hideMouseCursorIfUsingGamepad) {
|
||||
if (pauseManager.isUsingGamepad ()) {
|
||||
menuPause.setCursorVisibleState (previousCursorVisibleState);
|
||||
}
|
||||
}
|
||||
|
||||
pauseManager.showOrHideCursor (deviceEnabled);
|
||||
|
||||
pauseManager.changeCameraState (!deviceEnabled);
|
||||
|
||||
if (previouslyActivated) {
|
||||
usingDevicesManager.setIconButtonCanBeShownState (previouslyIconButtonActive);
|
||||
}
|
||||
|
||||
devicePositionTarget = originalPosition;
|
||||
deviceRotationTarget = originalRotation;
|
||||
|
||||
deviceTransform.SetParent (originalDeviceParentTransform);
|
||||
|
||||
usingDevicesManager.checkIfRemoveDeviceFromList ();
|
||||
|
||||
if (useBlurUIPanel) {
|
||||
pauseManager.changeBlurUIPanelValue (false, examineObjectBlurPanelParent, true);
|
||||
}
|
||||
}
|
||||
|
||||
pauseManager.enableOrDisableDynamicElementsOnScreen (!deviceEnabled);
|
||||
|
||||
if (disableAllPlayerHUD) {
|
||||
pauseManager.enableOrDisablePlayerHUD (!deviceEnabled);
|
||||
} else {
|
||||
if (disableSecondaryPlayerHUD) {
|
||||
pauseManager.enableOrDisableSecondaryPlayerHUD (!deviceEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
ignoreObjectRotation = false;
|
||||
|
||||
if (deviceEnabled && !rotateObjectOnCameraDirectionEnabled) {
|
||||
ignoreObjectRotation = true;
|
||||
}
|
||||
|
||||
if (smoothCameraMovement) {
|
||||
|
||||
//stop the coroutine to translate the device and call it again
|
||||
checkCameraPosition ();
|
||||
} else {
|
||||
deviceTransform.localRotation = deviceRotationTarget;
|
||||
deviceTransform.localPosition = devicePositionTarget;
|
||||
|
||||
if (!deviceEnabled) {
|
||||
setColliderListState (!deviceEnabled);
|
||||
|
||||
if (useExamineDeviceCameraEnabled) {
|
||||
setLayerListState (!deviceEnabled);
|
||||
|
||||
usingDevicesManager.setExamineteDevicesCameraState (deviceEnabled, useBlurUIPanel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (activateExaminateObjectSystem && examineObjectManager) {
|
||||
examineObjectManager.examineDevice ();
|
||||
}
|
||||
|
||||
pauseManager.showOrHideMouseCursorController (deviceEnabled);
|
||||
|
||||
if (setNewMouseCursorControllerSpeed) {
|
||||
if (deviceEnabled) {
|
||||
pauseManager.setMouseCursorControllerSpeedOnGameValue (newMouseCursroControllerSpeed);
|
||||
} else {
|
||||
pauseManager.setOriginalMouseCursorControllerSpeedOnGameValue ();
|
||||
}
|
||||
}
|
||||
|
||||
pauseManager.checkEnableOrDisableTouchZoneList (!deviceEnabled);
|
||||
}
|
||||
|
||||
public void checkCameraPosition ()
|
||||
{
|
||||
if (cameraState != null) {
|
||||
StopCoroutine (cameraState);
|
||||
}
|
||||
|
||||
cameraState = StartCoroutine (adjustCamera ());
|
||||
}
|
||||
|
||||
//move the device from its position in the scene to a fix position in player camera for a proper looking
|
||||
IEnumerator adjustCamera ()
|
||||
{
|
||||
if (deviceEnabled) {
|
||||
setRigidbodyState (true);
|
||||
}
|
||||
|
||||
bool isFirstPersonActive = currentPlayerControllerManager.isPlayerOnFirstPerson ();
|
||||
|
||||
bool rotateObject = true;
|
||||
|
||||
if (ignoreObjectRotation) {
|
||||
rotateObject = false;
|
||||
}
|
||||
|
||||
if (useFixedLerpMovement) {
|
||||
float i = 0;
|
||||
|
||||
Quaternion currentQ = deviceTransform.localRotation;
|
||||
Vector3 currentPos = deviceTransform.localPosition;
|
||||
|
||||
//translate position and rotation of the device
|
||||
while (i < 1) {
|
||||
i += Time.deltaTime * fixedLerpMovementSpeed;
|
||||
|
||||
if (rotateObject) {
|
||||
deviceTransform.localRotation = Quaternion.Lerp (currentQ, deviceRotationTarget, i);
|
||||
}
|
||||
|
||||
deviceTransform.localPosition = Vector3.Lerp (currentPos, devicePositionTarget, i);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
} else {
|
||||
float currentCameraMovementSpeed = cameraMovementSpeedThirdPerson;
|
||||
|
||||
if (isFirstPersonActive) {
|
||||
currentCameraMovementSpeed = cameraMovementSpeedFirstPerson;
|
||||
}
|
||||
|
||||
float dist = GKC_Utils.distance (deviceTransform.localPosition, devicePositionTarget);
|
||||
|
||||
float duration = dist / currentCameraMovementSpeed;
|
||||
|
||||
float t = 0;
|
||||
|
||||
float movementTimer = 0;
|
||||
|
||||
bool targetReached = false;
|
||||
|
||||
float angleDifference = 0;
|
||||
|
||||
float positionDifference = 0;
|
||||
|
||||
while (!targetReached) {
|
||||
t += Time.deltaTime / duration;
|
||||
|
||||
deviceTransform.localPosition = Vector3.Slerp (deviceTransform.localPosition, devicePositionTarget, t);
|
||||
|
||||
if (rotateObject) {
|
||||
deviceTransform.localRotation = Quaternion.Slerp (deviceTransform.localRotation, deviceRotationTarget, t);
|
||||
|
||||
angleDifference = Quaternion.Angle (deviceTransform.localRotation, deviceRotationTarget);
|
||||
} else {
|
||||
angleDifference = 0;
|
||||
}
|
||||
|
||||
positionDifference = GKC_Utils.distance (deviceTransform.localPosition, devicePositionTarget);
|
||||
|
||||
movementTimer += Time.deltaTime;
|
||||
|
||||
if ((positionDifference < 0.01f && angleDifference < 0.2f) || movementTimer > (duration + 1)) {
|
||||
targetReached = true;
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!deviceEnabled) {
|
||||
setColliderListState (true);
|
||||
|
||||
if (useExamineDeviceCameraEnabled) {
|
||||
setLayerListState (true);
|
||||
|
||||
usingDevicesManager.setExamineteDevicesCameraState (false, useBlurUIPanel);
|
||||
}
|
||||
|
||||
setRigidbodyState (false);
|
||||
|
||||
if (useBlurUIPanel) {
|
||||
examineObjectRenderTexturePanel.SetActive (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setRigidbodyState (bool state)
|
||||
{
|
||||
if (mainRigidbody != null && objectHasActiveRigidbody) {
|
||||
if (state) {
|
||||
originalKinematicValue = mainRigidbody.isKinematic;
|
||||
originalUseGravityValue = mainRigidbody.useGravity;
|
||||
mainRigidbody.useGravity = false;
|
||||
mainRigidbody.isKinematic = true;
|
||||
} else {
|
||||
mainRigidbody.useGravity = originalUseGravityValue;
|
||||
mainRigidbody.isKinematic = originalKinematicValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentPlayer (GameObject player)
|
||||
{
|
||||
currentPlayer = player;
|
||||
|
||||
if (currentPlayer != null) {
|
||||
mainPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
currentPlayerControllerManager = mainPlayerComponentsManager.getPlayerController ();
|
||||
|
||||
mainCamera = mainPlayerComponentsManager.getPlayerCamera ().getMainCamera ();
|
||||
|
||||
usingDevicesManager = mainPlayerComponentsManager.getUsingDevicesSystem ();
|
||||
|
||||
headBobManager = mainPlayerComponentsManager.getHeadBob ();
|
||||
|
||||
weaponsManager = mainPlayerComponentsManager.getPlayerWeaponsManager ();
|
||||
|
||||
stepManager = mainPlayerComponentsManager.getFootStepManager ();
|
||||
|
||||
playerCollider = currentPlayerControllerManager.getMainCollider ();
|
||||
|
||||
pauseManager = mainPlayerComponentsManager.getPauseManager ();
|
||||
|
||||
if (useBlurUIPanel) {
|
||||
examineObjectRenderTexturePanel = usingDevicesManager.getExamineObjectRenderTexturePanel ();
|
||||
examineObjectBlurPanelParent = usingDevicesManager.getExamineObjectBlurPanelParent ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setColliderListState (bool state)
|
||||
{
|
||||
for (int i = 0; i < colliderListToDisable.Count; i++) {
|
||||
if (colliderListToDisable [i] != null) {
|
||||
colliderListToDisable [i].enabled = state;
|
||||
|
||||
Physics.IgnoreCollision (playerCollider, colliderListToDisable [i], deviceEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < colliderListButtons.Count; i++) {
|
||||
Physics.IgnoreCollision (playerCollider, colliderListButtons [i], deviceEnabled);
|
||||
}
|
||||
|
||||
if (deviceTrigger != null) {
|
||||
if (ignoreDeviceTriggerEnabled && state) {
|
||||
deviceTrigger.enabled = false;
|
||||
} else {
|
||||
deviceTrigger.enabled = state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setIgnoreDeviceTriggerEnabledState (bool state)
|
||||
{
|
||||
ignoreDeviceTriggerEnabled = state;
|
||||
}
|
||||
|
||||
public void setLayerList ()
|
||||
{
|
||||
Component [] components = deviceGameObject.GetComponentsInChildren (typeof (Transform));
|
||||
|
||||
foreach (Component c in components) {
|
||||
layerInfo newLayerInfo = new layerInfo ();
|
||||
|
||||
newLayerInfo.gameObject = c.gameObject;
|
||||
newLayerInfo.layerNumber = c.gameObject.layer;
|
||||
|
||||
layerList.Add (newLayerInfo);
|
||||
}
|
||||
|
||||
if (useListOfDisabledObjects) {
|
||||
for (int i = 0; i < disabledObjectList.Count; i++) {
|
||||
if (disabledObjectList [i] != null) {
|
||||
if (disabledObjectList [i].activeSelf) {
|
||||
disabledObjectList [i].SetActive (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setLayerListState (bool state)
|
||||
{
|
||||
int layerIndex = LayerMask.NameToLayer (layerToExaminateDevices);
|
||||
|
||||
for (int i = 0; i < layerList.Count; i++) {
|
||||
if (layerList [i].gameObject != null) {
|
||||
if (state) {
|
||||
layerList [i].gameObject.layer = layerList [i].layerNumber;
|
||||
} else {
|
||||
layerList [i].gameObject.layer = layerIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void changeDeviceZoom (bool zoomIn)
|
||||
{
|
||||
if (zoomIn) {
|
||||
distanceFromCamera += Time.deltaTime * zoomSpeed;
|
||||
} else {
|
||||
distanceFromCamera -= Time.deltaTime * zoomSpeed;
|
||||
}
|
||||
|
||||
if (distanceFromCamera > maxZoomDistance) {
|
||||
distanceFromCamera = maxZoomDistance;
|
||||
}
|
||||
if (distanceFromCamera < minZoomDistance) {
|
||||
distanceFromCamera = minZoomDistance;
|
||||
}
|
||||
|
||||
checkCameraPosition ();
|
||||
|
||||
devicePositionTarget = Vector3.zero + Vector3.forward * distanceFromCamera;
|
||||
deviceRotationTarget = transform.localRotation;
|
||||
}
|
||||
|
||||
public void resetRotation ()
|
||||
{
|
||||
devicePositionTarget = transform.localPosition;
|
||||
deviceRotationTarget = Quaternion.identity;
|
||||
|
||||
checkCameraPosition ();
|
||||
}
|
||||
|
||||
public void resetRotationAndPosition ()
|
||||
{
|
||||
devicePositionTarget = Vector3.zero + Vector3.forward * originalDistanceFromCamera;
|
||||
deviceRotationTarget = Quaternion.identity;
|
||||
|
||||
checkCameraPosition ();
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class layerInfo
|
||||
{
|
||||
public GameObject gameObject;
|
||||
public int layerNumber;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de71c2ca26911274d8f50d6b3b90205f
|
||||
timeCreated: 1509843317
|
||||
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/Devices/moveDeviceToCamera.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,197 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class oneWayPlatformSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public List<string> tagToCheck = new List<string> ();
|
||||
|
||||
public bool ignoreCollisionOnTop;
|
||||
public bool ignoreCollisionOnBottom;
|
||||
|
||||
[Space]
|
||||
[Header ("Conditions Settings")]
|
||||
[Space]
|
||||
|
||||
public bool playerNeedsToCrouchToIgnore;
|
||||
|
||||
public bool useOnlyCrouchToIgnore;
|
||||
|
||||
public bool useOnlyMoveInputDownToIgnore;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool playerFound;
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
public List<passengersInfo> passengersInfoList = new List<passengersInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Collider platformCollider;
|
||||
public Transform platformTransform;
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (playerFound) {
|
||||
int passengersInfoListCount = passengersInfoList.Count;
|
||||
|
||||
for (int i = 0; i < passengersInfoListCount; i++) {
|
||||
passengersInfo currentPassengersInfo = passengersInfoList [i];
|
||||
|
||||
if (currentPassengersInfo.ignoringPlayerColliderFromBottom) {
|
||||
if (platformTransform.transform.position.y < currentPassengersInfo.playerTransform.position.y) {
|
||||
Physics.IgnoreCollision (platformCollider, currentPassengersInfo.playerCollider, false);
|
||||
|
||||
currentPassengersInfo.ignoringPlayerColliderFromBottom = false;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("ignoring player collider ended");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ignoreCollisionOnTop) {
|
||||
if (!currentPassengersInfo.ignoringPlayerColliderFromTop) {
|
||||
bool ignoreCollisionResult = false;
|
||||
|
||||
bool characterIsCrouching = currentPassengersInfo.playerControllerManager.isCrouching ();
|
||||
|
||||
if (currentPassengersInfo.playerControllerManager.getAxisValues ().y < 0) {
|
||||
if (useOnlyMoveInputDownToIgnore) {
|
||||
ignoreCollisionResult = true;
|
||||
} else {
|
||||
if (!playerNeedsToCrouchToIgnore || characterIsCrouching) {
|
||||
ignoreCollisionResult = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (useOnlyCrouchToIgnore && characterIsCrouching) {
|
||||
ignoreCollisionResult = true;
|
||||
}
|
||||
|
||||
if (ignoreCollisionResult) {
|
||||
Physics.IgnoreCollision (platformCollider, currentPassengersInfo.playerCollider, true);
|
||||
|
||||
currentPassengersInfo.playerControllerManager.setcheckOnGroundStatePausedState (true);
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("condition to ignore collision from the top activated");
|
||||
}
|
||||
|
||||
currentPassengersInfo.ignoringPlayerColliderFromTop = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnTriggerEnter (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, true);
|
||||
}
|
||||
|
||||
public void OnTriggerExit (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, false);
|
||||
}
|
||||
|
||||
public void checkTriggerInfo (Collider col, bool isEnter)
|
||||
{
|
||||
if (tagToCheck.Contains (col.tag)) {
|
||||
if (isEnter) {
|
||||
addPassenger (col.gameObject.transform);
|
||||
|
||||
passengersInfo currentPassengersInfo = passengersInfoList [passengersInfoList.Count - 1];
|
||||
|
||||
if (ignoreCollisionOnBottom) {
|
||||
if (platformTransform.transform.position.y > currentPassengersInfo.playerTransform.position.y) {
|
||||
Physics.IgnoreCollision (platformCollider, currentPassengersInfo.playerCollider, true);
|
||||
currentPassengersInfo.ignoringPlayerColliderFromBottom = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("player added on the list");
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < passengersInfoList.Count; i++) {
|
||||
passengersInfo currentPassengersInfo = passengersInfoList [i];
|
||||
|
||||
if (currentPassengersInfo.playerTransform == col.transform) {
|
||||
|
||||
Physics.IgnoreCollision (platformCollider, currentPassengersInfo.playerCollider, false);
|
||||
|
||||
if (ignoreCollisionOnTop) {
|
||||
currentPassengersInfo.playerControllerManager.setcheckOnGroundStatePausedState (false);
|
||||
}
|
||||
|
||||
removePassenger (currentPassengersInfo.playerTransform);
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("player removed");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addPassenger (Transform newPassenger)
|
||||
{
|
||||
bool passengerFound = false;
|
||||
|
||||
for (int i = 0; i < passengersInfoList.Count; i++) {
|
||||
if (passengersInfoList [i].playerTransform == newPassenger && !passengerFound) {
|
||||
passengerFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!passengerFound) {
|
||||
passengersInfo newPassengersInfo = new passengersInfo ();
|
||||
newPassengersInfo.playerTransform = newPassenger;
|
||||
newPassengersInfo.playerControllerManager = newPassenger.GetComponent<playerController> ();
|
||||
newPassengersInfo.playerCollider = newPassengersInfo.playerControllerManager.getMainCollider ();
|
||||
|
||||
passengersInfoList.Add (newPassengersInfo);
|
||||
|
||||
playerFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
void removePassenger (Transform newPassenger)
|
||||
{
|
||||
for (int i = 0; i < passengersInfoList.Count; i++) {
|
||||
if (passengersInfoList [i].playerTransform == newPassenger) {
|
||||
passengersInfoList.RemoveAt (i);
|
||||
}
|
||||
}
|
||||
|
||||
if (passengersInfoList.Count == 0) {
|
||||
playerFound = false;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class passengersInfo
|
||||
{
|
||||
public Transform playerTransform;
|
||||
public playerController playerControllerManager;
|
||||
public Collider playerCollider;
|
||||
|
||||
public bool ignoringPlayerColliderFromTop;
|
||||
public bool ignoringPlayerColliderFromBottom;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dbcd8b02c85223948967866e2f49f07e
|
||||
timeCreated: 1542734165
|
||||
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/Devices/oneWayPlatformSystem.cs
|
||||
uploadId: 814740
|
||||
523
Assets/Game Kit Controller/Scripts/Devices/padlockSystem.cs
Normal file
523
Assets/Game Kit Controller/Scripts/Devices/padlockSystem.cs
Normal file
@@ -0,0 +1,523 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
using System.Reflection;
|
||||
using GameKitController.Audio;
|
||||
|
||||
public class padlockSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public string currentCodeOnWheels;
|
||||
public string correctCode;
|
||||
public float rotateWheelSpeed;
|
||||
public int numbersPerWheel;
|
||||
|
||||
public float waitDelayAfterUnlock;
|
||||
|
||||
[Space]
|
||||
[Header ("Interaction Settings")]
|
||||
[Space]
|
||||
|
||||
public bool allowToUseKeyboard;
|
||||
public bool useSwipeToRotateWheels;
|
||||
public float minSwipeDist;
|
||||
public bool useSwipeAndClickForWheels;
|
||||
|
||||
public bool allowKeyboardControls;
|
||||
|
||||
public bool useMouseWheelToRotateActive = true;
|
||||
|
||||
[Space]
|
||||
[Header ("Wheel Settings")]
|
||||
[Space]
|
||||
|
||||
public List<wheelInfo> wheels = new List<wheelInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool usingDevice;
|
||||
|
||||
[Space]
|
||||
[Header ("Event Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventsOnUnlock;
|
||||
public UnityEvent eventOnUnlock;
|
||||
|
||||
public bool callEventsAfterActivateUnlock;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public GameObject resetButton;
|
||||
|
||||
public GameObject resolveButton;
|
||||
|
||||
public AudioClip corretPassSound;
|
||||
public AudioElement corretPassAudioElement;
|
||||
public AudioClip keyPressSound;
|
||||
public AudioElement keyPressAudioElement;
|
||||
|
||||
public Transform currentWheelMark;
|
||||
public Vector3 currentWheelMarkOffset;
|
||||
|
||||
public AudioSource audioSource;
|
||||
public electronicDevice deviceManager;
|
||||
public examineObjectSystem examineObjectManager;
|
||||
|
||||
readonly List<RaycastResult> captureRaycastResults = new List<RaycastResult> ();
|
||||
int length;
|
||||
bool unlocked;
|
||||
|
||||
bool touchPlatform;
|
||||
RaycastHit hit;
|
||||
GameObject currentCaptured;
|
||||
Touch currentTouch;
|
||||
|
||||
float anglePerWheel;
|
||||
|
||||
bool touching;
|
||||
|
||||
wheelInfo currentWheelInfo;
|
||||
int currentWheelIndex;
|
||||
|
||||
Vector3 swipeStartPos;
|
||||
Vector3 swipeFinalPos;
|
||||
|
||||
int currentWheelRotationDirection = 1;
|
||||
playerInputManager playerInput;
|
||||
bool pressingHorizontalRight;
|
||||
bool pressingHorizontalLeft;
|
||||
bool resetingPadlock;
|
||||
|
||||
GameObject currentPlayer;
|
||||
|
||||
Vector2 axisValues;
|
||||
|
||||
padlockSystemPlayerManagement currentPadlockSystemPlayerManagement;
|
||||
|
||||
private void InitializeAudioElements ()
|
||||
{
|
||||
if (audioSource == null) {
|
||||
audioSource = GetComponent<AudioSource> ();
|
||||
}
|
||||
|
||||
if (audioSource != null) {
|
||||
corretPassAudioElement.audioSource = audioSource;
|
||||
keyPressAudioElement.audioSource = audioSource;
|
||||
}
|
||||
|
||||
if (corretPassSound != null) {
|
||||
corretPassAudioElement.clip = corretPassSound;
|
||||
}
|
||||
|
||||
if (keyPressSound != null) {
|
||||
keyPressAudioElement.clip = keyPressSound;
|
||||
}
|
||||
}
|
||||
|
||||
void Start ()
|
||||
{
|
||||
anglePerWheel = 360 / numbersPerWheel;
|
||||
touchPlatform = touchJoystick.checkTouchPlatform ();
|
||||
|
||||
InitializeAudioElements ();
|
||||
|
||||
if (deviceManager == null) {
|
||||
deviceManager = GetComponent<electronicDevice> ();
|
||||
}
|
||||
|
||||
if (examineObjectManager == null) {
|
||||
examineObjectManager = GetComponent<examineObjectSystem> ();
|
||||
}
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
//if the terminal still locked, and the player is using it
|
||||
if (!unlocked && usingDevice && !playerInput.isGameManagerPaused ()) {
|
||||
// //use the center of the camera as mouse, checking also the touch input
|
||||
int touchCount = Input.touchCount;
|
||||
if (!touchPlatform) {
|
||||
touchCount++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < touchCount; i++) {
|
||||
if (!touchPlatform) {
|
||||
currentTouch = touchJoystick.convertMouseIntoFinger ();
|
||||
} else {
|
||||
currentTouch = Input.GetTouch (i);
|
||||
}
|
||||
|
||||
//get a list with all the objects under the center of the screen of the finger tap
|
||||
captureRaycastResults.Clear ();
|
||||
|
||||
PointerEventData p = new PointerEventData (EventSystem.current);
|
||||
p.position = currentTouch.position;
|
||||
p.clickCount = i;
|
||||
p.dragging = false;
|
||||
|
||||
EventSystem.current.RaycastAll (p, captureRaycastResults);
|
||||
|
||||
if (captureRaycastResults.Count > 0) {
|
||||
currentCaptured = captureRaycastResults [0].gameObject;
|
||||
//check the current number key pressed with the finger
|
||||
if (currentTouch.phase == TouchPhase.Began) {
|
||||
for (int k = 0; k < wheels.Count; k++) {
|
||||
if (wheels [k].wheelTransform == currentCaptured.transform) {
|
||||
|
||||
touching = true;
|
||||
changeExamineObjectState (false);
|
||||
|
||||
currentWheelInfo = wheels [k];
|
||||
|
||||
swipeStartPos = currentTouch.position;
|
||||
}
|
||||
}
|
||||
|
||||
if (resetButton) {
|
||||
if (currentCaptured == resetButton) {
|
||||
resetPadLock ();
|
||||
}
|
||||
}
|
||||
|
||||
if (resolveButton) {
|
||||
if (currentCaptured == resolveButton) {
|
||||
setCorrectCode ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (currentTouch.phase == TouchPhase.Ended) {
|
||||
if (touching && useSwipeToRotateWheels) {
|
||||
|
||||
swipeFinalPos = currentTouch.position;
|
||||
|
||||
Vector2 currentSwipe = new Vector2 (swipeFinalPos.x - swipeStartPos.x, swipeFinalPos.y - swipeStartPos.y);
|
||||
|
||||
if (currentSwipe.magnitude > minSwipeDist) {
|
||||
currentSwipe.Normalize ();
|
||||
if (Vector2.Dot (currentSwipe, GKC_Utils.swipeDirections.up) > 0.906f) {
|
||||
//up swipe
|
||||
setNextNumber ();
|
||||
}
|
||||
if (Vector2.Dot (currentSwipe, GKC_Utils.swipeDirections.down) > 0.906f) {
|
||||
//down swipe
|
||||
setPreviousNumber ();
|
||||
}
|
||||
}
|
||||
|
||||
if (useSwipeAndClickForWheels) {
|
||||
checkNumber (currentWheelInfo, -1);
|
||||
}
|
||||
}
|
||||
|
||||
changeExamineObjectState (true);
|
||||
|
||||
touching = false;
|
||||
|
||||
currentWheelInfo = null;
|
||||
}
|
||||
|
||||
if (touching && (currentTouch.phase == TouchPhase.Stationary || currentTouch.phase == TouchPhase.Moved)) {
|
||||
if (!useSwipeToRotateWheels) {
|
||||
checkNumber (currentWheelInfo, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (allowToUseKeyboard) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (Input.GetKeyDown ("" + i)) {
|
||||
checkNumberByKeyboard (i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (allowKeyboardControls) {
|
||||
axisValues = playerInput.getPlayerMovementAxis ();
|
||||
|
||||
if (axisValues.y < 0) {
|
||||
currentWheelInfo = wheels [currentWheelIndex];
|
||||
setNextNumber ();
|
||||
}
|
||||
|
||||
if (axisValues.y > 0) {
|
||||
currentWheelInfo = wheels [currentWheelIndex];
|
||||
setPreviousNumber ();
|
||||
}
|
||||
|
||||
if (!pressingHorizontalRight) {
|
||||
if (axisValues.x > 0) {
|
||||
setCurrentWheelIndex (1);
|
||||
pressingHorizontalRight = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pressingHorizontalLeft) {
|
||||
if (axisValues.x < 0) {
|
||||
setCurrentWheelIndex (-1);
|
||||
pressingHorizontalLeft = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (axisValues.x == 0) {
|
||||
pressingHorizontalLeft = false;
|
||||
pressingHorizontalRight = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentWheelIndex (int amount)
|
||||
{
|
||||
currentWheelIndex += amount;
|
||||
|
||||
if (currentWheelIndex >= wheels.Count) {
|
||||
currentWheelIndex = 0;
|
||||
}
|
||||
|
||||
if (currentWheelIndex < 0) {
|
||||
currentWheelIndex = wheels.Count - 1;
|
||||
}
|
||||
|
||||
if (currentWheelMark) {
|
||||
currentWheelMark.localPosition = wheels [currentWheelIndex].wheelTransform.localPosition + currentWheelMarkOffset;
|
||||
}
|
||||
}
|
||||
|
||||
public void setPreviousNumber ()
|
||||
{
|
||||
currentWheelRotationDirection = 1;
|
||||
|
||||
checkNumber (currentWheelInfo, -1);
|
||||
}
|
||||
|
||||
public void setNextNumber ()
|
||||
{
|
||||
currentWheelRotationDirection = -1;
|
||||
|
||||
checkNumber (currentWheelInfo, -1);
|
||||
}
|
||||
|
||||
public void activatePadlock ()
|
||||
{
|
||||
usingDevice = !usingDevice;
|
||||
|
||||
if (usingDevice) {
|
||||
currentPlayer = deviceManager.getCurrentPlayer ();
|
||||
|
||||
playerComponentsManager mainPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
playerInput = mainPlayerComponentsManager.getPlayerInputManager ();
|
||||
|
||||
currentPadlockSystemPlayerManagement = mainPlayerComponentsManager.getPadlockSystemPlayerManagement ();
|
||||
|
||||
currentPadlockSystemPlayerManagement.setCurrentPadlockSystem (this);
|
||||
}
|
||||
|
||||
currentPadlockSystemPlayerManagement.setUsingPadlockState (usingDevice);
|
||||
}
|
||||
|
||||
public void checkNumberByKeyboard (int number)
|
||||
{
|
||||
if (wheels [currentWheelIndex].wheelRotating) {
|
||||
return;
|
||||
}
|
||||
|
||||
checkNumber (wheels [currentWheelIndex], number);
|
||||
|
||||
setCurrentWheelIndex (1);
|
||||
}
|
||||
|
||||
public void checkNumber (wheelInfo wheel, int wheelNumber)
|
||||
{
|
||||
if (wheel.wheelRotating && !resetingPadlock) {
|
||||
return;
|
||||
}
|
||||
|
||||
AudioPlayer.PlayOneShot (keyPressAudioElement, gameObject);
|
||||
|
||||
if (wheelNumber > -1) {
|
||||
if (wheelNumber <= numbersPerWheel) {
|
||||
wheel.currentNumber = wheelNumber;
|
||||
|
||||
if (resetingPadlock) {
|
||||
StartCoroutine (rotateCenter (currentWheelRotationDirection, wheel, wheelNumber));
|
||||
} else {
|
||||
checkRotateWheel (currentWheelRotationDirection, wheel, wheel.currentNumber);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
wheel.currentNumber += currentWheelRotationDirection;
|
||||
|
||||
if (wheel.currentNumber >= numbersPerWheel) {
|
||||
wheel.currentNumber = 0;
|
||||
}
|
||||
|
||||
if (wheel.currentNumber < 0) {
|
||||
wheel.currentNumber = numbersPerWheel - 1;
|
||||
}
|
||||
|
||||
checkRotateWheel (currentWheelRotationDirection, wheel, wheel.currentNumber);
|
||||
}
|
||||
|
||||
currentCodeOnWheels = getCurrentCodeOnWheels ();
|
||||
|
||||
if (currentCodeOnWheels == correctCode) {
|
||||
setLockedState (true);
|
||||
}
|
||||
}
|
||||
|
||||
public string getCurrentCodeOnWheels ()
|
||||
{
|
||||
string code = "";
|
||||
|
||||
for (int i = 0; i < wheels.Count; i++) {
|
||||
code += wheels [i].currentNumber.ToString ();
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setLockedState (bool state)
|
||||
{
|
||||
if (state) {
|
||||
AudioPlayer.PlayOneShot (corretPassAudioElement, gameObject);
|
||||
unlocked = true;
|
||||
|
||||
GetComponent<Collider> ().enabled = false;
|
||||
|
||||
if (callEventsAfterActivateUnlock) {
|
||||
checkStopUsingDevice ();
|
||||
}
|
||||
|
||||
if (useEventsOnUnlock) {
|
||||
eventOnUnlock.Invoke ();
|
||||
}
|
||||
|
||||
deviceManager.unlockObject ();
|
||||
|
||||
if (!callEventsAfterActivateUnlock) {
|
||||
checkStopUsingDevice ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void checkStopUsingDevice ()
|
||||
{
|
||||
if (waitDelayAfterUnlock > 0) {
|
||||
StartCoroutine (waitingAfterUnlock ());
|
||||
} else {
|
||||
deviceManager.stopUsindDevice ();
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator waitingAfterUnlock ()
|
||||
{
|
||||
yield return new WaitForSeconds (waitDelayAfterUnlock);
|
||||
|
||||
deviceManager.stopUsindDevice ();
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
public void checkRotateWheel (int direction, wheelInfo wheel, int number)
|
||||
{
|
||||
StartCoroutine (rotateCenter (direction, wheel, number));
|
||||
}
|
||||
|
||||
public IEnumerator rotateCenter (int direction, wheelInfo wheel, int number)
|
||||
{
|
||||
wheel.wheelRotating = true;
|
||||
|
||||
Quaternion orgRotCenter = wheel.wheelTransform.localRotation;
|
||||
|
||||
float rotationAmount = number * anglePerWheel * direction * (-currentWheelRotationDirection);
|
||||
Quaternion dstRotCenter = Quaternion.Euler (new Vector3 (orgRotCenter.eulerAngles.x, orgRotCenter.eulerAngles.y, rotationAmount));
|
||||
|
||||
for (float t = 0; t < 1;) {
|
||||
t += Time.deltaTime * rotateWheelSpeed;
|
||||
wheel.wheelTransform.localRotation = Quaternion.Slerp (orgRotCenter, dstRotCenter, t);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
wheel.wheelRotating = false;
|
||||
|
||||
currentWheelRotationDirection = 1;
|
||||
|
||||
resetingPadlock = false;
|
||||
}
|
||||
|
||||
public void resetPadLock ()
|
||||
{
|
||||
resetingPadlock = true;
|
||||
|
||||
for (int i = 0; i < wheels.Count; i++) {
|
||||
currentWheelIndex = i;
|
||||
|
||||
checkNumberByKeyboard (0);
|
||||
}
|
||||
|
||||
currentWheelIndex = 0;
|
||||
|
||||
setCurrentWheelIndex (0);
|
||||
}
|
||||
|
||||
public void setCorrectCode ()
|
||||
{
|
||||
resetingPadlock = true;
|
||||
|
||||
for (int i = 0; i < wheels.Count; i++) {
|
||||
currentWheelIndex = i;
|
||||
|
||||
checkNumberByKeyboard (int.Parse (correctCode [i].ToString ()));
|
||||
}
|
||||
|
||||
currentWheelIndex = 0;
|
||||
|
||||
setCurrentWheelIndex (0);
|
||||
}
|
||||
|
||||
public void changeExamineObjectState (bool state)
|
||||
{
|
||||
if (examineObjectManager != null) {
|
||||
examineObjectManager.setExamineDeviceState (state);
|
||||
}
|
||||
}
|
||||
|
||||
public void inputRotateWheel (bool directionUp)
|
||||
{
|
||||
if (useMouseWheelToRotateActive) {
|
||||
if (directionUp) {
|
||||
currentWheelInfo = wheels [currentWheelIndex];
|
||||
|
||||
setNextNumber ();
|
||||
} else {
|
||||
currentWheelInfo = wheels [currentWheelIndex];
|
||||
|
||||
setPreviousNumber ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class wheelInfo
|
||||
{
|
||||
public string name;
|
||||
public int currentNumber;
|
||||
public Transform wheelTransform;
|
||||
public bool wheelRotating;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a89c7dad879cd60459300d708898ecc0
|
||||
timeCreated: 1512920632
|
||||
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/Devices/padlockSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,57 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class padlockSystemPlayerManagement : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool usingPadlock;
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventsOnStateChange;
|
||||
public UnityEvent evenOnStateEnabled;
|
||||
public UnityEvent eventOnStateDisabled;
|
||||
|
||||
padlockSystem currentPadlockSystem;
|
||||
|
||||
public void setCurrentPadlockSystem (padlockSystem newPadlockSystem)
|
||||
{
|
||||
currentPadlockSystem = newPadlockSystem;
|
||||
}
|
||||
|
||||
public void setUsingPadlockState (bool state)
|
||||
{
|
||||
usingPadlock = state;
|
||||
|
||||
checkEventsOnStateChange (usingPadlock);
|
||||
}
|
||||
|
||||
//CALL INPUT FUNCTIONS TO CURRENT PUZZLE SYSTEM
|
||||
public void inputRotateWheel (bool directionUp)
|
||||
{
|
||||
if (!usingPadlock) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentPadlockSystem != null) {
|
||||
currentPadlockSystem.inputRotateWheel (directionUp);
|
||||
}
|
||||
}
|
||||
|
||||
public void checkEventsOnStateChange (bool state)
|
||||
{
|
||||
if (useEventsOnStateChange) {
|
||||
if (state) {
|
||||
evenOnStateEnabled.Invoke ();
|
||||
} else {
|
||||
eventOnStateDisabled.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb41e41492942604a9829a8654f1122e
|
||||
timeCreated: 1551244781
|
||||
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/Devices/padlockSystemPlayerManagement.cs
|
||||
uploadId: 814740
|
||||
137
Assets/Game Kit Controller/Scripts/Devices/pressurePlate.cs
Normal file
137
Assets/Game Kit Controller/Scripts/Devices/pressurePlate.cs
Normal file
@@ -0,0 +1,137 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class pressurePlate : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public float minDistance;
|
||||
|
||||
public List<string> tagsToIgnore = new List<string>{ "Player" };
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public UnityEvent unlockFunctionCall = new UnityEvent ();
|
||||
public UnityEvent lockFunctionCall = new UnityEvent ();
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool usingPlate;
|
||||
public bool activeFunctionCalled;
|
||||
public bool disableFunctionCalled;
|
||||
|
||||
public List<GameObject> objects = new List<GameObject> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public GameObject plate;
|
||||
public Transform finalPosition;
|
||||
|
||||
List<Collider> colliders = new List<Collider> ();
|
||||
Coroutine setPlateState;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
Component[] components = GetComponentsInChildren (typeof(Collider));
|
||||
foreach (Collider c in components) {
|
||||
colliders.Add (c);
|
||||
}
|
||||
|
||||
Collider plateCollider = plate.GetComponent<Collider> ();
|
||||
|
||||
for (int i = 0; i < colliders.Count; i++) {
|
||||
if (colliders [i] != plate) {
|
||||
Physics.IgnoreCollision (plateCollider, colliders [i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (usingPlate) {
|
||||
if ((Mathf.Abs (Mathf.Abs (plate.transform.position.y) - Mathf.Abs (finalPosition.position.y)) < minDistance) || plate.transform.position.y < finalPosition.position.y) {
|
||||
if (!activeFunctionCalled) {
|
||||
activeFunctionCalled = true;
|
||||
disableFunctionCalled = false;
|
||||
|
||||
if (unlockFunctionCall.GetPersistentEventCount () > 0) {
|
||||
unlockFunctionCall.Invoke ();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (activeFunctionCalled) {
|
||||
activeFunctionCalled = false;
|
||||
disableFunctionCalled = true;
|
||||
|
||||
if (lockFunctionCall.GetPersistentEventCount () > 0) {
|
||||
lockFunctionCall.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerEnter (Collider col)
|
||||
{
|
||||
if (col.gameObject.GetComponent<Rigidbody> () && !tagsToIgnore.Contains (col.gameObject.tag)) {
|
||||
checkCoroutine (true);
|
||||
|
||||
if (!objects.Contains (col.gameObject) && col.gameObject != plate) {
|
||||
objects.Add (col.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit (Collider col)
|
||||
{
|
||||
if (col.gameObject.GetComponent<Rigidbody> () && !tagsToIgnore.Contains (col.gameObject.tag)) {
|
||||
if (objects.Contains (col.gameObject)) {
|
||||
objects.Remove (col.gameObject);
|
||||
}
|
||||
|
||||
for (int i = 0; i < objects.Count; i++) {
|
||||
if (!objects [i]) {
|
||||
objects.RemoveAt (i);
|
||||
}
|
||||
}
|
||||
|
||||
if (objects.Count == 0) {
|
||||
checkCoroutine (false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void checkCoroutine (bool state)
|
||||
{
|
||||
if (setPlateState != null) {
|
||||
StopCoroutine (setPlateState);
|
||||
}
|
||||
|
||||
setPlateState = StartCoroutine (enableOrDisablePlate (state));
|
||||
}
|
||||
|
||||
IEnumerator enableOrDisablePlate (bool state)
|
||||
{
|
||||
if (state) {
|
||||
usingPlate = true;
|
||||
yield return null;
|
||||
} else {
|
||||
yield return new WaitForSeconds (1);
|
||||
usingPlate = false;
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter (Collision col)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 868f75dfc5b3d4d4eb6e9cc799821f36
|
||||
timeCreated: 1468949402
|
||||
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/Devices/pressurePlate.cs
|
||||
uploadId: 814740
|
||||
179
Assets/Game Kit Controller/Scripts/Devices/rechargerStation.cs
Normal file
179
Assets/Game Kit Controller/Scripts/Devices/rechargerStation.cs
Normal file
@@ -0,0 +1,179 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using GameKitController.Audio;
|
||||
|
||||
public class rechargerStation : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public float healSpeed;
|
||||
public string animationName;
|
||||
public AudioClip sound;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool healing;
|
||||
public bool fullyHealed;
|
||||
public bool inside;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public AudioElement soundAudioElement;
|
||||
public GameObject button;
|
||||
public AudioSource mainAudioSource;
|
||||
public Collider buttonCollider;
|
||||
public Animation mainAnimation;
|
||||
|
||||
GameObject player;
|
||||
|
||||
bool playingAnimationForward;
|
||||
float healthAmount;
|
||||
float maxHealthAmount;
|
||||
float powerAmount;
|
||||
float maxPowerAmount;
|
||||
otherPowers powerManager;
|
||||
health currentHealth;
|
||||
|
||||
//this station reloads the player's health and energy, just in case that any of their values are lower that their max values
|
||||
void Start ()
|
||||
{
|
||||
//disable the button trigger
|
||||
if (mainAudioSource == null) {
|
||||
mainAudioSource = GetComponent<AudioSource> ();
|
||||
}
|
||||
|
||||
mainAudioSource.clip = sound;
|
||||
|
||||
if (sound != null) {
|
||||
soundAudioElement.clip = sound;
|
||||
}
|
||||
|
||||
if (mainAudioSource != null) {
|
||||
soundAudioElement.audioSource = mainAudioSource;
|
||||
}
|
||||
|
||||
if (buttonCollider == null) {
|
||||
buttonCollider = button.GetComponent<Collider> ();
|
||||
}
|
||||
|
||||
buttonCollider.enabled = false;
|
||||
|
||||
if (mainAnimation == null) {
|
||||
mainAnimation = GetComponent<Animation> ();
|
||||
}
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
//if the station is healing the player
|
||||
if (healing && !fullyHealed) {
|
||||
//refill health and energy
|
||||
healthAmount = applyDamage.getCurrentHealthAmount (player);
|
||||
|
||||
maxHealthAmount = applyDamage.getMaxHealthAmount (player);
|
||||
|
||||
powerAmount = powerManager.getCurrentEnergyAmount ();
|
||||
|
||||
maxPowerAmount = powerManager.getMaxEnergyAmount ();
|
||||
|
||||
if (healthAmount < maxHealthAmount) {
|
||||
currentHealth.getHealth (Time.deltaTime * healSpeed);
|
||||
}
|
||||
|
||||
if (powerAmount < maxPowerAmount) {
|
||||
powerManager.getEnergy (Time.deltaTime * healSpeed);
|
||||
}
|
||||
|
||||
//if the healht and energy are both refilled, stop the station
|
||||
if (healthAmount >= maxHealthAmount && powerAmount >= maxPowerAmount) {
|
||||
stopHealing ();
|
||||
}
|
||||
}
|
||||
|
||||
//if the player enters in the station and the button is not enabled
|
||||
if (inside && !healing && !buttonCollider.enabled) {
|
||||
//check the health and energy values
|
||||
healthAmount = applyDamage.getCurrentHealthAmount (player);
|
||||
maxHealthAmount = applyDamage.getMaxHealthAmount (player);
|
||||
powerAmount = powerManager.getCurrentEnergyAmount ();
|
||||
maxPowerAmount = powerManager.getMaxEnergyAmount ();
|
||||
|
||||
if (healthAmount < maxHealthAmount || powerAmount < maxPowerAmount) {
|
||||
//if they are not fulled, enable the button trigger
|
||||
fullyHealed = false;
|
||||
|
||||
buttonCollider.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (mainAnimation != null) {
|
||||
//if the player is full of energy and health, and the animation in the station is not being playing, then disable the station and play the disable animation
|
||||
if (playingAnimationForward && !mainAnimation.IsPlaying (animationName) && fullyHealed) {
|
||||
playingAnimationForward = false;
|
||||
|
||||
mainAnimation [animationName].speed = -1;
|
||||
mainAnimation [animationName].time = mainAnimation [animationName].length;
|
||||
mainAnimation.Play (animationName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//this function is called when the button is pressed
|
||||
public void healPlayer ()
|
||||
{
|
||||
//check if the player is inside the station and his health or energy is not fulled
|
||||
if (inside && !fullyHealed) {
|
||||
//start to heal him
|
||||
healing = true;
|
||||
playingAnimationForward = true;
|
||||
|
||||
//play the station animation and the heal sound
|
||||
mainAnimation [animationName].speed = 1;
|
||||
mainAnimation.Play (animationName);
|
||||
|
||||
AudioPlayer.Play (soundAudioElement, gameObject);
|
||||
mainAudioSource.loop = true;
|
||||
|
||||
buttonCollider.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
//stop the station
|
||||
public void stopHealing ()
|
||||
{
|
||||
healing = false;
|
||||
fullyHealed = true;
|
||||
|
||||
mainAudioSource.loop = false;
|
||||
}
|
||||
|
||||
void OnTriggerEnter (Collider col)
|
||||
{
|
||||
//check if the player is inside the station
|
||||
if (col.gameObject.CompareTag ("Player")) {
|
||||
player = col.gameObject;
|
||||
|
||||
powerManager = player.GetComponent<otherPowers> ();
|
||||
currentHealth = player.GetComponent<health> ();
|
||||
|
||||
inside = true;
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit (Collider col)
|
||||
{
|
||||
//if the player exits from the station and he was being healing, stop the station
|
||||
if (col.gameObject.CompareTag ("Player")) {
|
||||
inside = false;
|
||||
|
||||
if (healing) {
|
||||
stopHealing ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f18a283c869e08439a42ab88ad91fae
|
||||
timeCreated: 1464657314
|
||||
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/Devices/rechargerStation.cs
|
||||
uploadId: 814740
|
||||
27
Assets/Game Kit Controller/Scripts/Devices/refractionCube.cs
Normal file
27
Assets/Game Kit Controller/Scripts/Devices/refractionCube.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class refractionCube : MonoBehaviour
|
||||
{
|
||||
public Color refractionCubeColor;
|
||||
public GameObject cubeLaserDeviceGameObject;
|
||||
public GameObject cubeLaserConnectorGameObject;
|
||||
public bool refractingLaser;
|
||||
|
||||
//set the color in the cube, so when the laser is reflected, the color is applied to the laser
|
||||
|
||||
void Start ()
|
||||
{
|
||||
GetComponent<Renderer> ().material.color = refractionCubeColor;
|
||||
}
|
||||
|
||||
public void setRefractingLaserState (bool state)
|
||||
{
|
||||
refractingLaser = state;
|
||||
}
|
||||
|
||||
public bool isRefracting ()
|
||||
{
|
||||
return refractingLaser;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54af38445469b2746859a914cf55a7f4
|
||||
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/Devices/refractionCube.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,75 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class rotatingPlatform : MonoBehaviour
|
||||
{
|
||||
public bool rotationActive = true;
|
||||
public float rotationSpeed;
|
||||
public float rotationDelay;
|
||||
public float rotationAmount;
|
||||
|
||||
public Vector3 rotationAxis;
|
||||
|
||||
Coroutine rotationCoroutine;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (rotationActive) {
|
||||
rotatePlatform ();
|
||||
}
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void rotatePlatform ()
|
||||
{
|
||||
stopRotationCoroutine ();
|
||||
rotationCoroutine = StartCoroutine (rotatePlatformCoroutine ());
|
||||
}
|
||||
|
||||
public void stopRotationCoroutine ()
|
||||
{
|
||||
if (rotationCoroutine != null) {
|
||||
StopCoroutine (rotationCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator rotatePlatformCoroutine ()
|
||||
{
|
||||
Vector3 targetRotation = transform.eulerAngles + rotationAxis * rotationAmount;
|
||||
|
||||
Quaternion initialRotation = transform.rotation;
|
||||
|
||||
float t = 0.0f;
|
||||
while (t < rotationSpeed) {
|
||||
t += Time.deltaTime;
|
||||
transform.rotation = initialRotation * Quaternion.AngleAxis (t / rotationSpeed * rotationAmount, rotationAxis);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
transform.eulerAngles = targetRotation;
|
||||
|
||||
WaitForSeconds delay = new WaitForSeconds (rotationDelay);
|
||||
|
||||
yield return delay;
|
||||
|
||||
if (rotationActive) {
|
||||
|
||||
rotatePlatform ();
|
||||
}
|
||||
}
|
||||
|
||||
public void setRotationActiveState (bool state)
|
||||
{
|
||||
rotationActive = state;
|
||||
if (rotationActive) {
|
||||
rotatePlatform ();
|
||||
} else {
|
||||
stopRotationCoroutine ();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4f37cf26ab88c847bff7d989d3ffdec
|
||||
timeCreated: 1542587788
|
||||
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/Devices/rotatingPlatform.cs
|
||||
uploadId: 814740
|
||||
146
Assets/Game Kit Controller/Scripts/Devices/securityCamera.cs
Normal file
146
Assets/Game Kit Controller/Scripts/Devices/securityCamera.cs
Normal file
@@ -0,0 +1,146 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class securityCamera : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public float sensitivity;
|
||||
public Vector2 clampTiltY;
|
||||
public Vector2 clampTiltX;
|
||||
public Vector2 zoomLimit;
|
||||
|
||||
public bool activated;
|
||||
public float zoomSpeed;
|
||||
|
||||
public bool controlOverriden;
|
||||
public float inputRotationSpeed = 5;
|
||||
public float overrideRotationSpeed = 10;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public GameObject baseX;
|
||||
public GameObject baseY;
|
||||
|
||||
public overrideInputManager overrideInput;
|
||||
public Camera cam;
|
||||
|
||||
[HideInInspector] public Vector2 lookAngle;
|
||||
Vector2 axisValues;
|
||||
|
||||
float originalFov;
|
||||
|
||||
Vector2 currentLookAngle;
|
||||
float horizontalInput;
|
||||
float verticalInput;
|
||||
|
||||
Quaternion currentBaseXRotation;
|
||||
Quaternion currentBaseYRotation;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
//get the camera in the children, store the origianl fov and disable it
|
||||
if (cam == null) {
|
||||
cam = GetComponentInChildren<Camera> ();
|
||||
}
|
||||
|
||||
cam.enabled = false;
|
||||
|
||||
originalFov = cam.fieldOfView;
|
||||
|
||||
if (overrideInput == null) {
|
||||
overrideInput = GetComponent<overrideInputManager> ();
|
||||
}
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
//if the camera is being used
|
||||
if (activated) {
|
||||
//get the look angle value
|
||||
lookAngle.x += axisValues.x * sensitivity;
|
||||
lookAngle.y += axisValues.y * sensitivity;
|
||||
//clamp these values to limit the camera rotation
|
||||
lookAngle.y = Mathf.Clamp (lookAngle.y, -clampTiltX.x, clampTiltX.y);
|
||||
lookAngle.x = Mathf.Clamp (lookAngle.x, -clampTiltY.x, clampTiltY.y);
|
||||
//set every angle in the camera and the pivot
|
||||
baseX.transform.localRotation = Quaternion.Euler (-lookAngle.y, 0, 0);
|
||||
baseY.transform.localRotation = Quaternion.Euler (0, lookAngle.x, 0);
|
||||
}
|
||||
|
||||
if (controlOverriden) {
|
||||
axisValues = overrideInput.getCustomMovementAxis ();
|
||||
|
||||
axisValues += overrideInput.getCustomMouseAxis ();
|
||||
|
||||
horizontalInput = axisValues.x;
|
||||
verticalInput = axisValues.y;
|
||||
|
||||
currentLookAngle.x -= verticalInput * inputRotationSpeed;
|
||||
currentLookAngle.y += horizontalInput * inputRotationSpeed;
|
||||
|
||||
currentLookAngle.x = Mathf.Clamp (currentLookAngle.x, -clampTiltX.x, clampTiltX.y);
|
||||
currentLookAngle.y = Mathf.Clamp (currentLookAngle.y, -clampTiltY.x, clampTiltY.y);
|
||||
|
||||
currentBaseXRotation = Quaternion.Euler (currentLookAngle.x, 0, 0);
|
||||
currentBaseYRotation = Quaternion.Euler (0, currentLookAngle.y, 0);
|
||||
|
||||
baseX.transform.localRotation = Quaternion.Slerp (baseX.transform.localRotation, currentBaseXRotation, Time.deltaTime * overrideRotationSpeed);
|
||||
baseY.transform.localRotation = Quaternion.Slerp (baseY.transform.localRotation, currentBaseYRotation, Time.deltaTime * overrideRotationSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
//the camera is being rotated, so set the axis values
|
||||
public void getLookValue (Vector2 currentAxisValues)
|
||||
{
|
||||
axisValues = currentAxisValues;
|
||||
}
|
||||
|
||||
//the zoom is being used, so change the fov according to the type of zoom, in or out
|
||||
public void setZoom (int mult)
|
||||
{
|
||||
float zoomValue = cam.fieldOfView;
|
||||
zoomValue += Time.deltaTime * mult * zoomSpeed;
|
||||
zoomValue = Mathf.Clamp (zoomValue, zoomLimit.x, zoomLimit.y);
|
||||
cam.fieldOfView = zoomValue;
|
||||
}
|
||||
|
||||
//enable or disable the camera according to if the control is being using if a computer device
|
||||
public void changeCameraState (bool state)
|
||||
{
|
||||
activated = state;
|
||||
|
||||
if (cam != null) {
|
||||
cam.enabled = state;
|
||||
|
||||
if (!activated) {
|
||||
cam.fieldOfView = originalFov;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void startOverride ()
|
||||
{
|
||||
overrideControlState (true);
|
||||
}
|
||||
|
||||
public void stopOverride ()
|
||||
{
|
||||
overrideControlState (false);
|
||||
}
|
||||
|
||||
public void overrideControlState (bool state)
|
||||
{
|
||||
if (state) {
|
||||
currentLookAngle = new Vector2 (baseX.transform.localRotation.y, baseY.transform.localRotation.x);
|
||||
} else {
|
||||
currentLookAngle = Vector2.zero;
|
||||
axisValues = Vector2.zero;
|
||||
}
|
||||
|
||||
controlOverriden = state;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d02aed615bd9f24591fb54dc8242d61
|
||||
timeCreated: 1465519525
|
||||
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/Devices/securityCamera.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,322 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class securityCameraControl : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public LayerMask layer;
|
||||
public float dragDistance = 1;
|
||||
public bool controlEnabled;
|
||||
public Vector2 clampTiltX;
|
||||
public Vector2 clampTiltZ;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public GameObject securityCameraGameObject;
|
||||
public GameObject joystick;
|
||||
public Transform joystickAxisX;
|
||||
public Transform joystickAxisZ;
|
||||
public GameObject zoomOutButton;
|
||||
public GameObject zoomInButton;
|
||||
|
||||
public electronicDevice deviceManager;
|
||||
public securityCamera securityCameraManager;
|
||||
|
||||
Touch currentTouch;
|
||||
int i;
|
||||
bool touchPlatform;
|
||||
bool touching;
|
||||
RaycastHit hit;
|
||||
Vector2 currentAxisValue;
|
||||
Vector3 beginTouchPosition;
|
||||
|
||||
Vector2 lookAngle;
|
||||
bool zoomIn;
|
||||
bool zoomOut;
|
||||
Coroutine inCoroutine;
|
||||
Coroutine outCoroutine;
|
||||
Camera mainCamera;
|
||||
Vector2 currentTouchPosition;
|
||||
|
||||
playerComponentsManager mainPlayerComponentsManager;
|
||||
playerInputManager playerInput;
|
||||
usingDevicesSystem mainUsingDevicesSystem;
|
||||
playerController mainPlayerController;
|
||||
|
||||
GameObject currentPlayer;
|
||||
|
||||
bool securityCameraManagerLocated;
|
||||
|
||||
float lastTimeDeviceUsed;
|
||||
|
||||
|
||||
void Update ()
|
||||
{
|
||||
//if the security camera control is being used
|
||||
if (controlEnabled) {
|
||||
|
||||
//check for touch input from the mouse or the finger
|
||||
int touchCount = Input.touchCount;
|
||||
if (!touchPlatform) {
|
||||
touchCount++;
|
||||
}
|
||||
|
||||
for (i = 0; i < touchCount; i++) {
|
||||
if (!touchPlatform) {
|
||||
currentTouch = touchJoystick.convertMouseIntoFinger ();
|
||||
} else {
|
||||
currentTouch = Input.GetTouch (i);
|
||||
}
|
||||
|
||||
currentTouchPosition = currentTouch.position;
|
||||
|
||||
//in the touch begin phase
|
||||
if (currentTouch.phase == TouchPhase.Began && !touching) {
|
||||
//check with a ray
|
||||
Ray ray = mainCamera.ScreenPointToRay (currentTouchPosition);
|
||||
if (Physics.Raycast (ray, out hit, Mathf.Infinity, layer)) {
|
||||
//the pressed position is the joystick of the camera
|
||||
if (hit.collider.gameObject == joystick) {
|
||||
touching = true;
|
||||
//store the initial press position
|
||||
beginTouchPosition = new Vector3 (currentTouchPosition.x, currentTouchPosition.y, 0);
|
||||
}
|
||||
//the pressed position is the zoom in button
|
||||
if (hit.collider.gameObject == zoomInButton) {
|
||||
zoomIn = true;
|
||||
//move the button down
|
||||
checkButtonTranslation (true, zoomInButton, true);
|
||||
}
|
||||
//the pressed position is the zoom out button
|
||||
if (hit.collider.gameObject == zoomOutButton) {
|
||||
zoomOut = true;
|
||||
//move the button down
|
||||
checkButtonTranslation (false, zoomOutButton, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//the current touch press is being moved
|
||||
if ((currentTouch.phase == TouchPhase.Moved || currentTouch.phase == TouchPhase.Stationary) && touching) {
|
||||
//like in the joystick script, get the amount of movement between the inital press position and the current touch position
|
||||
Vector3 globalTouchPosition = new Vector3 (currentTouchPosition.x, currentTouchPosition.y, 0);
|
||||
Vector3 differenceVector = globalTouchPosition - beginTouchPosition;
|
||||
|
||||
if (differenceVector.sqrMagnitude > dragDistance * dragDistance) {
|
||||
differenceVector.Normalize ();
|
||||
}
|
||||
|
||||
//get the axis from the touch movement
|
||||
currentAxisValue = differenceVector;
|
||||
|
||||
rotateCamera (currentAxisValue);
|
||||
}
|
||||
|
||||
//if the touch ends, reset the rotation of the joystick, the current axis values and the zoom buttons positions
|
||||
if (currentTouch.phase == TouchPhase.Ended) {
|
||||
touching = false;
|
||||
currentAxisValue = Vector2.zero;
|
||||
lookAngle = Vector2.zero;
|
||||
|
||||
StartCoroutine (resetJoystick ());
|
||||
|
||||
if (zoomIn) {
|
||||
zoomIn = false;
|
||||
checkButtonTranslation (true, zoomInButton, false);
|
||||
}
|
||||
|
||||
if (zoomOut) {
|
||||
zoomOut = false;
|
||||
checkButtonTranslation (false, zoomOutButton, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!touching && playerInput) {
|
||||
bool canUseInputResult = true;
|
||||
|
||||
if (lastTimeDeviceUsed > 0) {
|
||||
if (Time.time > lastTimeDeviceUsed + 0.3f) {
|
||||
if (mainUsingDevicesSystem != null) {
|
||||
if (!mainUsingDevicesSystem.anyDeviceDetected ()) {
|
||||
canUseInputResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (mainPlayerController != null) {
|
||||
if (!mainPlayerController.isUsingDevice ()) {
|
||||
canUseInputResult = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (canUseInputResult) {
|
||||
currentAxisValue = playerInput.getPlayerMovementAxis ();
|
||||
|
||||
rotateCamera (currentAxisValue);
|
||||
}
|
||||
}
|
||||
|
||||
if (securityCameraManagerLocated) {
|
||||
//send the current axis value to the security camera to rotate it
|
||||
securityCameraManager.getLookValue (currentAxisValue);
|
||||
}
|
||||
}
|
||||
|
||||
if (securityCameraManagerLocated) {
|
||||
//set the zoom in the camera
|
||||
if (zoomIn) {
|
||||
securityCameraManager.setZoom (-1);
|
||||
}
|
||||
|
||||
if (zoomOut) {
|
||||
securityCameraManager.setZoom (1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void rotateCamera (Vector2 values)
|
||||
{
|
||||
if (securityCameraManagerLocated) {
|
||||
//rotate the camera joystick too
|
||||
lookAngle.x += values.x * securityCameraManager.sensitivity;
|
||||
lookAngle.y += values.y * securityCameraManager.sensitivity;
|
||||
}
|
||||
|
||||
//clamp these values to limit the joystick rotation
|
||||
lookAngle.y = Mathf.Clamp (lookAngle.y, -clampTiltX.x, clampTiltX.y);
|
||||
lookAngle.x = Mathf.Clamp (lookAngle.x, -clampTiltZ.x, clampTiltZ.y);
|
||||
|
||||
//apply the rotation to every component in the X and Z axis
|
||||
joystickAxisX.transform.localRotation = Quaternion.Euler (0, 0, -lookAngle.x);
|
||||
joystickAxisZ.transform.localRotation = Quaternion.Euler (lookAngle.y, 0, 0);
|
||||
}
|
||||
|
||||
//reset the joystick rotation
|
||||
IEnumerator resetJoystick ()
|
||||
{
|
||||
for (float t = 0; t < 1;) {
|
||||
t += Time.deltaTime * 3;
|
||||
|
||||
joystickAxisX.transform.localRotation = Quaternion.Slerp (joystickAxisX.transform.localRotation, Quaternion.identity, t);
|
||||
joystickAxisZ.transform.localRotation = Quaternion.Slerp (joystickAxisZ.transform.localRotation, Quaternion.identity, t);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void activateSecurityControl ()
|
||||
{
|
||||
setSecurityCameraControlState (true);
|
||||
}
|
||||
|
||||
public void deactivateSecurityCameraControl ()
|
||||
{
|
||||
setSecurityCameraControlState (false);
|
||||
}
|
||||
|
||||
public void setSecurityCameraControlState (bool state)
|
||||
{
|
||||
getMainComponents ();
|
||||
|
||||
touchPlatform = touchJoystick.checkTouchPlatform ();
|
||||
|
||||
controlEnabled = state;
|
||||
|
||||
if (controlEnabled) {
|
||||
currentPlayer = deviceManager.getCurrentPlayer ();
|
||||
|
||||
if (currentPlayer != null) {
|
||||
mainPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
mainCamera = mainPlayerComponentsManager.getPlayerCamera ().getMainCamera ();
|
||||
playerInput = mainPlayerComponentsManager.getPlayerInputManager ();
|
||||
|
||||
mainUsingDevicesSystem = mainPlayerComponentsManager.getUsingDevicesSystem ();
|
||||
|
||||
mainPlayerController = mainPlayerComponentsManager.getPlayerController ();
|
||||
}
|
||||
} else {
|
||||
if (gameObject.activeInHierarchy) {
|
||||
StartCoroutine (resetJoystick ());
|
||||
}
|
||||
}
|
||||
|
||||
lastTimeDeviceUsed = Time.time;
|
||||
|
||||
securityCameraManagerLocated = securityCameraManager != null;
|
||||
|
||||
if (securityCameraManagerLocated) {
|
||||
securityCameraManager.changeCameraState (controlEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
void getMainComponents ()
|
||||
{
|
||||
if (securityCameraManager == null && securityCameraGameObject != null) {
|
||||
//get the security camera component of the camera
|
||||
securityCamera currentSecurityCamera = securityCameraGameObject.GetComponent<securityCamera> ();
|
||||
|
||||
if (currentSecurityCamera != null) {
|
||||
securityCameraManager = currentSecurityCamera;
|
||||
}
|
||||
}
|
||||
|
||||
securityCameraManagerLocated = securityCameraManager != null;
|
||||
}
|
||||
|
||||
//if this control is enabled, enable the camera component too
|
||||
void OnEnable ()
|
||||
{
|
||||
setSecurityCameraControlState (true);
|
||||
}
|
||||
|
||||
//else, this control is disabled, so disable the camera component too
|
||||
void OnDisable ()
|
||||
{
|
||||
setSecurityCameraControlState (false);
|
||||
}
|
||||
|
||||
//if a zoom button is pressed, check the coroutine, stop it and play it again
|
||||
void checkButtonTranslation (bool state, GameObject button, bool value)
|
||||
{
|
||||
if (state) {
|
||||
if (inCoroutine != null) {
|
||||
StopCoroutine (inCoroutine);
|
||||
}
|
||||
|
||||
inCoroutine = StartCoroutine (pressButton (button, value));
|
||||
} else {
|
||||
if (outCoroutine != null) {
|
||||
StopCoroutine (outCoroutine);
|
||||
}
|
||||
|
||||
outCoroutine = StartCoroutine (pressButton (button, value));
|
||||
}
|
||||
}
|
||||
|
||||
//move the zoom buttons up and down when they are pressed, instead of using animations
|
||||
IEnumerator pressButton (GameObject button, bool value)
|
||||
{
|
||||
int mult = 1;
|
||||
|
||||
if (value) {
|
||||
mult = -1;
|
||||
}
|
||||
|
||||
Vector3 buttonPos = button.transform.localPosition;
|
||||
Vector3 newButtonPos = button.transform.localPosition + Vector3.up * (mult * 0.03f);
|
||||
|
||||
for (float t = 0; t < 1;) {
|
||||
t += Time.deltaTime * 3;
|
||||
|
||||
button.transform.localPosition = Vector3.MoveTowards (buttonPos, newButtonPos, t);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c6b4b26fe1b21346a9b5ba5197c251e
|
||||
timeCreated: 1465521254
|
||||
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/Devices/securityCameraControl.cs
|
||||
uploadId: 814740
|
||||
204
Assets/Game Kit Controller/Scripts/Devices/simpleSwitch.cs
Normal file
204
Assets/Game Kit Controller/Scripts/Devices/simpleSwitch.cs
Normal file
@@ -0,0 +1,204 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using GameKitController.Audio;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class simpleSwitch : MonoBehaviour
|
||||
{
|
||||
public bool buttonEnabled = true;
|
||||
|
||||
public AudioClip pressSound;
|
||||
public AudioElement pressAudioElement;
|
||||
public bool sendCurrentUser;
|
||||
public bool notUsableWhileAnimationIsPlaying = true;
|
||||
public bool useSingleSwitch = true;
|
||||
|
||||
public bool buttonUsesAnimation = true;
|
||||
public string switchAnimationName = "simpleSwitch";
|
||||
|
||||
public float animationSpeed = 1;
|
||||
|
||||
public bool useUnityEvents = true;
|
||||
public UnityEvent objectToCallFunctions = new UnityEvent ();
|
||||
|
||||
public UnityEvent turnOnEvent = new UnityEvent ();
|
||||
public UnityEvent turnOffEvent = new UnityEvent ();
|
||||
|
||||
public GameObject objectToActive;
|
||||
public string activeFunctionName;
|
||||
public bool sendThisButton;
|
||||
|
||||
public bool switchTurnedOn;
|
||||
|
||||
public AudioSource audioSource;
|
||||
public Animation buttonAnimation;
|
||||
public deviceStringAction deviceStringActionManager;
|
||||
|
||||
GameObject currentPlayer;
|
||||
|
||||
private void InitializeAudioElements ()
|
||||
{
|
||||
if (audioSource == null) {
|
||||
audioSource = GetComponent<AudioSource> ();
|
||||
}
|
||||
|
||||
if (pressSound != null) {
|
||||
pressAudioElement.clip = pressSound;
|
||||
}
|
||||
|
||||
if (audioSource != null) {
|
||||
pressAudioElement.audioSource = audioSource;
|
||||
}
|
||||
}
|
||||
|
||||
void Start ()
|
||||
{
|
||||
InitializeAudioElements ();
|
||||
|
||||
if (buttonAnimation == null) {
|
||||
if (buttonUsesAnimation && switchAnimationName != "") {
|
||||
buttonAnimation = GetComponent<Animation> ();
|
||||
}
|
||||
}
|
||||
|
||||
if (deviceStringActionManager == null) {
|
||||
deviceStringActionManager = GetComponent<deviceStringAction> ();
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentPlayer (GameObject newPlayer)
|
||||
{
|
||||
currentPlayer = newPlayer;
|
||||
}
|
||||
|
||||
public void setCurrentUser (GameObject newPlayer)
|
||||
{
|
||||
currentPlayer = newPlayer;
|
||||
}
|
||||
|
||||
public void turnSwitchOff ()
|
||||
{
|
||||
if (switchTurnedOn) {
|
||||
activateDevice ();
|
||||
}
|
||||
}
|
||||
|
||||
public void turnSwitchOn ()
|
||||
{
|
||||
if (!switchTurnedOn) {
|
||||
activateDevice ();
|
||||
}
|
||||
}
|
||||
|
||||
public void activateDevice ()
|
||||
{
|
||||
if (!buttonEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool canUseButton = false;
|
||||
|
||||
if (buttonUsesAnimation) {
|
||||
if (buttonAnimation != null) {
|
||||
if ((!buttonAnimation.IsPlaying (switchAnimationName) && notUsableWhileAnimationIsPlaying)
|
||||
|| !notUsableWhileAnimationIsPlaying) {
|
||||
canUseButton = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
canUseButton = true;
|
||||
}
|
||||
|
||||
//check if the player is inside the trigger, and if he press the button to activate the devide
|
||||
if (canUseButton) {
|
||||
if (useSingleSwitch) {
|
||||
playSingleAnimation ();
|
||||
} else {
|
||||
switchTurnedOn = !switchTurnedOn;
|
||||
|
||||
playDualAnimation (switchTurnedOn);
|
||||
|
||||
setDeviceStringActionState (switchTurnedOn);
|
||||
}
|
||||
|
||||
if (sendCurrentUser && currentPlayer != null) {
|
||||
objectToActive.SendMessage ("setCurrentUser", currentPlayer, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
if (useUnityEvents) {
|
||||
if (useSingleSwitch) {
|
||||
objectToCallFunctions.Invoke ();
|
||||
} else {
|
||||
if (switchTurnedOn) {
|
||||
turnOnEvent.Invoke ();
|
||||
} else {
|
||||
turnOffEvent.Invoke ();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (objectToActive) {
|
||||
if (sendThisButton) {
|
||||
objectToActive.SendMessage (activeFunctionName, gameObject, SendMessageOptions.DontRequireReceiver);
|
||||
} else {
|
||||
objectToActive.SendMessage (activeFunctionName, SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setButtonEnabledState (bool state)
|
||||
{
|
||||
buttonEnabled = state;
|
||||
}
|
||||
|
||||
public void triggerButtonEventFromEditor ()
|
||||
{
|
||||
activateDevice ();
|
||||
}
|
||||
|
||||
public void playSingleAnimation ()
|
||||
{
|
||||
if (buttonUsesAnimation) {
|
||||
buttonAnimation [switchAnimationName].speed = animationSpeed;
|
||||
buttonAnimation.Play (switchAnimationName);
|
||||
}
|
||||
|
||||
if (pressAudioElement != null) {
|
||||
AudioPlayer.PlayOneShot (pressAudioElement, gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void playDualAnimation (bool playForward)
|
||||
{
|
||||
if (buttonUsesAnimation) {
|
||||
if (playForward) {
|
||||
|
||||
buttonAnimation [switchAnimationName].speed = animationSpeed;
|
||||
} else {
|
||||
|
||||
buttonAnimation [switchAnimationName].speed = -animationSpeed;
|
||||
|
||||
buttonAnimation [switchAnimationName].time = buttonAnimation [switchAnimationName].length;
|
||||
|
||||
}
|
||||
|
||||
if (!buttonAnimation.IsPlaying (switchAnimationName)) {
|
||||
buttonAnimation.Play (switchAnimationName);
|
||||
} else {
|
||||
buttonAnimation.CrossFade (switchAnimationName);
|
||||
}
|
||||
}
|
||||
|
||||
if (pressAudioElement != null) {
|
||||
AudioPlayer.PlayOneShot (pressAudioElement, gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDeviceStringActionState (bool state)
|
||||
{
|
||||
if (deviceStringActionManager != null) {
|
||||
deviceStringActionManager.changeActionName (state);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c22e01c2beea51d44b1fbdf441f37fda
|
||||
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/Devices/simpleSwitch.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,240 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class teleportationPlatform : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool teleportEnabled = true;
|
||||
public Transform platformToMove;
|
||||
public LayerMask layermask;
|
||||
|
||||
public bool useButtonToActivate;
|
||||
|
||||
[Space]
|
||||
[Header ("Check Layer Settings")]
|
||||
[Space]
|
||||
|
||||
public bool checkObjectLayerToTeleport;
|
||||
public LayerMask objectLayerToTeleport;
|
||||
|
||||
public bool ignoreVehiclesToTeleport;
|
||||
|
||||
public float vehicleRadiusMultiplier = 0.5f;
|
||||
|
||||
[Space]
|
||||
[Header ("Rotation Settings")]
|
||||
[Space]
|
||||
|
||||
public bool setObjectRotation;
|
||||
public bool setFullObjectRotation;
|
||||
|
||||
public bool adjustPlayerCameraRotationIfPlayerTeleported;
|
||||
|
||||
public Transform objectRotationTransform;
|
||||
|
||||
[Space]
|
||||
[Header ("Gravity Settings")]
|
||||
[Space]
|
||||
|
||||
public bool setGravityDirection;
|
||||
|
||||
public setGravity setGravityManager;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public GameObject objectInside;
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool callEventOnTeleport;
|
||||
public UnityEvent eventOnTeleport;
|
||||
public bool callEventOnEveryTeleport;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public teleportationPlatform platformToMoveManager;
|
||||
|
||||
bool platformToMoveManagerLocated;
|
||||
|
||||
bool eventCalled;
|
||||
|
||||
RaycastHit hit;
|
||||
grabbedObjectState currentGrabbedObject;
|
||||
|
||||
|
||||
void OnTriggerEnter (Collider col)
|
||||
{
|
||||
if (!teleportEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (objectInside != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject currentObject = col.gameObject;
|
||||
|
||||
if (checkObjectLayerToTeleport) {
|
||||
if ((1 << currentObject.layer & objectLayerToTeleport.value) != 1 << currentObject.layer) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (ignoreVehiclesToTeleport) {
|
||||
if (applyDamage.isVehicle (currentObject)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
GameObject objectToTeleport = applyDamage.getCharacterOrVehicle (currentObject);
|
||||
|
||||
if (objectToTeleport != null) {
|
||||
currentObject = objectToTeleport;
|
||||
}
|
||||
|
||||
Rigidbody currentRigidbody = currentObject.GetComponent<Rigidbody> ();
|
||||
|
||||
if (currentRigidbody == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (currentObject == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
objectInside = currentObject;
|
||||
|
||||
//if the object is being carried by the player, make him drop it
|
||||
currentGrabbedObject = objectInside.GetComponent<grabbedObjectState> ();
|
||||
|
||||
if (currentGrabbedObject != null) {
|
||||
if (currentGrabbedObject.isCarryingObjectPhysically ()) {
|
||||
objectInside = null;
|
||||
|
||||
return;
|
||||
} else {
|
||||
GKC_Utils.dropObject (currentGrabbedObject.getCurrentHolder (), objectInside);
|
||||
}
|
||||
}
|
||||
|
||||
if (!useButtonToActivate) {
|
||||
activateTeleport ();
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit (Collider col)
|
||||
{
|
||||
if (objectInside != null && col.gameObject == objectInside) {
|
||||
objectInside = null;
|
||||
currentGrabbedObject = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeObjectInside ()
|
||||
{
|
||||
objectInside = null;
|
||||
}
|
||||
|
||||
void activateDevice ()
|
||||
{
|
||||
if (!teleportEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (useButtonToActivate && objectInside != null) {
|
||||
activateTeleport ();
|
||||
}
|
||||
}
|
||||
|
||||
public void activateTeleport ()
|
||||
{
|
||||
if (!platformToMoveManagerLocated) {
|
||||
if (platformToMove != null) {
|
||||
platformToMoveManager = platformToMove.GetComponent<teleportationPlatform> ();
|
||||
}
|
||||
|
||||
platformToMoveManagerLocated = platformToMoveManager != null;
|
||||
}
|
||||
|
||||
if (platformToMoveManagerLocated) {
|
||||
platformToMoveManager.sendObject (objectInside);
|
||||
|
||||
removeObjectInside ();
|
||||
|
||||
if (callEventOnTeleport) {
|
||||
if (!eventCalled || callEventOnEveryTeleport) {
|
||||
eventOnTeleport.Invoke ();
|
||||
eventCalled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sendObject (GameObject objectToMove)
|
||||
{
|
||||
Vector3 targetPosition = transform.position + transform.up * 0.3f;
|
||||
|
||||
if (Physics.Raycast (transform.position + transform.up * 2, -transform.up, out hit, Mathf.Infinity, layermask)) {
|
||||
targetPosition = hit.point;
|
||||
|
||||
objectInside = objectToMove;
|
||||
}
|
||||
|
||||
bool objectIsVehicle = applyDamage.isVehicle (objectToMove);
|
||||
|
||||
if (objectIsVehicle) {
|
||||
float vehicleRadius = applyDamage.getVehicleRadius (objectToMove);
|
||||
|
||||
if (vehicleRadius != -1) {
|
||||
targetPosition += objectToMove.transform.up * vehicleRadius * vehicleRadiusMultiplier;
|
||||
}
|
||||
}
|
||||
|
||||
objectToMove.transform.position = targetPosition;
|
||||
|
||||
if (setObjectRotation) {
|
||||
if (setFullObjectRotation) {
|
||||
objectToMove.transform.rotation = objectRotationTransform.rotation;
|
||||
} else {
|
||||
float rotationAngle = Vector3.SignedAngle (objectToMove.transform.forward, objectRotationTransform.forward, objectToMove.transform.up);
|
||||
|
||||
objectToMove.transform.Rotate (objectToMove.transform.up * rotationAngle);
|
||||
}
|
||||
|
||||
bool objectIsCharacter = applyDamage.isCharacter (objectToMove);
|
||||
|
||||
if (objectIsCharacter) {
|
||||
if (adjustPlayerCameraRotationIfPlayerTeleported) {
|
||||
playerController currentPlayerController = objectToMove.GetComponent<playerController> ();
|
||||
|
||||
if (currentPlayerController != null) {
|
||||
currentPlayerController.getPlayerCameraGameObject ().transform.rotation = objectToMove.transform.rotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (setGravityDirection && setGravityManager != null) {
|
||||
Collider currentCollider = objectToMove.GetComponent<Collider> ();
|
||||
|
||||
if (currentCollider != null) {
|
||||
setGravityManager.checkTriggerType (currentCollider, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setTeleportEnabledState (bool state)
|
||||
{
|
||||
teleportEnabled = state;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b053707fff82fce4a95680f5a5e0fb5b
|
||||
timeCreated: 1474126274
|
||||
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/Devices/teleportationPlatform.cs
|
||||
uploadId: 814740
|
||||
111
Assets/Game Kit Controller/Scripts/Devices/vendingMachine.cs
Normal file
111
Assets/Game Kit Controller/Scripts/Devices/vendingMachine.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class vendingMachine : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool vendingMachineEnabled = true;
|
||||
|
||||
public float radiusToSpawn;
|
||||
|
||||
public bool useSpawnLimitAmount;
|
||||
public int spawnLimitAmount;
|
||||
|
||||
[Space]
|
||||
[Header ("Object To Spawn Settings")]
|
||||
[Space]
|
||||
|
||||
public GameObject objectToSpawn;
|
||||
public Transform spawnPosition;
|
||||
|
||||
public bool spawnObjectList;
|
||||
public List<GameObject> objectListToSpawn = new List<GameObject> ();
|
||||
|
||||
[Header ("Gizmo Settings")]
|
||||
[Space]
|
||||
|
||||
public bool showGizmo;
|
||||
|
||||
int currentSpawnAmount;
|
||||
|
||||
|
||||
public void setVendingMachineEnabledState (bool state)
|
||||
{
|
||||
vendingMachineEnabled = state;
|
||||
}
|
||||
|
||||
//simple script to spawn vehicles in the scene, or other objects
|
||||
public void getObject ()
|
||||
{
|
||||
if (spawnObjectList) {
|
||||
for (int i = 0; i < objectListToSpawn.Count; i++) {
|
||||
spawnObject (objectListToSpawn [i]);
|
||||
}
|
||||
|
||||
} else {
|
||||
spawnObject (objectToSpawn);
|
||||
}
|
||||
}
|
||||
|
||||
public void spawnObject (GameObject newObject)
|
||||
{
|
||||
if (!vendingMachineEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (newObject == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (useSpawnLimitAmount) {
|
||||
currentSpawnAmount++;
|
||||
|
||||
if (currentSpawnAmount >= spawnLimitAmount) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 positionToSpawn = spawnPosition.position;
|
||||
|
||||
if (radiusToSpawn > 0) {
|
||||
Vector2 circlePosition = Random.insideUnitCircle * radiusToSpawn;
|
||||
Vector3 newSpawnPosition = new Vector3 (circlePosition.x, 0, circlePosition.y);
|
||||
positionToSpawn += newSpawnPosition;
|
||||
}
|
||||
|
||||
GameObject objectToSpawnClone = (GameObject)Instantiate (newObject, positionToSpawn, spawnPosition.rotation);
|
||||
|
||||
objectToSpawnClone.name = objectToSpawn.name;
|
||||
|
||||
if (!objectToSpawnClone.activeSelf) {
|
||||
objectToSpawnClone.SetActive (true);
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmos ()
|
||||
{
|
||||
if (!showGizmo) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
|
||||
DrawGizmos ();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected ()
|
||||
{
|
||||
DrawGizmos ();
|
||||
}
|
||||
|
||||
void DrawGizmos ()
|
||||
{
|
||||
if (showGizmo) {
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawWireSphere (spawnPosition.position, radiusToSpawn);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab7fbb1d4b6593f45abf82cca85cb35a
|
||||
timeCreated: 1464828068
|
||||
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/Devices/vendingMachine.cs
|
||||
uploadId: 814740
|
||||
566
Assets/Game Kit Controller/Scripts/Devices/waypointPlatform.cs
Normal file
566
Assets/Game Kit Controller/Scripts/Devices/waypointPlatform.cs
Normal file
@@ -0,0 +1,566 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class waypointPlatform : MonoBehaviour
|
||||
{
|
||||
public bool platformActive = true;
|
||||
public Transform platformTransform;
|
||||
public List<Transform> wayPoints = new List<Transform> ();
|
||||
public Transform waypointsParent;
|
||||
public bool repeatWaypoints;
|
||||
public bool moveInCircles;
|
||||
public bool stopIfPlayerOutside;
|
||||
public float waitTimeBetweenPoints;
|
||||
public float movementSpeed;
|
||||
public bool movingForward = true;
|
||||
|
||||
public string playerTag = "Player";
|
||||
public string vehicleTag = "vehicle";
|
||||
|
||||
public bool useJustToMovePlatform;
|
||||
|
||||
public bool showGizmo;
|
||||
public Color gizmoLabelColor = Color.black;
|
||||
public float gizmoRadius;
|
||||
public bool useHandleForVertex;
|
||||
public float handleRadius;
|
||||
public Color handleGizmoColor;
|
||||
|
||||
public bool showVertexHandles;
|
||||
|
||||
public List<string> tagToCheckToMove = new List<string> ();
|
||||
|
||||
public List<string> tagToCheckBelow = new List<string> ();
|
||||
|
||||
public List<GameObject> objectsDetectedBelowList = new List<GameObject> ();
|
||||
|
||||
public bool mirrorPlatformMovement;
|
||||
public Vector3 mirrorMovementDirection = Vector3.one;
|
||||
public waypointPlatform platformToMirror;
|
||||
|
||||
public bool useEventOnWaypointReached;
|
||||
public List<eventOnWaypointInfo> eventOnWaypointReachedList = new List<eventOnWaypointInfo> ();
|
||||
|
||||
public List<passengersInfo> passengersInfoList = new List<passengersInfo> ();
|
||||
|
||||
public List<vehiclesInfo> vehiclesInfoList = new List<vehiclesInfo> ();
|
||||
|
||||
public deviceStringAction deviceStringActionManager;
|
||||
|
||||
List<Transform> forwardPath = new List<Transform> ();
|
||||
List<Transform> inversePath = new List<Transform> ();
|
||||
List<Transform> currentPath = new List<Transform> ();
|
||||
Coroutine movement;
|
||||
Transform currentWaypoint;
|
||||
int currentPlatformIndex;
|
||||
int i;
|
||||
|
||||
bool activateMovementForward;
|
||||
|
||||
Vector3 currentPlatformPosition;
|
||||
bool mirroringPlatformActive;
|
||||
|
||||
bool settingPositionOnMirrorPlatflorm;
|
||||
public float distanceToMirror;
|
||||
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (platformTransform == null) {
|
||||
platformTransform = transform;
|
||||
}
|
||||
|
||||
forwardPath = new List<Transform> (wayPoints);
|
||||
inversePath = new List<Transform> (wayPoints);
|
||||
|
||||
inversePath.Reverse ();
|
||||
|
||||
if (!stopIfPlayerOutside && !useJustToMovePlatform && platformActive) {
|
||||
checkMovementCoroutine (true);
|
||||
}
|
||||
|
||||
if (deviceStringActionManager == null) {
|
||||
deviceStringActionManager = GetComponent<deviceStringAction> ();
|
||||
}
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (mirroringPlatformActive) {
|
||||
platformTransform.position = currentPlatformPosition +
|
||||
new Vector3 (platformToMirror.distanceToMirror * mirrorMovementDirection.x,
|
||||
platformToMirror.distanceToMirror * mirrorMovementDirection.y,
|
||||
platformToMirror.distanceToMirror * mirrorMovementDirection.z);
|
||||
}
|
||||
|
||||
if (settingPositionOnMirrorPlatflorm) {
|
||||
distanceToMirror = GKC_Utils.distance (currentPlatformPosition, platformTransform.position);
|
||||
}
|
||||
}
|
||||
|
||||
public void setMirroringPlatformActiveState (bool state)
|
||||
{
|
||||
if (!mirrorPlatformMovement) {
|
||||
return;
|
||||
}
|
||||
|
||||
mirroringPlatformActive = state;
|
||||
|
||||
if (platformTransform != null) {
|
||||
currentPlatformPosition = platformTransform.position;
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerEnter (Collider col)
|
||||
{
|
||||
if (useJustToMovePlatform) {
|
||||
return;
|
||||
}
|
||||
|
||||
//if the player enters inside the platform trigger, then
|
||||
if (col.gameObject.CompareTag (playerTag)) {
|
||||
//store him
|
||||
addPassenger (col.gameObject.transform);
|
||||
|
||||
//if he is not driving, then attach the player and the camera inside the platform
|
||||
setPlayerParent (platformTransform, col.gameObject.transform);
|
||||
|
||||
//if the platform stops when the player exits from it, then restart its movement
|
||||
if (stopIfPlayerOutside) {
|
||||
checkMovementCoroutine (true);
|
||||
}
|
||||
|
||||
} else if (col.gameObject.CompareTag (vehicleTag)) {
|
||||
//store him
|
||||
addVehicle (col.gameObject.transform);
|
||||
|
||||
//if he is not driving, then attach the player and the camera inside the platform
|
||||
setVehicleParent (platformTransform, col.gameObject.transform);
|
||||
|
||||
} else if (tagToCheckToMove.Contains (col.gameObject.tag)) {
|
||||
col.gameObject.transform.SetParent (platformTransform);
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit (Collider col)
|
||||
{
|
||||
if (useJustToMovePlatform) {
|
||||
return;
|
||||
}
|
||||
|
||||
//if the player exits, then disattach the player
|
||||
if (col.gameObject.CompareTag (playerTag)) {
|
||||
setPlayerParent (null, col.gameObject.transform);
|
||||
|
||||
removePassenger (col.gameObject.transform);
|
||||
|
||||
//if the platform stops when the player exits from it, stop the platform
|
||||
if (stopIfPlayerOutside) {
|
||||
checkMovementCoroutine (false);
|
||||
}
|
||||
} else if (col.gameObject.CompareTag (vehicleTag)) {
|
||||
setVehicleParent (null, col.gameObject.transform);
|
||||
|
||||
removeVehicle (col.gameObject.transform);
|
||||
|
||||
} else if (tagToCheckToMove.Contains (col.gameObject.tag)) {
|
||||
col.gameObject.transform.SetParent (null);
|
||||
}
|
||||
}
|
||||
|
||||
//attach and disattch the player and the camera inside the elevator
|
||||
void setPlayerParent (Transform father, Transform newPassenger)
|
||||
{
|
||||
bool passengerFound = false;
|
||||
passengersInfo newPassengersInfo = new passengersInfo ();
|
||||
|
||||
for (i = 0; i < passengersInfoList.Count; i++) {
|
||||
if (passengersInfoList [i].playerTransform == newPassenger && !passengerFound) {
|
||||
newPassengersInfo = passengersInfoList [i];
|
||||
passengerFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (passengerFound) {
|
||||
newPassengersInfo.playerControllerManager.setPlayerAndCameraAndFBAPivotTransformParent (father);
|
||||
|
||||
newPassengersInfo.playerControllerManager.setMovingOnPlatformActiveState (father != null);
|
||||
}
|
||||
}
|
||||
|
||||
void setAllPlayersParent (Transform father)
|
||||
{
|
||||
for (i = 0; i < passengersInfoList.Count; i++) {
|
||||
passengersInfoList [i].playerControllerManager.setPlayerAndCameraAndFBAPivotTransformParent (father);
|
||||
|
||||
passengersInfoList [i].playerControllerManager.setMovingOnPlatformActiveState (father != null);
|
||||
}
|
||||
}
|
||||
|
||||
public void addPassenger (Transform newPassenger)
|
||||
{
|
||||
bool passengerFound = false;
|
||||
for (i = 0; i < passengersInfoList.Count; i++) {
|
||||
if (passengersInfoList [i].playerTransform == newPassenger && !passengerFound) {
|
||||
passengerFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!passengerFound) {
|
||||
passengersInfo newPassengersInfo = new passengersInfo ();
|
||||
newPassengersInfo.playerTransform = newPassenger;
|
||||
newPassengersInfo.playerControllerManager = newPassenger.GetComponent<playerController> ();
|
||||
passengersInfoList.Add (newPassengersInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void removePassenger (Transform newPassenger)
|
||||
{
|
||||
for (i = 0; i < passengersInfoList.Count; i++) {
|
||||
if (passengersInfoList [i].playerTransform == newPassenger) {
|
||||
passengersInfoList.RemoveAt (i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setVehicleParent (Transform father, Transform newVehicle)
|
||||
{
|
||||
bool vehicleFound = false;
|
||||
|
||||
vehiclesInfo newVehiclesInfo = new vehiclesInfo ();
|
||||
|
||||
for (i = 0; i < vehiclesInfoList.Count; i++) {
|
||||
if (vehiclesInfoList [i].vehicleTransform == newVehicle && !vehicleFound) {
|
||||
newVehiclesInfo = vehiclesInfoList [i];
|
||||
vehicleFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (vehicleFound) {
|
||||
newVehiclesInfo.HUDManager.setVehicleAndCameraParent (father);
|
||||
}
|
||||
}
|
||||
|
||||
void setAllVehiclesParent (Transform father)
|
||||
{
|
||||
for (i = 0; i < vehiclesInfoList.Count; i++) {
|
||||
vehiclesInfoList [i].HUDManager.setVehicleAndCameraParent (father);
|
||||
}
|
||||
}
|
||||
|
||||
public void addVehicle (Transform newVehicle)
|
||||
{
|
||||
bool vehicleFound = false;
|
||||
for (i = 0; i < vehiclesInfoList.Count; i++) {
|
||||
if (vehiclesInfoList [i].vehicleTransform == newVehicle && !vehicleFound) {
|
||||
vehicleFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!vehicleFound) {
|
||||
vehiclesInfo newVehiclesInfo = new vehiclesInfo ();
|
||||
newVehiclesInfo.vehicleTransform = newVehicle;
|
||||
|
||||
newVehiclesInfo.HUDManager = newVehicle.GetComponent<vehicleHUDManager> ();
|
||||
|
||||
vehiclesInfoList.Add (newVehiclesInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void removeVehicle (Transform newVehicle)
|
||||
{
|
||||
for (i = 0; i < vehiclesInfoList.Count; i++) {
|
||||
if (vehiclesInfoList [i].vehicleTransform == newVehicle) {
|
||||
vehiclesInfoList.RemoveAt (i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void disablePlatform ()
|
||||
{
|
||||
stopPlatformMovement ();
|
||||
|
||||
platformActive = false;
|
||||
|
||||
setAllPlayersParent (null);
|
||||
|
||||
setAllVehiclesParent (null);
|
||||
|
||||
GetComponent<Collider> ().enabled = false;
|
||||
|
||||
this.enabled = false;
|
||||
}
|
||||
|
||||
public void activatePlatformMovement ()
|
||||
{
|
||||
if (currentPath.Count == 0) {
|
||||
for (i = currentPlatformIndex; i < forwardPath.Count; i++) {
|
||||
currentPath.Add (forwardPath [i]);
|
||||
}
|
||||
}
|
||||
|
||||
checkMovementCoroutine (true);
|
||||
}
|
||||
|
||||
public void deactivatePlatformMovement ()
|
||||
{
|
||||
checkMovementCoroutine (false);
|
||||
}
|
||||
|
||||
//stop the platform coroutine movement and play again
|
||||
public void checkMovementCoroutine (bool play)
|
||||
{
|
||||
stopPlatformMovement ();
|
||||
|
||||
if (!platformActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mirrorPlatformMovement) {
|
||||
platformToMirror.setMirroringPlatformActiveState (play);
|
||||
settingPositionOnMirrorPlatflorm = play;
|
||||
currentPlatformPosition = transform.position;
|
||||
}
|
||||
|
||||
if (play) {
|
||||
movement = StartCoroutine (moveThroughWayPoints ());
|
||||
}
|
||||
}
|
||||
|
||||
public void stopPlatformMovement ()
|
||||
{
|
||||
if (movement != null) {
|
||||
StopCoroutine (movement);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator moveThroughWayPoints ()
|
||||
{
|
||||
if (!useJustToMovePlatform) {
|
||||
currentPath.Clear ();
|
||||
|
||||
//if the platform moves from waypoint to waypoint and it starts again, then
|
||||
if (moveInCircles) {
|
||||
//from the current waypoint to the last of them, add these waypoints
|
||||
for (i = currentPlatformIndex; i < forwardPath.Count; i++) {
|
||||
currentPath.Add (forwardPath [i]);
|
||||
}
|
||||
} else {
|
||||
//else, if only moves from the first waypoint to the last and then stop, then
|
||||
//if the platform moves between waypoins in the order list
|
||||
if (movingForward) {
|
||||
//from the current waypoint to the last of them, add these waypoints
|
||||
for (i = currentPlatformIndex; i < forwardPath.Count; i++) {
|
||||
currentPath.Add (forwardPath [i]);
|
||||
}
|
||||
} else {
|
||||
//from the current waypoint to the first of them, add these waypoints, making the reverse path
|
||||
for (i = currentPlatformIndex; i < inversePath.Count; i++) {
|
||||
currentPath.Add (inversePath [i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if the current path to move has waypoints, then
|
||||
if (currentPath.Count > 0) {
|
||||
//move between every waypoint
|
||||
foreach (Transform point in currentPath) {
|
||||
//wait the amount of time configured
|
||||
WaitForSeconds delay = new WaitForSeconds (waitTimeBetweenPoints);
|
||||
|
||||
yield return delay;
|
||||
|
||||
Vector3 pos = point.position;
|
||||
Quaternion rot = point.rotation;
|
||||
|
||||
currentWaypoint = point;
|
||||
|
||||
//while the platform moves from the previous waypoint to the next, then displace it
|
||||
while (GKC_Utils.distance (platformTransform.position, pos) > .01f) {
|
||||
platformTransform.position = Vector3.MoveTowards (platformTransform.position, pos, Time.deltaTime * movementSpeed);
|
||||
platformTransform.rotation = Quaternion.Slerp (platformTransform.rotation, rot, Time.deltaTime * movementSpeed);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
//when the platform reaches the next waypoint
|
||||
currentPlatformIndex++;
|
||||
|
||||
int currentIndex = currentPlatformIndex;
|
||||
|
||||
if (currentPlatformIndex > wayPoints.Count - 1) {
|
||||
currentPlatformIndex = 0;
|
||||
movingForward = !movingForward;
|
||||
}
|
||||
|
||||
if (useEventOnWaypointReached) {
|
||||
for (i = 0; i < eventOnWaypointReachedList.Count; i++) {
|
||||
if (currentIndex == (eventOnWaypointReachedList [i].waypointToReach)) {
|
||||
eventOnWaypointReachedList [i].eventOnWaypoint.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if the platform moves in every moment, then repeat the path
|
||||
if (repeatWaypoints) {
|
||||
checkMovementCoroutine (true);
|
||||
}
|
||||
} else {
|
||||
//else, stop the movement
|
||||
checkMovementCoroutine (false);
|
||||
}
|
||||
}
|
||||
|
||||
public void activetMovementByButton ()
|
||||
{
|
||||
activateMovementForward = !activateMovementForward;
|
||||
|
||||
currentPath.Clear ();
|
||||
|
||||
if (activateMovementForward) {
|
||||
//from the current waypoint to the last of them, add these waypoints
|
||||
for (i = currentPlatformIndex; i < forwardPath.Count; i++) {
|
||||
currentPath.Add (forwardPath [i]);
|
||||
}
|
||||
} else {
|
||||
//from the current waypoint to the first of them, add these waypoints, making the reverse path
|
||||
for (i = currentPlatformIndex; i < inversePath.Count; i++) {
|
||||
currentPath.Add (inversePath [i]);
|
||||
}
|
||||
}
|
||||
|
||||
setDeviceStringActionState (activateMovementForward);
|
||||
|
||||
checkMovementCoroutine (true);
|
||||
}
|
||||
|
||||
public void setDeviceStringActionState (bool state)
|
||||
{
|
||||
if (deviceStringActionManager != null) {
|
||||
deviceStringActionManager.changeActionName (state);
|
||||
}
|
||||
}
|
||||
|
||||
public void addObjectDetectedBelow (GameObject objectToCheck)
|
||||
{
|
||||
if (!objectsDetectedBelowList.Contains (objectToCheck)) {
|
||||
if (tagToCheckBelow.Contains (objectToCheck.tag) || objectToCheck.GetComponent<Rigidbody> ()) {
|
||||
|
||||
objectsDetectedBelowList.Add (objectToCheck);
|
||||
|
||||
currentPlatformIndex = 0;
|
||||
|
||||
checkMovementCoroutine (true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeObjectDetectedBelow (GameObject objectToCheck)
|
||||
{
|
||||
if (objectsDetectedBelowList.Contains (objectToCheck)) {
|
||||
objectsDetectedBelowList.Remove (objectToCheck);
|
||||
}
|
||||
}
|
||||
|
||||
//add a new waypoint
|
||||
public void addNewWayPoint ()
|
||||
{
|
||||
Vector3 newPosition = Vector3.zero;
|
||||
|
||||
if (platformTransform == null) {
|
||||
newPosition = transform.position;
|
||||
} else {
|
||||
newPosition = platformTransform.position;
|
||||
}
|
||||
|
||||
if (wayPoints.Count > 0) {
|
||||
newPosition = wayPoints [wayPoints.Count - 1].position + wayPoints [wayPoints.Count - 1].forward;
|
||||
}
|
||||
|
||||
GameObject newWayPoint = new GameObject ();
|
||||
newWayPoint.transform.SetParent (waypointsParent);
|
||||
newWayPoint.transform.position = newPosition;
|
||||
newWayPoint.name = (wayPoints.Count + 1).ToString ();
|
||||
wayPoints.Add (newWayPoint.transform);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
|
||||
GKC_Utils.updateDirtyScene ("Update Waypoint Platform " + gameObject.name, gameObject);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void OnDrawGizmos ()
|
||||
{
|
||||
if (!showGizmo) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
|
||||
DrawGizmos ();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected ()
|
||||
{
|
||||
DrawGizmos ();
|
||||
}
|
||||
|
||||
void DrawGizmos ()
|
||||
{
|
||||
if (showGizmo) {
|
||||
for (i = 0; i < wayPoints.Count; i++) {
|
||||
if (wayPoints [i] != null) {
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawSphere (wayPoints [i].position, gizmoRadius);
|
||||
|
||||
if (i + 1 < wayPoints.Count) {
|
||||
Gizmos.color = Color.white;
|
||||
Gizmos.DrawLine (wayPoints [i].position, wayPoints [i + 1].position);
|
||||
}
|
||||
|
||||
if (i == wayPoints.Count - 1 && moveInCircles) {
|
||||
Gizmos.color = Color.white;
|
||||
Gizmos.DrawLine (wayPoints [i].position, wayPoints [0].position);
|
||||
}
|
||||
|
||||
if (currentWaypoint != null) {
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawSphere (currentWaypoint.position, gizmoRadius);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
[System.Serializable]
|
||||
public class eventOnWaypointInfo
|
||||
{
|
||||
public string Name;
|
||||
public int waypointToReach;
|
||||
public UnityEvent eventOnWaypoint;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class passengersInfo
|
||||
{
|
||||
public Transform playerTransform;
|
||||
public playerController playerControllerManager;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class vehiclesInfo
|
||||
{
|
||||
public Transform vehicleTransform;
|
||||
public vehicleHUDManager HUDManager;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53dd9cd4418506e4b820733f8549d28a
|
||||
timeCreated: 1471387847
|
||||
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/Devices/waypointPlatform.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,440 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using GameKitController.Audio;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class waypointPlayerPathSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public List<wayPointInfo> wayPoints = new List<wayPointInfo> ();
|
||||
public bool inOrder;
|
||||
public bool showOneByOne;
|
||||
|
||||
[Space]
|
||||
[Header ("Other Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useTimer;
|
||||
public float timerSpeed;
|
||||
[Range (0, 60)] public float minutesToComplete;
|
||||
[Range (0, 60)] public float secondsToComplete;
|
||||
public float extraTimePerPoint;
|
||||
public int pointsReached;
|
||||
public AudioClip pathCompleteAudioSound;
|
||||
public AudioElement pathCompleteAudioElement;
|
||||
public AudioClip pathUncompleteAudioSound;
|
||||
public AudioElement pathUncompleteAudioElement;
|
||||
public AudioClip secondTimerSound;
|
||||
public AudioElement secondTimerAudioElement;
|
||||
public float secondSoundTimerLowerThan;
|
||||
public AudioClip pointReachedSound;
|
||||
public AudioElement pointReachedAudioElement;
|
||||
public bool useLineRenderer;
|
||||
public Color lineRendererColor = Color.yellow;
|
||||
public float lineRendererWidth;
|
||||
|
||||
public string mainManagerName = "Screen Objectives Manager";
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool pathActive;
|
||||
|
||||
[Space]
|
||||
[Header ("Event Settings")]
|
||||
[Space]
|
||||
|
||||
public UnityEvent eventOnPathComplete = new UnityEvent ();
|
||||
public UnityEvent eventOnPathIncomplete = new UnityEvent ();
|
||||
|
||||
[Space]
|
||||
[Header ("Gizmo Settings")]
|
||||
[Space]
|
||||
|
||||
public bool showGizmo;
|
||||
public Color gizmoLabelColor;
|
||||
public bool useRegularGizmoRadius;
|
||||
public float gizmoRadius;
|
||||
public float triggerRadius;
|
||||
public bool showOffScreenIcon;
|
||||
public bool showMapWindowIcon;
|
||||
public bool showDistance;
|
||||
public bool showInfoLabel = true;
|
||||
|
||||
public bool useHandleForVertex;
|
||||
public float handleRadius;
|
||||
public Color handleGizmoColor;
|
||||
public bool showDoPositionHandles;
|
||||
|
||||
List<GameObject> points = new List<GameObject> ();
|
||||
int i;
|
||||
int pointsNumber;
|
||||
float totalSecondsTimer;
|
||||
Text screenTimerText;
|
||||
AudioSource audioSource;
|
||||
LineRenderer lineRenderer;
|
||||
screenObjectivesSystem screenObjectivesManager;
|
||||
showGameInfoHud gameInfoHudManager;
|
||||
|
||||
GameObject currentUser;
|
||||
|
||||
playerComponentsManager mainPlayerComponentsManager;
|
||||
|
||||
private void InitializeAudioElements ()
|
||||
{
|
||||
if (pathCompleteAudioSound != null) {
|
||||
pathCompleteAudioElement.clip = pathCompleteAudioSound;
|
||||
}
|
||||
|
||||
if (pathUncompleteAudioSound != null) {
|
||||
pathUncompleteAudioElement.clip = pathUncompleteAudioSound;
|
||||
}
|
||||
|
||||
if (secondTimerSound != null) {
|
||||
secondTimerAudioElement.clip = secondTimerSound;
|
||||
}
|
||||
|
||||
if (pointReachedSound != null) {
|
||||
pointReachedAudioElement.clip = pointReachedSound;
|
||||
}
|
||||
}
|
||||
|
||||
void Start ()
|
||||
{
|
||||
InitializeAudioElements ();
|
||||
|
||||
if (inOrder && !showOneByOne && useLineRenderer) {
|
||||
lineRenderer = gameObject.AddComponent<LineRenderer> ();
|
||||
|
||||
lineRenderer.material = new Material (Shader.Find ("Sprites/Default")) { color = lineRendererColor };
|
||||
lineRenderer.startWidth = lineRendererWidth;
|
||||
lineRenderer.endWidth = lineRendererWidth;
|
||||
lineRenderer.startColor = lineRendererColor;
|
||||
lineRenderer.endColor = lineRendererColor;
|
||||
lineRenderer.positionCount = 0;
|
||||
}
|
||||
|
||||
bool screenObjectivesManagerLocated = screenObjectivesManager != null;
|
||||
|
||||
if (!screenObjectivesManagerLocated) {
|
||||
screenObjectivesManager = screenObjectivesSystem.Instance;
|
||||
|
||||
screenObjectivesManagerLocated = screenObjectivesManager != null;
|
||||
}
|
||||
|
||||
if (!screenObjectivesManagerLocated) {
|
||||
GKC_Utils.instantiateMainManagerOnSceneWithTypeOnApplicationPlaying (screenObjectivesSystem.getMainManagerName (), typeof(screenObjectivesSystem), true);
|
||||
|
||||
screenObjectivesManager = screenObjectivesSystem.Instance;
|
||||
}
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (pathActive) {
|
||||
if (useTimer) {
|
||||
totalSecondsTimer -= Time.deltaTime * timerSpeed;
|
||||
|
||||
screenTimerText.text = convertSeconds ();
|
||||
|
||||
if (secondTimerAudioElement != null) {
|
||||
if (totalSecondsTimer - 1 <= secondSoundTimerLowerThan && totalSecondsTimer % 1 < 0.1f) {
|
||||
playAudioSourceShoot (secondTimerAudioElement);
|
||||
}
|
||||
}
|
||||
|
||||
if (totalSecondsTimer <= 0) {
|
||||
stopPath ();
|
||||
}
|
||||
}
|
||||
|
||||
if (inOrder && !showOneByOne && useLineRenderer) {
|
||||
lineRenderer.startColor = lineRendererColor;
|
||||
lineRenderer.endColor = lineRendererColor;
|
||||
lineRenderer.positionCount = wayPoints.Count - pointsReached;
|
||||
|
||||
for (i = 0; i < wayPoints.Count; i++) {
|
||||
if (!wayPoints [i].reached) {
|
||||
lineRenderer.SetPosition (i - pointsReached, wayPoints [i].point.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string convertSeconds ()
|
||||
{
|
||||
int minutes = Mathf.FloorToInt (totalSecondsTimer / 60F);
|
||||
int seconds = Mathf.FloorToInt (totalSecondsTimer - minutes * 60);
|
||||
return string.Format ("{0:00}:{1:00}", minutes, seconds);
|
||||
}
|
||||
|
||||
//add a new waypoint
|
||||
public void addNewWayPoint ()
|
||||
{
|
||||
Vector3 newPosition = transform.position;
|
||||
if (wayPoints.Count > 0) {
|
||||
newPosition = wayPoints [wayPoints.Count - 1].point.position + wayPoints [wayPoints.Count - 1].point.forward * (wayPoints [wayPoints.Count - 1].triggerRadius * 3);
|
||||
}
|
||||
|
||||
GameObject newWayPoint = new GameObject ();
|
||||
newWayPoint.transform.SetParent (transform);
|
||||
newWayPoint.transform.position = newPosition;
|
||||
newWayPoint.name = (wayPoints.Count + 1).ToString ();
|
||||
|
||||
wayPointInfo newWayPointInfo = new wayPointInfo ();
|
||||
newWayPointInfo.Name = newWayPoint.name;
|
||||
newWayPointInfo.point = newWayPoint.transform;
|
||||
newWayPointInfo.triggerRadius = triggerRadius;
|
||||
|
||||
mapObjectInformation newMapObjectInformation = newWayPoint.AddComponent<mapObjectInformation> ();
|
||||
|
||||
newMapObjectInformation.setPathElementInfo (showOffScreenIcon, showMapWindowIcon, showDistance);
|
||||
newMapObjectInformation.enabled = false;
|
||||
|
||||
wayPoints.Add (newWayPointInfo);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void renamePoints ()
|
||||
{
|
||||
for (i = 0; i < wayPoints.Count; i++) {
|
||||
wayPoints [i].Name = (i + 1).ToString ();
|
||||
wayPoints [i].point.name = wayPoints [i].Name;
|
||||
}
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void pointReached (Transform point)
|
||||
{
|
||||
bool pointReachedCorrectly = false;
|
||||
|
||||
if (showOneByOne) {
|
||||
if (wayPoints [pointsReached].point == point) {
|
||||
wayPoints [pointsReached].reached = true;
|
||||
pointReachedCorrectly = true;
|
||||
pointsReached++;
|
||||
|
||||
if (pointsReached < pointsNumber) {
|
||||
mapObjectInformation newMapObjectInformation = wayPoints [pointsReached].point.GetComponent<mapObjectInformation> ();
|
||||
|
||||
if (newMapObjectInformation != null) {
|
||||
newMapObjectInformation.createMapIconInfo ();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
stopPath ();
|
||||
}
|
||||
} else {
|
||||
if (inOrder) {
|
||||
if (wayPoints [pointsReached].point == point) {
|
||||
wayPoints [pointsReached].reached = true;
|
||||
|
||||
pointReachedCorrectly = true;
|
||||
|
||||
pointsReached++;
|
||||
} else {
|
||||
stopPath ();
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < wayPoints.Count; i++) {
|
||||
if (wayPoints [i].point == point) {
|
||||
wayPoints [i].reached = true;
|
||||
|
||||
pointReachedCorrectly = true;
|
||||
|
||||
pointsReached++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pointReachedCorrectly) {
|
||||
if (pointsReached < pointsNumber && useTimer) {
|
||||
totalSecondsTimer += extraTimePerPoint;
|
||||
}
|
||||
|
||||
if (pointReachedAudioElement != null) {
|
||||
playAudioSourceShoot (pointReachedAudioElement);
|
||||
}
|
||||
|
||||
if (pointsReached == pointsNumber) {
|
||||
eventOnPathComplete.Invoke ();
|
||||
|
||||
pathActive = false;
|
||||
if (useTimer) {
|
||||
screenTimerText.gameObject.SetActive (false);
|
||||
}
|
||||
if (pathCompleteAudioElement != null) {
|
||||
playAudioSourceShoot (pathCompleteAudioElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentUser (GameObject user)
|
||||
{
|
||||
currentUser = user;
|
||||
}
|
||||
|
||||
public void resetPath ()
|
||||
{
|
||||
mainPlayerComponentsManager = currentUser.GetComponent<playerComponentsManager> ();
|
||||
|
||||
audioSource = mainPlayerComponentsManager.getPlayerStatesManager ().getAudioSourceElement ("Timer Audio Source");
|
||||
|
||||
gameInfoHudManager = mainPlayerComponentsManager.getGameInfoHudManager ();
|
||||
|
||||
pointsReached = 0;
|
||||
|
||||
pointsNumber = wayPoints.Count;
|
||||
|
||||
if (useTimer) {
|
||||
totalSecondsTimer = secondsToComplete + minutesToComplete * 60;
|
||||
|
||||
if (screenTimerText == null) {
|
||||
screenTimerText = gameInfoHudManager.getHudElement ("Timer", "Timer Text").GetComponent<Text> ();
|
||||
}
|
||||
|
||||
if (screenTimerText != null) {
|
||||
screenTimerText.gameObject.SetActive (true);
|
||||
}
|
||||
}
|
||||
|
||||
points.Clear ();
|
||||
|
||||
for (i = 0; i < wayPoints.Count; i++) {
|
||||
wayPoints [i].reached = false;
|
||||
points.Add (wayPoints [i].point.gameObject);
|
||||
}
|
||||
|
||||
if (screenObjectivesManager != null) {
|
||||
screenObjectivesManager.removeGameObjectListFromList (points);
|
||||
}
|
||||
|
||||
if (showOneByOne) {
|
||||
mapObjectInformation newMapObjectInformation = wayPoints [pointsReached].point.GetComponent<mapObjectInformation> ();
|
||||
|
||||
if (newMapObjectInformation != null) {
|
||||
newMapObjectInformation.createMapIconInfo ();
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < wayPoints.Count; i++) {
|
||||
mapObjectInformation newMapObjectInformation = wayPoints [i].point.GetComponent<mapObjectInformation> ();
|
||||
|
||||
if (newMapObjectInformation != null) {
|
||||
newMapObjectInformation.createMapIconInfo ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pathActive = true;
|
||||
|
||||
if (inOrder && !showOneByOne && useLineRenderer) {
|
||||
lineRenderer.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void stopPath ()
|
||||
{
|
||||
pathActive = false;
|
||||
|
||||
if (useTimer) {
|
||||
screenTimerText.gameObject.SetActive (false);
|
||||
}
|
||||
|
||||
if (screenObjectivesManager != null) {
|
||||
screenObjectivesManager.removeGameObjectListFromList (points);
|
||||
}
|
||||
|
||||
if (pathUncompleteAudioElement != null) {
|
||||
playAudioSourceShoot (pathUncompleteAudioElement);
|
||||
}
|
||||
|
||||
if (inOrder && !showOneByOne && useLineRenderer) {
|
||||
lineRenderer.enabled = false;
|
||||
}
|
||||
|
||||
eventOnPathIncomplete.Invoke ();
|
||||
}
|
||||
|
||||
public void playAudioSourceShoot (AudioElement clip)
|
||||
{
|
||||
if (audioSource != null) {
|
||||
clip.audioSource = audioSource;
|
||||
}
|
||||
|
||||
if (clip != null) {
|
||||
AudioPlayer.PlayOneShot (clip, gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
|
||||
GKC_Utils.updateDirtyScene ("Update Waypoint player path system info", gameObject);
|
||||
}
|
||||
|
||||
void OnDrawGizmos ()
|
||||
{
|
||||
if (!showGizmo) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
|
||||
DrawGizmos ();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected ()
|
||||
{
|
||||
DrawGizmos ();
|
||||
}
|
||||
|
||||
void DrawGizmos ()
|
||||
{
|
||||
if (!Application.isPlaying) {
|
||||
if (showGizmo) {
|
||||
for (i = 0; i < wayPoints.Count; i++) {
|
||||
if (wayPoints [i].point != null) {
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawSphere (wayPoints [i].point.position, gizmoRadius);
|
||||
|
||||
if (inOrder) {
|
||||
if (i + 1 < wayPoints.Count) {
|
||||
Gizmos.color = Color.white;
|
||||
Gizmos.DrawLine (wayPoints [i].point.position, wayPoints [i + 1].point.position);
|
||||
}
|
||||
} else {
|
||||
Gizmos.color = Color.white;
|
||||
Gizmos.DrawLine (wayPoints [i].point.position, transform.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < wayPoints.Count; i++) {
|
||||
if (wayPoints [i].point != null) {
|
||||
wayPoints [i].point.GetComponent<mapObjectInformation> ().showGizmo = showGizmo;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class wayPointInfo
|
||||
{
|
||||
public string Name;
|
||||
public Transform point;
|
||||
public bool reached;
|
||||
public float triggerRadius;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 138ed111d17d2b24ba3734b8526660e7
|
||||
timeCreated: 1479231988
|
||||
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/Devices/waypointPlayerPathSystem.cs
|
||||
uploadId: 814740
|
||||
419
Assets/Game Kit Controller/Scripts/Devices/zipline.cs
Normal file
419
Assets/Game Kit Controller/Scripts/Devices/zipline.cs
Normal file
@@ -0,0 +1,419 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class zipline : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public float extraDistance;
|
||||
public float speed;
|
||||
public float maxSpeed;
|
||||
public float minSpeed;
|
||||
|
||||
public bool ziplineConnected = true;
|
||||
public float connectZiplineSpeed = 5;
|
||||
|
||||
[Space]
|
||||
[Header ("IK Settings")]
|
||||
[Space]
|
||||
|
||||
public IKZiplineInfo IKZipline;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool usingZipline;
|
||||
|
||||
public bool showDebugPrint;
|
||||
|
||||
[Space]
|
||||
[Header ("Gizmo Setting")]
|
||||
[Space]
|
||||
|
||||
public bool showGizmo;
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public electronicDevice deviceManager;
|
||||
public Collider trigger;
|
||||
|
||||
public Transform finalPosition;
|
||||
public Transform initialPosition;
|
||||
public Transform movingTransform;
|
||||
public Transform middleLine;
|
||||
public Transform middleLinePivot;
|
||||
|
||||
GameObject currentPlayer;
|
||||
|
||||
float originalSpeed;
|
||||
int i;
|
||||
bool stoppedByPlayer;
|
||||
|
||||
playerInputManager playerInput;
|
||||
menuPause pauseManager;
|
||||
playerController playerControllerManager;
|
||||
|
||||
playerComponentsManager mainPlayerComponentsManager;
|
||||
|
||||
IKSystem currentIKSystem;
|
||||
usingDevicesSystem currentUsingDevicesSystem;
|
||||
|
||||
Vector3 movingTransformTargetPosition;
|
||||
bool movingForward;
|
||||
bool movingBackward;
|
||||
|
||||
Vector2 axisValues;
|
||||
|
||||
Coroutine ziplineMovementCoroutine;
|
||||
Coroutine connectCoroutine;
|
||||
|
||||
Coroutine mainCoroutine;
|
||||
|
||||
|
||||
void Start ()
|
||||
{
|
||||
if (trigger == null) {
|
||||
trigger = GetComponent<Collider> ();
|
||||
}
|
||||
|
||||
if (deviceManager == null) {
|
||||
deviceManager = GetComponent<electronicDevice> ();
|
||||
}
|
||||
|
||||
originalSpeed = speed;
|
||||
|
||||
Vector3 heading = finalPosition.position - movingTransform.position;
|
||||
float distance = heading.magnitude;
|
||||
Vector3 direction = heading / distance;
|
||||
Quaternion targetRotation = Quaternion.LookRotation (direction, movingTransform.up);
|
||||
|
||||
movingTransform.eulerAngles = new Vector3 (movingTransform.eulerAngles.x, targetRotation.eulerAngles.y, movingTransform.eulerAngles.x);
|
||||
|
||||
if (!ziplineConnected) {
|
||||
heading = middleLine.position - initialPosition.position;
|
||||
distance = heading.magnitude;
|
||||
|
||||
middleLinePivot.localScale = new Vector3 (1, 1, distance);
|
||||
|
||||
trigger.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void stopUpdateCoroutine ()
|
||||
{
|
||||
if (mainCoroutine != null) {
|
||||
StopCoroutine (mainCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator updateCoroutine ()
|
||||
{
|
||||
// var waitTime = new WaitForFixedUpdate ();
|
||||
|
||||
var waitTime = new WaitForSecondsRealtime (0.00001f);
|
||||
|
||||
while (true) {
|
||||
updateState ();
|
||||
|
||||
yield return waitTime;
|
||||
}
|
||||
}
|
||||
|
||||
void updateState ()
|
||||
{
|
||||
//if the player is using the zipline, move his position from the current position to the final
|
||||
if (usingZipline) {
|
||||
axisValues = playerInput.getPlayerMovementAxis ();
|
||||
|
||||
if (axisValues.y > 0) {
|
||||
speed += Time.deltaTime * speed;
|
||||
}
|
||||
|
||||
if (axisValues.y < 0) {
|
||||
speed -= Time.deltaTime * speed;
|
||||
}
|
||||
|
||||
speed = Mathf.Clamp (speed, minSpeed, maxSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
//function called when the player use the interaction button, to use the zipline
|
||||
public void activateZipLine ()
|
||||
{
|
||||
usingZipline = !usingZipline;
|
||||
|
||||
stopUpdateCoroutine ();
|
||||
|
||||
//if the player press the interaction button while he stills using the zipline, stop his movement and released from the zipline
|
||||
if (usingZipline) {
|
||||
mainCoroutine = StartCoroutine (updateCoroutine ());
|
||||
} else {
|
||||
stoppedByPlayer = true;
|
||||
}
|
||||
|
||||
changeZiplineState (usingZipline);
|
||||
}
|
||||
|
||||
public void changeZiplineState (bool state)
|
||||
{
|
||||
//set the current state of the player in the IKSystem component, to enable or disable the ik positions
|
||||
currentIKSystem.ziplineState (state, IKZipline);
|
||||
|
||||
//enable or disable the player's capsule collider
|
||||
currentPlayer.GetComponent<Collider> ().isTrigger = state;
|
||||
|
||||
//if the player is using the zipline, then
|
||||
if (state) {
|
||||
//disable the trigger of the zipline, to avoid the player remove this device from the compoenet usingDeviceSystem when he exits from its trigger
|
||||
trigger.enabled = false;
|
||||
//set the position of the object which moves throught the zipline
|
||||
movingTransform.transform.position = initialPosition.transform.position;
|
||||
|
||||
//disable the player controller component
|
||||
playerControllerManager.changeScriptState (false);
|
||||
|
||||
playerControllerManager.setHeadTrackCanBeUsedState (false);
|
||||
|
||||
playerControllerManager.enableOrDisablePlayerControllerScript (false);
|
||||
|
||||
playerControllerManager.getRigidbody ().isKinematic = true;
|
||||
|
||||
//set that the player is using a device
|
||||
playerControllerManager.setUsingDeviceState (state);
|
||||
|
||||
pauseManager.usingDeviceState (state);
|
||||
|
||||
//make the player and the camera a child of the object which moves in the zipline
|
||||
playerControllerManager.setPlayerAndCameraAndFBAPivotTransformParent (movingTransform);
|
||||
|
||||
currentPlayer.transform.localRotation = Quaternion.identity;
|
||||
|
||||
movingTransformTargetPosition = finalPosition.transform.position;
|
||||
} else {
|
||||
//the player stops using the zipline, so release him from it
|
||||
trigger.enabled = enabled;
|
||||
|
||||
playerControllerManager.getRigidbody ().isKinematic = false;
|
||||
playerControllerManager.changeScriptState (true);
|
||||
|
||||
playerControllerManager.setHeadTrackCanBeUsedState (true);
|
||||
|
||||
playerControllerManager.enableOrDisablePlayerControllerScript (true);
|
||||
|
||||
currentUsingDevicesSystem.disableIcon ();
|
||||
|
||||
playerControllerManager.setUsingDeviceState (state);
|
||||
|
||||
pauseManager.usingDeviceState (state);
|
||||
|
||||
playerControllerManager.setPlayerAndCameraAndFBAPivotTransformParent (null);
|
||||
|
||||
//movingTransform.transform.position = initialPosition.transform.position;
|
||||
|
||||
// If the player has stopped his movement before he reaches the end of the zipline, add an extra force in the zipline direction
|
||||
if (stoppedByPlayer) {
|
||||
playerControllerManager.useJumpPlatform ((movingTransform.forward - currentPlayer.transform.up * 0.5f) * (speed * 2), ForceMode.Impulse);
|
||||
}
|
||||
|
||||
currentUsingDevicesSystem.clearDeviceList ();
|
||||
|
||||
deviceManager.setUsingDeviceState (false);
|
||||
movingTransformTargetPosition = initialPosition.transform.position;
|
||||
}
|
||||
|
||||
speed = originalSpeed;
|
||||
|
||||
stoppedByPlayer = false;
|
||||
|
||||
checkZiplineMovement ();
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("changeZiplineState " + state);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentPlayer (GameObject player)
|
||||
{
|
||||
currentPlayer = player;
|
||||
|
||||
if (currentPlayer != null) {
|
||||
mainPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
|
||||
|
||||
playerControllerManager = mainPlayerComponentsManager.getPlayerController ();
|
||||
|
||||
playerInput = mainPlayerComponentsManager.getPlayerInputManager ();
|
||||
|
||||
pauseManager = mainPlayerComponentsManager.getPauseManager ();
|
||||
|
||||
currentIKSystem = mainPlayerComponentsManager.getIKSystem ();
|
||||
|
||||
currentUsingDevicesSystem = mainPlayerComponentsManager.getUsingDevicesSystem ();
|
||||
}
|
||||
}
|
||||
|
||||
public void checkZiplineMovement ()
|
||||
{
|
||||
if (ziplineMovementCoroutine != null) {
|
||||
StopCoroutine (ziplineMovementCoroutine);
|
||||
}
|
||||
|
||||
ziplineMovementCoroutine = StartCoroutine (ziplineMovement ());
|
||||
}
|
||||
|
||||
IEnumerator ziplineMovement ()
|
||||
{
|
||||
//while the platform moves from the previous waypoint to the next, then displace it
|
||||
bool targetReached = false;
|
||||
|
||||
Vector3 movingTransformPosition = movingTransform.transform.position;
|
||||
|
||||
float dist = GKC_Utils.distance (movingTransformPosition, movingTransformTargetPosition);
|
||||
|
||||
float duration = dist / speed;
|
||||
|
||||
float movementTimer = 0;
|
||||
|
||||
float t = 0;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print (dist + " " + movingTransformPosition + " " + movingTransformTargetPosition + " " + duration);
|
||||
}
|
||||
|
||||
while (!targetReached) {
|
||||
t += Time.deltaTime / duration;
|
||||
|
||||
movingTransform.transform.position =
|
||||
Vector3.Lerp (movingTransformPosition, movingTransformTargetPosition, t);
|
||||
|
||||
float currentDistance = GKC_Utils.distance (movingTransform.transform.position, movingTransformTargetPosition);
|
||||
|
||||
if (currentDistance <= 0.01f) {
|
||||
targetReached = true;
|
||||
}
|
||||
|
||||
movementTimer += Time.deltaTime;
|
||||
|
||||
if (movementTimer > (duration + 1)) {
|
||||
targetReached = true;
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
if (usingZipline) {
|
||||
usingZipline = false;
|
||||
|
||||
changeZiplineState (usingZipline);
|
||||
}
|
||||
}
|
||||
|
||||
public void setZiplineConnectedState (bool state)
|
||||
{
|
||||
ziplineConnected = state;
|
||||
trigger.enabled = state;
|
||||
|
||||
if (ziplineConnected) {
|
||||
connectZipine ();
|
||||
}
|
||||
}
|
||||
|
||||
public void connectZipine ()
|
||||
{
|
||||
if (connectCoroutine != null) {
|
||||
StopCoroutine (connectCoroutine);
|
||||
}
|
||||
|
||||
connectCoroutine = StartCoroutine (connectZipineCoroutine ());
|
||||
}
|
||||
|
||||
IEnumerator connectZipineCoroutine ()
|
||||
{
|
||||
float scaleZ = GKC_Utils.distance (middleLine.position, finalPosition.position);
|
||||
float distance = scaleZ + (scaleZ * extraDistance) + 0.5f;
|
||||
|
||||
float currentMidleLineScale = 1;
|
||||
|
||||
//while the platform moves from the previous waypoint to the next, then displace it
|
||||
while (currentMidleLineScale < distance) {
|
||||
currentMidleLineScale = Mathf.MoveTowards (currentMidleLineScale, distance, Time.deltaTime * connectZiplineSpeed);
|
||||
middleLinePivot.localScale = new Vector3 (1, 1, currentMidleLineScale);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
//draw every ik position in the editor
|
||||
void OnDrawGizmos ()
|
||||
{
|
||||
if (!showGizmo) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GKC_Utils.isCurrentSelectionActiveGameObject (gameObject)) {
|
||||
DrawGizmos ();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected ()
|
||||
{
|
||||
DrawGizmos ();
|
||||
}
|
||||
|
||||
void DrawGizmos ()
|
||||
{
|
||||
if (showGizmo) {
|
||||
for (i = 0; i < IKZipline.IKGoals.Count; i++) {
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawSphere (IKZipline.IKGoals [i].position.position, 0.1f);
|
||||
}
|
||||
|
||||
for (i = 0; i < IKZipline.IKHints.Count; i++) {
|
||||
Gizmos.color = Color.blue;
|
||||
Gizmos.DrawSphere (IKZipline.IKHints [i].position.position, 0.1f);
|
||||
}
|
||||
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawSphere (IKZipline.bodyPosition.position, 0.1f);
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawLine (initialPosition.position, finalPosition.position);
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawSphere (initialPosition.position, 0.2f);
|
||||
Gizmos.color = Color.blue;
|
||||
Gizmos.DrawSphere (finalPosition.position, 0.2f);
|
||||
|
||||
float scaleZ = GKC_Utils.distance (middleLine.position, finalPosition.position);
|
||||
middleLinePivot.transform.localScale = new Vector3 (1, 1, scaleZ + (scaleZ * extraDistance) + 0.5f);
|
||||
middleLine.LookAt (finalPosition);
|
||||
movingTransform.position = initialPosition.position;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class IKZiplineInfo
|
||||
{
|
||||
public List<IKGoalsZiplinePositions> IKGoals = new List<IKGoalsZiplinePositions> ();
|
||||
public List<IKHintsZiplinePositions> IKHints = new List<IKHintsZiplinePositions> ();
|
||||
public Transform bodyPosition;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class IKGoalsZiplinePositions
|
||||
{
|
||||
public string Name;
|
||||
public AvatarIKGoal limb;
|
||||
public Transform position;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class IKHintsZiplinePositions
|
||||
{
|
||||
public string Name;
|
||||
public AvatarIKHint limb;
|
||||
public Transform position;
|
||||
}
|
||||
}
|
||||
19
Assets/Game Kit Controller/Scripts/Devices/zipline.cs.meta
Normal file
19
Assets/Game Kit Controller/Scripts/Devices/zipline.cs.meta
Normal file
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 026866a3532acd04aab8925bbffb6e60
|
||||
timeCreated: 1468001694
|
||||
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/Devices/zipline.cs
|
||||
uploadId: 814740
|
||||
Reference in New Issue
Block a user