Skip to content

Instantly share code, notes, and snippets.

@Lachee
Last active February 24, 2022 06:15
Show Gist options
  • Save Lachee/659d68969512473f3ba3f7f578e9cb91 to your computer and use it in GitHub Desktop.
Save Lachee/659d68969512473f3ba3f7f578e9cb91 to your computer and use it in GitHub Desktop.
Enforces Avatar Privating
/**
* This avatar has been marked as private. As per the licensing agreement when downloading this model,
* you are not allowed to share it.
*
* This script automatically disables the share button in VRChat when publishing to help enforce this rule.
*
* Script Author: Lachee
* Installation: Include this script in any folder called Editor.
* For additional safety, also include the PrivateAvatarBehaviour and uncomment the configuration
*
* Script License: MIT
* - Do what you want with this script. Include it in all your models. Author tag is appricated but not required.
*
* Script Source: https://gist.github.com/Lachee/659d68969512473f3ba3f7f578e9cb91
*/
#if UNITY_EDITOR
using UnityEngine;
using VRCSDK2;
using UnityEditor;
namespace Lachee.VRC.Editor
{
[InitializeOnLoad]
public static class PrivateAvatar
{
static PrivateAvatar()
{
EditorApplication.playModeStateChanged += LogPlayModeState;
}
private static void LogPlayModeState(PlayModeStateChange state)
{
if (state == PlayModeStateChange.EnteredPlayMode)
{
// If you have the PrivateAvatarBehaviour included, uncomment this code.
//var obj = new GameObject("RBC Private Enforcer", typeof(PrivateAvatarBehaviour));
//obj.hideFlags = HideFlags.HideAndDontSave;
var RBC = GameObject.FindObjectOfType<RuntimeBlueprintCreation>();
if (RBC) ConfigureRBC(RBC);
}
}
public static void ConfigureRBC(RuntimeBlueprintCreation RBC)
{
RBC.sharePublic.isOn = false;
RBC.sharePublic.interactable = false;
var label = RBC.sharePublic.GetComponentInChildren<UnityEngine.UI.Text>();
if (label)
{
label.text = "Public (private avatar)";
}
}
}
}
#endif
/**
* OPTIONAL
*
* This script is an additonally sanity check to enforce that the public button cannot be pressed.
* It checks every frame and forces it back to false.
*
* Note that it is optional and just the editor script is sufficient.
*
* Script Author: Lachee
* Script Source: https://gist.github.com/Lachee/659d68969512473f3ba3f7f578e9cb91
* Installation:
* - Place this script outside an Editor folder.
* - Ensure the Editor/PrivateAvatar.cs is configured correctly
*/
#if UNITY_EDITOR
using UnityEngine;
using VRCSDK2;
namespace Lachee.VRC
{
/// <summary>
/// This script ensures the avatars are private
/// </summary>
public class PrivateAvatarBehaviour : MonoBehaviour
{
public RuntimeBlueprintCreation RBC;
private void Awake()
{
// First try to find it attached
RBC = GetComponent<RuntimeBlueprintCreation>();
}
private void Update()
{
// We still dont have it, find it later
if (!RBC)
RBC = GameObject.FindObjectOfType<RuntimeBlueprintCreation>();
DisablePublic();
}
private void LateUpdate()
{
DisablePublic();
}
public void DisablePublic()
{
if (RBC && RBC.sharePublic)
{
RBC.sharePublic.isOn = false;
RBC.sharePublic.interactable = false;
var label = RBC.sharePublic.GetComponentInChildren<UnityEngine.UI.Text>();
if (label)
{
label.text = "Public (private avatar)";
}
}
}
}
}
#endif
@Lachee
Copy link
Author

Lachee commented Feb 24, 2022

This code is licensed under MIT:

  • You can use it how you want
  • You dont need to credit (although appriciated)
  • You can use commercially
  • You can redistribute
  • Script is provided "AS IS" without warranty

Copyright 2022 Lachee

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment