Skip to content

Instantly share code, notes, and snippets.

@ApprenticeGC
Last active October 13, 2017 03:55
Show Gist options
  • Save ApprenticeGC/a64f35877df1889ee5455852b3fcfb74 to your computer and use it in GitHub Desktop.
Save ApprenticeGC/a64f35877df1889ee5455852b3fcfb74 to your computer and use it in GitHub Desktop.
Create symlink to import plugins to Unity project
{
"name": "PlayMaker",
"toSymlink": [
{
"name": "PlayMaker",
"to": "Standard Assets/PlayMaker"
},
{
"name": "Gizmos/PlayMakerFSM Icon.tiff",
"to": "Gizmos/PlayMakerFSM Icon.tiff"
},
{
"name": "Gizmos/PlayMakerGlobals Icon.tiff",
"to": "Gizmos/PlayMakerGlobals Icon.tiff"
},
{
"name": "Gizmos/PlayMakerGUI Icon.tiff",
"to": "Gizmos/PlayMakerGUI Icon.tiff"
},
{
"name": "Gizmos/PlaymakerIcon.tiff",
"to": "Gizmos/PlaymakerIcon.tiff"
},
{
"name": "Gizmos/PlayMakerPrefs Icon.tiff",
"to": "Gizmos/PlayMakerPrefs Icon.tiff"
},
{
"name": "Plugins/PlayMaker",
"to": "Plugins/PlayMaker"
}
]
}
#Requires -Version 2.0
$currentPath = (Get-Item -Path ".\" -Verbose).FullName
$referencedSettingsBase = Join-Path -Path $currentPath -ChildPath "referenced-settings"
$inReferencesBase = Join-Path -Path $currentPath -ChildPath "in-references"
$unityAssetsBase = Join-Path -Path $currentPath -ChildPath "Assets"
$gizmosDirectory = Join-Path -Path $unityAssetsBase -ChildPath "Gizmos"
$pluginDirectory = Join-Path -Path $unityAssetsBase -ChildPath "Plugins"
$pluginEditorDirectory = Join-Path -Path $pluginDirectory -ChildPath "Editor"
$standardAssetsDirectory = Join-Path -Path $unityAssetsBase -ChildPath "Standard Assets"
$standardAssetsEditorDirectory = Join-Path -Path $standardAssetsDirectory -ChildPath "Editor"
# $unityAssetsBase
function Create-Directory ()
{
New-Item -ItemType Directory -Force -Path $gizmosDirectory
New-Item -ItemType Directory -Force -Path $pluginDirectory
New-Item -ItemType Directory -Force -Path $pluginEditorDirectory
New-Item -ItemType Directory -Force -Path $standardAssetsDirectory
New-Item -ItemType Directory -Force -Path $standardAssetsEditorDirectory
return 0
}
# Create-Directory
function Symlink-InReferences ()
{
$files = @(Get-ChildItem "$referencedSettingsBase\*.json")
foreach ($file in $files) {
$setting = (Get-Content $file) | ConvertFrom-Json
$sourceBase = Join-Path -Path $inReferencesBase -ChildPath $setting.name
foreach ($symlinkItem in $setting.toSymlink) {
$name = $symlinkItem.name
$toLocation = $symlinkItem.to
$sourceLocation = Join-Path -Path $sourceBase -ChildPath $name
$sourceMetaLocation = Join-Path -Path $sourceBase -ChildPath "$name.meta"
$targetLocation = Join-Path -Path $unityAssetsBase -ChildPath $toLocation
$targetMetaLocation = Join-Path -Path $unityAssetsBase -ChildPath "$toLocation.meta"
# Remove symlinked file/folder
$targetLocationFile = Get-Item $targetLocation -Force -ea SilentlyContinue
if ([bool]($targetLocationFile.Attributes -band [IO.FileAttributes]::ReparsePoint)) {
Remove-Item $targetLocation
} else {
$showText = "It is not symlink"
$showText
}
# Remove meta file
$targetMetaLocationFile = Get-Item $targetMetaLocation -Force -ea SilentlyContinue
if (Test-Path $targetMetaLocation) {
Remove-Item $targetMetaLocation
}
# Symlink file/folder if there is any
if (Test-Path $sourceLocation) {
New-Item -ItemType SymbolicLink -Path $targetLocation -Value $sourceLocation
}
# Symlink meta file if there is any
if (Test-Path $sourceMetaLocation) {
New-Item -ItemType SymbolicLink -Path $targetMetaLocation -Value $sourceMetaLocation
}
}
}
return 0
}
# Create folder first then create symlink
Create-Directory
Symlink-InReferences
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment