unity code style

This commit is contained in:
2015-07-11 15:57:58 +06:00
parent ff2db6d279
commit 3437fa40ce
23 changed files with 926 additions and 923 deletions

View File

@@ -22,15 +22,15 @@ namespace IsoTools {
_iso_zpositions = targets _iso_zpositions = targets
.Where(p => p as IsoObject) .Where(p => p as IsoObject)
.Select(p => p as IsoObject) .Select(p => p as IsoObject)
.ToDictionary(p => p, p => p.Position.z); .ToDictionary(p => p, p => p.position.z);
_center = _viewCenter = _positions.Aggregate(Vector3.zero, (AccIn, p) => { _center = _viewCenter = _positions.Aggregate(Vector3.zero, (AccIn, p) => {
return AccIn + IsoUtils.Vec3FromVec2(iso_world.IsoToScreen(p.Key.Position + p.Key.Size * 0.5f)); return AccIn + IsoUtils.Vec3FromVec2(iso_world.IsoToScreen(p.Key.position + p.Key.size * 0.5f));
}) / _positions.Count; }) / _positions.Count;
} }
} }
bool IsAnyAlignment { bool IsAnyAlignment {
get { return _positions.Keys.Any(p => p.Alignment); } get { return _positions.Keys.Any(p => p.isAlignment); }
} }
void AlignmentSelection() { void AlignmentSelection() {
@@ -41,7 +41,7 @@ namespace IsoTools {
} }
void AlignmentIsoObject(IsoObject iso_object) { void AlignmentIsoObject(IsoObject iso_object) {
iso_object.Position = iso_object.TilePosition; iso_object.position = iso_object.tilePosition;
iso_object.FixTransform(); iso_object.FixTransform();
} }
@@ -51,12 +51,12 @@ namespace IsoTools {
return _iso_zpositions.Aggregate(0.0f, (AccIn, pair) => { return _iso_zpositions.Aggregate(0.0f, (AccIn, pair) => {
var iso_object = pair.Key; var iso_object = pair.Key;
var iso_orig_z = pair.Value; var iso_orig_z = pair.Value;
iso_object.PositionZ = iso_orig_z + delta; iso_object.positionZ = iso_orig_z + delta;
iso_object.FixTransform(); iso_object.FixTransform();
if ( is_any_alignment ) { if ( is_any_alignment ) {
AlignmentIsoObject(iso_object); AlignmentIsoObject(iso_object);
} }
var z_delta = iso_object.Position.z - iso_orig_z; var z_delta = iso_object.position.z - iso_orig_z;
return Mathf.Abs(z_delta) > Mathf.Abs(AccIn) ? z_delta : AccIn; return Mathf.Abs(z_delta) > Mathf.Abs(AccIn) ? z_delta : AccIn;
}); });
} }
@@ -81,10 +81,10 @@ namespace IsoTools {
var iso_world = GameObject.FindObjectOfType<IsoWorld>(); var iso_world = GameObject.FindObjectOfType<IsoWorld>();
if ( iso_world ) { if ( iso_world ) {
Handles.color = Handles.zAxisColor; Handles.color = Handles.zAxisColor;
var delta = Handles.Slider(_viewCenter, IsoUtils.Vec3OneY) - _viewCenter; var delta = Handles.Slider(_viewCenter, IsoUtils.vec3OneY) - _viewCenter;
if ( Mathf.Abs(delta.y) > Mathf.Epsilon ) { if ( Mathf.Abs(delta.y) > Mathf.Epsilon ) {
float tmp_y = ZMoveIsoObjects((_viewCenter.y - _center.y + delta.y) / iso_world.TileSize); float tmp_y = ZMoveIsoObjects((_viewCenter.y - _center.y + delta.y) / iso_world.tileSize);
_viewCenter = _center + IsoUtils.Vec3FromY(tmp_y * iso_world.TileSize); _viewCenter = _center + IsoUtils.Vec3FromY(tmp_y * iso_world.tileSize);
} }
} }
} }
@@ -134,15 +134,18 @@ namespace IsoTools {
} }
void OnDisable() { void OnDisable() {
Tools.hidden = false; if ( Tools.hidden ) {
Tools.hidden = false;
Tools.current = Tool.Move;
}
} }
void OnSceneGUI() { void OnSceneGUI() {
if ( Tools.current == Tool.Move ) { if ( Tools.current == Tool.Move ) {
Tools.hidden = true; Tools.hidden = true;
ZMoveSlider(); ZMoveSlider();
XYMoveSlider(Handles.xAxisColor, IsoUtils.Vec3OneX); XYMoveSlider(Handles.xAxisColor, IsoUtils.vec3OneX);
XYMoveSlider(Handles.yAxisColor, IsoUtils.Vec3OneY); XYMoveSlider(Handles.yAxisColor, IsoUtils.vec3OneY);
XYMoveRectangle(); XYMoveRectangle();
} else { } else {
Tools.hidden = false; Tools.hidden = false;

View File

@@ -39,7 +39,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 114888} m_GameObject: {fileID: 114888}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 1.29999995, y: .649999976, z: 22.2222233} m_LocalPosition: {x: 32, y: 16, z: 22.2222233}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 483872} - {fileID: 483872}

View File

@@ -39,7 +39,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 155780} m_GameObject: {fileID: 155780}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -2.5999999, y: 0, z: 0} m_LocalPosition: {x: -64, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 457334} - {fileID: 457334}

View File

@@ -51,7 +51,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 112436} m_GameObject: {fileID: 112436}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 1.29999995, y: -.649999976, z: 0} m_LocalPosition: {x: 32, y: -16, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 400788} - {fileID: 400788}

File diff suppressed because it is too large Load Diff

View File

@@ -3,8 +3,8 @@ using System.Collections;
namespace IsoTools { namespace Examples { namespace IsoTools { namespace Examples {
public class CircleFly : MonoBehaviour { public class CircleFly : MonoBehaviour {
public float FlyRadius = 150.0f; public float flyRadius = 150.0f;
public float FlySpeed = 1.0f; public float flySpeed = 1.0f;
Vector3 _start_pos; Vector3 _start_pos;
float _fly_timer; float _fly_timer;
@@ -15,10 +15,10 @@ namespace IsoTools { namespace Examples {
} }
void Update () { void Update () {
_fly_timer += FlySpeed * Time.deltaTime; _fly_timer += flySpeed * Time.deltaTime;
transform.position = new Vector3( transform.position = new Vector3(
_start_pos.x + Mathf.Cos(_fly_timer) * FlyRadius, _start_pos.x + Mathf.Cos(_fly_timer) * flyRadius,
_start_pos.y + Mathf.Sin(_fly_timer) * FlyRadius, _start_pos.y + Mathf.Sin(_fly_timer) * flyRadius,
_start_pos.z); _start_pos.z);
} }
} }

View File

@@ -3,15 +3,15 @@ using System.Collections;
namespace IsoTools { namespace Examples { namespace IsoTools { namespace Examples {
public class IsoAutoController : MonoBehaviour { public class IsoAutoController : MonoBehaviour {
public float StepTicks = 0.5f; public float stepTicks = 0.5f;
public float StepRndTicks = 0.5f; public float stepRndTicks = 0.5f;
void Start() { void Start() {
StartCoroutine("Move"); StartCoroutine("Move");
} }
WaitForSeconds RndWait() { WaitForSeconds RndWait() {
return new WaitForSeconds(StepTicks + Random.Range(0.0f, StepRndTicks)); return new WaitForSeconds(stepTicks + Random.Range(0.0f, stepRndTicks));
} }
IEnumerator Move() { IEnumerator Move() {
@@ -19,13 +19,13 @@ namespace IsoTools { namespace Examples {
if ( iso_object ) { if ( iso_object ) {
for (;;) { for (;;) {
yield return RndWait(); yield return RndWait();
iso_object.Position += new Vector3(1, 0, 0); iso_object.position += new Vector3(1, 0, 0);
yield return RndWait(); yield return RndWait();
iso_object.Position += new Vector3(0, 1, 0); iso_object.position += new Vector3(0, 1, 0);
yield return RndWait(); yield return RndWait();
iso_object.Position += new Vector3(-1, 0, 0); iso_object.position += new Vector3(-1, 0, 0);
yield return RndWait(); yield return RndWait();
iso_object.Position += new Vector3(0, -1, 0); iso_object.position += new Vector3(0, -1, 0);
} }
} }
} }

View File

@@ -7,9 +7,9 @@ namespace IsoTools { namespace Examples {
var iso_object = GetComponent<IsoObject>(); var iso_object = GetComponent<IsoObject>();
var iso_rigidbody = GetComponent<IsoRigidbody>(); var iso_rigidbody = GetComponent<IsoRigidbody>();
if ( iso_rigidbody ) { if ( iso_rigidbody ) {
iso_rigidbody.Velocity = dir; iso_rigidbody.velocity = dir;
} else if ( iso_object) { } else if ( iso_object) {
iso_object.Position += dir * Time.deltaTime; iso_object.position += dir * Time.deltaTime;
} }
} }
void Update () { void Update () {

View File

@@ -18,13 +18,13 @@ namespace IsoTools { namespace Examples {
void OnIsoCollisionEnter(IsoCollision iso_collision) { void OnIsoCollisionEnter(IsoCollision iso_collision) {
Debug.LogFormat( Debug.LogFormat(
"OnIsoCollisionEnter. self:{0} other:{1}", "OnIsoCollisionEnter. self:{0} other:{1}",
gameObject.name, iso_collision.GameObject.name); gameObject.name, iso_collision.gameObject.name);
} }
void OnIsoCollisionExit(IsoCollision iso_collision) { void OnIsoCollisionExit(IsoCollision iso_collision) {
Debug.LogFormat( Debug.LogFormat(
"OnIsoCollisionExit. self:{0} other:{1}", "OnIsoCollisionExit. self:{0} other:{1}",
gameObject.name, iso_collision.GameObject.name); gameObject.name, iso_collision.gameObject.name);
} }
} }
}} // namespace IsoTools::Examples }} // namespace IsoTools::Examples

View File

@@ -10,63 +10,63 @@ namespace IsoTools {
[SerializeField] [SerializeField]
public Vector3 _size = Vector3.zero; public Vector3 _size = Vector3.zero;
public Vector3 Size { public Vector3 size {
get { return _size; } get { return _size; }
set { set {
_size = value; _size = value;
if ( RealBoxCollider ) { if ( realBoxCollider ) {
RealBoxCollider.size = value; realBoxCollider.size = value;
} }
} }
} }
[SerializeField] [SerializeField]
public Vector3 _offset = Vector3.zero; public Vector3 _offset = Vector3.zero;
public Vector3 Offset { public Vector3 offset {
get { return _offset; } get { return _offset; }
set { set {
_offset = value; _offset = value;
if ( RealBoxCollider ) { if ( realBoxCollider ) {
RealBoxCollider.center = value; realBoxCollider.center = value;
} }
} }
} }
protected override Collider CreateRealCollider(GameObject target) { protected override Collider CreateRealCollider(GameObject target) {
var collider = target.AddComponent<BoxCollider>(); var collider = target.AddComponent<BoxCollider>();
collider.size = Size; collider.size = size;
collider.center = Offset; collider.center = offset;
return collider; return collider;
} }
public BoxCollider RealBoxCollider { public BoxCollider realBoxCollider {
get { return RealCollider as BoxCollider; } get { return realCollider as BoxCollider; }
} }
#if UNITY_EDITOR #if UNITY_EDITOR
protected override void Reset() { protected override void Reset() {
base.Reset(); base.Reset();
var iso_object = GetComponent<IsoObject>(); var iso_object = GetComponent<IsoObject>();
Size = iso_object ? iso_object.Size : Vector3.zero; size = iso_object ? iso_object.size : Vector3.zero;
Offset = iso_object ? iso_object.Size * 0.5f : Vector3.zero; offset = iso_object ? iso_object.size * 0.5f : Vector3.zero;
EditorUtility.SetDirty(this); EditorUtility.SetDirty(this);
} }
protected override void OnValidate() { protected override void OnValidate() {
base.OnValidate(); base.OnValidate();
if ( RealBoxCollider ) { if ( realBoxCollider ) {
RealBoxCollider.size = Size; realBoxCollider.size = size;
RealBoxCollider.center = Offset; realBoxCollider.center = offset;
} }
} }
void OnDrawGizmosSelected() { void OnDrawGizmosSelected() {
var iso_object = GetComponent<IsoObject>(); var iso_object = GetComponent<IsoObject>();
if ( iso_object && iso_object.IsoWorld ) { if ( iso_object && iso_object.isoWorld ) {
IsoUtils.DrawCube( IsoUtils.DrawCube(
iso_object.IsoWorld, iso_object.isoWorld,
iso_object.Position + Offset, iso_object.position + offset,
Size, size,
Color.green); Color.green);
} }
} }

View File

@@ -10,67 +10,67 @@ namespace IsoTools {
protected abstract Collider CreateRealCollider(GameObject target); protected abstract Collider CreateRealCollider(GameObject target);
Collider _realCollider = null; Collider _realCollider = null;
protected Collider RealCollider { protected Collider realCollider {
get { return _realCollider; } get { return _realCollider; }
} }
protected GameObject IsoFakeObject { protected GameObject fakeObject {
get { get {
var helper = IsoUtils.GetOrCreateComponent<IsoPhysicHelper>(gameObject); var helper = IsoUtils.GetOrCreateComponent<IsoPhysicHelper>(gameObject);
return helper ? helper.IsoFakeObject : null; return helper ? helper.isoFakeObject : null;
} }
} }
[SerializeField] [SerializeField]
public PhysicMaterial _material = null; public PhysicMaterial _material = null;
public PhysicMaterial Material { public PhysicMaterial material {
get { return _material; } get { return _material; }
set { set {
_material = value; _material = value;
if ( RealCollider ) { if ( realCollider ) {
RealCollider.material = value; realCollider.material = value;
} }
} }
} }
[SerializeField] [SerializeField]
public bool _isTrigger = false; public bool _isTrigger = false;
public bool IsTrigger { public bool isTrigger {
get { return _isTrigger; } get { return _isTrigger; }
set { set {
_isTrigger = value; _isTrigger = value;
if ( RealCollider ) { if ( realCollider ) {
RealCollider.isTrigger = value; realCollider.isTrigger = value;
} }
} }
} }
public IsoRigidbody AttachedRigidbody { public IsoRigidbody attachedRigidbody {
get { get {
return RealCollider return realCollider
? IsoUtils.IsoConvertRigidbody(RealCollider.attachedRigidbody) ? IsoUtils.IsoConvertRigidbody(realCollider.attachedRigidbody)
: null; : null;
} }
} }
public Bounds Bounds { public Bounds bounds {
get { get {
return RealCollider return realCollider
? RealCollider.bounds ? realCollider.bounds
: new Bounds(); : new Bounds();
} }
} }
public Vector3 ClosestPointOnBounds(Vector3 position) { public Vector3 ClosestPointOnBounds(Vector3 position) {
return RealCollider return realCollider
? RealCollider.ClosestPointOnBounds(position) ? realCollider.ClosestPointOnBounds(position)
: Vector3.zero; : Vector3.zero;
} }
public bool Raycast(Ray ray, out IsoRaycastHit iso_hit_info, float max_distance) { public bool Raycast(Ray ray, out IsoRaycastHit iso_hit_info, float max_distance) {
RaycastHit hit_info; RaycastHit hit_info;
var result = RealCollider var result = realCollider
? RealCollider.Raycast(ray, out hit_info, max_distance) ? realCollider.Raycast(ray, out hit_info, max_distance)
: false; : false;
iso_hit_info = result ? new IsoRaycastHit(hit_info) : new IsoRaycastHit(); iso_hit_info = result ? new IsoRaycastHit(hit_info) : new IsoRaycastHit();
return result; return result;
@@ -78,22 +78,22 @@ namespace IsoTools {
void Awake() { void Awake() {
var fake_collider_go = new GameObject(); var fake_collider_go = new GameObject();
fake_collider_go.transform.SetParent(IsoFakeObject.transform, false); fake_collider_go.transform.SetParent(fakeObject.transform, false);
fake_collider_go.AddComponent<IsoFakeCollider>().Init(this); fake_collider_go.AddComponent<IsoFakeCollider>().Init(this);
_realCollider = CreateRealCollider(fake_collider_go); _realCollider = CreateRealCollider(fake_collider_go);
_realCollider.material = Material; _realCollider.material = material;
_realCollider.isTrigger = IsTrigger; _realCollider.isTrigger = isTrigger;
} }
void OnEnable() { void OnEnable() {
if ( RealCollider ) { if ( realCollider ) {
RealCollider.enabled = true; realCollider.enabled = true;
} }
} }
void OnDisable() { void OnDisable() {
if ( RealCollider ) { if ( realCollider ) {
RealCollider.enabled = false; realCollider.enabled = false;
} }
} }
@@ -106,14 +106,14 @@ namespace IsoTools {
#if UNITY_EDITOR #if UNITY_EDITOR
protected virtual void Reset() { protected virtual void Reset() {
Material = null; material = null;
IsTrigger = false; isTrigger = false;
EditorUtility.SetDirty(this); EditorUtility.SetDirty(this);
} }
protected virtual void OnValidate() { protected virtual void OnValidate() {
Material = _material; material = _material;
IsTrigger = _isTrigger; isTrigger = _isTrigger;
} }
#endif #endif
} }

View File

@@ -3,18 +3,18 @@
namespace IsoTools { namespace IsoTools {
public class IsoCollision { public class IsoCollision {
public IsoCollider IsoCollider { get; private set; } public IsoCollider collider { get; private set; }
public IsoContactPoint[] IsoContacts { get; private set; } public IsoContactPoint[] contacts { get; private set; }
public GameObject GameObject { get; private set; } public GameObject gameObject { get; private set; }
public Vector3 RelativeVelocity { get; private set; } public Vector3 relativeVelocity { get; private set; }
public IsoRigidbody IsoRigidbody { get; private set; } public IsoRigidbody rigidbody { get; private set; }
public IsoCollision(Collision collision) { public IsoCollision(Collision collision) {
IsoCollider = IsoUtils.IsoConvertCollider(collision.collider); collider = IsoUtils.IsoConvertCollider(collision.collider);
IsoContacts = IsoUtils.IsoConvertContactPoints(collision.contacts); contacts = IsoUtils.IsoConvertContactPoints(collision.contacts);
GameObject = IsoUtils.IsoConvertGameObject(collision.gameObject); gameObject = IsoUtils.IsoConvertGameObject(collision.gameObject);
RelativeVelocity = collision.relativeVelocity; relativeVelocity = collision.relativeVelocity;
IsoRigidbody = IsoUtils.IsoConvertRigidbody(collision.rigidbody); rigidbody = IsoUtils.IsoConvertRigidbody(collision.rigidbody);
} }
} }
} // namespace IsoTools } // namespace IsoTools

View File

@@ -3,16 +3,16 @@
namespace IsoTools { namespace IsoTools {
public struct IsoContactPoint { public struct IsoContactPoint {
public Vector3 Normal { get; private set; } public Vector3 normal { get; private set; }
public IsoCollider OtherIsoCollider { get; private set; } public IsoCollider otherCollider { get; private set; }
public Vector3 Point { get; private set; } public Vector3 point { get; private set; }
public IsoCollider ThisIsoCollider { get; private set; } public IsoCollider thisCollider { get; private set; }
public IsoContactPoint(ContactPoint contact_point) { public IsoContactPoint(ContactPoint contact_point) {
Normal = contact_point.normal; normal = contact_point.normal;
OtherIsoCollider = IsoUtils.IsoConvertCollider(contact_point.otherCollider); otherCollider = IsoUtils.IsoConvertCollider(contact_point.otherCollider);
Point = contact_point.point; point = contact_point.point;
ThisIsoCollider = IsoUtils.IsoConvertCollider(contact_point.thisCollider); thisCollider = IsoUtils.IsoConvertCollider(contact_point.thisCollider);
} }
} }
} // namespace IsoTools } // namespace IsoTools

View File

@@ -9,7 +9,7 @@ namespace IsoTools {
_isoCollider = iso_collider; _isoCollider = iso_collider;
} }
public IsoCollider IsoCollider { public IsoCollider isoCollider {
get { return _isoCollider; } get { return _isoCollider; }
} }
} }

View File

@@ -8,45 +8,45 @@ namespace IsoTools {
public void Init(IsoObject iso_object) { public void Init(IsoObject iso_object) {
_isoObject = iso_object; _isoObject = iso_object;
_lastPosition = iso_object.Position; _lastPosition = iso_object.position;
transform.position = iso_object.Position; transform.position = iso_object.position;
} }
public IsoObject IsoObject { public IsoObject isoObject {
get { return _isoObject; } get { return _isoObject; }
} }
void FixedUpdate() { void FixedUpdate() {
if ( !IsoUtils.Vec3Approximately(_lastPosition, IsoObject.Position) ) { if ( !IsoUtils.Vec3Approximately(_lastPosition, isoObject.position) ) {
_lastPosition = transform.position = IsoObject.Position; _lastPosition = transform.position = isoObject.position;
} else if ( !IsoUtils.Vec3Approximately(_lastPosition, transform.position) ) { } else if ( !IsoUtils.Vec3Approximately(_lastPosition, transform.position) ) {
_lastPosition = IsoObject.Position = transform.position; _lastPosition = isoObject.position = transform.position;
} }
} }
void OnTriggerEnter(Collider collider) { void OnTriggerEnter(Collider collider) {
IsoObject.gameObject.SendMessage( isoObject.gameObject.SendMessage(
"OnIsoTriggerEnter", "OnIsoTriggerEnter",
IsoUtils.IsoConvertCollider(collider), IsoUtils.IsoConvertCollider(collider),
SendMessageOptions.DontRequireReceiver); SendMessageOptions.DontRequireReceiver);
} }
void OnTriggerExit(Collider collider) { void OnTriggerExit(Collider collider) {
IsoObject.gameObject.SendMessage( isoObject.gameObject.SendMessage(
"OnIsoTriggerExit", "OnIsoTriggerExit",
IsoUtils.IsoConvertCollider(collider), IsoUtils.IsoConvertCollider(collider),
SendMessageOptions.DontRequireReceiver); SendMessageOptions.DontRequireReceiver);
} }
void OnCollisionEnter(Collision collision) { void OnCollisionEnter(Collision collision) {
IsoObject.gameObject.SendMessage( isoObject.gameObject.SendMessage(
"OnIsoCollisionEnter", "OnIsoCollisionEnter",
new IsoCollision(collision), new IsoCollision(collision),
SendMessageOptions.DontRequireReceiver); SendMessageOptions.DontRequireReceiver);
} }
void OnCollisionExit(Collision collision) { void OnCollisionExit(Collision collision) {
IsoObject.gameObject.SendMessage( isoObject.gameObject.SendMessage(
"OnIsoCollisionExit", "OnIsoCollisionExit",
new IsoCollision(collision), new IsoCollision(collision),
SendMessageOptions.DontRequireReceiver); SendMessageOptions.DontRequireReceiver);

View File

@@ -9,7 +9,7 @@ namespace IsoTools {
_isoRigidbody = iso_rigidbody; _isoRigidbody = iso_rigidbody;
} }
public IsoRigidbody IsoRigidbody { public IsoRigidbody isoRigidbody {
get { return _isoRigidbody; } get { return _isoRigidbody; }
} }
} }

View File

@@ -11,7 +11,7 @@ namespace IsoTools {
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// //
// Size // size
// //
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@@ -19,7 +19,7 @@ namespace IsoTools {
Vector3 _size = Vector3.one; Vector3 _size = Vector3.one;
/// <summary>Isometric object size.</summary> /// <summary>Isometric object size.</summary>
public Vector3 Size { public Vector3 size {
get { return _size; } get { return _size; }
set { set {
_size = IsoUtils.Vec3Max(value, Vector3.zero); _size = IsoUtils.Vec3Max(value, Vector3.zero);
@@ -28,41 +28,41 @@ namespace IsoTools {
} }
/// <summary>Isometric object size X.</summary> /// <summary>Isometric object size X.</summary>
public float SizeX { public float sizeX {
get { return Size.x; } get { return size.x; }
set { Size = IsoUtils.Vec3ChangeX(Size, value); } set { size = IsoUtils.Vec3ChangeX(size, value); }
} }
/// <summary>Isometric object size Y.</summary> /// <summary>Isometric object size Y.</summary>
public float SizeY { public float sizeY {
get { return Size.y; } get { return size.y; }
set { Size = IsoUtils.Vec3ChangeY(Size, value); } set { size = IsoUtils.Vec3ChangeY(size, value); }
} }
/// <summary>Isometric object size Z.</summary> /// <summary>Isometric object size Z.</summary>
public float SizeZ { public float sizeZ {
get { return Size.z; } get { return size.z; }
set { Size = IsoUtils.Vec3ChangeZ(Size, value); } set { size = IsoUtils.Vec3ChangeZ(size, value); }
} }
/// <summary>Isometric object size XY.</summary> /// <summary>Isometric object size XY.</summary>
public Vector2 SizeXY { public Vector2 sizeXY {
get { return new Vector2(SizeX, SizeY); } get { return new Vector2(sizeX, sizeY); }
} }
/// <summary>Isometric object size YZ.</summary> /// <summary>Isometric object size YZ.</summary>
public Vector2 SizeYZ { public Vector2 sizeYZ {
get { return new Vector2(SizeY, SizeZ); } get { return new Vector2(sizeY, sizeZ); }
} }
/// <summary>Isometric object size XZ.</summary> /// <summary>Isometric object size XZ.</summary>
public Vector2 SizeXZ { public Vector2 sizeXZ {
get { return new Vector2(SizeX, SizeZ); } get { return new Vector2(sizeX, sizeZ); }
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// //
// Position // position
// //
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@@ -70,7 +70,7 @@ namespace IsoTools {
Vector3 _position = Vector3.zero; Vector3 _position = Vector3.zero;
/// <summary>Isometric object position.</summary> /// <summary>Isometric object position.</summary>
public Vector3 Position { public Vector3 position {
get { return _position; } get { return _position; }
set { set {
_position = value; _position = value;
@@ -79,81 +79,81 @@ namespace IsoTools {
} }
/// <summary>Isometric object position X.</summary> /// <summary>Isometric object position X.</summary>
public float PositionX { public float positionX {
get { return Position.x; } get { return position.x; }
set { Position = IsoUtils.Vec3ChangeX(Position, value); } set { position = IsoUtils.Vec3ChangeX(position, value); }
} }
/// <summary>Isometric object position Y.</summary> /// <summary>Isometric object position Y.</summary>
public float PositionY { public float positionY {
get { return Position.y; } get { return position.y; }
set { Position = IsoUtils.Vec3ChangeY(Position, value); } set { position = IsoUtils.Vec3ChangeY(position, value); }
} }
/// <summary>Isometric object position Z.</summary> /// <summary>Isometric object position Z.</summary>
public float PositionZ { public float positionZ {
get { return Position.z; } get { return position.z; }
set { Position = IsoUtils.Vec3ChangeZ(Position, value); } set { position = IsoUtils.Vec3ChangeZ(position, value); }
} }
/// <summary>Isometric object position XY.</summary> /// <summary>Isometric object position XY.</summary>
public Vector2 PositionXY { public Vector2 positionXY {
get { return new Vector2(PositionX, PositionY); } get { return new Vector2(positionX, positionY); }
} }
/// <summary>Isometric object position YZ.</summary> /// <summary>Isometric object position YZ.</summary>
public Vector2 PositionYZ { public Vector2 positionYZ {
get { return new Vector2(PositionY, PositionZ); } get { return new Vector2(positionY, positionZ); }
} }
/// <summary>Isometric object position XZ.</summary> /// <summary>Isometric object position XZ.</summary>
public Vector2 PositionXZ { public Vector2 positionXZ {
get { return new Vector2(PositionX, PositionZ); } get { return new Vector2(positionX, positionZ); }
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// //
// TilePosition // tilePosition
// //
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/// <summary>Isometric object tile position.</summary> /// <summary>Isometric object tile position.</summary>
public Vector3 TilePosition { public Vector3 tilePosition {
get { return IsoUtils.Vec3Round(Position); } get { return IsoUtils.Vec3Round(position); }
set { Position = value; } set { position = value; }
} }
/// <summary>Isometric object tile position X.</summary> /// <summary>Isometric object tile position X.</summary>
public float TilePositionX { public float tilePositionX {
get { return TilePosition.x; } get { return tilePosition.x; }
set { TilePosition = IsoUtils.Vec3ChangeX(TilePosition, value); } set { tilePosition = IsoUtils.Vec3ChangeX(tilePosition, value); }
} }
/// <summary>Isometric object tile position Y.</summary> /// <summary>Isometric object tile position Y.</summary>
public float TilePositionY { public float tilePositionY {
get { return TilePosition.y; } get { return tilePosition.y; }
set { TilePosition = IsoUtils.Vec3ChangeY(TilePosition, value); } set { tilePosition = IsoUtils.Vec3ChangeY(tilePosition, value); }
} }
/// <summary>Isometric object tile position Z.</summary> /// <summary>Isometric object tile position Z.</summary>
public float TilePositionZ { public float tilePositionZ {
get { return TilePosition.z; } get { return tilePosition.z; }
set { TilePosition = IsoUtils.Vec3ChangeZ(TilePosition, value); } set { tilePosition = IsoUtils.Vec3ChangeZ(tilePosition, value); }
} }
/// <summary>Isometric object tile position XY.</summary> /// <summary>Isometric object tile position XY.</summary>
public Vector2 TilePositionXY { public Vector2 tilePositionXY {
get { return new Vector2(TilePositionX, TilePositionY); } get { return new Vector2(tilePositionX, tilePositionY); }
} }
/// <summary>Isometric object tile position YZ.</summary> /// <summary>Isometric object tile position YZ.</summary>
public Vector2 TilePositionYZ { public Vector2 tilePositionYZ {
get { return new Vector2(TilePositionY, TilePositionZ); } get { return new Vector2(tilePositionY, tilePositionZ); }
} }
/// <summary>Isometric object tile position XZ.</summary> /// <summary>Isometric object tile position XZ.</summary>
public Vector2 TilePositionXZ { public Vector2 tilePositionXZ {
get { return new Vector2(TilePositionX, TilePositionZ); } get { return new Vector2(tilePositionX, tilePositionZ); }
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@@ -167,15 +167,15 @@ namespace IsoTools {
Vector3 _lastPosition = Vector3.zero; Vector3 _lastPosition = Vector3.zero;
Vector2 _lastTransform = Vector2.zero; Vector2 _lastTransform = Vector2.zero;
[SerializeField] bool _alignment = true; [SerializeField] bool _isAlignment = true;
[SerializeField] bool _showBounds = false; [SerializeField] bool _isShowBounds = false;
public bool Alignment { public bool isAlignment {
get { return _alignment; } get { return _isAlignment; }
} }
public bool ShowBounds { public bool isShowBounds {
get { return _showBounds; } get { return _isShowBounds; }
} }
#endif #endif
@@ -186,7 +186,7 @@ namespace IsoTools {
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
IsoWorld _isoWorld = null; IsoWorld _isoWorld = null;
public IsoWorld IsoWorld { public IsoWorld isoWorld {
get { get {
if ( (object)_isoWorld == null ) { if ( (object)_isoWorld == null ) {
_isoWorld = GameObject.FindObjectOfType<IsoWorld>(); _isoWorld = GameObject.FindObjectOfType<IsoWorld>();
@@ -204,12 +204,12 @@ namespace IsoTools {
public void FixTransform() { public void FixTransform() {
#if UNITY_EDITOR #if UNITY_EDITOR
if ( Application.isEditor && !Application.isPlaying && Alignment ) { if ( Application.isEditor && !Application.isPlaying && isAlignment ) {
_position = TilePosition; _position = tilePosition;
} }
#endif #endif
transform.position = IsoUtils.Vec3ChangeZ( transform.position = IsoUtils.Vec3ChangeZ(
IsoWorld.IsoToScreen(Position), isoWorld.IsoToScreen(position),
transform.position.z); transform.position.z);
FixLastProperties(); FixLastProperties();
MartDirtyIsoWorld(); MartDirtyIsoWorld();
@@ -217,21 +217,21 @@ namespace IsoTools {
} }
public void FixIsoPosition() { public void FixIsoPosition() {
Position = IsoWorld.ScreenToIso( position = isoWorld.ScreenToIso(
transform.position, transform.position,
PositionZ); positionZ);
} }
void FixLastProperties() { void FixLastProperties() {
#if UNITY_EDITOR #if UNITY_EDITOR
_lastSize = Size; _lastSize = size;
_lastPosition = Position; _lastPosition = position;
_lastTransform = transform.position; _lastTransform = transform.position;
#endif #endif
} }
void MartDirtyIsoWorld() { void MartDirtyIsoWorld() {
IsoWorld.MarkDirty(this); isoWorld.MarkDirty(this);
} }
void MarkEditorObjectDirty() { void MarkEditorObjectDirty() {
@@ -253,28 +253,28 @@ namespace IsoTools {
#if UNITY_EDITOR #if UNITY_EDITOR
void Reset() { void Reset() {
Size = Vector3.one; size = Vector3.one;
Position = Vector3.zero; position = Vector3.zero;
} }
void OnValidate() { void OnValidate() {
Size = _size; size = _size;
Position = _position; position = _position;
} }
void OnDrawGizmos() { void OnDrawGizmos() {
if ( ShowBounds && IsoWorld ) { if ( isShowBounds && isoWorld ) {
IsoUtils.DrawCube(IsoWorld, Position + Size * 0.5f, Size, Color.red); IsoUtils.DrawCube(isoWorld, position + size * 0.5f, size, Color.red);
} }
} }
void Update() { void Update() {
if ( Application.isEditor ) { if ( Application.isEditor ) {
if ( !IsoUtils.Vec3Approximately(_lastSize, _size) ) { if ( !IsoUtils.Vec3Approximately(_lastSize, _size) ) {
Size = _size; size = _size;
} }
if ( !IsoUtils.Vec3Approximately(_lastPosition, _position) ) { if ( !IsoUtils.Vec3Approximately(_lastPosition, _position) ) {
Position = _position; position = _position;
} }
if ( !IsoUtils.Vec2Approximately(_lastTransform, transform.position) ) { if ( !IsoUtils.Vec2Approximately(_lastTransform, transform.position) ) {
FixIsoPosition(); FixIsoPosition();

View File

@@ -6,7 +6,7 @@ namespace IsoTools {
public class IsoPhysicHelper : MonoBehaviour { public class IsoPhysicHelper : MonoBehaviour {
GameObject _isoFakeObject = null; GameObject _isoFakeObject = null;
public GameObject IsoFakeObject { public GameObject isoFakeObject {
get { return _isoFakeObject; } get { return _isoFakeObject; }
} }

View File

@@ -3,18 +3,18 @@
namespace IsoTools { namespace IsoTools {
public struct IsoRaycastHit { public struct IsoRaycastHit {
public IsoCollider IsoCollider { get; private set; } public IsoCollider collider { get; private set; }
public float Distance { get; private set; } public float distance { get; private set; }
public Vector3 Normal { get; private set; } public Vector3 normal { get; private set; }
public Vector3 Point { get; private set; } public Vector3 point { get; private set; }
public IsoRigidbody IsoRigidbody { get; private set; } public IsoRigidbody rigidbody { get; private set; }
public IsoRaycastHit(RaycastHit hit_info) { public IsoRaycastHit(RaycastHit hit_info) {
IsoCollider = IsoUtils.IsoConvertCollider(hit_info.collider); collider = IsoUtils.IsoConvertCollider(hit_info.collider);
Distance = hit_info.distance; distance = hit_info.distance;
Normal = hit_info.normal; normal = hit_info.normal;
Point = hit_info.point; point = hit_info.point;
IsoRigidbody = IsoUtils.IsoConvertRigidbody(hit_info.rigidbody); rigidbody = IsoUtils.IsoConvertRigidbody(hit_info.rigidbody);
} }
} }
} // namespace IsoTools } // namespace IsoTools

View File

@@ -10,136 +10,136 @@ namespace IsoTools {
public class IsoRigidbody : MonoBehaviour { public class IsoRigidbody : MonoBehaviour {
Rigidbody _realRigidbody = null; Rigidbody _realRigidbody = null;
protected Rigidbody RealRigidbody { protected Rigidbody realRigidbody {
get { return _realRigidbody; } get { return _realRigidbody; }
} }
protected GameObject IsoFakeObject { protected GameObject fakeObject {
get { get {
var helper = IsoUtils.GetOrCreateComponent<IsoPhysicHelper>(gameObject); var helper = IsoUtils.GetOrCreateComponent<IsoPhysicHelper>(gameObject);
return helper ? helper.IsoFakeObject : null; return helper ? helper.isoFakeObject : null;
} }
} }
[SerializeField] [SerializeField]
public bool _isKinematic = false; public bool _isKinematic = false;
public bool IsKinematic { public bool isKinematic {
get { return _isKinematic; } get { return _isKinematic; }
set { set {
_isKinematic = value; _isKinematic = value;
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.isKinematic = value; realRigidbody.isKinematic = value;
} }
} }
} }
[SerializeField] [SerializeField]
public RigidbodyInterpolation _interpolation = RigidbodyInterpolation.None; public RigidbodyInterpolation _interpolation = RigidbodyInterpolation.None;
public RigidbodyInterpolation Interpolation { public RigidbodyInterpolation interpolation {
get { return _interpolation; } get { return _interpolation; }
set { set {
_interpolation = value; _interpolation = value;
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.interpolation = value; realRigidbody.interpolation = value;
} }
} }
} }
[SerializeField] [SerializeField]
public CollisionDetectionMode _collisionDetectionMode = CollisionDetectionMode.Discrete; public CollisionDetectionMode _collisionDetectionMode = CollisionDetectionMode.Discrete;
public CollisionDetectionMode CollisionDetectionMode { public CollisionDetectionMode collisionDetectionMode {
get { return _collisionDetectionMode; } get { return _collisionDetectionMode; }
set { set {
_collisionDetectionMode = value; _collisionDetectionMode = value;
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.collisionDetectionMode = value; realRigidbody.collisionDetectionMode = value;
} }
} }
} }
public Vector3 CenterOfMass { public Vector3 centerOfMass {
get { return RealRigidbody ? RealRigidbody.centerOfMass : Vector3.zero; } get { return realRigidbody ? realRigidbody.centerOfMass : Vector3.zero; }
set { set {
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.centerOfMass = value; realRigidbody.centerOfMass = value;
} }
} }
} }
public float Drag { public float drag {
get { return RealRigidbody ? RealRigidbody.drag : 0.0f; } get { return realRigidbody ? realRigidbody.drag : 0.0f; }
set { set {
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.drag = value; realRigidbody.drag = value;
} }
} }
} }
public Vector3 InertiaTensor { public Vector3 inertiaTensor {
get { return RealRigidbody ? RealRigidbody.inertiaTensor : Vector3.zero; } get { return realRigidbody ? realRigidbody.inertiaTensor : Vector3.zero; }
set { set {
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.inertiaTensor = value; realRigidbody.inertiaTensor = value;
} }
} }
} }
public float Mass { public float mass {
get { return RealRigidbody ? RealRigidbody.mass : 0.0f; } get { return realRigidbody ? realRigidbody.mass : 0.0f; }
set { set {
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.mass = value; realRigidbody.mass = value;
} }
} }
} }
public float MaxDepenetrationVelocity { public float maxDepenetrationVelocity {
get { return RealRigidbody ? RealRigidbody.maxDepenetrationVelocity : 0.0f; } get { return realRigidbody ? realRigidbody.maxDepenetrationVelocity : 0.0f; }
set { set {
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.maxDepenetrationVelocity = value; realRigidbody.maxDepenetrationVelocity = value;
} }
} }
} }
public float SleepThreshold { public float sleepThreshold {
get { return RealRigidbody ? RealRigidbody.sleepThreshold : 0.0f; } get { return realRigidbody ? realRigidbody.sleepThreshold : 0.0f; }
set { set {
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.sleepThreshold = value; realRigidbody.sleepThreshold = value;
} }
} }
} }
public int SolverIterationCount { public int solverIterationCount {
get { return RealRigidbody ? RealRigidbody.solverIterationCount : 0; } get { return realRigidbody ? realRigidbody.solverIterationCount : 0; }
set { set {
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.solverIterationCount = value; realRigidbody.solverIterationCount = value;
} }
} }
} }
public bool UseGravity { public bool useGravity {
get { return RealRigidbody ? RealRigidbody.useGravity : false; } get { return realRigidbody ? realRigidbody.useGravity : false; }
set { set {
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.useGravity = value; realRigidbody.useGravity = value;
} }
} }
} }
public Vector3 Velocity { public Vector3 velocity {
get { return RealRigidbody ? RealRigidbody.velocity : Vector3.zero; } get { return realRigidbody ? realRigidbody.velocity : Vector3.zero; }
set { set {
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.velocity = value; realRigidbody.velocity = value;
} }
} }
} }
public Vector3 worldCenterOfMass { public Vector3 worldCenterOfMass {
get { return RealRigidbody ? RealRigidbody.worldCenterOfMass : Vector3.zero; } get { return realRigidbody ? realRigidbody.worldCenterOfMass : Vector3.zero; }
} }
public void AddExplosionForce( public void AddExplosionForce(
@@ -163,8 +163,8 @@ namespace IsoTools {
float explosion_force, Vector3 explosion_position, float explosion_radius, float explosion_force, Vector3 explosion_position, float explosion_radius,
float upwards_modifier, ForceMode mode) float upwards_modifier, ForceMode mode)
{ {
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.AddExplosionForce( realRigidbody.AddExplosionForce(
explosion_force, explosion_position, explosion_radius, explosion_force, explosion_position, explosion_radius,
upwards_modifier, mode); upwards_modifier, mode);
} }
@@ -175,8 +175,8 @@ namespace IsoTools {
} }
public void AddForce(Vector3 force, ForceMode mode) { public void AddForce(Vector3 force, ForceMode mode) {
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.AddForce(force, mode); realRigidbody.AddForce(force, mode);
} }
} }
@@ -185,8 +185,8 @@ namespace IsoTools {
} }
public void AddRelativeForce(Vector3 force, ForceMode mode) { public void AddRelativeForce(Vector3 force, ForceMode mode) {
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.AddRelativeForce(force, mode); realRigidbody.AddRelativeForce(force, mode);
} }
} }
@@ -195,38 +195,38 @@ namespace IsoTools {
} }
public void AddForceAtPosition(Vector3 force, Vector3 position, ForceMode mode) { public void AddForceAtPosition(Vector3 force, Vector3 position, ForceMode mode) {
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.AddForceAtPosition(force, position, mode); realRigidbody.AddForceAtPosition(force, position, mode);
} }
} }
public Vector3 ClosestPointOnBounds(Vector3 position) { public Vector3 ClosestPointOnBounds(Vector3 position) {
return RealRigidbody return realRigidbody
? RealRigidbody.ClosestPointOnBounds(position) ? realRigidbody.ClosestPointOnBounds(position)
: Vector3.zero; : Vector3.zero;
} }
public bool IsSleeping() { public bool IsSleeping() {
return RealRigidbody return realRigidbody
? RealRigidbody.IsSleeping() ? realRigidbody.IsSleeping()
: false; : false;
} }
public void SetDensity(float density) { public void SetDensity(float density) {
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.SetDensity(density); realRigidbody.SetDensity(density);
} }
} }
public void Sleep() { public void Sleep() {
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.Sleep(); realRigidbody.Sleep();
} }
} }
public void WakeUp() { public void WakeUp() {
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.WakeUp(); realRigidbody.WakeUp();
} }
} }
@@ -236,8 +236,8 @@ namespace IsoTools {
public bool SweepTest(Vector3 direction, out IsoRaycastHit iso_hit_info, float max_distance) { public bool SweepTest(Vector3 direction, out IsoRaycastHit iso_hit_info, float max_distance) {
RaycastHit hit_info; RaycastHit hit_info;
var result = RealRigidbody var result = realRigidbody
? RealRigidbody.SweepTest(direction, out hit_info, max_distance) ? realRigidbody.SweepTest(direction, out hit_info, max_distance)
: false; : false;
iso_hit_info = result ? new IsoRaycastHit(hit_info) : new IsoRaycastHit(); iso_hit_info = result ? new IsoRaycastHit(hit_info) : new IsoRaycastHit();
return result; return result;
@@ -248,35 +248,35 @@ namespace IsoTools {
} }
public IsoRaycastHit[] SweepTestAll(Vector3 direction, float max_distance) { public IsoRaycastHit[] SweepTestAll(Vector3 direction, float max_distance) {
return RealRigidbody return realRigidbody
? IsoUtils.IsoConvertRaycastHits(RealRigidbody.SweepTestAll(direction, max_distance)) ? IsoUtils.IsoConvertRaycastHits(realRigidbody.SweepTestAll(direction, max_distance))
: new IsoRaycastHit[0]; : new IsoRaycastHit[0];
} }
void Awake() { void Awake() {
IsoFakeObject.AddComponent<IsoFakeRigidbody>().Init(this); fakeObject.AddComponent<IsoFakeRigidbody>().Init(this);
_realRigidbody = IsoFakeObject.AddComponent<Rigidbody>(); _realRigidbody = fakeObject.AddComponent<Rigidbody>();
_realRigidbody.freezeRotation = true; _realRigidbody.freezeRotation = true;
_realRigidbody.isKinematic = IsKinematic; _realRigidbody.isKinematic = isKinematic;
_realRigidbody.interpolation = Interpolation; _realRigidbody.interpolation = interpolation;
_realRigidbody.collisionDetectionMode = CollisionDetectionMode; _realRigidbody.collisionDetectionMode = collisionDetectionMode;
} }
void OnEnable() { void OnEnable() {
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.detectCollisions = true; realRigidbody.detectCollisions = true;
} }
} }
void OnDisable() { void OnDisable() {
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.detectCollisions = false; realRigidbody.detectCollisions = false;
} }
} }
void OnDestroy() { void OnDestroy() {
if ( _realRigidbody ) { if ( _realRigidbody ) {
Destroy(IsoFakeObject.GetComponent<IsoFakeRigidbody>()); Destroy(fakeObject.GetComponent<IsoFakeRigidbody>());
Destroy(_realRigidbody); Destroy(_realRigidbody);
_realRigidbody = null; _realRigidbody = null;
} }
@@ -284,17 +284,17 @@ namespace IsoTools {
#if UNITY_EDITOR #if UNITY_EDITOR
void Reset() { void Reset() {
IsKinematic = false; isKinematic = false;
Interpolation = RigidbodyInterpolation.None; interpolation = RigidbodyInterpolation.None;
CollisionDetectionMode = CollisionDetectionMode.Discrete; collisionDetectionMode = CollisionDetectionMode.Discrete;
EditorUtility.SetDirty(this); EditorUtility.SetDirty(this);
} }
void OnValidate() { void OnValidate() {
if ( RealRigidbody ) { if ( realRigidbody ) {
RealRigidbody.isKinematic = IsKinematic; realRigidbody.isKinematic = isKinematic;
RealRigidbody.interpolation = Interpolation; realRigidbody.interpolation = interpolation;
RealRigidbody.collisionDetectionMode = CollisionDetectionMode; realRigidbody.collisionDetectionMode = collisionDetectionMode;
} }
} }
#endif #endif

View File

@@ -10,63 +10,63 @@ namespace IsoTools {
[SerializeField] [SerializeField]
public float _radius = 0.0f; public float _radius = 0.0f;
public float Radius { public float radius {
get { return _radius; } get { return _radius; }
set { set {
_radius = value; _radius = value;
if ( RealSphereCollider ) { if ( realSphereCollider ) {
RealSphereCollider.radius = value; realSphereCollider.radius = value;
} }
} }
} }
[SerializeField] [SerializeField]
public Vector3 _offset = Vector3.zero; public Vector3 _offset = Vector3.zero;
public Vector3 Offset { public Vector3 offset {
get { return _offset; } get { return _offset; }
set { set {
_offset = value; _offset = value;
if ( RealSphereCollider ) { if ( realSphereCollider ) {
RealSphereCollider.center = value; realSphereCollider.center = value;
} }
} }
} }
protected override Collider CreateRealCollider(GameObject target) { protected override Collider CreateRealCollider(GameObject target) {
var collider = target.AddComponent<SphereCollider>(); var collider = target.AddComponent<SphereCollider>();
collider.radius = Radius; collider.radius = radius;
collider.center = Offset; collider.center = offset;
return collider; return collider;
} }
public SphereCollider RealSphereCollider { public SphereCollider realSphereCollider {
get { return RealCollider as SphereCollider; } get { return realCollider as SphereCollider; }
} }
#if UNITY_EDITOR #if UNITY_EDITOR
protected override void Reset() { protected override void Reset() {
base.Reset(); base.Reset();
var iso_object = GetComponent<IsoObject>(); var iso_object = GetComponent<IsoObject>();
Radius = iso_object ? IsoUtils.Vec3MinF(iso_object.Size) * 0.5f : 0.0f; radius = iso_object ? IsoUtils.Vec3MinF(iso_object.size) * 0.5f : 0.0f;
Offset = iso_object ? iso_object.Size * 0.5f : Vector3.zero; offset = iso_object ? iso_object.size * 0.5f : Vector3.zero;
EditorUtility.SetDirty(this); EditorUtility.SetDirty(this);
} }
protected override void OnValidate() { protected override void OnValidate() {
base.OnValidate(); base.OnValidate();
if ( RealSphereCollider ) { if ( realSphereCollider ) {
RealSphereCollider.radius = Radius; realSphereCollider.radius = radius;
RealSphereCollider.center = Offset; realSphereCollider.center = offset;
} }
} }
void OnDrawGizmosSelected() { void OnDrawGizmosSelected() {
var iso_object = GetComponent<IsoObject>(); var iso_object = GetComponent<IsoObject>();
if ( iso_object && iso_object.IsoWorld ) { if ( iso_object && iso_object.isoWorld ) {
IsoUtils.DrawSphere( IsoUtils.DrawSphere(
iso_object.IsoWorld, iso_object.isoWorld,
iso_object.Position + Offset, iso_object.position + offset,
Radius, radius,
Color.green); Color.green);
} }
} }

View File

@@ -13,16 +13,16 @@ namespace IsoTools {
// //
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
public static Vector3 Vec2OneX { get { return new Vector2(1.0f, 0.0f); } } public static Vector3 vec2OneX { get { return new Vector2(1.0f, 0.0f); } }
public static Vector3 Vec2OneY { get { return new Vector2(0.0f, 1.0f); } } public static Vector3 vec2OneY { get { return new Vector2(0.0f, 1.0f); } }
public static Vector3 Vec2OneXY { get { return new Vector2(1.0f, 1.0f); } } public static Vector3 vec2OneXY { get { return new Vector2(1.0f, 1.0f); } }
public static Vector3 Vec3OneX { get { return new Vector3(1.0f, 0.0f, 0.0f); } } public static Vector3 vec3OneX { get { return new Vector3(1.0f, 0.0f, 0.0f); } }
public static Vector3 Vec3OneY { get { return new Vector3(0.0f, 1.0f, 0.0f); } } public static Vector3 vec3OneY { get { return new Vector3(0.0f, 1.0f, 0.0f); } }
public static Vector3 Vec3OneZ { get { return new Vector3(0.0f, 0.0f, 1.0f); } } public static Vector3 vec3OneZ { get { return new Vector3(0.0f, 0.0f, 1.0f); } }
public static Vector3 Vec3OneXY { get { return new Vector3(1.0f, 1.0f, 0.0f); } } public static Vector3 vec3OneXY { get { return new Vector3(1.0f, 1.0f, 0.0f); } }
public static Vector3 Vec3OneYZ { get { return new Vector3(0.0f, 1.0f, 1.0f); } } public static Vector3 vec3OneYZ { get { return new Vector3(0.0f, 1.0f, 1.0f); } }
public static Vector3 Vec3OneXZ { get { return new Vector3(1.0f, 0.0f, 1.0f); } } public static Vector3 vec3OneXZ { get { return new Vector3(1.0f, 0.0f, 1.0f); } }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// //
@@ -372,17 +372,17 @@ namespace IsoTools {
public static IsoCollider IsoConvertCollider(Collider collider) { public static IsoCollider IsoConvertCollider(Collider collider) {
var fake_collider = collider ? collider.GetComponent<IsoFakeCollider>() : null; var fake_collider = collider ? collider.GetComponent<IsoFakeCollider>() : null;
return fake_collider ? fake_collider.IsoCollider : null; return fake_collider ? fake_collider.isoCollider : null;
} }
public static IsoRigidbody IsoConvertRigidbody(Rigidbody rigidbody) { public static IsoRigidbody IsoConvertRigidbody(Rigidbody rigidbody) {
var fake_rigidbody = rigidbody ? rigidbody.GetComponent<IsoFakeRigidbody>() : null; var fake_rigidbody = rigidbody ? rigidbody.GetComponent<IsoFakeRigidbody>() : null;
return fake_rigidbody ? fake_rigidbody.IsoRigidbody : null; return fake_rigidbody ? fake_rigidbody.isoRigidbody : null;
} }
public static GameObject IsoConvertGameObject(GameObject game_object) { public static GameObject IsoConvertGameObject(GameObject game_object) {
var fake_object = game_object ? game_object.GetComponent<IsoFakeObject>() : null; var fake_object = game_object ? game_object.GetComponent<IsoFakeObject>() : null;
var iso_object = fake_object ? fake_object.IsoObject : null; var iso_object = fake_object ? fake_object.isoObject : null;
return iso_object ? iso_object.gameObject : null; return iso_object ? iso_object.gameObject : null;
} }
@@ -452,7 +452,7 @@ namespace IsoTools {
Handles.RadiusHandle( Handles.RadiusHandle(
Quaternion.Euler(45.0f, 45.0f, 0.0f), Quaternion.Euler(45.0f, 45.0f, 0.0f),
iso_world.IsoToScreen(pos), iso_world.IsoToScreen(pos),
radius * iso_world.TileSize * 2.0f); radius * iso_world.tileSize * 2.0f);
} }
} }
#endif #endif

View File

@@ -12,31 +12,31 @@ namespace IsoTools {
public class IsoWorld : MonoBehaviour { public class IsoWorld : MonoBehaviour {
class ObjectInfo { class ObjectInfo {
public int Index; public int index;
public IsoObject IsoObject; public IsoObject isoObject;
public Vector3 MinSector; public Vector3 minSector;
public Vector3 MaxSector; public Vector3 maxSector;
public bool Visited; public bool visited;
public int BeginDepend; public int beginDepend;
public int EndDepend; public int endDepend;
public ObjectInfo(int index, IsoObject iso_object, Vector3 min_sector, Vector3 max_sector) { public ObjectInfo(int index, IsoObject iso_object, Vector3 min_sector, Vector3 max_sector) {
Index = index; this.index = index;
IsoObject = iso_object; this.isoObject = iso_object;
MinSector = min_sector; this.minSector = min_sector;
MaxSector = max_sector; this.maxSector = max_sector;
} }
public void Init(int first_depend) { public void Init(int first_depend) {
Visited = false; this.visited = false;
BeginDepend = first_depend; this.beginDepend = first_depend;
EndDepend = first_depend; this.endDepend = first_depend;
} }
} }
class SectorInfo { class SectorInfo {
public List<int> Objects = new List<int>(); public List<int> objects = new List<int>();
} }
bool _dirty = true; bool _dirty = true;
@@ -52,7 +52,7 @@ namespace IsoTools {
[SerializeField] [SerializeField]
public float _tileSize = 32.0f; public float _tileSize = 32.0f;
/// <summary>Isometric tile size.</summary> /// <summary>Isometric tile size.</summary>
public float TileSize { public float tileSize {
get { return _tileSize; } get { return _tileSize; }
set { set {
_tileSize = Mathf.Max(value, Mathf.Epsilon); _tileSize = Mathf.Max(value, Mathf.Epsilon);
@@ -63,7 +63,7 @@ namespace IsoTools {
[SerializeField] [SerializeField]
public float _minDepth = 0.0f; public float _minDepth = 0.0f;
/// <summary>Min sorting depth value.</summary> /// <summary>Min sorting depth value.</summary>
public float MinDepth { public float minDepth {
get { return _minDepth; } get { return _minDepth; }
set { set {
_minDepth = value; _minDepth = value;
@@ -74,7 +74,7 @@ namespace IsoTools {
[SerializeField] [SerializeField]
public float _maxDepth = 100.0f; public float _maxDepth = 100.0f;
/// <summary>Max sorting depth value.</summary> /// <summary>Max sorting depth value.</summary>
public float MaxDepth { public float maxDepth {
get { return _maxDepth; } get { return _maxDepth; }
set { set {
_maxDepth = value; _maxDepth = value;
@@ -114,7 +114,7 @@ namespace IsoTools {
public Vector2 IsoToScreen(Vector3 pos) { public Vector2 IsoToScreen(Vector3 pos) {
return new Vector2( return new Vector2(
(pos.x - pos.y), (pos.x - pos.y),
(pos.x + pos.y) * 0.5f + pos.z) * TileSize; (pos.x + pos.y) * 0.5f + pos.z) * tileSize;
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@@ -128,7 +128,7 @@ namespace IsoTools {
return new Vector3( return new Vector3(
(pos.x * 0.5f + pos.y), (pos.x * 0.5f + pos.y),
(pos.y - pos.x * 0.5f), (pos.y - pos.x * 0.5f),
0.0f) / TileSize; 0.0f) / tileSize;
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@@ -141,7 +141,7 @@ namespace IsoTools {
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
public Vector3 ScreenToIso(Vector2 pos, float iso_z) { public Vector3 ScreenToIso(Vector2 pos, float iso_z) {
return IsoUtils.Vec3ChangeZ( return IsoUtils.Vec3ChangeZ(
ScreenToIso(new Vector2(pos.x, pos.y - iso_z * TileSize)), ScreenToIso(new Vector2(pos.x, pos.y - iso_z * tileSize)),
iso_z); iso_z);
} }
@@ -289,7 +289,7 @@ namespace IsoTools {
var objsSum = 0; var objsSum = 0;
foreach ( var obj in _visibles ) { foreach ( var obj in _visibles ) {
++objsSum; ++objsSum;
_objsSectorSize += Mathf.Max(obj.Size.x, obj.Size.y, obj.Size.z); _objsSectorSize += IsoUtils.Vec3MaxF(obj.size);
} }
_objsSectorSize = Mathf.Round(Mathf.Max(3.0f, _objsSectorSize / objsSum)); _objsSectorSize = Mathf.Round(Mathf.Max(3.0f, _objsSectorSize / objsSum));
} }
@@ -299,9 +299,9 @@ namespace IsoTools {
_objsMinNumPos = Vector3.zero; _objsMinNumPos = Vector3.zero;
_objsMaxNumPos = Vector3.one; _objsMaxNumPos = Vector3.one;
foreach ( var obj in _visibles ) { foreach ( var obj in _visibles ) {
var max_size = IsoUtils.Vec3Max(Vector3.one, obj.Size); var max_size = IsoUtils.Vec3Max(Vector3.one, obj.size);
var min_npos = IsoUtils.Vec3DivFloor(obj.Position, _objsSectorSize); var min_npos = IsoUtils.Vec3DivFloor(obj.position, _objsSectorSize);
var max_npos = IsoUtils.Vec3DivCeil(obj.Position + max_size, _objsSectorSize); var max_npos = IsoUtils.Vec3DivCeil(obj.position + max_size, _objsSectorSize);
_objsMinNumPos = IsoUtils.Vec3Min(_objsMinNumPos, min_npos); _objsMinNumPos = IsoUtils.Vec3Min(_objsMinNumPos, min_npos);
_objsMaxNumPos = IsoUtils.Vec3Max(_objsMaxNumPos, max_npos); _objsMaxNumPos = IsoUtils.Vec3Max(_objsMaxNumPos, max_npos);
_objects.Add(new ObjectInfo(_objects.Count, obj, min_npos, max_npos)); _objects.Add(new ObjectInfo(_objects.Count, obj, min_npos, max_npos));
@@ -316,12 +316,12 @@ namespace IsoTools {
_sectors.Add(new SectorInfo()); _sectors.Add(new SectorInfo());
} }
foreach ( var obj in _objects ) { foreach ( var obj in _objects ) {
obj.MinSector -= _objsMinNumPos; obj.minSector -= _objsMinNumPos;
obj.MaxSector -= _objsMinNumPos; obj.maxSector -= _objsMinNumPos;
IsoUtils.LookUpCube(obj.MinSector, obj.MaxSector, p => { IsoUtils.LookUpCube(obj.minSector, obj.maxSector, p => {
var sector = FindSector(p); var sector = FindSector(p);
if ( sector != null ) { if ( sector != null ) {
sector.Objects.Add(obj.Index); sector.objects.Add(obj.index);
} }
}); });
} }
@@ -331,14 +331,14 @@ namespace IsoTools {
_depends.Clear(); _depends.Clear();
foreach ( var obj_a in _objects ) { foreach ( var obj_a in _objects ) {
obj_a.Init(_depends.Count); obj_a.Init(_depends.Count);
var obj_ao = obj_a.IsoObject; var obj_ao = obj_a.isoObject;
IsoUtils.LookUpCube(obj_a.MinSector, obj_a.MaxSector, num_pos => { IsoUtils.LookUpCube(obj_a.minSector, obj_a.maxSector, num_pos => {
LookUpSectorDepends(num_pos, sec => { LookUpSectorDepends(num_pos, sec => {
foreach ( var obj_bi in sec.Objects ) { foreach ( var obj_bi in sec.objects ) {
var obj_bo = _objects[obj_bi].IsoObject; 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) ) { if ( obj_ao != obj_bo && IsDepends(obj_ao.position, obj_ao.size, obj_bo.position, obj_bo.size) ) {
_depends.Add(obj_bi); _depends.Add(obj_bi);
++obj_a.EndDepend; ++obj_a.endDepend;
} }
} }
}); });
@@ -347,7 +347,7 @@ namespace IsoTools {
} }
void PlaceAllObjects() { void PlaceAllObjects() {
var depth = MinDepth; var depth = minDepth;
foreach ( var info in _objects ) { foreach ( var info in _objects ) {
depth = PlaceObject(info, depth); depth = PlaceObject(info, depth);
} }
@@ -362,17 +362,17 @@ namespace IsoTools {
} }
float PlaceObject(ObjectInfo info, float depth) { float PlaceObject(ObjectInfo info, float depth) {
if ( info.Visited ) { if ( info.visited ) {
return depth; return depth;
} }
info.Visited = true; info.visited = true;
for ( var i = info.BeginDepend; i < info.EndDepend && i < _depends.Count; ++i ) { for ( var i = info.beginDepend; i < info.endDepend && i < _depends.Count; ++i ) {
var obj_index = _depends[i]; var obj_index = _depends[i];
var obj = _objects[obj_index]; var obj = _objects[obj_index];
depth = PlaceObject(obj, depth); depth = PlaceObject(obj, depth);
} }
PlaceObject(info.IsoObject, depth); PlaceObject(info.isoObject, depth);
return depth + (MaxDepth - MinDepth) / _objects.Count; return depth + (maxDepth - minDepth) / _objects.Count;
} }
void StepSort() { void StepSort() {
@@ -407,15 +407,15 @@ namespace IsoTools {
#if UNITY_EDITOR #if UNITY_EDITOR
void Reset() { void Reset() {
TileSize = 32.0f; tileSize = 32.0f;
MinDepth = 0.0f; minDepth = 0.0f;
MaxDepth = 100.0f; maxDepth = 100.0f;
} }
void OnValidate() { void OnValidate() {
TileSize = _tileSize; tileSize = _tileSize;
MinDepth = _minDepth; minDepth = _minDepth;
MaxDepth = _maxDepth; maxDepth = _maxDepth;
} }
void OnRenderObject() { void OnRenderObject() {