def test_get_project_company_name(self): project_dir = Path(__file__).parent / 'unity' self.assertTrue(project_dir.exists()) project = UnityProject(str(project_dir)) self.assertEqual(project.get_project_company_name(), 'fopoon')
def test_get_project_tags(self): project_dir = Path(__file__).parent / 'unity' self.assertTrue(project_dir.exists()) project = UnityProject(str(project_dir)) tags = project.get_project_tags() self.assertCountEqual(tags, ['tag_0'])
def test_get_project_bundle_version(self): project_dir = Path(__file__).parent / 'unity' self.assertTrue(project_dir.exists()) project = UnityProject(str(project_dir)) bundle_version = project.get_project_bundle_version() self.assertEqual(bundle_version, 0.1)
def test_get_editor_version(self): project_dir = Path(__file__).parent / 'unity' self.assertTrue(project_dir.exists()) project = UnityProject(str(project_dir)) editor_version = project.get_editor_version() self.assertEqual(editor_version, '2019.2.6f1')
def test_get_project_sorting_layers(self): project_dir = Path(__file__).parent / 'unity' self.assertTrue(project_dir.exists()) project = UnityProject(str(project_dir)) sorting_layers = project.get_project_sorting_layers() self.assertCountEqual(sorting_layers, ['Default', 'sorting_layer_1'])
def test_get_build_scenes(self): project_dir = Path(__file__).parent / 'unity' self.assertTrue(project_dir.exists()) project = UnityProject(str(project_dir)) scenes = project.get_build_scenes() self.assertTrue(scenes)
def __import_run(self, *args: str, project: UnityProject) -> int: pkg_name, pkg_data = rsc_data pkg_dir = FUnityEditor.__get_package(package=pkg_name, resource_name=pkg_data) FUnityEditor.__import_package(project, pkg_name=pkg_name, pkg_dir=pkg_dir) return_code = self.run(*args, '-projectPath', str(project), cli=True, log_func=FUnityEditor.__log) project.delete_asset(pkg_name) return return_code
def test_find_assets(self): project_dir = Path(__file__).parent / 'unity' self.assertTrue(project_dir.exists()) project = UnityProject(str(project_dir)) csharp_assets = project.find_assets( file_extensions=['.cs'], skip_folders=UnityProject.SPECIAL_DIRS) self.assertTrue(csharp_assets) self.assertCountEqual(csharp_assets, [ 'Assets/Scripts/MyClass.cs', 'Assets/Scripts/MyMonoBehaviour.cs', ])
def __import_package(project: UnityProject, pkg_name: str, pkg_dir: str) -> None: src_path = Path(pkg_dir) asset_path = project.get_assets_path() dst_path = asset_path / pkg_name if (asset_path / pkg_name).exists(): raise Exception('Unable to import package') copytree(str(src_path), str(dst_path))
def main(): # Get arguments. arguments = parse_arguments() output = arguments.output version = arguments.version project_path = arguments.project asset_paths = arguments.assets # Get paths. fdp = Path(__file__).parent rdp = fdp.parent.parent cache_path = fdp / "editor.cache" # Get Unity editor. editor = get_editor(str(cache_path)) # Get Unity project. project = UnityProject(str(rdp / project_path)) # Setup output path. output_dir_name = "UnityPackages" output_dir = project.path / output_dir_name output_dir.mkdir(parents=True, exist_ok=True) # Setup file name. file_extension = ".unitypackage" file_name = f"{output}_v{version}{file_extension}" file_path = output_dir / file_name try: # Run 'exportPackage' on the Unity project using the Unity editor CLI. return_code = editor.run( "-projectPath", str(project), "-exportPackage", *asset_paths, str(file_path.relative_to(project.path)), # log_func=lambda l: print(l, end=""), cli= True # Shorthand for '-batchmode', '-nographics', '-quit', '-silent-crashes'. ) if return_code != 0 or not file_path.exists(): raise Exception("Failed to export package.") # Setup bin path. bupdp = rdp / "bin/UnityPackages" bupdp.mkdir(parents=True, exist_ok=True) # Move file into bin/UnityPackages folder. src = file_path dst = bupdp / file_path.name move(str(src), str(dst)) print(f"{str(src.relative_to(rdp))} → {str(dst.relative_to(rdp))}") finally: # Delete output directory. rmtree(str(output_dir), ignore_errors=True)
def test_compile(self): editor = UnityEditor(str(UnityEditor.find_all()[0])) self.assertIsNotNone(editor) project_dir = Path(__file__).parent / 'unity' self.assertTrue(project_dir.exists()) project = UnityProject(str(project_dir)) tmp_path = project.path / 'tmp' tmp_path.mkdir(exist_ok=True) self.assertTrue(tmp_path.exists()) output_file = tmp_path / 'test.dll' self.assertFalse(output_file.exists()) unity_libraries = editor.get_libs() self.assertTrue(unity_libraries) csharp_assets = project.find_assets( file_extensions=['.cs'], skip_folders=UnityProject.SPECIAL_DIRS) csharp_files = [str(project.path / a) for a in csharp_assets] self.assertTrue(csharp_files) try: return_code = editor.compile(*csharp_files, out=str(output_file), references=unity_libraries, target='library') self.assertEqual(0, return_code) self.assertTrue(output_file.exists()) finally: rmtree(str(tmp_path), ignore_errors=True)
def test_get_project_layers(self): project_dir = Path(__file__).parent / 'unity' self.assertTrue(project_dir.exists()) project = UnityProject(str(project_dir)) layers = project.get_project_layers() self.assertCountEqual(layers, [ 'Default', 'TransparentFX', 'Ignore Raycast', 'Water', 'UI', 'layer_8' ]) layers = project.get_project_layers(include_none=True) self.assertCountEqual(layers, [ 'Default', 'TransparentFX', 'Ignore Raycast', None, 'Water', 'UI', None, None, 'layer_8', None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None ])
def test_set_serialization_mode(self): editor = FUnityEditor(str(FUnityEditor.find_all()[0])) self.assertIsNotNone(editor) project_dir = Path(__file__).parent / 'unity' self.assertTrue(project_dir.exists()) project = UnityProject(str(project_dir)) return_code = editor.run_set_serialization_mode( project=project, serialization_mode='ForceText') self.assertEqual(0, return_code)
def test_get_project_input_axes(self): project_dir = Path(__file__).parent / 'unity' self.assertTrue(project_dir.exists()) project = UnityProject(str(project_dir)) axes = project.get_project_input_axes() self.assertCountEqual(axes, [{ 'serializedVersion': 3, 'm_Name': 'Horizontal', 'descriptiveName': None, 'descriptiveNegativeName': None, 'negativeButton': 'left', 'positiveButton': 'right', 'altNegativeButton': 'a', 'altPositiveButton': 'd', 'gravity': 3, 'dead': 0.001, 'sensitivity': 3, 'snap': 1, 'invert': 0, 'type': 0, 'axis': 0, 'joyNum': 0 }, { 'serializedVersion': 3, 'm_Name': 'Vertical', 'descriptiveName': None, 'descriptiveNegativeName': None, 'negativeButton': 'down', 'positiveButton': 'up', 'altNegativeButton': 's', 'altPositiveButton': 'w', 'gravity': 3, 'dead': 0.001, 'sensitivity': 3, 'snap': 1, 'invert': 0, 'type': 0, 'axis': 0, 'joyNum': 0 }, { 'serializedVersion': 3, 'm_Name': 'Fire1', 'descriptiveName': None, 'descriptiveNegativeName': None, 'negativeButton': None, 'positiveButton': 'left ctrl', 'altNegativeButton': None, 'altPositiveButton': 'mouse 0', 'gravity': 1000, 'dead': 0.001, 'sensitivity': 1000, 'snap': 0, 'invert': 0, 'type': 0, 'axis': 0, 'joyNum': 0 }, { 'serializedVersion': 3, 'm_Name': 'Fire2', 'descriptiveName': None, 'descriptiveNegativeName': None, 'negativeButton': None, 'positiveButton': 'left alt', 'altNegativeButton': None, 'altPositiveButton': 'mouse 1', 'gravity': 1000, 'dead': 0.001, 'sensitivity': 1000, 'snap': 0, 'invert': 0, 'type': 0, 'axis': 0, 'joyNum': 0 }, { 'serializedVersion': 3, 'm_Name': 'Fire3', 'descriptiveName': None, 'descriptiveNegativeName': None, 'negativeButton': None, 'positiveButton': 'left shift', 'altNegativeButton': None, 'altPositiveButton': 'mouse 2', 'gravity': 1000, 'dead': 0.001, 'sensitivity': 1000, 'snap': 0, 'invert': 0, 'type': 0, 'axis': 0, 'joyNum': 0 }, { 'serializedVersion': 3, 'm_Name': 'Jump', 'descriptiveName': None, 'descriptiveNegativeName': None, 'negativeButton': None, 'positiveButton': 'space', 'altNegativeButton': None, 'altPositiveButton': None, 'gravity': 1000, 'dead': 0.001, 'sensitivity': 1000, 'snap': 0, 'invert': 0, 'type': 0, 'axis': 0, 'joyNum': 0 }, { 'serializedVersion': 3, 'm_Name': 'Mouse X', 'descriptiveName': None, 'descriptiveNegativeName': None, 'negativeButton': None, 'positiveButton': None, 'altNegativeButton': None, 'altPositiveButton': None, 'gravity': 0, 'dead': 0, 'sensitivity': 0.1, 'snap': 0, 'invert': 0, 'type': 1, 'axis': 0, 'joyNum': 0 }, { 'serializedVersion': 3, 'm_Name': 'Mouse Y', 'descriptiveName': None, 'descriptiveNegativeName': None, 'negativeButton': None, 'positiveButton': None, 'altNegativeButton': None, 'altPositiveButton': None, 'gravity': 0, 'dead': 0, 'sensitivity': 0.1, 'snap': 0, 'invert': 0, 'type': 1, 'axis': 1, 'joyNum': 0 }, { 'serializedVersion': 3, 'm_Name': 'Mouse ScrollWheel', 'descriptiveName': None, 'descriptiveNegativeName': None, 'negativeButton': None, 'positiveButton': None, 'altNegativeButton': None, 'altPositiveButton': None, 'gravity': 0, 'dead': 0, 'sensitivity': 0.1, 'snap': 0, 'invert': 0, 'type': 1, 'axis': 2, 'joyNum': 0 }, { 'serializedVersion': 3, 'm_Name': 'Horizontal', 'descriptiveName': None, 'descriptiveNegativeName': None, 'negativeButton': None, 'positiveButton': None, 'altNegativeButton': None, 'altPositiveButton': None, 'gravity': 0, 'dead': 0.19, 'sensitivity': 1, 'snap': 0, 'invert': 0, 'type': 2, 'axis': 0, 'joyNum': 0 }, { 'serializedVersion': 3, 'm_Name': 'Vertical', 'descriptiveName': None, 'descriptiveNegativeName': None, 'negativeButton': None, 'positiveButton': None, 'altNegativeButton': None, 'altPositiveButton': None, 'gravity': 0, 'dead': 0.19, 'sensitivity': 1, 'snap': 0, 'invert': 1, 'type': 2, 'axis': 1, 'joyNum': 0 }, { 'serializedVersion': 3, 'm_Name': 'Fire1', 'descriptiveName': None, 'descriptiveNegativeName': None, 'negativeButton': None, 'positiveButton': 'joystick button 0', 'altNegativeButton': None, 'altPositiveButton': None, 'gravity': 1000, 'dead': 0.001, 'sensitivity': 1000, 'snap': 0, 'invert': 0, 'type': 0, 'axis': 0, 'joyNum': 0 }, { 'serializedVersion': 3, 'm_Name': 'Fire2', 'descriptiveName': None, 'descriptiveNegativeName': None, 'negativeButton': None, 'positiveButton': 'joystick button 1', 'altNegativeButton': None, 'altPositiveButton': None, 'gravity': 1000, 'dead': 0.001, 'sensitivity': 1000, 'snap': 0, 'invert': 0, 'type': 0, 'axis': 0, 'joyNum': 0 }, { 'serializedVersion': 3, 'm_Name': 'Fire3', 'descriptiveName': None, 'descriptiveNegativeName': None, 'negativeButton': None, 'positiveButton': 'joystick button 2', 'altNegativeButton': None, 'altPositiveButton': None, 'gravity': 1000, 'dead': 0.001, 'sensitivity': 1000, 'snap': 0, 'invert': 0, 'type': 0, 'axis': 0, 'joyNum': 0 }, { 'serializedVersion': 3, 'm_Name': 'Jump', 'descriptiveName': None, 'descriptiveNegativeName': None, 'negativeButton': None, 'positiveButton': 'joystick button 3', 'altNegativeButton': None, 'altPositiveButton': None, 'gravity': 1000, 'dead': 0.001, 'sensitivity': 1000, 'snap': 0, 'invert': 0, 'type': 0, 'axis': 0, 'joyNum': 0 }, { 'serializedVersion': 3, 'm_Name': 'Submit', 'descriptiveName': None, 'descriptiveNegativeName': None, 'negativeButton': None, 'positiveButton': 'return', 'altNegativeButton': None, 'altPositiveButton': 'joystick button 0', 'gravity': 1000, 'dead': 0.001, 'sensitivity': 1000, 'snap': 0, 'invert': 0, 'type': 0, 'axis': 0, 'joyNum': 0 }, { 'serializedVersion': 3, 'm_Name': 'Submit', 'descriptiveName': None, 'descriptiveNegativeName': None, 'negativeButton': None, 'positiveButton': 'enter', 'altNegativeButton': None, 'altPositiveButton': 'space', 'gravity': 1000, 'dead': 0.001, 'sensitivity': 1000, 'snap': 0, 'invert': 0, 'type': 0, 'axis': 0, 'joyNum': 0 }, { 'serializedVersion': 3, 'm_Name': 'Cancel', 'descriptiveName': None, 'descriptiveNegativeName': None, 'negativeButton': None, 'positiveButton': 'escape', 'altNegativeButton': None, 'altPositiveButton': 'joystick button 1', 'gravity': 1000, 'dead': 0.001, 'sensitivity': 1000, 'snap': 0, 'invert': 0, 'type': 0, 'axis': 0, 'joyNum': 0 }])