Exemplo n.º 1
0
        private static bool CheckAffectedAsset(string affectedAsset, AssetRule assetRule, int selectedSelective)
        {
            SerializedObject assetImporterSO = null;
            SerializedObject ruleImporterSO  = null;

            if (TypeFromAssetType(assetRule.assetType) == typeof(Texture))
            {
                TextureImporter assetimporter =
                    AssetImporter.GetAtPath(affectedAsset) as
                    TextureImporter;

                // this may happen (e.g. render texture)
                if (assetimporter == null)
                {
                    return(false);
                }

                TextureImporter ruleimporter =
                    AssetImporter.GetAtPath(AssetDatabase.GUIDToAssetPath(assetRule.AssetGuid)) as
                    TextureImporter;

                if (assetimporter.GetInstanceID() == ruleimporter.GetInstanceID())
                {
                    return(false); // this shouldnt happen but is a nice failsafe
                }
                assetImporterSO = new SerializedObject(assetimporter);
                ruleImporterSO  = new SerializedObject(ruleimporter);
            }

            if (TypeFromAssetType(assetRule.assetType) == typeof(GameObject))
            {
                ModelImporter assetimporter =
                    AssetImporter.GetAtPath(affectedAsset) as
                    ModelImporter;
                ModelImporter ruleimporter =
                    AssetImporter.GetAtPath(AssetDatabase.GUIDToAssetPath(assetRule.AssetGuid)) as
                    ModelImporter;

                if (assetimporter.GetInstanceID() == ruleimporter.GetInstanceID())
                {
                    return(false); // this shouldnt happen but is a nice failsafe
                }
                assetImporterSO = new SerializedObject(assetimporter);
                ruleImporterSO  = new SerializedObject(ruleimporter);
            }

            if (TypeFromAssetType(assetRule.assetType) == typeof(AudioClip))
            {
                AudioImporter assetimporter =
                    AssetImporter.GetAtPath(affectedAsset) as
                    AudioImporter;
                AudioImporter ruleimporter =
                    AssetImporter.GetAtPath(AssetDatabase.GUIDToAssetPath(assetRule.AssetGuid)) as
                    AudioImporter;

                if (assetimporter.GetInstanceID() == ruleimporter.GetInstanceID())
                {
                    return(false); // this shouldnt happen but is a nice failsafe
                }
                assetImporterSO = new SerializedObject(assetimporter);
                ruleImporterSO  = new SerializedObject(ruleimporter);
            }

            if (assetImporterSO == null || ruleImporterSO == null)
            {
                return(false);                                                   // TODO log message here
            }
            if (!assetRule.SelectiveMode || assetRule.SelectiveProperties.Count <= 0)
            {
                return(CompareSerializedObject(assetImporterSO, ruleImporterSO));
            }
            string property = assetRule.SelectiveProperties[selectedSelective];

            string realname = GetPropertyNameFromDisplayName(assetImporterSO, property);

            SerializedProperty foundAssetSP = assetImporterSO.FindProperty(realname);

            SerializedProperty assetRuleSP = ruleImporterSO.FindProperty(realname);

            return(CompareSerializedProperty(foundAssetSP, assetRuleSP));
        }