1
This commit is contained in:
136
Assets/Mods/Demo/Scripts/FlyCameraDemo.cs
Normal file
136
Assets/Mods/Demo/Scripts/FlyCameraDemo.cs
Normal file
@@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITKit;
|
||||
using BITKit.UX;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.Interactions;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Net.Like.Xue.Tokyo.SNS.Demo
|
||||
{
|
||||
public class FlyCameraDemo : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float initialSpeed;
|
||||
[SerializeField] private float accelerationSpeed;
|
||||
|
||||
[SerializeField] private InputActionReference viewAction;
|
||||
[SerializeField] private InputActionReference moveAction;
|
||||
[SerializeField] private InputActionReference entryViewAction;
|
||||
[SerializeField] private InputActionReference accelerateAction;
|
||||
[SerializeField] private InputActionReference verticalAction;
|
||||
|
||||
private Vector2 _inputDirection;
|
||||
private Vector2 _viewDirection;
|
||||
private float _currentAccelerate;
|
||||
private float _verticalFactor;
|
||||
private bool _isViewing;
|
||||
private bool _isAccelerated;
|
||||
private Vector3 _currentVelocity;
|
||||
|
||||
[UXBindPath("sensitivity-slider")]
|
||||
private Slider _sensitivitySlider;
|
||||
[UXBindPath("open-document-button")]
|
||||
private Button _openDocumentButton;
|
||||
|
||||
private readonly InputActionGroup _inputActionGroup = new()
|
||||
{
|
||||
allowGlobalActivation = false
|
||||
};
|
||||
|
||||
private void Start()
|
||||
{
|
||||
destroyCancellationToken.Register(Dispose);
|
||||
|
||||
_inputActionGroup.RegisterCallback(viewAction, OnView);
|
||||
_inputActionGroup.RegisterCallback(moveAction, OnMove);
|
||||
_inputActionGroup.RegisterCallback(entryViewAction, OnEntryView);
|
||||
_inputActionGroup.RegisterCallback(accelerateAction, OnAccelerate);
|
||||
_inputActionGroup.RegisterCallback(verticalAction, OnVertical);
|
||||
|
||||
_inputActionGroup.allowInput.AddElement(this);
|
||||
|
||||
UXUtils.Inject(this);
|
||||
|
||||
//Quaternion.Euler(-_viewDirection.y,_viewDirection.x,0);
|
||||
var direction = MathV.TransientRotationAxis(transform.eulerAngles);
|
||||
_viewDirection.x = direction.y;
|
||||
_viewDirection.y = -direction.x;
|
||||
|
||||
_openDocumentButton.clicked += () =>
|
||||
{
|
||||
Application.OpenURL("https://docs.qq.com/aio/DU3NsV3J4SnNNZHdV?p=l3kba61Nvtd9jKXAeQvnQV");
|
||||
};
|
||||
}
|
||||
|
||||
private void OnVertical(InputAction.CallbackContext obj)
|
||||
{
|
||||
_verticalFactor = obj.ReadValue<float>();
|
||||
}
|
||||
|
||||
private void OnAccelerate(InputAction.CallbackContext obj)
|
||||
{
|
||||
_isAccelerated=obj switch
|
||||
{
|
||||
{interaction:PressInteraction,performed:true}=>true,
|
||||
{interaction:PressInteraction,canceled:true}=>false,
|
||||
_ => _isAccelerated,
|
||||
};
|
||||
}
|
||||
|
||||
private void OnEntryView(InputAction.CallbackContext obj)
|
||||
{
|
||||
_isViewing = obj switch
|
||||
{
|
||||
{interaction:PressInteraction,performed:true}=>true,
|
||||
{interaction:PressInteraction,canceled:true}=>false,
|
||||
_ => _isViewing,
|
||||
};
|
||||
BITAppForUnity.AllowCursor.SetElements(0,_isViewing is false);
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
var direction = _inputDirection;
|
||||
var velocity = transform.rotation * new Vector3(direction.x, _verticalFactor, direction.y);
|
||||
|
||||
velocity *= initialSpeed * Time.deltaTime;
|
||||
|
||||
_currentAccelerate = _isAccelerated ? _currentAccelerate += accelerationSpeed * Time.fixedDeltaTime : 0;
|
||||
|
||||
velocity += velocity * _currentAccelerate;
|
||||
|
||||
_currentVelocity = Vector3.Lerp(_currentVelocity, velocity, 16 * Time.fixedDeltaTime);
|
||||
|
||||
transform.position += _currentVelocity;
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if(_isViewing is false)return;
|
||||
transform.rotation = Quaternion.Euler(-_viewDirection.y,_viewDirection.x,0);
|
||||
}
|
||||
|
||||
private void OnMove(InputAction.CallbackContext obj)
|
||||
{
|
||||
_inputDirection = obj.ReadValue<Vector2>();
|
||||
}
|
||||
|
||||
private void OnView(InputAction.CallbackContext obj)
|
||||
{
|
||||
if(_isViewing is false)return;
|
||||
var value = obj.ReadValue<Vector2>() * 0.018f * _sensitivitySlider.value;
|
||||
_viewDirection.x += value.x;
|
||||
_viewDirection.y += value.y;
|
||||
|
||||
_viewDirection.y = Mathf.Clamp(_viewDirection.y, -80, 80);
|
||||
}
|
||||
|
||||
private void Dispose()
|
||||
{
|
||||
_inputActionGroup.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
18
Assets/Mods/Demo/Scripts/Net.Like.Xue.Tokyo.SNS.Demo.asmdef
Normal file
18
Assets/Mods/Demo/Scripts/Net.Like.Xue.Tokyo.SNS.Demo.asmdef
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "Net.Like.Xue.Tokyo.SNS.Demo",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:75469ad4d38634e559750d17036d5f7c",
|
||||
"GUID:6ef4ed8ff60a7aa4bb60a8030e6f4008"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
28
Assets/Mods/Demo/Scripts/SwitchSceneDemo.cs
Normal file
28
Assets/Mods/Demo/Scripts/SwitchSceneDemo.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITKit.UX;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Net.Like.Xue.Tokyo.SNS.Demo
|
||||
{
|
||||
public class SwitchSceneDemo : MonoBehaviour
|
||||
{
|
||||
[UXBindPath("scene-dropdown")] private DropdownField _sceneDropdown;
|
||||
[UXBindPath("entry-scene-button")] private Button _entrySceneButton;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
UXUtils.Inject(this);
|
||||
_entrySceneButton.clicked += NextLevel;
|
||||
|
||||
}
|
||||
private void NextLevel()
|
||||
{
|
||||
SceneManager.LoadScene(_sceneDropdown.index);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
17
Assets/Mods/Demo/UX/UXDemo.uxml
Normal file
17
Assets/Mods/Demo/UX/UXDemo.uxml
Normal file
@@ -0,0 +1,17 @@
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
|
||||
<Style src="project://database/Assets/BITKit/Unity/UX/Common/Common.uss?fileID=7433441132597879392&guid=a3a69d3518fd02b489e721f3c5b0b539&type=3#Common" />
|
||||
<ui:VisualElement style="position: absolute; left: 32px; top: 32px; padding-top: 24px; padding-right: 32px; padding-bottom: 24px; padding-left: 32px; background-color: rgba(0, 0, 0, 0.78);">
|
||||
<ui:Label tabindex="-1" text="选择关卡" parse-escape-sequences="true" display-tooltip-when-elided="true" />
|
||||
<ui:DropdownField label="去哪里" choices="秋叶原,东京街道,郊区" index="0" name="scene-dropdown" />
|
||||
<ui:Button text="进入场景" parse-escape-sequences="true" display-tooltip-when-elided="true" name="entry-scene-button" />
|
||||
</ui:VisualElement>
|
||||
<ui:VisualElement style="position: absolute; left: 32px; bottom: 32px; padding-top: 24px; padding-right: 32px; padding-bottom: 24px; padding-left: 32px; background-color: rgba(0, 0, 0, 0.78);">
|
||||
<ui:Label tabindex="-1" text="操作说明" parse-escape-sequences="true" display-tooltip-when-elided="true" class="tl" />
|
||||
<ui:Label tabindex="-1" text="按住[鼠标右键]旋转视角 按住[WASD]移动视角 按住[Shift]启用移动加速度 按住[QE]上下移动" parse-escape-sequences="true" display-tooltip-when-elided="true" />
|
||||
<ui:Label tabindex="-1" text="灵敏度" parse-escape-sequences="true" display-tooltip-when-elided="true" class="tm" />
|
||||
<ui:Slider high-value="5" show-input-field="true" low-value="1" name="sensitivity-slider" />
|
||||
<ui:Label tabindex="-1" text="快捷方式" parse-escape-sequences="true" display-tooltip-when-elided="true" class="tl" />
|
||||
<ui:Label tabindex="-1" text="快速记录需要互动的点位" parse-escape-sequences="true" display-tooltip-when-elided="true" />
|
||||
<ui:Button text="打开记录文档" parse-escape-sequences="true" display-tooltip-when-elided="true" name="open-document-button" />
|
||||
</ui:VisualElement>
|
||||
</ui:UXML>
|
Reference in New Issue
Block a user