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
eb02ff1b
Commit
eb02ff1b
authored
Dec 10, 2018
by
15김민규
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sang-un will implement LoadDropTable
parent
ac20fee3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
148 additions
and
20 deletions
+148
-20
exam.csv
Assets/Data/exam.csv
+7
-0
Enemy.cs
Assets/Scripts/Characters/Enemy.cs
+51
-10
EnemyManager.cs
Assets/Scripts/Characters/EnemyManager.cs
+24
-10
Singleton.cs
Assets/Scripts/Singleton.cs
+55
-0
Singleton.cs.meta
Assets/Scripts/Singleton.cs.meta
+11
-0
No files found.
Assets/Data/exam.csv
0 → 100644
View file @
eb02ff1b
monsterid,name,itemid,weight
1,몬스터1,2,3
,,3,2
2,몬스터2,5,3
,,6,1
,,7,2
3,몬스터3,4,1
Assets/Scripts/Characters/Enemy.cs
View file @
eb02ff1b
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
Enemy
:
MonoBehaviour
{
// Use this for initialization
void
Start
()
{
}
// Update is called once per frame
void
Update
()
{
}
private
readonly
float
maxHealth
;
private
readonly
float
weight
;
private
float
currHealth
;
private
EnemyManager
.
State
currState
;
private
List
<
int
[
]>
dropTable
;
// [item ID, numerator]
private
Dictionary
<
EnemyManager
.
State
,
EnemyManager
.
Action
<
int
>>
actionByState
;
public
Enemy
(
uint
id
,
float
maxHealth
,
float
weight
)
{
this
.
maxHealth
=
maxHealth
;
this
.
weight
=
weight
;
this
.
currHealth
=
maxHealth
;
this
.
dropTable
=
GetDropTable
(
id
);
this
.
actionByState
=
GetActionByState
(
id
);
this
.
currState
=
EnemyManager
.
State
.
Idle
;
}
public
void
GetDamaged
(
float
damage
)
{
float
unitDist
=
3
;
currHealth
-=
damage
;
if
(
currHealth
<=
0
)
{
mamaWooWooWoo_I_Dont_Wanna_Die
();
return
;
}
float
knockback_dist
=
damage
*
unitDist
/
weight
;
// do something - knockback animation
}
private
List
<
int
[
]>
GetDropTable
(
uint
id
)
{
List
<
int
[
]>
resultList
=
new
List
<
int
[
]>
();
return
resultList
;
}
private
Dictionary
<
EnemyManager
.
State
,
EnemyManager
.
Action
<
int
>>
GetActionByState
(
uint
id
)
{
var
resultDictionary
=
new
Dictionary
<
EnemyManager
.
State
,
EnemyManager
.
Action
<
int
>>();
return
resultDictionary
;
}
private
void
mamaWooWooWoo_I_Dont_Wanna_Die
()
{
int
dropItemId
=
-
1
;
if
(
dropTable
!=
null
)
{
float
denominator
=
dropTable
[
dropTable
.
Count
-
1
][
1
];
float
numerator
=
Random
.
Range
(
0f
,
denominator
);
foreach
(
var
drop
in
dropTable
)
{
if
(
numerator
<=
drop
[
1
])
{
dropItemId
=
drop
[
0
];
break
;
}
}
}
// spawn a item that has ID
// destroy itself (or, deactivate for pooling)
Destroy
(
gameObject
);
}
}
Assets/Scripts/Characters/EnemyManager.cs
View file @
eb02ff1b
...
...
@@ -2,15 +2,29 @@
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
EnemyManager
:
MonoBehaviour
{
public
class
EnemyManager
:
Singleton
<
EnemyManager
>
{
public
enum
State
{
Idle
,
Track
,
Attack
}
// 상속을 통해 수정할 가능성 높음. 염두만 해 두자.
// Use this for initialization
void
Start
()
{
}
// Update is called once per frame
void
Update
()
{
}
public
delegate
void
Action
<
T
>();
private
Dictionary
<
uint
,
List
<
int
[
]>
>
dropTableByID
;
private
Dictionary
<
uint
,
List
<
int
[
]>
>
actionDictByID
;
protected
EnemyManager
()
{
string
dropTableDataPath
=
null
;
string
actionTableDataPath
=
null
;
LoadDropTable
(
dropTableDataPath
);
LoadActionTable
(
actionTableDataPath
);
}
private
void
LoadDropTable
(
string
dataPath
)
{
}
private
void
LoadActionTable
(
string
dataPath
)
{
}
}
Assets/Scripts/Singleton.cs
0 → 100644
View file @
eb02ff1b
using
UnityEngine
;
using
System.Collections
;
/// <summary>
/// Be aware this will not prevent a non singleton constructor
/// such as `T myT = new T();`
/// To prevent that, add `protected T () {}` to your singleton class.
/// As a note, this is made as MonoBehaviour because we need Coroutines.
/// </summary>
public
abstract
class
Singleton
<
T
>
:
MonoBehaviour
where
T
:
MonoBehaviour
{
private
static
T
_instance
=
null
;
private
static
object
_syncobj
=
new
object
();
private
static
bool
appIsClosing
=
false
;
public
static
T
Instance
{
get
{
if
(
appIsClosing
)
return
null
;
lock
(
_syncobj
)
{
if
(
_instance
==
null
)
{
T
[]
objs
=
FindObjectsOfType
<
T
>();
if
(
objs
.
Length
>
0
)
_instance
=
objs
[
0
];
if
(
objs
.
Length
>
1
)
Debug
.
LogError
(
"There is more than one "
+
typeof
(
T
).
Name
+
" in the scene."
);
if
(
_instance
==
null
)
{
string
goName
=
typeof
(
T
).
ToString
();
GameObject
go
=
GameObject
.
Find
(
goName
);
if
(
go
==
null
)
go
=
new
GameObject
(
goName
);
_instance
=
go
.
AddComponent
<
T
>();
}
}
return
_instance
;
}
}
}
/// <summary>
/// When Unity quits, it destroys objects in a random order.
/// In principle, a Singleton is only destroyed when application quits.
/// If any script calls Instance after it have been destroyed,
/// it will create a buggy ghost object that will stay on the Editor scene
/// even after stopping playing the Application. Really bad!
/// So, this was made to be sure we're not creating that buggy ghost object.
/// </summary>
protected
virtual
void
OnApplicationQuit
()
{
// release reference on exit
appIsClosing
=
true
;
}
}
\ No newline at end of file
Assets/Scripts/Singleton.cs.meta
0 → 100644
View file @
eb02ff1b
fileFormatVersion: 2
guid: a4301571906f4094aba1a7696df8d3ba
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