mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-13 06:59:46 +07:00
physics wip
This commit is contained in:
@@ -46,9 +46,8 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\IsoTools\Editor\IsoAlignmentWindow.cs" />
|
||||
<Compile Include="Assets\IsoTools\Editor\IsoEditorWindow.cs" />
|
||||
<Compile Include="Assets\IsoTools\Editor\IsoObjectEditor.cs" />
|
||||
<Compile Include="Assets\IsoTools\Editor\IsoRigidbodyEditor.cs" />
|
||||
<Reference Include="UnityEngine.UI">
|
||||
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>
|
||||
</Reference>
|
||||
|
||||
@@ -46,9 +46,8 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\IsoTools\Editor\IsoAlignmentWindow.cs" />
|
||||
<Compile Include="Assets\IsoTools\Editor\IsoEditorWindow.cs" />
|
||||
<Compile Include="Assets\IsoTools\Editor\IsoObjectEditor.cs" />
|
||||
<Compile Include="Assets\IsoTools\Editor\IsoRigidbodyEditor.cs" />
|
||||
<Reference Include="UnityEngine.UI">
|
||||
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>
|
||||
</Reference>
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\IsoTools\Examples\Scripts\CircleFlyCamera.cs" />
|
||||
<Compile Include="Assets\IsoTools\Examples\Scripts\CircleFly.cs" />
|
||||
<Compile Include="Assets\IsoTools\Examples\Scripts\IsoAutoController.cs" />
|
||||
<Compile Include="Assets\IsoTools\Examples\Scripts\IsoController.cs" />
|
||||
<Compile Include="Assets\IsoTools\Scripts\IsoObject.cs" />
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\IsoTools\Examples\Scripts\CircleFlyCamera.cs" />
|
||||
<Compile Include="Assets\IsoTools\Examples\Scripts\CircleFly.cs" />
|
||||
<Compile Include="Assets\IsoTools\Examples\Scripts\IsoAutoController.cs" />
|
||||
<Compile Include="Assets\IsoTools\Examples\Scripts\IsoController.cs" />
|
||||
<Compile Include="Assets\IsoTools\Scripts\IsoObject.cs" />
|
||||
|
||||
@@ -3,9 +3,10 @@ using UnityEditor;
|
||||
using System.Linq;
|
||||
|
||||
namespace IsoTools {
|
||||
public class IsoAlignmentWindow : EditorWindow {
|
||||
public class IsoEditorWindow : EditorWindow {
|
||||
|
||||
public static bool Alignment { get; private set; }
|
||||
public static bool Alignment { get; private set; }
|
||||
public static bool ShowBounds { get; private set; }
|
||||
|
||||
void AlignmentSelection() {
|
||||
var iso_objects = Selection.gameObjects
|
||||
@@ -17,15 +18,16 @@ namespace IsoTools {
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("IsoTools/Alignment")]
|
||||
[MenuItem("IsoTools/IsoEditor")]
|
||||
static void Init() {
|
||||
var window = EditorWindow.GetWindow<IsoAlignmentWindow>();
|
||||
window.title = "IsoAlignment";
|
||||
var window = EditorWindow.GetWindow<IsoEditorWindow>();
|
||||
window.title = "IsoEditor";
|
||||
window.Show();
|
||||
}
|
||||
|
||||
void OnGUI() {
|
||||
GUILayout.Space(5);
|
||||
ShowBounds = EditorGUILayout.Toggle("Show bounds", ShowBounds);
|
||||
Alignment = EditorGUILayout.Toggle("Auto alignment", Alignment);
|
||||
if ( GUILayout.Button("Alignment selection objects") || Alignment ) {
|
||||
AlignmentSelection();
|
||||
@@ -27,7 +27,7 @@ namespace IsoTools {
|
||||
}
|
||||
|
||||
void AlignmentIsoObject(IsoObject iso_object) {
|
||||
if ( IsoAlignmentWindow.Alignment ) {
|
||||
if ( IsoEditorWindow.Alignment ) {
|
||||
iso_object.Position = iso_object.TilePosition;
|
||||
iso_object.FixTransform();
|
||||
}
|
||||
@@ -111,6 +111,47 @@ namespace IsoTools {
|
||||
}
|
||||
}
|
||||
|
||||
void DrawTop(Vector3 pos, Vector3 size) {
|
||||
var iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
||||
if ( iso_world ) {
|
||||
var points = new Vector3[]{
|
||||
iso_world.IsoToScreen(pos),
|
||||
iso_world.IsoToScreen(pos + IsoUtils.Vec3FromX(size.x)),
|
||||
iso_world.IsoToScreen(pos + IsoUtils.Vec3FromXY(size.x, size.y)),
|
||||
iso_world.IsoToScreen(pos + IsoUtils.Vec3FromY(size.y)),
|
||||
iso_world.IsoToScreen(pos)
|
||||
};
|
||||
Handles.DrawPolyLine(points);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawVert(Vector3 pos, Vector3 size) {
|
||||
var iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
||||
if ( iso_world ) {
|
||||
Handles.DrawLine(
|
||||
iso_world.IsoToScreen(pos),
|
||||
iso_world.IsoToScreen(pos + IsoUtils.Vec3FromZ(size.z)));
|
||||
}
|
||||
}
|
||||
|
||||
void DrawCube(Vector3 pos, Vector3 size) {
|
||||
Handles.color = Color.green;
|
||||
DrawTop (pos - IsoUtils.Vec3FromZ(0.5f), size);
|
||||
DrawTop (pos + IsoUtils.Vec3FromZ(size.z - 0.5f), size);
|
||||
DrawVert(pos - IsoUtils.Vec3FromZ(0.5f), size);
|
||||
DrawVert(pos - IsoUtils.Vec3FromZ(0.5f) + IsoUtils.Vec3FromX(size.x), size);
|
||||
DrawVert(pos - IsoUtils.Vec3FromZ(0.5f) + IsoUtils.Vec3FromY(size.y), size);
|
||||
}
|
||||
|
||||
void DrawTargetBounds() {
|
||||
if ( IsoEditorWindow.ShowBounds ) {
|
||||
var iso_object = target as IsoObject;
|
||||
if ( iso_object ) {
|
||||
DrawCube(iso_object.Position, iso_object.Size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable() {
|
||||
GrabPositions();
|
||||
}
|
||||
@@ -129,6 +170,7 @@ namespace IsoTools {
|
||||
} else {
|
||||
Tools.hidden = false;
|
||||
}
|
||||
DrawTargetBounds();
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace IsoTools {
|
||||
[CustomEditor(typeof(IsoRigidbody)), CanEditMultipleObjects]
|
||||
class IsoRigidbodyEditor : Editor {
|
||||
void DrawTop(Vector3 pos, Vector3 size) {
|
||||
var iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
||||
if ( iso_world ) {
|
||||
var points = new Vector3[]{
|
||||
iso_world.IsoToScreen(pos),
|
||||
iso_world.IsoToScreen(pos + IsoUtils.Vec3FromX(size.x)),
|
||||
iso_world.IsoToScreen(pos + IsoUtils.Vec3FromXY(size.x, size.y)),
|
||||
iso_world.IsoToScreen(pos + IsoUtils.Vec3FromY(size.y)),
|
||||
iso_world.IsoToScreen(pos)
|
||||
};
|
||||
Handles.DrawPolyLine(points);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawVert(Vector3 pos, Vector3 size) {
|
||||
var iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
||||
if ( iso_world ) {
|
||||
Handles.DrawLine(
|
||||
iso_world.IsoToScreen(pos),
|
||||
iso_world.IsoToScreen(pos + IsoUtils.Vec3FromZ(size.z)));
|
||||
}
|
||||
}
|
||||
|
||||
void DrawCube(Vector3 pos, Vector3 size) {
|
||||
Handles.color = Color.green;
|
||||
DrawTop (pos - IsoUtils.Vec3FromZ(0.5f), size);
|
||||
DrawTop (pos + IsoUtils.Vec3FromZ(size.z - 0.5f), size);
|
||||
DrawVert(pos - IsoUtils.Vec3FromZ(0.5f), size);
|
||||
DrawVert(pos - IsoUtils.Vec3FromZ(0.5f) + IsoUtils.Vec3FromX(size.x), size);
|
||||
DrawVert(pos - IsoUtils.Vec3FromZ(0.5f) + IsoUtils.Vec3FromY(size.y), size);
|
||||
}
|
||||
|
||||
void OnSceneGUI() {
|
||||
var iso_rigidbody = target as IsoRigidbody;
|
||||
var iso_object = iso_rigidbody.GetComponent<IsoObject>();
|
||||
if ( iso_object ) {
|
||||
DrawCube(iso_object.Position, iso_object.Size);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace IsoTools
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 80c086762f3ba4f369819009dd52e46f
|
||||
timeCreated: 1431880115
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1810
Assets/IsoTools/Examples/Scenes/Scene6.unity
Normal file
1810
Assets/IsoTools/Examples/Scenes/Scene6.unity
Normal file
File diff suppressed because it is too large
Load Diff
8
Assets/IsoTools/Examples/Scenes/Scene6.unity.meta
Normal file
8
Assets/IsoTools/Examples/Scenes/Scene6.unity.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a36e5b75dcb974aa095d2b0f8926cbb5
|
||||
timeCreated: 1433267030
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
Assets/IsoTools/Examples/Scripts/CircleFly.cs
Normal file
25
Assets/IsoTools/Examples/Scripts/CircleFly.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace IsoTools { namespace Examples {
|
||||
public class CircleFly : MonoBehaviour {
|
||||
public float FlyRadius = 150.0f;
|
||||
public float FlySpeed = 1.0f;
|
||||
|
||||
Vector3 _start_pos;
|
||||
float _fly_timer;
|
||||
|
||||
void Start() {
|
||||
_start_pos = transform.position;
|
||||
_fly_timer = 0.0f;
|
||||
}
|
||||
|
||||
void Update () {
|
||||
_fly_timer += FlySpeed * Time.deltaTime;
|
||||
transform.position = new Vector3(
|
||||
_start_pos.x + Mathf.Cos(_fly_timer) * FlyRadius,
|
||||
_start_pos.y + Mathf.Sin(_fly_timer) * FlyRadius,
|
||||
_start_pos.z);
|
||||
}
|
||||
}
|
||||
}} // namespace IsoTools::Examples
|
||||
@@ -1,24 +0,0 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class CircleFlyCamera : MonoBehaviour {
|
||||
|
||||
public float FlyRadius = 150.0f;
|
||||
public float FlySpeed = 1.0f;
|
||||
|
||||
Vector3 _start_pos;
|
||||
float _fly_timer;
|
||||
|
||||
void Start() {
|
||||
_start_pos = transform.position;
|
||||
_fly_timer = 0.0f;
|
||||
}
|
||||
|
||||
void Update () {
|
||||
_fly_timer += FlySpeed * Time.deltaTime;
|
||||
transform.position = new Vector3(
|
||||
_start_pos.x + Mathf.Cos(_fly_timer) * FlyRadius,
|
||||
_start_pos.y + Mathf.Sin(_fly_timer) * FlyRadius,
|
||||
_start_pos.z);
|
||||
}
|
||||
}
|
||||
@@ -2,32 +2,32 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace IsoTools { namespace Examples {
|
||||
public class IsoAutoController : MonoBehaviour {
|
||||
public float StepTicks = 0.5f;
|
||||
public float StepRndTicks = 0.5f;
|
||||
public class IsoAutoController : MonoBehaviour {
|
||||
public float StepTicks = 0.5f;
|
||||
public float StepRndTicks = 0.5f;
|
||||
|
||||
void Start() {
|
||||
StartCoroutine("Move");
|
||||
}
|
||||
void Start() {
|
||||
StartCoroutine("Move");
|
||||
}
|
||||
|
||||
WaitForSeconds RndWait() {
|
||||
return new WaitForSeconds(StepTicks + Random.Range(0.0f, StepRndTicks));
|
||||
}
|
||||
WaitForSeconds RndWait() {
|
||||
return new WaitForSeconds(StepTicks + Random.Range(0.0f, StepRndTicks));
|
||||
}
|
||||
|
||||
IEnumerator Move() {
|
||||
var iso_object = GetComponent<IsoObject>();
|
||||
if ( iso_object ) {
|
||||
for (;;) {
|
||||
yield return RndWait();
|
||||
iso_object.Position += new Vector3(1, 0, 0);
|
||||
yield return RndWait();
|
||||
iso_object.Position += new Vector3(0, 1, 0);
|
||||
yield return RndWait();
|
||||
iso_object.Position += new Vector3(-1, 0, 0);
|
||||
yield return RndWait();
|
||||
iso_object.Position += new Vector3(0, -1, 0);
|
||||
IEnumerator Move() {
|
||||
var iso_object = GetComponent<IsoObject>();
|
||||
if ( iso_object ) {
|
||||
for (;;) {
|
||||
yield return RndWait();
|
||||
iso_object.Position += new Vector3(1, 0, 0);
|
||||
yield return RndWait();
|
||||
iso_object.Position += new Vector3(0, 1, 0);
|
||||
yield return RndWait();
|
||||
iso_object.Position += new Vector3(-1, 0, 0);
|
||||
yield return RndWait();
|
||||
iso_object.Position += new Vector3(0, -1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}} // namespace IsoTools::Examples
|
||||
@@ -1,30 +1,39 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace IsoTools { namespace Examples {
|
||||
public class IsoController : MonoBehaviour {
|
||||
void Update () {
|
||||
var iso_object = gameObject.GetComponent<IsoObject>();
|
||||
if ( iso_object ) {
|
||||
if ( Input.GetKeyUp(KeyCode.LeftArrow) ) {
|
||||
iso_object.Position += new Vector3(-1, 0, 0);
|
||||
namespace IsoTools {
|
||||
namespace Examples {
|
||||
public class IsoController : MonoBehaviour {
|
||||
void MoveIsoObject(Vector3 dir) {
|
||||
var iso_object = GetComponent<IsoObject>();
|
||||
var iso_rigidbody = GetComponent<IsoRigidbody>();
|
||||
if ( iso_rigidbody ) {
|
||||
iso_rigidbody.Rigidbody.velocity = dir;
|
||||
}
|
||||
else if ( iso_object ) {
|
||||
iso_object.Position += dir * Time.deltaTime;
|
||||
}
|
||||
}
|
||||
if ( Input.GetKeyUp(KeyCode.RightArrow) ) {
|
||||
iso_object.Position += new Vector3(1, 0, 0);
|
||||
}
|
||||
if ( Input.GetKeyUp(KeyCode.DownArrow) ) {
|
||||
iso_object.Position += new Vector3(0, -1, 0);
|
||||
}
|
||||
if ( Input.GetKeyUp(KeyCode.UpArrow) ) {
|
||||
iso_object.Position += new Vector3(0, 1, 0);
|
||||
}
|
||||
if ( Input.GetKeyUp(KeyCode.A) ) {
|
||||
iso_object.Position += new Vector3(0, 0, 1);
|
||||
}
|
||||
if ( Input.GetKeyUp(KeyCode.Z) ) {
|
||||
iso_object.Position += new Vector3(0, 0, -1);
|
||||
void Update () {
|
||||
if ( Input.GetKey(KeyCode.LeftArrow) ) {
|
||||
MoveIsoObject(new Vector3(-1, 0, 0));
|
||||
}
|
||||
if ( Input.GetKey(KeyCode.RightArrow) ) {
|
||||
MoveIsoObject(new Vector3(1, 0, 0));
|
||||
}
|
||||
if ( Input.GetKey(KeyCode.DownArrow) ) {
|
||||
MoveIsoObject(new Vector3(0, -1, 0));
|
||||
}
|
||||
if ( Input.GetKey(KeyCode.UpArrow) ) {
|
||||
MoveIsoObject(new Vector3(0, 1, 0));
|
||||
}
|
||||
if ( Input.GetKey(KeyCode.A) ) {
|
||||
MoveIsoObject(new Vector3(0, 0, 1));
|
||||
}
|
||||
if ( Input.GetKey(KeyCode.Z) ) {
|
||||
MoveIsoObject(new Vector3(0, 0, -1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}} // namespace IsoTools::Examples
|
||||
}
|
||||
@@ -167,21 +167,21 @@ namespace IsoTools {
|
||||
//
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
IsoWorld _iso_world = null;
|
||||
IsoWorld _isoWorld = null;
|
||||
public IsoWorld IsoWorld {
|
||||
get {
|
||||
if ( !_iso_world ) {
|
||||
_iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
||||
if ( !_isoWorld ) {
|
||||
_isoWorld = GameObject.FindObjectOfType<IsoWorld>();
|
||||
}
|
||||
if ( !_iso_world ) {
|
||||
if ( !_isoWorld ) {
|
||||
throw new UnityException("IsoObject. IsoWorld not found!");
|
||||
}
|
||||
return _iso_world;
|
||||
return _isoWorld;
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetIsoWorld() {
|
||||
_iso_world = null;
|
||||
_isoWorld = null;
|
||||
}
|
||||
|
||||
public void FixTransform() {
|
||||
@@ -228,6 +228,7 @@ namespace IsoTools {
|
||||
MartDirtyIsoWorld();
|
||||
}
|
||||
|
||||
//TODO: now working for child sprites
|
||||
void OnBecameVisible() {
|
||||
MartDirtyIsoWorld();
|
||||
}
|
||||
@@ -238,8 +239,12 @@ namespace IsoTools {
|
||||
if ( !IsoUtils.Vec2Approximately(_lastTransform, transform.position) ) {
|
||||
FixIsoPosition();
|
||||
}
|
||||
if ( _lastPosition != _position ) Position = _position;
|
||||
if ( _lastSize != _size ) Size = _size;
|
||||
if ( !IsoUtils.Vec3Approximately(_lastPosition, _position) ) {
|
||||
Position = _position;
|
||||
}
|
||||
if ( !IsoUtils.Vec3Approximately(_lastSize, _size) ) {
|
||||
Size = _size;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -14,42 +14,88 @@ namespace IsoTools {
|
||||
public CollisionDetectionMode CollisionMode = CollisionDetectionMode.Discrete;
|
||||
public PhysicMaterial PhysicMaterial = null;
|
||||
|
||||
IsoObject _iso_object = null;
|
||||
GameObject _fake_object = null;
|
||||
Rigidbody _rigid_body = null;
|
||||
BoxCollider _box_collider = null;
|
||||
IsoObject _isoObject = null;
|
||||
GameObject _fakeObject = null;
|
||||
Vector3 _lastPosition = Vector3.zero;
|
||||
|
||||
public IsoObject IsoObject {
|
||||
get {
|
||||
if ( !_isoObject ) {
|
||||
_isoObject = GetComponent<IsoObject>();
|
||||
}
|
||||
if ( !_isoObject ) {
|
||||
throw new UnityException("IsoRigidbody. IsoObject not found!");
|
||||
}
|
||||
return _isoObject;
|
||||
}
|
||||
}
|
||||
|
||||
public GameObject FakeGameObject {
|
||||
get { return _fakeObject; }
|
||||
}
|
||||
|
||||
public Rigidbody Rigidbody {
|
||||
get { return _rigid_body; }
|
||||
get { return FakeGameObject.GetComponent<Rigidbody>(); }
|
||||
}
|
||||
|
||||
void AddBoxCollider() {
|
||||
var collider = FakeGameObject.AddComponent<BoxCollider>();
|
||||
collider.center = IsoObject.Size / 2.0f;
|
||||
collider.size = IsoObject.Size;
|
||||
collider.isTrigger = IsTrigger;
|
||||
collider.material = PhysicMaterial;
|
||||
}
|
||||
|
||||
void AddHelperSphere(Vector3 pos, float radius) {
|
||||
var collider = FakeGameObject.AddComponent<SphereCollider>();
|
||||
collider.center = pos;
|
||||
collider.radius = radius;
|
||||
collider.isTrigger = IsTrigger;
|
||||
collider.material = PhysicMaterial;
|
||||
}
|
||||
|
||||
void AddHelperSpheres() {
|
||||
var radius = 0.1f;
|
||||
var rdelta = radius * 0.1f;
|
||||
var size = IsoObject.Size;
|
||||
if ( size.x > radius && size.y > radius && size.z > radius ) {
|
||||
AddHelperSphere(new Vector3(radius - rdelta , radius - rdelta , radius - rdelta ), radius);
|
||||
AddHelperSphere(new Vector3(size.x - radius + rdelta, radius - rdelta , radius - rdelta ), radius);
|
||||
AddHelperSphere(new Vector3(radius - rdelta , size.y - radius + rdelta, radius - rdelta ), radius);
|
||||
AddHelperSphere(new Vector3(size.x - radius + rdelta, size.y - radius + rdelta, radius - rdelta ), radius);
|
||||
AddHelperSphere(new Vector3(radius - rdelta , radius - rdelta , size.z - radius + rdelta), radius);
|
||||
AddHelperSphere(new Vector3(size.x - radius + rdelta, radius - rdelta , size.z - radius + rdelta), radius);
|
||||
AddHelperSphere(new Vector3(radius - rdelta , size.y - radius + rdelta, size.z - radius + rdelta), radius);
|
||||
AddHelperSphere(new Vector3(size.x - radius + rdelta, size.y - radius + rdelta, size.z - radius + rdelta), radius);
|
||||
}
|
||||
}
|
||||
|
||||
void Awake() {
|
||||
_iso_object = GetComponent<IsoObject>();
|
||||
if ( !_iso_object ) {
|
||||
throw new UnityException("IsoRigidbody. IsoObject not found!");
|
||||
}
|
||||
_fake_object = new GameObject();
|
||||
_fake_object.name = "_Fake" + gameObject.name;
|
||||
_fakeObject = new GameObject();
|
||||
FakeGameObject.name = "_Fake" + gameObject.name;
|
||||
FakeGameObject.hideFlags = HideFlags.HideInHierarchy;
|
||||
|
||||
_rigid_body = _fake_object.AddComponent<Rigidbody>();
|
||||
_rigid_body.freezeRotation = true;
|
||||
_rigid_body.isKinematic = IsKinematic;
|
||||
_rigid_body.interpolation = Interpolation;
|
||||
_rigid_body.collisionDetectionMode = CollisionMode;
|
||||
var rigidbody = FakeGameObject.AddComponent<Rigidbody>();
|
||||
rigidbody.freezeRotation = true;
|
||||
rigidbody.isKinematic = IsKinematic;
|
||||
rigidbody.interpolation = Interpolation;
|
||||
rigidbody.collisionDetectionMode = CollisionMode;
|
||||
|
||||
_box_collider = _fake_object.AddComponent<BoxCollider>();
|
||||
_box_collider.center = IsoUtils.Vec3SwapYZ(_iso_object.Size / 2.0f);
|
||||
_box_collider.size = IsoUtils.Vec3SwapYZ(_iso_object.Size);
|
||||
_box_collider.isTrigger = IsTrigger;
|
||||
_box_collider.material = PhysicMaterial;
|
||||
AddBoxCollider();
|
||||
AddHelperSpheres();
|
||||
|
||||
_fake_object.transform.position = IsoUtils.Vec3SwapYZ(_iso_object.Position);
|
||||
_lastPosition = IsoObject.Position;
|
||||
FakeGameObject.transform.position = IsoObject.Position;
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
if ( _iso_object ) {
|
||||
_iso_object.Position = IsoUtils.Vec3SwapYZ(_fake_object.transform.position);
|
||||
var fake_transform = FakeGameObject.transform;
|
||||
if ( !IsoUtils.Vec3Approximately(_lastPosition, IsoObject.Position) ) {
|
||||
fake_transform.position = IsoObject.Position;
|
||||
} else {
|
||||
IsoObject.Position = fake_transform.position;
|
||||
}
|
||||
_lastPosition = IsoObject.Position;
|
||||
}
|
||||
}
|
||||
} // namespace IsoTools
|
||||
@@ -21,28 +21,6 @@ namespace IsoTools {
|
||||
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); } }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
//
|
||||
// Swap
|
||||
//
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
public static Vector2 Vec2SwapXY(Vector2 v) {
|
||||
return new Vector2(v.y, v.x);
|
||||
}
|
||||
|
||||
public static Vector3 Vec3SwapXY(Vector3 v) {
|
||||
return new Vector3(v.y, v.x, v.z);
|
||||
}
|
||||
|
||||
public static Vector3 Vec3SwapYZ(Vector3 v) {
|
||||
return new Vector3(v.x, v.z, v.y);
|
||||
}
|
||||
|
||||
public static Vector3 Vec3SwapXZ(Vector3 v) {
|
||||
return new Vector3(v.z, v.y, v.x);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
//
|
||||
// Abs/Min/Max
|
||||
|
||||
@@ -3,13 +3,12 @@
|
||||
--- !u!55 &1
|
||||
PhysicsManager:
|
||||
m_ObjectHideFlags: 0
|
||||
m_Gravity: {x: 0, y: -9.81000042, z: 0}
|
||||
m_Gravity: {x: 0, y: 0, z: -9.81000042}
|
||||
m_DefaultMaterial: {fileID: 0}
|
||||
m_BounceThreshold: 2
|
||||
m_SleepVelocity: .150000006
|
||||
m_SleepAngularVelocity: .140000001
|
||||
m_MaxAngularVelocity: 7
|
||||
m_MinPenetrationForPenalty: .00999999978
|
||||
m_SleepThreshold: .00499999989
|
||||
m_DefaultContactOffset: .00999999978
|
||||
m_SolverIterationCount: 6
|
||||
m_RaycastsHitTriggers: 1
|
||||
m_EnableAdaptiveForce: 0
|
||||
m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
|
||||
|
||||
@@ -23,7 +23,7 @@ Global
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
StartupItem = Assembly-CSharp.csproj
|
||||
Policies = $0
|
||||
$0.TextStylePolicy = $1
|
||||
|
||||
@@ -23,7 +23,7 @@ Global
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
StartupItem = Assembly-CSharp.csproj
|
||||
Policies = $0
|
||||
$0.TextStylePolicy = $1
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
<Properties>
|
||||
<MonoDevelop.Ide.Workspace />
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Scripts/IsoWorld.cs">
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="MonoDevelop.Default" />
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Scripts/IsoRigidbody.cs">
|
||||
<Files>
|
||||
<File FileName="Assets/IsoTools/Scripts/IsoObject.cs" Line="242" Column="56" />
|
||||
<File FileName="Assets/IsoTools/Scripts/IsoWorld.cs" Line="266" Column="24" />
|
||||
<File FileName="Assets/IsoTools/Editor/IsoObjectEditor.cs" Line="1" Column="1" />
|
||||
<File FileName="Assets/IsoTools/Scripts/IsoRigidbody.cs" Line="22" Column="31" />
|
||||
<File FileName="Assets/IsoTools/Scripts/IsoObject.cs" Line="14" Column="12" />
|
||||
</Files>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
|
||||
Reference in New Issue
Block a user