add ckg
plantilla base para movimiento básico
This commit is contained in:
@@ -0,0 +1,235 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class infoPanelOnScreenSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool infoPanelEnabled = true;
|
||||
|
||||
public bool showPanelInfoOnlyFirstTime;
|
||||
|
||||
[Space]
|
||||
[Header ("Panel Detection Settings")]
|
||||
[Space]
|
||||
|
||||
public List<string> tagsToCheck = new List<string> ();
|
||||
public LayerMask layermaskToCheck;
|
||||
|
||||
public Transform objectToFollow;
|
||||
|
||||
[Space]
|
||||
[Header ("Name Text Settings")]
|
||||
[Space]
|
||||
|
||||
public bool usePanelNameText;
|
||||
public string panelNameText;
|
||||
|
||||
[Space]
|
||||
[Header ("Image Settings")]
|
||||
[Space]
|
||||
|
||||
public bool setImageOnPanel;
|
||||
public Texture imageOnPanel;
|
||||
|
||||
[Space]
|
||||
[Header ("Panel Type Settings")]
|
||||
[Space]
|
||||
|
||||
public string panelName = "Default";
|
||||
|
||||
[TextArea (3, 10)] public string panelNameExplanation = "There are 4 types so far, but you can add any amount of panel info types: \n" +
|
||||
"Little, Default, Big, Large and Extra Large";
|
||||
|
||||
[Space]
|
||||
[Header ("Panel Text Settings")]
|
||||
[Space]
|
||||
|
||||
[TextArea (8, 15)] public string panelOnScreenText;
|
||||
|
||||
public string includedActionNameOnText;
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
[TextArea (3, 10)] public string explanation = "Write -ACTION NAME- in the field Panel On Screen Text where you want to place the" +
|
||||
"key used for an action. For example, by default, Jump will show 'Space";
|
||||
|
||||
[Space]
|
||||
[Header ("Panel Position Settings")]
|
||||
[Space]
|
||||
|
||||
public Vector3 panelOffset;
|
||||
|
||||
public bool useFixedPanelPosition;
|
||||
|
||||
public bool useSeparatedTransformForEveryView;
|
||||
public Transform transformForThirdPerson;
|
||||
public Transform transformForFirstPerson;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool removeDeviceFromPlayerListOnMaxDistance;
|
||||
public float maxDistanceToRemoveDeviceFromPlayerList;
|
||||
|
||||
[Space]
|
||||
[Header ("Gizmo Settings")]
|
||||
[Space]
|
||||
|
||||
public bool showGizmo;
|
||||
public Color gizmoLabelColor = Color.green;
|
||||
public Color gizmoColor = Color.white;
|
||||
public float gizmoRadius = 0.3f;
|
||||
|
||||
|
||||
List<GameObject> playerFoundList = new List<GameObject> ();
|
||||
|
||||
GameObject currentPlayer;
|
||||
|
||||
|
||||
void OnTriggerEnter (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, true);
|
||||
}
|
||||
|
||||
void OnTriggerExit (Collider col)
|
||||
{
|
||||
checkTriggerInfo (col, false);
|
||||
}
|
||||
|
||||
public void checkTriggerInfo (Collider col, bool isEnter)
|
||||
{
|
||||
if (!infoPanelEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((1 << col.gameObject.layer & layermaskToCheck.value) == 1 << col.gameObject.layer) {
|
||||
|
||||
if (isEnter) {
|
||||
|
||||
if (tagsToCheck.Contains (col.tag)) {
|
||||
|
||||
if (!playerFoundList.Contains (col.gameObject)) {
|
||||
playerFoundList.Add (col.gameObject);
|
||||
}
|
||||
|
||||
currentPlayer = col.gameObject;
|
||||
|
||||
enableOrdisablePanelInfoFromPlayer (currentPlayer, true);
|
||||
}
|
||||
} else {
|
||||
|
||||
//if the player is leaving the trigger
|
||||
if (tagsToCheck.Contains (col.tag)) {
|
||||
//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);
|
||||
}
|
||||
|
||||
enableOrdisablePanelInfoFromPlayer (col.gameObject, false);
|
||||
|
||||
if (playerFoundList.Count == 0) {
|
||||
currentPlayer = null;
|
||||
|
||||
if (showPanelInfoOnlyFirstTime) {
|
||||
disablePanelText ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void disablePanelText ()
|
||||
{
|
||||
if (playerFoundList.Count > 0) {
|
||||
for (int i = 0; i < playerFoundList.Count; i++) {
|
||||
enableOrdisablePanelInfoFromPlayer (playerFoundList [i], false);
|
||||
}
|
||||
|
||||
infoPanelEnabled = false;
|
||||
|
||||
gameObject.SetActive (false);
|
||||
}
|
||||
}
|
||||
|
||||
public void enableOrdisablePanelInfoFromPlayer (GameObject playerToCheck, bool enablePanel)
|
||||
{
|
||||
playerComponentsManager currentPlayerComponentsManager = playerToCheck.GetComponent<playerComponentsManager> ();
|
||||
|
||||
if (currentPlayerComponentsManager != null) {
|
||||
|
||||
playerInfoPanelOnScreenSystem currentPlayerInfoPanelOnScreenSystem = currentPlayerComponentsManager.getPlayerInfoPanelOnScreenSystem ();
|
||||
|
||||
if (currentPlayerInfoPanelOnScreenSystem != null) {
|
||||
|
||||
if (objectToFollow == null) {
|
||||
objectToFollow = transform;
|
||||
}
|
||||
|
||||
if (enablePanel) {
|
||||
currentPlayerInfoPanelOnScreenSystem.getNewPanelInfo (this);
|
||||
} else {
|
||||
currentPlayerInfoPanelOnScreenSystem.disablePanelInfo (objectToFollow);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void disablePanelInfoFromAllPlayersRemotely ()
|
||||
{
|
||||
if (playerFoundList.Count > 0) {
|
||||
for (int i = 0; i < playerFoundList.Count; i++) {
|
||||
enableOrdisablePanelInfoFromPlayer (playerFoundList [i], false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 + panelOffset;
|
||||
|
||||
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 (objectToFollow != null) {
|
||||
gizmoPosition = objectToFollow.position;
|
||||
} else {
|
||||
gizmoPosition = transform.position;
|
||||
}
|
||||
|
||||
Gizmos.DrawSphere (gizmoPosition, gizmoRadius);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c7ddf5f2dc715384883e89753937ffb4
|
||||
timeCreated: 1571933503
|
||||
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/Panel Info System/infoPanelOnScreenSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,442 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using GKC.Localization;
|
||||
|
||||
public class playerInfoPanelOnScreenSystem : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool panelOnScreenEnabled = true;
|
||||
|
||||
public bool useFadePanel;
|
||||
public float fadeOnPanelSpeed;
|
||||
public float fadeOffPanelSpeed;
|
||||
|
||||
public string actionNameField = "-ACTION NAME-";
|
||||
|
||||
[Space]
|
||||
[Header ("Panel GameObject List")]
|
||||
[Space]
|
||||
|
||||
public List<infoPanel> panelGameObjectList = new List<infoPanel> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public List<Transform> panelTransformFoundList = new List<Transform> ();
|
||||
public List<infoPanelOnScreenSystem> infoPanelOnScreenSystemList = new List<infoPanelOnScreenSystem> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Components")]
|
||||
[Space]
|
||||
|
||||
public Camera mainCamera;
|
||||
|
||||
public playerCamera mainPlayerCamera;
|
||||
|
||||
public playerInputManager playerInput;
|
||||
|
||||
|
||||
Text panelText;
|
||||
|
||||
RawImage currentPanelImage;
|
||||
|
||||
Text currentPanelNameText;
|
||||
|
||||
GameObject panelGameObject;
|
||||
|
||||
RectTransform panelRectTransform;
|
||||
|
||||
bool useFixedPanelPosition;
|
||||
|
||||
Transform fixedPanelPosition;
|
||||
|
||||
bool useSeparatedTransformForEveryView;
|
||||
Transform transformForThirdPerson;
|
||||
Transform transformForFirstPerson;
|
||||
|
||||
bool removeDeviceFromPlayerListOnMaxDistance;
|
||||
float maxDistanceToRemoveDeviceFromPlayerList;
|
||||
|
||||
Vector3 panelOffset;
|
||||
|
||||
bool targetOnScreen;
|
||||
Vector2 mainCanvasSizeDelta;
|
||||
Vector2 halfMainCanvasSizeDelta;
|
||||
|
||||
Vector2 iconPosition2d;
|
||||
bool usingScreenSpaceCamera;
|
||||
|
||||
bool showPanelInfoActive;
|
||||
|
||||
Vector3 screenPoint;
|
||||
|
||||
Vector3 currentPanelPosition;
|
||||
|
||||
Transform objectToFollow;
|
||||
|
||||
infoPanel currentInfoPanel;
|
||||
|
||||
float screenWidth;
|
||||
float screenHeight;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
mainCanvasSizeDelta = mainPlayerCamera.getMainCanvasSizeDelta ();
|
||||
halfMainCanvasSizeDelta = mainCanvasSizeDelta * 0.5f;
|
||||
usingScreenSpaceCamera = mainPlayerCamera.isUsingScreenSpaceCamera ();
|
||||
}
|
||||
|
||||
Coroutine updateCoroutine;
|
||||
|
||||
public void stopUpdateCoroutine ()
|
||||
{
|
||||
if (updateCoroutine != null) {
|
||||
StopCoroutine (updateCoroutine);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator updateSystemCoroutine ()
|
||||
{
|
||||
var waitTime = new WaitForSecondsRealtime (0.0001f);
|
||||
|
||||
while (true) {
|
||||
updateSystem ();
|
||||
|
||||
yield return waitTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void updateSystem ()
|
||||
{
|
||||
if (!panelOnScreenEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (showPanelInfoActive) {
|
||||
if (!useFixedPanelPosition) {
|
||||
calculatePanelPosition ();
|
||||
|
||||
if (targetOnScreen) {
|
||||
enableOrDisablePanel (true);
|
||||
} else {
|
||||
enableOrDisablePanel (false);
|
||||
}
|
||||
} else {
|
||||
if (objectToFollow == null) {
|
||||
disablePanelInfo (null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void calculatePanelPosition ()
|
||||
{
|
||||
if (objectToFollow != null) {
|
||||
currentPanelPosition = objectToFollow.position;
|
||||
|
||||
if (useSeparatedTransformForEveryView) {
|
||||
if (mainPlayerCamera.isFirstPersonActive ()) {
|
||||
currentPanelPosition = transformForFirstPerson.position;
|
||||
} else {
|
||||
currentPanelPosition = transformForThirdPerson.position;
|
||||
}
|
||||
}
|
||||
|
||||
currentPanelPosition += panelOffset;
|
||||
|
||||
if (!usingScreenSpaceCamera) {
|
||||
screenWidth = Screen.width;
|
||||
screenHeight = Screen.height;
|
||||
}
|
||||
|
||||
if (usingScreenSpaceCamera) {
|
||||
screenPoint = mainCamera.WorldToViewportPoint (currentPanelPosition);
|
||||
targetOnScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;
|
||||
} else {
|
||||
screenPoint = mainCamera.WorldToScreenPoint (currentPanelPosition);
|
||||
targetOnScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < screenWidth && screenPoint.y > 0 && screenPoint.y < screenHeight;
|
||||
}
|
||||
|
||||
if (usingScreenSpaceCamera) {
|
||||
iconPosition2d = new Vector2 ((screenPoint.x * mainCanvasSizeDelta.x) - halfMainCanvasSizeDelta.x, (screenPoint.y * mainCanvasSizeDelta.y) - halfMainCanvasSizeDelta.y);
|
||||
|
||||
panelRectTransform.anchoredPosition = iconPosition2d;
|
||||
} else {
|
||||
panelGameObject.transform.position = new Vector3 (screenPoint.x, screenPoint.y, 0);
|
||||
}
|
||||
|
||||
if (removeDeviceFromPlayerListOnMaxDistance) {
|
||||
float distanceToObject = GKC_Utils.distance (mainPlayerCamera.transform.position, currentPanelPosition);
|
||||
|
||||
if (distanceToObject > maxDistanceToRemoveDeviceFromPlayerList) {
|
||||
disablePanelInfo (objectToFollow);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
disablePanelInfo (null);
|
||||
}
|
||||
}
|
||||
|
||||
public void getNewPanelInfo (infoPanelOnScreenSystem newInfoPanelOnScreenSystem)
|
||||
{
|
||||
if (!panelOnScreenEnabled || newInfoPanelOnScreenSystem == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainCamera == null) {
|
||||
mainCamera = mainPlayerCamera.getMainCamera ();
|
||||
}
|
||||
|
||||
useSeparatedTransformForEveryView = newInfoPanelOnScreenSystem.useSeparatedTransformForEveryView;
|
||||
transformForThirdPerson = newInfoPanelOnScreenSystem.transformForThirdPerson;
|
||||
transformForFirstPerson = newInfoPanelOnScreenSystem.transformForFirstPerson;
|
||||
|
||||
removeDeviceFromPlayerListOnMaxDistance = newInfoPanelOnScreenSystem.removeDeviceFromPlayerListOnMaxDistance;
|
||||
maxDistanceToRemoveDeviceFromPlayerList = newInfoPanelOnScreenSystem.maxDistanceToRemoveDeviceFromPlayerList;
|
||||
|
||||
objectToFollow = newInfoPanelOnScreenSystem.objectToFollow;
|
||||
|
||||
string newPanelText = newInfoPanelOnScreenSystem.panelOnScreenText;
|
||||
|
||||
if (newPanelText.Contains (actionNameField)) {
|
||||
string keyAction = playerInput.getButtonKey (newInfoPanelOnScreenSystem.includedActionNameOnText);
|
||||
newPanelText = newPanelText.Replace (actionNameField, keyAction);
|
||||
}
|
||||
|
||||
if (!panelTransformFoundList.Contains (objectToFollow)) {
|
||||
panelTransformFoundList.Add (objectToFollow);
|
||||
|
||||
infoPanelOnScreenSystemList.Add (newInfoPanelOnScreenSystem);
|
||||
}
|
||||
|
||||
if (panelGameObject != null && panelGameObject.activeSelf) {
|
||||
panelGameObject.SetActive (false);
|
||||
}
|
||||
|
||||
useFixedPanelPosition = newInfoPanelOnScreenSystem.useFixedPanelPosition;
|
||||
|
||||
bool panelFound = false;
|
||||
|
||||
for (int i = 0; i < panelGameObjectList.Count; i++) {
|
||||
if (panelGameObjectList [i].Name.Equals (newInfoPanelOnScreenSystem.panelName)) {
|
||||
panelText = panelGameObjectList [i].panelText;
|
||||
|
||||
panelGameObject = panelGameObjectList [i].panelGameObject;
|
||||
|
||||
panelRectTransform = panelGameObjectList [i].panelRectTransform;
|
||||
|
||||
panelGameObjectList [i].isActive = true;
|
||||
|
||||
fixedPanelPosition = panelGameObjectList [i].fixedPanelPosition;
|
||||
|
||||
currentPanelImage = panelGameObjectList [i].panelImage;
|
||||
|
||||
currentPanelNameText = panelGameObjectList [i].panelNameText;
|
||||
|
||||
panelFound = true;
|
||||
|
||||
currentInfoPanel = panelGameObjectList [i];
|
||||
} else {
|
||||
panelGameObjectList [i].isActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!panelFound) {
|
||||
print ("WARNING: No panel with the name " + newInfoPanelOnScreenSystem.panelName + " has been found, make sure to configure a panel with that name");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
string newTextContet = getLocalizedText (newPanelText);
|
||||
|
||||
panelText.text = newTextContet;
|
||||
|
||||
panelOffset = newInfoPanelOnScreenSystem.panelOffset;
|
||||
|
||||
if (currentPanelImage != null) {
|
||||
if (currentPanelImage.gameObject.activeSelf != newInfoPanelOnScreenSystem.setImageOnPanel) {
|
||||
currentPanelImage.gameObject.SetActive (newInfoPanelOnScreenSystem.setImageOnPanel);
|
||||
}
|
||||
|
||||
if (newInfoPanelOnScreenSystem.setImageOnPanel) {
|
||||
currentPanelImage.texture = newInfoPanelOnScreenSystem.imageOnPanel;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentPanelNameText != null) {
|
||||
if (currentPanelNameText.gameObject.activeSelf != newInfoPanelOnScreenSystem.usePanelNameText) {
|
||||
currentPanelNameText.gameObject.SetActive (newInfoPanelOnScreenSystem.usePanelNameText);
|
||||
}
|
||||
|
||||
if (newInfoPanelOnScreenSystem.usePanelNameText) {
|
||||
string newNameTextContet = getLocalizedText (newInfoPanelOnScreenSystem.panelNameText);
|
||||
|
||||
currentPanelNameText.text = newNameTextContet;
|
||||
}
|
||||
}
|
||||
|
||||
if (useFixedPanelPosition) {
|
||||
panelGameObject.transform.position = fixedPanelPosition.position;
|
||||
|
||||
if (useFadePanel) {
|
||||
fadePanel (currentInfoPanel, false);
|
||||
}
|
||||
|
||||
enableOrDisablePanel (true);
|
||||
} else {
|
||||
|
||||
calculatePanelPosition ();
|
||||
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate (panelRectTransform);
|
||||
LayoutRebuilder.MarkLayoutForRebuild (panelRectTransform);
|
||||
|
||||
calculatePanelPosition ();
|
||||
|
||||
panelGameObject.SetActive (true);
|
||||
panelGameObject.SetActive (false);
|
||||
|
||||
if (useFadePanel) {
|
||||
fadePanel (currentInfoPanel, false);
|
||||
}
|
||||
}
|
||||
|
||||
showPanelInfoActive = true;
|
||||
|
||||
stopUpdateCoroutine ();
|
||||
|
||||
updateCoroutine = StartCoroutine (updateSystemCoroutine ());
|
||||
}
|
||||
|
||||
string getLocalizedText (string textContent)
|
||||
{
|
||||
if (gameLanguageSelector.isCheckLanguageActive ()) {
|
||||
textContent = interactionObjectsLocalizationManager.GetLocalizedValue (textContent);
|
||||
}
|
||||
|
||||
return textContent;
|
||||
}
|
||||
|
||||
public void disablePanelInfo (Transform newObjectToFollow)
|
||||
{
|
||||
for (int i = panelTransformFoundList.Count - 1; i >= 0; i--) {
|
||||
if (panelTransformFoundList [i] == null) {
|
||||
panelTransformFoundList.RemoveAt (i);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = infoPanelOnScreenSystemList.Count - 1; i >= 0; i--) {
|
||||
if (infoPanelOnScreenSystemList [i] == null) {
|
||||
infoPanelOnScreenSystemList.RemoveAt (i);
|
||||
}
|
||||
}
|
||||
|
||||
if (newObjectToFollow != null) {
|
||||
if (panelTransformFoundList.Contains (newObjectToFollow)) {
|
||||
panelTransformFoundList.Remove (newObjectToFollow);
|
||||
|
||||
int panelIndex = infoPanelOnScreenSystemList.FindIndex (s => s.objectToFollow == newObjectToFollow);
|
||||
|
||||
if (panelIndex > -1) {
|
||||
infoPanelOnScreenSystemList.RemoveAt (panelIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (panelTransformFoundList.Count == 0) {
|
||||
showPanelInfoActive = false;
|
||||
|
||||
stopUpdateCoroutine ();
|
||||
|
||||
if (useFadePanel) {
|
||||
fadePanel (currentInfoPanel, true);
|
||||
} else {
|
||||
enableOrDisablePanel (false);
|
||||
}
|
||||
} else {
|
||||
getNewPanelInfo (infoPanelOnScreenSystemList [0]);
|
||||
}
|
||||
}
|
||||
|
||||
public void enableOrDisablePanel (bool state)
|
||||
{
|
||||
if (panelGameObject != null && panelGameObject.activeSelf != state) {
|
||||
panelGameObject.SetActive (state);
|
||||
}
|
||||
}
|
||||
|
||||
public void fadePanel (infoPanel newInfoPanel, bool fadingPanel)
|
||||
{
|
||||
if (newInfoPanel == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (newInfoPanel.fadePanelCoroutine != null) {
|
||||
StopCoroutine (newInfoPanel.fadePanelCoroutine);
|
||||
}
|
||||
|
||||
newInfoPanel.fadePanelCoroutine = StartCoroutine (fadePanelCoroutine (newInfoPanel, fadingPanel));
|
||||
}
|
||||
|
||||
IEnumerator fadePanelCoroutine (infoPanel newInfoPanel, bool fadingPanel)
|
||||
{
|
||||
float targetValue = 1;
|
||||
|
||||
float fadeSpeed = fadeOffPanelSpeed;
|
||||
|
||||
if (fadingPanel) {
|
||||
targetValue = 0;
|
||||
|
||||
fadeSpeed = fadeOnPanelSpeed;
|
||||
}
|
||||
|
||||
if (!fadingPanel) {
|
||||
if (currentInfoPanel.mainCanvasGroup.alpha == 1) {
|
||||
currentInfoPanel.mainCanvasGroup.alpha = 0;
|
||||
}
|
||||
}
|
||||
|
||||
while (newInfoPanel.mainCanvasGroup.alpha != targetValue) {
|
||||
newInfoPanel.mainCanvasGroup.alpha = Mathf.MoveTowards (newInfoPanel.mainCanvasGroup.alpha, targetValue, Time.deltaTime * fadeSpeed);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
if (fadingPanel) {
|
||||
newInfoPanel.panelGameObject.SetActive (false);
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class infoPanel
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public string Name;
|
||||
public GameObject panelGameObject;
|
||||
public RectTransform panelRectTransform;
|
||||
public Text panelText;
|
||||
|
||||
public RawImage panelImage;
|
||||
|
||||
public Text panelNameText;
|
||||
|
||||
public Transform fixedPanelPosition;
|
||||
|
||||
public CanvasGroup mainCanvasGroup;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool isActive;
|
||||
|
||||
public Coroutine fadePanelCoroutine;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 774c90f9d14353348be3f010fb0783d3
|
||||
timeCreated: 1571933584
|
||||
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/Panel Info System/playerInfoPanelOnScreenSystem.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,117 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class sliderInfoSystem : MonoBehaviour
|
||||
{
|
||||
public bool sliderInfoSystemEnabled = true;
|
||||
|
||||
public List<sliderInfo> sliderInfoList = new List<sliderInfo> ();
|
||||
|
||||
public void activateSliderByName (string sliderName)
|
||||
{
|
||||
if (!sliderInfoSystemEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
int sliderIndex = sliderInfoList.FindIndex (s => s.Name.Equals (sliderName));
|
||||
|
||||
if (sliderIndex > -1) {
|
||||
sliderInfo currentSliderInfo = sliderInfoList [sliderIndex];
|
||||
|
||||
if (currentSliderInfo.sliderInfoEnable) {
|
||||
|
||||
currentSliderInfo.sliderActive = true;
|
||||
|
||||
if (!currentSliderInfo.sliderGameObject.activeSelf) {
|
||||
currentSliderInfo.sliderGameObject.SetActive (true);
|
||||
}
|
||||
|
||||
currentSliderInfo.mainSlider.maxValue = currentSliderInfo.sliderMaxValue;
|
||||
|
||||
if (currentSliderInfo.decreaseSliderValue) {
|
||||
currentSliderInfo.mainSlider.value = currentSliderInfo.sliderMaxValue;
|
||||
} else {
|
||||
currentSliderInfo.mainSlider.value = 0;
|
||||
}
|
||||
|
||||
currentSliderInfo.sliderCoroutine = StartCoroutine (updateUseSliderCoroutine (currentSliderInfo));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void deactivateSliderByName (string sliderName)
|
||||
{
|
||||
if (!sliderInfoSystemEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
int sliderIndex = sliderInfoList.FindIndex (s => s.Name.Equals (sliderName));
|
||||
|
||||
if (sliderIndex > -1) {
|
||||
sliderInfo currentSliderInfo = sliderInfoList [sliderIndex];
|
||||
|
||||
if (currentSliderInfo.sliderInfoEnable) {
|
||||
if (currentSliderInfo.sliderGameObject.activeSelf) {
|
||||
currentSliderInfo.sliderGameObject.SetActive (false);
|
||||
}
|
||||
|
||||
if (currentSliderInfo.sliderCoroutine != null) {
|
||||
StopCoroutine (currentSliderInfo.sliderCoroutine);
|
||||
}
|
||||
|
||||
currentSliderInfo.sliderActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator updateUseSliderCoroutine (sliderInfo currentSliderInfo)
|
||||
{
|
||||
var waitTime = new WaitForFixedUpdate ();
|
||||
|
||||
while (true) {
|
||||
yield return waitTime;
|
||||
|
||||
float sliderValue = 0;
|
||||
|
||||
if (currentSliderInfo.useUnscaledTime) {
|
||||
sliderValue = Time.unscaledDeltaTime;
|
||||
} else {
|
||||
sliderValue = Time.deltaTime;
|
||||
}
|
||||
|
||||
float multiplierSign = 1;
|
||||
|
||||
if (currentSliderInfo.decreaseSliderValue) {
|
||||
multiplierSign = -1;
|
||||
}
|
||||
|
||||
currentSliderInfo.mainSlider.value += sliderValue * currentSliderInfo.useSliderValueRate * multiplierSign;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class sliderInfo
|
||||
{
|
||||
public string Name;
|
||||
|
||||
public bool sliderInfoEnable = true;
|
||||
|
||||
public bool decreaseSliderValue;
|
||||
|
||||
public float sliderMaxValue;
|
||||
|
||||
public float useSliderValueRate;
|
||||
|
||||
public bool useUnscaledTime;
|
||||
|
||||
public bool sliderActive;
|
||||
|
||||
public Coroutine sliderCoroutine;
|
||||
|
||||
public Slider mainSlider;
|
||||
|
||||
public GameObject sliderGameObject;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: abda4573db9440f47abff0138cd7dc27
|
||||
timeCreated: 1645409372
|
||||
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/Panel Info System/sliderInfoSystem.cs
|
||||
uploadId: 814740
|
||||
Reference in New Issue
Block a user