ajout d'une latence (paramétrable via script) sur la récupération
des inputs pour les selector lors du choix du "transport" Ajout input pour les axes des deux joueurs via clavier
This commit is contained in:
parent
e4e6b58654
commit
7ee6e8aa36
@ -2873,7 +2873,7 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
m_Material: {fileID: 0}
|
m_Material: {fileID: 0}
|
||||||
m_Color: {r: 0, g: 0.10196079, b: 0.20784315, a: 1}
|
m_Color: {r: 0, g: 0, b: 0, a: 1}
|
||||||
m_RaycastTarget: 1
|
m_RaycastTarget: 1
|
||||||
m_OnCullStateChanged:
|
m_OnCullStateChanged:
|
||||||
m_PersistentCalls:
|
m_PersistentCalls:
|
||||||
|
|||||||
@ -28,6 +28,13 @@ public class SelectorBehavior : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DateTime lastInput;
|
||||||
|
|
||||||
|
bool IsSpawned
|
||||||
|
{
|
||||||
|
get { return lastInput == null || (DateTime.Now - lastInput).Milliseconds < InputDelay; }
|
||||||
|
}
|
||||||
|
|
||||||
Transform CurrentTransport
|
Transform CurrentTransport
|
||||||
{
|
{
|
||||||
get { return currentTransport; }
|
get { return currentTransport; }
|
||||||
@ -36,7 +43,7 @@ public class SelectorBehavior : MonoBehaviour
|
|||||||
lock (selectionLock)
|
lock (selectionLock)
|
||||||
{
|
{
|
||||||
currentTransport = value;
|
currentTransport = value;
|
||||||
SelectTransports(currentTransport);
|
AlignSelectorWithTransport(currentTransport);
|
||||||
UpdatePlayerUIElements();
|
UpdatePlayerUIElements();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,6 +58,7 @@ public class SelectorBehavior : MonoBehaviour
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
_selected = value;
|
_selected = value;
|
||||||
|
lastInput = DateTime.Now;
|
||||||
SelectedChanged();
|
SelectedChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,6 +67,7 @@ public class SelectorBehavior : MonoBehaviour
|
|||||||
|
|
||||||
#region public fields
|
#region public fields
|
||||||
public bool Player2;
|
public bool Player2;
|
||||||
|
public int InputDelay = 200;
|
||||||
public int Padding;
|
public int Padding;
|
||||||
public Transform TransportsPanel;
|
public Transform TransportsPanel;
|
||||||
public Transform PlayerPanel;
|
public Transform PlayerPanel;
|
||||||
@ -71,28 +80,18 @@ public class SelectorBehavior : MonoBehaviour
|
|||||||
public string CancelButtonName;
|
public string CancelButtonName;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Behavior overrided methods
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
selectionLock = new object();
|
selectionLock = new object();
|
||||||
|
lastInput = DateTime.Now.AddSeconds(1.5);
|
||||||
//3E00FFFF
|
//3E00FFFF
|
||||||
InitGameObjectImage();
|
InitGameObjectImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitGameObjectImage()
|
|
||||||
{
|
|
||||||
_gameObjectImage = transform.GetChild(0).gameObject.GetComponent<Image>();
|
|
||||||
if (_gameObjectImage != null)
|
|
||||||
{
|
|
||||||
_gameObjectImage.sprite = SelectorImage;
|
|
||||||
_gameObjectImage.color = SelectorColor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnRenderObject()
|
private void OnRenderObject()
|
||||||
{
|
{
|
||||||
if (transports == null)
|
if (transports == null) InitializedTransportsList();
|
||||||
InitializedTransportsList();
|
|
||||||
if (PlayerPanel != null)
|
if (PlayerPanel != null)
|
||||||
{
|
{
|
||||||
if (playerPanelImage == null && playerPanelText == null)
|
if (playerPanelImage == null && playerPanelText == null)
|
||||||
@ -104,6 +103,22 @@ public class SelectorBehavior : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
HandleInputs();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private void InitGameObjectImage()
|
||||||
|
{
|
||||||
|
_gameObjectImage = transform.GetChild(0).gameObject.GetComponent<Image>();
|
||||||
|
if (_gameObjectImage != null)
|
||||||
|
{
|
||||||
|
_gameObjectImage.sprite = SelectorImage;
|
||||||
|
_gameObjectImage.color = SelectorColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void InitializedTransportsList()
|
private void InitializedTransportsList()
|
||||||
{
|
{
|
||||||
if (TransportsPanel != null)
|
if (TransportsPanel != null)
|
||||||
@ -116,7 +131,9 @@ public class SelectorBehavior : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SelectTransports(Transform transport)
|
#region Ui
|
||||||
|
|
||||||
|
private void AlignSelectorWithTransport(Transform transport)
|
||||||
{
|
{
|
||||||
if (transport != null)
|
if (transport != null)
|
||||||
{
|
{
|
||||||
@ -141,17 +158,12 @@ public class SelectorBehavior : MonoBehaviour
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
|
||||||
{
|
|
||||||
HandleInputs();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void HandleInputs()
|
private void HandleInputs()
|
||||||
{
|
{
|
||||||
if (transports == null || LaunchGameScript.Current.Launching) return;
|
if (IsSpawned || transports == null || LaunchGameScript.Current.Launching) return;
|
||||||
if (!string.IsNullOrEmpty(VerticalAxisName) && !Selected)
|
if (!string.IsNullOrEmpty(VerticalAxisName) && !Selected)
|
||||||
{
|
{
|
||||||
var verticalAxis = Input.GetAxis(VerticalAxisName);
|
var verticalAxis = Input.GetAxis(VerticalAxisName);
|
||||||
@ -189,12 +201,13 @@ public class SelectorBehavior : MonoBehaviour
|
|||||||
{
|
{
|
||||||
if (Selected)
|
if (Selected)
|
||||||
Selected = false;
|
Selected = false;
|
||||||
//else if (StartupScript.Current != null)
|
else if (StartupScript.Current != null)
|
||||||
// StartupScript.Current.Display(0, 1);
|
StartupScript.Current.Display(0, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Move selector
|
||||||
private static bool? IsPositiveMove(float axis)
|
private static bool? IsPositiveMove(float axis)
|
||||||
{
|
{
|
||||||
bool? move = null;
|
bool? move = null;
|
||||||
@ -202,7 +215,6 @@ public class SelectorBehavior : MonoBehaviour
|
|||||||
else if (axis == -1) move = false;
|
else if (axis == -1) move = false;
|
||||||
return move;
|
return move;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MoveVertical(bool positive)
|
private void MoveVertical(bool positive)
|
||||||
{
|
{
|
||||||
var value = GetCurrentTransportIndex;
|
var value = GetCurrentTransportIndex;
|
||||||
@ -213,6 +225,7 @@ public class SelectorBehavior : MonoBehaviour
|
|||||||
//if (positive) value += 1;
|
//if (positive) value += 1;
|
||||||
//else value -= 1;
|
//else value -= 1;
|
||||||
//if (value > transports.Count - 1) value -= transports.Count - 1;
|
//if (value > transports.Count - 1) value -= transports.Count - 1;
|
||||||
|
lastInput = DateTime.Now;
|
||||||
CurrentTransport = transports[value];
|
CurrentTransport = transports[value];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,9 +235,13 @@ public class SelectorBehavior : MonoBehaviour
|
|||||||
|
|
||||||
if (positive) value++;
|
if (positive) value++;
|
||||||
else value--;
|
else value--;
|
||||||
if (value > transports.Count - 1) value -= transports.Count - 1;
|
if (value < 0) value = transports.Count - 1;
|
||||||
|
if (value > transports.Count - 1) value = 0;
|
||||||
|
|
||||||
|
lastInput = DateTime.Now;
|
||||||
CurrentTransport = transports[value];
|
CurrentTransport = transports[value];
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
private void SelectedChanged()
|
private void SelectedChanged()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -108,7 +108,7 @@ InputManager:
|
|||||||
negativeButton:
|
negativeButton:
|
||||||
positiveButton: joystick 1 button 0
|
positiveButton: joystick 1 button 0
|
||||||
altNegativeButton:
|
altNegativeButton:
|
||||||
altPositiveButton:
|
altPositiveButton: space
|
||||||
gravity: 1000
|
gravity: 1000
|
||||||
dead: 0.001
|
dead: 0.001
|
||||||
sensitivity: 1000
|
sensitivity: 1000
|
||||||
@ -124,7 +124,7 @@ InputManager:
|
|||||||
negativeButton:
|
negativeButton:
|
||||||
positiveButton: joystick 1 button 1
|
positiveButton: joystick 1 button 1
|
||||||
altNegativeButton:
|
altNegativeButton:
|
||||||
altPositiveButton:
|
altPositiveButton: left ctrl
|
||||||
gravity: 1000
|
gravity: 1000
|
||||||
dead: 0.001
|
dead: 0.001
|
||||||
sensitivity: 1000
|
sensitivity: 1000
|
||||||
@ -172,7 +172,7 @@ InputManager:
|
|||||||
negativeButton:
|
negativeButton:
|
||||||
positiveButton: joystick 2 button 0
|
positiveButton: joystick 2 button 0
|
||||||
altNegativeButton:
|
altNegativeButton:
|
||||||
altPositiveButton: space
|
altPositiveButton: return
|
||||||
gravity: 1000
|
gravity: 1000
|
||||||
dead: 0.001
|
dead: 0.001
|
||||||
sensitivity: 1000
|
sensitivity: 1000
|
||||||
@ -188,7 +188,7 @@ InputManager:
|
|||||||
negativeButton:
|
negativeButton:
|
||||||
positiveButton: joystick 2 button 1
|
positiveButton: joystick 2 button 1
|
||||||
altNegativeButton:
|
altNegativeButton:
|
||||||
altPositiveButton: space
|
altPositiveButton: right ctrl
|
||||||
gravity: 1000
|
gravity: 1000
|
||||||
dead: 0.001
|
dead: 0.001
|
||||||
sensitivity: 1000
|
sensitivity: 1000
|
||||||
@ -197,3 +197,67 @@ InputManager:
|
|||||||
type: 0
|
type: 0
|
||||||
axis: 1
|
axis: 1
|
||||||
joyNum: 2
|
joyNum: 2
|
||||||
|
- serializedVersion: 3
|
||||||
|
m_Name: HorizontalP1
|
||||||
|
descriptiveName:
|
||||||
|
descriptiveNegativeName:
|
||||||
|
negativeButton: q
|
||||||
|
positiveButton: d
|
||||||
|
altNegativeButton:
|
||||||
|
altPositiveButton:
|
||||||
|
gravity: 1000
|
||||||
|
dead: 0.001
|
||||||
|
sensitivity: 1000
|
||||||
|
snap: 1
|
||||||
|
invert: 0
|
||||||
|
type: 0
|
||||||
|
axis: 1
|
||||||
|
joyNum: 0
|
||||||
|
- serializedVersion: 3
|
||||||
|
m_Name: VerticalP1
|
||||||
|
descriptiveName:
|
||||||
|
descriptiveNegativeName:
|
||||||
|
negativeButton: s
|
||||||
|
positiveButton: z
|
||||||
|
altNegativeButton:
|
||||||
|
altPositiveButton:
|
||||||
|
gravity: 1000
|
||||||
|
dead: 0.001
|
||||||
|
sensitivity: 1000
|
||||||
|
snap: 1
|
||||||
|
invert: 0
|
||||||
|
type: 0
|
||||||
|
axis: 1
|
||||||
|
joyNum: 0
|
||||||
|
- serializedVersion: 3
|
||||||
|
m_Name: HorizontalP2
|
||||||
|
descriptiveName:
|
||||||
|
descriptiveNegativeName:
|
||||||
|
negativeButton: left
|
||||||
|
positiveButton: right
|
||||||
|
altNegativeButton:
|
||||||
|
altPositiveButton:
|
||||||
|
gravity: 1000
|
||||||
|
dead: 0.001
|
||||||
|
sensitivity: 1000
|
||||||
|
snap: 1
|
||||||
|
invert: 0
|
||||||
|
type: 0
|
||||||
|
axis: 1
|
||||||
|
joyNum: 0
|
||||||
|
- serializedVersion: 3
|
||||||
|
m_Name: VerticalP2
|
||||||
|
descriptiveName:
|
||||||
|
descriptiveNegativeName:
|
||||||
|
negativeButton: down
|
||||||
|
positiveButton: up
|
||||||
|
altNegativeButton:
|
||||||
|
altPositiveButton:
|
||||||
|
gravity: 1000
|
||||||
|
dead: 0.001
|
||||||
|
sensitivity: 1000
|
||||||
|
snap: 1
|
||||||
|
invert: 0
|
||||||
|
type: 0
|
||||||
|
axis: 1
|
||||||
|
joyNum: 0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user