Skip to content

Commit

Permalink
Merge pull request #12 from VRLabs/fix/dont-rename-by-default
Browse files Browse the repository at this point in the history
Dont rename by default
  • Loading branch information
jellejurre authored Oct 23, 2024
2 parents 99b26f2 + f0519a9 commit d169e40
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions Instancer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Instancer : MonoBehaviour

static Instancer()
{
renameInstances = PlayerPrefs.GetString("VRLabs.Instancer.RenameInstances", "True") == "True"; ;
renameInstances = PlayerPrefs.GetString("VRLabs.Instancer.RenameInstances", "False") == "True"; ;
}

[MenuItem("VRLabs/Rename new Instances", priority = 1)]
Expand Down Expand Up @@ -255,6 +255,7 @@ static void FixReferences(string[] localAssetPaths, string sourceFolder, string
bool newChanged = false;
do
{
if (property.propertyPath.Contains("m_Modification")) continue;
if (property.propertyType == SerializedPropertyType.ObjectReference)
{
if (property.objectReferenceValue != null)
Expand Down Expand Up @@ -297,24 +298,14 @@ static void RenameInstance(string[] localAssetPaths, string targetFolder, string
UnityEngine.Object[] targetAssets = AssetDatabase.LoadAllAssetsAtPath(targetAssetPath).Where(x => x != null).ToArray();
if (targetAssets.Length == 0) continue;
string[] possibleNames = new []{packageName, packageName.Replace("-", ""), packageName.Replace("-", " ")};

String fileName = Path.GetFileName(targetAssetPath);
foreach (string possibleName in possibleNames)
{
if (fileName.StartsWith(possibleName))
{
fileName = ReplaceAtStart(fileName, possibleName, newInstanceName);
AssetDatabase.RenameAsset(targetAssetPath, fileName);
break;
}
}

foreach (var targetAsset in targetAssets)
{
SerializedObject serializedObject = new SerializedObject(targetAsset);
SerializedProperty property = serializedObject.GetIterator();
do
{
if (property.propertyPath.Contains("m_Modification")) continue;
if (property.propertyType == SerializedPropertyType.String)
{
string value = property.stringValue;
Expand All @@ -333,6 +324,17 @@ static void RenameInstance(string[] localAssetPaths, string targetFolder, string

serializedObject.ApplyModifiedProperties();
}

String fileName = Path.GetFileName(targetAssetPath);
foreach (string possibleName in possibleNames)
{
if (fileName.StartsWith(possibleName))
{
fileName = ReplaceAtStart(fileName, possibleName, newInstanceName);
AssetDatabase.RenameAsset(targetAssetPath, fileName);
break;
}
}
}
}

Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit d169e40

Please sign in to comment.