mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-14 17:09:31 +07:00
ref counter for IsoPhysicHelper
This commit is contained in:
@@ -10,6 +10,16 @@ namespace IsoTools.Internal {
|
||||
get { return _isoFakeObject; }
|
||||
}
|
||||
|
||||
int _refCounter = 0;
|
||||
public void AddRefCounter() {
|
||||
++_refCounter;
|
||||
}
|
||||
public void DropRefCounter() {
|
||||
if ( --_refCounter <= 0 ) {
|
||||
Destroy(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Awake() {
|
||||
hideFlags = HideFlags.HideInInspector;
|
||||
var iso_object = GetComponent<IsoObject>();
|
||||
|
||||
@@ -16,10 +16,11 @@ namespace IsoTools {
|
||||
}
|
||||
|
||||
protected GameObject fakeObject {
|
||||
get {
|
||||
var helper = IsoUtils.GetOrCreateComponent<IsoPhysicHelper>(gameObject);
|
||||
return helper ? helper.isoFakeObject : null;
|
||||
}
|
||||
get { return physicHelper.isoFakeObject; }
|
||||
}
|
||||
|
||||
protected IsoPhysicHelper physicHelper {
|
||||
get { return IsoUtils.GetOrCreateComponent<IsoPhysicHelper>(gameObject); }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
@@ -96,6 +97,7 @@ namespace IsoTools {
|
||||
_realCollider = CreateRealCollider(fake_collider_go);
|
||||
_realCollider.material = material;
|
||||
_realCollider.isTrigger = isTrigger;
|
||||
physicHelper.AddRefCounter();
|
||||
}
|
||||
|
||||
void OnEnable() {
|
||||
@@ -115,6 +117,7 @@ namespace IsoTools {
|
||||
Destroy(_realCollider.gameObject);
|
||||
_realCollider = null;
|
||||
}
|
||||
physicHelper.DropRefCounter();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
@@ -11,15 +11,16 @@ namespace IsoTools {
|
||||
public class IsoRigidbody : MonoBehaviour {
|
||||
|
||||
Rigidbody _realRigidbody = null;
|
||||
protected Rigidbody realRigidbody {
|
||||
Rigidbody realRigidbody {
|
||||
get { return _realRigidbody; }
|
||||
}
|
||||
|
||||
protected GameObject fakeObject {
|
||||
get {
|
||||
var helper = IsoUtils.GetOrCreateComponent<IsoPhysicHelper>(gameObject);
|
||||
return helper ? helper.isoFakeObject : null;
|
||||
}
|
||||
GameObject fakeObject {
|
||||
get { return physicHelper.isoFakeObject; }
|
||||
}
|
||||
|
||||
IsoPhysicHelper physicHelper {
|
||||
get { return IsoUtils.GetOrCreateComponent<IsoPhysicHelper>(gameObject); }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
@@ -326,6 +327,7 @@ namespace IsoTools {
|
||||
_realRigidbody.isKinematic = isKinematic;
|
||||
_realRigidbody.interpolation = interpolation;
|
||||
_realRigidbody.collisionDetectionMode = collisionDetectionMode;
|
||||
physicHelper.AddRefCounter();
|
||||
}
|
||||
|
||||
void OnEnable() {
|
||||
@@ -346,6 +348,7 @@ namespace IsoTools {
|
||||
Destroy(_realRigidbody);
|
||||
_realRigidbody = null;
|
||||
}
|
||||
physicHelper.DropRefCounter();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
Reference in New Issue
Block a user