miepzerino
2025-04-01 f5e15fa93d84acbae6a26b86fddf20add38bb485
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using Assets.Scripts.Helpers;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
#region player data
[Serializable]
public class SaveDataInventorySlot
{
    public int itemId;
    public string itemName;
    public int quantity;
 
    public SaveDataInventorySlot(InventorySlot slot)
    {
        itemId = slot.item.itemId;
        itemName = slot.item.itemName;
        quantity = slot.quantity;
    }
}
[Serializable]
public class SaveDataPlayer
{
    public int maxHealth;
    public int health;
    public float[] position;
    public float[] velocity;
    public List<SaveDataInventorySlot> inventoryItems;
 
    public SaveDataPlayer(PlayerController player, Inventory inventory)
    {
        maxHealth = player.health.MaxHealth;
        health = player.health.Health;
        position = player.transform.position.ConvertToFloatArray();
        velocity = player.rb.velocity.ConvertToFloatArray();
 
        // Save inventory items
        inventoryItems = new List<SaveDataInventorySlot>();
        foreach (var slot in inventory.items)
        {
            inventoryItems.Add(new SaveDataInventorySlot(slot));
        }
    }
}
#endregion
 
#region map data
[Serializable]
public class SaveDataMap
{
    public int seed;
    public List<DestroyedTile> destroyedTiles;
    public SaveDataMap(List<Vector3Int> destroyedTiles, int seed)
    {
        this.seed = seed;
        this.destroyedTiles = new List<DestroyedTile>();
        foreach (var item in destroyedTiles.ConvertToListIntArray())
        {
            this.destroyedTiles.Add(new DestroyedTile(item));
        }
    }
}
 
[Serializable]
public class DestroyedTile
{
    public DestroyedTile(int[] tileCoord)
    {
        this.tileCoord = tileCoord;
    }
    public int[] tileCoord;
}
#endregion