Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Object Query Cache #11682

Closed
marlenaklein-msft opened this issue Jul 6, 2023 · 1 comment
Closed

Implement Object Query Cache #11682

marlenaklein-msft opened this issue Jul 6, 2023 · 1 comment

Comments

@marlenaklein-msft
Copy link
Contributor

marlenaklein-msft commented Jul 6, 2023

This issue has been migrated a new MRTK repository, and the status of this issue will now be tracked at the following location:


Overview

In MRTK3 implement a generic component object cache. This would be a generic class with a type parameter T. The generic class should be capable is searching for type T, and cache the first found instance of T. T must derive from the Unity Component base class.

Class definition

using UnityEngine;

namespace Microsoft.MixedReality.Toolkit
{
   static class ComponentCache<T> where T : Componet
   {
        private static T cache = null;

        public static T FindFirstInstance()
        {
             _ = TryFindFirstInstance(out T result);
             return result;
        }

        public static bool TryFindFirstInstance(out T result)
        {
            if (cache == null)
            {
               cache = Object.FindFirstObjectByType<T>();
            }

            result  = cache;
            return result  != null;
        }
   }
}

@marlenaklein-msft
Copy link
Contributor Author

Closed with #11686.

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

No branches or pull requests

2 participants