Skip to content

Implement Object Query Cache #11682

Closed
Closed
@marlenaklein-msft

Description

@marlenaklein-msft

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

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions