Skip to content

Commit

Permalink
DataPathDrawer: added directory select button
Browse files Browse the repository at this point in the history
  • Loading branch information
i-saint committed May 31, 2017
1 parent 2c08aaa commit 30548a2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,27 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
var indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;

float buttonWidth = 22;
float rootWidth = 70;
float leafWidth = position.width - rootWidth - 5;
Rect rootRect = new Rect(position.x, position.y, rootWidth, position.height);
Rect leafRect = new Rect(position.x + rootWidth + 5, position.y, leafWidth, position.height);
float leafWidth = position.width - rootWidth - 5 - buttonWidth;
var rootRect = new Rect(position.x, position.y, rootWidth, position.height);
var leafRect = new Rect(position.x + rootWidth + 5, position.y, leafWidth, position.height);
var buttonRect = new Rect(position.x + rootWidth + 5 + leafWidth, position.y, buttonWidth, position.height);

EditorGUI.PropertyField(rootRect, property.FindPropertyRelative("m_root"), GUIContent.none);
EditorGUI.PropertyField(leafRect, property.FindPropertyRelative("m_leaf"), GUIContent.none);
var pRoot = property.FindPropertyRelative("m_root");
var pLeaf = property.FindPropertyRelative("m_leaf");
EditorGUI.PropertyField(rootRect, pRoot, GUIContent.none);
EditorGUI.PropertyField(leafRect, pLeaf, GUIContent.none);
if (GUI.Button(buttonRect, "..."))
{
var path = EditorUtility.OpenFolderPanel("Output Directory", ".", "");
if (path.Length > 0)
{
var newPath = new DataPath(path);
pRoot.intValue = (int)newPath.root;
pLeaf.stringValue = newPath.leaf;
}
}

EditorGUI.indentLevel = indent;
EditorGUI.EndProperty();
Expand Down
21 changes: 15 additions & 6 deletions FrameCapturer/Assets/UTJ/FrameCapturer/Scripts/Misc/DataPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,36 @@ public DataPath(string path)
if (path.Contains(Application.streamingAssetsPath))
{
m_root = Root.StreamingAssets;
m_leaf = path.Replace(Application.streamingAssetsPath, "");
m_leaf = path.Replace(Application.streamingAssetsPath, "").TrimStart('/');
}
else if (path.Contains(Application.dataPath))
{
m_root = Root.DataPath;
m_leaf = path.Replace(Application.dataPath, "");
m_leaf = path.Replace(Application.dataPath, "").TrimStart('/');
}
else if (path.Contains(Application.persistentDataPath))
{
m_root = Root.PersistentData;
m_leaf = path.Replace(Application.persistentDataPath, "");
m_leaf = path.Replace(Application.persistentDataPath, "").TrimStart('/');
}
else if (path.Contains(Application.temporaryCachePath))
{
m_root = Root.TemporaryCache;
m_leaf = path.Replace(Application.temporaryCachePath, "");
m_leaf = path.Replace(Application.temporaryCachePath, "").TrimStart('/');
}
else
{
m_root = Root.Absolute;
m_leaf = path;
var cur = System.IO.Directory.GetCurrentDirectory().Replace("\\", "/");
if (path.Contains(cur))
{
m_root = Root.Current;
m_leaf = path.Replace(cur, "").TrimStart('/');
}
else
{
m_root = Root.Absolute;
m_leaf = path;
}
}
}

Expand Down

0 comments on commit 30548a2

Please sign in to comment.