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_EditorClassIdentifier:
|
||||
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_OnCullStateChanged:
|
||||
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
|
||||
{
|
||||
get { return currentTransport; }
|
||||
@ -36,7 +43,7 @@ public class SelectorBehavior : MonoBehaviour
|
||||
lock (selectionLock)
|
||||
{
|
||||
currentTransport = value;
|
||||
SelectTransports(currentTransport);
|
||||
AlignSelectorWithTransport(currentTransport);
|
||||
UpdatePlayerUIElements();
|
||||
}
|
||||
}
|
||||
@ -51,6 +58,7 @@ public class SelectorBehavior : MonoBehaviour
|
||||
set
|
||||
{
|
||||
_selected = value;
|
||||
lastInput = DateTime.Now;
|
||||
SelectedChanged();
|
||||
}
|
||||
}
|
||||
@ -59,6 +67,7 @@ public class SelectorBehavior : MonoBehaviour
|
||||
|
||||
#region public fields
|
||||
public bool Player2;
|
||||
public int InputDelay = 200;
|
||||
public int Padding;
|
||||
public Transform TransportsPanel;
|
||||
public Transform PlayerPanel;
|
||||
@ -71,28 +80,18 @@ public class SelectorBehavior : MonoBehaviour
|
||||
public string CancelButtonName;
|
||||
#endregion
|
||||
|
||||
#region Behavior overrided methods
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
selectionLock = new object();
|
||||
lastInput = DateTime.Now.AddSeconds(1.5);
|
||||
//3E00FFFF
|
||||
InitGameObjectImage();
|
||||
}
|
||||
|
||||
private void InitGameObjectImage()
|
||||
{
|
||||
_gameObjectImage = transform.GetChild(0).gameObject.GetComponent<Image>();
|
||||
if (_gameObjectImage != null)
|
||||
{
|
||||
_gameObjectImage.sprite = SelectorImage;
|
||||
_gameObjectImage.color = SelectorColor;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRenderObject()
|
||||
{
|
||||
if (transports == null)
|
||||
InitializedTransportsList();
|
||||
if (transports == null) InitializedTransportsList();
|
||||
if (PlayerPanel != 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()
|
||||
{
|
||||
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)
|
||||
{
|
||||
@ -141,17 +158,12 @@ public class SelectorBehavior : MonoBehaviour
|
||||
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
HandleInputs();
|
||||
}
|
||||
|
||||
|
||||
private void HandleInputs()
|
||||
{
|
||||
if (transports == null || LaunchGameScript.Current.Launching) return;
|
||||
if (IsSpawned || transports == null || LaunchGameScript.Current.Launching) return;
|
||||
if (!string.IsNullOrEmpty(VerticalAxisName) && !Selected)
|
||||
{
|
||||
var verticalAxis = Input.GetAxis(VerticalAxisName);
|
||||
@ -189,12 +201,13 @@ public class SelectorBehavior : MonoBehaviour
|
||||
{
|
||||
if (Selected)
|
||||
Selected = false;
|
||||
//else if (StartupScript.Current != null)
|
||||
// StartupScript.Current.Display(0, 1);
|
||||
else if (StartupScript.Current != null)
|
||||
StartupScript.Current.Display(0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Move selector
|
||||
private static bool? IsPositiveMove(float axis)
|
||||
{
|
||||
bool? move = null;
|
||||
@ -202,7 +215,6 @@ public class SelectorBehavior : MonoBehaviour
|
||||
else if (axis == -1) move = false;
|
||||
return move;
|
||||
}
|
||||
|
||||
private void MoveVertical(bool positive)
|
||||
{
|
||||
var value = GetCurrentTransportIndex;
|
||||
@ -213,6 +225,7 @@ public class SelectorBehavior : MonoBehaviour
|
||||
//if (positive) value += 1;
|
||||
//else value -= 1;
|
||||
//if (value > transports.Count - 1) value -= transports.Count - 1;
|
||||
lastInput = DateTime.Now;
|
||||
CurrentTransport = transports[value];
|
||||
}
|
||||
|
||||
@ -222,9 +235,13 @@ public class SelectorBehavior : MonoBehaviour
|
||||
|
||||
if (positive) 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];
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void SelectedChanged()
|
||||
{
|
||||
|
@ -108,7 +108,7 @@ InputManager:
|
||||
negativeButton:
|
||||
positiveButton: joystick 1 button 0
|
||||
altNegativeButton:
|
||||
altPositiveButton:
|
||||
altPositiveButton: space
|
||||
gravity: 1000
|
||||
dead: 0.001
|
||||
sensitivity: 1000
|
||||
@ -124,7 +124,7 @@ InputManager:
|
||||
negativeButton:
|
||||
positiveButton: joystick 1 button 1
|
||||
altNegativeButton:
|
||||
altPositiveButton:
|
||||
altPositiveButton: left ctrl
|
||||
gravity: 1000
|
||||
dead: 0.001
|
||||
sensitivity: 1000
|
||||
@ -172,7 +172,7 @@ InputManager:
|
||||
negativeButton:
|
||||
positiveButton: joystick 2 button 0
|
||||
altNegativeButton:
|
||||
altPositiveButton: space
|
||||
altPositiveButton: return
|
||||
gravity: 1000
|
||||
dead: 0.001
|
||||
sensitivity: 1000
|
||||
@ -188,7 +188,7 @@ InputManager:
|
||||
negativeButton:
|
||||
positiveButton: joystick 2 button 1
|
||||
altNegativeButton:
|
||||
altPositiveButton: space
|
||||
altPositiveButton: right ctrl
|
||||
gravity: 1000
|
||||
dead: 0.001
|
||||
sensitivity: 1000
|
||||
@ -197,3 +197,67 @@ InputManager:
|
||||
type: 0
|
||||
axis: 1
|
||||
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