65 lines
1.6 KiB
C#
65 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.CompilerServices;
|
|
using UnityEngine;
|
|
|
|
public class Object : MonoBehaviour {
|
|
[SerializeField] private ObjectSO _objectSo;
|
|
[SerializeField] private Renderer _renderer;
|
|
|
|
private IObjectParentHolder _objectParent;
|
|
|
|
private float _paidPrice;
|
|
|
|
private bool _isBroken;
|
|
|
|
public ObjectSO ObjectSo {
|
|
get => _objectSo;
|
|
set => _objectSo = value;
|
|
}
|
|
|
|
public float PaidPrice {
|
|
get => _paidPrice;
|
|
set => _paidPrice = value;
|
|
}
|
|
|
|
//When its broken it should be a diff color
|
|
public bool IsBroken {
|
|
get => _isBroken;
|
|
set {
|
|
_isBroken = value;
|
|
GetComponent<Object>().SetBroken(value);
|
|
}
|
|
}
|
|
|
|
private void SetBroken(bool value) {
|
|
//Set to red if broken
|
|
if (value) {
|
|
_renderer.material.color = Color.red;
|
|
}
|
|
else {
|
|
_renderer.material.color = Color.white;
|
|
}
|
|
}
|
|
|
|
public IObjectParentHolder getObjectParent() {
|
|
return _objectParent;
|
|
}
|
|
|
|
public void setObjectParent(IObjectParentHolder objectParent) {
|
|
if (this._objectParent != null) {
|
|
this._objectParent.ClearObject();
|
|
}
|
|
|
|
this._objectParent = objectParent;
|
|
if (objectParent.HasObject()) {
|
|
Debug.LogError("Parent has already something on it?");
|
|
Debug.Break();
|
|
}
|
|
objectParent.SetObject(this);
|
|
|
|
|
|
transform.parent = _objectParent.GetHolderTransform();
|
|
transform.localPosition = Vector3.zero;
|
|
}
|
|
} |