201 lines
3.7 KiB
C#
201 lines
3.7 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Serialization;
|
|
|
|
public class PickUpItem : MonoBehaviour
|
|
{
|
|
public bool specialPickupEnd;
|
|
|
|
[SerializeField]
|
|
[FormerlySerializedAs("skinnable")]
|
|
private bool _skinnable = true;
|
|
[SerializeField]
|
|
[FormerlySerializedAs("rotationObject")]
|
|
private bool _rotationObject = true;
|
|
[SerializeField]
|
|
private GameObject visual;
|
|
|
|
[SerializeField]
|
|
[FormerlySerializedAs("visual_ABTest")]
|
|
private GameObject _visual_ABTest;
|
|
|
|
[SerializeField]
|
|
[FormerlySerializedAs("door")]
|
|
private GameObject _door;
|
|
|
|
[SerializeField]
|
|
[FormerlySerializedAs("doorsScript")]
|
|
private Doors _doorsScript;
|
|
|
|
[SerializeField]
|
|
private bool AB_test_tandom;
|
|
|
|
[SerializeField]
|
|
[FormerlySerializedAs("rdmVisual")]
|
|
private List<GameObject> _rdmVisual;
|
|
|
|
[SerializeField]
|
|
[FormerlySerializedAs("rdmVisualSafe")]
|
|
private List<GameObject> _rdmVisualSafe;
|
|
|
|
[SerializeField]
|
|
private float rotationSpeed;
|
|
|
|
[SerializeField]
|
|
[FormerlySerializedAs("dependenceItem")]
|
|
private PickUpItem _dependenceItem;
|
|
|
|
[SerializeField]
|
|
[FormerlySerializedAs("hasItemsNoSafe")]
|
|
private bool _hasItemsNoSafe = true;
|
|
[SerializeField]
|
|
private Transform instanceCont;
|
|
|
|
public TypeItem typeItem;
|
|
|
|
public float valueChange;
|
|
|
|
public static bool DebugItemNoSafeEnabled = true;
|
|
private GameObject _visualInstance;
|
|
|
|
private PickupSkinProvider _skinProvider;
|
|
|
|
private CoreController coreController;
|
|
|
|
public bool isUse { get; private set; }
|
|
|
|
private void Awake()
|
|
{
|
|
if (_skinnable)
|
|
{
|
|
_skinProvider = GetComponentInParent<PickupSkinProvider>();
|
|
if (_skinProvider != null)
|
|
{
|
|
_skinProvider.onSkinChanged += ApplySkin;
|
|
ApplySkin();
|
|
}
|
|
}
|
|
coreController = GetComponentInParent<CoreController>();
|
|
if (coreController != null)
|
|
{
|
|
}
|
|
if (_doorsScript != null)
|
|
{
|
|
_doorsScript.AddDoor(this);
|
|
}
|
|
if (_visual_ABTest != null)
|
|
{
|
|
_visual_ABTest.SetActive(value: true);
|
|
}
|
|
}
|
|
|
|
private void ApplySkin()
|
|
{
|
|
if (_visualInstance != null)
|
|
{
|
|
Object.Destroy(_visualInstance.gameObject);
|
|
_visualInstance = null;
|
|
}
|
|
GameObject prefab = null;
|
|
if (_skinnable && _skinProvider != null)
|
|
{
|
|
prefab = _skinProvider.GetSkin(typeItem);
|
|
}
|
|
if (prefab == null)
|
|
{
|
|
List<GameObject> list = ((DebugItemNoSafeEnabled && _hasItemsNoSafe) ? _rdmVisual : _rdmVisualSafe);
|
|
if (_rdmVisual != null && _rdmVisual.Count >= 1)
|
|
{
|
|
prefab = list[Random.Range(0, list.Count)];
|
|
}
|
|
}
|
|
if (prefab != null)
|
|
{
|
|
_visualInstance = Object.Instantiate(prefab, instanceCont);
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (_skinProvider != null)
|
|
{
|
|
_skinProvider.onSkinChanged -= ApplySkin;
|
|
}
|
|
if (coreController != null)
|
|
{
|
|
}
|
|
}
|
|
|
|
private void OnRevive()
|
|
{
|
|
PickUpItem item = this;
|
|
while (item.isUse)
|
|
{
|
|
item.ResetItem();
|
|
if (!(item._dependenceItem != null))
|
|
{
|
|
break;
|
|
}
|
|
item = item._dependenceItem;
|
|
}
|
|
}
|
|
|
|
private void ResetItem()
|
|
{
|
|
isUse = false;
|
|
visual.SetActive(value: true);
|
|
if (_visual_ABTest != null)
|
|
{
|
|
_visual_ABTest.SetActive(value: true);
|
|
}
|
|
if (_door != null)
|
|
{
|
|
_door.SetActive(value: true);
|
|
}
|
|
}
|
|
|
|
public void ReviveDependenceItem()
|
|
{
|
|
if (isUse)
|
|
{
|
|
ResetItem();
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!isUse && _rotationObject)
|
|
{
|
|
visual.transform.Rotate(Vector3.up * rotationSpeed * Time.deltaTime);
|
|
}
|
|
}
|
|
|
|
public void UseDependenceItem()
|
|
{
|
|
isUse = true;
|
|
visual.SetActive(value: false);
|
|
if (_visual_ABTest != null)
|
|
{
|
|
_visual_ABTest.SetActive(value: false);
|
|
}
|
|
if (_door != null)
|
|
{
|
|
_door.SetActive(value: false);
|
|
}
|
|
}
|
|
|
|
public void UseItem()
|
|
{
|
|
isUse = true;
|
|
visual.SetActive(value: false);
|
|
if (_visual_ABTest != null)
|
|
{
|
|
_visual_ABTest.SetActive(value: false);
|
|
}
|
|
if (_door != null)
|
|
{
|
|
_door.SetActive(value: false);
|
|
}
|
|
}
|
|
}
|