A safe, drop-in replacement for MonoBehaviour as your base class. Each property value is cached and GetComponent will be called if the instance is null or is destroyed.
Inheritance: BaseBehaviour
Exemplo n.º 1
0
 static public int get_camera(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         CacheBehaviour self = (CacheBehaviour)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.camera);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Exemplo n.º 2
0
        private static BindingFlags GetBindingFlags(CacheBehaviour behaviour)
        {
            var result = BindingFlags.Instance | BindingFlags.Public;

            if (behaviour == CacheBehaviour.IncludePrivate)
            {
                result |= BindingFlags.NonPublic;
            }

            return(result);
        }
Exemplo n.º 3
0
        private static IEnumerable <PropertyReader> GetFields(Type type, CacheBehaviour behaviour)
        {
            var bindingFlags = GetBindingFlags(behaviour);
            var fields       = type.GetFields(bindingFlags).AsEnumerable();

            fields = RemoveHiddenFields(fields);

            return(fields
                   .Select(
                       x => new PropertyReader
            {
                Name = x.Name,
                DeclaringType = type,
                Read = o => x.GetValue(o)
            }));
        }
Exemplo n.º 4
0
        private static IEnumerable <PropertyReader> GetProperties(Type type, CacheBehaviour behaviour)
        {
            var bindingFlags = GetBindingFlags(behaviour);
            var properties   = type.GetProperties(bindingFlags).AsEnumerable();

            properties = RemoveHiddenProperties(properties);
            properties = ExcludeIndexProperties(properties);

            return(properties
                   .Select(
                       x => new PropertyReader
            {
                Name = x.Name,
                DeclaringType = type,
                Read = o => x.GetValue(o, null)
            }));
        }
Exemplo n.º 5
0
 private static PropertyReader[] GetPropertiesAndFields(Type type, CacheBehaviour behaviour)
 {
     return(GetProperties(type, behaviour)
            .Concat(GetFields(type, behaviour))
            .ToArray());
 }
Exemplo n.º 6
0
 private static PropertyReader[] GetPropertiesAndFields(Type type, CacheBehaviour behaviour)
 {
     return GetProperties(type, behaviour)
         .Concat(GetFields(type, behaviour))
         .ToArray();
 }
Exemplo n.º 7
0
        private static IEnumerable<PropertyReader> GetProperties(Type type, CacheBehaviour behaviour)
        {
            var bindingFlags = GetBindingFlags(behaviour);
            var properties = type.GetProperties(bindingFlags).AsEnumerable();

            properties = RemoveHiddenProperties(properties);
            properties = ExcludeIndexProperties(properties);

            return properties
                .Select(
                    x => new PropertyReader
                        {
                            Name = x.Name,
                            DeclaringType = type,
                            Read = o => x.GetValue(o, null)
                        });
        }
Exemplo n.º 8
0
        private static IEnumerable<PropertyReader> GetFields(Type type, CacheBehaviour behaviour)
        {
            var bindingFlags = GetBindingFlags(behaviour);
            var fields = type.GetFields(bindingFlags).AsEnumerable();

            fields = RemoveHiddenFields(fields);

            return fields
                .Select(
                    x => new PropertyReader
                        {
                            Name = x.Name,
                            DeclaringType = type,
                            Read = o => x.GetValue(o)
                        });
        }
Exemplo n.º 9
0
        private static BindingFlags GetBindingFlags(CacheBehaviour behaviour)
        {
            var result = BindingFlags.Instance | BindingFlags.Public;

            if (behaviour == CacheBehaviour.IncludePrivate)
            {
                result |= BindingFlags.NonPublic;
            }

            return result;
        }