51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
using game;
|
|
using UnityEngine;
|
|
|
|
public class ConsumableItemPreviewer : BaseItemPreviewer
|
|
{
|
|
private ConfBaseShopItem _itemConf;
|
|
private GameObject _previewObject;
|
|
public override void ChangeItem(ConfBaseShopItem conf, bool needShade)
|
|
{
|
|
_itemConf = conf;
|
|
|
|
Error.Verify(_itemConf != null, "ConsumableShopItemPreviewer: invalid type for item config " + conf.GetType());
|
|
|
|
TryDestroyLastPreview();
|
|
_previewObject = CreatePreview();
|
|
|
|
if(needShade)
|
|
ShadeObject(_previewObject);
|
|
}
|
|
|
|
public override void Show(bool skipAnimation = true)
|
|
{
|
|
if(_previewObject == null)
|
|
return;
|
|
|
|
_previewObject.SetActive(true);
|
|
}
|
|
|
|
public override void Hide(bool skipAnimation = true)
|
|
{
|
|
if(_previewObject == null)
|
|
return;
|
|
|
|
_previewObject.SetActive(false);
|
|
}
|
|
|
|
private void TryDestroyLastPreview()
|
|
{
|
|
if (_previewObject != null)
|
|
Destroy(_previewObject);
|
|
}
|
|
|
|
private GameObject CreatePreview()
|
|
{
|
|
GameObject obj = Assets.Create<GameObject>(_itemConf.previewPath);
|
|
obj.SetParent(transform);
|
|
obj.transform.localPosition = Vector3.zero;
|
|
return obj;
|
|
}
|
|
}
|