mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-14 17:09:31 +07:00
copy-paste fix
This commit is contained in:
@@ -6,71 +6,18 @@ namespace IsoTools.Internal {
|
|||||||
[RequireComponent(typeof(IsoObject))]
|
[RequireComponent(typeof(IsoObject))]
|
||||||
public class IsoPhysicHelper : MonoBehaviour {
|
public class IsoPhysicHelper : MonoBehaviour {
|
||||||
|
|
||||||
static List<IsoCollider> _tmpColliders = new List<IsoCollider>(7);
|
|
||||||
static List<IsoRigidbody> _tmpRigidbodies = new List<IsoRigidbody>(7);
|
|
||||||
static List<IsoTriggerListener> _tmpTriggerListeners = new List<IsoTriggerListener>(7);
|
|
||||||
static List<IsoCollisionListener> _tmpCollisionListeners = new List<IsoCollisionListener>(7);
|
|
||||||
|
|
||||||
GameObject _isoFakeObject = null;
|
GameObject _isoFakeObject = null;
|
||||||
public GameObject isoFakeObject {
|
public GameObject isoFakeObject {
|
||||||
get { return _isoFakeObject; }
|
get { return _isoFakeObject; }
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: fix copy-paste
|
|
||||||
public void DestroyIfUnnecessary(Component except) {
|
|
||||||
var unnecessary = true;
|
|
||||||
GetComponents<IsoCollider> (_tmpColliders);
|
|
||||||
GetComponents<IsoRigidbody> (_tmpRigidbodies);
|
|
||||||
GetComponents<IsoTriggerListener> (_tmpTriggerListeners);
|
|
||||||
GetComponents<IsoCollisionListener>(_tmpCollisionListeners);
|
|
||||||
if ( unnecessary ) {
|
|
||||||
for ( int i = 0, e = _tmpColliders.Count; i < e; ++i ) {
|
|
||||||
if ( _tmpColliders[i] != except ) {
|
|
||||||
unnecessary = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( unnecessary ) {
|
|
||||||
for ( int i = 0, e = _tmpRigidbodies.Count; i < e; ++i ) {
|
|
||||||
if ( _tmpRigidbodies[i] != except ) {
|
|
||||||
unnecessary = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( unnecessary ) {
|
|
||||||
for ( int i = 0, e = _tmpTriggerListeners.Count; i < e; ++i ) {
|
|
||||||
if ( _tmpTriggerListeners[i] != except ) {
|
|
||||||
unnecessary = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( unnecessary ) {
|
|
||||||
for ( int i = 0, e = _tmpCollisionListeners.Count; i < e; ++i ) {
|
|
||||||
if ( _tmpCollisionListeners[i] != except ) {
|
|
||||||
unnecessary = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_tmpColliders.Clear();
|
|
||||||
_tmpRigidbodies.Clear();
|
|
||||||
_tmpTriggerListeners.Clear();
|
|
||||||
_tmpCollisionListeners.Clear();
|
|
||||||
if ( unnecessary ) {
|
|
||||||
Destroy(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Awake() {
|
void Awake() {
|
||||||
hideFlags = HideFlags.HideInInspector;
|
//hideFlags = HideFlags.HideInInspector;
|
||||||
var iso_object = GetComponent<IsoObject>();
|
var iso_object = GetComponent<IsoObject>();
|
||||||
if ( iso_object ) {
|
if ( iso_object ) {
|
||||||
_isoFakeObject = new GameObject("_Fake" + gameObject.name);
|
_isoFakeObject = new GameObject("_Fake" + gameObject.name);
|
||||||
_isoFakeObject.AddComponent<IsoFakeObject>().Init(iso_object);
|
_isoFakeObject.AddComponent<IsoFakeObject>().Init(iso_object);
|
||||||
_isoFakeObject.hideFlags = HideFlags.HideInHierarchy | HideFlags.NotEditable;
|
//_isoFakeObject.hideFlags = HideFlags.HideInHierarchy | HideFlags.NotEditable;
|
||||||
GameObject.DontDestroyOnLoad(_isoFakeObject);
|
GameObject.DontDestroyOnLoad(_isoFakeObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace IsoTools.Internal {
|
namespace IsoTools.Internal {
|
||||||
public class IsoPhysicHelperHolder : MonoBehaviour {
|
public class IsoPhysicHelperHolder : MonoBehaviour {
|
||||||
|
|
||||||
|
static List<IsoPhysicHelperHolder> _tmpHolders = new List<IsoPhysicHelperHolder>(7);
|
||||||
|
|
||||||
protected GameObject fakeObject {
|
protected GameObject fakeObject {
|
||||||
get { return physicHelper.isoFakeObject; }
|
get { return physicHelper.isoFakeObject; }
|
||||||
}
|
}
|
||||||
@@ -12,7 +15,18 @@ namespace IsoTools.Internal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void DestroyUnnecessaryCheck() {
|
protected void DestroyUnnecessaryCheck() {
|
||||||
physicHelper.DestroyIfUnnecessary(this);
|
var unnecessary = true;
|
||||||
|
GetComponents<IsoPhysicHelperHolder>(_tmpHolders);
|
||||||
|
for ( int i = 0, e = _tmpHolders.Count; i < e; ++i ) {
|
||||||
|
if ( _tmpHolders[i] != this ) {
|
||||||
|
unnecessary = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( unnecessary ) {
|
||||||
|
Destroy(physicHelper);
|
||||||
|
}
|
||||||
|
_tmpHolders.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user