Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
顺
顺职VR迷宫游戏教学
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨泽宇
顺职VR迷宫游戏教学
Commits
e00f18d6
Commit
e00f18d6
authored
Feb 29, 2024
by
张英美
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'main' of git@gitlab.sd-zeus.com:yangzeyu/ShunZhiMazeVR.git
parents
16229fb1
f4dc446a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
1562 additions
and
180 deletions
+1562
-180
XRDeviceSimulatorSettings.asset
...ts/XRI/Settings/Resources/XRDeviceSimulatorSettings.asset
+2
-2
2_Maze2.unity
Assets/_Scenes/2_Maze2.unity
+1241
-178
ArrowController.cs
Assets/_Scripts/ArrowController.cs
+83
-0
ArrowController.cs.meta
Assets/_Scripts/ArrowController.cs.meta
+11
-0
ArrowTrigger.cs
Assets/_Scripts/ArrowTrigger.cs
+27
-0
ArrowTrigger.cs.meta
Assets/_Scripts/ArrowTrigger.cs.meta
+11
-0
BowController.cs
Assets/_Scripts/BowController.cs
+46
-0
BowController.cs.meta
Assets/_Scripts/BowController.cs.meta
+11
-0
PullMeasurer.cs
Assets/_Scripts/PullMeasurer.cs
+62
-0
PullMeasurer.cs.meta
Assets/_Scripts/PullMeasurer.cs.meta
+11
-0
StringRenderer.cs
Assets/_Scripts/StringRenderer.cs
+46
-0
StringRenderer.cs.meta
Assets/_Scripts/StringRenderer.cs.meta
+11
-0
No files found.
Assets/XRI/Settings/Resources/XRDeviceSimulatorSettings.asset
View file @
e00f18d6
...
@@ -12,5 +12,5 @@ MonoBehaviour:
...
@@ -12,5 +12,5 @@ MonoBehaviour:
m_Script
:
{
fileID
:
11500000
,
guid
:
690929a59dc7a42da9030305190d391f
,
type
:
3
}
m_Script
:
{
fileID
:
11500000
,
guid
:
690929a59dc7a42da9030305190d391f
,
type
:
3
}
m_Name
:
XRDeviceSimulatorSettings
m_Name
:
XRDeviceSimulatorSettings
m_EditorClassIdentifier
:
m_EditorClassIdentifier
:
m_AutomaticallyInstantiateSimulatorPrefab
:
1
m_AutomaticallyInstantiateSimulatorPrefab
:
0
m_SimulatorPrefab
:
{
fileID
:
6598815579406187037
,
guid
:
18ddb545287c546e19cc77dc9fbb2189
,
type
:
3
}
m_SimulatorPrefab
:
{
fileID
:
0
}
Assets/_Scenes/2_Maze2.unity
View file @
e00f18d6
This diff is collapsed.
Click to expand it.
Assets/_Scripts/ArrowController.cs
0 → 100644
View file @
e00f18d6
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
using
UnityEngine.XR.Interaction.Toolkit
;
public
class
ArrowController
:
MonoBehaviour
{
// Start is called before the first frame update
public
GameObject
arrowPrefab
;
public
GameObject
arrowPlace
;
public
GameObject
arrowTrigger
;
public
GameObject
arrowBack
;
public
Vector3
arrowHeading
;
public
bool
waitingToShoot
=
false
;
void
Start
()
{
arrowPlace
=
GameObject
.
Find
(
"XR Interaction Setup/XR Origin (XR Rig)/Camera Offset/Main Camera/ArrowPlace"
);
arrowTrigger
=
GameObject
.
Find
(
"Bow/ArrowTrigger"
);
arrowBack
=
GameObject
.
Find
(
"Bow/String/Notch"
);
}
// Update is called once per frame
void
Update
()
{
arrowHeading
=
arrowTrigger
.
transform
.
position
-
arrowBack
.
transform
.
position
;
if
(
waitingToShoot
)
{
gameObject
.
transform
.
position
=
arrowBack
.
transform
.
position
+
gameObject
.
transform
.
localScale
.
y
/
2.4f
*
arrowHeading
.
normalized
;
gameObject
.
transform
.
rotation
=
Quaternion
.
LookRotation
(
arrowHeading
,
Vector3
.
forward
);
}
}
public
void
GrabArrow
()
{
GameObject
arrow
=
Instantiate
(
arrowPrefab
,
arrowPlace
.
transform
.
position
,
arrowPlace
.
transform
.
rotation
);
arrow
.
transform
.
parent
=
GameObject
.
Find
(
"XR Interaction Setup/XR Origin (XR Rig)/Camera Offset/Main Camera"
).
transform
;
}
public
void
ReleaseArrow
()
{
gameObject
.
GetComponent
<
Rigidbody
>().
useGravity
=
true
;
gameObject
.
GetComponent
<
Rigidbody
>().
isKinematic
=
false
;
gameObject
.
transform
.
parent
=
null
;
if
(
arrowTrigger
.
GetComponent
<
ArrowTrigger
>().
arrowOnBow
==
gameObject
)
{
gameObject
.
GetComponent
<
Rigidbody
>().
useGravity
=
false
;
gameObject
.
transform
.
parent
=
arrowTrigger
.
transform
;
waitingToShoot
=
true
;
}
Debug
.
Log
(
"ReleaseArrow:"
+
gameObject
.
transform
.
parent
);
}
void
OnTriggerEnter
(
Collider
other
)
{
if
(
other
.
tag
==
"Target"
)
{
gameObject
.
transform
.
parent
=
other
.
transform
;
gameObject
.
GetComponentInParent
<
Rigidbody
>().
velocity
=
new
Vector3
(
0
,
0
,
0
);
gameObject
.
GetComponentInParent
<
Rigidbody
>().
useGravity
=
false
;
gameObject
.
GetComponentInParent
<
Rigidbody
>().
isKinematic
=
true
;
}
}
void
OnTriggerExit
(
Collider
other
)
{
if
(
other
.
tag
==
"Target"
)
{
gameObject
.
transform
.
parent
=
null
;
gameObject
.
GetComponentInParent
<
Rigidbody
>().
useGravity
=
true
;
gameObject
.
GetComponentInParent
<
Rigidbody
>().
constraints
=
RigidbodyConstraints
.
None
;
gameObject
.
GetComponentInParent
<
Rigidbody
>().
isKinematic
=
false
;
}
}
}
Assets/_Scripts/ArrowController.cs.meta
0 → 100644
View file @
e00f18d6
fileFormatVersion: 2
guid: a5c80d12c595e834eaf04fc07ee37b38
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/_Scripts/ArrowTrigger.cs
0 → 100644
View file @
e00f18d6
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
ArrowTrigger
:
MonoBehaviour
{
public
GameObject
arrowOnBow
;
private
bool
arrowStatus
;
void
OnTriggerEnter
(
Collider
other
)
{
if
(
other
.
tag
==
"Arrow"
)
{
arrowStatus
=
true
;
arrowOnBow
=
other
.
gameObject
;
}
}
void
OnTriggerExit
(
Collider
other
)
{
if
(
other
.
tag
==
"Arrow"
)
{
arrowStatus
=
false
;
arrowOnBow
=
null
;
}
}
}
Assets/_Scripts/ArrowTrigger.cs.meta
0 → 100644
View file @
e00f18d6
fileFormatVersion: 2
guid: d0db9fd0bb60ef34faae5098fe6fae6e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/_Scripts/BowController.cs
0 → 100644
View file @
e00f18d6
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
/// <summary>
/// 弓控制器
/// </summary>
public
class
BowController
:
MonoBehaviour
{
public
float
arrowSpeed
=
400
;
public
GameObject
arrowTrigger
;
public
GameObject
arrowAttachedPoint
;
public
GameObject
stringStartPoint
;
public
GameObject
stringEndPoint
;
public
GameObject
stringMiddlePoint
;
// Start is called before the first frame update
void
Start
()
{
}
// Update is called once per frame
void
Update
()
{
}
public
void
ReleaseString
()
{
Debug
.
Log
(
"ReleaseString"
);
stringMiddlePoint
.
transform
.
position
=
(
stringStartPoint
.
transform
.
position
+
stringEndPoint
.
transform
.
position
+
new
Vector3
(
0
,
0.07f
,
0
))
/
2
;
stringMiddlePoint
.
GetComponent
<
Rigidbody
>().
velocity
=
new
Vector3
(
0
,
0
,
0
);
stringMiddlePoint
.
GetComponent
<
Rigidbody
>().
angularVelocity
=
new
Vector3
(
0
,
0
,
0
);
if
(
arrowTrigger
.
GetComponent
<
ArrowTrigger
>().
arrowOnBow
)
{
GameObject
arrowOnBow
=
arrowTrigger
.
GetComponent
<
ArrowTrigger
>().
arrowOnBow
;
arrowOnBow
.
transform
.
parent
=
null
;
arrowOnBow
.
GetComponent
<
Rigidbody
>().
constraints
=
RigidbodyConstraints
.
FreezeRotationX
|
RigidbodyConstraints
.
FreezeRotationY
;
arrowOnBow
.
GetComponent
<
Rigidbody
>().
useGravity
=
true
;
arrowOnBow
.
GetComponent
<
ArrowController
>().
waitingToShoot
=
false
;
arrowOnBow
.
GetComponent
<
Rigidbody
>().
AddForce
(
arrowOnBow
.
GetComponent
<
ArrowController
>().
arrowHeading
*
arrowOnBow
.
GetComponent
<
ArrowController
>().
arrowHeading
.
magnitude
*
arrowSpeed
);
}
}
}
Assets/_Scripts/BowController.cs.meta
0 → 100644
View file @
e00f18d6
fileFormatVersion: 2
guid: a9bd1017b01dad845a964a4becf11c9a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/_Scripts/PullMeasurer.cs
0 → 100644
View file @
e00f18d6
using
UnityEngine
;
using
UnityEngine.XR.Interaction.Toolkit
;
public
class
PullMeasurer
:
XRBaseInteractable
{
[
SerializeField
]
private
Transform
start
;
// 拉伸测量的起始点
[
SerializeField
]
private
Transform
end
;
// 拉伸测量的结束点
public
float
PullAmount
{
get
;
private
set
;
}
=
0.0f
;
// 当前拉伸的程度,初始值为 0
// 通过线性插值获取当前拉伸位置的方法
public
Vector3
PullPosition
=>
Vector3
.
Lerp
(
start
.
position
,
end
.
position
,
PullAmount
);
protected
override
void
OnSelectExited
(
SelectExitEventArgs
args
)
{
base
.
OnSelectExited
(
args
);
PullAmount
=
0
;
// 当交互结束时,重置拉伸程度为 0
}
public
override
void
ProcessInteractable
(
XRInteractionUpdateOrder
.
UpdatePhase
updatePhase
)
{
base
.
ProcessInteractable
(
updatePhase
);
if
(
isSelected
)
{
// 在物体被选中时更新拉伸值
if
(
updatePhase
==
XRInteractionUpdateOrder
.
UpdatePhase
.
Dynamic
)
UpdatePull
();
}
}
private
void
UpdatePull
()
{
// 使用交互者的位置来计算拉伸程度
Vector3
interactorPosition
=
firstInteractorSelecting
.
transform
.
position
;
// 计算新的拉伸程度,并返回它在空间中的位置
PullAmount
=
CalculatePull
(
interactorPosition
);
}
private
float
CalculatePull
(
Vector3
pullPosition
)
{
// 计算方向和长度
Vector3
pullDirection
=
pullPosition
-
start
.
position
;
Vector3
targetDirection
=
end
.
position
-
start
.
position
;
// 规范化目标方向
float
maxLength
=
targetDirection
.
magnitude
;
targetDirection
.
Normalize
();
// 计算拉伸值
float
pullValue
=
Vector3
.
Dot
(
pullDirection
,
targetDirection
)
/
maxLength
;
return
Mathf
.
Clamp
(
pullValue
,
0.0f
,
1.0f
);
// 将拉伸值限制在 0 到 1 之间
}
private
void
OnDrawGizmos
()
{
// 在场景中绘制起始点到结束点的连线
if
(
start
&&
end
)
Gizmos
.
DrawLine
(
start
.
position
,
end
.
position
);
}
}
Assets/_Scripts/PullMeasurer.cs.meta
0 → 100644
View file @
e00f18d6
fileFormatVersion: 2
guid: 25fb566416268a1409511aab6f4e2d73
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/_Scripts/StringRenderer.cs
0 → 100644
View file @
e00f18d6
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
/// <summary>
/// 弓弦的绘制
/// </summary>
public
class
StringRenderer
:
MonoBehaviour
{
[
Header
(
"渲染位置"
)]
[
SerializeField
]
private
Transform
start
;
// 弓弦的起始点
[
SerializeField
]
private
Transform
middle
;
// 弓弦的中间点
[
SerializeField
]
private
Transform
end
;
// 弓弦的结束点
private
LineRenderer
lineRenderer
;
// 用于渲染弓弦的 LineRenderer 组件
private
void
Awake
()
{
lineRenderer
=
GetComponent
<
LineRenderer
>();
// 获取当前游戏对象上的 LineRenderer 组件
}
private
void
Update
()
{
if
(
Application
.
isEditor
&&
!
Application
.
isPlaying
)
UpdatePositions
();
// 在编辑器模式下,每帧更新弓弦的位置
}
private
void
OnEnable
()
{
Application
.
onBeforeRender
+=
UpdatePositions
;
// 在渲染之前更新弓弦的位置
}
private
void
OnDisable
()
{
Application
.
onBeforeRender
-=
UpdatePositions
;
// 移除在渲染之前更新弓弦的位置的监听
}
/// <summary>
/// 更新弓弦的位置
/// </summary>
private
void
UpdatePositions
()
{
// 设置 LineRenderer 组件的顶点位置为起始点、中间点和结束点的位置
lineRenderer
.
SetPositions
(
new
Vector3
[]
{
start
.
position
,
middle
.
position
,
end
.
position
});
}
}
Assets/_Scripts/StringRenderer.cs.meta
0 → 100644
View file @
e00f18d6
fileFormatVersion: 2
guid: cd5065d3a03425c40a7a8a0c97d287d7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment