Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/new input #897

Merged
merged 6 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Assets/Fungus/Fungus.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"references": [
"GUID:6055be8ebefd69e48b49212b09b47b2f"
],
"optionalUnityReferences": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": []
"versionDefines": [],
"noEngineReferences": false
}
87 changes: 87 additions & 0 deletions Assets/Fungus/Resources/Prefabs/EventSystem_NewInputSystem.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &6933822064623478704
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6933822064623094736}
- component: {fileID: 6933822064613159708}
- component: {fileID: 1750760308580961868}
m_Layer: 0
m_Name: EventSystem_NewInputSystem
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6933822064623094736
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6933822064623478704}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &6933822064613159708
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6933822064623478704}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 76c392e42b5098c458856cdf6ecaaaa1, type: 3}
m_Name:
m_EditorClassIdentifier:
m_FirstSelected: {fileID: 0}
m_sendNavigationEvents: 1
m_DragThreshold: 5
--- !u!114 &1750760308580961868
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6933822064623478704}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 01614664b831546d2ae94a42149d80ac, type: 3}
m_Name:
m_EditorClassIdentifier:
m_MoveRepeatDelay: 0.5
m_MoveRepeatRate: 0.1
m_ActionsAsset: {fileID: -944628639613478452, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_PointAction: {fileID: 1054132383583890850, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_MoveAction: {fileID: 3710738434707379630, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_SubmitAction: {fileID: 2064916234097673511, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_CancelAction: {fileID: -1967631576421560919, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_LeftClickAction: {fileID: 8056856818456041789, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_MiddleClickAction: {fileID: 3279352641294131588, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_RightClickAction: {fileID: 3837173908680883260, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_ScrollWheelAction: {fileID: 4502412055082496612, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_TrackedDevicePositionAction: {fileID: 4754684134866288074, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_TrackedDeviceOrientationAction: {fileID: 1025543830046995696, guid: ca9f5fa95ffab41fb9a615ab714db018,
type: 3}
m_DeselectOnBackgroundClick: 1
m_PointerBehavior: 0

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions Assets/Fungus/Scripts/Commands/Input/GetAxis.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// This code is part of the Fungus library (https://github.com/snozbot/fungus)
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Fungus
Expand Down Expand Up @@ -58,6 +56,5 @@ public override bool HasReference(Variable variable)

return false;
}

}
}
}
19 changes: 14 additions & 5 deletions Assets/Fungus/Scripts/Commands/Input/GetMousePosition.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using UnityEngine;
// This code is part of the Fungus library (https://github.com/snozbot/fungus)
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)

using UnityEngine;

namespace Fungus
{
Expand Down Expand Up @@ -37,26 +40,32 @@ public override void OnEnter()
castCamera = Camera.main;
}

#if ENABLE_INPUT_SYSTEM
var mousePos = UnityEngine.InputSystem.Mouse.current?.position.ReadValue() ?? Vector2.zero;
#else
var mousePos = Input.mousePosition;
#endif

if (screenPosition != null)
{
screenPosition.Value = Input.mousePosition;
screenPosition.Value = mousePos;
}

if (viewPosition != null)
{
viewPosition.Value = castCamera.ScreenToViewportPoint(Input.mousePosition);
viewPosition.Value = castCamera.ScreenToViewportPoint(mousePos);
}

if (worldPosition != null)
{
var screenWithZ = Input.mousePosition;
Vector3 screenWithZ = mousePos;
screenWithZ.z = castCamera.nearClipPlane;
worldPosition.Value = castCamera.ScreenToWorldPoint(screenWithZ);
}

if (worldDirection != null)
{
var screenWithZ = Input.mousePosition;
Vector3 screenWithZ = mousePos;
screenWithZ.z = castCamera.nearClipPlane;
worldDirection.Value = castCamera.ScreenPointToRay(screenWithZ).direction;
}
Expand Down
20 changes: 17 additions & 3 deletions Assets/Fungus/Scripts/Components/CameraManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Fungus;

namespace Fungus
{
Expand Down Expand Up @@ -118,8 +117,22 @@ protected virtual void Update()
}

Vector3 delta = Vector3.zero;

if (Input.touchCount > 0)

#if ENABLE_INPUT_SYSTEM
delta = UnityEngine.InputSystem.Touchscreen.current?.primaryTouch?.delta.ReadValue() ?? Vector3.zero;

if(UnityEngine.InputSystem.Mouse.current?.leftButton.wasPressedThisFrame ?? false)
{
previousMousePos = UnityEngine.InputSystem.Mouse.current.position.ReadValue();
}
else if(UnityEngine.InputSystem.Mouse.current?.leftButton.isPressed ?? false)
{
delta = UnityEngine.InputSystem.Mouse.current.position.ReadValue() - (Vector2)previousMousePos;
previousMousePos = UnityEngine.InputSystem.Mouse.current.position.ReadValue();
}
#else
if (
Input.touchCount > 0)
{
if (Input.GetTouch(0).phase == TouchPhase.Moved)
{
Expand All @@ -136,6 +149,7 @@ protected virtual void Update()
delta = Input.mousePosition - previousMousePos;
previousMousePos = Input.mousePosition;
}
#endif

Vector3 cameraDelta = swipeCamera.ScreenToViewportPoint(delta);
cameraDelta.x *= -2f * swipeSpeedMultiplier;
Expand Down
31 changes: 28 additions & 3 deletions Assets/Fungus/Scripts/Components/DialogInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ public class DialogInput : MonoBehaviour

protected float ignoreClickTimer;

#if ENABLE_INPUT_SYSTEM
protected UnityEngine.InputSystem.UI.InputSystemUIInputModule inputSystemUIInputModule;
#else
protected StandaloneInputModule currentStandaloneInputModule;
#endif

protected Writer writer;

Expand All @@ -63,7 +67,7 @@ protected virtual void CheckEventSystem()
if (eventSystem == null)
{
// Auto spawn an Event System from the prefab
GameObject prefab = Resources.Load<GameObject>("Prefabs/EventSystem");
GameObject prefab = Resources.Load<GameObject>(FungusConstants.EventSystemPrefabName);
if (prefab != null)
{
GameObject go = Instantiate(prefab) as GameObject;
Expand All @@ -79,6 +83,21 @@ protected virtual void Update()
return;
}

#if ENABLE_INPUT_SYSTEM
if(inputSystemUIInputModule == null)
{
inputSystemUIInputModule = FindObjectOfType<UnityEngine.InputSystem.UI.InputSystemUIInputModule>();
}

if (writer != null && writer.IsWriting)
{
if (inputSystemUIInputModule.submit.action.triggered ||
(cancelEnabled && inputSystemUIInputModule.cancel.action.triggered))
{
SetNextLineFlag();
}
}
#else
if (currentStandaloneInputModule == null)
{
currentStandaloneInputModule = EventSystem.current.GetComponent<StandaloneInputModule>();
Expand All @@ -92,13 +111,19 @@ protected virtual void Update()
SetNextLineFlag();
}
}
#endif

switch (clickMode)
{
case ClickMode.Disabled:
break;
case ClickMode.ClickAnywhere:
#if ENABLE_INPUT_SYSTEM
if ((UnityEngine.InputSystem.Mouse.current?.leftButton.wasPressedThisFrame ?? false) ||
(UnityEngine.InputSystem.Touchscreen.current?.primaryTouch?.press.wasPressedThisFrame ?? false))
#else
if (Input.GetMouseButtonDown(0))
#endif
{
SetNextLineFlag();
}
Expand Down Expand Up @@ -142,7 +167,7 @@ protected virtual void Update()
}
}

#region Public members
#region Public members

/// <summary>
/// Trigger next line input event from script.
Expand Down Expand Up @@ -183,6 +208,6 @@ public virtual void SetButtonClickedFlag()
}
}

#endregion
#endregion
}
}
19 changes: 14 additions & 5 deletions Assets/Fungus/Scripts/Components/Draggable2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,13 @@ protected virtual void OnTriggerExit2D(Collider2D other)
protected virtual void DoBeginDrag()
{
// Offset the object so that the drag is anchored to the exact point where the user clicked it
float x = Input.mousePosition.x;
float y = Input.mousePosition.y;
delta = Camera.main.ScreenToWorldPoint(new Vector3(x, y, 10f)) - transform.position;

#if ENABLE_INPUT_SYSTEM
var mousePos = UnityEngine.InputSystem.Mouse.current?.position.ReadValue() ?? Vector2.zero;
#else
var mousePos = Input.mousePosition;
#endif
delta = Camera.main.ScreenToWorldPoint(new Vector3(mousePos.x, mousePos.y, 10f)) - transform.position;
delta.z = 0f;

startingPosition = transform.position;
Expand All @@ -115,8 +119,13 @@ protected virtual void DoDrag()
return;
}

float x = Input.mousePosition.x;
float y = Input.mousePosition.y;
#if ENABLE_INPUT_SYSTEM
var mousePos = UnityEngine.InputSystem.Mouse.current?.position.ReadValue() ?? Vector2.zero;
#else
var mousePos = Input.mousePosition;
#endif
float x = mousePos.x;
float y = mousePos.y;
float z = transform.position.z;

newPosition = Camera.main.ScreenToWorldPoint(new Vector3(x, y, 10f)) - delta;
Expand Down
2 changes: 1 addition & 1 deletion Assets/Fungus/Scripts/Components/Flowchart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected virtual void CheckEventSystem()
if (eventSystem == null)
{
// Auto spawn an Event System from the prefab
GameObject prefab = Resources.Load<GameObject>("Prefabs/EventSystem");
GameObject prefab = Resources.Load<GameObject>(FungusConstants.EventSystemPrefabName);
if (prefab != null)
{
GameObject go = Instantiate(prefab) as GameObject;
Expand Down
2 changes: 1 addition & 1 deletion Assets/Fungus/Scripts/Components/MenuDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected virtual void CheckEventSystem()
if (eventSystem == null)
{
// Auto spawn an Event System from the prefab
GameObject prefab = Resources.Load<GameObject>("Prefabs/EventSystem");
GameObject prefab = Resources.Load<GameObject>(FungusConstants.EventSystemPrefabName);
if (prefab != null)
{
GameObject go = Instantiate(prefab) as GameObject;
Expand Down
9 changes: 7 additions & 2 deletions Assets/Fungus/Scripts/Components/Parallax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,14 @@ protected virtual void Update ()
// Apply parallax translation based on device accelerometer
if (SystemInfo.supportsAccelerometer)
{
float maxParallaxScale = Mathf.Max(parallaxScale.x, parallaxScale.y);
float maxParallaxScale = Mathf.Max(parallaxScale.x, parallaxScale.y);
// The accelerometer data is quite noisy, so we apply smoothing to even it out.
acceleration = Vector3.SmoothDamp(acceleration, Input.acceleration, ref velocity, 0.1f);
#if ENABLE_INPUT_SYSTEM
Vector3 accel = UnityEngine.InputSystem.Accelerometer.current?.acceleration.ReadValue() ?? Vector3.zero;
#else
Vector3 accel = Input.acceleration;
#endif
acceleration = Vector3.SmoothDamp(acceleration, accel, ref velocity, 0.1f);
// Assuming a 45 degree "neutral position" when holding a mobile device
Vector3 accelerometerOffset = Quaternion.Euler(45, 0, 0) * acceleration * maxParallaxScale * accelerometerScale;
translation += accelerometerOffset;
Expand Down
11 changes: 11 additions & 0 deletions Assets/Fungus/Scripts/Components/Variable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ public abstract class Variable : MonoBehaviour
/// </summary>
public abstract object GetValue();

/// <summary>
/// Set value in inherited types via Boxed value.
/// Not recommended for direct use, primarily intended for use in editor code.
/// </summary>
public abstract void SetValue(object value);

//we are required to be on a flowchart so we provide this as a helper
public virtual Flowchart GetFlowchart()
{
Expand Down Expand Up @@ -228,6 +234,11 @@ public override object GetValue()
return value;
}

public override void SetValue(object value)
{
this.value = (T)value;
}

protected T startValue;

public override void OnReset()
Expand Down
Loading