The early realization of the basic backpack storage functions, and now began to build backpack items mobile and Exchange functions, the specific ideas are as follows:
① reads the lattice information of the existing item.
② the mobile target location (that is, the tag on your surface):
If the tag of surface is empty, the local coordinates of the item are zeroed;
If your surface's tag is not empty, there are a few things to consider:
1.Tag for backpack lattice: indicating that the mobile location is empty lattice, so that the object information assigned to the target, clear the existing information can be;
2.Tag for backpack items: indicating that the mobile location for the item lattice, the two grid information exchange can be;
3.Tag for other items: Describes unconventional movements, zeroing out the displacement information of the item.
The script is added as follows:
Class Inventory_item
{
void Resetposition ()
{
Tranform.localpostion = Vector3.zero;
}
protected override void Ondragdroprelease (Gameobject surface)
{
Base. Ondragdroprelease (surface);
if (surface! = null)
{
if (surface. Tag = = "Inventory_grid")
{
if (surface = This.transform.parent.gameObject)
{
Resetposition ();
}
Else
{
Inventorygrid Nowgrid = this.transform.parent.getcompnent<inventorygird> ();
This.tranform.parent = Surface.transform;
Resetposition ();
Inventorygrid Newgrid = surface. Getcompnent<inventorygrid> ();
Newgrid. SetId (Nowgrid.id,nowgrid.num);
Nowgrid. Clearinfo ();
}
}
else if (surface. Tag = = "Inventoryitem")
{
Inventorygird grid1 = this.transform.parent.getcompnent<inventorygrid> ();
Inventorygrid Grid2 = surface.transform.parent.getcompnent<inventorygrid> ();
int id = grid1.id; int num = Grid1.num;
Grid1. SetId (Grid2.id,grid2.num);
Grid2. SetId (Id,num);
}
Else
{
Resetpositon ();
}
}
Else
{
Resetposition ();
}
}
}
UNITY3D-RPG Project Study notes (12)