7
7
using System . IO ;
8
8
using System . Linq ;
9
9
using System . Management . Instrumentation ;
10
+ using System . Reflection ;
10
11
using System . Runtime . InteropServices ;
11
12
using System . Text ;
12
13
using System . Threading . Tasks ;
@@ -79,11 +80,11 @@ public static void StartEdit()
79
80
SceneManager . sceneLoaded += InitEditor ;
80
81
SceneManager . LoadScene ( 6 ) ;
81
82
}
83
+ const float clickGizmoScaleFactor = 0.1f ;
82
84
static List < GameObject > clickGizmo ;
83
85
static Camera gizmoCamera ;
84
86
static Vector3 gizmoMovePos ;
85
87
static Vector3 gizmoMoveDirection = Vector3 . zero ;
86
- static float oldGizmoDistance ;
87
88
88
89
static string targetGroup = "" ;
89
90
static GUIex . Dropdown enemyGun ;
@@ -194,6 +195,7 @@ public static void Dialog(string caption, Action<string> action, string input =
194
195
195
196
private static int selObj = - 1 ;
196
197
private static float moveStep = 0.05f ;
198
+ private static bool aligned = false ;
197
199
private static Vector2 object_browser_scroll = new Vector2 ( 0 , 0 ) ;
198
200
199
201
public static void _ongui ( )
@@ -733,7 +735,7 @@ void recurence(string file)
733
735
wir [ ( int ) WindowId . LevelData ] = GUI . Window ( wid [ ( int ) WindowId . LevelData ] , wir [ ( int ) WindowId . LevelData ] , ( windowId ) => {
734
736
GUI . DragWindow ( new Rect ( 0 , 0 , 200 , 20 ) ) ;
735
737
GUI . Label ( new Rect ( 5 , 20 , 100 , 20 ) , "Grid Align" ) ;
736
- GUI . TextField ( new Rect ( 95 , 20 , 50 , 20 ) , "TBA" ) ;
738
+ gridAlign = float . Parse ( GUI . TextField ( new Rect ( 95 , 20 , 50 , 20 ) , gridAlign . ToString ( "0.00" ) ) ) ;
737
739
738
740
GUI . Label ( new Rect ( 5 , 40 , 100 , 20 ) , "Starting Gun" ) ;
739
741
startGunDD . Draw ( new Rect ( 95 , 40 , 100 , 20 ) ) ;
@@ -778,6 +780,7 @@ void recurence(string file)
778
780
public static void _onupdate ( )
779
781
{
780
782
if ( ! editorMode || Camera . main == null ) return ;
783
+ if ( levelName == "" ) return ;
781
784
782
785
if ( dg_screenshot && Input . GetKey ( KeyCode . Return ) )
783
786
{
@@ -841,10 +844,27 @@ public static void _onupdate()
841
844
842
845
if ( selObj != - 1 )
843
846
{
847
+ float distanceToGizmo = Vector3 . Distance ( Camera . main . transform . position , clickGizmo [ 0 ] . transform . position ) ;
844
848
clickGizmo [ 0 ] . transform . position = objects [ selObj ] . go . transform . position ;
845
849
clickGizmo [ 1 ] . transform . position = objects [ selObj ] . go . transform . position + new Vector3 ( 0 , 0 , 1 ) ;
850
+ clickGizmo [ 1 ] . transform . rotation = Quaternion . Euler ( 90 , 0 , 0 ) ;
846
851
clickGizmo [ 2 ] . transform . position = objects [ selObj ] . go . transform . position + new Vector3 ( 0 , 1 , 0 ) ;
852
+ clickGizmo [ 2 ] . transform . rotation = Quaternion . Euler ( 0 , 0 , 0 ) ;
847
853
clickGizmo [ 3 ] . transform . position = objects [ selObj ] . go . transform . position + new Vector3 ( 1 , 0 , 0 ) ;
854
+ clickGizmo [ 3 ] . transform . rotation = Quaternion . Euler ( 0 , 0 , 90 ) ;
855
+ if ( Input . GetKey ( KeyCode . LeftShift ) )
856
+ {
857
+ // rotate gizmo
858
+ void rotateX ( int x )
859
+ {
860
+ clickGizmo [ x ] . transform . RotateAround ( clickGizmo [ 0 ] . transform . position , new Vector3 ( 1 , 0 , 0 ) , objects [ selObj ] . aRotation . x ) ;
861
+ clickGizmo [ x ] . transform . RotateAround ( clickGizmo [ 0 ] . transform . position , new Vector3 ( 0 , 1 , 0 ) , objects [ selObj ] . aRotation . y ) ;
862
+ clickGizmo [ x ] . transform . RotateAround ( clickGizmo [ 0 ] . transform . position , new Vector3 ( 0 , 0 , 1 ) , objects [ selObj ] . aRotation . z ) ;
863
+ }
864
+ rotateX ( 1 ) ;
865
+ rotateX ( 2 ) ;
866
+ rotateX ( 3 ) ;
867
+ }
848
868
// check for hovering gizmo
849
869
850
870
Ray ray = gizmoCamera . ScreenPointToRay ( Input . mousePosition ) ;
@@ -885,24 +905,23 @@ public static void _onupdate()
885
905
{
886
906
gizmoMovePos = ray . GetPoint ( hit . distance ) ;
887
907
if ( clickGizmo [ 1 ] == hit . transform . gameObject )
888
- gizmoMoveDirection = new Vector3 ( 0 , 0 , 1 ) ;
908
+ gizmoMoveDirection = clickGizmo [ 1 ] . transform . up ;
889
909
if ( clickGizmo [ 2 ] == hit . transform . gameObject )
890
- gizmoMoveDirection = new Vector3 ( 0 , 1 , 0 ) ;
910
+ gizmoMoveDirection = clickGizmo [ 2 ] . transform . up ;
891
911
if ( clickGizmo [ 3 ] == hit . transform . gameObject )
892
- gizmoMoveDirection = new Vector3 ( 1 , 0 , 0 ) ;
912
+ gizmoMoveDirection = - clickGizmo [ 3 ] . transform . up ;
893
913
}
894
- oldGizmoDistance = hit . distance ;
895
914
}
896
915
if ( Input . GetMouseButton ( 0 ) && gizmoMoveDirection != Vector3 . zero )
897
916
{
898
- Vector3 delta = ray . GetPoint ( oldGizmoDistance ) - gizmoMovePos ;
899
- delta . Scale ( gizmoMoveDirection ) ;
917
+ Vector3 delta = gizmoMoveDirection * Vector3Extensions . DistanceOnDirection ( gizmoMovePos , ray . GetPoint ( distanceToGizmo ) , gizmoMoveDirection ) ;
900
918
objects [ selObj ] . aPosition += delta ;
901
- gizmoMovePos = ray . GetPoint ( oldGizmoDistance ) ;
919
+ gizmoMovePos = ray . GetPoint ( distanceToGizmo ) ;
902
920
}
903
921
if ( Input . GetMouseButtonUp ( 0 ) )
904
922
{
905
923
gizmoMoveDirection = Vector3 . zero ;
924
+ aligned = false ;
906
925
}
907
926
}
908
927
else
@@ -915,30 +934,27 @@ public static void _onupdate()
915
934
916
935
startPosition = objects [ 0 ] . aPosition ;
917
936
startOrientation = objects [ 0 ] . aRotation . y ;
918
-
919
- // update grid align
937
+
938
+ // grid align
920
939
if ( gridAlign != 0 )
921
940
{
922
- if ( gridAlign < 0 ) gridAlign = 0 ;
923
- foreach ( var obj in objects )
941
+ if ( gridAlign < 0 )
924
942
{
925
- Vector3 delta = obj . aPosition ;
926
- while ( delta . x >= gridAlign )
927
- delta . x -= gridAlign ;
928
- if ( 2 * delta . x / gridAlign >= 1 )
929
- delta . x = gridAlign - delta . x ;
930
-
931
- while ( delta . y >= gridAlign )
932
- delta . y -= gridAlign ;
933
- if ( 2 * delta . y / gridAlign >= 1 )
934
- delta . y = gridAlign - delta . y ;
935
-
936
- while ( delta . z >= gridAlign )
937
- delta . z -= gridAlign ;
938
- if ( 2 * delta . z / gridAlign >= 1 )
939
- delta . z = gridAlign - delta . z ;
940
-
941
- obj . aPosition -= delta ;
943
+ gridAlign = 0 ;
944
+ }
945
+ else
946
+ {
947
+ if ( ! aligned )
948
+ {
949
+ Loadson . Console . Log ( "Aligning objects" ) ;
950
+ foreach ( var obj in objects )
951
+ {
952
+ obj . aPosition += Vector3Extensions . Snap ( obj . aPosition , gridAlign ) - obj . aPosition ;
953
+ obj . aRotation += Vector3Extensions . Snap ( obj . aRotation , gridAlign ) - obj . aRotation ;
954
+ obj . aScale += Vector3Extensions . Snap ( obj . aScale , gridAlign ) - obj . aScale ;
955
+ }
956
+ aligned = true ;
957
+ }
942
958
}
943
959
}
944
960
}
@@ -1056,6 +1072,7 @@ private static void LoadLevel(string path)
1056
1072
globalPhysics = true ; ToggleGlobalPhysics ( ) ;
1057
1073
targetGroup = "" ;
1058
1074
selObj = - 1 ;
1075
+ aligned = false ;
1059
1076
}
1060
1077
1061
1078
private static IEnumerator identifyObject ( GameObject go )
0 commit comments