Skip to content

Commit

Permalink
Added a couple example projects, MonoBehaviourScriptingHost, stubbing…
Browse files Browse the repository at this point in the history
… out initial editor project
  • Loading branch information
thegoldenmule committed Apr 5, 2017
1 parent 56252e7 commit 65626f8
Show file tree
Hide file tree
Showing 40 changed files with 781 additions and 67 deletions.
13 changes: 10 additions & 3 deletions Documentation/roadmap.md
@@ -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 not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 8 additions & 0 deletions Examples/MonoBehaviourScripting/Assets/Scripts/math.html
@@ -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 modified Examples/Repl/Assets/Plugins/Jint.Ninject.dll.mdb
Binary file not shown.
Binary file modified Examples/Repl/Assets/Plugins/Jint.Unity.dll.mdb
Binary file not shown.
Binary file modified Examples/Repl/Assets/Plugins/Jint.dll.mdb
Binary file not shown.
33 changes: 0 additions & 33 deletions Examples/Repl/Assets/Resources/createRandomObjects.html

This file was deleted.

Binary file not shown.
Binary file added Examples/UQL/Assets/Plugins/Jint.Ninject.dll.mdb
Binary file not shown.
Binary file added Examples/UQL/Assets/Plugins/Jint.Unity.dll.mdb
Binary file not shown.
Binary file added Examples/UQL/Assets/Plugins/Jint.dll.mdb
Binary file not shown.
Binary file added Examples/UQL/Assets/Scenes/uql.unity
Binary file not shown.
136 changes: 136 additions & 0 deletions Jint.Unity.Editor/Components/List/ListComponent.cs
@@ -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 Jint.Unity.Editor/EditorWindow/ScriptSelectionEditorWindow.cs
@@ -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 Jint.Unity.Editor/Inspector/MonoBehaviourScriptingHostInspector.cs
@@ -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;
}
}*/
}

0 comments on commit 65626f8

Please sign in to comment.