mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-16 22:16:55 +07:00
physics wip
This commit is contained in:
@@ -46,9 +46,8 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<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\IsoObjectEditor.cs" />
|
||||||
<Compile Include="Assets\IsoTools\Editor\IsoRigidbodyEditor.cs" />
|
|
||||||
<Reference Include="UnityEngine.UI">
|
<Reference Include="UnityEngine.UI">
|
||||||
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>
|
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|||||||
@@ -46,9 +46,8 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<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\IsoObjectEditor.cs" />
|
||||||
<Compile Include="Assets\IsoTools\Editor\IsoRigidbodyEditor.cs" />
|
|
||||||
<Reference Include="UnityEngine.UI">
|
<Reference Include="UnityEngine.UI">
|
||||||
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>
|
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<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\IsoAutoController.cs" />
|
||||||
<Compile Include="Assets\IsoTools\Examples\Scripts\IsoController.cs" />
|
<Compile Include="Assets\IsoTools\Examples\Scripts\IsoController.cs" />
|
||||||
<Compile Include="Assets\IsoTools\Scripts\IsoObject.cs" />
|
<Compile Include="Assets\IsoTools\Scripts\IsoObject.cs" />
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<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\IsoAutoController.cs" />
|
||||||
<Compile Include="Assets\IsoTools\Examples\Scripts\IsoController.cs" />
|
<Compile Include="Assets\IsoTools\Examples\Scripts\IsoController.cs" />
|
||||||
<Compile Include="Assets\IsoTools\Scripts\IsoObject.cs" />
|
<Compile Include="Assets\IsoTools\Scripts\IsoObject.cs" />
|
||||||
|
|||||||
@@ -3,9 +3,10 @@ using UnityEditor;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace IsoTools {
|
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() {
|
void AlignmentSelection() {
|
||||||
var iso_objects = Selection.gameObjects
|
var iso_objects = Selection.gameObjects
|
||||||
@@ -17,15 +18,16 @@ namespace IsoTools {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[MenuItem("IsoTools/Alignment")]
|
[MenuItem("IsoTools/IsoEditor")]
|
||||||
static void Init() {
|
static void Init() {
|
||||||
var window = EditorWindow.GetWindow<IsoAlignmentWindow>();
|
var window = EditorWindow.GetWindow<IsoEditorWindow>();
|
||||||
window.title = "IsoAlignment";
|
window.title = "IsoEditor";
|
||||||
window.Show();
|
window.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnGUI() {
|
void OnGUI() {
|
||||||
GUILayout.Space(5);
|
GUILayout.Space(5);
|
||||||
|
ShowBounds = EditorGUILayout.Toggle("Show bounds", ShowBounds);
|
||||||
Alignment = EditorGUILayout.Toggle("Auto alignment", Alignment);
|
Alignment = EditorGUILayout.Toggle("Auto alignment", Alignment);
|
||||||
if ( GUILayout.Button("Alignment selection objects") || Alignment ) {
|
if ( GUILayout.Button("Alignment selection objects") || Alignment ) {
|
||||||
AlignmentSelection();
|
AlignmentSelection();
|
||||||
@@ -27,7 +27,7 @@ namespace IsoTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AlignmentIsoObject(IsoObject iso_object) {
|
void AlignmentIsoObject(IsoObject iso_object) {
|
||||||
if ( IsoAlignmentWindow.Alignment ) {
|
if ( IsoEditorWindow.Alignment ) {
|
||||||
iso_object.Position = iso_object.TilePosition;
|
iso_object.Position = iso_object.TilePosition;
|
||||||
iso_object.FixTransform();
|
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() {
|
void OnEnable() {
|
||||||
GrabPositions();
|
GrabPositions();
|
||||||
}
|
}
|
||||||
@@ -129,6 +170,7 @@ namespace IsoTools {
|
|||||||
} else {
|
} else {
|
||||||
Tools.hidden = false;
|
Tools.hidden = false;
|
||||||
}
|
}
|
||||||
|
DrawTargetBounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnInspectorGUI() {
|
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,7 +2,7 @@
|
|||||||
using System.Collections;
|
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;
|
||||||
|
|
||||||
@@ -29,5 +29,5 @@ public class IsoAutoController : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}} // namespace IsoTools::Examples
|
}} // namespace IsoTools::Examples
|
||||||
@@ -1,30 +1,39 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
||||||
namespace IsoTools { namespace Examples {
|
namespace IsoTools {
|
||||||
public class IsoController : MonoBehaviour {
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
void Update () {
|
void Update () {
|
||||||
var iso_object = gameObject.GetComponent<IsoObject>();
|
if ( Input.GetKey(KeyCode.LeftArrow) ) {
|
||||||
if ( iso_object ) {
|
MoveIsoObject(new Vector3(-1, 0, 0));
|
||||||
if ( Input.GetKeyUp(KeyCode.LeftArrow) ) {
|
|
||||||
iso_object.Position += new Vector3(-1, 0, 0);
|
|
||||||
}
|
}
|
||||||
if ( Input.GetKeyUp(KeyCode.RightArrow) ) {
|
if ( Input.GetKey(KeyCode.RightArrow) ) {
|
||||||
iso_object.Position += new Vector3(1, 0, 0);
|
MoveIsoObject(new Vector3(1, 0, 0));
|
||||||
}
|
}
|
||||||
if ( Input.GetKeyUp(KeyCode.DownArrow) ) {
|
if ( Input.GetKey(KeyCode.DownArrow) ) {
|
||||||
iso_object.Position += new Vector3(0, -1, 0);
|
MoveIsoObject(new Vector3(0, -1, 0));
|
||||||
}
|
}
|
||||||
if ( Input.GetKeyUp(KeyCode.UpArrow) ) {
|
if ( Input.GetKey(KeyCode.UpArrow) ) {
|
||||||
iso_object.Position += new Vector3(0, 1, 0);
|
MoveIsoObject(new Vector3(0, 1, 0));
|
||||||
}
|
}
|
||||||
if ( Input.GetKeyUp(KeyCode.A) ) {
|
if ( Input.GetKey(KeyCode.A) ) {
|
||||||
iso_object.Position += new Vector3(0, 0, 1);
|
MoveIsoObject(new Vector3(0, 0, 1));
|
||||||
|
}
|
||||||
|
if ( Input.GetKey(KeyCode.Z) ) {
|
||||||
|
MoveIsoObject(new Vector3(0, 0, -1));
|
||||||
}
|
}
|
||||||
if ( Input.GetKeyUp(KeyCode.Z) ) {
|
|
||||||
iso_object.Position += new Vector3(0, 0, -1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}} // namespace IsoTools::Examples
|
|
||||||
@@ -167,21 +167,21 @@ namespace IsoTools {
|
|||||||
//
|
//
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
IsoWorld _iso_world = null;
|
IsoWorld _isoWorld = null;
|
||||||
public IsoWorld IsoWorld {
|
public IsoWorld IsoWorld {
|
||||||
get {
|
get {
|
||||||
if ( !_iso_world ) {
|
if ( !_isoWorld ) {
|
||||||
_iso_world = GameObject.FindObjectOfType<IsoWorld>();
|
_isoWorld = GameObject.FindObjectOfType<IsoWorld>();
|
||||||
}
|
}
|
||||||
if ( !_iso_world ) {
|
if ( !_isoWorld ) {
|
||||||
throw new UnityException("IsoObject. IsoWorld not found!");
|
throw new UnityException("IsoObject. IsoWorld not found!");
|
||||||
}
|
}
|
||||||
return _iso_world;
|
return _isoWorld;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResetIsoWorld() {
|
public void ResetIsoWorld() {
|
||||||
_iso_world = null;
|
_isoWorld = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FixTransform() {
|
public void FixTransform() {
|
||||||
@@ -228,6 +228,7 @@ namespace IsoTools {
|
|||||||
MartDirtyIsoWorld();
|
MartDirtyIsoWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: now working for child sprites
|
||||||
void OnBecameVisible() {
|
void OnBecameVisible() {
|
||||||
MartDirtyIsoWorld();
|
MartDirtyIsoWorld();
|
||||||
}
|
}
|
||||||
@@ -238,8 +239,12 @@ namespace IsoTools {
|
|||||||
if ( !IsoUtils.Vec2Approximately(_lastTransform, transform.position) ) {
|
if ( !IsoUtils.Vec2Approximately(_lastTransform, transform.position) ) {
|
||||||
FixIsoPosition();
|
FixIsoPosition();
|
||||||
}
|
}
|
||||||
if ( _lastPosition != _position ) Position = _position;
|
if ( !IsoUtils.Vec3Approximately(_lastPosition, _position) ) {
|
||||||
if ( _lastSize != _size ) Size = _size;
|
Position = _position;
|
||||||
|
}
|
||||||
|
if ( !IsoUtils.Vec3Approximately(_lastSize, _size) ) {
|
||||||
|
Size = _size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -14,42 +14,88 @@ namespace IsoTools {
|
|||||||
public CollisionDetectionMode CollisionMode = CollisionDetectionMode.Discrete;
|
public CollisionDetectionMode CollisionMode = CollisionDetectionMode.Discrete;
|
||||||
public PhysicMaterial PhysicMaterial = null;
|
public PhysicMaterial PhysicMaterial = null;
|
||||||
|
|
||||||
IsoObject _iso_object = null;
|
IsoObject _isoObject = null;
|
||||||
GameObject _fake_object = null;
|
GameObject _fakeObject = null;
|
||||||
Rigidbody _rigid_body = null;
|
Vector3 _lastPosition = Vector3.zero;
|
||||||
BoxCollider _box_collider = null;
|
|
||||||
|
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 {
|
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() {
|
void Awake() {
|
||||||
_iso_object = GetComponent<IsoObject>();
|
_fakeObject = new GameObject();
|
||||||
if ( !_iso_object ) {
|
FakeGameObject.name = "_Fake" + gameObject.name;
|
||||||
throw new UnityException("IsoRigidbody. IsoObject not found!");
|
FakeGameObject.hideFlags = HideFlags.HideInHierarchy;
|
||||||
}
|
|
||||||
_fake_object = new GameObject();
|
|
||||||
_fake_object.name = "_Fake" + gameObject.name;
|
|
||||||
|
|
||||||
_rigid_body = _fake_object.AddComponent<Rigidbody>();
|
var rigidbody = FakeGameObject.AddComponent<Rigidbody>();
|
||||||
_rigid_body.freezeRotation = true;
|
rigidbody.freezeRotation = true;
|
||||||
_rigid_body.isKinematic = IsKinematic;
|
rigidbody.isKinematic = IsKinematic;
|
||||||
_rigid_body.interpolation = Interpolation;
|
rigidbody.interpolation = Interpolation;
|
||||||
_rigid_body.collisionDetectionMode = CollisionMode;
|
rigidbody.collisionDetectionMode = CollisionMode;
|
||||||
|
|
||||||
_box_collider = _fake_object.AddComponent<BoxCollider>();
|
AddBoxCollider();
|
||||||
_box_collider.center = IsoUtils.Vec3SwapYZ(_iso_object.Size / 2.0f);
|
AddHelperSpheres();
|
||||||
_box_collider.size = IsoUtils.Vec3SwapYZ(_iso_object.Size);
|
|
||||||
_box_collider.isTrigger = IsTrigger;
|
|
||||||
_box_collider.material = PhysicMaterial;
|
|
||||||
|
|
||||||
_fake_object.transform.position = IsoUtils.Vec3SwapYZ(_iso_object.Position);
|
_lastPosition = IsoObject.Position;
|
||||||
|
FakeGameObject.transform.position = IsoObject.Position;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FixedUpdate() {
|
void FixedUpdate() {
|
||||||
if ( _iso_object ) {
|
var fake_transform = FakeGameObject.transform;
|
||||||
_iso_object.Position = IsoUtils.Vec3SwapYZ(_fake_object.transform.position);
|
if ( !IsoUtils.Vec3Approximately(_lastPosition, IsoObject.Position) ) {
|
||||||
|
fake_transform.position = IsoObject.Position;
|
||||||
|
} else {
|
||||||
|
IsoObject.Position = fake_transform.position;
|
||||||
}
|
}
|
||||||
|
_lastPosition = IsoObject.Position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace IsoTools
|
} // 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 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); } }
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// 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
|
// Abs/Min/Max
|
||||||
|
|||||||
@@ -3,13 +3,12 @@
|
|||||||
--- !u!55 &1
|
--- !u!55 &1
|
||||||
PhysicsManager:
|
PhysicsManager:
|
||||||
m_ObjectHideFlags: 0
|
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_DefaultMaterial: {fileID: 0}
|
||||||
m_BounceThreshold: 2
|
m_BounceThreshold: 2
|
||||||
m_SleepVelocity: .150000006
|
m_SleepThreshold: .00499999989
|
||||||
m_SleepAngularVelocity: .140000001
|
m_DefaultContactOffset: .00999999978
|
||||||
m_MaxAngularVelocity: 7
|
|
||||||
m_MinPenetrationForPenalty: .00999999978
|
|
||||||
m_SolverIterationCount: 6
|
m_SolverIterationCount: 6
|
||||||
m_RaycastsHitTriggers: 1
|
m_RaycastsHitTriggers: 1
|
||||||
|
m_EnableAdaptiveForce: 0
|
||||||
m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
|
m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
<Properties>
|
<Properties>
|
||||||
<MonoDevelop.Ide.Workspace />
|
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="MonoDevelop.Default" />
|
||||||
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Scripts/IsoWorld.cs">
|
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/IsoTools/Scripts/IsoRigidbody.cs">
|
||||||
<Files>
|
<Files>
|
||||||
<File FileName="Assets/IsoTools/Scripts/IsoObject.cs" Line="242" Column="56" />
|
<File FileName="Assets/IsoTools/Scripts/IsoRigidbody.cs" Line="22" Column="31" />
|
||||||
<File FileName="Assets/IsoTools/Scripts/IsoWorld.cs" Line="266" Column="24" />
|
<File FileName="Assets/IsoTools/Scripts/IsoObject.cs" Line="14" Column="12" />
|
||||||
<File FileName="Assets/IsoTools/Editor/IsoObjectEditor.cs" Line="1" Column="1" />
|
|
||||||
</Files>
|
</Files>
|
||||||
</MonoDevelop.Ide.Workbench>
|
</MonoDevelop.Ide.Workbench>
|
||||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||||
|
|||||||
Reference in New Issue
Block a user