Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Modify VRC_SpatialAudioSource editors to allow for multiple and remov…
Browse files Browse the repository at this point in the history
…ed the advanced setting that just hides two fields...

Also fixed bugs relating to when the file is not found.
  • Loading branch information
CyanLaser committed Mar 8, 2021
1 parent b27aadd commit 959d978
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
20 changes: 19 additions & 1 deletion CyanEmu/Resources/FileModifications/modifications.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
2
4
VRC_TriggerEditor.cs
1
AddAfter 3 4
Expand Down Expand Up @@ -31,3 +31,21 @@ AddAfter 3 1
break;
}
GUILayout.EndScrollView();
VRC_SpatialAudioSourceEditor3.cs
3
AddAfter 1 1
[CustomEditor(typeof(VRC.SDK3.Components.VRCSpatialAudioSource))]
[CanEditMultipleObjects]
Delete 1
showAdvancedOptions = EditorGUILayout.Foldout(showAdvancedOptions, "Advanced Options");
Delete 1
if (showAdvancedOptions)
VRC_SpatialAudioSourceEditor.cs
3
AddAfter 1 1
[CustomEditor(typeof(VRCSDK2.VRC_SpatialAudioSource))]
[CanEditMultipleObjects]
Delete 1
showAdvancedOptions = EditorGUILayout.Foldout(showAdvancedOptions, "Advanced Options");
Delete 1
if (showAdvancedOptions)
34 changes: 28 additions & 6 deletions CyanEmu/Scripts/Editor/CyanEmuFileModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ public static void PerformModifications()
Debug.Log("Attempting to modify " + filename);

FileInfo file = GetFile(filename);
bool performOperations = true;
if (file == null || !file.Exists)
{
Debug.LogError("File to modify does not exist! " + filename);
continue;
Debug.LogWarning("File to modify does not exist! " + filename);
performOperations = false;
}

string fileContents = File.ReadAllText(file.FullName).Replace("\r\n", "\n");
string fileContents = performOperations
? File.ReadAllText(file.FullName).Replace("\r\n", "\n")
: "";

int numOperations = int.Parse(reader.ReadLine());

Expand Down Expand Up @@ -81,6 +84,11 @@ public static void PerformModifications()
replace += "\n" + reader.ReadLine();
}

if (!performOperations)
{
continue;
}

if (fileContents.Contains(replace))
{
Debug.LogWarning("File [" + filename + "] already contains added lines. Skipping");
Expand All @@ -90,7 +98,7 @@ public static void PerformModifications()
int index = fileContents.IndexOf(searchLines);
if (fileContents.IndexOf(searchLines, index + 1) != -1)
{
Debug.LogWarning("File [" + filename + "] contains multilpe copies of the lines to replace. Skipping");
Debug.LogWarning("File [" + filename + "] contains multiple copies of the lines to replace. Skipping");
continue;
}

Expand All @@ -110,6 +118,11 @@ public static void PerformModifications()
}
searchLines += reader.ReadLine();
}

if (!performOperations)
{
continue;
}

if (!fileContents.Contains(searchLines))
{
Expand All @@ -133,6 +146,11 @@ public static void PerformModifications()
}
}

if (!performOperations)
{
continue;
}

File.WriteAllText(file.FullName, fileContents);
}
AssetDatabase.Refresh();
Expand All @@ -148,8 +166,12 @@ private static FileInfo GetFile(string filename)
{
DirectoryInfo sdkDir = new DirectoryInfo(VRCSDK_PATH);
FileInfo[] fileInfos = sdkDir.GetFiles(filename, SearchOption.AllDirectories);
Debug.Assert(fileInfos.Length == 1);
return fileInfos[0];

if (fileInfos.Length > 0)
{
return fileInfos[0];
}
return null;
}
}
}

0 comments on commit 959d978

Please sign in to comment.