forked from sebastienros/jint
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a couple example projects, MonoBehaviourScriptingHost, stubbing…
… out initial editor project
- Loading branch information
1 parent
56252e7
commit 65626f8
Showing
40 changed files
with
781 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
##### Roadmap | ||
|
||
* `inject()` | ||
* `await()` | ||
* ~~`inject()`~~ | ||
* ~~`await()`~~ | ||
* Serialization + inspector integration. | ||
* UQL. | ||
* Serialization + inspector integration. | ||
* Runtime JS editor. | ||
* Fill out resolver implementations. | ||
* StrangeIoC | ||
* Fill out loader implemenations. | ||
* Need method to pull requires out of script to help with streaming scripts. | ||
* StreamingAssets | ||
* FileSystem |
Binary file added
BIN
+1.29 KB
Examples/MonoBehaviourScripting/Assets/Plugins/Editor/Jint.Unity.Editor.dll.mdb
Binary file not shown.
Binary file added
BIN
+798 Bytes
Examples/MonoBehaviourScripting/Assets/Plugins/Jint.Ninject.dll.mdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+12.1 KB
Examples/MonoBehaviourScripting/Assets/Scenes/MonoBehaviourScripting.unity
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
random: { | ||
value: Math.random(), | ||
range: function(a, b) { | ||
return a + Math.floor((b - a) * Math.random()); | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace Jint.Unity.Editor | ||
{ | ||
public class LabelListElement : ListElement | ||
{ | ||
private readonly string _label; | ||
|
||
public readonly object Value; | ||
|
||
public LabelListElement( | ||
object value, | ||
string label) | ||
{ | ||
Value = value; | ||
_label = label; | ||
} | ||
|
||
public override void Draw() | ||
{ | ||
base.Draw(); | ||
|
||
GUILayout.Label(new GUIContent(_label), GUILayout.ExpandWidth(true)); | ||
var rect = GUILayoutUtility.GetLastRect(); | ||
if (Event.current.type == EventType.mouseUp | ||
&& rect.Contains(Event.current.mousePosition)) | ||
{ | ||
Selected(this); | ||
} | ||
} | ||
} | ||
|
||
public class ListElement | ||
{ | ||
public event Action<ListElement> OnRepaint; | ||
public event Action<ListElement> OnSelected; | ||
|
||
public virtual void Draw() | ||
{ | ||
// | ||
} | ||
|
||
protected void Selected(ListElement element) | ||
{ | ||
if (null != OnSelected) | ||
{ | ||
OnSelected(element); | ||
} | ||
} | ||
} | ||
|
||
public class ListComponent | ||
{ | ||
private readonly List<ListElement> _elements = new List<ListElement>(); | ||
private Vector2 _position; | ||
private ListElement _selected; | ||
|
||
public ListElement Selected | ||
{ | ||
get | ||
{ | ||
return _selected; | ||
} | ||
|
||
set | ||
{ | ||
if (_selected == value) | ||
{ | ||
return; | ||
} | ||
|
||
_selected = value; | ||
|
||
if (null != OnSelected) | ||
{ | ||
OnSelected(_selected); | ||
} | ||
|
||
if (null != OnRepaint) | ||
{ | ||
OnRepaint(); | ||
} | ||
} | ||
} | ||
|
||
public event Action OnRepaint; | ||
public event Action<ListElement> OnSelected; | ||
|
||
public void Populate(ListElement[] elements) | ||
{ | ||
foreach (var element in _elements) | ||
{ | ||
element.OnRepaint -= Element_OnRepaint; | ||
element.OnSelected -= Element_OnSelected; | ||
} | ||
_elements.Clear(); | ||
|
||
foreach (var element in elements) | ||
{ | ||
element.OnRepaint += Element_OnRepaint; | ||
element.OnSelected += Element_OnSelected; | ||
_elements.Add(element); | ||
} | ||
} | ||
|
||
public void Draw() | ||
{ | ||
_position = GUILayout.BeginScrollView( | ||
_position, | ||
GUILayout.ExpandHeight(true), | ||
GUILayout.ExpandWidth(true)); | ||
|
||
foreach (var element in _elements) | ||
{ | ||
element.Draw(); | ||
} | ||
|
||
GUILayout.EndScrollView(); | ||
} | ||
|
||
private void Element_OnSelected(ListElement element) | ||
{ | ||
Selected = element; | ||
} | ||
|
||
private void Element_OnRepaint(ListElement element) | ||
{ | ||
if (null != OnRepaint) | ||
{ | ||
OnRepaint(); | ||
} | ||
} | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
Jint.Unity.Editor/EditorWindow/ScriptSelectionEditorWindow.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
using System.IO; | ||
using System.Linq; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Jint.Unity.Editor | ||
{ | ||
public class ScriptSelectionEditorWindow : EditorWindow | ||
{ | ||
public interface IScriptSelectionDelegate | ||
{ | ||
void Selected(TextAsset asset); | ||
} | ||
|
||
private class ScriptSelectionRecord | ||
{ | ||
public string Name; | ||
public string AbsPath; | ||
public string Source; | ||
} | ||
|
||
private readonly ListComponent _scriptsListComponent = new ListComponent(); | ||
private ScriptSelectionRecord[] _scripts; | ||
private ScriptSelectionRecord _selected; | ||
private Vector2 _scriptListPosition; | ||
private Vector2 _scriptPreviewPosition; | ||
|
||
public IScriptSelectionDelegate Delegate; | ||
|
||
private void FindAllScripts() | ||
{ | ||
_scripts = Directory | ||
.GetFiles( | ||
Application.dataPath, | ||
"*.html", | ||
SearchOption.AllDirectories) | ||
.Select(file => new ScriptSelectionRecord | ||
{ | ||
Name = Path.GetFileName(file), | ||
AbsPath = file | ||
}) | ||
.ToArray(); | ||
_selected = _scripts.FirstOrDefault(); | ||
} | ||
|
||
private void OnEnable() | ||
{ | ||
FindAllScripts(); | ||
|
||
titleContent = new GUIContent("Scripts"); | ||
|
||
_scriptsListComponent.Populate( | ||
_scripts | ||
.Select(script => new LabelListElement(script, script.AbsPath)) | ||
.ToArray()); | ||
} | ||
|
||
private void OnDisable() | ||
{ | ||
|
||
} | ||
|
||
private void OnGUI() | ||
{ | ||
GUILayout.BeginHorizontal( | ||
GUILayout.ExpandHeight(true), | ||
GUILayout.ExpandWidth(true)); | ||
|
||
DrawScriptList(); | ||
DrawScript(); | ||
|
||
GUILayout.EndHorizontal(); | ||
} | ||
|
||
private void DrawScriptList() | ||
{ | ||
GUILayout.BeginVertical( | ||
GUILayout.ExpandHeight(true), | ||
GUILayout.Width(Screen.width/2f)); | ||
|
||
_scriptsListComponent.Draw(); | ||
|
||
GUILayout.EndVertical(); | ||
} | ||
|
||
private void DrawScript() | ||
{ | ||
_scriptPreviewPosition = GUILayout.BeginScrollView( | ||
_scriptPreviewPosition, | ||
GUILayout.ExpandHeight(true), | ||
GUILayout.Width(Screen.width / 2f)); | ||
|
||
if (null == _selected) | ||
{ | ||
|
||
} | ||
else | ||
{ | ||
if (string.IsNullOrEmpty(_selected.Source)) | ||
{ | ||
_selected.Source = File.ReadAllText(_selected.AbsPath); | ||
} | ||
|
||
var enabled = GUI.enabled; | ||
GUI.enabled = false; | ||
GUILayout.TextArea( | ||
_selected.Source, | ||
GUILayout.ExpandHeight(true), | ||
GUILayout.ExpandWidth(true)); | ||
GUI.enabled = enabled; | ||
} | ||
|
||
GUILayout.EndScrollView(); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Jint.Unity.Editor/Inspector/MonoBehaviourScriptingHostInspector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using UnityEditor; | ||
|
||
namespace Jint.Unity.Editor | ||
{ | ||
/// <summary> | ||
/// Custom inspector for scripting host. | ||
/// </summary> | ||
/*[CustomEditor(typeof(MonoBehaviourScriptingHost))] | ||
public class MonoBehaviourScriptingHostInspector : UnityEditor.Editor | ||
{ | ||
/// <summary> | ||
/// Called by Unity to draw inspector. | ||
/// </summary> | ||
public override void OnInspectorGUI() | ||
{ | ||
var host = (MonoBehaviourScriptingHost) target; | ||
} | ||
}*/ | ||
} |
Oops, something went wrong.