Skip to content

Commit

Permalink
converted more systems over to use the police content system
Browse files Browse the repository at this point in the history
  • Loading branch information
dooly123 committed Dec 10, 2024
1 parent 79e94c7 commit 48cb406
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 56 deletions.
21 changes: 18 additions & 3 deletions Packages/Basis Framework/Avatar/BasisAvatarFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ public static async Task LoadAvatarLocal(BasisLocalPlayer Player,byte Mode, Basi
case 1://localload
Debug.Log("Requested Avatar was a Addressable Avatar " + BasisLoadableBundle.BasisRemoteBundleEncrypted.BundleURL);
var Para = new UnityEngine.ResourceManagement.ResourceProviders.InstantiationParameters(Player.transform.position, Quaternion.identity, null);
(List<GameObject> GameObjects, AddressableGenericResource resource) = await AddressableResourceProcess.LoadAsGameObjectsAsync(BasisLoadableBundle.BasisRemoteBundleEncrypted.BundleURL, Para);
ChecksRequired Required = new ChecksRequired
{
UseContentRemoval = true,
DisableAnimatorEvents = false
};
(List<GameObject> GameObjects, AddressableGenericResource resource) = await AddressableResourceProcess.LoadAsGameObjectsAsync(BasisLoadableBundle.BasisRemoteBundleEncrypted.BundleURL, Para, Required);

if (GameObjects.Count > 0)
{
Expand Down Expand Up @@ -120,8 +125,13 @@ public static async Task LoadAvatarRemote(BasisRemotePlayer Player,byte Mode, Ba
break;
case 1://localload
Debug.Log("Requested Avatar was a Addressable Avatar " + BasisLoadableBundle.BasisRemoteBundleEncrypted.BundleURL);
ChecksRequired Required = new ChecksRequired
{
UseContentRemoval = false,
DisableAnimatorEvents = false
};
var Para = new UnityEngine.ResourceManagement.ResourceProviders.InstantiationParameters(Player.transform.position, Quaternion.identity, null);
(List<GameObject> GameObjects, AddressableGenericResource resource) = await AddressableResourceProcess.LoadAsGameObjectsAsync(BasisLoadableBundle.BasisRemoteBundleEncrypted.BundleURL, Para);
(List<GameObject> GameObjects, AddressableGenericResource resource) = await AddressableResourceProcess.LoadAsGameObjectsAsync(BasisLoadableBundle.BasisRemoteBundleEncrypted.BundleURL, Para, Required);

if (GameObjects.Count > 0)
{
Expand Down Expand Up @@ -192,8 +202,13 @@ public static async Task LoadAvatarAfterError(BasisPlayer Player)
{
try
{
ChecksRequired Required = new ChecksRequired
{
UseContentRemoval = false,
DisableAnimatorEvents = false
};
var Para = new UnityEngine.ResourceManagement.ResourceProviders.InstantiationParameters(Player.transform.position, Quaternion.identity, null);
(List<GameObject> GameObjects, AddressableGenericResource resource) = await AddressableResourceProcess.LoadAsGameObjectsAsync(LoadingAvatar.BasisLocalEncryptedBundle.LocalBundleFile, Para);
(List<GameObject> GameObjects, AddressableGenericResource resource) = await AddressableResourceProcess.LoadAsGameObjectsAsync(LoadingAvatar.BasisLocalEncryptedBundle.LocalBundleFile, Para, Required);

if (GameObjects.Count != 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ public void ShutDownXR(bool isExiting = false)
}
public static async Task LoadGameobject(string playerAddressableID, InstantiationParameters instantiationParameters)
{
(List<GameObject>, Addressable_Driver.AddressableGenericResource) data = await AddressableResourceProcess.LoadAsGameObjectsAsync(playerAddressableID, instantiationParameters);
ChecksRequired Required = new ChecksRequired();
Required.UseContentRemoval = false;
(List<GameObject>, Addressable_Driver.AddressableGenericResource) data = await AddressableResourceProcess.LoadAsGameObjectsAsync(playerAddressableID, instantiationParameters, Required);
List<GameObject> gameObjects = data.Item1;

if (gameObjects.Count == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ static void OnBeforeSceneLoadRuntimeMethod()
}
private static async void OnAddressablesInitializationComplete(AsyncOperationHandle<IResourceLocator> obj)
{
var data = await AddressableResourceProcess.LoadAsGameObjectsAsync(BootManager, new UnityEngine.ResourceManagement.ResourceProviders.InstantiationParameters());
ChecksRequired Required = new ChecksRequired
{
UseContentRemoval = false,
DisableAnimatorEvents = false
};
var data = await AddressableResourceProcess.LoadAsGameObjectsAsync(BootManager, new UnityEngine.ResourceManagement.ResourceProviders.InstantiationParameters(), Required);
List<GameObject> Gameobjects = data.Item1;
if (Gameobjects.Count != 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ public void Update()
}
public static async Task CreateInputAction(BasisLocalPlayer Local)
{
var data = await AddressableResourceProcess.LoadAsGameObjectsAsync(InputActions, new UnityEngine.ResourceManagement.ResourceProviders.InstantiationParameters());
ChecksRequired Required = new ChecksRequired
{
UseContentRemoval = false,
DisableAnimatorEvents = false
};
var data = await AddressableResourceProcess.LoadAsGameObjectsAsync(InputActions, new UnityEngine.ResourceManagement.ResourceProviders.InstantiationParameters(), Required);
List<GameObject> Gameobjects = data.Item1;
if (Gameobjects.Count != 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ public static class BasisPlayerFactoryNetworked
public static async Task<BasisNetworkedPlayer> CreateNetworkedPlayer(InstantiationParameters InstantiationParameters, string PlayerAddressableID = "NetworkedPlayer")
{
Debug.Log("creating NetworkedPlayer Player");
var data = await AddressableResourceProcess.LoadAsGameObjectsAsync(PlayerAddressableID, InstantiationParameters);
ChecksRequired Required = new ChecksRequired
{
UseContentRemoval = false,
DisableAnimatorEvents = false
};
var data = await AddressableResourceProcess.LoadAsGameObjectsAsync(PlayerAddressableID, InstantiationParameters, Required);
List<GameObject> Gameobjects = data.Item1;
if (Gameobjects.Count != 0)
{
Expand Down
62 changes: 32 additions & 30 deletions Packages/Basis Framework/Players/BasisPlayerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,44 @@

namespace Basis.Scripts.Player
{
public static class BasisPlayerFactory
{
public static async Task<BasisLocalPlayer> CreateLocalPlayer(InstantiationParameters InstantiationParameters, string RemotePlayerId = "LocalPlayer")
{
BasisPlayer Player = await CreatePlayer(RemotePlayerId, InstantiationParameters);
BasisLocalPlayer CreatedLocalPlayer = (BasisLocalPlayer)Player;
await CreatedLocalPlayer.LocalInitialize();
return CreatedLocalPlayer;
}
public static async Task<BasisRemotePlayer> CreateRemotePlayer(InstantiationParameters InstantiationParameters, ClientAvatarChangeMessage AvatarURL, PlayerMetaDataMessage PlayerMetaDataMessage, string LocalPlayerId = "RemotePlayer")
public static class BasisPlayerFactory
{
BasisPlayer Player = await CreatePlayer(LocalPlayerId, InstantiationParameters);
BasisRemotePlayer CreatedRemotePlayer = (BasisRemotePlayer)Player;
await CreatedRemotePlayer.RemoteInitialize(AvatarURL, PlayerMetaDataMessage);
return CreatedRemotePlayer;
}
public static async Task<BasisPlayer> CreatePlayer(string PlayerAddressableID, InstantiationParameters InstantiationParameters)
{
var data = await AddressableResourceProcess.LoadAsGameObjectsAsync(PlayerAddressableID, InstantiationParameters);
List<GameObject> Gameobjects = data.Item1;
if (Gameobjects.Count != 0)
public static async Task<BasisLocalPlayer> CreateLocalPlayer(InstantiationParameters InstantiationParameters, string RemotePlayerId = "LocalPlayer")
{
BasisPlayer Player = await CreatePlayer(RemotePlayerId, InstantiationParameters);
BasisLocalPlayer CreatedLocalPlayer = (BasisLocalPlayer)Player;
await CreatedLocalPlayer.LocalInitialize();
return CreatedLocalPlayer;
}
public static async Task<BasisRemotePlayer> CreateRemotePlayer(InstantiationParameters InstantiationParameters, ClientAvatarChangeMessage AvatarURL, PlayerMetaDataMessage PlayerMetaDataMessage, string LocalPlayerId = "RemotePlayer")
{
foreach (GameObject gameObject in Gameobjects)
BasisPlayer Player = await CreatePlayer(LocalPlayerId, InstantiationParameters);
BasisRemotePlayer CreatedRemotePlayer = (BasisRemotePlayer)Player;
await CreatedRemotePlayer.RemoteInitialize(AvatarURL, PlayerMetaDataMessage);
return CreatedRemotePlayer;
}
public static async Task<BasisPlayer> CreatePlayer(string PlayerAddressableID, InstantiationParameters InstantiationParameters)
{
ChecksRequired Required = new ChecksRequired();
Required.UseContentRemoval = false;
var data = await AddressableResourceProcess.LoadAsGameObjectsAsync(PlayerAddressableID, InstantiationParameters, Required);
List<GameObject> Gameobjects = data.Item1;
if (Gameobjects.Count != 0)
{
if (gameObject.TryGetComponent(out BasisPlayer Player))
foreach (GameObject gameObject in Gameobjects)
{
return Player;
if (gameObject.TryGetComponent(out BasisPlayer Player))
{
return Player;
}
}
}
else
{
Debug.LogError("Missing ");
}
Debug.LogError("Error Missing Player!");
return null;
}
else
{
Debug.LogError("Missing ");
}
Debug.LogError("Error Missing Player!");
return null;
}
}
}
7 changes: 6 additions & 1 deletion Packages/Basis Framework/UI/BasisPointRaycaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ public async Task Initialize(BasisInput basisInput)
}
public async Task CreateRadical()
{
(List<GameObject>, AddressableGenericResource) data = await AddressableResourceProcess.LoadAsGameObjectsAsync(LoadUIRedicalAddress, new UnityEngine.ResourceManagement.ResourceProviders.InstantiationParameters());
ChecksRequired Required = new ChecksRequired
{
UseContentRemoval = false,
DisableAnimatorEvents = false
};
(List<GameObject>, AddressableGenericResource) data = await AddressableResourceProcess.LoadAsGameObjectsAsync(LoadUIRedicalAddress, new UnityEngine.ResourceManagement.ResourceProviders.InstantiationParameters(), Required);
List<GameObject> gameObjects = data.Item1;
if (gameObjects == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ public class BasisRemoteNamePlate : BasisNamePlate
{
public static async Task LoadRemoteNamePlate(BasisRemotePlayer Player, string RemoteNamePlate = "Assets/UI/Prefabs/NamePlate.prefab")
{
var data = await AddressableResourceProcess.LoadAsGameObjectsAsync(RemoteNamePlate, new UnityEngine.ResourceManagement.ResourceProviders.InstantiationParameters());
ChecksRequired Required = new ChecksRequired
{
UseContentRemoval = false,
DisableAnimatorEvents = false
};
var data = await AddressableResourceProcess.LoadAsGameObjectsAsync(RemoteNamePlate, new UnityEngine.ResourceManagement.ResourceProviders.InstantiationParameters(), Required);
List<GameObject> Gameobjects = data.Item1;
if (Gameobjects.Count != 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static List<SceneInstance> LoadAsSceneInstances(AddressableLoadResourceBa
}
return Instantiated;
}
public static async Task<List<GameObject>> LoadAsGameObjectsAsync(AddressableGenericResource loadRequest, InstantiationParameters instantiationParameters)
public static async Task<List<GameObject>> LoadAsGameObjectsAsync(AddressableGenericResource loadRequest, InstantiationParameters instantiationParameters, ChecksRequired Required)
{
List<GameObject> instantiated = new List<GameObject>();
for (int Index = 0; Index < loadRequest.Handles.Count; Index++)
Expand All @@ -29,7 +29,7 @@ public static async Task<List<GameObject>> LoadAsGameObjectsAsync(AddressableGen
object result = await handle.Task;
if (result is GameObject resource)
{
GameObject spawned = Object.Instantiate(resource, instantiationParameters.Position, instantiationParameters.Rotation, instantiationParameters.Parent);
GameObject spawned = ContentPoliceControl.ContentControl(resource, Required, instantiationParameters.Position, instantiationParameters.Rotation, instantiationParameters.Parent);
// Debug.Log("Spawned " + spawned.name + " at " + spawned.transform.position + " with rotation " + spawned.transform.rotation);
instantiated.Add(spawned);
}
Expand All @@ -41,13 +41,13 @@ public static async Task<List<GameObject>> LoadAsGameObjectsAsync(AddressableGen
return instantiated;
}

public static async Task<(List<GameObject>, AddressableGenericResource)> LoadAsGameObjectsAsync(string key, InstantiationParameters instantiationParameters)
public static async Task<(List<GameObject>, AddressableGenericResource)> LoadAsGameObjectsAsync(string key, InstantiationParameters instantiationParameters, ChecksRequired Required)
{
AddressableGenericResource loadRequest = new AddressableGenericResource(key, AddressableExpectedResult.SingleItem);
bool loaded = await AddressableLoadFactory.LoadAddressableResourceAsync<GameObject>(loadRequest);
if (loaded)
{
return ( await LoadAsGameObjectsAsync(loadRequest, instantiationParameters),loadRequest);
return ( await LoadAsGameObjectsAsync(loadRequest, instantiationParameters,Required),loadRequest);
}
else
{
Expand Down
37 changes: 24 additions & 13 deletions Packages/basisdk/Scripts/Content Police/ContentPoliceControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ public static class ContentPoliceControl
/// <returns>A copy of the GameObject with unapproved scripts removed.</returns>
public static GameObject ContentControl(GameObject SearchAndDestroy, ChecksRequired ChecksRequired, Vector3 Position, Quaternion Rotation, Transform Parent = null)
{
GameObject newGameObject = new GameObject("Temp");
newGameObject.SetActive(false);
if (ChecksRequired.UseContentRemoval)
{
GameObject newGameObject = new GameObject("Temp");
newGameObject.SetActive(false);

SearchAndDestroy = GameObject.Instantiate(SearchAndDestroy, Position, Rotation, newGameObject.transform);
// Create a list to hold all components in the original GameObject
UnityEngine.Component[] components = SearchAndDestroy.GetComponentsInChildren<UnityEngine.Component>(true);
Expand All @@ -29,8 +30,7 @@ public static GameObject ContentControl(GameObject SearchAndDestroy, ChecksRequi
{
if (ChecksRequired.DisableAnimatorEvents)
{
Animator Animator = component as Animator;
Animator.fireEvents = false;
animator.fireEvents = false;
}
}
// Check if the component is a MonoBehaviour and not in the approved list
Expand All @@ -45,20 +45,31 @@ public static GameObject ContentControl(GameObject SearchAndDestroy, ChecksRequi
}
}
}
}
// Instantiate the cleaned GameObject copy
if (Parent == null)
{
SearchAndDestroy.transform.parent = null;
SearchAndDestroy.SetActive(true);
}
else
{
SearchAndDestroy.transform.parent = Parent;
SearchAndDestroy.SetActive(true);
}
GameObject.DestroyImmediate(newGameObject);

// Instantiate the cleaned GameObject copy
if (Parent == null)
{
SearchAndDestroy.transform.parent = null;
SearchAndDestroy.SetActive(true);
}
else
{
SearchAndDestroy.transform.parent = Parent;
SearchAndDestroy.SetActive(true);
if (Parent == null)
{
SearchAndDestroy = GameObject.Instantiate(SearchAndDestroy, Position, Rotation);
}
else
{
SearchAndDestroy = GameObject.Instantiate(SearchAndDestroy, Position, Rotation, Parent);
}
}
GameObject.DestroyImmediate(newGameObject);
return SearchAndDestroy;
}
}
Expand Down

0 comments on commit 48cb406

Please sign in to comment.