From e7c5ccbb1567ef7a19defcb39272515d314907ac Mon Sep 17 00:00:00 2001 From: jibola1997 Date: Wed, 19 May 2021 13:44:27 -0400 Subject: [PATCH] Removed sg_client instances, direct import of UnityEngine (#54) Co-authored-by: mojibola obadimeji --- hooks/tk-multi-publish2/basic/add_metadata.py | 5 +---- hooks/tk-multi-shotgunpanel/unity_actions.py | 7 ++++--- hooks/tk-unity/bootstrap/apply_metadata.py | 6 ++---- hooks/utils/unity_metadata.py | 8 +++----- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/hooks/tk-multi-publish2/basic/add_metadata.py b/hooks/tk-multi-publish2/basic/add_metadata.py index bc647e3..0effd0a 100644 --- a/hooks/tk-multi-publish2/basic/add_metadata.py +++ b/hooks/tk-multi-publish2/basic/add_metadata.py @@ -1,5 +1,4 @@ -from sg_client import GetUnityEngine - +import UnityEngine import json import os import sgtk @@ -44,7 +43,6 @@ class UnitySessionAddMetadataPlugin(HookBaseClass): logger.critical("There is no text field 'sg_unity_metadata' on Version entity type. Create one to store Unity metadata when publishing a Version") return else: - UnityEngine = GetUnityEngine() data_path = UnityEngine.Application.dataPath project_path = os.path.dirname(data_path) @@ -61,7 +59,6 @@ class UnitySessionAddMetadataPlugin(HookBaseClass): { 'project_path' : project_path, 'scene_path' : scene_path, 'metadata_version': _metadata_version } ) - # Update the version entity with new metadata engine.shotgun.update('Version', version['id'], { 'sg_unity_metadata' : metadata_json } ) diff --git a/hooks/tk-multi-shotgunpanel/unity_actions.py b/hooks/tk-multi-shotgunpanel/unity_actions.py index 55f40c5..c13d9df 100644 --- a/hooks/tk-multi-shotgunpanel/unity_actions.py +++ b/hooks/tk-multi-shotgunpanel/unity_actions.py @@ -1,5 +1,6 @@ import sgtk -from sg_client import GetUnityEngine, GetUnityEditor +import UnityEngine +import UnityEditor import json import os @@ -101,8 +102,8 @@ class UnityActions(HookBaseClass): "Parameters: %s. Shotgun Data: %s" % (name, params, sg_data)) if name == "jump_to_frame": - UnityEditor = GetUnityEditor() - UnityEngine = GetUnityEngine() + UnityEditor = UnityEditor + UnityEngine = UnityEngine # Open the scene metadata = params diff --git a/hooks/tk-unity/bootstrap/apply_metadata.py b/hooks/tk-unity/bootstrap/apply_metadata.py index ef2b093..7ecb3cc 100644 --- a/hooks/tk-unity/bootstrap/apply_metadata.py +++ b/hooks/tk-unity/bootstrap/apply_metadata.py @@ -1,6 +1,6 @@ # Shotgun import sgtk -from sg_client import GetUnityEditor +import UnityEditor # misc import json @@ -47,8 +47,6 @@ class UnityApplyMetadata(HookBaseClass): if not unity_metadata.relates_to_current_project(metadata): self.logger.warning('Not applying Shotgun metadata as it does not relate to the currently loaded project. Metadata = "{}")'.format(pprint.pformat(metadata))) - # TODO: could we call GetUnityEditor().EditorApplication.OpenProject? - # What would be the effect on the bootstrap, domain reload, etc.? return # Find the scene to open @@ -56,5 +54,5 @@ class UnityApplyMetadata(HookBaseClass): return # open the correct scene in Unity - GetUnityEditor().SceneManagement.EditorSceneManager.OpenScene(metadata.get('scene_path')) + UnityEditor.SceneManagement.EditorSceneManager.OpenScene(metadata.get('scene_path')) \ No newline at end of file diff --git a/hooks/utils/unity_metadata.py b/hooks/utils/unity_metadata.py index 1f8b0f4..82d692e 100644 --- a/hooks/utils/unity_metadata.py +++ b/hooks/utils/unity_metadata.py @@ -71,10 +71,10 @@ def get_metadata_from_entity(entity, sg): return metadata def relates_to_current_project(metadata): - from sg_client import GetUnityEngine + import UnityEngine # Make sure the right project is currently loaded - loaded_project = GetUnityEngine().Application.dataPath + loaded_project = UnityEngine.Application.dataPath # Remove /Assets loaded_project = os.path.split(loaded_project)[0] @@ -86,14 +86,12 @@ def relates_to_current_project(metadata): return metadata_project == loaded_project def relates_to_existing_scene(metadata): - from sg_client import GetUnityEditor + import UnityEditor metadata_scene_path = metadata.get('scene_path') if not metadata_scene_path: return False - UnityEditor = GetUnityEditor() - scene_guids = UnityEditor.AssetDatabase.FindAssets('t:scene') for guid in scene_guids: scene_path = UnityEditor.AssetDatabase.GUIDToAssetPath(guid)