IsoWorld static instance

This commit is contained in:
2016-04-17 19:20:43 +06:00
parent 8d5a177eb1
commit 7c22b52489
4 changed files with 24 additions and 9 deletions

View File

@@ -13,7 +13,7 @@ namespace IsoTools.Internal {
Vector3 _viewCenter = Vector3.zero;
void GrabPositions() {
var iso_world = GameObject.FindObjectOfType<IsoWorld>();
var iso_world = IsoWorld.Instance;
if ( iso_world ) {
_positions = targets
.Where(p => p is IsoObject)
@@ -97,7 +97,7 @@ namespace IsoTools.Internal {
}
void ZMoveSlider() {
var iso_world = GameObject.FindObjectOfType<IsoWorld>();
var iso_world = IsoWorld.Instance;
if ( iso_world ) {
Handles.color = Handles.zAxisColor;
var delta = Handles.Slider(_viewCenter, IsoUtils.vec3OneY) - _viewCenter;
@@ -109,7 +109,7 @@ namespace IsoTools.Internal {
}
void XYMoveSlider(Color color, Vector3 dir) {
var iso_world = GameObject.FindObjectOfType<IsoWorld>();
var iso_world = IsoWorld.Instance;
if ( iso_world ) {
Handles.color = color;
var delta = Handles.Slider(_viewCenter, iso_world.IsoToScreen(dir)) - _viewCenter;

View File

@@ -238,13 +238,11 @@ namespace IsoTools {
//
// ---------------------------------------------------------------------
IsoWorld _isoWorld = null;
public IsoWorld isoWorld {
get {
if ( !_isoWorld && gameObject.activeInHierarchy ) {
_isoWorld = GameObject.FindObjectOfType<IsoWorld>();
}
return _isoWorld;
return gameObject.activeInHierarchy
? IsoWorld.Instance
: null;
}
}

View File

@@ -10,6 +10,8 @@ namespace IsoTools {
[ExecuteInEditMode, DisallowMultipleComponent]
public class IsoWorld : MonoBehaviour {
static IsoWorld _instance = null;
bool _dirty = false;
IsoAssocList<IsoObject> _objects = new IsoAssocList<IsoObject>();
IsoAssocList<IsoObject> _visibles = new IsoAssocList<IsoObject>();
@@ -129,6 +131,21 @@ namespace IsoTools {
}
}
// ---------------------------------------------------------------------
//
// Instance
//
// ---------------------------------------------------------------------
public static IsoWorld Instance {
get {
if ( !_instance ) {
_instance = GameObject.FindObjectOfType<IsoWorld>();
}
return _instance;
}
}
// ---------------------------------------------------------------------
//
// IsoToScreen/ScreenToIso

View File

@@ -144,7 +144,7 @@ namespace IsoTools.Tiled.Internal {
}
IsoWorld GetIsoWorld() {
var iso_world = GameObject.FindObjectOfType<IsoWorld>();
var iso_world = IsoWorld.Instance;
if ( !iso_world ) {
throw new UnityException("not found IsoWorld");
}