Sign in or sign up before continuing. Don't have an account yet? Register now to get started.
Register now

Auto refresh assets without refreshing scripts

Another quality of life feature that would be nice is to have an option to auto refresh all assets except scripts..With auto refresh off i have to ctrl+r if i change a sprite or something.

Example code that shows how some assets are not refreshed:

using System.IO;
using Newtonsoft.Json;
using Sirenix.OdinInspector;
using UnityEditor;
using UnityEngine;
public class ExampleClass : MonoBehaviour
{
        public class SmallWrapperClass
        {
                public int a;
                public int b; 
        }
        [SerializeField] private TextAsset textAssetOnTheDisk;
        public int secondInt;
        [Button]
        public void SerializeDataNowButtonInUI()
        {
                SmallWrapperClass smallClassToWriteOnTheDisk = new SmallWrapperClass();
                smallClassToWriteOnTheDisk.a = 10;
                smallClassToWriteOnTheDisk.b = secondInt;

                Debug.Log("Before serializing. Values are a: " + smallClassToWriteOnTheDisk.a + " b: " + smallClassToWriteOnTheDisk.b);
                
                var bigJsonString =
                        JsonConvert.SerializeObject(smallClassToWriteOnTheDisk);
                var p = Application.dataPath;
                var str = AssetDatabase.GetAssetPath(textAssetOnTheDisk);
                str = str.Remove(0, 6);
                var combinedFinalPath = p + str;
                Debug.Log(combinedFinalPath);
                StreamWriter writer = null;
                writer = new StreamWriter(combinedFinalPath, false);
                writer.Write(bigJsonString);
                writer.Close();
                Debug.Log("Writing to the filed completed");
        }
        [Button]
        public void DeserializeFileFromTheDiskAndLogValues()
        {
                var bigJsonInTheFile = textAssetOnTheDisk.ToString();
                Debug.Log(bigJsonInTheFile);
                var wrapperClassDeserialized = JsonConvert.DeserializeObject<SmallWrapperClass>(bigJsonInTheFile);
                Debug.Log("After deserializing. Values are a: " + wrapperClassDeserialized.a + " b: " + wrapperClassDeserialized.b);
        }
}
Edited May 20, 2023 by n12o
Assignee Loading
Time tracking Loading