示例#1
0
        public static Gesture InstallRandomGestureAsset(IMEPackage package, float minSequenceLength = 0, MERPackageCache cache = null)
        {
            var gestureFiles    = MERUtilities.ListStaticAssets("binary.gestures");
            var randGestureFile = gestureFiles.RandomElement();

            cache ??= new MERPackageCache();
            var gPackage = cache.GetCachedPackageEmbedded(randGestureFile, isFullPath: true);
            var options  = gPackage.Exports.Where(x => x.ClassName == "AnimSequence").ToList();

            // Pick a random element, make sure it's long enough
            var randomGestureExport = options.RandomElement();
            var seqLength           = randomGestureExport.GetProperty <FloatProperty>("SequenceLength");

            int numRetries = 5;

            while (seqLength < minSequenceLength)
            {
                randomGestureExport = options.RandomElement();
                seqLength           = randomGestureExport.GetProperty <FloatProperty>("SequenceLength");
                numRetries--;
            }

            var portedInExp = PackageTools.PortExportIntoPackage(package, randomGestureExport);

            return(new Gesture(portedInExp));
        }
示例#2
0
        public static Gesture InstallRandomFilteredGestureAsset(IMEPackage targetPackage, float minLength = 0, string[] filterKeywords = null, string[] blacklistedKeywords = null, string[] mainPackagesAllowed = null, bool includeSpecial = false, MERPackageCache cache = null)
        {
            var gestureFiles = MERUtilities.ListStaticAssets("binary.gestures", includeSpecial);

            // Special and package file filtering
            if (mainPackagesAllowed != null)
            {
                var newList = new List <string>();
                foreach (var gf in gestureFiles)
                {
                    if (includeSpecial && gf.Contains("gestures.special."))
                    {
                        newList.Add(gf);
                        continue;
                    }

                    var packageName = Path.GetFileNameWithoutExtension(MERUtilities.GetFilenameFromAssetName(gf));
                    if (mainPackagesAllowed.Contains(packageName))
                    {
                        newList.Add(gf);
                        continue;
                    }
                }

                gestureFiles = newList;
            }

            // Pick a random package
            var randGestureFile = gestureFiles.RandomElement();
            var hasCache        = cache != null;

            cache ??= new MERPackageCache();
            var gPackage = cache.GetCachedPackageEmbedded(randGestureFile, isFullPath: true);
            List <ExportEntry> options;

            if (filterKeywords != null && blacklistedKeywords != null)
            {
                options = gPackage.Exports.Where(x => x.ClassName == "AnimSequence" &&
                                                 x.ObjectName.Name.ContainsAny(StringComparison.InvariantCultureIgnoreCase, filterKeywords) &&
                                                 !x.ObjectName.Name.ContainsAny(blacklistedKeywords)).ToList();
            }
            else if (filterKeywords != null)
            {
                options = gPackage.Exports.Where(x => x.ClassName == "AnimSequence" &&
                                                 x.ObjectName.Name.ContainsAny(StringComparison.InvariantCultureIgnoreCase, filterKeywords)).ToList();
            }
            else if (blacklistedKeywords != null)
            {
                options = gPackage.Exports.Where(x => x.ClassName == "AnimSequence" &&
                                                 !x.ObjectName.Name.ContainsAny(blacklistedKeywords)).ToList();
            }
            else
            {
                options = gPackage.Exports.Where(x => x.ClassName == "AnimSequence").ToList();
            }

            if (options.Any())
            {
                // Pick a random element
                var randomGestureExport = options.RandomElement();

                // Filter it out if we cannot use it
                var seqLength = randomGestureExport.GetProperty <FloatProperty>("SequenceLength");

                int numRetries = 7;
                while (seqLength < minLength && numRetries >= 0)
                {
                    randomGestureExport = options.RandomElement();
                    seqLength           = randomGestureExport.GetProperty <FloatProperty>("SequenceLength");
                    numRetries--;
                }

                var portedInExp = PackageTools.PortExportIntoPackage(targetPackage, randomGestureExport);
                if (!hasCache)
                {
                    cache.ReleasePackages();
                }

                return(new Gesture(portedInExp));
            }

            return(null);
        }