示例#1
0
        public override void OnInspectorGUI()
        {
            if (serializedObject.FindProperty("updateOnReloadScripts").boolValue)
            {
                GUILayout.Label("Updating...");
            }
            else
            {
                if (GUILayout.Button("Sync with EditorResources folder"))
                {
                    FungusEditorResources.GenerateResourcesScript();
                }

                DrawDefaultInspector();
            }
        }
示例#2
0
 private static void OnPostprocessAllAssets(string[] importedAssets, string[] _, string[] __, string[] ___)
 {
     foreach (var path in importedAssets)
     {
         if (path.EndsWith("FungusEditorResources.asset"))
         {
             var asset = AssetDatabase.LoadAssetAtPath(path, typeof(FungusEditorResources)) as FungusEditorResources;
             if (asset != null)
             {
                 FungusEditorResources.UpdateTextureReferences(asset);
                 AssetDatabase.SaveAssets();
                 return;
             }
         }
     }
 }
示例#3
0
        internal static void UpdateTextureReferences(FungusEditorResources 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;

            // The ApplyModifiedPropertiesWithoutUndo() function wasn't documented until Unity 5.2
#if UNITY_5_0 || UNITY_5_1
            var flags       = BindingFlags.Instance | BindingFlags.NonPublic;
            var applyMethod = typeof(SerializedObject).GetMethod("ApplyModifiedPropertiesWithoutUndo", flags);
            applyMethod.Invoke(serializedObject, null);
#else
            serializedObject.ApplyModifiedPropertiesWithoutUndo();
#endif
        }