Tanoda
StreamingFolder.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using System;
10using System.Linq;
11using UnityEngine;
12#if UNITY_EDITOR
13using UnityEditor;
14#endif
15
16namespace Leap.Unity {
17
18 [Serializable]
19 public class StreamingFolder : AssetFolder, ISerializationCallbackReceiver {
20
21 [SerializeField]
22 private string _relativePath;
23
30 public override string Path {
31 get {
32 if (_relativePath == null) { _relativePath = ""; }
33 return System.IO.Path.Combine(Application.streamingAssetsPath, _relativePath);
34 }
35 set {
36 throw new InvalidOperationException();
37 }
38 }
39
40 public void OnAfterDeserialize() { }
41
42 public void OnBeforeSerialize() {
43#if UNITY_EDITOR
44 string assetPath = AssetDatabase.GetAssetPath(_assetFolder);
45 if (string.IsNullOrEmpty(assetPath)) {
46 _relativePath = null;
47 } else {
48 string fullFolder = System.IO.Path.GetFullPath(assetPath);
49 _relativePath = Utils.MakeRelativePath(Application.streamingAssetsPath, fullFolder);
50 _relativePath = string.Join(System.IO.Path.DirectorySeparatorChar.ToString(),
51 _relativePath.Split(System.IO.Path.DirectorySeparatorChar).Skip(1).ToArray());
52 }
53#endif
54 }
55 }
56}
A convenient serializable representation of an asset folder. Only useful for editor scripts since ass...
Definition: AssetFolder.cs:26
UnityObject _assetFolder
Definition: AssetFolder.cs:29
override string Path
Gets the full path to the streaming folder. This operation is safe to be called from within a build o...