Example #1
0
        private static void PopulateTypes(AssetType excludeType, ICollection <Type> types, AssetType assetType)
        {
            var type = GetMatchingType(assetType);

            if (excludeType.HasFlag(assetType))
            {
                types.Add(type);
            }
            else
            {
                types.Remove(type);
            }
        }
        public bool IsAssetOfType(string assetPath, AssetType assetTypeMask, bool isDeleted)
        {
            if (assetTypeMask.HasFlag(AssetType.Scene) && assetPath.EndsWith(".unity", StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            if (assetTypeMask.HasFlag(AssetType.TerrainData) && AssetDatabase.LoadAssetAtPath <TerrainData>(assetPath))
            {
                return(true);
            }



            if (assetTypeMask.HasFlag(AssetType.Prefab) || assetTypeMask.HasFlag(AssetType.Model))
            {
                var go = AssetDatabase.LoadMainAssetAtPath(assetPath) as GameObject;

                if (go)
                {
#if UNITY_2018_1_OR_NEWER
                    var prefabType = PrefabUtility.GetPrefabAssetType(go);

                    if (assetTypeMask.HasFlag(AssetType.Prefab))
                    {
                        return(prefabType == PrefabAssetType.Regular || prefabType == PrefabAssetType.Variant);
                    }

                    if (assetTypeMask.HasFlag(AssetType.Model))
                    {
                        return(prefabType == PrefabAssetType.Model);
                    }
#else
                    var prefabType = PrefabUtility.GetPrefabType(go);
                    if (assetTypeMask.HasFlag(AssetType.Prefab))
                    {
                        return(prefabType == PrefabType.Prefab);
                    }

                    if (assetTypeMask.HasFlag(AssetType.Model))
                    {
                        return(prefabType == PrefabType.ModelPrefab);
                    }
#endif
                }

                if (isDeleted)
                {
                    if (assetTypeMask.HasFlag(AssetType.Prefab) && assetPath.EndsWith(".prefab", StringComparison.OrdinalIgnoreCase))
                    {
                        return(true);
                    }

                    // Most popular models?
                    if (assetTypeMask.HasFlag(AssetType.Model) && assetPath.EndsWith(".fbx", StringComparison.OrdinalIgnoreCase))
                    {
                        return(true);
                    }
                    if (assetTypeMask.HasFlag(AssetType.Model) && assetPath.EndsWith(".dae", StringComparison.OrdinalIgnoreCase))
                    {
                        return(true);
                    }
                    if (assetTypeMask.HasFlag(AssetType.Model) && assetPath.EndsWith(".3ds", StringComparison.OrdinalIgnoreCase))
                    {
                        return(true);
                    }
                    if (assetTypeMask.HasFlag(AssetType.Model) && assetPath.EndsWith(".obj", StringComparison.OrdinalIgnoreCase))
                    {
                        return(true);
                    }
                }
            }

            if (assetTypeMask.HasFlag(AssetType.Mesh) && AssetDatabase.LoadAssetAtPath <Mesh>(assetPath))
            {
                return(true);
            }


            if (assetTypeMask.HasFlag(AssetType.Material) && assetPath.EndsWith(".mat", StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            if (assetTypeMask.HasFlag(AssetType.Texture) && AssetDatabase.LoadAssetAtPath <Texture>(assetPath))
            {
                return(true);
            }

            // Most popular extensions?
            if (assetTypeMask.HasFlag(AssetType.Texture) && isDeleted && assetPath.EndsWith(".psd", StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }
            if (assetTypeMask.HasFlag(AssetType.Texture) && isDeleted && assetPath.EndsWith(".png", StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }
            if (assetTypeMask.HasFlag(AssetType.Texture) && isDeleted && assetPath.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }
            if (assetTypeMask.HasFlag(AssetType.Texture) && isDeleted && assetPath.EndsWith(".tga", StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }
            if (assetTypeMask.HasFlag(AssetType.Texture) && isDeleted && assetPath.EndsWith(".tiff", StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }
            if (assetTypeMask.HasFlag(AssetType.Texture) && isDeleted && assetPath.EndsWith(".iff", StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }



            if (assetTypeMask.HasFlag(AssetType.Animation) && AssetDatabase.LoadAssetAtPath <AnimationClip>(assetPath))
            {
                return(true);
            }
            if (assetTypeMask.HasFlag(AssetType.Animation) && isDeleted && assetPath.EndsWith(".anim", StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            if (assetTypeMask.HasFlag(AssetType.Animator) && AssetDatabase.LoadAssetAtPath <RuntimeAnimatorController>(assetPath))
            {
                return(true);
            }
            if (assetTypeMask.HasFlag(AssetType.Animator) && isDeleted && assetPath.EndsWith(".controller", StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }
            if (assetTypeMask.HasFlag(AssetType.Animator) && isDeleted && assetPath.EndsWith(".overrideController", StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }



            if (assetTypeMask.HasFlag(AssetType.Script) && (
                    assetPath.EndsWith(".cs", StringComparison.OrdinalIgnoreCase)

                    || assetPath.EndsWith(".c", StringComparison.OrdinalIgnoreCase) ||                          // For hard-core players
                    assetPath.EndsWith(".cpp", StringComparison.OrdinalIgnoreCase) ||                           // For hard-core players
                    assetPath.EndsWith(".h", StringComparison.OrdinalIgnoreCase) ||                             // For hard-core players
                    assetPath.EndsWith(".hpp", StringComparison.OrdinalIgnoreCase)                              // For hard-core players

                    || assetPath.EndsWith(".js", StringComparison.OrdinalIgnoreCase) ||                         // No one uses this!
                    assetPath.EndsWith(".boo", StringComparison.OrdinalIgnoreCase)                              // No one uses this!
                    )
                )
            {
                return(true);
            }

#if UNITY_2019_3_OR_NEWER
            if (assetTypeMask.HasFlag(AssetType.UIElementsAssets) && AssetDatabase.LoadAssetAtPath <UnityEngine.UIElements.StyleSheet>(assetPath))
            {
                return(true);
            }

            if (assetTypeMask.HasFlag(AssetType.UIElementsAssets) && AssetDatabase.LoadAssetAtPath <UnityEngine.UIElements.VisualTreeAsset>(assetPath))
            {
                return(true);
            }
#endif
            if (assetTypeMask.HasFlag(AssetType.Shader) && assetPath.EndsWith(".shader", StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            if (assetTypeMask.HasFlag(AssetType.ScriptableObject) && AssetDatabase.LoadAssetAtPath <ScriptableObject>(assetPath))
            {
                return(true);
            }
            if (assetTypeMask.HasFlag(AssetType.ScriptableObject) && isDeleted && assetPath.EndsWith(".asset", StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }



            if (assetTypeMask.HasFlag(AssetType.Audio) && AssetDatabase.LoadAssetAtPath <AudioClip>(assetPath))
            {
                return(true);
            }

            if (assetTypeMask.HasFlag(AssetType.Video) && AssetDatabase.LoadAssetAtPath <UnityEngine.Video.VideoClip>(assetPath))
            {
                return(true);
            }

#if UNITY_2018_4 || USE_TIMELINE
            if (assetTypeMask.HasFlag(AssetType.TimeLineAssets) && AssetDatabase.LoadAssetAtPath <UnityEngine.Timeline.TimelineAsset>(assetPath))
            {
                return(true);
            }
            if (assetTypeMask.HasFlag(AssetType.TimeLineAssets) && AssetDatabase.LoadAssetAtPath <UnityEngine.Timeline.TrackAsset>(assetPath))
            {
                return(true);
            }
            if (assetTypeMask.HasFlag(AssetType.TimeLineAssets) && AssetDatabase.LoadAssetAtPath <UnityEngine.Playables.PlayableAsset>(assetPath))
            {
                return(true);
            }
#endif

            return(false);
        }
Example #3
0
        public List <AssetSearchResultItem> SearchAsset(AddonPackage pPackage)
        {
            List <AssetSearchResultItem> found = new List <AssetSearchResultItem>();

            AssetSearchResultItem baseResultItem = new AssetSearchResultItem()
            {
                AddonName      = pPackage.Name,
                AddonPublisher = pPackage.Publisher,
                Free           = pPackage.Free,
                Location       = pPackage.Location
            };

            baseResultItem.Installed   = (pPackage.AddonFormat == AddonPackageFormat.InstalledFolder);
            baseResultItem.ContentPack = pPackage.Location.ToLower().StartsWith(ContentPacksPath);

            if ((pPackage.BodyModelsSummary?.Puppets?.Puppets.Count ?? 0) > 0)
            {
                if (AssetType.HasFlag(AddonAssetType.BodyPart))
                {
                    SearchBodyParts(pPackage.BodyModelsSummary.Puppets.Puppets, baseResultItem, found);
                }

                if (AssetType.HasFlag(AddonAssetType.Decal))
                {
                    SearchDecals(pPackage.BodyModelsSummary.Puppets.Puppets, baseResultItem, found);
                }
            }

            if (AssetType.HasFlag(AddonAssetType.Prop) && ((pPackage.PropModelsSummary.Props?.Props.Count ?? 0) > 0))
            {
                SearchProps(pPackage.PropModelsSummary.Props.Props, baseResultItem, found);
            }

            if (AssetType.HasFlag(AddonAssetType.Verb) && (pPackage.VerbsSummary?.Verbs.HasData ?? false))
            {
                SearchVerbs(pPackage.VerbsSummary.Verbs, baseResultItem, found);
            }


            if (AssetType.HasFlag(AddonAssetType.Animation))
            {
                SearchAnimations(pPackage.AssetManifest, baseResultItem, found);
            }

            if (AssetType.HasFlag(AddonAssetType.CuttingRoomAsset))
            {
                SearchCuttingRoomAssets(pPackage.CuttingRoomAssetsSummary, baseResultItem, found);
            }

            if (AssetType.HasFlag(AddonAssetType.Material) && (((pPackage.Materials?.Count ?? 0) > 0)))
            {
                SearchCommon(pPackage.Materials, AddonAssetType.Material, baseResultItem, found);
            }


            if (AssetType.HasFlag(AddonAssetType.Sound) && (((pPackage.Sounds?.Count ?? 0) > 0)))
            {
                SearchCommon(pPackage.Sounds, AddonAssetType.Sound, baseResultItem, found);
            }

            if (AssetType.HasFlag(AddonAssetType.SpecialEffect) && (((pPackage.SpecialEffects?.Count ?? 0) > 0)))
            {
                SearchCommon(pPackage.SpecialEffects, AddonAssetType.SpecialEffect, baseResultItem, found);
            }

            /*
             * if (AssetType.HasFlag(AddonAssetType.CuttingRoomAsset) && (((pPackage.Filters?.Count ?? 0) > 0)))
             * {
             *  SearchCommon(pPackage.Filters, AddonAssetType.CuttingRoomAsset, baseResultItem, found);
             * }
             */

            if (AssetType.HasFlag(AddonAssetType.SkyTexture) && (((pPackage.SkyTextures?.Count ?? 0) > 0)))
            {
                SearchCommon(pPackage.SkyTextures, AddonAssetType.SkyTexture, baseResultItem, found);
            }

            if (AssetType.HasFlag(AddonAssetType.OtherAsset) && (((pPackage.OtherAssets?.Count ?? 0) > 0)))
            {
                SearchCommon(pPackage.OtherAssets, AddonAssetType.OtherAsset, baseResultItem, found);
            }



            if (AssetType.HasFlag(AddonAssetType.Stock) && (((pPackage.StockAssets?.Count ?? 0) > 0)))
            {
                SearchCommon(pPackage.StockAssets, AddonAssetType.Stock, baseResultItem, found);
            }

            if (AssetType.HasFlag(AddonAssetType.StartMovie) && (((pPackage.DemoMovies?.Count ?? 0) > 0)))
            {
                SearchCommon2(pPackage.DemoMovies, AddonAssetType.StartMovie, baseResultItem, found);
            }


            return(found.Count > 0 ? found : null);
        }