ооооо

This commit is contained in:
Enikeevtimur
2022-04-18 22:37:09 +07:00
parent d911dce62a
commit dfbdf7ad31
1505 changed files with 696529 additions and 513 deletions

View File

@ -0,0 +1,75 @@
using System;
using UnityEngine;
using UnityEngine.EventSystems;
namespace UnityStandardAssets.CrossPlatformInput
{
public class AxisTouchButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
// designed to work in a pair with another axis touch button
// (typically with one having -1 and one having 1 axisValues)
public string axisName = "Horizontal"; // The name of the axis
public float axisValue = 1; // The axis that the value has
public float responseSpeed = 3; // The speed at which the axis touch button responds
public float returnToCentreSpeed = 3; // The speed at which the button will return to its centre
AxisTouchButton m_PairedWith; // Which button this one is paired with
CrossPlatformInputManager.VirtualAxis m_Axis; // A reference to the virtual axis as it is in the cross platform input
void OnEnable()
{
if (!CrossPlatformInputManager.AxisExists(axisName))
{
// if the axis doesnt exist create a new one in cross platform input
m_Axis = new CrossPlatformInputManager.VirtualAxis(axisName);
CrossPlatformInputManager.RegisterVirtualAxis(m_Axis);
}
else
{
m_Axis = CrossPlatformInputManager.VirtualAxisReference(axisName);
}
FindPairedButton();
}
void FindPairedButton()
{
// find the other button witch which this button should be paired
// (it should have the same axisName)
var otherAxisButtons = FindObjectsOfType(typeof(AxisTouchButton)) as AxisTouchButton[];
if (otherAxisButtons != null)
{
for (int i = 0; i < otherAxisButtons.Length; i++)
{
if (otherAxisButtons[i].axisName == axisName && otherAxisButtons[i] != this)
{
m_PairedWith = otherAxisButtons[i];
}
}
}
}
void OnDisable()
{
// The object is disabled so remove it from the cross platform input system
m_Axis.Remove();
}
public void OnPointerDown(PointerEventData data)
{
if (m_PairedWith == null)
{
FindPairedButton();
}
// update the axis and record that the button has been pressed this frame
m_Axis.Update(Mathf.MoveTowards(m_Axis.GetValue, axisValue, responseSpeed * Time.deltaTime));
}
public void OnPointerUp(PointerEventData data)
{
m_Axis.Update(Mathf.MoveTowards(m_Axis.GetValue, 0, responseSpeed * Time.deltaTime));
}
}
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 9ab98b66288df7b4fa182075f2f12bd6
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@ -0,0 +1,50 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.CrossPlatformInput
{
public class ButtonHandler : MonoBehaviour
{
public string Name;
void OnEnable()
{
}
public void SetDownState()
{
CrossPlatformInputManager.SetButtonDown(Name);
}
public void SetUpState()
{
CrossPlatformInputManager.SetButtonUp(Name);
}
public void SetAxisPositiveState()
{
CrossPlatformInputManager.SetAxisPositive(Name);
}
public void SetAxisNeutralState()
{
CrossPlatformInputManager.SetAxisZero(Name);
}
public void SetAxisNegativeState()
{
CrossPlatformInputManager.SetAxisNegative(Name);
}
public void Update()
{
}
}
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 85bf3be603548374ca46f521a3aa7fda
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@ -0,0 +1,318 @@
using System;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput.PlatformSpecific;
namespace UnityStandardAssets.CrossPlatformInput
{
public static class CrossPlatformInputManager
{
public enum ActiveInputMethod
{
Hardware,
Touch
}
private static VirtualInput activeInput;
private static VirtualInput s_TouchInput;
private static VirtualInput s_HardwareInput;
static CrossPlatformInputManager()
{
s_TouchInput = new MobileInput();
s_HardwareInput = new StandaloneInput();
#if MOBILE_INPUT
activeInput = s_TouchInput;
#else
activeInput = s_HardwareInput;
#endif
}
public static void SwitchActiveInputMethod(ActiveInputMethod activeInputMethod)
{
switch (activeInputMethod)
{
case ActiveInputMethod.Hardware:
activeInput = s_HardwareInput;
break;
case ActiveInputMethod.Touch:
activeInput = s_TouchInput;
break;
}
}
public static bool AxisExists(string name)
{
return activeInput.AxisExists(name);
}
public static bool ButtonExists(string name)
{
return activeInput.ButtonExists(name);
}
public static void RegisterVirtualAxis(VirtualAxis axis)
{
activeInput.RegisterVirtualAxis(axis);
}
public static void RegisterVirtualButton(VirtualButton button)
{
activeInput.RegisterVirtualButton(button);
}
public static void UnRegisterVirtualAxis(string name)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
activeInput.UnRegisterVirtualAxis(name);
}
public static void UnRegisterVirtualButton(string name)
{
activeInput.UnRegisterVirtualButton(name);
}
// returns a reference to a named virtual axis if it exists otherwise null
public static VirtualAxis VirtualAxisReference(string name)
{
return activeInput.VirtualAxisReference(name);
}
// returns the platform appropriate axis for the given name
public static float GetAxis(string name)
{
return GetAxis(name, false);
}
public static float GetAxisRaw(string name)
{
return GetAxis(name, true);
}
// private function handles both types of axis (raw and not raw)
private static float GetAxis(string name, bool raw)
{
return activeInput.GetAxis(name, raw);
}
// -- Button handling --
public static bool GetButton(string name)
{
return activeInput.GetButton(name);
}
public static bool GetButtonDown(string name)
{
return activeInput.GetButtonDown(name);
}
public static bool GetButtonUp(string name)
{
return activeInput.GetButtonUp(name);
}
public static void SetButtonDown(string name)
{
activeInput.SetButtonDown(name);
}
public static void SetButtonUp(string name)
{
activeInput.SetButtonUp(name);
}
public static void SetAxisPositive(string name)
{
activeInput.SetAxisPositive(name);
}
public static void SetAxisNegative(string name)
{
activeInput.SetAxisNegative(name);
}
public static void SetAxisZero(string name)
{
activeInput.SetAxisZero(name);
}
public static void SetAxis(string name, float value)
{
activeInput.SetAxis(name, value);
}
public static Vector3 mousePosition
{
get { return activeInput.MousePosition(); }
}
public static void SetVirtualMousePositionX(float f)
{
activeInput.SetVirtualMousePositionX(f);
}
public static void SetVirtualMousePositionY(float f)
{
activeInput.SetVirtualMousePositionY(f);
}
public static void SetVirtualMousePositionZ(float f)
{
activeInput.SetVirtualMousePositionZ(f);
}
// virtual axis and button classes - applies to mobile input
// Can be mapped to touch joysticks, tilt, gyro, etc, depending on desired implementation.
// Could also be implemented by other input devices - kinect, electronic sensors, etc
public class VirtualAxis
{
public string name { get; private set; }
private float m_Value;
public bool matchWithInputManager { get; private set; }
public VirtualAxis(string name)
: this(name, true)
{
}
public VirtualAxis(string name, bool matchToInputSettings)
{
this.name = name;
matchWithInputManager = matchToInputSettings;
}
// removes an axes from the cross platform input system
public void Remove()
{
UnRegisterVirtualAxis(name);
}
// a controller gameobject (eg. a virtual thumbstick) should update this class
public void Update(float value)
{
m_Value = value;
}
public float GetValue
{
get { return m_Value; }
}
public float GetValueRaw
{
get { return m_Value; }
}
}
// a controller gameobject (eg. a virtual GUI button) should call the
// 'pressed' function of this class. Other objects can then read the
// Get/Down/Up state of this button.
public class VirtualButton
{
public string name { get; private set; }
public bool matchWithInputManager { get; private set; }
private int m_LastPressedFrame = -5;
private int m_ReleasedFrame = -5;
private bool m_Pressed;
public VirtualButton(string name)
: this(name, true)
{
}
public VirtualButton(string name, bool matchToInputSettings)
{
this.name = name;
matchWithInputManager = matchToInputSettings;
}
// A controller gameobject should call this function when the button is pressed down
public void Pressed()
{
if (m_Pressed)
{
return;
}
m_Pressed = true;
m_LastPressedFrame = Time.frameCount;
}
// A controller gameobject should call this function when the button is released
public void Released()
{
m_Pressed = false;
m_ReleasedFrame = Time.frameCount;
}
// the controller gameobject should call Remove when the button is destroyed or disabled
public void Remove()
{
UnRegisterVirtualButton(name);
}
// these are the states of the button which can be read via the cross platform input system
public bool GetButton
{
get { return m_Pressed; }
}
public bool GetButtonDown
{
get
{
return m_LastPressedFrame - Time.frameCount == -1;
}
}
public bool GetButtonUp
{
get
{
return (m_ReleasedFrame == Time.frameCount - 1);
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6ac1ce5a5adfd9f46adbf5b6f752a47c
labels:
- Done
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: -1010
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@ -0,0 +1,17 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.CrossPlatformInput
{
public class InputAxisScrollbar : MonoBehaviour
{
public string axis;
void Update() { }
public void HandleInput(float value)
{
CrossPlatformInputManager.SetAxis(axis, (value*2f) - 1f);
}
}
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 7d3269566d48b8447bb48d2259e28f8b
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@ -0,0 +1,118 @@
using System;
using UnityEngine;
using UnityEngine.EventSystems;
namespace UnityStandardAssets.CrossPlatformInput
{
public class Joystick : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler
{
public enum AxisOption
{
// Options for which axes to use
Both, // Use both
OnlyHorizontal, // Only horizontal
OnlyVertical // Only vertical
}
public int MovementRange = 100;
public AxisOption axesToUse = AxisOption.Both; // The options for the axes that the still will use
public string horizontalAxisName = "Horizontal"; // The name given to the horizontal axis for the cross platform input
public string verticalAxisName = "Vertical"; // The name given to the vertical axis for the cross platform input
Vector3 m_StartPos;
bool m_UseX; // Toggle for using the x axis
bool m_UseY; // Toggle for using the Y axis
CrossPlatformInputManager.VirtualAxis m_HorizontalVirtualAxis; // Reference to the joystick in the cross platform input
CrossPlatformInputManager.VirtualAxis m_VerticalVirtualAxis; // Reference to the joystick in the cross platform input
void OnEnable()
{
CreateVirtualAxes();
}
void Start()
{
m_StartPos = transform.position;
}
void UpdateVirtualAxes(Vector3 value)
{
var delta = m_StartPos - value;
delta.y = -delta.y;
delta /= MovementRange;
if (m_UseX)
{
m_HorizontalVirtualAxis.Update(-delta.x);
}
if (m_UseY)
{
m_VerticalVirtualAxis.Update(delta.y);
}
}
void CreateVirtualAxes()
{
// set axes to use
m_UseX = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyHorizontal);
m_UseY = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyVertical);
// create new axes based on axes to use
if (m_UseX)
{
m_HorizontalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(horizontalAxisName);
CrossPlatformInputManager.RegisterVirtualAxis(m_HorizontalVirtualAxis);
}
if (m_UseY)
{
m_VerticalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(verticalAxisName);
CrossPlatformInputManager.RegisterVirtualAxis(m_VerticalVirtualAxis);
}
}
public void OnDrag(PointerEventData data)
{
Vector3 newPos = Vector3.zero;
if (m_UseX)
{
int delta = (int)(data.position.x - m_StartPos.x);
delta = Mathf.Clamp(delta, - MovementRange, MovementRange);
newPos.x = delta;
}
if (m_UseY)
{
int delta = (int)(data.position.y - m_StartPos.y);
delta = Mathf.Clamp(delta, -MovementRange, MovementRange);
newPos.y = delta;
}
transform.position = new Vector3(m_StartPos.x + newPos.x, m_StartPos.y + newPos.y, m_StartPos.z + newPos.z);
UpdateVirtualAxes(transform.position);
}
public void OnPointerUp(PointerEventData data)
{
transform.position = m_StartPos;
UpdateVirtualAxes(m_StartPos);
}
public void OnPointerDown(PointerEventData data) { }
void OnDisable()
{
// remove the joysticks from the cross platform input
if (m_UseX)
{
m_HorizontalVirtualAxis.Remove();
}
if (m_UseY)
{
m_VerticalVirtualAxis.Remove();
}
}
}
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 00c3c865782347f41b6358d9fba14b48
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@ -0,0 +1,102 @@
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
namespace UnityStandardAssets.CrossPlatformInput
{
[ExecuteInEditMode]
public class MobileControlRig : MonoBehaviour
#if UNITY_EDITOR
, UnityEditor.Build.IActiveBuildTargetChanged
#endif
{
// this script enables or disables the child objects of a control rig
// depending on whether the USE_MOBILE_INPUT define is declared.
// This define is set or unset by a menu item that is included with
// the Cross Platform Input package.
#if !UNITY_EDITOR
void OnEnable()
{
CheckEnableControlRig();
}
#else
public int callbackOrder
{
get
{
return 1;
}
}
#endif
private void Start()
{
#if UNITY_EDITOR
if (Application.isPlaying) //if in the editor, need to check if we are playing, as start is also called just after exiting play
#endif
{
UnityEngine.EventSystems.EventSystem system = GameObject.FindObjectOfType<UnityEngine.EventSystems.EventSystem>();
if (system == null)
{//the scene have no event system, spawn one
GameObject o = new GameObject("EventSystem");
o.AddComponent<UnityEngine.EventSystems.EventSystem>();
o.AddComponent<UnityEngine.EventSystems.StandaloneInputModule>();
}
}
}
#if UNITY_EDITOR
private void OnEnable()
{
EditorApplication.update += Update;
}
private void OnDisable()
{
EditorApplication.update -= Update;
}
private void Update()
{
CheckEnableControlRig();
}
#endif
private void CheckEnableControlRig()
{
#if MOBILE_INPUT
EnableControlRig(true);
#else
EnableControlRig(false);
#endif
}
private void EnableControlRig(bool enabled)
{
foreach (Transform t in transform)
{
t.gameObject.SetActive(enabled);
}
}
#if UNITY_EDITOR
public void OnActiveBuildTargetChanged(BuildTarget previousTarget, BuildTarget newTarget)
{
CheckEnableControlRig();
}
#endif
}
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 71398ce7fbc3a5b4fa50b50bd54317a7
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 0bc72db1e9dcb9647818df5a07871127
folderAsset: yes
timeCreated: 1436977288
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,133 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.CrossPlatformInput.PlatformSpecific
{
public class MobileInput : VirtualInput
{
private void AddButton(string name)
{
// we have not registered this button yet so add it, happens in the constructor
CrossPlatformInputManager.RegisterVirtualButton(new CrossPlatformInputManager.VirtualButton(name));
}
private void AddAxes(string name)
{
// we have not registered this button yet so add it, happens in the constructor
CrossPlatformInputManager.RegisterVirtualAxis(new CrossPlatformInputManager.VirtualAxis(name));
}
public override float GetAxis(string name, bool raw)
{
if (!m_VirtualAxes.ContainsKey(name))
{
AddAxes(name);
}
return m_VirtualAxes[name].GetValue;
}
public override void SetButtonDown(string name)
{
if (!m_VirtualButtons.ContainsKey(name))
{
AddButton(name);
}
m_VirtualButtons[name].Pressed();
}
public override void SetButtonUp(string name)
{
if (!m_VirtualButtons.ContainsKey(name))
{
AddButton(name);
}
m_VirtualButtons[name].Released();
}
public override void SetAxisPositive(string name)
{
if (!m_VirtualAxes.ContainsKey(name))
{
AddAxes(name);
}
m_VirtualAxes[name].Update(1f);
}
public override void SetAxisNegative(string name)
{
if (!m_VirtualAxes.ContainsKey(name))
{
AddAxes(name);
}
m_VirtualAxes[name].Update(-1f);
}
public override void SetAxisZero(string name)
{
if (!m_VirtualAxes.ContainsKey(name))
{
AddAxes(name);
}
m_VirtualAxes[name].Update(0f);
}
public override void SetAxis(string name, float value)
{
if (!m_VirtualAxes.ContainsKey(name))
{
AddAxes(name);
}
m_VirtualAxes[name].Update(value);
}
public override bool GetButtonDown(string name)
{
if (m_VirtualButtons.ContainsKey(name))
{
return m_VirtualButtons[name].GetButtonDown;
}
AddButton(name);
return m_VirtualButtons[name].GetButtonDown;
}
public override bool GetButtonUp(string name)
{
if (m_VirtualButtons.ContainsKey(name))
{
return m_VirtualButtons[name].GetButtonUp;
}
AddButton(name);
return m_VirtualButtons[name].GetButtonUp;
}
public override bool GetButton(string name)
{
if (m_VirtualButtons.ContainsKey(name))
{
return m_VirtualButtons[name].GetButton;
}
AddButton(name);
return m_VirtualButtons[name].GetButton;
}
public override Vector3 MousePosition()
{
return virtualMousePosition;
}
}
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 9703d53e47195aa4190acd11369ccd1b
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@ -0,0 +1,79 @@
using System;
using UnityEngine;
namespace UnityStandardAssets.CrossPlatformInput.PlatformSpecific
{
public class StandaloneInput : VirtualInput
{
public override float GetAxis(string name, bool raw)
{
return raw ? Input.GetAxisRaw(name) : Input.GetAxis(name);
}
public override bool GetButton(string name)
{
return Input.GetButton(name);
}
public override bool GetButtonDown(string name)
{
return Input.GetButtonDown(name);
}
public override bool GetButtonUp(string name)
{
return Input.GetButtonUp(name);
}
public override void SetButtonDown(string name)
{
throw new Exception(
" This is not possible to be called for standalone input. Please check your platform and code where this is called");
}
public override void SetButtonUp(string name)
{
throw new Exception(
" This is not possible to be called for standalone input. Please check your platform and code where this is called");
}
public override void SetAxisPositive(string name)
{
throw new Exception(
" This is not possible to be called for standalone input. Please check your platform and code where this is called");
}
public override void SetAxisNegative(string name)
{
throw new Exception(
" This is not possible to be called for standalone input. Please check your platform and code where this is called");
}
public override void SetAxisZero(string name)
{
throw new Exception(
" This is not possible to be called for standalone input. Please check your platform and code where this is called");
}
public override void SetAxis(string name, float value)
{
throw new Exception(
" This is not possible to be called for standalone input. Please check your platform and code where this is called");
}
public override Vector3 MousePosition()
{
return Input.mousePosition;
}
}
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 9961032f4f02c4f41997c3ea399d2f22
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@ -0,0 +1,145 @@
using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace UnityStandardAssets.CrossPlatformInput
{
// helps with managing tilt input on mobile devices
public class TiltInput : MonoBehaviour
{
// options for the various orientations
public enum AxisOptions
{
ForwardAxis,
SidewaysAxis,
}
[Serializable]
public class AxisMapping
{
public enum MappingType
{
NamedAxis,
MousePositionX,
MousePositionY,
MousePositionZ
};
public MappingType type;
public string axisName;
}
public AxisMapping mapping;
public AxisOptions tiltAroundAxis = AxisOptions.ForwardAxis;
public float fullTiltAngle = 25;
public float centreAngleOffset = 0;
private CrossPlatformInputManager.VirtualAxis m_SteerAxis;
private void OnEnable()
{
if (mapping.type == AxisMapping.MappingType.NamedAxis)
{
m_SteerAxis = new CrossPlatformInputManager.VirtualAxis(mapping.axisName);
CrossPlatformInputManager.RegisterVirtualAxis(m_SteerAxis);
}
}
private void Update()
{
float angle = 0;
if (Input.acceleration != Vector3.zero)
{
switch (tiltAroundAxis)
{
case AxisOptions.ForwardAxis:
angle = Mathf.Atan2(Input.acceleration.x, -Input.acceleration.y)*Mathf.Rad2Deg +
centreAngleOffset;
break;
case AxisOptions.SidewaysAxis:
angle = Mathf.Atan2(Input.acceleration.z, -Input.acceleration.y)*Mathf.Rad2Deg +
centreAngleOffset;
break;
}
}
float axisValue = Mathf.InverseLerp(-fullTiltAngle, fullTiltAngle, angle)*2 - 1;
switch (mapping.type)
{
case AxisMapping.MappingType.NamedAxis:
m_SteerAxis.Update(axisValue);
break;
case AxisMapping.MappingType.MousePositionX:
CrossPlatformInputManager.SetVirtualMousePositionX(axisValue*Screen.width);
break;
case AxisMapping.MappingType.MousePositionY:
CrossPlatformInputManager.SetVirtualMousePositionY(axisValue*Screen.width);
break;
case AxisMapping.MappingType.MousePositionZ:
CrossPlatformInputManager.SetVirtualMousePositionZ(axisValue*Screen.width);
break;
}
}
private void OnDisable()
{
m_SteerAxis.Remove();
}
}
}
namespace UnityStandardAssets.CrossPlatformInput.Inspector
{
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof (TiltInput.AxisMapping))]
public class TiltInputAxisStylePropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
float x = position.x;
float y = position.y;
float inspectorWidth = position.width;
// Don't make child fields be indented
var indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
var props = new[] {"type", "axisName"};
var widths = new[] {.4f, .6f};
if (property.FindPropertyRelative("type").enumValueIndex > 0)
{
// hide name if not a named axis
props = new[] {"type"};
widths = new[] {1f};
}
const float lineHeight = 18;
for (int n = 0; n < props.Length; ++n)
{
float w = widths[n]*inspectorWidth;
// Calculate rects
Rect rect = new Rect(x, y, w, lineHeight);
x += w;
EditorGUI.PropertyField(rect, property.FindPropertyRelative(props[n]), GUIContent.none);
}
// Set indent back to what it was
EditorGUI.indentLevel = indent;
EditorGUI.EndProperty();
}
}
#endif
}

View File

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 5c2d84226fbbaf94e9c1451f1c39b06a
labels:
- Not
- Fully
- Implemented
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: -1001
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@ -0,0 +1,156 @@
using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace UnityStandardAssets.CrossPlatformInput
{
[RequireComponent(typeof(Image))]
public class TouchPad : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
// Options for which axes to use
public enum AxisOption
{
Both, // Use both
OnlyHorizontal, // Only horizontal
OnlyVertical // Only vertical
}
public enum ControlStyle
{
Absolute, // operates from teh center of the image
Relative, // operates from the center of the initial touch
Swipe, // swipe to touch touch no maintained center
}
public AxisOption axesToUse = AxisOption.Both; // The options for the axes that the still will use
public ControlStyle controlStyle = ControlStyle.Absolute; // control style to use
public string horizontalAxisName = "Horizontal"; // The name given to the horizontal axis for the cross platform input
public string verticalAxisName = "Vertical"; // The name given to the vertical axis for the cross platform input
public float Xsensitivity = 1f;
public float Ysensitivity = 1f;
Vector3 m_StartPos;
Vector2 m_PreviousDelta;
Vector3 m_JoytickOutput;
bool m_UseX; // Toggle for using the x axis
bool m_UseY; // Toggle for using the Y axis
CrossPlatformInputManager.VirtualAxis m_HorizontalVirtualAxis; // Reference to the joystick in the cross platform input
CrossPlatformInputManager.VirtualAxis m_VerticalVirtualAxis; // Reference to the joystick in the cross platform input
bool m_Dragging;
int m_Id = -1;
Vector2 m_PreviousTouchPos; // swipe style control touch
#if !UNITY_EDITOR
private Vector3 m_Center;
private Image m_Image;
#else
Vector3 m_PreviousMouse;
#endif
void OnEnable()
{
CreateVirtualAxes();
}
void Start()
{
#if !UNITY_EDITOR
m_Image = GetComponent<Image>();
m_Center = m_Image.transform.position;
#endif
}
void CreateVirtualAxes()
{
// set axes to use
m_UseX = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyHorizontal);
m_UseY = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyVertical);
// create new axes based on axes to use
if (m_UseX)
{
m_HorizontalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(horizontalAxisName);
CrossPlatformInputManager.RegisterVirtualAxis(m_HorizontalVirtualAxis);
}
if (m_UseY)
{
m_VerticalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(verticalAxisName);
CrossPlatformInputManager.RegisterVirtualAxis(m_VerticalVirtualAxis);
}
}
void UpdateVirtualAxes(Vector3 value)
{
value = value.normalized;
if (m_UseX)
{
m_HorizontalVirtualAxis.Update(value.x);
}
if (m_UseY)
{
m_VerticalVirtualAxis.Update(value.y);
}
}
public void OnPointerDown(PointerEventData data)
{
m_Dragging = true;
m_Id = data.pointerId;
#if !UNITY_EDITOR
if (controlStyle != ControlStyle.Absolute )
m_Center = data.position;
#endif
}
void Update()
{
if (!m_Dragging)
{
return;
}
if (Input.touchCount >= m_Id + 1 && m_Id != -1)
{
#if !UNITY_EDITOR
if (controlStyle == ControlStyle.Swipe)
{
m_Center = m_PreviousTouchPos;
m_PreviousTouchPos = Input.touches[m_Id].position;
}
Vector2 pointerDelta = new Vector2(Input.touches[m_Id].position.x - m_Center.x , Input.touches[m_Id].position.y - m_Center.y).normalized;
pointerDelta.x *= Xsensitivity;
pointerDelta.y *= Ysensitivity;
#else
Vector2 pointerDelta;
pointerDelta.x = Input.mousePosition.x - m_PreviousMouse.x;
pointerDelta.y = Input.mousePosition.y - m_PreviousMouse.y;
m_PreviousMouse = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f);
#endif
UpdateVirtualAxes(new Vector3(pointerDelta.x, pointerDelta.y, 0));
}
}
public void OnPointerUp(PointerEventData data)
{
m_Dragging = false;
m_Id = -1;
UpdateVirtualAxes(Vector3.zero);
}
void OnDisable()
{
if (CrossPlatformInputManager.AxisExists(horizontalAxisName))
CrossPlatformInputManager.UnRegisterVirtualAxis(horizontalAxisName);
if (CrossPlatformInputManager.AxisExists(verticalAxisName))
CrossPlatformInputManager.UnRegisterVirtualAxis(verticalAxisName);
}
}
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 1caf40fc8bebb6b43b2550c05ca791d6
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:

View File

@ -0,0 +1,134 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace UnityStandardAssets.CrossPlatformInput
{
public abstract class VirtualInput
{
public Vector3 virtualMousePosition { get; private set; }
protected Dictionary<string, CrossPlatformInputManager.VirtualAxis> m_VirtualAxes =
new Dictionary<string, CrossPlatformInputManager.VirtualAxis>();
// Dictionary to store the name relating to the virtual axes
protected Dictionary<string, CrossPlatformInputManager.VirtualButton> m_VirtualButtons =
new Dictionary<string, CrossPlatformInputManager.VirtualButton>();
protected List<string> m_AlwaysUseVirtual = new List<string>();
// list of the axis and button names that have been flagged to always use a virtual axis or button
public bool AxisExists(string name)
{
return m_VirtualAxes.ContainsKey(name);
}
public bool ButtonExists(string name)
{
return m_VirtualButtons.ContainsKey(name);
}
public void RegisterVirtualAxis(CrossPlatformInputManager.VirtualAxis axis)
{
// check if we already have an axis with that name and log and error if we do
if (m_VirtualAxes.ContainsKey(axis.name))
{
Debug.LogError("There is already a virtual axis named " + axis.name + " registered.");
}
else
{
// add any new axes
m_VirtualAxes.Add(axis.name, axis);
// if we dont want to match with the input manager setting then revert to always using virtual
if (!axis.matchWithInputManager)
{
m_AlwaysUseVirtual.Add(axis.name);
}
}
}
public void RegisterVirtualButton(CrossPlatformInputManager.VirtualButton button)
{
// check if already have a buttin with that name and log an error if we do
if (m_VirtualButtons.ContainsKey(button.name))
{
Debug.LogError("There is already a virtual button named " + button.name + " registered.");
}
else
{
// add any new buttons
m_VirtualButtons.Add(button.name, button);
// if we dont want to match to the input manager then always use a virtual axis
if (!button.matchWithInputManager)
{
m_AlwaysUseVirtual.Add(button.name);
}
}
}
public void UnRegisterVirtualAxis(string name)
{
// if we have an axis with that name then remove it from our dictionary of registered axes
if (m_VirtualAxes.ContainsKey(name))
{
m_VirtualAxes.Remove(name);
}
}
public void UnRegisterVirtualButton(string name)
{
// if we have a button with this name then remove it from our dictionary of registered buttons
if (m_VirtualButtons.ContainsKey(name))
{
m_VirtualButtons.Remove(name);
}
}
// returns a reference to a named virtual axis if it exists otherwise null
public CrossPlatformInputManager.VirtualAxis VirtualAxisReference(string name)
{
return m_VirtualAxes.ContainsKey(name) ? m_VirtualAxes[name] : null;
}
public void SetVirtualMousePositionX(float f)
{
virtualMousePosition = new Vector3(f, virtualMousePosition.y, virtualMousePosition.z);
}
public void SetVirtualMousePositionY(float f)
{
virtualMousePosition = new Vector3(virtualMousePosition.x, f, virtualMousePosition.z);
}
public void SetVirtualMousePositionZ(float f)
{
virtualMousePosition = new Vector3(virtualMousePosition.x, virtualMousePosition.y, f);
}
public abstract float GetAxis(string name, bool raw);
public abstract bool GetButton(string name);
public abstract bool GetButtonDown(string name);
public abstract bool GetButtonUp(string name);
public abstract void SetButtonDown(string name);
public abstract void SetButtonUp(string name);
public abstract void SetAxisPositive(string name);
public abstract void SetAxisNegative(string name);
public abstract void SetAxisZero(string name);
public abstract void SetAxis(string name, float value);
public abstract Vector3 MousePosition();
}
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 0f57aeb1b8dce3342bea5c28ac17db24
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName: