Ejemplo n.º 1
0
        /// <summary>
        /// Save the specified settings to the Unity project.
        /// Editor only.
        /// </summary>
        /// <param name="save">The settings to save</param>
        public static void SaveAsset(DynamicCSharp save)
        {
#if UNITY_EDITOR && UNITY_WEBPLAYER == false
            // Check for existing
            if (AssetDatabase.Contains(save) == false)
            {
                // Get the full path
                string fullPath = Path.Combine(InstallLocation + editorSettingsDirectory, settingsLocation + ".asset");

                // Locate the file info
                FileInfo info = new FileInfo(fullPath);

                // Get the directory for the file
                DirectoryInfo dir = info.Directory;

                // Make sure the directory exists
                if (dir.Exists == false)
                {
                    dir.Create();
                }

                // Create the asset
                AssetDatabase.CreateAsset(save, fullPath);

                // Import the folder
                AssetDatabase.Refresh();
            }

            // Mark as dirty
            EditorUtility.SetDirty(save);

            // Save assets
            AssetDatabase.SaveAssets();
#endif
        }
Ejemplo n.º 2
0
        private static void CreateNewSettings()
        {
            // Create an instance
            DynamicCSharp asset = ScriptableObject.CreateInstance <DynamicCSharp>();

            // Get the full path
            string fullPath = Path.Combine(editorSettingsDirectory, settingsLocation);

            // Create an asset id at the path
            string id = AssetDatabase.GenerateUniqueAssetPath(fullPath);

            // Create the asset
            AssetDatabase.CreateAsset(asset, id);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Load the settings from the Unity project.
        /// Editor only.
        /// </summary>
        public static void LoadAsset()
        {
#if UNITY_EDITOR && UNITY_WEBPLAYER == false
            // Get the full path
            string fullPath = Path.Combine(InstallLocation + editorSettingsDirectory, settingsLocation + ".asset");

            // Try to load the asset
            DynamicCSharp result = AssetDatabase.LoadAssetAtPath(fullPath, typeof(DynamicCSharp)) as DynamicCSharp;

            // Check for error
            if (result == null)
            {
                Debug.LogWarning("Failed to load settings from '" + fullPath + "'");
            }

            // Load into active settings
            instance = result;
#endif
        }