private void OnEnable() { //加载配置文件 string configPath = Path.GetDirectoryName(Application.dataPath); configPath = Path.Combine(configPath, "ProjectSettings/octree.json"); if (File.Exists(configPath)) { _octreeConfig = JsonUtility.FromJson <OctreeEditorConfig>(File.ReadAllText(configPath)); } else { _octreeConfig = new OctreeEditorConfig(); } //默认打开某个物体 if (Selection.activeObject != null) { _octree = Selection.activeObject as Octree; if (_octree != null) { _octreeConfig.OctreeAssetPath = AssetDatabase.GetAssetPath(Selection.activeObject); _octreeConfig.MaxBounds = _octree.Root.Bounds; _octreeConfig.MaxDepth = _octree.MaxDepth; } } //octreeDebug _octreeDebug = new GameObject("Octree Debug").AddComponent <OctreeDebug>(); _octreeDebug.Octree = _octree; //update EditorApplication.update += OnUpdate; }
private void OnDisable() { if (_octreeDebug != null) { DestroyImmediate(_octreeDebug.gameObject); _octreeDebug = null; } //保存配置文件 string configPath = Path.GetDirectoryName(Application.dataPath); configPath = Path.Combine(configPath, "ProjectSettings/octree.json"); if (_octreeConfig != null) { File.WriteAllText(configPath, JsonUtility.ToJson(_octreeConfig)); } EditorApplication.update -= OnUpdate; _octree = null; }