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

View File

@@ -0,0 +1,601 @@
using System.Collections;
using System.Collections.Generic;
using GameKitController.Audio;
using UnityEngine;
using UnityEngine.UI;
#if UNITY_EDITOR
using UnityEditor;
#endif
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE || UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX
using UnityEngine.Video;
#endif
public class playerTutorialSystem : MonoBehaviour
{
public bool tutorialsEnabled;
public float minTimeToPressKey = 0.4f;
public int currentTutorialIndex;
public int currentTutorialPanelIndex;
public bool tutorialOpened;
public bool instantiateTutorialPanelIfNotFound;
public bool mainTutorialUISystemFound;
public GameObject tutorialPanelPrefab;
public playerController playerControllerManager;
public menuPause pauseManager;
public AudioSource mainAudioSource;
public tutorialUISystem mainTutorialUISystem;
tutorialInfo currentTutorialInfo;
KeyCode[] validKeyCodes;
float lastTimeTutorialOpened;
float previousTimeScale;
Coroutine resumeCoroutine;
bool activatingTutorialByNameFromEditorState;
Coroutine openTutorialCoroutine;
Coroutine tutorialOpenedCoroutine;
public Transform tutorialsPanel;
public AudioSource videoAudioSource;
public List<tutorialInfo> tutorialInfoList = new List<tutorialInfo> ();
bool validKeyCodesStored;
float lastTimeKeyPressed;
private void InitializeAudioElements ()
{
foreach (var tutorialInfo in tutorialInfoList) {
tutorialInfo.InitializeAudioElements ();
if (mainAudioSource != null) {
tutorialInfo.onTutorialOpenAudioElement.audioSource = mainAudioSource;
}
}
}
void Start ()
{
InitializeAudioElements ();
getTutorialUISystem ();
}
void getTutorialUISystem ()
{
if (mainTutorialUISystem != null) {
mainTutorialUISystemFound = true;
} else {
if (mainTutorialUISystem == null) {
mainTutorialUISystem = FindObjectOfType<tutorialUISystem> ();
}
if (mainTutorialUISystem != null) {
mainTutorialUISystemFound = true;
}
}
}
void getValidKeyCodes ()
{
if (!validKeyCodesStored) {
validKeyCodes = (KeyCode[])System.Enum.GetValues (typeof(KeyCode));
validKeyCodesStored = true;
}
}
void updateTutorialOpenedState ()
{
if (tutorialOpened && (currentTutorialInfo.pressAnyButtonToNextTutorial || pauseManager.isMenuPaused ())) {
if (Time.unscaledTime > lastTimeTutorialOpened + currentTutorialInfo.timeToEnableKeys ||
pauseManager.isMenuPaused () ||
currentTutorialInfo.setCustomTimeScale) {
if (Time.unscaledTime > lastTimeKeyPressed + minTimeToPressKey) {
foreach (KeyCode vKey in validKeyCodes) {
if (Input.GetKeyDown (vKey)) {
lastTimeKeyPressed = Time.unscaledTime;
setNextPanelOnTutorial ();
if (!tutorialOpened) {
stopCheckTutorialOpenedState ();
}
return;
}
}
}
}
}
}
IEnumerator checkTutorialOpenedStateCoroutine ()
{
while (true) {
yield return new WaitForSecondsRealtime (0.0001f);
updateTutorialOpenedState ();
}
}
public void stopCheckTutorialOpenedState ()
{
if (tutorialOpenedCoroutine != null) {
StopCoroutine (tutorialOpenedCoroutine);
}
}
public void checkTutorialOpenedState ()
{
stopCheckTutorialOpenedState ();
tutorialOpenedCoroutine = StartCoroutine (checkTutorialOpenedStateCoroutine ());
}
public void activatingTutorialByNameFromEditor ()
{
activatingTutorialByNameFromEditorState = true;
}
public void activateTutorialByName (string tutorialName)
{
if (!tutorialsEnabled && !pauseManager.isMenuPaused ()) {
return;
}
if (!mainTutorialUISystemFound) {
bool tutorialFound = false;
if (instantiateTutorialPanelIfNotFound) {
instantiateTutorialPanelPrefab ();
getTutorialUISystem ();
if (mainTutorialUISystemFound) {
tutorialFound = true;
}
}
if (!tutorialFound) {
print ("WARNING: No tutorial UI system found, make sure to drop it on the scene");
return;
}
}
tutorialsPanel = mainTutorialUISystem.getTutorialsPanel ();
videoAudioSource = mainTutorialUISystem.getVideoAudioSource ();
tutorialInfoList = mainTutorialUISystem.getTutorialInfoList ();
for (int i = 0; i < tutorialInfoList.Count; i++) {
if (tutorialInfoList [i].Name.Equals (tutorialName)) {
currentTutorialInfo = tutorialInfoList [i];
if (mainAudioSource)
currentTutorialInfo.onTutorialOpenAudioElement.audioSource = mainAudioSource;
if (!activatingTutorialByNameFromEditorState) {
if (currentTutorialInfo.playTutorialOnlyOnce && !pauseManager.isMenuPaused () && currentTutorialInfo.tutorialPlayed) {
return;
}
}
currentTutorialIndex = i;
currentTutorialPanelIndex = 0;
checkOpenOrCloseTutorial (true);
return;
}
}
print ("WARNING: no tutorial was found with the name " + tutorialName + ", check if the name is properly configured in the event and in the player tutorial system inspector");
}
public void checkOpenOrCloseTutorial (bool state)
{
if (state) {
if (pauseManager.isMenuPaused ()) {
openOrCloseTutorial (true);
} else {
stopCheckOpenOrCloseTutorial ();
playerControllerManager.getPlayerInput ().pauseOrResumeInput (true);
openTutorialCoroutine = StartCoroutine (checkOpenOrCloseTutorialCoroutine ());
}
} else {
stopCheckOpenOrCloseTutorial ();
openOrCloseTutorial (false);
}
}
public void stopCheckOpenOrCloseTutorial ()
{
if (openTutorialCoroutine != null) {
StopCoroutine (openTutorialCoroutine);
}
}
IEnumerator checkOpenOrCloseTutorialCoroutine ()
{
yield return new WaitForSeconds (currentTutorialInfo.openTutorialDelay);
openOrCloseTutorial (true);
}
public void setNextPanelOnTutorial ()
{
if (currentTutorialInfo.tutorialPanelList.Count == 0) {
closeTutorial ();
return;
}
currentTutorialInfo.tutorialPanelList [currentTutorialPanelIndex].panelGameObject.SetActive (false);
currentTutorialPanelIndex++;
if (currentTutorialPanelIndex <= currentTutorialInfo.tutorialPanelList.Count - 1) {
currentTutorialInfo.tutorialPanelList [currentTutorialPanelIndex].panelGameObject.SetActive (true);
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE || UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX
if (currentTutorialInfo.containsVideo) {
currentTutorialInfo.currentVideoIndex++;
playTutorialVideo (currentTutorialInfo);
}
#endif
} else {
currentTutorialPanelIndex = currentTutorialInfo.tutorialPanelList.Count - 1;
closeTutorial ();
}
}
public void setPreviousPanelOnTutorial ()
{
if (currentTutorialInfo.tutorialPanelList.Count == 0) {
return;
}
currentTutorialInfo.tutorialPanelList [currentTutorialPanelIndex].panelGameObject.SetActive (false);
currentTutorialPanelIndex--;
if (currentTutorialPanelIndex < 0) {
currentTutorialPanelIndex = 0;
}
currentTutorialInfo.tutorialPanelList [currentTutorialPanelIndex].panelGameObject.SetActive (false);
}
public void openOrCloseTutorial (bool opened)
{
tutorialOpened = opened;
if (tutorialOpened) {
lastTimeKeyPressed = 0;
getValidKeyCodes ();
checkTutorialOpenedState ();
currentTutorialInfo.panelGameObject.SetActive (true);
if (currentTutorialInfo.tutorialPanelList.Count > 0) {
currentTutorialInfo.tutorialPanelList [0].panelGameObject.SetActive (true);
}
lastTimeTutorialOpened = Time.unscaledTime;
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE || UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX
if (currentTutorialInfo.containsVideo) {
playTutorialVideo (currentTutorialInfo);
}
#endif
}
bool isPlayerDriving = playerControllerManager.isPlayerDriving ();
if (!pauseManager.isMenuPaused ()) {
if (!tutorialOpened || currentTutorialInfo.unlockCursorOnTutorialActive) {
if (!isPlayerDriving) {
pauseManager.showOrHideCursor (tutorialOpened);
}
}
if (!isPlayerDriving) {
pauseManager.changeCameraState (!tutorialOpened);
pauseManager.setHeadBobPausedState (!tutorialOpened);
}
pauseManager.usingSubMenuState (tutorialOpened);
}
pauseManager.openOrClosePlayerMenu (tutorialOpened, tutorialsPanel, true);
if (!isPlayerDriving) {
pauseManager.usingDeviceState (tutorialOpened);
playerControllerManager.setUsingDeviceState (tutorialOpened);
playerControllerManager.changeScriptState (!tutorialOpened);
} else {
playerControllerManager.getPlayerInput ().setInputCurrentlyActiveState (!tutorialOpened);
}
if (tutorialOpened) {
stopResumePlayerInputCoroutine ();
playerControllerManager.getPlayerInput ().pauseOrResumeInput (tutorialOpened);
} else {
resumePlayerInput ();
}
if (pauseManager.isMenuPaused () && !tutorialOpened) {
pauseManager.resetPauseMenuBlurPanel ();
}
if (!pauseManager.isMenuPaused ()) {
if (!activatingTutorialByNameFromEditorState) {
currentTutorialInfo.tutorialPlayed = true;
}
activatingTutorialByNameFromEditorState = false;
if (tutorialOpened && currentTutorialInfo.useSoundOnTutorialOpen) {
if (currentTutorialInfo.onTutorialOpenAudioElement != null) {
AudioPlayer.PlayOneShot (currentTutorialInfo.onTutorialOpenAudioElement, gameObject);
}
}
if (currentTutorialInfo.setCustomTimeScale) {
if (tutorialOpened) {
previousTimeScale = Time.timeScale;
Time.timeScale = currentTutorialInfo.customTimeScale;
} else {
Time.timeScale = previousTimeScale;
}
}
}
}
public void resumePlayerInput ()
{
stopResumePlayerInputCoroutine ();
if (Time.timeScale == 0) {
playerControllerManager.getPlayerInput ().pauseOrResumeInput (false);
} else {
resumeCoroutine = StartCoroutine (resumePlayerInputCoroutine ());
}
}
public void stopResumePlayerInputCoroutine ()
{
if (resumeCoroutine != null) {
StopCoroutine (resumeCoroutine);
}
}
IEnumerator resumePlayerInputCoroutine ()
{
yield return new WaitForSeconds (0.5f);
playerControllerManager.getPlayerInput ().pauseOrResumeInput (tutorialOpened);
}
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE || UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX
Coroutine currentTutorialVideoCoroutine;
public void playTutorialVideo (tutorialInfo newTutorialInfo)
{
stopTutorialVideoCoroutine ();
currentTutorialVideoCoroutine = StartCoroutine (playTutorialVideoCoroutine (newTutorialInfo));
}
public void stopTutorialVideoCoroutine ()
{
if (currentTutorialInfo != null) {
if (currentTutorialInfo.containsVideo) {
VideoPlayer mainVideoPlayer = mainTutorialUISystem.getMainVideoPlayerPanel ().GetComponent<VideoPlayer> ();
if (mainVideoPlayer != null) {
if (mainVideoPlayer.isPlaying) {
mainVideoPlayer.Stop ();
if (videoAudioSource != null) {
videoAudioSource.Stop ();
}
}
}
}
}
if (currentTutorialVideoCoroutine != null) {
StopCoroutine (currentTutorialVideoCoroutine);
}
}
IEnumerator playTutorialVideoCoroutine (tutorialInfo newTutorialInfo)
{
if (currentTutorialInfo.currentVideoIndex < currentTutorialInfo.videoInfoList.Count) {
VideoPlayer mainVideoPlayer = mainTutorialUISystem.getMainVideoPlayerPanel ().GetComponent<VideoPlayer> ();
if (mainVideoPlayer != null) {
videoInfo currentVideoInfo = currentTutorialInfo.videoInfoList [currentTutorialInfo.currentVideoIndex];
mainVideoPlayer.source = VideoSource.VideoClip;
mainVideoPlayer.clip = currentVideoInfo.videoFile;
//Set Audio Output to AudioSource
mainVideoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;
//Assign the Audio from Video to AudioSource to be played
mainVideoPlayer.EnableAudioTrack (0, true);
mainVideoPlayer.SetTargetAudioSource (0, videoAudioSource);
if (currentVideoInfo.useVideoAudio) {
videoAudioSource.volume = currentVideoInfo.videoAudioVolume;
} else {
videoAudioSource.volume = 0;
}
//Set video To Play then prepare Audio to prevent Buffering
mainVideoPlayer.Prepare ();
//Wait until video is prepared
while (!mainVideoPlayer.isPrepared) {
yield return null;
}
//Assign the Texture from Video to RawImage to be displayed
currentVideoInfo.videoRawImage.texture = mainVideoPlayer.texture;
//Play Video
mainVideoPlayer.Play ();
//Play Sound
if (currentVideoInfo.useVideoAudio) {
videoAudioSource.Play ();
}
while (mainVideoPlayer.isPlaying) {
//Debug.LogWarning ("Video Time: " + Mathf.FloorToInt ((float)mainVideoPlayer.time));
yield return null;
}
if (currentVideoInfo.loopVideo) {
playTutorialVideo (currentTutorialInfo);
}
} else {
yield return null;
}
if (currentTutorialInfo.setNextPanelWhenVideoEnds) {
setNextPanelOnTutorial ();
}
}
}
#endif
public void closeTutorial ()
{
if (currentTutorialInfo.tutorialPanelList.Count > 0) {
currentTutorialInfo.tutorialPanelList [currentTutorialPanelIndex].panelGameObject.SetActive (false);
}
checkOpenOrCloseTutorial (false);
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE || UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX
if (currentTutorialInfo.containsVideo) {
stopTutorialVideoCoroutine ();
currentTutorialInfo.currentVideoIndex = 0;
}
#endif
currentTutorialInfo.panelGameObject.SetActive (false);
}
public void callNextTutorialPanel ()
{
if (tutorialOpened) {
if (currentTutorialInfo.useActionButtonToMoveThroughTutorial) {
setNextPanelOnTutorial ();
}
}
}
public void resetAllTutorials ()
{
for (int i = 0; i < tutorialInfoList.Count; i++) {
if (tutorialInfoList [i].panelGameObject != null) {
tutorialInfoList [i].panelGameObject.SetActive (false);
}
for (int j = 0; j < tutorialInfoList [i].tutorialPanelList.Count; j++) {
if (tutorialInfoList [i].tutorialPanelList [j].panelGameObject != null) {
if (j == 0) {
tutorialInfoList [i].tutorialPanelList [j].panelGameObject.SetActive (true);
} else {
tutorialInfoList [i].tutorialPanelList [j].panelGameObject.SetActive (false);
}
}
}
}
}
public void setTutorialsEnabledState (bool state)
{
tutorialsEnabled = state;
}
public void setTutorialUISystem (tutorialUISystem newTutorialUISystem)
{
mainTutorialUISystem = newTutorialUISystem;
updateComponent ();
}
public void instantiateTutorialPanelPrefab ()
{
if (mainTutorialUISystem == null) {
if (tutorialPanelPrefab == null) {
return;
}
GameObject newTutorialPanel = (GameObject)Instantiate (tutorialPanelPrefab, Vector3.zero, Quaternion.identity);
newTutorialPanel.name = tutorialPanelPrefab.name;
tutorialUISystem currentTutorialUISystem = newTutorialPanel.GetComponentInChildren<tutorialUISystem> ();
if (currentTutorialUISystem != null) {
currentTutorialUISystem.searchPlayerTutorialSystem ();
GKC_Utils.updateAllLanguageElementCheckerOnScene ();
}
} else {
print ("Tutorial Panel is already on the scene");
}
}
public void setTutorialsEnabledStateFromEditor (bool state)
{
setTutorialsEnabledState (state);
updateComponent ();
}
public void updateComponent ()
{
GKC_Utils.updateComponent (this);
GKC_Utils.updateDirtyScene ("Update Tutorial System", gameObject);
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 3fda07e7c5f07274da8f05368f943391
timeCreated: 1536589529
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/Tutorial System/playerTutorialSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class tutorialActivatorSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool tutorialEnabled = true;
public string tutorialName;
public string extraString = "Controls";
GameObject currentPlayer;
public void activateTutorial (GameObject newPlayer)
{
if (!tutorialEnabled) {
return;
}
playerTutorialSystem currentPlayerTutorialSystem = FindObjectOfType<playerTutorialSystem> ();
if (currentPlayerTutorialSystem != null) {
string tutorialNameToActivate = tutorialName;
if (extraString != "") {
tutorialNameToActivate += " " + extraString;
}
currentPlayerTutorialSystem.activateTutorialByName (tutorialNameToActivate);
} else {
print ("WARNING: no tutorial system has been found in the scene, make sure to drop the tutorial system prefab into it");
}
}
public void setTutorialEnabledState (bool state)
{
tutorialEnabled = state;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 5a0f6b3621de72c4391a51cf3f1fb7a6
timeCreated: 1546573102
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/Tutorial System/tutorialActivatorSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,70 @@
using System.Collections;
using System.Collections.Generic;
using GameKitController.Audio;
using UnityEngine;
using UnityEngine.UI;
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE || UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX
using UnityEngine.Video;
#endif
[System.Serializable]
public class tutorialInfo
{
public string Name;
public GameObject panelGameObject;
public List<panelInfo> tutorialPanelList = new List<panelInfo> ();
public bool unlockCursorOnTutorialActive;
public bool useActionButtonToMoveThroughTutorial;
public bool pressAnyButtonToNextTutorial;
public float timeToEnableKeys = 1;
public float openTutorialDelay;
public bool setCustomTimeScale;
public float customTimeScale;
public bool useSoundOnTutorialOpen;
public AudioClip soundOnTutorialOpen;
public AudioElement onTutorialOpenAudioElement;
public bool playTutorialOnlyOnce;
public bool tutorialPlayed;
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE || UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX
public bool containsVideo;
public List<videoInfo> videoInfoList = new List<videoInfo> ();
public bool setNextPanelWhenVideoEnds;
public int currentVideoIndex;
#endif
public void InitializeAudioElements ()
{
if (soundOnTutorialOpen != null) {
onTutorialOpenAudioElement.clip = soundOnTutorialOpen;
}
}
}
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE || UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX
[System.Serializable]
public class videoInfo
{
public string Name = "New Video";
public RawImage videoRawImage;
public VideoClip videoFile;
public bool useVideoAudio = true;
public float videoAudioVolume = 1;
public bool loopVideo = true;
public Coroutine currentTutorialVideoCoroutine;
}
#endif
[System.Serializable]
public class panelInfo
{
public string Name;
public GameObject panelGameObject;
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 7604d2a68393c5440974e499ef13460b
timeCreated: 1588825134
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/Tutorial System/tutorialInfo.cs
uploadId: 814740

View File

@@ -0,0 +1,67 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class tutorialUISystem : MonoBehaviour
{
public List<tutorialInfo> tutorialInfoList = new List<tutorialInfo> ();
public Transform tutorialsPanel;
public AudioSource videoAudioSource;
public Transform mainVideoPlayerPanel;
public playerTutorialSystem mainPlayerTutorialSystem;
private void Start ()
{
foreach (var tutorialInfo in tutorialInfoList) {
tutorialInfo.InitializeAudioElements ();
}
}
public Transform getTutorialsPanel ()
{
return tutorialsPanel;
}
public AudioSource getVideoAudioSource ()
{
return videoAudioSource;
}
public Transform getMainVideoPlayerPanel ()
{
return mainVideoPlayerPanel;
}
public List<tutorialInfo> getTutorialInfoList ()
{
return tutorialInfoList;
}
public void activateTutorialByName (string tutorialName)
{
if (mainPlayerTutorialSystem != null) {
mainPlayerTutorialSystem.activatingTutorialByNameFromEditor ();
mainPlayerTutorialSystem.activateTutorialByName (tutorialName);
}
}
public void searchPlayerTutorialSystem ()
{
if (mainPlayerTutorialSystem == null) {
mainPlayerTutorialSystem = FindObjectOfType<playerTutorialSystem> ();
}
if (mainPlayerTutorialSystem != null) {
mainPlayerTutorialSystem.setTutorialUISystem (this);
}
updateComponent ();
}
public void updateComponent ()
{
GKC_Utils.updateComponent (this);
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 0be2dce24715a5f46b129a0ea02b3aab
timeCreated: 1588825065
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/Tutorial System/tutorialUISystem.cs
uploadId: 814740