11/*
2- * Copyright (c) <2020> Side Effects Software Inc.
3- * All rights reserved.
4- *
5- * Redistribution and use in source and binary forms, with or without
6- * modification, are permitted provided that the following conditions are met:
7- *
8- * 1. Redistributions of source code must retain the above copyright notice,
9- * this list of conditions and the following disclaimer.
10- *
11- * 2. The name of Side Effects Software may not be used to endorse or
12- * promote products derived from this software without specific prior
13- * written permission.
14- *
15- * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE "AS IS" AND ANY EXPRESS
16- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
18- * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
19- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
21- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25- */
2+ * Copyright (c) <2020> Side Effects Software Inc.
3+ * All rights reserved.
4+ *
5+ * Redistribution and use in source and binary forms, with or without
6+ * modification, are permitted provided that the following conditions are met:
7+ *
8+ * 1. Redistributions of source code must retain the above copyright notice,
9+ * this list of conditions and the following disclaimer.
10+ *
11+ * 2. The name of Side Effects Software may not be used to endorse or
12+ * promote products derived from this software without specific prior
13+ * written permission.
14+ *
15+ * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE "AS IS" AND ANY EXPRESS
16+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
18+ * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
19+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
21+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+ */
2626
2727
2828using UnityEngine ;
@@ -37,100 +37,100 @@ namespace HoudiniEngineUnity
3737 [ InitializeOnLoad ]
3838 public static class HEU_EditorApp
3939 {
40-
41- /// <summary>
42- /// Executed after script (re)load. Sets up plugin callbacks.
43- /// </summary>
44- static HEU_EditorApp ( )
45- {
46- EditorApplication . hierarchyWindowItemOnGUI += HierarchyWindowItemOnGUI ;
40+ /// <summary>
41+ /// Executed after script (re)load. Sets up plugin callbacks.
42+ /// </summary>
43+ static HEU_EditorApp ( )
44+ {
45+ EditorApplication . hierarchyWindowItemOnGUI += HierarchyWindowItemOnGUI ;
4746
4847#if UNITY_2018_1_OR_NEWER
49- EditorApplication . quitting += EditorQuit ;
48+ EditorApplication . quitting += EditorQuit ;
5049#endif
5150
5251#if UNITY_2019_1_OR_NEWER
53- SceneView . duringSceneGui += OnSceneGUIDelegate ;
52+ SceneView . duringSceneGui += OnSceneGUIDelegate ;
5453#else
5554 SceneView . onSceneGUIDelegate += OnSceneGUIDelegate ;
5655#endif
57- }
58-
59- private static void HierarchyWindowItemOnGUI ( int instanceID , Rect selectionRect )
60- {
61- ProcessDragEvent ( Event . current , null ) ;
62- }
63-
64- private static void OnSceneGUIDelegate ( SceneView sceneView )
65- {
66- ProcessDragEvent ( Event . current , sceneView ) ;
67- }
68-
69- private static void ProcessDragEvent ( Event dragEvent , SceneView sceneView )
70- {
71- if ( dragEvent != null && ( dragEvent . type == EventType . DragUpdated || dragEvent . type == EventType . DragPerform ) )
72- {
73- bool dragHDAs = false ;
74- List < string > hdaList = new List < string > ( ) ;
75- foreach ( string file in DragAndDrop . paths )
76- {
77- if ( HEU_HAPIUtility . IsHoudiniAssetFile ( file ) )
78- {
79- dragHDAs = true ;
80- DragAndDrop . visualMode = DragAndDropVisualMode . Move ;
81- hdaList . Add ( file ) ;
82- break ;
83- }
84- }
85-
86- if ( dragHDAs )
87- {
88- if ( dragEvent . type == EventType . DragPerform )
89- {
90- if ( HEU_SessionManager . ValidatePluginSession ( ) )
91- {
92- Vector3 dropPos = Vector3 . zero ;
93- if ( sceneView != null )
94- {
95- Camera camera = sceneView . camera ;
96- Vector3 mousePos = HEU_EditorUI . GetMousePosition ( ref dragEvent , camera ) ;
97-
98- Ray ray = camera . ScreenPointToRay ( mousePos ) ;
99- ray . origin = camera . transform . position ;
100- Plane plane = new Plane ( ) ;
101- plane . SetNormalAndPosition ( Vector3 . up , Vector3 . zero ) ;
102- float enter = 0f ;
103- plane . Raycast ( ray , out enter ) ;
104- enter = Mathf . Clamp ( enter , camera . nearClipPlane , camera . farClipPlane ) ;
105- dropPos = ray . origin + ray . direction * enter ;
106- }
107-
108- List < GameObject > createdGOs = new List < GameObject > ( ) ;
109- foreach ( string file in hdaList )
110- {
111- GameObject go = HEU_HAPIUtility . InstantiateHDA ( file , dropPos , HEU_SessionManager . GetOrCreateDefaultSession ( ) , true ) ;
112- if ( go != null )
113- {
114- createdGOs . Add ( go ) ;
115- }
116- }
117-
118- // Select the created assets
119- HEU_EditorUtility . SelectObjects ( createdGOs . ToArray ( ) ) ;
120- }
121- }
122-
123- dragEvent . Use ( ) ;
124- }
125- }
126- }
127-
128- private static void EditorQuit ( )
129- {
130- HEU_Logger . Log ( "Houdini Engine: Editor is closing. Closing all sessions and clearing cache." ) ;
131- HEU_SessionManager . CloseAllSessions ( ) ;
132- HEU_PluginStorage . DeleteAllSavedSessionData ( ) ;
133- }
56+ }
57+
58+ private static void HierarchyWindowItemOnGUI ( int instanceID , Rect selectionRect )
59+ {
60+ ProcessDragEvent ( Event . current , null ) ;
61+ }
62+
63+ private static void OnSceneGUIDelegate ( SceneView sceneView )
64+ {
65+ ProcessDragEvent ( Event . current , sceneView ) ;
66+ }
67+
68+ private static void ProcessDragEvent ( Event dragEvent , SceneView sceneView )
69+ {
70+ if ( dragEvent != null &&
71+ ( dragEvent . type == EventType . DragUpdated || dragEvent . type == EventType . DragPerform ) )
72+ {
73+ bool dragHDAs = false ;
74+ List < string > hdaList = new List < string > ( ) ;
75+ foreach ( string file in DragAndDrop . paths )
76+ {
77+ if ( HEU_HAPIUtility . IsHoudiniAssetFile ( file ) )
78+ {
79+ dragHDAs = true ;
80+ DragAndDrop . visualMode = DragAndDropVisualMode . Move ;
81+ hdaList . Add ( file ) ;
82+ break ;
83+ }
84+ }
85+
86+ if ( dragHDAs )
87+ {
88+ if ( dragEvent . type == EventType . DragPerform )
89+ {
90+ if ( HEU_SessionManager . ValidatePluginSession ( ) )
91+ {
92+ Vector3 dropPos = Vector3 . zero ;
93+ if ( sceneView != null )
94+ {
95+ Camera camera = sceneView . camera ;
96+ Vector3 mousePos = HEU_EditorUI . GetMousePosition ( ref dragEvent , camera ) ;
97+
98+ Ray ray = camera . ScreenPointToRay ( mousePos ) ;
99+ ray . origin = camera . transform . position ;
100+ Plane plane = new Plane ( ) ;
101+ plane . SetNormalAndPosition ( Vector3 . up , Vector3 . zero ) ;
102+ float enter = 0f ;
103+ plane . Raycast ( ray , out enter ) ;
104+ enter = Mathf . Clamp ( enter , camera . nearClipPlane , camera . farClipPlane ) ;
105+ dropPos = ray . origin + ray . direction * enter ;
106+ }
107+
108+ List < GameObject > createdGOs = new List < GameObject > ( ) ;
109+ foreach ( string file in hdaList )
110+ {
111+ GameObject go = HEU_HAPIUtility . InstantiateHDA ( file , dropPos ,
112+ HEU_SessionManager . GetOrCreateDefaultSession ( ) , true ) ;
113+ if ( go != null )
114+ {
115+ createdGOs . Add ( go ) ;
116+ }
117+ }
118+
119+ // Select the created assets
120+ HEU_EditorUtility . SelectObjects ( createdGOs . ToArray ( ) ) ;
121+ }
122+ }
123+
124+ dragEvent . Use ( ) ;
125+ }
126+ }
127+ }
128+
129+ private static void EditorQuit ( )
130+ {
131+ HEU_Logger . Log ( "Houdini Engine: Editor is closing. Closing all sessions and clearing cache." ) ;
132+ HEU_SessionManager . CloseAllSessions ( ) ;
133+ HEU_PluginStorage . DeleteAllSavedSessionData ( ) ;
134+ }
134135 }
135-
136136}
0 commit comments