Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
tetra-tower
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Oenos
tetra-tower
Commits
c626bd44
Commit
c626bd44
authored
Feb 13, 2019
by
15김민규
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
벽, 낭떠러지 체크 확인 가능하도록 함. velocity로 움직이는 것을 Idle까지 개선. Enum 및 Enemy에서의 함수를 통해 반복되는 행동 간략화
parent
de12185d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
154 additions
and
59 deletions
+154
-59
melee.controller
Assets/Animation/Enemy/melee.controller
+5
-5
Room Start 1-1.prefab
Assets/Prefabs/Rooms/SpecialRoom/Room Start 1-1.prefab
+1
-1
testEnemy.unity
Assets/Scenes/testEnemy.unity
+58
-1
EnemyMeleeIdle.cs
...Scripts/Characters/Enemy/Animator State/EnemyMeleeIdle.cs
+19
-10
Enemy.cs
Assets/Scripts/Characters/Enemy/Enemy.cs
+64
-42
Enumerators.cs
Assets/Scripts/Enumerators.cs
+7
-0
No files found.
Assets/Animation/Enemy/melee.controller
View file @
c626bd44
...
...
@@ -13,31 +13,31 @@ AnimatorController:
m_DefaultFloat
:
0
m_DefaultInt
:
0
m_DefaultBool
:
0
m_Controller
:
{
fileID
:
0
}
m_Controller
:
{
fileID
:
910000
0
}
-
m_Name
:
AttackTrigger
m_Type
:
9
m_DefaultFloat
:
0
m_DefaultInt
:
0
m_DefaultBool
:
0
m_Controller
:
{
fileID
:
0
}
m_Controller
:
{
fileID
:
910000
0
}
-
m_Name
:
DamagedTrigger
m_Type
:
9
m_DefaultFloat
:
0
m_DefaultInt
:
0
m_DefaultBool
:
0
m_Controller
:
{
fileID
:
0
}
m_Controller
:
{
fileID
:
910000
0
}
-
m_Name
:
DeadTrigger
m_Type
:
9
m_DefaultFloat
:
0
m_DefaultInt
:
0
m_DefaultBool
:
0
m_Controller
:
{
fileID
:
0
}
m_Controller
:
{
fileID
:
910000
0
}
-
m_Name
:
knockbackTime
m_Type
:
1
m_DefaultFloat
:
0
m_DefaultInt
:
0
m_DefaultBool
:
0
m_Controller
:
{
fileID
:
0
}
m_Controller
:
{
fileID
:
910000
0
}
m_AnimatorLayers
:
-
serializedVersion
:
5
m_Name
:
Base Layer
...
...
Assets/Prefabs/Rooms/SpecialRoom/Room Start 1-1.prefab
View file @
c626bd44
...
...
@@ -219,7 +219,7 @@ Transform:
m_PrefabInternal
:
{
fileID
:
100100000
}
m_GameObject
:
{
fileID
:
1124637384100458
}
m_LocalRotation
:
{
x
:
0
,
y
:
0
,
z
:
0
,
w
:
1
}
m_LocalPosition
:
{
x
:
2.5
,
y
:
9
,
z
:
0
}
m_LocalPosition
:
{
x
:
4
,
y
:
9
,
z
:
0
}
m_LocalScale
:
{
x
:
1
,
y
:
1
,
z
:
1
}
m_Children
:
[]
m_Father
:
{
fileID
:
4054145534218116
}
...
...
Assets/Scenes/testEnemy.unity
View file @
c626bd44
...
...
@@ -1149,7 +1149,8 @@ Transform:
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_Children
:
-
{
fileID
:
1509282194
}
m_Father
:
{
fileID
:
0
}
m_RootOrder
:
4
m_LocalEulerAnglesHint
:
{
x
:
0
,
y
:
0
,
z
:
0
}
...
...
@@ -1329,6 +1330,62 @@ Canvas:
m_CorrespondingSourceObject
:
{
fileID
:
223237664237935382
,
guid
:
692aad2449e06054799ea4706578fb23
,
type
:
2
}
m_PrefabInternal
:
{
fileID
:
28941081
}
---
!u!1001
&1509282193
Prefab
:
m_ObjectHideFlags
:
0
serializedVersion
:
2
m_Modification
:
m_TransformParent
:
{
fileID
:
1244139631
}
m_Modifications
:
-
target
:
{
fileID
:
66792933649035248
,
guid
:
0443c2e9410bbe545bda40dc30fa6a63
,
type
:
2
}
propertyPath
:
m_ColliderPaths.Array.size
value
:
0
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
4874486600194970
,
guid
:
0443c2e9410bbe545bda40dc30fa6a63
,
type
:
2
}
propertyPath
:
m_LocalPosition.x
value
:
0
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
4874486600194970
,
guid
:
0443c2e9410bbe545bda40dc30fa6a63
,
type
:
2
}
propertyPath
:
m_LocalPosition.y
value
:
0
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
4874486600194970
,
guid
:
0443c2e9410bbe545bda40dc30fa6a63
,
type
:
2
}
propertyPath
:
m_LocalPosition.z
value
:
0
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
4874486600194970
,
guid
:
0443c2e9410bbe545bda40dc30fa6a63
,
type
:
2
}
propertyPath
:
m_LocalRotation.x
value
:
0
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
4874486600194970
,
guid
:
0443c2e9410bbe545bda40dc30fa6a63
,
type
:
2
}
propertyPath
:
m_LocalRotation.y
value
:
0
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
4874486600194970
,
guid
:
0443c2e9410bbe545bda40dc30fa6a63
,
type
:
2
}
propertyPath
:
m_LocalRotation.z
value
:
0
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
4874486600194970
,
guid
:
0443c2e9410bbe545bda40dc30fa6a63
,
type
:
2
}
propertyPath
:
m_LocalRotation.w
value
:
1
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
4874486600194970
,
guid
:
0443c2e9410bbe545bda40dc30fa6a63
,
type
:
2
}
propertyPath
:
m_RootOrder
value
:
0
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
1915452461634262
,
guid
:
0443c2e9410bbe545bda40dc30fa6a63
,
type
:
2
}
propertyPath
:
m_IsActive
value
:
0
objectReference
:
{
fileID
:
0
}
m_RemovedComponents
:
[]
m_SourcePrefab
:
{
fileID
:
100100000
,
guid
:
0443c2e9410bbe545bda40dc30fa6a63
,
type
:
2
}
m_IsPrefabAsset
:
0
---
!u!4
&1509282194
stripped
Transform
:
m_CorrespondingSourceObject
:
{
fileID
:
4874486600194970
,
guid
:
0443c2e9410bbe545bda40dc30fa6a63
,
type
:
2
}
m_PrefabInternal
:
{
fileID
:
1509282193
}
---
!u!4
&1604462410
stripped
Transform
:
m_CorrespondingSourceObject
:
{
fileID
:
4884929250924374
,
guid
:
e6794ab8e2e4c6340a23b382e9497cbb
,
...
...
Assets/Scripts/Characters/Enemy/Animator State/EnemyMeleeIdle.cs
View file @
c626bd44
...
...
@@ -11,30 +11,39 @@ public class EnemyMeleeIdle : StateMachineBehaviour {
Vector3
leftsideAngle
=
new
Vector3
(
0
,
0
,
0
);
Vector3
rightsideAngle
=
new
Vector3
(
0
,
180
,
0
);
Transform
animatorRoot
;
Enemy
enemy
;
NumeratedDir
moveDir
=
NumeratedDir
.
Left
;
// go left first
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
override
public
void
OnStateEnter
(
Animator
animator
,
AnimatorStateInfo
stateInfo
,
int
layerIndex
)
{
origin
=
animator
.
transform
.
position
;
patrolRange
=
animator
.
GetComponent
<
Enemy
>().
patrolRange
;
noticeRange
=
animator
.
GetComponent
<
Enemy
>().
noticeRange
;
patrolSpeed
=
animator
.
GetComponent
<
Enemy
>().
patrolSpeed
;
animatorRoot
=
animator
.
transform
.
parent
;
enemy
=
animator
.
GetComponent
<
Enemy
>();
patrolRange
=
enemy
.
patrolRange
;
noticeRange
=
enemy
.
noticeRange
;
patrolSpeed
=
enemy
.
patrolSpeed
;
enemy
.
ChangeDir
(
NumeratedDir
.
Left
);
enemy
.
ChangeVelocityX
((
int
)
moveDir
*
patrolSpeed
);
}
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
override
public
void
OnStateUpdate
(
Animator
animator
,
AnimatorStateInfo
stateInfo
,
int
layerIndex
)
{
if
(
animator
.
GetComponent
<
Enemy
>()
.
PlayerDistance
<
noticeRange
)
if
(
enemy
.
PlayerDistance
<
noticeRange
)
{
animator
.
SetTrigger
(
"TrackTrigger"
);
return
;
}
Vector2
currPosition
=
animatorRoot
.
position
;
Vector2
movingDistance
=
-
1
*
animatorRoot
.
right
*
patrolSpeed
*
Time
.
deltaTime
;
// go left first
animatorRoot
.
gameObject
.
GetComponent
<
Rigidbody2D
>().
MovePosition
(
currPosition
+
movingDistance
);
if
(
Mathf
.
Abs
(
animatorRoot
.
position
.
x
-
origin
.
x
)
>
patrolRange
)
int
integerDir
=
(
int
)
enemy
.
MoveDir
;
float
span
=
animatorRoot
.
position
.
x
-
origin
.
x
;
if
((
Mathf
.
Abs
(
span
)
>
patrolRange
&&
span
*
integerDir
>
0
)
||
enemy
.
WallTest
[(
integerDir
+
1
)
/
2
]
||
enemy
.
CliffTest
[(
integerDir
+
1
)
/
2
]
)
{
animatorRoot
.
eulerAngles
=
(
origin
.
x
<
animatorRoot
.
position
.
x
)
?
leftsideAngle
:
rightsideAngle
;
enemy
.
ChangeDir
(
integerDir
*
-
1
)
;
}
}
...
...
Assets/Scripts/Characters/Enemy/Enemy.cs
View file @
c626bd44
using
System
.Collections
;
using
System.Collections
.Generic
;
using
System
;
using
System.Collections
;
using
UnityEngine
;
using
Random
=
UnityEngine
.
Random
;
public
class
Enemy
:
MonoBehaviour
{
...
...
@@ -34,13 +34,18 @@ public class Enemy : MonoBehaviour {
private
LifeStoneManager
lifeStoneManager
;
private
EnemyManager
enemyManager
;
// for
animation
// for
movement
private
Animator
animator
;
public
bool
Invisible
{
get
;
private
set
;
}
public
bool
DuringKnockback
{
get
;
private
set
;
}
public
float
PlayerDistance
{
get
;
private
set
;
}
private
readonly
float
knockbackCritPoint
=
0.25f
;
public
bool
[]
WallTest
{
get
;
private
set
;
}
// {left, right}
public
bool
[]
CliffTest
{
get
;
private
set
;
}
// {left, right}
public
NumeratedDir
MoveDir
{
get
;
private
set
;
}
// drop item
private
int
[]
dropTable
;
...
...
@@ -52,69 +57,63 @@ public class Enemy : MonoBehaviour {
inventoryManager
=
GameObject
.
Find
(
"InventoryManager"
).
GetComponent
<
InventoryManager
>();
lifeStoneManager
=
GameObject
.
Find
(
"UI Canvas"
).
transform
.
GetChild
(
0
).
GetComponent
<
LifeStoneManager
>();
animator
=
GetComponent
<
Animator
>();
WallTest
=
new
bool
[]
{
false
,
false
};
CliffTest
=
new
bool
[]
{
false
,
false
};
}
private
void
Start
()
{
MoveDir
=
NumeratedDir
.
Left
;
currHealth
=
maxHealth
;
Invisible
=
DuringKnockback
=
false
;
dropTable
=
enemyManager
.
DropTableByID
[
monsterID
];
Physics2D
.
IgnoreCollision
(
enemyManager
.
Player
.
gameObject
.
GetComponent
<
Collider2D
>(),
transform
.
parent
.
GetComponent
<
Collider2D
>());
}
private
void
FixedUpdate
()
{
bool
wallTest
=
IsTouchingWall
();
if
(
wallTest
)
{
Debug
.
Log
(
"Touching wall"
);
}
bool
cliffTest
=
IsAdvancingToCliff
();
if
(
cliffTest
)
{
Debug
.
Log
(
"Advancing to cliff"
);
}
}
private
void
Update
()
{
PlayerDistance
=
Vector2
.
Distance
(
enemyManager
.
Player
.
transform
.
position
,
transform
.
parent
.
position
);
CheckCliff
();
CheckWall
();
}
// check whether enemy is
advancing
to cliff
p
ublic
bool
IsAdvancingTo
Cliff
()
// check whether enemy is
near
to cliff
p
rivate
void
Check
Cliff
()
{
Vector2
velocity
=
transform
.
parent
.
GetComponent
<
Rigidbody2D
>().
velocity
;
Vector2
colliderSize
=
transform
.
parent
.
GetComponent
<
BoxCollider2D
>().
size
;
if
(
velocity
.
x
==
0
)
{
return
false
;
}
int
enemyDir
=
(
velocity
.
x
>
0
)
?
1
:
-
1
;
Vector2
origin
=
(
Vector2
)
transform
.
parent
.
position
+
enemyDir
*
new
Vector2
(
colliderSize
.
x
/
2.0f
,
0
);
Vector2
direction
=
Vector2
.
down
;
float
distance
=
colliderSize
.
y
/
2.0f
;
int
layerMask
=
LayerMask
.
NameToLayer
(
"platform"
);
RaycastHit2D
hit
=
Physics2D
.
Raycast
(
origin
,
direction
,
distance
,
layerMask
);
foreach
(
int
Dir
in
Enum
.
GetValues
(
typeof
(
NumeratedDir
)))
{
Vector2
origin
=
(
Vector2
)
transform
.
parent
.
position
+
Dir
*
new
Vector2
(
colliderSize
.
x
/
2.0f
,
0
);
Vector2
direction
=
Vector2
.
down
;
float
distance
=
colliderSize
.
y
/
2.0f
;
int
layerMask
=
LayerMask
.
NameToLayer
(
"platform"
);
RaycastHit2D
hit
=
Physics2D
.
Raycast
(
origin
,
direction
,
distance
,
layerMask
);
return
(
hit
.
collider
==
null
);
CliffTest
[(
Dir
+
1
)
/
2
]
=
(
hit
.
collider
==
null
);
}
}
p
ublic
bool
IsTouching
Wall
()
// check whether enemy is touching wall
p
rivate
void
Check
Wall
()
{
int
enemyDir
=
(
transform
.
parent
.
eulerAngles
.
y
==
180.0f
)
?
1
:
-
1
;
Vector2
colliderSize
=
transform
.
parent
.
GetComponent
<
BoxCollider2D
>().
size
;
Vector2
origin
=
(
Vector2
)
transform
.
parent
.
position
+
enemyDir
*
new
Vector2
(
colliderSize
.
x
/
2.0f
,
0
);
Vector2
direction
=
Vector2
.
right
*
enemyDir
;
float
distance
=
0.02f
;
int
layerMask
=
LayerMask
.
GetMask
(
"Wall"
,
"OuterWall"
);
RaycastHit2D
hit
=
Physics2D
.
Raycast
(
origin
,
direction
,
distance
,
layerMask
);
foreach
(
int
Dir
in
Enum
.
GetValues
(
typeof
(
NumeratedDir
)))
{
Vector2
origin
=
(
Vector2
)
transform
.
parent
.
position
+
Dir
*
new
Vector2
(
colliderSize
.
x
/
2.0f
,
0
);
Vector2
direction
=
Vector2
.
right
*
Dir
;
float
distance
=
0.02f
;
int
layerMask
=
LayerMask
.
GetMask
(
"Wall"
,
"OuterWall"
);
RaycastHit2D
hit
=
Physics2D
.
Raycast
(
origin
,
direction
,
distance
,
layerMask
);
return
(
hit
.
collider
!=
null
);
WallTest
[(
Dir
+
1
)
/
2
]
=
(
hit
.
collider
!=
null
);
}
}
// hit by player or debuff
public
void
GetDamaged
(
PlayerAttackInfo
attack
)
{
public
void
GetDamaged
(
PlayerAttackInfo
attack
)
{
currHealth
-=
attack
.
damage
;
if
(
currHealth
<=
0
)
{
...
...
@@ -137,6 +136,28 @@ public class Enemy : MonoBehaviour {
}
}
// change speed of rigidbody of enemy
public
void
ChangeVelocityX
(
float
val
)
{
Vector2
tempVelocity
=
transform
.
parent
.
GetComponent
<
Rigidbody2D
>().
velocity
;
tempVelocity
.
x
=
val
;
transform
.
parent
.
GetComponent
<
Rigidbody2D
>().
velocity
=
tempVelocity
;
}
public
void
ChangeDir
(
NumeratedDir
dir
)
{
MoveDir
=
dir
;
transform
.
parent
.
eulerAngles
=
(
dir
==
NumeratedDir
.
Left
)
?
new
Vector2
(
0
,
0
)
:
new
Vector2
(
0
,
180
);
ChangeVelocityX
((
int
)
dir
*
Mathf
.
Abs
(
transform
.
parent
.
GetComponent
<
Rigidbody2D
>().
velocity
.
x
));
}
public
void
ChangeDir
(
int
dir
)
{
MoveDir
=
(
NumeratedDir
)
dir
;
transform
.
parent
.
eulerAngles
=
((
NumeratedDir
)
dir
==
NumeratedDir
.
Left
)
?
new
Vector2
(
0
,
0
)
:
new
Vector2
(
0
,
180
);
ChangeVelocityX
(
dir
*
Mathf
.
Abs
(
transform
.
parent
.
GetComponent
<
Rigidbody2D
>().
velocity
.
x
));
}
// Animation Event
// Dead
public
void
DeadEvent
()
...
...
@@ -191,10 +212,11 @@ public class Enemy : MonoBehaviour {
IEnumerator
Knockback
(
float
knockbackDist
,
float
knockbackTime
)
{
DuringKnockback
=
true
;
bool
isPlayerLeft
=
(
enemyManager
.
Player
.
transform
.
position
.
x
-
transform
.
parent
.
position
.
x
<=
0
);
NumeratedDir
isPlayerLeft
=
(
enemyManager
.
Player
.
transform
.
position
.
x
-
transform
.
parent
.
position
.
x
<=
0
)
?
NumeratedDir
.
Left
:
NumeratedDir
.
Right
;
float
knockbackVelocity
=
(
(
isPlayerLeft
)
?
1
:
-
1
)
*
knockbackDist
/
knockbackTime
;
transform
.
parent
.
eulerAngles
=
(
isPlayerLeft
)
?
new
Vector2
(
0.0f
,
0.0f
)
:
new
Vector2
(
0.0f
,
180.0f
);
float
knockbackVelocity
=
(
int
)
isPlayerLeft
*
knockbackDist
/
knockbackTime
;
transform
.
parent
.
eulerAngles
=
(
isPlayerLeft
==
NumeratedDir
.
Left
)
?
new
Vector2
(
0.0f
,
0.0f
)
:
new
Vector2
(
0.0f
,
180.0f
);
Vector2
tempVelocity
=
transform
.
parent
.
GetComponent
<
Rigidbody2D
>().
velocity
;
tempVelocity
.
x
=
knockbackVelocity
;
...
...
Assets/Scripts/Enumerators.cs
View file @
c626bd44
...
...
@@ -6,6 +6,13 @@
blind
,
charm
};
public
enum
NumeratedDir
{
Left
=
-
1
,
Right
=
1
};
public
enum
PlayerDebuffCase
{
...
...
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