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
namespace IsoTools.Internal {
public abstract class IsoBehaviour<T> : MonoBehaviour
where T : IsoBehaviour<T>
{
static IsoAssocList<T> _behaviours = new IsoAssocList<T>();
public abstract class IsoBehaviour : MonoBehaviour {
static List<IsoWorld> _tempWorlds = new List<IsoWorld>();
// ---------------------------------------------------------------------
@@ -44,14 +41,6 @@ namespace IsoTools.Internal {
return ret_value;
}
protected static int AllBehaviourCount {
get { return _behaviours.Count; }
}
protected static T GetBehaviourByIndex(int index) {
return _behaviours[index];
}
// ---------------------------------------------------------------------
//
// Public
@@ -61,25 +50,5 @@ namespace IsoTools.Internal {
public bool IsActive() {
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 {
public abstract class IsoObjectBase : IsoBehaviour<IsoObject> {
public abstract class IsoObjectBase : IsoBehaviour {
IsoWorld _isoWorld = null;
// ---------------------------------------------------------------------
@@ -46,13 +46,11 @@
//
// ---------------------------------------------------------------------
protected override void OnEnable() {
base.OnEnable();
protected virtual void OnEnable() {
Internal_RecacheIsoWorld();
}
protected override void OnDisable() {
base.OnDisable();
protected virtual void OnDisable() {
Internal_ResetIsoWorld();
}

View File

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

View File

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

View File

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