AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
OpenLocalFileEditor.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using System;
5 using UnityEngine;
6 using UnityEditor;
7 
8 namespace HoloToolkit.Unity
9 {
13  [CustomPropertyDrawer(typeof(OpenLocalFileAttribute))]
14  public class OpenLocalFileEditor : PropertyDrawer
15  {
16  public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
17  {
18  if (property.propertyType != SerializedPropertyType.String)
19  {
20  throw new ArgumentException();
21  }
22 
23  position.width -= 30;
24  EditorGUI.PropertyField(position, property, label);
25 
26  position.x += position.width;
27  position.width = 30.0f;
28 
29  if (GUI.Button(position, "..."))
30  {
31  var path = EditorUtility.OpenFilePanel("Select a file", Application.dataPath, "");
32  if (string.IsNullOrEmpty(path))
33  {
34  return;
35  }
36 
37  if (path.StartsWith(Application.dataPath))
38  {
39  path = path.Substring(Application.dataPath.Length);
40  path = path.Replace("/", "\\");
41  }
42 
43  property.stringValue = path;
44  }
45  }
46  }
47 }
Property drawer for selection of a local input file with the resultant path stored in a string ...
override void OnGUI(Rect position, SerializedProperty property, GUIContent label)