Esempio n. 1
0
        public static ulong ComputeVariantHash(Type variantType, GhostComponentVariationAttribute attribute)
        {
            var hash = Entities.TypeHash.FNV1A64(attribute.GetType().FullName);
            var componentTypeName = attribute.ComponentType.FullName.Replace("+", "/");
            var variantName       = variantType.FullName.Replace("+", "/");

            hash = Entities.TypeHash.CombineFNV1A64(hash, Entities.TypeHash.FNV1A64(componentTypeName));
            hash = Entities.TypeHash.CombineFNV1A64(hash, Entities.TypeHash.FNV1A64(variantName));
            return(hash);
        }
Esempio n. 2
0
        public static void InitVariantCache()
        {
            VariantsCache = new Dictionary <string, List <VariantEntry> >();
            //Traverse all pertinent assemblies (netcode or netcode referecens) and fetch any struct with GhostComponentVariationAttribute
            var assemblies = System.AppDomain.CurrentDomain.GetAssemblies().Where(a =>
            {
                return(a.GetName().Name.StartsWith("Unity.NetCode") ||
                       a.GetReferencedAssemblies().Any(r => r.Name == "Unity.NetCode"));
            });

            foreach (var a in assemblies)
            {
                foreach (var t in a.GetExportedTypes())
                {
                    var variant = t.GetCustomAttribute <GhostComponentVariationAttribute>();
                    if (variant == null)
                    {
                        continue;
                    }
                    variant.VariantHash = GhostComponentVariationAttribute.ComputeVariantHash(t, variant);
                    if (string.IsNullOrEmpty(variant.DisplayName))
                    {
                        variant.DisplayName = t.FullName;
                    }
                    if (!VariantsCache.TryGetValue(variant.ComponentType.FullName, out var list))
                    {
                        list = new List <VariantEntry>();
                        //Add a default entry
                        list.Add(new VariantEntry
                        {
                            Attribute   = new GhostComponentVariationAttribute(variant.ComponentType),
                            VariantType = null
                        }
                                 );
                        VariantsCache.Add(variant.ComponentType.FullName, list);
                    }
                    list.Add(new VariantEntry
                    {
                        Attribute   = variant,
                        VariantType = t
                    });
                }
            }
        }