-
Notifications
You must be signed in to change notification settings - Fork 1
/
SaveLocalFileEditor.cs
46 lines (39 loc) · 1.47 KB
/
SaveLocalFileEditor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using System;
using UnityEngine;
using UnityEditor;
namespace HoloToolkit.Unity
{
/// <summary>
/// Property drawer for selection of a local output file with the resultant path stored in a string
/// </summary>
[CustomPropertyDrawer(typeof(SaveLocalFileAttribute))]
public class SaveLocalFileEditor : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (property.propertyType != SerializedPropertyType.String)
{
throw new ArgumentException() { };
}
position.width -= 30;
EditorGUI.PropertyField(position, property, label);
position.x += position.width;
position.width = 30.0f;
if (GUI.Button(position, "..."))
{
var path = EditorUtility.SaveFilePanel("Select a file", Application.dataPath, "", "");
if (string.IsNullOrEmpty(path))
{
return;
}
if (path.StartsWith(Application.dataPath))
{
path = path.Substring(Application.dataPath.Length);
}
property.stringValue = path;
}
}
}
}