mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-13 15:52:03 +07:00
name refactor
This commit is contained in:
@@ -29,10 +29,10 @@ namespace IsoTools.Tiled.Internal {
|
|||||||
void CreateTiledMap(GameObject map_go) {
|
void CreateTiledMap(GameObject map_go) {
|
||||||
var map_data = _asset.Data;
|
var map_data = _asset.Data;
|
||||||
|
|
||||||
var iso_object = map_go.AddComponent<IsoObject>();
|
var iso_object = map_go.AddComponent<IsoObject>();
|
||||||
iso_object.mode = IsoObject.Mode.Mode3d;
|
iso_object.renderersMode = IsoObject.RenderersMode.Mode3d;
|
||||||
iso_object.position = Vector3.zero;
|
iso_object.position = Vector3.zero;
|
||||||
iso_object.size = IsoUtils.Vec3FromXY(map_data.Height, map_data.Width);
|
iso_object.size = IsoUtils.Vec3FromXY(map_data.Height, map_data.Width);
|
||||||
|
|
||||||
var tiled_map = map_go.AddComponent<TiledMap>();
|
var tiled_map = map_go.AddComponent<TiledMap>();
|
||||||
tiled_map.Asset = _asset;
|
tiled_map.Asset = _asset;
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
using UnityEditor;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace IsoTools.Internal {
|
namespace IsoTools.Internal {
|
||||||
public abstract class IsoBehaviour<T> : MonoBehaviour
|
public abstract class IsoBehaviour<T> : MonoBehaviour
|
||||||
where T : IsoBehaviour<T>
|
where T : IsoBehaviour<T>
|
||||||
@@ -14,10 +18,18 @@ namespace IsoTools.Internal {
|
|||||||
//
|
//
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
public bool IsActive() {
|
public void Internal_SetDirtyInEditorMode() {
|
||||||
return isActiveAndEnabled && gameObject.activeInHierarchy;
|
#if UNITY_EDITOR
|
||||||
|
EditorUtility.SetDirty(this);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Protected
|
||||||
|
//
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
protected IsoWorld FindFirstActiveWorld() {
|
protected IsoWorld FindFirstActiveWorld() {
|
||||||
IsoWorld ret_value = null;
|
IsoWorld ret_value = null;
|
||||||
GetComponentsInParent<IsoWorld>(false, _tempWorlds);
|
GetComponentsInParent<IsoWorld>(false, _tempWorlds);
|
||||||
@@ -40,6 +52,16 @@ namespace IsoTools.Internal {
|
|||||||
return _behaviours[index];
|
return _behaviours[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Public
|
||||||
|
//
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
public bool IsActive() {
|
||||||
|
return isActiveAndEnabled && gameObject.activeInHierarchy;
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Virtual
|
// Virtual
|
||||||
|
|||||||
@@ -1,71 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace IsoTools.Internal {
|
|
||||||
public abstract class IsoHolder<THold, TInst> : IsoBehaviour<THold>
|
|
||||||
where THold : IsoHolder <THold, TInst>
|
|
||||||
where TInst : IsoInstance <THold, TInst>
|
|
||||||
{
|
|
||||||
IsoAssocList<TInst> _instances = new IsoAssocList<TInst>();
|
|
||||||
static List<TInst> _tempInstances = new List<TInst>();
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Private
|
|
||||||
//
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
void RecacheChildrenHolders() {
|
|
||||||
GetComponentsInChildren<TInst>(false, _tempInstances);
|
|
||||||
for ( int i = 0, e = _tempInstances.Count; i < e; ++i ) {
|
|
||||||
_tempInstances[i].RecacheHolder();
|
|
||||||
}
|
|
||||||
_tempInstances.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Internal
|
|
||||||
//
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
public void AddInstance(TInst instance) {
|
|
||||||
if ( instance && instance.IsActive() ) {
|
|
||||||
_instances.Add(instance);
|
|
||||||
OnAddInstanceToHolder(instance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RemoveInstance(TInst instance) {
|
|
||||||
if ( instance ) {
|
|
||||||
_instances.Remove(instance);
|
|
||||||
OnRemoveInstanceFromHolder(instance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IsoAssocList<TInst> GetInstances() {
|
|
||||||
return _instances;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Virtual
|
|
||||||
//
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
protected override void OnEnable() {
|
|
||||||
base.OnEnable();
|
|
||||||
RecacheChildrenHolders();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnDisable() {
|
|
||||||
base.OnDisable();
|
|
||||||
RecacheChildrenHolders();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void OnAddInstanceToHolder(TInst instance) {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void OnRemoveInstanceFromHolder(TInst instance) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace IsoTools.Internal {
|
|
||||||
public abstract class IsoInstance<THold, TInst> : IsoBehaviour<TInst>
|
|
||||||
where THold : IsoHolder <THold, TInst>
|
|
||||||
where TInst : IsoInstance <THold, TInst>
|
|
||||||
{
|
|
||||||
THold _holder = null;
|
|
||||||
static List<THold> _tempHolders = new List<THold>();
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Private
|
|
||||||
//
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
THold FindFirstActiveHolder() {
|
|
||||||
THold ret_value = null;
|
|
||||||
GetComponentsInParent<THold>(false, _tempHolders);
|
|
||||||
for ( int i = 0, e = _tempHolders.Count; i < e; ++i ) {
|
|
||||||
var holder = _tempHolders[i];
|
|
||||||
if ( holder.IsActive() ) {
|
|
||||||
ret_value = holder;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_tempHolders.Clear();
|
|
||||||
return ret_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Internal
|
|
||||||
//
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
public void ResetHolder() {
|
|
||||||
if ( _holder ) {
|
|
||||||
_holder.RemoveInstance(this as TInst);
|
|
||||||
_holder = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RecacheHolder() {
|
|
||||||
ResetHolder();
|
|
||||||
if ( IsActive() ) {
|
|
||||||
_holder = FindFirstActiveHolder();
|
|
||||||
if ( _holder ) {
|
|
||||||
_holder.AddInstance(this as TInst);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected THold GetHolder() {
|
|
||||||
if ( !_holder ) {
|
|
||||||
RecacheHolder();
|
|
||||||
}
|
|
||||||
return _holder;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Virtual
|
|
||||||
//
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
protected override void OnEnable() {
|
|
||||||
base.OnEnable();
|
|
||||||
RecacheHolder();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnDisable() {
|
|
||||||
base.OnDisable();
|
|
||||||
ResetHolder();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void OnTransformParentChanged() {
|
|
||||||
RecacheHolder();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
63
Assets/IsoTools/Scripts/Internal/IsoObjectBase.cs
Normal file
63
Assets/IsoTools/Scripts/Internal/IsoObjectBase.cs
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
namespace IsoTools.Internal {
|
||||||
|
public abstract class IsoObjectBase : IsoBehaviour<IsoObject> {
|
||||||
|
IsoWorld _isoWorld = null;
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Internal
|
||||||
|
//
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
public void Internal_ResetIsoWorld() {
|
||||||
|
if ( _isoWorld ) {
|
||||||
|
_isoWorld.Internal_RemoveIsoObject(this as IsoObject);
|
||||||
|
_isoWorld = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Internal_RecacheIsoWorld() {
|
||||||
|
Internal_ResetIsoWorld();
|
||||||
|
if ( IsActive() ) {
|
||||||
|
_isoWorld = FindFirstActiveWorld();
|
||||||
|
if ( _isoWorld ) {
|
||||||
|
_isoWorld.Internal_AddIsoObject(this as IsoObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Public
|
||||||
|
//
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
public IsoWorld isoWorld {
|
||||||
|
get {
|
||||||
|
if ( !_isoWorld ) {
|
||||||
|
Internal_RecacheIsoWorld();
|
||||||
|
}
|
||||||
|
return _isoWorld;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Virtual
|
||||||
|
//
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
protected override void OnEnable() {
|
||||||
|
base.OnEnable();
|
||||||
|
Internal_RecacheIsoWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnDisable() {
|
||||||
|
base.OnDisable();
|
||||||
|
Internal_ResetIsoWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnTransformParentChanged() {
|
||||||
|
Internal_RecacheIsoWorld();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -151,14 +151,14 @@ namespace IsoTools.Internal {
|
|||||||
//
|
//
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
public void OnAddInstance(IsoObject iso_object) {
|
public void OnAddIsoObject(IsoObject iso_object) {
|
||||||
iso_object.Internal.QTItem = _quadTree.AddItem(
|
iso_object.Internal.QTItem = _quadTree.AddItem(
|
||||||
iso_object.Internal.QTBounds,
|
iso_object.Internal.QTBounds,
|
||||||
iso_object);
|
iso_object);
|
||||||
_minIsoXY = IsoUtils.Vec2Min(_minIsoXY, iso_object.position);
|
_minIsoXY = IsoUtils.Vec2Min(_minIsoXY, iso_object.position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnRemoveInstance(IsoObject iso_object) {
|
public void OnRemoveIsoObject(IsoObject iso_object) {
|
||||||
_oldVisibles.Remove(iso_object);
|
_oldVisibles.Remove(iso_object);
|
||||||
_curVisibles.Remove(iso_object);
|
_curVisibles.Remove(iso_object);
|
||||||
if ( iso_object.Internal.QTItem != null ) {
|
if ( iso_object.Internal.QTItem != null ) {
|
||||||
@@ -168,7 +168,7 @@ namespace IsoTools.Internal {
|
|||||||
ClearIsoObjectDepends(iso_object);
|
ClearIsoObjectDepends(iso_object);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool OnMarkDirtyInstance(IsoObject iso_object) {
|
public bool OnMarkDirtyIsoObject(IsoObject iso_object) {
|
||||||
if ( iso_object.Internal.QTItem != null ) {
|
if ( iso_object.Internal.QTItem != null ) {
|
||||||
iso_object.Internal.QTItem = _quadTree.MoveItem(
|
iso_object.Internal.QTItem = _quadTree.MoveItem(
|
||||||
iso_object.Internal.QTBounds,
|
iso_object.Internal.QTBounds,
|
||||||
@@ -198,9 +198,9 @@ namespace IsoTools.Internal {
|
|||||||
//
|
//
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
public void StepSortingAction(IsoWorld iso_world, IsoAssocList<IsoObject> instances) {
|
public void StepSortingAction(IsoWorld iso_world, IsoAssocList<IsoObject> iso_objects) {
|
||||||
Profiler.BeginSample("IsoScreenSolver.ProcessInstances");
|
Profiler.BeginSample("IsoScreenSolver.ProcessIsoObjects");
|
||||||
ProcessInstances(instances);
|
ProcessIsoObjects(iso_objects);
|
||||||
Profiler.EndSample();
|
Profiler.EndSample();
|
||||||
Profiler.BeginSample("IsoScreenSolver.ProcessVisibles");
|
Profiler.BeginSample("IsoScreenSolver.ProcessVisibles");
|
||||||
ProcessVisibles(iso_world.isSortInSceneView);
|
ProcessVisibles(iso_world.isSortInSceneView);
|
||||||
@@ -236,10 +236,10 @@ namespace IsoTools.Internal {
|
|||||||
//
|
//
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
void ProcessInstances(IsoAssocList<IsoObject> instances) {
|
void ProcessIsoObjects(IsoAssocList<IsoObject> iso_objects) {
|
||||||
if ( instances.Count > 0 ) {
|
if ( iso_objects.Count > 0 ) {
|
||||||
for ( int i = 0, e = instances.Count; i < e; ++i ) {
|
for ( int i = 0, e = iso_objects.Count; i < e; ++i ) {
|
||||||
var iso_object = instances[i];
|
var iso_object = iso_objects[i];
|
||||||
if ( !IsoUtils.Vec2Approximately(
|
if ( !IsoUtils.Vec2Approximately(
|
||||||
iso_object.Internal.LastTrans,
|
iso_object.Internal.LastTrans,
|
||||||
iso_object.Internal.Transform.position) )
|
iso_object.Internal.Transform.position) )
|
||||||
|
|||||||
@@ -19,19 +19,19 @@ namespace IsoTools.Internal {
|
|||||||
//
|
//
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
public void OnAddInstance(IsoObject iso_object) {
|
public void OnAddIsoObject(IsoObject iso_object) {
|
||||||
if ( iso_object.cacheRenderers ) {
|
if ( iso_object.isCachedRenderers ) {
|
||||||
iso_object.UpdateCachedRenderers();
|
iso_object.UpdateCachedRenderers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnRemoveInstance(IsoObject iso_object) {
|
public void OnRemoveIsoObject(IsoObject iso_object) {
|
||||||
if ( iso_object.cacheRenderers ) {
|
if ( iso_object.isCachedRenderers ) {
|
||||||
iso_object.ClearCachedRenderers();
|
iso_object.ClearCachedRenderers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool OnMarkDirtyInstance(IsoObject iso_object) {
|
public bool OnMarkDirtyIsoObject(IsoObject iso_object) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ namespace IsoTools.Internal {
|
|||||||
iso_object.Internal.Dirty = false;
|
iso_object.Internal.Dirty = false;
|
||||||
mark_dirty = true;
|
mark_dirty = true;
|
||||||
}
|
}
|
||||||
if ( iso_object.mode == IsoObject.Mode.Mode3d ) {
|
if ( iso_object.renderersMode == IsoObject.RenderersMode.Mode3d ) {
|
||||||
if ( UpdateIsoObjectBounds3d(iso_object) ) {
|
if ( UpdateIsoObjectBounds3d(iso_object) ) {
|
||||||
mark_dirty = true;
|
mark_dirty = true;
|
||||||
}
|
}
|
||||||
@@ -141,7 +141,7 @@ namespace IsoTools.Internal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<Renderer> GetIsoObjectRenderers(IsoObject iso_object) {
|
List<Renderer> GetIsoObjectRenderers(IsoObject iso_object) {
|
||||||
if ( iso_object.cacheRenderers ) {
|
if ( iso_object.isCachedRenderers ) {
|
||||||
return iso_object.Internal.Renderers;
|
return iso_object.Internal.Renderers;
|
||||||
} else {
|
} else {
|
||||||
iso_object.GetComponentsInChildren<Renderer>(_tmpRenderers);
|
iso_object.GetComponentsInChildren<Renderer>(_tmpRenderers);
|
||||||
@@ -174,7 +174,7 @@ namespace IsoTools.Internal {
|
|||||||
for ( int i = 0, e = self_depends.Count; i < e; ++i ) {
|
for ( int i = 0, e = self_depends.Count; i < e; ++i ) {
|
||||||
start_depth = RecursivePlaceIsoObject(self_depends[i], step_depth, start_depth);
|
start_depth = RecursivePlaceIsoObject(self_depends[i], step_depth, start_depth);
|
||||||
}
|
}
|
||||||
if ( iso_object.mode == IsoObject.Mode.Mode3d ) {
|
if ( iso_object.renderersMode == IsoObject.RenderersMode.Mode3d ) {
|
||||||
var zoffset = iso_object.Internal.Offset3d;
|
var zoffset = iso_object.Internal.Offset3d;
|
||||||
var extents = iso_object.Internal.MinMax3d.size;
|
var extents = iso_object.Internal.MinMax3d.size;
|
||||||
PlaceIsoObject(iso_object, start_depth + extents * 0.5f + zoffset);
|
PlaceIsoObject(iso_object, start_depth + extents * 0.5f + zoffset);
|
||||||
|
|||||||
68
Assets/IsoTools/Scripts/Internal/IsoWorldBase.cs
Normal file
68
Assets/IsoTools/Scripts/Internal/IsoWorldBase.cs
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace IsoTools.Internal {
|
||||||
|
public abstract class IsoWorldBase : IsoBehaviour<IsoWorld> {
|
||||||
|
IsoAssocList<IsoObject> _isoObjects = new IsoAssocList<IsoObject>();
|
||||||
|
static List<IsoObject> _tempIsoObjects = new List<IsoObject>();
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Private
|
||||||
|
//
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
void RecacheIsoObjectWorlds() {
|
||||||
|
GetComponentsInChildren<IsoObject>(false, _tempIsoObjects);
|
||||||
|
for ( int i = 0, e = _tempIsoObjects.Count; i < e; ++i ) {
|
||||||
|
_tempIsoObjects[i].Internal_RecacheIsoWorld();
|
||||||
|
}
|
||||||
|
_tempIsoObjects.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Internal
|
||||||
|
//
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
public void Internal_AddIsoObject(IsoObject iso_object) {
|
||||||
|
if ( iso_object && iso_object.IsActive() ) {
|
||||||
|
_isoObjects.Add(iso_object);
|
||||||
|
OnAddIsoObjectToWorld(iso_object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Internal_RemoveIsoObject(IsoObject iso_object) {
|
||||||
|
if ( iso_object ) {
|
||||||
|
_isoObjects.Remove(iso_object);
|
||||||
|
OnRemoveIsoObjectFromWorld(iso_object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IsoAssocList<IsoObject> GetIsoObjects() {
|
||||||
|
return _isoObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Virtual
|
||||||
|
//
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
protected override void OnEnable() {
|
||||||
|
base.OnEnable();
|
||||||
|
RecacheIsoObjectWorlds();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnDisable() {
|
||||||
|
base.OnDisable();
|
||||||
|
RecacheIsoObjectWorlds();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnAddIsoObjectToWorld(IsoObject iso_object) {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnRemoveIsoObjectFromWorld(IsoObject iso_object) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,14 +2,10 @@ using UnityEngine;
|
|||||||
using IsoTools.Internal;
|
using IsoTools.Internal;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
using UnityEditor;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace IsoTools {
|
namespace IsoTools {
|
||||||
[SelectionBase]
|
[SelectionBase]
|
||||||
[ExecuteInEditMode, DisallowMultipleComponent]
|
[ExecuteInEditMode, DisallowMultipleComponent]
|
||||||
public sealed class IsoObject : IsoInstance<IsoWorld, IsoObject> {
|
public sealed class IsoObject : IsoObjectBase {
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
@@ -142,22 +138,22 @@ namespace IsoTools {
|
|||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Mode
|
// Renderers mode
|
||||||
//
|
//
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
public enum Mode {
|
public enum RenderersMode {
|
||||||
Mode2d,
|
Mode2d,
|
||||||
Mode3d
|
Mode3d
|
||||||
}
|
}
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
Mode _mode = Mode.Mode2d;
|
RenderersMode _renderersMode = RenderersMode.Mode2d;
|
||||||
|
|
||||||
public Mode mode {
|
public RenderersMode renderersMode {
|
||||||
get { return _mode; }
|
get { return _renderersMode; }
|
||||||
set {
|
set {
|
||||||
_mode = value;
|
_renderersMode = value;
|
||||||
FixTransform();
|
FixTransform();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,12 +165,12 @@ namespace IsoTools {
|
|||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
bool _cacheRenderers = false;
|
bool _cachedRenderers = false;
|
||||||
|
|
||||||
public bool cacheRenderers {
|
public bool isCachedRenderers {
|
||||||
get { return _cacheRenderers; }
|
get { return _cachedRenderers; }
|
||||||
set {
|
set {
|
||||||
_cacheRenderers = value;
|
_cachedRenderers = value;
|
||||||
if ( value ) {
|
if ( value ) {
|
||||||
UpdateCachedRenderers();
|
UpdateCachedRenderers();
|
||||||
} else {
|
} else {
|
||||||
@@ -208,16 +204,10 @@ namespace IsoTools {
|
|||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Functions
|
// Public
|
||||||
//
|
//
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
public IsoWorld isoWorld {
|
|
||||||
get {
|
|
||||||
return GetHolder();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void FixTransform() {
|
public void FixTransform() {
|
||||||
var iso_world = isoWorld;
|
var iso_world = isoWorld;
|
||||||
var cached_transform = FixCachedTransform();
|
var cached_transform = FixCachedTransform();
|
||||||
@@ -249,6 +239,12 @@ namespace IsoTools {
|
|||||||
Internal.Renderers.Clear();
|
Internal.Renderers.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Private
|
||||||
|
//
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
void FixScreenBounds() {
|
void FixScreenBounds() {
|
||||||
var iso_world = isoWorld;
|
var iso_world = isoWorld;
|
||||||
if ( iso_world ) {
|
if ( iso_world ) {
|
||||||
@@ -277,11 +273,9 @@ namespace IsoTools {
|
|||||||
void MartDirtyIsoWorld() {
|
void MartDirtyIsoWorld() {
|
||||||
var iso_world = isoWorld;
|
var iso_world = isoWorld;
|
||||||
if ( iso_world ) {
|
if ( iso_world ) {
|
||||||
iso_world.MarkDirty(this);
|
iso_world.Internal_MarkDirty(this);
|
||||||
}
|
}
|
||||||
#if UNITY_EDITOR
|
Internal_SetDirtyInEditorMode();
|
||||||
EditorUtility.SetDirty(this);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
@@ -314,17 +308,17 @@ namespace IsoTools {
|
|||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
void Reset() {
|
void Reset() {
|
||||||
size = Vector3.one;
|
size = Vector3.one;
|
||||||
position = Vector3.zero;
|
position = Vector3.zero;
|
||||||
mode = Mode.Mode2d;
|
renderersMode = RenderersMode.Mode2d;
|
||||||
cacheRenderers = false;
|
isCachedRenderers = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnValidate() {
|
void OnValidate() {
|
||||||
size = _size;
|
size = _size;
|
||||||
position = _position;
|
position = _position;
|
||||||
mode = _mode;
|
renderersMode = _renderersMode;
|
||||||
cacheRenderers = _cacheRenderers;
|
isCachedRenderers = _cachedRenderers;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDrawGizmos() {
|
void OnDrawGizmos() {
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using IsoTools.Internal;
|
using IsoTools.Internal;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
using UnityEditor;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace IsoTools {
|
namespace IsoTools {
|
||||||
[ExecuteInEditMode, DisallowMultipleComponent]
|
[ExecuteInEditMode, DisallowMultipleComponent]
|
||||||
public sealed class IsoWorld : IsoHolder<IsoWorld, IsoObject> {
|
public sealed class IsoWorld : IsoWorldBase {
|
||||||
|
|
||||||
Matrix4x4 _isoMatrix = Matrix4x4.identity;
|
Matrix4x4 _isoMatrix = Matrix4x4.identity;
|
||||||
Matrix4x4 _isoRMatrix = Matrix4x4.identity;
|
Matrix4x4 _isoRMatrix = Matrix4x4.identity;
|
||||||
@@ -180,10 +175,11 @@ namespace IsoTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Vector3 TouchIsoPosition(int finger_id, float iso_z) {
|
public Vector3 TouchIsoPosition(int finger_id, float iso_z) {
|
||||||
if ( !Camera.main ) {
|
var camera = Camera.main;
|
||||||
|
if ( !camera ) {
|
||||||
throw new UnityException("Main camera not found!");
|
throw new UnityException("Main camera not found!");
|
||||||
}
|
}
|
||||||
return TouchIsoPosition(finger_id, Camera.main, iso_z);
|
return TouchIsoPosition(finger_id, camera, iso_z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3 TouchIsoPosition(int finger_id, Camera camera) {
|
public Vector3 TouchIsoPosition(int finger_id, Camera camera) {
|
||||||
@@ -192,7 +188,7 @@ namespace IsoTools {
|
|||||||
|
|
||||||
public Vector3 TouchIsoPosition(int finger_id, Camera camera, float iso_z) {
|
public Vector3 TouchIsoPosition(int finger_id, Camera camera, float iso_z) {
|
||||||
if ( !camera ) {
|
if ( !camera ) {
|
||||||
throw new UnityException("Camera argument is incorrect!");
|
throw new UnityException("Camera argument is null!");
|
||||||
}
|
}
|
||||||
for ( var i = 0; i < Input.touchCount; ++i ) {
|
for ( var i = 0; i < Input.touchCount; ++i ) {
|
||||||
var touch = Input.GetTouch(i);
|
var touch = Input.GetTouch(i);
|
||||||
@@ -238,10 +234,11 @@ namespace IsoTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Vector3 MouseIsoPosition(float iso_z) {
|
public Vector3 MouseIsoPosition(float iso_z) {
|
||||||
if ( !Camera.main ) {
|
var camera = Camera.main;
|
||||||
|
if ( !camera ) {
|
||||||
throw new UnityException("Main camera not found!");
|
throw new UnityException("Main camera not found!");
|
||||||
}
|
}
|
||||||
return MouseIsoPosition(Camera.main, iso_z);
|
return MouseIsoPosition(camera, iso_z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3 MouseIsoPosition(Camera camera) {
|
public Vector3 MouseIsoPosition(Camera camera) {
|
||||||
@@ -250,7 +247,7 @@ namespace IsoTools {
|
|||||||
|
|
||||||
public Vector3 MouseIsoPosition(Camera camera, float iso_z) {
|
public Vector3 MouseIsoPosition(Camera camera, float iso_z) {
|
||||||
if ( !camera ) {
|
if ( !camera ) {
|
||||||
throw new UnityException("Camera argument is incorrect!");
|
throw new UnityException("Camera argument is null!");
|
||||||
}
|
}
|
||||||
return ScreenToIso(
|
return ScreenToIso(
|
||||||
camera.ScreenToWorldPoint(Input.mousePosition),
|
camera.ScreenToWorldPoint(Input.mousePosition),
|
||||||
@@ -329,12 +326,12 @@ namespace IsoTools {
|
|||||||
//
|
//
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
public void MarkDirty(IsoObject iso_object) {
|
public void Internal_MarkDirty(IsoObject iso_object) {
|
||||||
if ( _screenSolver.OnMarkDirtyInstance(iso_object) ) {
|
if ( _screenSolver.OnMarkDirtyIsoObject(iso_object) ) {
|
||||||
MarkDirty();
|
Internal_SetDirtyInEditorMode();
|
||||||
}
|
}
|
||||||
if ( _sortingSolver.OnMarkDirtyInstance(iso_object) ) {
|
if ( _sortingSolver.OnMarkDirtyIsoObject(iso_object) ) {
|
||||||
MarkDirty();
|
Internal_SetDirtyInEditorMode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,12 +341,6 @@ namespace IsoTools {
|
|||||||
//
|
//
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
void MarkDirty() {
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
EditorUtility.SetDirty(this);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdateIsoMatrix() {
|
void UpdateIsoMatrix() {
|
||||||
_isoMatrix =
|
_isoMatrix =
|
||||||
Matrix4x4.Scale(new Vector3(1.0f, tileRatio, 1.0f)) *
|
Matrix4x4.Scale(new Vector3(1.0f, tileRatio, 1.0f)) *
|
||||||
@@ -360,23 +351,23 @@ namespace IsoTools {
|
|||||||
_isoRMatrix = _isoMatrix.inverse;
|
_isoRMatrix = _isoMatrix.inverse;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FixInstanceTransforms() {
|
void FixIsoObjectTransforms() {
|
||||||
var instances = GetInstances();
|
var iso_objects = GetIsoObjects();
|
||||||
for ( int i = 0, e = instances.Count; i < e; ++i ) {
|
for ( int i = 0, e = iso_objects.Count; i < e; ++i ) {
|
||||||
instances[i].FixTransform();
|
iso_objects[i].FixTransform();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChangeSortingProperty() {
|
void ChangeSortingProperty() {
|
||||||
MarkDirty();
|
|
||||||
UpdateIsoMatrix();
|
UpdateIsoMatrix();
|
||||||
FixInstanceTransforms();
|
FixIsoObjectTransforms();
|
||||||
|
Internal_SetDirtyInEditorMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StepSortingProcess() {
|
void StepSortingProcess() {
|
||||||
_screenSolver.StepSortingAction(this, GetInstances());
|
_screenSolver.StepSortingAction(this, GetIsoObjects());
|
||||||
if ( _sortingSolver.StepSortingAction(this, _screenSolver) ) {
|
if ( _sortingSolver.StepSortingAction(this, _screenSolver) ) {
|
||||||
MarkDirty();
|
Internal_SetDirtyInEditorMode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,16 +396,16 @@ namespace IsoTools {
|
|||||||
_sortingSolver.Clear();
|
_sortingSolver.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnAddInstanceToHolder(IsoObject instance) {
|
protected override void OnAddIsoObjectToWorld(IsoObject iso_object) {
|
||||||
base.OnAddInstanceToHolder(instance);
|
base.OnAddIsoObjectToWorld(iso_object);
|
||||||
_screenSolver.OnAddInstance(instance);
|
_screenSolver.OnAddIsoObject(iso_object);
|
||||||
_sortingSolver.OnAddInstance(instance);
|
_sortingSolver.OnAddIsoObject(iso_object);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnRemoveInstanceFromHolder(IsoObject instance) {
|
protected override void OnRemoveIsoObjectFromWorld(IsoObject iso_object) {
|
||||||
base.OnRemoveInstanceFromHolder(instance);
|
base.OnRemoveIsoObjectFromWorld(iso_object);
|
||||||
_screenSolver.OnRemoveInstance(instance);
|
_screenSolver.OnRemoveIsoObject(iso_object);
|
||||||
_sortingSolver.OnRemoveInstance(instance);
|
_sortingSolver.OnRemoveIsoObject(iso_object);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
@@ -439,7 +430,7 @@ namespace IsoTools {
|
|||||||
void OnRenderObject() {
|
void OnRenderObject() {
|
||||||
var camera = Camera.current;
|
var camera = Camera.current;
|
||||||
if ( camera && camera.name == "SceneCamera" ) {
|
if ( camera && camera.name == "SceneCamera" ) {
|
||||||
MarkDirty();
|
Internal_SetDirtyInEditorMode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user