AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
SaveLocalFileEditor.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(SaveLocalFileAttribute))]
14  public class SaveLocalFileEditor : 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.SaveFilePanel("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  }
41 
42  property.stringValue = path;
43  }
44  }
45  }
46 }
Property drawer for selection of a local output file with the resultant path stored in a string ...
override void OnGUI(Rect position, SerializedProperty property, GUIContent label)