예제 #1
0
        void ReimportNonReadonlyTextures(IEnumerable <Material> allMaterials)
        {
            IEnumerable <Texture> allTextures = allMaterials.SelectMany(X => ShaderPropertyUtility.GetAllTextures(X)).Distinct();

            AssetPostprocessor postProcessor = new AssetPostprocessor();

            float currentCount = 0.0f;
            int   targetCount  = allTextures.Count();

            foreach (Texture t in allTextures)
            {
                EditorUtility.DisplayProgressBar("Turning Off Readonly", "Analyzing texture " + ((int)currentCount + 1).ToString() + " of " + targetCount.ToString(), currentCount / targetCount);
                currentCount += 1;
                string assetPath = AssetDatabase.GetAssetPath(t);

                if (assetPath != null)
                {
                    postProcessor.assetPath = assetPath;
                    TextureImporter importer = (TextureImporter)postProcessor.assetImporter;
                    if (importer != null && !importer.isReadable)
                    {
                        importer.isReadable    = true;
                        importer.textureFormat = TextureImporterFormat.ARGB32;
                        AssetDatabase.ImportAsset(assetPath);
                        AssetDatabase.Refresh();
                    }
                }
            }

            EditorUtility.ClearProgressBar();
        }
        void OnEnable()
        {
            drawCallTarget            = target as DrawCallMinimizer;
            destroyOriginalGameObject = serializedObject.FindProperty("destroyOriginalGameObject");
            textureAtlasProperties    = serializedObject.FindProperty("_textureAtlasProperties");
            skipAtlasingTextures      = serializedObject.FindProperty("skipTextureAtlasing");
            propertiesToLookFor       = drawCallTarget.textureAtlasProperties;

            if (propertiesToLookFor == null)
            {
                propertiesToLookFor = new DrawCallMinimizerInfo();
            }
            IEnumerable <string> propertiesList = ShaderPropertyUtility.GetUniqueShaderPropertyNames(drawCallTarget.GetComponentsInChildren <Renderer>().Select(X => X.sharedMaterial).Distinct());

            //here we clear out properties that are no longer referenced
            IList <ShaderProperties> activeProperties = propertiesToLookFor.shaderPropertiesToLookFor.Where(x => propertiesList.Contains(x.propertyName)).ToList();

            //then we figure out which properties still need to be added to the list
            propertiesList = propertiesList.Where(x => !activeProperties.Select(property => property.propertyName).Contains(x));

            foreach (string s in propertiesList)
            {
                activeProperties.Add(new ShaderProperties(false, s));
            }

            propertiesToLookFor.shaderPropertiesToLookFor = activeProperties;
            serializedObject.ApplyModifiedProperties();
            ReimportNonReadonly();
            //Reimport anything that is needed
        }
예제 #3
0
        /// <summary>
        /// Shows the list of objects that you have chosen to combine
        /// </summary>
        private void ShowObjectsList()
        {
            if (GUILayout.Button(new GUIContent("Combined Objects" + (_isShowingObjectsList ? string.Empty : " (Hidden)")), ReorderableListGUI.defaultTitleStyle, GUILayout.Height(20f)))
            {
                _isShowingObjectsList = !_isShowingObjectsList;
            }

            if (_isShowingObjectsList)
            {
                GUILayout.Space(-6);
                EditorGUI.BeginChangeCheck();
                ReorderableListGUI.ListField <GameObject> (_combinedObjects, PropertyItemDrawer);
                if (EditorGUI.EndChangeCheck())
                {
                    //get all shader properties
                    IEnumerable <GameObject> validGameObjects = _combinedObjects.Select(currentObject => currentObject).
                                                                Where(currentObject => currentObject != null);

                    IEnumerable <Material> uniqueMaterials = validGameObjects.SelectMany(currentObject => currentObject.GetComponentsInChildren <Renderer> ().Select(currentRenderer => currentRenderer.sharedMaterial)).Distinct();

                    IEnumerable <string> propertiesList = ShaderPropertyUtility.GetUniqueShaderPropertyNames(uniqueMaterials);

                    //here we clear out properties that are no longer referenced
                    List <ShaderProperties> activeShaderProperties = _textureAtlasProperties.shaderPropertiesToLookFor.Where(x => propertiesList.Contains(x.propertyName)).ToList();

                    //then we figure out which properties still need to be added to the list
                    propertiesList = propertiesList.Where(x => !activeShaderProperties.Select(property => property.propertyName).Contains(x));

                    foreach (string s in propertiesList)
                    {
                        activeShaderProperties.Add(new ShaderProperties(false, s));
                    }

                    _textureAtlasProperties.shaderPropertiesToLookFor = activeShaderProperties;

                    if (!_combinedObjects.Contains(null))
                    {
                        Undo.RegisterCompleteObjectUndo(_combinedObjects.ToArray(), "UNDOOOOOO");
                        CombineSelectedObjects();
                    }
                    UpdateFoldoutsCount();

                    IEnumerable <Mesh> allMeshes = validGameObjects.SelectMany(currentObject => currentObject.GetComponentsInChildren <MeshFilter> ().Select(currentMeshFilter => currentMeshFilter.sharedMesh)).Distinct();

                    ReimportNonReadableMeshes(allMeshes);
                }
            }
        }