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
3568fa26
Commit
3568fa26
authored
Feb 03, 2019
by
18류지석
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
아이템과 애드온을 등급 기준으로 랜덤 생성 가능
parent
5796d2ec
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
146 additions
and
14 deletions
+146
-14
InventoryManager.cs
Assets/Scripts/Item/InventoryManager.cs
+146
-14
No files found.
Assets/Scripts/Item/InventoryManager.cs
View file @
3568fa26
...
@@ -7,8 +7,8 @@ public class InventoryManager : MonoBehaviour {
...
@@ -7,8 +7,8 @@ public class InventoryManager : MonoBehaviour {
public
List
<
Item
>
itemList
=
new
List
<
Item
>();
public
List
<
Item
>
itemList
=
new
List
<
Item
>();
public
List
<
Addon
>
addonList
=
new
List
<
Addon
>();
public
List
<
Addon
>
addonList
=
new
List
<
Addon
>();
InventoryUI
ui
;
InventoryUI
ui
;
public
List
<
string
>
itemPool
=
new
List
<
string
>()
;
public
List
<
string
>
[]
itemPool
=
new
List
<
string
>[
4
]
;
public
List
<
string
>
addonPool
=
new
List
<
string
>()
;
public
List
<
string
>
[]
addonPool
=
new
List
<
string
>[
4
]
;
public
GameObject
droppedPrefab
;
public
GameObject
droppedPrefab
;
GameObject
player
;
GameObject
player
;
...
@@ -19,24 +19,70 @@ public class InventoryManager : MonoBehaviour {
...
@@ -19,24 +19,70 @@ public class InventoryManager : MonoBehaviour {
player
=
GameObject
.
Find
(
"Player"
);
player
=
GameObject
.
Find
(
"Player"
);
//itemPool
SetPool
();
itemPool
.
Add
(
"Baculus"
);
itemPool
.
Add
(
"BambooSpear"
);
itemPool
.
Add
(
"Bow"
);
itemPool
.
Add
(
"ChainSickle"
);
itemPool
.
Add
(
"Festo"
);
//addonPool
StartCoroutine
(
TestCoroutine
());
addonPool
.
Add
(
"ApprenticesMark"
);
}
addonPool
.
Add
(
"ParchmentPiece"
);
/// <summary>
addonPool
.
Add
(
"GlowingHerb"
);
/// Set Item, Addon Pool and shuffle them
/// </summary>
StartCoroutine
(
"TestCoroutine"
);
void
SetPool
()
{
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
itemPool
[
i
]
=
new
List
<
string
>();
addonPool
[
i
]
=
new
List
<
string
>();
}
}
itemPool
[
0
].
Add
(
"Bow"
);
itemPool
[
1
].
Add
(
"Baculus"
);
itemPool
[
1
].
Add
(
"BambooSpear"
);
itemPool
[
1
].
Add
(
"ChainSickle"
);
itemPool
[
1
].
Add
(
"ExplosionGloves"
);
itemPool
[
1
].
Add
(
"Festo"
);
itemPool
[
1
].
Add
(
"FrostShield"
);
itemPool
[
2
].
Add
(
"Ksanife"
);
itemPool
[
2
].
Add
(
"MeteorSword"
);
itemPool
[
2
].
Add
(
"Morgenstern"
);
//itemPool[3].Add("");
addonPool
[
0
].
Add
(
"ParchmentPiece"
);
addonPool
[
0
].
Add
(
"KnightsStirrup"
);
addonPool
[
0
].
Add
(
"ApprenticesMark"
);
addonPool
[
1
].
Add
(
"GlowingHerb"
);
addonPool
[
1
].
Add
(
"CoollyPride"
);
//addonPool[2].Add("");
//addonPool[3].Add("");
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
ShuffleList
(
itemPool
[
i
]);
ShuffleList
(
addonPool
[
i
]);
}
}
void
ShuffleList
(
List
<
string
>
list
)
{
System
.
Random
random
=
new
System
.
Random
();
for
(
int
i
=
list
.
Count
-
1
;
i
>=
0
;
i
--)
{
string
tmp
=
list
[
i
];
int
n
=
random
.
Next
(
i
+
1
);
list
[
i
]
=
list
[
n
];
list
[
n
]
=
tmp
;
}
}
IEnumerator
TestCoroutine
()
IEnumerator
TestCoroutine
()
{
{
yield
return
null
;
yield
return
null
;
ItemInstantiate
(
ItemQuality
.
Ordinary
,
player
.
transform
.
position
);
/*PushItem((Item)System.Activator.CreateInstance(System.Type.GetType(itemPool[0])));
/*PushItem((Item)System.Activator.CreateInstance(System.Type.GetType(itemPool[0])));
PushItem((Item)System.Activator.CreateInstance(System.Type.GetType(itemPool[2])));
PushItem((Item)System.Activator.CreateInstance(System.Type.GetType(itemPool[2])));
yield return new WaitForSeconds(1.5f);
yield return new WaitForSeconds(1.5f);
...
@@ -65,35 +111,93 @@ public class InventoryManager : MonoBehaviour {
...
@@ -65,35 +111,93 @@ public class InventoryManager : MonoBehaviour {
yield return new WaitForSeconds(1f);
yield return new WaitForSeconds(1f);
*/
*/
}
}
/// <summary>
/// Instantiate random item by quality
/// </summary>
/// <param name="quality"></param>
/// <param name="pos"></param>
public
void
ItemInstantiate
(
ItemQuality
quality
,
Vector3
pos
)
{
if
(
itemPool
[(
int
)
quality
].
Count
>
0
)
{
ItemInstantiate
(
itemPool
[(
int
)
quality
][
0
],
pos
);
itemPool
[(
int
)
quality
].
RemoveAt
(
0
);
}
}
/// <summary>
/// Instantiate item by name on pos, also Instantiate Item class
/// </summary>
/// <param name="str"></param>
/// <param name="pos"></param>
public
void
ItemInstantiate
(
string
str
,
Vector3
pos
)
public
void
ItemInstantiate
(
string
str
,
Vector3
pos
)
{
{
GameObject
tmpItem
=
Instantiate
(
droppedPrefab
);
GameObject
tmpItem
=
Instantiate
(
droppedPrefab
);
tmpItem
.
GetComponent
<
DroppedItem
>().
Init
((
Item
)
System
.
Activator
.
CreateInstance
(
System
.
Type
.
GetType
(
str
)),
pos
);
tmpItem
.
GetComponent
<
DroppedItem
>().
Init
((
Item
)
System
.
Activator
.
CreateInstance
(
System
.
Type
.
GetType
(
str
)),
pos
);
}
}
/// <summary>
/// Instantiate item by Item Instance on pos
/// </summary>
/// <param name="item"></param>
/// <param name="pos"></param>
public
void
ItemInstantiate
(
Item
item
,
Vector3
pos
)
public
void
ItemInstantiate
(
Item
item
,
Vector3
pos
)
{
{
GameObject
tmpItem
=
Instantiate
(
droppedPrefab
);
GameObject
tmpItem
=
Instantiate
(
droppedPrefab
);
tmpItem
.
GetComponent
<
DroppedItem
>().
Init
(
item
,
pos
);
tmpItem
.
GetComponent
<
DroppedItem
>().
Init
(
item
,
pos
);
}
}
/// <summary>
/// Instantiate random addon by quality
/// </summary>
/// <param name="quality"></param>
/// <param name="pos"></param>
public
void
AddonInstantiate
(
ItemQuality
quality
,
Vector3
pos
)
{
if
(
addonPool
[(
int
)
quality
].
Count
>
0
)
{
AddonInstantiate
(
addonPool
[(
int
)
quality
][
0
],
pos
);
addonPool
[(
int
)
quality
].
RemoveAt
(
0
);
}
}
/// <summary>
/// Instantiate addon by name on pos, also Instantiate Addon class
/// </summary>
/// <param name="str"></param>
/// <param name="pos"></param>
public
void
AddonInstantiate
(
string
str
,
Vector3
pos
)
public
void
AddonInstantiate
(
string
str
,
Vector3
pos
)
{
{
GameObject
tmpItem
=
Instantiate
(
droppedPrefab
);
GameObject
tmpItem
=
Instantiate
(
droppedPrefab
);
tmpItem
.
GetComponent
<
DroppedItem
>().
Init
((
Addon
)
System
.
Activator
.
CreateInstance
(
System
.
Type
.
GetType
(
str
)),
pos
);
tmpItem
.
GetComponent
<
DroppedItem
>().
Init
((
Addon
)
System
.
Activator
.
CreateInstance
(
System
.
Type
.
GetType
(
str
)),
pos
);
}
}
/// <summary>
/// Instantiate addon by Addon Instance on pos
/// </summary>
/// <param name="item"></param>
/// <param name="pos"></param>
public
void
AddonInstantiate
(
Addon
addon
,
Vector3
pos
)
public
void
AddonInstantiate
(
Addon
addon
,
Vector3
pos
)
{
{
GameObject
tmpItem
=
Instantiate
(
droppedPrefab
);
GameObject
tmpItem
=
Instantiate
(
droppedPrefab
);
tmpItem
.
GetComponent
<
DroppedItem
>().
Init
(
addon
,
pos
);
tmpItem
.
GetComponent
<
DroppedItem
>().
Init
(
addon
,
pos
);
}
}
/// <summary>
/// reset inventory canvas
/// </summary>
public
void
SetOnPosition
()
public
void
SetOnPosition
()
{
{
ui
.
SetOnPosition
(
itemList
,
addonList
);
ui
.
SetOnPosition
(
itemList
,
addonList
);
}
}
/// <summary>
/// call when item has been clicked
/// </summary>
/// <param name="itemIndex"></param>
public
void
ItemSelect
(
int
itemIndex
)
public
void
ItemSelect
(
int
itemIndex
)
{
{
ui
.
selectedItem
=
itemIndex
;
ui
.
selectedItem
=
itemIndex
;
ui
.
SetOnPosition
(
itemList
,
addonList
);
ui
.
SetOnPosition
(
itemList
,
addonList
);
}
}
/// <summary>
/// push item in inventory
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public
bool
PushItem
(
Item
item
)
public
bool
PushItem
(
Item
item
)
{
{
for
(
int
i
=
0
;
i
<
item
.
skillNum
;
i
++)
for
(
int
i
=
0
;
i
<
item
.
skillNum
;
i
++)
...
@@ -108,6 +212,11 @@ public class InventoryManager : MonoBehaviour {
...
@@ -108,6 +212,11 @@ public class InventoryManager : MonoBehaviour {
ui
.
SetOnPosition
(
itemList
,
addonList
);
ui
.
SetOnPosition
(
itemList
,
addonList
);
return
true
;
return
true
;
}
}
/// <summary>
/// push addon in inventory
/// </summary>
/// <param name="addon"></param>
/// <returns></returns>
public
bool
PushAddon
(
Addon
addon
)
public
bool
PushAddon
(
Addon
addon
)
{
{
if
(
addonList
.
Count
>
8
)
return
false
;
if
(
addonList
.
Count
>
8
)
return
false
;
...
@@ -116,6 +225,10 @@ public class InventoryManager : MonoBehaviour {
...
@@ -116,6 +225,10 @@ public class InventoryManager : MonoBehaviour {
ui
.
SetOnPosition
(
itemList
,
addonList
);
ui
.
SetOnPosition
(
itemList
,
addonList
);
return
true
;
return
true
;
}
}
/// <summary>
/// call when item has been discarded. instantiate dropped item object
/// </summary>
/// <param name="index"></param>
public
void
DiscardItem
(
int
index
)
public
void
DiscardItem
(
int
index
)
{
{
if
(
itemList
.
Count
>
index
)
if
(
itemList
.
Count
>
index
)
...
@@ -127,6 +240,10 @@ public class InventoryManager : MonoBehaviour {
...
@@ -127,6 +240,10 @@ public class InventoryManager : MonoBehaviour {
}
}
ui
.
SetOnPosition
(
itemList
,
addonList
);
ui
.
SetOnPosition
(
itemList
,
addonList
);
}
}
/// <summary>
/// call when addon(not attached on item) has been discarded. instantiate dropped addon object
/// </summary>
/// <param name="index"></param>
public
void
DiscardAddon
(
int
index
)
public
void
DiscardAddon
(
int
index
)
{
{
if
(
addonList
.
Count
>
index
)
if
(
addonList
.
Count
>
index
)
...
@@ -136,6 +253,11 @@ public class InventoryManager : MonoBehaviour {
...
@@ -136,6 +253,11 @@ public class InventoryManager : MonoBehaviour {
}
}
ui
.
SetOnPosition
(
itemList
,
addonList
);
ui
.
SetOnPosition
(
itemList
,
addonList
);
}
}
/// <summary>
/// call when addon(attached on item) has been discarded. instantiate dropped addon object
/// </summary>
/// <param name="itemIndex"></param>
/// <param name="addonType"></param>
public
void
DiscardAddon
(
int
itemIndex
,
AddonType
addonType
)
public
void
DiscardAddon
(
int
itemIndex
,
AddonType
addonType
)
{
{
if
(
itemList
[
itemIndex
].
addons
[(
int
)
addonType
]
!=
null
)
if
(
itemList
[
itemIndex
].
addons
[(
int
)
addonType
]
!=
null
)
...
@@ -145,6 +267,11 @@ public class InventoryManager : MonoBehaviour {
...
@@ -145,6 +267,11 @@ public class InventoryManager : MonoBehaviour {
}
}
ui
.
SetOnPosition
(
itemList
,
addonList
);
ui
.
SetOnPosition
(
itemList
,
addonList
);
}
}
/// <summary>
/// attach addon to item
/// </summary>
/// <param name="itemIndex"></param>
/// <param name="addonIndex"></param>
public
void
AttachAddon
(
int
itemIndex
,
int
addonIndex
)
public
void
AttachAddon
(
int
itemIndex
,
int
addonIndex
)
{
{
if
(
itemList
[
itemIndex
].
attachable
[(
int
)
addonList
[
addonIndex
].
type
]
&&
itemList
[
itemIndex
].
addons
[(
int
)
addonList
[
addonIndex
].
type
]
==
null
)
if
(
itemList
[
itemIndex
].
attachable
[(
int
)
addonList
[
addonIndex
].
type
]
&&
itemList
[
itemIndex
].
addons
[(
int
)
addonList
[
addonIndex
].
type
]
==
null
)
...
@@ -154,6 +281,11 @@ public class InventoryManager : MonoBehaviour {
...
@@ -154,6 +281,11 @@ public class InventoryManager : MonoBehaviour {
}
}
ui
.
SetOnPosition
(
itemList
,
addonList
);
ui
.
SetOnPosition
(
itemList
,
addonList
);
}
}
/// <summary>
/// dettach addon from item
/// </summary>
/// <param name="itemIndex"></param>
/// <param name="addonType"></param>
public
void
DetachAddon
(
int
itemIndex
,
AddonType
addonType
)
public
void
DetachAddon
(
int
itemIndex
,
AddonType
addonType
)
{
{
if
(
addonList
.
Count
<
9
&&
itemList
[
itemIndex
].
addons
[(
int
)
addonType
]
!=
null
)
if
(
addonList
.
Count
<
9
&&
itemList
[
itemIndex
].
addons
[(
int
)
addonType
]
!=
null
)
...
...
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