-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from OpenCommissioning/development
Hotfix
- Loading branch information
Showing
7 changed files
with
103 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using UnityEngine; | ||
using UnityEditor; | ||
using System.IO; | ||
|
||
namespace OC.Editor | ||
{ | ||
public class SamplesAssetPostprocessor : AssetPostprocessor | ||
{ | ||
private const string DATA_PATH = "Demo/Data/RFID"; | ||
private const string SAMPLE_IDENTIFIER = "Samples/Open Commissioning/"; | ||
private static void OnPostprocessAllAssets( | ||
string[] importedAssets, | ||
string[] deletedAssets, | ||
string[] movedAssets, | ||
string[] movedFromAssetPaths) | ||
{ | ||
if (Directory.Exists(Path.Combine(Application.streamingAssetsPath, DATA_PATH))) return; | ||
if (importedAssets.Length == 0 || !importedAssets[0].StartsWith("Assets/"+SAMPLE_IDENTIFIER)) return; | ||
|
||
var splits = importedAssets[0].Split('/'); | ||
var versionString = splits[3]; | ||
|
||
var sourceFullPath = Path.Combine(Path.GetFullPath(Application.dataPath), "Samples/Open Commissioning/", versionString, DATA_PATH); | ||
|
||
MoveTemplateFiles(sourceFullPath); | ||
|
||
var deletePath = Directory.GetParent(sourceFullPath)!.FullName; | ||
FileUtil.DeleteFileOrDirectory(deletePath); | ||
FileUtil.DeleteFileOrDirectory(deletePath + ".meta"); | ||
AssetDatabase.Refresh(); | ||
} | ||
|
||
private static void MoveTemplateFiles(string sourceFullPath) | ||
{ | ||
var targetDirectory = Path.Combine(Application.streamingAssetsPath, DATA_PATH); | ||
|
||
if (!Directory.Exists(targetDirectory)) Directory.CreateDirectory(targetDirectory); | ||
|
||
try | ||
{ | ||
foreach (var file in Directory.GetFiles(sourceFullPath)) | ||
{ | ||
var targetFileName = Path.Combine(targetDirectory, Path.GetFileName(file)); | ||
File.Move(file, targetFileName); | ||
} | ||
} | ||
catch (System.Exception e) | ||
{ | ||
Debug.LogError($"Error moving files to StreamingAssets: {e.Message}"); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters