first optimisation iteration end

This commit is contained in:
2015-03-08 22:13:06 +06:00
parent 4690117cb0
commit 44bc16bcef
8 changed files with 3673 additions and 7056 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,498 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
SceneSettings:
m_ObjectHideFlags: 0
m_PVSData:
m_PVSObjectsArray: []
m_PVSPortalsArray: []
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: .25
backfaceThreshold: 100
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 6
m_Fog: 0
m_FogColor: {r: .5, g: .5, b: .5, a: 1}
m_FogMode: 3
m_FogDensity: .00999999978
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: .211999997, g: .226999998, b: .259000003, a: 1}
m_AmbientEquatorColor: {r: .114, g: .125, b: .133000001, a: 1}
m_AmbientGroundColor: {r: .0469999984, g: .0430000015, b: .0350000001, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 3
m_SkyboxMaterial: {fileID: 0}
m_HaloStrength: .5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
--- !u!127 &3
LevelGameManager:
m_ObjectHideFlags: 0
--- !u!157 &4
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 5
m_GIWorkflowMode: 0
m_LightmapsMode: 1
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_TemporalCoherenceThreshold: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 0
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 3
m_Resolution: 2
m_BakeResolution: 40
m_TextureWidth: 1024
m_TextureHeight: 1024
m_AOMaxDistance: 1
m_Padding: 2
m_CompAOExponent: 0
m_LightmapParameters: {fileID: 0}
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherRayCount: 1024
m_LightmapSnapshot: {fileID: 0}
m_RuntimeCPUUsage: 25
--- !u!196 &5
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentRadius: .5
agentHeight: 2
agentSlope: 45
agentClimb: .400000006
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
accuratePlacement: 0
minRegionArea: 2
cellSize: .166666672
manualCellSize: 0
m_NavMeshData: {fileID: 0}
--- !u!1001 &373266025
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: m_LocalPosition.y
value: 32
objectReference: {fileID: 0}
- target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: m_LocalPosition.z
value: 66.6666641
objectReference: {fileID: 0}
- target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 11417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: _position.x
value: 2
objectReference: {fileID: 0}
- target: {fileID: 11417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: _position.y
value: 2
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
m_IsPrefabParent: 0
--- !u!1001 &583856369
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 453620, guid: dbd21aa1b9a2cdf4a944f50e64d145a1, type: 2}
propertyPath: m_LocalPosition.x
value: 48
objectReference: {fileID: 0}
- target: {fileID: 453620, guid: dbd21aa1b9a2cdf4a944f50e64d145a1, type: 2}
propertyPath: m_LocalPosition.y
value: 8
objectReference: {fileID: 0}
- target: {fileID: 453620, guid: dbd21aa1b9a2cdf4a944f50e64d145a1, type: 2}
propertyPath: m_LocalPosition.z
value: 33.3333321
objectReference: {fileID: 0}
- target: {fileID: 453620, guid: dbd21aa1b9a2cdf4a944f50e64d145a1, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 453620, guid: dbd21aa1b9a2cdf4a944f50e64d145a1, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 453620, guid: dbd21aa1b9a2cdf4a944f50e64d145a1, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 453620, guid: dbd21aa1b9a2cdf4a944f50e64d145a1, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 453620, guid: dbd21aa1b9a2cdf4a944f50e64d145a1, type: 2}
propertyPath: m_RootOrder
value: 3
objectReference: {fileID: 0}
- target: {fileID: 11453620, guid: dbd21aa1b9a2cdf4a944f50e64d145a1, type: 2}
propertyPath: _position.x
value: 2
objectReference: {fileID: 0}
- target: {fileID: 11453620, guid: dbd21aa1b9a2cdf4a944f50e64d145a1, type: 2}
propertyPath: _position.y
value: -1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: dbd21aa1b9a2cdf4a944f50e64d145a1, type: 2}
m_IsPrefabParent: 0
--- !u!1 &984653569
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 984653575}
- 20: {fileID: 984653574}
- 92: {fileID: 984653573}
- 124: {fileID: 984653572}
- 81: {fileID: 984653571}
- 114: {fileID: 984653570}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &984653570
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 984653569}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3f01619d3802e814f86f9e6bb965349a, type: 3}
m_Name:
m_EditorClassIdentifier:
_tileType: 0
_tileSize: 16
_minDepth: 0
_maxDepth: 100
_sectorSize: 5
--- !u!81 &984653571
AudioListener:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 984653569}
m_Enabled: 1
--- !u!124 &984653572
Behaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 984653569}
m_Enabled: 1
--- !u!92 &984653573
Behaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 984653569}
m_Enabled: 1
--- !u!20 &984653574
Camera:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 984653569}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: .192156866, g: .301960796, b: .474509805, a: .0196078438}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: .300000012
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 67.4300003
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_HDR: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: .0219999999
--- !u!4 &984653575
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 984653569}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 6
--- !u!1001 &1210758687
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 463702, guid: 6dac6372d911f0646a34e2e83f03c30c, type: 2}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 463702, guid: 6dac6372d911f0646a34e2e83f03c30c, type: 2}
propertyPath: m_LocalPosition.y
value: 32
objectReference: {fileID: 0}
- target: {fileID: 463702, guid: 6dac6372d911f0646a34e2e83f03c30c, type: 2}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 463702, guid: 6dac6372d911f0646a34e2e83f03c30c, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 463702, guid: 6dac6372d911f0646a34e2e83f03c30c, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 463702, guid: 6dac6372d911f0646a34e2e83f03c30c, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 463702, guid: 6dac6372d911f0646a34e2e83f03c30c, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 463702, guid: 6dac6372d911f0646a34e2e83f03c30c, type: 2}
propertyPath: m_RootOrder
value: 5
objectReference: {fileID: 0}
- target: {fileID: 11463702, guid: 6dac6372d911f0646a34e2e83f03c30c, type: 2}
propertyPath: _position.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 11463702, guid: 6dac6372d911f0646a34e2e83f03c30c, type: 2}
propertyPath: _position.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 11463702, guid: 6dac6372d911f0646a34e2e83f03c30c, type: 2}
propertyPath: _position.z
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 6dac6372d911f0646a34e2e83f03c30c, type: 2}
m_IsPrefabParent: 0
--- !u!1001 &1455085887
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: m_LocalPosition.y
value: 16
objectReference: {fileID: 0}
- target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: m_LocalPosition.z
value: 16.666666
objectReference: {fileID: 0}
- target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: m_RootOrder
value: 4
objectReference: {fileID: 0}
- target: {fileID: 11417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: _position.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 11417528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: _position.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 117528, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
propertyPath: m_Name
value: Cube_1x1x2
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: c1b9b2ad3a021c549aa9190df3101248, type: 2}
m_IsPrefabParent: 0
--- !u!1001 &1577586909
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 462204, guid: fb3806e9ed7ada045b1b57419ac1ee53, type: 2}
propertyPath: m_LocalPosition.x
value: -48
objectReference: {fileID: 0}
- target: {fileID: 462204, guid: fb3806e9ed7ada045b1b57419ac1ee53, type: 2}
propertyPath: m_LocalPosition.y
value: 8
objectReference: {fileID: 0}
- target: {fileID: 462204, guid: fb3806e9ed7ada045b1b57419ac1ee53, type: 2}
propertyPath: m_LocalPosition.z
value: 50
objectReference: {fileID: 0}
- target: {fileID: 462204, guid: fb3806e9ed7ada045b1b57419ac1ee53, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 462204, guid: fb3806e9ed7ada045b1b57419ac1ee53, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 462204, guid: fb3806e9ed7ada045b1b57419ac1ee53, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 462204, guid: fb3806e9ed7ada045b1b57419ac1ee53, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 462204, guid: fb3806e9ed7ada045b1b57419ac1ee53, type: 2}
propertyPath: m_RootOrder
value: 2
objectReference: {fileID: 0}
- target: {fileID: 11462204, guid: fb3806e9ed7ada045b1b57419ac1ee53, type: 2}
propertyPath: _position.x
value: -1
objectReference: {fileID: 0}
- target: {fileID: 11462204, guid: fb3806e9ed7ada045b1b57419ac1ee53, type: 2}
propertyPath: _position.y
value: 2
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: fb3806e9ed7ada045b1b57419ac1ee53, type: 2}
m_IsPrefabParent: 0
--- !u!1001 &1595152117
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
propertyPath: m_LocalPosition.z
value: 83.3333282
objectReference: {fileID: 0}
- target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 11453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
propertyPath: _position.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 11453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
propertyPath: _position.y
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2}
m_IsPrefabParent: 0

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: e55e1f5dda065443787b1627ccd4d252
timeCreated: 1425063966
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -47,17 +47,17 @@ namespace IsoTools {
bool _dirty = true;
List<SectorInfo> _sectors = new List<SectorInfo>();
Vector3 _sectorsNum = Vector3.zero;
Vector3 _sectorsMinNumPos = Vector3.zero;
List<ObjectInfo> _objects = new List<ObjectInfo>();
List<int> _depends = new List<int>();
float _objsSectorSize = 0.0f;
Vector3 _objsMinNumPos = Vector3.zero;
Vector3 _objsMaxNumPos = Vector3.zero;
Vector3 _objsNumPosCount = Vector3.zero;
TileTypes _lastTileType = TileTypes.Isometric;
float _lastTileSize = 0.0f;
float _lastMinDepth = 0.0f;
float _lastMaxDepth = 0.0f;
float _lastSectorSize = 0.0f;
[SerializeField]
public TileTypes _tileType = TileTypes.Isometric;
@@ -102,17 +102,6 @@ namespace IsoTools {
ChangeSortingProperty();
}
}
[SerializeField]
public float _sectorSize = 3.0f;
/// <summary>Sorting sector size.</summary>
public float SectorSize {
get { return _sectorSize; }
set {
_sectorSize = Mathf.Max(value, 1.0f);
ChangeSortingProperty();
}
}
// ------------------------------------------------------------------------
/// <summary>
@@ -134,8 +123,7 @@ namespace IsoTools {
if ( obj && obj.Sorting ) {
var renderer = obj.GetComponent<Renderer>();
if ( renderer && renderer.isVisible ) {
_dirty = true;
MarkEditorWorldDirty();
MarkDirty();
}
}
}
@@ -218,6 +206,13 @@ namespace IsoTools {
}
#endif
}
void ApplyToAllIsoObjects(Action<IsoObject> act) {
var iso_objects = GameObject.FindObjectsOfType<IsoObject>();
foreach ( var obj in iso_objects ) {
act(obj);
}
}
void FixAllTransforms() {
ApplyToAllIsoObjects(obj => obj.FixTransform());
@@ -226,28 +221,20 @@ namespace IsoTools {
void ChangeSortingProperty() {
MarkDirty();
FixAllTransforms();
_lastTileType = TileType;
_lastTileSize = TileSize;
_lastMinDepth = MinDepth;
_lastMaxDepth = MaxDepth;
_lastSectorSize = SectorSize;
}
void ApplyToAllIsoObjects(Action<IsoObject> act) {
var iso_objects = GameObject.FindObjectsOfType<IsoObject>();
foreach ( var iso_object in iso_objects ) {
act(iso_object);
}
_lastTileType = TileType;
_lastTileSize = TileSize;
_lastMinDepth = MinDepth;
_lastMaxDepth = MaxDepth;
}
int SectorIndex(Vector3 num_pos) {
return Mathf.FloorToInt(
num_pos.x + _sectorsNum.x * (num_pos.y + num_pos.z * _sectorsNum.y));
num_pos.x + _objsNumPosCount.x * (num_pos.y + num_pos.z * _objsNumPosCount.y));
}
Vector3 SectorNumPos(int index) {
var mz = _sectorsNum.x * _sectorsNum.y;
var my = _sectorsNum.x;
var mz = _objsNumPosCount.x * _objsNumPosCount.y;
var my = _objsNumPosCount.x;
var vz = Mathf.FloorToInt(index / mz);
var vy = Mathf.FloorToInt((index - vz * mz) / my);
var vx = Mathf.FloorToInt(index - vz * mz - vy * my);
@@ -258,44 +245,88 @@ namespace IsoTools {
if ( num_pos.x < 0 || num_pos.y < 0 || num_pos.z < 0 ) {
return null;
}
if ( num_pos.x >= _sectorsNum.x || num_pos.y >= _sectorsNum.y || num_pos.z >= _sectorsNum.z ) {
if ( num_pos.x >= _objsNumPosCount.x || num_pos.y >= _objsNumPosCount.y || num_pos.z >= _objsNumPosCount.z ) {
return null;
}
return _sectors[SectorIndex(num_pos)];
}
void SetupSectors() {
var iso_objects = GameObject.FindObjectsOfType<IsoObject>();
void LookUpSectorDepends(Vector3 num_pos, Action<SectorInfo> act) {
var ms = FindSector(num_pos);
if ( ms != null ) {
act(ms);
var s1 = FindSector(num_pos + new Vector3(-1, 0, 0));
var s2 = FindSector(num_pos + new Vector3( 0, -1, 0));
var s3 = FindSector(num_pos + new Vector3(-1, -1, 0));
if ( s1 != null ) act(s1);
if ( s2 != null ) act(s2);
if ( s3 != null ) act(s3);
for ( var i = 0; i <= _objsNumPosCount.z; ++i ) {
var ss1 = FindSector(num_pos + new Vector3( 0 - i, 0 - i, i + 1));
var ss2 = FindSector(num_pos + new Vector3(-1 - i, 0 - i, i + 1));
var ss3 = FindSector(num_pos + new Vector3( 0 - i, -1 - i, i + 1));
var ss4 = FindSector(num_pos + new Vector3(-1 - i, -1 - i, i + 1));
var ss5 = FindSector(num_pos + new Vector3(-2 - i, -1 - i, i + 1));
var ss6 = FindSector(num_pos + new Vector3(-1 - i, -2 - i, i + 1));
var ss7 = FindSector(num_pos + new Vector3(-2 - i, -2 - i, i + 1));
if ( ss1 != null ) act(ss1);
if ( ss2 != null ) act(ss2);
if ( ss3 != null ) act(ss3);
if ( ss4 != null ) act(ss4);
if ( ss5 != null ) act(ss5);
if ( ss6 != null ) act(ss6);
if ( ss7 != null ) act(ss7);
}
}
}
_objects.Clear();
_objects.Capacity = iso_objects.Length;
bool IsDepends(Vector3 a_min, Vector3 a_size, Vector3 b_min, Vector3 b_size) {
var a_max = a_min + a_size;
var b_max = b_min + b_size;
return a_max.x > b_min.x && a_max.y > b_min.y && b_max.z > a_min.z;
}
var min_num_pos = Vector3.zero;
var max_num_pos = Vector3.one;
void SetupSectorSize(IsoObject[] iso_objects) {
_objsSectorSize = 0.0f;
var objsSum = 0;
foreach ( var obj in iso_objects ) {
var renderer = obj.GetComponent<Renderer>();
if ( renderer && renderer.isVisible ) {
var obj_max_size = IsoUtils.Vec3Max(Vector3.one, obj.Size);
var obj_min_num_pos = IsoUtils.Vec3DivFloor(obj.Position, SectorSize);
var obj_max_num_pos = IsoUtils.Vec3DivCeil(obj.Position + obj_max_size, SectorSize);
min_num_pos = IsoUtils.Vec3Min(min_num_pos, obj_min_num_pos);
max_num_pos = IsoUtils.Vec3Max(max_num_pos, obj_max_num_pos);
_objects.Add(new ObjectInfo(_objects.Count, obj, obj_min_num_pos, obj_max_num_pos));
++objsSum;
_objsSectorSize += Mathf.Max(obj.Size.x, obj.Size.y, obj.Size.z);
}
}
_objsSectorSize = Mathf.Round(Mathf.Max(3.0f, _objsSectorSize / objsSum));
}
_sectorsNum = max_num_pos - min_num_pos;
_sectorsMinNumPos = min_num_pos;
void SetupObjects(IsoObject[] iso_objects) {
_objects.Clear();
_objsMinNumPos = Vector3.zero;
_objsMaxNumPos = Vector3.one;
foreach ( var obj in iso_objects ) {
var renderer = obj.GetComponent<Renderer>();
if ( renderer && renderer.isVisible ) {
var max_size = IsoUtils.Vec3Max(Vector3.one, obj.Size);
var min_npos = IsoUtils.Vec3DivFloor(obj.Position, _objsSectorSize);
var max_npos = IsoUtils.Vec3DivCeil(obj.Position + max_size, _objsSectorSize);
_objsMinNumPos = IsoUtils.Vec3Min(_objsMinNumPos, min_npos);
_objsMaxNumPos = IsoUtils.Vec3Max(_objsMaxNumPos, max_npos);
_objects.Add(new ObjectInfo(_objects.Count, obj, min_npos, max_npos));
}
}
_objsNumPosCount = _objsMaxNumPos - _objsMinNumPos;
}
void SetupSectors() {
_sectors.Clear();
_sectors.Capacity = Mathf.FloorToInt(_sectorsNum.x * _sectorsNum.y * _sectorsNum.z);
_sectors.Capacity = Mathf.FloorToInt(_objsNumPosCount.x * _objsNumPosCount.y * _objsNumPosCount.z);
while ( _sectors.Count < _sectors.Capacity ) {
_sectors.Add(new SectorInfo());
}
foreach ( var obj in _objects ) {
obj.MinSector -= _sectorsMinNumPos;
obj.MaxSector -= _sectorsMinNumPos;
obj.MinSector -= _objsMinNumPos;
obj.MaxSector -= _objsMinNumPos;
IsoUtils.LookUpCube(obj.MinSector, obj.MaxSector, p => {
var sector = FindSector(p);
if ( sector != null ) {
@@ -305,38 +336,13 @@ namespace IsoTools {
}
}
void LookUpSectorDepends(Vector3 num_pos, Action<SectorInfo> act) {
var ms = FindSector(num_pos);
if ( ms != null ) {
act(ms);
var s1 = FindSector(num_pos + new Vector3(-1, 0, 0));
var s2 = FindSector(num_pos + new Vector3( 0, -1, 0));
var s3 = FindSector(num_pos + new Vector3(-1, -1, 0));
if ( s1 != null ) act(s1);
if ( s2 != null ) act(s2);
if ( s3 != null ) act(s3);
for ( var i = 1; i <= _sectorsNum.z ; ++i ) {
var ss1 = FindSector(num_pos + new Vector3( 0 - i, 0 - i, i + 1));
var ss2 = FindSector(num_pos + new Vector3(-1 - i, 0 - i, i + 1));
var ss3 = FindSector(num_pos + new Vector3( 0 - i, -1 - i, i + 1));
var ss4 = FindSector(num_pos + new Vector3(-1 - i, -1 - i, i + 1));
if ( ss1 != null ) act(ss1);
if ( ss2 != null ) act(ss2);
if ( ss3 != null ) act(ss3);
if ( ss4 != null ) act(ss4);
}
}
}
void SetupObjectDepends() {
_depends.Clear();
foreach ( var obj_a in _objects ) {
obj_a.Init(_depends.Count);
var obj_ao = obj_a.IsoObject;
IsoUtils.LookUpCube(obj_a.MinSector, obj_a.MaxSector, p => {
LookUpSectorDepends(p, sec => {
IsoUtils.LookUpCube(obj_a.MinSector, obj_a.MaxSector, num_pos => {
LookUpSectorDepends(num_pos, sec => {
foreach ( var obj_bi in sec.Objects ) {
var obj_bo = _objects[obj_bi].IsoObject;
if ( obj_ao != obj_bo && IsDepends(obj_ao.Position, obj_ao.Size, obj_bo.Position, obj_bo.Size) ) {
@@ -349,17 +355,12 @@ namespace IsoTools {
}
}
bool IsDepends(Vector3 a_min, Vector3 a_size, Vector3 b_min, Vector3 b_size) {
var a_max = a_min + a_size;
var b_max = b_min + b_size;
return a_max.x > b_min.x && a_max.y > b_min.y && b_max.z > a_min.z;
}
void SetupAllObjects() {
void PlaceAllObjects() {
var depth = MinDepth;
foreach ( var info in _objects ) {
depth = PlaceObject(info, depth);
}
_sectors.Clear();
_objects.Clear();
_depends.Clear();
}
@@ -385,9 +386,12 @@ namespace IsoTools {
void StepSort() {
if ( _dirty ) {
var iso_objects = GameObject.FindObjectsOfType<IsoObject>();
SetupSectorSize(iso_objects);
SetupObjects(iso_objects);
SetupSectors();
SetupObjectDepends();
SetupAllObjects();
PlaceAllObjects();
_dirty = false;
}
}
@@ -399,11 +403,10 @@ namespace IsoTools {
void LateUpdate() {
if ( Application.isEditor ) {
if ( _lastTileType != _tileType ) TileType = _tileType;
if ( !Mathf.Approximately(_lastTileSize, _tileSize ) ) TileSize = _tileSize;
if ( !Mathf.Approximately(_lastMinDepth, _minDepth ) ) MinDepth = _minDepth;
if ( !Mathf.Approximately(_lastMaxDepth, _maxDepth ) ) MaxDepth = _maxDepth;
if ( !Mathf.Approximately(_lastSectorSize, _sectorSize) ) SectorSize = _sectorSize;
if ( _lastTileType != _tileType ) TileType = _tileType;
if ( !Mathf.Approximately(_lastTileSize, _tileSize ) ) TileSize = _tileSize;
if ( !Mathf.Approximately(_lastMinDepth, _minDepth ) ) MinDepth = _minDepth;
if ( !Mathf.Approximately(_lastMaxDepth, _maxDepth ) ) MaxDepth = _maxDepth;
}
StepSort();
}