Tanoda
StreamingFolderPropertyDrawer.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.IO;
11using UnityEngine;
12using UnityEditor;
13
14namespace Leap.Unity {
15
16 [CustomPropertyDrawer(typeof(StreamingFolder), useForChildren: true)]
18
19 protected override bool ValidatePath(string fullPath, string relativePath, out string errorMessage) {
20 var fullInfo = new DirectoryInfo(fullPath);
21 var streamingInfo = new DirectoryInfo(Application.streamingAssetsPath);
22
23 if (IsInsideOrEqual(fullInfo, streamingInfo)) {
24 errorMessage = null;
25 return true;
26 } else {
27 errorMessage = "The specified folder is not a streaming asset folder. Streaming asset folders must be inside project's Assets/StreamingAssets directory.";
28 return false;
29 }
30 }
31
32 private bool IsInsideOrEqual(DirectoryInfo path, DirectoryInfo folder) {
33 if (path.Parent == null) {
34 return false;
35 }
36
37 if (string.Equals(path.FullName, folder.FullName, StringComparison.InvariantCultureIgnoreCase)) {
38 return true;
39 }
40
41 return IsInsideOrEqual(path.Parent, folder);
42 }
43 }
44}
override bool ValidatePath(string fullPath, string relativePath, out string errorMessage)