Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
man-in-the-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MIM
man-in-the-mirror
Commits
238ad08b
Commit
238ad08b
authored
May 14, 2019
by
18손재민
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'bullet'
parents
9a83270c
078c1d2a
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
344 additions
and
18 deletions
+344
-18
ModelScene.meta
Assets/Scenes/ModelScene.meta
+8
-0
Pair.cs
Assets/Scripts/Generals/Pair.cs
+20
-0
Pair.cs.meta
Assets/Scripts/Generals/Pair.cs.meta
+11
-0
Briefcase.cs
Assets/Scripts/Interactors/Briefcase.cs
+17
-2
CameraTurret.cs
Assets/Scripts/Interactors/CameraTurret.cs
+16
-1
IObject.cs
Assets/Scripts/Interactors/Interfaces/IObject.cs
+18
-0
IObject.cs.meta
Assets/Scripts/Interactors/Interfaces/IObject.cs.meta
+11
-0
Mannequin.cs
Assets/Scripts/Interactors/Mannequin.cs
+16
-1
Mirror.cs
Assets/Scripts/Interactors/Mirror.cs
+190
-10
NormalWall.cs
Assets/Scripts/Interactors/NormalWall.cs
+6
-2
GameManager.cs
Assets/Scripts/Managers/GameManager.cs
+1
-0
Map.cs
Assets/Scripts/Map/Map.cs
+4
-2
Wall.cs
Assets/Scripts/Map/Wall.cs
+21
-0
Player.cs
Assets/Scripts/Player.cs
+5
-0
No files found.
Assets/Scenes/ModelScene.meta
0 → 100644
View file @
238ad08b
fileFormatVersion: 2
guid: a32ca40f7f255ea47ac7ee9d558755ce
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/Generals/Pair.cs
0 → 100644
View file @
238ad08b
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
Pair
<
L
,
R
>
{
public
L
l
;
public
R
r
;
public
Pair
(
L
_l
,
R
_r
)
{
this
.
l
=
_l
;
this
.
r
=
_r
;
}
public
Pair
<
R
,
L
>
Swap
()
{
return
new
Pair
<
R
,
L
>(
r
,
l
);
}
}
Assets/Scripts/Generals/Pair.cs.meta
0 → 100644
View file @
238ad08b
fileFormatVersion: 2
guid: 6f1adc6ee7fc32943bb2c1a1dda4c4f9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/Interactors/Briefcase.cs
View file @
238ad08b
...
...
@@ -2,13 +2,23 @@
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
Briefcase
:
MonoBehaviour
,
IPlayerInteractor
public
class
Briefcase
:
MonoBehaviour
,
I
Object
,
I
PlayerInteractor
{
[
SerializeField
]
private
Floor
floor
=
null
;
public
Vector2Int
Position
{
get
{
return
floor
!=
null
?
floor
.
mapPos
:
throw
new
UnassignedReferenceException
(
"Floor of Interactor is not assigned"
);
}
}
public
void
Init
(
Floor
floor
)
public
GameObject
GetObject
()
{
return
gameObject
;
}
public
Vector2
GetPos
()
{
return
new
Vector2
(
transform
.
position
.
x
,
transform
.
position
.
z
);
}
public
void
Init
(
Floor
floor
)
{
this
.
floor
=
floor
;
PlayerController
.
inst
.
OnPlayerMove
+=
Interact
;
...
...
@@ -23,4 +33,9 @@ public class Briefcase : MonoBehaviour, IPlayerInteractor
Destroy
(
gameObject
);
}
}
ObjType
IObject
.
GetType
()
{
return
ObjType
.
Briefcase
;
}
}
Assets/Scripts/Interactors/CameraTurret.cs
View file @
238ad08b
...
...
@@ -2,7 +2,7 @@
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
CameraTurret
:
MonoBehaviour
,
IBreakable
,
IPlayerInteractor
public
class
CameraTurret
:
MonoBehaviour
,
I
Object
,
I
Breakable
,
IPlayerInteractor
{
[
SerializeField
]
private
Floor
floor
=
null
;
...
...
@@ -27,4 +27,19 @@ public class CameraTurret : MonoBehaviour, IBreakable, IPlayerInteractor
//TODO : Restart Level
}
}
public
GameObject
GetObject
()
{
return
gameObject
;
}
public
Vector2
GetPos
()
{
return
new
Vector2
(
transform
.
position
.
x
,
transform
.
position
.
z
);
}
ObjType
IObject
.
GetType
()
{
return
ObjType
.
Camera
;
}
}
Assets/Scripts/Interactors/Interfaces/IObject.cs
0 → 100644
View file @
238ad08b
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
public
enum
ObjType
{
NULL
,
Briefcase
,
Camera
,
Mannequin
}
public
interface
IObject
{
GameObject
GetObject
();
Vector2
GetPos
();
ObjType
GetType
();
}
Assets/Scripts/Interactors/Interfaces/IObject.cs.meta
0 → 100644
View file @
238ad08b
fileFormatVersion: 2
guid: e7d883246c45c6f4f94bae2ca2d05d6f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/Interactors/Mannequin.cs
View file @
238ad08b
...
...
@@ -2,7 +2,7 @@
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
Mannequin
:
MonoBehaviour
,
IBulletInteractor
public
class
Mannequin
:
MonoBehaviour
,
I
Object
,
I
BulletInteractor
{
[
SerializeField
]
private
Mesh
[]
mannequinMesh
=
new
Mesh
[
2
];
...
...
@@ -48,4 +48,19 @@ public class Mannequin : MonoBehaviour, IBulletInteractor
{
Color
=
isWhite
?
Color
.
white
:
Color
.
black
;
}
public
GameObject
GetObject
()
{
return
gameObject
;
}
public
Vector2
GetPos
()
{
return
new
Vector2
(
transform
.
position
.
x
,
transform
.
position
.
z
);
}
ObjType
IObject
.
GetType
()
{
return
ObjType
.
Mannequin
;
}
}
Assets/Scripts/Interactors/Mirror.cs
View file @
238ad08b
...
...
@@ -3,11 +3,8 @@ using System.Collections.Generic;
using
UnityEngine
;
using
UnityEngine.AI
;
public
class
Mirror
:
MonoBehaviour
,
IBulletInteractor
,
IBreakable
public
class
Mirror
:
Wall
,
IBulletInteractor
,
IBreakable
{
private
Camera
camera
;
private
RenderTexture
rt
;
public
void
Break
()
{
Destroy
(
gameObject
);
...
...
@@ -17,18 +14,201 @@ public class Mirror : MonoBehaviour, IBulletInteractor, IBreakable
{
if
(
bullet
is
FakeBullet
)
{
//Break Mirror & Make reflected objects
// Make reflected objects
CopyObjects
(
PlayerController
.
inst
.
currentPlayer
);
}
else
if
(
bullet
is
TruthBullet
)
{
// Break Mirror
}
}
private
void
Start
()
/// <summary>
/// copy objects which reflected by this mirror
/// </summary>
/// <param name="_shooter">transform of shooter</param>
private
void
CopyObjects
(
Player
_shooter
)
{
camera
=
GetComponent
<
Camera
>();
//TODO : Create RenderTexture and put it into Camera's targeTexture
Vector2Int
stPos
=
_shooter
.
pos
;
// position of shooter's cell
List
<
Pair
<
float
,
float
>>
parRay
=
new
List
<
Pair
<
float
,
float
>>
{
new
Pair
<
float
,
float
>(
0
,
1
)
};
// check before reflect (check walls and mirrors)
foreach
(
var
wall
in
MapManager
.
inst
.
currentMap
.
wallGrid
)
{
Pair
<
float
,
float
>
pair
=
new
Pair
<
float
,
float
>(
PointToParRay
(
stPos
,
wall
.
Value
.
ldPos
,
false
),
PointToParRay
(
stPos
,
wall
.
Value
.
rdPos
,
false
));
if
(
pair
.
l
>
pair
.
r
)
pair
=
pair
.
Swap
();
SubtractRay
(
parRay
,
pair
);
}
foreach
(
var
mirr
in
MapManager
.
inst
.
currentMap
.
mirrorGrid
)
{
if
(
mirr
.
Value
!=
this
)
{
Pair
<
float
,
float
>
pair
=
new
Pair
<
float
,
float
>(
PointToParRay
(
stPos
,
mirr
.
Value
.
ldPos
,
false
),
PointToParRay
(
stPos
,
mirr
.
Value
.
rdPos
,
false
));
if
(
pair
.
l
>
pair
.
r
)
pair
=
pair
.
Swap
();
SubtractRay
(
parRay
,
pair
);
}
}
// check after reflect, if obj or floor, copy else if wall or mirror, Subtract
int
side
,
i
;
if
(
dir
)
// horizontal, parallel with x
{
side
=
(
ldPos
.
y
-
stPos
.
y
>
0
)
?
-
1
:
1
;
i
=
ldPos
.
y
;
}
else
// vertical, parallel with y
{
side
=
(
ldPos
.
x
-
stPos
.
x
>
0
)
?
-
1
:
1
;
i
=
ldPos
.
x
;
}
for
(;
i
<
MapManager
.
inst
.
currentMap
.
maxMapSize
;
i
+=
side
)
{
foreach
(
var
floor
in
MapManager
.
inst
.
currentMap
.
floorGrid
)
{
if
((
dir
?
floor
.
Key
.
y
:
floor
.
Key
.
x
)
==
i
)
{
if
(
IsInRay
(
parRay
,
PointToParRay
(
stPos
,
floor
.
Value
.
mapPos
,
true
)))
{
// copy floor
int
nextx
=
dir
?
floor
.
Key
.
x
:
2
*
ldPos
.
x
-
floor
.
Key
.
x
;
int
nexty
=
dir
?
2
*
ldPos
.
y
-
floor
.
Key
.
y
:
floor
.
Key
.
y
;
MapManager
.
inst
.
currentMap
.
CreateFloor
(
nextx
,
nexty
);
}
}
}
foreach
(
var
obj
in
MapManager
.
inst
.
currentMap
.
objectGrid
)
{
if
((
dir
?
obj
.
Key
.
y
:
obj
.
Key
.
x
)
==
i
)
{
if
(
IsInRay
(
parRay
,
PointToParRay
(
stPos
,
obj
.
Value
.
GetPos
(),
true
)))
{
/*copy object*/
}
}
}
foreach
(
var
wall
in
MapManager
.
inst
.
currentMap
.
wallGrid
)
{
if
((
dir
?
wall
.
Key
.
y
:
wall
.
Key
.
x
)
==
i
)
{
Pair
<
float
,
float
>
pair
=
new
Pair
<
float
,
float
>(
PointToParRay
(
stPos
,
wall
.
Value
.
ldPos
,
true
),
PointToParRay
(
stPos
,
wall
.
Value
.
rdPos
,
true
));
if
(
pair
.
l
>
pair
.
r
)
pair
=
pair
.
Swap
();
/*copy wall*/
SubtractRay
(
parRay
,
pair
);
}
}
foreach
(
var
mirr
in
MapManager
.
inst
.
currentMap
.
mirrorGrid
)
{
if
(
mirr
.
Value
!=
this
&&
(
dir
?
mirr
.
Key
.
y
:
mirr
.
Key
.
x
)
==
i
)
{
Pair
<
float
,
float
>
pair
=
new
Pair
<
float
,
float
>(
PointToParRay
(
stPos
,
mirr
.
Value
.
ldPos
,
true
),
PointToParRay
(
stPos
,
mirr
.
Value
.
rdPos
,
true
));
if
(
pair
.
l
>
pair
.
r
)
pair
=
pair
.
Swap
();
/*copy mirror*/
SubtractRay
(
parRay
,
pair
);
}
}
}
}
private
void
Update
()
/// <summary>
/// subtract _sub from _parRay
/// </summary>
/// <param name="_parRay">ray list to subtracted</param>
/// <param name="_sub">ray to subtract</param>
void
SubtractRay
(
List
<
Pair
<
float
,
float
>>
_parRay
,
Pair
<
float
,
float
>
_sub
)
{
//TODO :Calculate Camera's Position and Rotation
foreach
(
Pair
<
float
,
float
>
pair
in
_parRay
)
{
if
(
pair
.
r
<
_sub
.
l
||
pair
.
l
>
_sub
.
r
)
continue
;
float
[]
arr
=
{
pair
.
l
,
pair
.
r
,
_sub
.
l
,
_sub
.
r
};
for
(
int
i
=
0
;
i
<
4
;
i
++)
// sort arr
{
float
smallest
=
arr
[
i
];
int
smallIdx
=
i
;
for
(
int
j
=
i
+
1
;
j
<
4
;
j
++)
{
if
(
smallest
>
arr
[
j
])
{
smallest
=
arr
[
j
];
smallIdx
=
j
;
}
}
float
temp
=
arr
[
i
];
arr
[
i
]
=
smallest
;
arr
[
smallIdx
]
=
temp
;
}
// subtract
if
(
arr
[
0
]
==
_sub
.
l
&&
arr
[
2
]
==
_sub
.
r
)
{
pair
.
l
=
_sub
.
r
;
}
else
if
(
arr
[
1
]
==
_sub
.
l
&&
arr
[
3
]
==
_sub
.
r
)
{
pair
.
r
=
_sub
.
l
;
}
else
if
(
arr
[
1
]
==
_sub
.
l
&&
arr
[
2
]
==
_sub
.
r
)
{
_parRay
.
Add
(
new
Pair
<
float
,
float
>(
pair
.
r
,
_sub
.
r
));
pair
.
r
=
_sub
.
l
;
}
}
}
/// <summary>
/// check if _range is included in _parRay
/// </summary>
/// <param name="_parRay">ray list to be checked</param>
/// <param name="_range">range to check</param>
/// <returns>if _range is included in _parRay, return true</returns>
bool
IsInRay
(
List
<
Pair
<
float
,
float
>>
_parRay
,
Pair
<
float
,
float
>
_range
)
{
bool
output
=
false
;
foreach
(
Pair
<
float
,
float
>
pair
in
_parRay
)
{
if
(
pair
.
r
<=
_range
.
l
||
pair
.
l
>=
_range
.
r
)
continue
;
else
{
output
=
true
;
break
;
}
}
return
output
;
}
bool
IsInRay
(
List
<
Pair
<
float
,
float
>>
_parRay
,
float
_obj
)
{
foreach
(
Pair
<
float
,
float
>
pair
in
_parRay
)
{
if
(
pair
.
l
<=
_obj
&&
pair
.
r
>=
_obj
)
return
true
;
}
return
false
;
}
/// <summary>
/// calculate where _chPos is from _stPos
/// </summary>
/// <param name="_stPos">position of shooter</param>
/// <param name="_chPos">position of object</param>
/// <param name="_isRefl">if we calculate after reflecting, true</param>
/// <returns>float value of _chPos is posed</returns>
float
PointToParRay
(
Vector2
_stPos
,
Vector2
_chPos
,
bool
_isRefl
)
{
if
(
dir
)
// horizontal
{
float
dist
=
_chPos
.
y
-
_stPos
.
y
+
(
_isRefl
?
(
ldPos
.
y
-
_chPos
.
y
)
*
2
:
0
);
float
spreadLen
=
len
*
dist
/
(
ldPos
.
y
-
_stPos
.
y
);
float
rayStPos
=
_stPos
.
x
+
(
ldPos
.
x
-
_stPos
.
x
)
*
dist
/
(
ldPos
.
y
-
_stPos
.
y
);
return
(
_chPos
.
x
-
rayStPos
)
/
spreadLen
;
}
else
// vertical
{
float
dist
=
_chPos
.
x
-
_stPos
.
x
+
(
_isRefl
?
(
ldPos
.
x
-
_chPos
.
x
)
*
2
:
0
);
float
spreadLen
=
len
*
dist
/
(
ldPos
.
x
-
_stPos
.
x
);
float
rayStPos
=
_stPos
.
y
+
(
ldPos
.
y
-
_stPos
.
y
)
*
dist
/
(
ldPos
.
x
-
_stPos
.
x
);
return
(
_chPos
.
y
-
rayStPos
)
/
spreadLen
;
}
}
}
Assets/Scripts/Interactors/NormalWall.cs
View file @
238ad08b
...
...
@@ -2,7 +2,7 @@
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
NormalWall
:
MonoBehaviour
,
IBulletInteractor
public
class
NormalWall
:
Wall
,
IBulletInteractor
{
public
void
Interact
(
Bullet
bullet
)
{
...
...
@@ -12,7 +12,11 @@ public class NormalWall : MonoBehaviour, IBulletInteractor
}
else
if
(
bullet
is
MirrorBullet
)
{
gameObject
.
AddComponent
<
Mirror
>();
Mirror
mirror
=
gameObject
.
AddComponent
<
Mirror
>();
GetComponent
<
Renderer
>().
material
=
GameManager
.
inst
.
mirrorMaterial
;
mirror
.
SetmapPos
(
mapPos
);
mirror
.
len
=
len
;
mirror
.
type
=
WallType
.
Mirror
;
Destroy
(
this
);
}
}
...
...
Assets/Scripts/Managers/GameManager.cs
View file @
238ad08b
...
...
@@ -5,6 +5,7 @@ using System.Linq;
public
class
GameManager
:
SingletonBehaviour
<
GameManager
>
{
public
Material
mirrorMaterial
;
/*
private List<IPlayerInteractor> playerInteractors;
...
...
Assets/Scripts/Map/Map.cs
View file @
238ad08b
...
...
@@ -7,8 +7,10 @@ public class Map : MonoBehaviour
{
public
int
testInputSizeX
,
testInputSizeY
;
public
int
maxMapSize
;
private
Dictionary
<
Vector2Int
,
Floor
>
floorGrid
;
private
Dictionary
<
Vector2
,
Wall
>
wallGrid
;
public
Dictionary
<
Vector2Int
,
Floor
>
floorGrid
;
public
Dictionary
<
Vector2
,
Wall
>
wallGrid
;
public
Dictionary
<
Vector2
,
Mirror
>
mirrorGrid
;
public
Dictionary
<
Vector2Int
,
IObject
>
objectGrid
;
public
GameObject
floors
;
public
GameObject
walls
;
public
List
<
Floor
>
startFloors
;
...
...
Assets/Scripts/Map/Wall.cs
View file @
238ad08b
...
...
@@ -2,12 +2,33 @@
using
System.Collections.Generic
;
using
UnityEngine
;
public
enum
WallType
{
NULL
,
Normal
,
Mirror
}
public
class
Wall
:
MonoBehaviour
{
/// <summary>
/// Position of this floor at the map.
/// </summary>
public
Vector2
mapPos
;
public
Vector2Int
ldPos
// left down pos
{
get
{
return
new
Vector2Int
((
int
)
mapPos
.
x
,
(
int
)
mapPos
.
y
);
}
}
public
Vector2Int
rdPos
// right down pos
{
get
{
return
ldPos
+
(
dir
?
new
Vector2Int
(
len
,
0
)
:
new
Vector2Int
(
0
,
len
));
}
}
public
bool
dir
// false: ver, true: hor
{
get
{
return
(
int
)(
transform
.
rotation
.
eulerAngles
.
y
/
90
)
%
2
!=
1
;
}
}
public
int
len
=
1
;
// length of wall
public
WallType
type
;
public
void
SetmapPos
(
Vector2
pos
)
{
...
...
Assets/Scripts/Player.cs
View file @
238ad08b
...
...
@@ -5,6 +5,11 @@ using UnityEngine.AI;
public
class
Player
:
MonoBehaviour
{
public
Vector2Int
pos
{
get
{
return
new
Vector2Int
((
int
)
transform
.
position
.
x
,
(
int
)
transform
.
position
.
y
);
}
}
Coroutine
playerArrivalCheck
;
public
GameObject
head
;
...
...
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