Skip to content

Commit

Permalink
add global class completion #7.
Browse files Browse the repository at this point in the history
  • Loading branch information
hecomi committed Mar 9, 2017
1 parent 40c91d5 commit e1bfa8b
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 4 deletions.
Binary file modified Assets/uREPL/Examples/Scenes/Single Line.unity
Binary file not shown.
Binary file modified Assets/uREPL/Plugins/Mono.CSharp.dll
Binary file not shown.
43 changes: 43 additions & 0 deletions Assets/uREPL/Scripts/Completions/GlobalClassCompletion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using UnityEngine;
using System.Linq;

namespace uREPL
{

public class GlobalClassCompletion : CompletionPlugin
{
static private string[] globalClassNames_;

protected override void OnEnable()
{
if (globalClassNames_ == null) {
globalClassNames_ = System.AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(asm => asm.GetTypes())
.Where(type => type.IsClass && type.Namespace == null)
.Select(type => type.Name)
.Where(name => char.IsLetter(name[0]))
.Distinct()
.OrderBy(name => name[0])
.ToArray();
}

base.OnEnable();
}

public override CompletionInfo[] GetCompletions(string input)
{
var parts = input.Split(new char[] { '\n', ' ', '\t', '=', '{', '}', '(', ')', '<', '>' });
var lastPart = parts.Last();
return globalClassNames_
.Where(name => name.IndexOf(lastPart) == 0)
.Select(name => new CompletionInfo(
lastPart,
name,
"G",
new Color32(50, 70, 240, 255),
"global::" + name))
.ToArray();
}
}

}
12 changes: 12 additions & 0 deletions Assets/uREPL/Scripts/Completions/GlobalClassCompletion.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Assets/uREPL/Scripts/Core/Evaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ static private void ReferenceAllAssemblies()
static private void SetUsings()
{
Mono.CSharp.Evaluator.Run("using uREPL;");
Mono.CSharp.Evaluator.Run("using System;");
Mono.CSharp.Evaluator.Run("using UnityEngine;");
// #if UNITY_EDITOR
// Mono.CSharp.Evaluator.Run("using UnityEditor;");
Expand Down
1 change: 1 addition & 0 deletions Assets/uREPL/Scripts/Core/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void UpdateAllDefaultCompletionPlugins()
UpdateCompletionPlugin<CommandCompletion>(parameters.useCommandCompletion);
UpdateCompletionPlugin<GameObjectNameCompletion>(parameters.useGameObjectNameCompletion);
UpdateCompletionPlugin<GameObjectPathCompletion>(parameters.useGameObjectPathCompletion);
UpdateCompletionPlugin<GlobalClassCompletion>(parameters.useGlobalClassCompletion);
}

private void UpdateCompletionPlugin<T>(bool enabled) where T : MonoBehaviour
Expand Down
1 change: 1 addition & 0 deletions Assets/uREPL/Scripts/Core/Parameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Parameters
public bool useCommandCompletion = true;
public bool useGameObjectNameCompletion = true;
public bool useGameObjectPathCompletion = true;
public bool useGlobalClassCompletion = true;
#endregion

#region [Parameters]
Expand Down
1 change: 1 addition & 0 deletions Assets/uREPL/Scripts/Editor/MainEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ private void DrawCompletionPluginGUI()
Toggle("Command", ref parameters.useCommandCompletion);
Toggle("GameObject Name", ref parameters.useGameObjectNameCompletion);
Toggle("GameObject Path", ref parameters.useGameObjectPathCompletion);
Toggle("Global Class", ref parameters.useGlobalClassCompletion);
EditorGUILayout.Separator();
--EditorGUI.indentLevel;
}
Expand Down
1 change: 0 additions & 1 deletion Assets/uREPL/Scripts/Gui/FieldItems/EnumFieldItem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Linq;

namespace uREPL
{
Expand Down
5 changes: 5 additions & 0 deletions Assets/uREPL/Scripts/Gui/FieldItems/FieldItem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using UnityEngine;
using UnityEngine.UI;

namespace uREPL
{

public abstract class FieldItem : MonoBehaviour
{
protected Text labelText;
Expand Down Expand Up @@ -31,3 +34,5 @@ void Awake()
labelText = transform.FindChild("Label").GetComponent<Text>();
}
}

}
6 changes: 5 additions & 1 deletion Assets/uREPL/Scripts/Gui/FieldItems/ReadonlyFieldItem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Reflection;

namespace uREPL
{

public class ReadonlyFieldItem : FieldItem
{
Expand All @@ -18,3 +20,5 @@ void Update()
value = componentType.GetField(fieldName).GetValue(component);
}
}

}
Binary file modified ProjectSettings/GraphicsSettings.asset
Binary file not shown.
Binary file modified ProjectSettings/ProjectSettings.asset
Binary file not shown.
3 changes: 1 addition & 2 deletions ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
m_EditorVersion: 5.4.1f1
m_StandardAssetsVersion: 0
m_EditorVersion: 5.5.1f1

0 comments on commit e1bfa8b

Please sign in to comment.