fix serialization generic classes problem

This commit is contained in:
2017-03-16 17:16:03 +07:00
parent ac8a1a670d
commit ed980cfbd8
5 changed files with 18 additions and 46 deletions

View File

@@ -6,10 +6,7 @@ using UnityEditor;
#endif #endif
namespace IsoTools.Internal { namespace IsoTools.Internal {
public abstract class IsoBehaviour<T> : MonoBehaviour public abstract class IsoBehaviour : MonoBehaviour {
where T : IsoBehaviour<T>
{
static IsoAssocList<T> _behaviours = new IsoAssocList<T>();
static List<IsoWorld> _tempWorlds = new List<IsoWorld>(); static List<IsoWorld> _tempWorlds = new List<IsoWorld>();
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@@ -44,14 +41,6 @@ namespace IsoTools.Internal {
return ret_value; return ret_value;
} }
protected static int AllBehaviourCount {
get { return _behaviours.Count; }
}
protected static T GetBehaviourByIndex(int index) {
return _behaviours[index];
}
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// //
// Public // Public
@@ -61,25 +50,5 @@ namespace IsoTools.Internal {
public bool IsActive() { public bool IsActive() {
return isActiveAndEnabled && gameObject.activeInHierarchy; return isActiveAndEnabled && gameObject.activeInHierarchy;
} }
// ---------------------------------------------------------------------
//
// Virtual
//
// ---------------------------------------------------------------------
protected virtual void OnEnable() {
var behaviour = this as T;
if ( behaviour && behaviour.IsActive() ) {
_behaviours.Add(behaviour);
}
}
protected virtual void OnDisable() {
var behaviour = this as T;
if ( behaviour ) {
_behaviours.Remove(behaviour);
}
}
} }
} }

View File

@@ -1,5 +1,5 @@
namespace IsoTools.Internal { namespace IsoTools.Internal {
public abstract class IsoObjectBase : IsoBehaviour<IsoObject> { public abstract class IsoObjectBase : IsoBehaviour {
IsoWorld _isoWorld = null; IsoWorld _isoWorld = null;
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@@ -46,13 +46,11 @@
// //
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
protected override void OnEnable() { protected virtual void OnEnable() {
base.OnEnable();
Internal_RecacheIsoWorld(); Internal_RecacheIsoWorld();
} }
protected override void OnDisable() { protected virtual void OnDisable() {
base.OnDisable();
Internal_ResetIsoWorld(); Internal_ResetIsoWorld();
} }

View File

@@ -1,7 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace IsoTools.Internal { namespace IsoTools.Internal {
public abstract class IsoWorldBase : IsoBehaviour<IsoWorld> { public abstract class IsoWorldBase : IsoBehaviour {
IsoAssocList<IsoObject> _isoObjects = new IsoAssocList<IsoObject>(); IsoAssocList<IsoObject> _isoObjects = new IsoAssocList<IsoObject>();
static List<IsoObject> _tempIsoObjects = new List<IsoObject>(); static List<IsoObject> _tempIsoObjects = new List<IsoObject>();
@@ -55,13 +55,11 @@ namespace IsoTools.Internal {
// //
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
protected override void OnEnable() { protected virtual void OnEnable() {
base.OnEnable();
RecacheIsoObjectWorlds(); RecacheIsoObjectWorlds();
} }
protected override void OnDisable() { protected virtual void OnDisable() {
base.OnDisable();
RecacheIsoObjectWorlds(); RecacheIsoObjectWorlds();
} }

View File

@@ -4,7 +4,7 @@ using IsoTools.Internal;
namespace IsoTools { namespace IsoTools {
[SelectionBase] [SelectionBase]
[ExecuteInEditMode, DisallowMultipleComponent] [ExecuteInEditMode, DisallowMultipleComponent]
public sealed class IsoParent : IsoBehaviour<IsoParent> { public sealed class IsoParent : IsoBehaviour {
public IsoWorld isoWorld { public IsoWorld isoWorld {
get { get {
return FindFirstActiveWorld(); return FindFirstActiveWorld();

View File

@@ -118,12 +118,14 @@ namespace IsoTools {
// //
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
static IsoAssocList<IsoWorld> _instances = new IsoAssocList<IsoWorld>();
public static int AllWorldCount { public static int AllWorldCount {
get { return AllBehaviourCount; } get { return _instances.Count; }
} }
public static IsoWorld GetWorld(int index) { public static IsoWorld GetWorld(int index) {
return GetBehaviourByIndex(index); return _instances[index];
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@@ -358,7 +360,8 @@ namespace IsoTools {
void UpdateIsoMatrix() { void UpdateIsoMatrix() {
_isoMatrix = _isoMatrix =
Matrix4x4.Scale(new Vector3(1.0f, tileRatio, 1.0f)) * Matrix4x4.Scale(
new Vector3(1.0f, tileRatio, 1.0f)) *
Matrix4x4.TRS( Matrix4x4.TRS(
Vector3.zero, Vector3.zero,
Quaternion.AngleAxis(90.0f - tileAngle, IsoUtils.vec3OneZ), Quaternion.AngleAxis(90.0f - tileAngle, IsoUtils.vec3OneZ),
@@ -404,6 +407,9 @@ namespace IsoTools {
protected override void OnEnable() { protected override void OnEnable() {
base.OnEnable(); base.OnEnable();
if ( IsActive() ) {
_instances.Add(this);
}
} }
protected override void OnDisable() { protected override void OnDisable() {
@@ -411,6 +417,7 @@ namespace IsoTools {
_screenSolver.Clear(); _screenSolver.Clear();
_sortingSolver.Clear(); _sortingSolver.Clear();
_warningSolver.Clear(); _warningSolver.Clear();
_instances.Remove(this);
} }
protected override void OnAddIsoObjectToWorld(IsoObject iso_object) { protected override void OnAddIsoObjectToWorld(IsoObject iso_object) {