Пример #1
0
        internal static void UpdateTextureReferences(MerinoEditorResources instance)
        {
            // Iterate through all fields in instance and set texture references
            var serializedObject = new SerializedObject(instance);
            var prop             = serializedObject.GetIterator();
            var rootFolder       = new [] { GetRootFolder() };

            prop.NextVisible(true);
            while (prop.NextVisible(false))
            {
                if (prop.propertyType == SerializedPropertyType.Generic)
                {
                    var guids = AssetDatabase.FindAssets(prop.name + " t:Texture2D", rootFolder);
                    var paths = guids.Select(guid => AssetDatabase.GUIDToAssetPath(guid)).Where(
                        path => path.Contains(prop.name + ".")
                        );

                    foreach (var path in paths)
                    {
                        var texture = AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture2D;
                        if (path.ToLower().Contains("/pro/"))
                        {
                            prop.FindPropertyRelative("pro").objectReferenceValue = texture;
                        }
                        else
                        {
                            prop.FindPropertyRelative("free").objectReferenceValue = texture;
                        }
                    }
                }
            }

            serializedObject.FindProperty("updateOnReloadScripts").boolValue = false;
            serializedObject.ApplyModifiedPropertiesWithoutUndo();
        }
Пример #2
0
 private static void OnPostprocessAllAssets(string[] importedAssets, string[] _, string[] __, string[] ___)
 {
     foreach (var path in importedAssets)
     {
         if (path.EndsWith("MerinoEditorResources.asset"))
         {
             var asset = AssetDatabase.LoadAssetAtPath(path, typeof(MerinoEditorResources)) as MerinoEditorResources;
             if (asset != null)
             {
                 MerinoEditorResources.UpdateTextureReferences(asset);
                 AssetDatabase.SaveAssets();
                 return;
             }
         }
     }
 }
Пример #3
0
        public override void OnInspectorGUI()
        {
            if (serializedObject.FindProperty("updateOnReloadScripts").boolValue)
            {
                GUILayout.Label("Updating...");
            }
            else
            {
                if (GUILayout.Button("Sync with EditorResources folder"))
                {
                    MerinoEditorResources.GenerateResourcesScript();
                }

                DrawDefaultInspector();
            }
        }