private void Awake() { InteractionRigProvider rigProvider = null; if (enforcedProvider != null) { rigProvider = enforcedProvider; } else if (PossibleInteractionRigs != null) { rigProvider = FindAvailableInteractionRig(); } if (rigProvider != null) { rigProvider.PreSetup(); Vector3 position = Vector3.zero; Quaternion rotation = new Quaternion(); if (DummyTrainee != null) { position = DummyTrainee.transform.position; rotation = DummyTrainee.transform.rotation; DestroyImmediate(DummyTrainee); } GameObject prefab = rigProvider.GetPrefab(); if (prefab != null) { GameObject instance = Instantiate(rigProvider.GetPrefab()); instance.name = instance.name.Replace("(Clone)", ""); instance.transform.position = position; instance.transform.rotation = rotation; } rigProvider.OnSetup(); } else if (DummyTrainee != null) { DestroyImmediate(DummyTrainee); } Destroy(gameObject); }
private InteractionRigProvider FindAvailableInteractionRig() { IEnumerable <InteractionRigProvider> availableRigs = ReflectionUtils.GetConcreteImplementationsOf <InteractionRigProvider>() .Select(type => (InteractionRigProvider)ReflectionUtils.CreateInstanceOfType(type)) .Where(provider => provider.CanBeUsed()); foreach (RigInfo rigInfo in PossibleInteractionRigs) { if (rigInfo.Enabled) { InteractionRigProvider provider = availableRigs.FirstOrDefault(p => p.Name == rigInfo.Name); if (provider != null) { return(provider); } } } return(null); }
/// <summary> /// Enforces the giving Rig to be used, if possible. /// </summary> /// <param name="prefab">Prefab of the rig to be used.</param> public static void SetEnforcedInteractionRig(InteractionRigProvider provider) { enforcedProvider = provider; }