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 #65

Closed
IssueSyncBot opened this issue Aug 20, 2023 · 1 comment
Closed

Implement Object Query Cache #65

IssueSyncBot opened this issue Aug 20, 2023 · 1 comment
Assignees

Comments

@IssueSyncBot
Copy link

IssueSyncBot commented Aug 20, 2023

Original issue opened by:

@marlenaklein-msft marlenaklein-msft


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;
        }
   }
}


ISSUE MIGRATION

Issue migrated from: microsoft/MixedRealityToolkit-Unity#11682

@IssueSyncBot
Copy link
Author

Original comment by:

@marlenaklein-msft marlenaklein-msft


Closed with #11686.

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

No branches or pull requests

2 participants