48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEditor;
|
|
using UnityEditor.SceneManagement;
|
|
using UnityEngine;
|
|
|
|
[Serializable]
|
|
public class ItemData : MonoBehaviour
|
|
{
|
|
[Tooltip("Location is populated automatically")]
|
|
public string assetLocation;
|
|
public int itemId;
|
|
public bool canStack;
|
|
public string itemName;
|
|
public string itemDescription;
|
|
public GameObject prefab;
|
|
public Vector3 scaleInContainer;
|
|
public Vector3 positionInContainer;
|
|
|
|
private void OnValidate()
|
|
{
|
|
if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(prefab))) assetLocation = AssetDatabase.GetAssetPath(prefab);
|
|
|
|
AdjustPath();
|
|
}
|
|
|
|
private void AdjustPath()
|
|
{
|
|
//trims the location for use with Resources.Load later
|
|
if (assetLocation.StartsWith("Assets/Resources/"))
|
|
assetLocation = assetLocation[17 .. ^7];
|
|
else if (!string.IsNullOrEmpty(assetLocation))
|
|
if (assetLocation.StartsWith("Assets"))
|
|
{
|
|
Debug.LogError(itemName +
|
|
": item with this script should be placed in the Assets/Resources/ folder. Currently: " +
|
|
assetLocation);
|
|
}
|
|
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{base.ToString()}, itemId: {itemId}, canStack: {canStack}, itemName: {itemName}";
|
|
}
|
|
}
|