Beispiel #1
0
        //[UnityEditor.MenuItem("Tools/Vexe/CompileAsm")]
        //public static void CompileAsm()
        //{
        //var types = ReflectionHelper.CachedGetRuntimeTypes().Concat(ReflectionHelper.GetUnityEngineTypes()).ToList();
        //var types = ReflectionHelper.CachedGetRuntimeTypes().ToList();
        //var serializer = new FastSerializer();
        //var adapters = new IBaseSerializer[] { new UnityObjectSerializer() };
        //serializer.CompileAssembly(types, adapters, new VFWPredicates(), "SerTest", "Assets", "SERIALIZER");
        //UnityEditor.AssetDatabase.ImportAsset("Assets/SerTest.dll", UnityEditor.ImportAssetOptions.ForceUpdate);
        //}
#endif

        static ALPHA_FastSerializerBackend()
        {
            var types        = ReflectionHelper.CachedGetRuntimeTypes().ToList();
            var serializsers = new IBaseSerializer[] { new UnityObjectSerializer() };

            Serializer = FastSerializer.CompileDynamic(types, serializsers, new VFWPredicates());
        }
        protected override void Initialize()
        {
            string fromMember = attribute.PopulateFrom;

            if (fromMember.IsNullOrEmpty())
            {
                _values           = attribute.values;
                _showUpdateButton = false;
            }
            else
            {
                _showUpdateButton = !attribute.HideUpdate;
                Type populateFrom;
                var  split = fromMember.Split('.');
                if (split.Length == 1)
                {
                    populateFrom = targetType;
                }
                else
                {
                    if (split[0].ToLower() == kOwnerTypePrefix)                     // populate from unityTarget
                    {
                        populateFrom        = unityTarget.GetType();
                        _populateFromTarget = true;
                    }
                    else                     // populate from type (member should be static)
                    {
                        var typeName = split[0];
                        populateFrom = ReflectionHelper.CachedGetRuntimeTypes()
                                       .FirstOrDefault(x => x.Name == typeName);

                        if (populateFrom == null)
                        {
                            throw new InvalidOperationException("Couldn't find type to populate the popup from " + typeName);
                        }

                        _populateFromType = true;
                    }

                    fromMember = split[1];
                }

                var all       = populateFrom.GetAllMembers(typeof(object));
                var popMember = all.FirstOrDefault(x => attribute.CaseSensitive ? x.Name == fromMember : x.Name.ToLower() == fromMember.ToLower());
                if (popMember == null)
                {
                    ErrorHelper.MemberNotFound(populateFrom, fromMember);
                }

                var field = popMember as FieldInfo;
                if (field != null)
                {
                    _populateMember = (popMember as FieldInfo).DelegateForGet();
                }
                else
                {
                    var prop = popMember as PropertyInfo;
                    if (prop != null)
                    {
                        _populateMember = (popMember as PropertyInfo).DelegateForGet();
                    }
                    else
                    {
                        var method = popMember as MethodInfo;
                        if (method == null)
                        {
                            throw new Exception("{0} is not a field, nor a property nor a method!".FormatWith(fromMember));
                        }

                        _populateMethod = (popMember as MethodInfo).DelegateForCall();
                    }
                }
            }
        }