generated from max/template-unity-project
Basic split saving and loading of scene files
This commit is contained in:
parent
a335984b1c
commit
bdbfaf34c0
8
Editor.meta
Normal file
8
Editor.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 610c555885ab54a4bb3fb07faa93d1c8
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
24
Editor/ScenePartitionSO.cs
Normal file
24
Editor/ScenePartitionSO.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace VertexColor.ScenePartition
|
||||||
|
{
|
||||||
|
[CreateAssetMenu(fileName = "Scene", menuName = "Max/ScenePartitionSO")]
|
||||||
|
public class ScenePartitionSO : ScriptableObject
|
||||||
|
{
|
||||||
|
[field: SerializeField]
|
||||||
|
public SceneAsset sceneAsset { get; private set; } = null;
|
||||||
|
public string sceneName { get; private set; } = "";
|
||||||
|
|
||||||
|
private List<string> loadedPartitions = new List<string>();
|
||||||
|
|
||||||
|
private void OnValidate()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(sceneName) && sceneAsset != null)
|
||||||
|
{
|
||||||
|
sceneName= sceneAsset.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Editor/ScenePartitionSO.cs.meta
Normal file
11
Editor/ScenePartitionSO.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 247a42f35aa1a81489369b19a7b1a706
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
48
Editor/ScenePartitionSOEditor.cs
Normal file
48
Editor/ScenePartitionSOEditor.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace VertexColor.ScenePartition.Editor
|
||||||
|
{
|
||||||
|
[CustomEditor(typeof(ScenePartitionSO))]
|
||||||
|
public class ScenePartitionSOEditor : UnityEditor.Editor
|
||||||
|
{
|
||||||
|
//SerializedProperty property;
|
||||||
|
|
||||||
|
void OnEnable()
|
||||||
|
{
|
||||||
|
//property = serializedObject.FindProperty("myProperty");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnInspectorGUI()
|
||||||
|
{
|
||||||
|
DrawDefaultInspector();
|
||||||
|
|
||||||
|
ScenePartitionSO scenePartitionSO = (target as ScenePartitionSO);
|
||||||
|
|
||||||
|
serializedObject.Update();
|
||||||
|
//EditorGUILayout.PropertyField(property);
|
||||||
|
serializedObject.ApplyModifiedProperties();
|
||||||
|
|
||||||
|
if (GUILayout.Button("Load"))
|
||||||
|
{
|
||||||
|
ScenePartitionUtils.Load(scenePartitionSO);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GUILayout.Button("Save"))
|
||||||
|
{
|
||||||
|
ScenePartitionUtils.Save(scenePartitionSO);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GUILayout.Button("Unload"))
|
||||||
|
{
|
||||||
|
ScenePartitionUtils.Unload(scenePartitionSO);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(GUILayout.Button("Open Scene Data"))
|
||||||
|
{
|
||||||
|
EditorUtility.RevealInFinder(ScenePartitionUtils.GetDataPath(scenePartitionSO));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Editor/ScenePartitionSOEditor.cs.meta
Normal file
11
Editor/ScenePartitionSOEditor.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4b0b68d7b48521245b1dec0163002c6b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
94
Editor/ScenePartitionUtils.cs
Normal file
94
Editor/ScenePartitionUtils.cs
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEditor.SceneManagement;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
|
namespace VertexColor.ScenePartition.Editor
|
||||||
|
{
|
||||||
|
public static class ScenePartitionUtils
|
||||||
|
{
|
||||||
|
public static string GetDataPath(ScenePartitionSO scenePartitionSO)
|
||||||
|
{
|
||||||
|
string dataPath = Path.Combine(Application.dataPath, $"../Data/Scenes/{scenePartitionSO.name}");
|
||||||
|
|
||||||
|
if (!Directory.Exists(dataPath))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(dataPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetScenePath(ScenePartitionSO scenePartitionSO)
|
||||||
|
{
|
||||||
|
string scenePath = AssetDatabase.GetAssetOrScenePath(scenePartitionSO.sceneAsset);
|
||||||
|
|
||||||
|
return scenePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Load(ScenePartitionSO scenePartitionSO)
|
||||||
|
{
|
||||||
|
string dataPath = GetDataPath(scenePartitionSO);
|
||||||
|
string scenePath = GetScenePath(scenePartitionSO);
|
||||||
|
|
||||||
|
List<string> data = new List<string>();
|
||||||
|
List<string> files = Directory.GetFiles(dataPath).ToList();
|
||||||
|
files.Sort();
|
||||||
|
|
||||||
|
for (int i = 0; i < files.Count; i++)
|
||||||
|
{
|
||||||
|
data.AddRange(File.ReadAllLines(files[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
File.WriteAllLines(scenePath, data);
|
||||||
|
|
||||||
|
AssetDatabase.Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Save(ScenePartitionSO scenePartitionSO)
|
||||||
|
{
|
||||||
|
string dataPath = GetDataPath(scenePartitionSO);
|
||||||
|
string scenePath = GetScenePath(scenePartitionSO);
|
||||||
|
|
||||||
|
string[] data = File.ReadAllLines(scenePath);
|
||||||
|
|
||||||
|
int lastIndex = data.Length;
|
||||||
|
for (int i = data.Length - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
if (data[i].StartsWith("---")) // --- is the start of a new yaml document.
|
||||||
|
{
|
||||||
|
int idStartIndex = data[i].IndexOf(" &") + 2; // & is the start of the object id.
|
||||||
|
int idLength = data[i].Length;
|
||||||
|
|
||||||
|
File.WriteAllLines($"{dataPath}/{scenePartitionSO.sceneName}-{data[i][idStartIndex..idLength]}.yaml", data[i..lastIndex]);
|
||||||
|
|
||||||
|
lastIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
File.WriteAllLines($"{dataPath}/{scenePartitionSO.sceneName}.yaml", data[0..lastIndex]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Unload(ScenePartitionSO scenePartitionSO)
|
||||||
|
{
|
||||||
|
string dataPath = GetDataPath(scenePartitionSO);
|
||||||
|
string scenePath = GetScenePath(scenePartitionSO);
|
||||||
|
|
||||||
|
Scene scene = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single);
|
||||||
|
|
||||||
|
GameObject[] gameObjects = scene.GetRootGameObjects();
|
||||||
|
|
||||||
|
for (int i = gameObjects.Length - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
Object.DestroyImmediate(gameObjects[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorSceneManager.SaveScene(scene);
|
||||||
|
|
||||||
|
AssetDatabase.Refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Editor/ScenePartitionUtils.cs.meta
Normal file
11
Editor/ScenePartitionUtils.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 883382d711d46814a916c091ff78921b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
18
Editor/VertexColor.ScenePartition.Editor.asmdef
Normal file
18
Editor/VertexColor.ScenePartition.Editor.asmdef
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"name": "VertexColor.ScenePartition.Editor",
|
||||||
|
"rootNamespace": "VertexColor.ScenePartition.Editor",
|
||||||
|
"references": [
|
||||||
|
"GUID:98426b68bf187c24cab8b1c081ec48eb"
|
||||||
|
],
|
||||||
|
"includePlatforms": [
|
||||||
|
"Editor"
|
||||||
|
],
|
||||||
|
"excludePlatforms": [],
|
||||||
|
"allowUnsafeCode": false,
|
||||||
|
"overrideReferences": false,
|
||||||
|
"precompiledReferences": [],
|
||||||
|
"autoReferenced": true,
|
||||||
|
"defineConstraints": [],
|
||||||
|
"versionDefines": [],
|
||||||
|
"noEngineReferences": false
|
||||||
|
}
|
7
Editor/VertexColor.ScenePartition.Editor.asmdef.meta
Normal file
7
Editor/VertexColor.ScenePartition.Editor.asmdef.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8e94aa69083318d4fb4aec25f8853dfa
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
7
LICENSE.meta
Normal file
7
LICENSE.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 55a18e70c50ceb34fbecf432e70dfdc5
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
7
README.md.meta
Normal file
7
README.md.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: eaed98c3d0c700a4aab6fb8cf702b040
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
8
Runtime.meta
Normal file
8
Runtime.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3573ba34d7fdcc544a43c56669d03616
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
14
Runtime/VertexColor.ScenePartition.asmdef
Normal file
14
Runtime/VertexColor.ScenePartition.asmdef
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "VertexColor.ScenePartition",
|
||||||
|
"rootNamespace": "VertexColor.ScenePartition",
|
||||||
|
"references": [],
|
||||||
|
"includePlatforms": [],
|
||||||
|
"excludePlatforms": [],
|
||||||
|
"allowUnsafeCode": false,
|
||||||
|
"overrideReferences": false,
|
||||||
|
"precompiledReferences": [],
|
||||||
|
"autoReferenced": true,
|
||||||
|
"defineConstraints": [],
|
||||||
|
"versionDefines": [],
|
||||||
|
"noEngineReferences": false
|
||||||
|
}
|
7
Runtime/VertexColor.ScenePartition.asmdef.meta
Normal file
7
Runtime/VertexColor.ScenePartition.asmdef.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 98426b68bf187c24cab8b1c081ec48eb
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
18
package.json
Normal file
18
package.json
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"name": "com.vertexcolor.scenepartition",
|
||||||
|
"displayName": "ScenePartition",
|
||||||
|
"version": "0.1.4",
|
||||||
|
"unity": "2019.3",
|
||||||
|
"description": "Unity scene partition framework.",
|
||||||
|
"category": "Tool",
|
||||||
|
"type": "tool",
|
||||||
|
"license": "MIT",
|
||||||
|
"author": {
|
||||||
|
"name": "Max Kruf",
|
||||||
|
"email": "info@maxartz15.com",
|
||||||
|
"url": "https://www.maxartz15.com"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"Scene Partition"
|
||||||
|
]
|
||||||
|
}
|
7
package.json.meta
Normal file
7
package.json.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 420d2ef5a566f3b429f86eebb929fe62
|
||||||
|
PackageManifestImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user