Skip to content

Commit

Permalink
Merge pull request #2 from jokoho48/master
Browse files Browse the repository at this point in the history
Fix issues With Unity Network Module and Unity's Assembly Definitions
  • Loading branch information
omid3098 authored Feb 27, 2018
2 parents 9db54e8 + f5bd17f commit e9413f0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions Assets/OpenTerminal/Sample/RotateCube.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ void Update()
}


[Command("stop-cube", "stops the cube from rotating")]
[TerminalCommand("stop-cube", "stops the cube from rotating")]
public void StopCube()
{
stop = true;
}


[Command("rotate-cube", "rotates the cube")]
[TerminalCommand("rotate-cube", "rotates the cube")]
public void RotateTheCube()
{
stop = false;
}

[Command("move-cube", "move-cube(x,y,z) Moves the cube")]
[TerminalCommand("move-cube", "move-cube(x,y,z) Moves the cube")]
public void Move(float x, float y, float z)
{
transform.position = new Vector3(x, y, z);
Expand Down
10 changes: 5 additions & 5 deletions Assets/OpenTerminal/Scripts/BasicCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@
public class BasicCommands
{

[Command("clear", "clears the terminal screen")]
[TerminalCommand("clear", "clears the terminal screen")]
public void ClearTerminal()
{
Terminal.instance.Clear();
}

[Command("help", "Shows list of available commands")]
[TerminalCommand("help", "Shows list of available commands")]
public string Help()
{
string help_string = "List of available commands:";
foreach (var method in Terminal.instance.terminalMethods.methods)
{
foreach (var attribute in method.GetCustomAttributes(true))
{
if (attribute is CommandAttribute) //Does not pass
if (attribute is TerminalCommandAttribute) //Does not pass
{
CommandAttribute attr = (CommandAttribute)attribute;
TerminalCommandAttribute attr = (TerminalCommandAttribute)attribute;
help_string += "\n " + attr.commandName + " --> " + attr.commandDesc;
}
}
}
return help_string;
}

[Command("hide", "Hides the terminal")]
[TerminalCommand("hide", "Hides the terminal")]
public void Hide()
{
Terminal.instance.Hide();
Expand Down
2 changes: 1 addition & 1 deletion Assets/OpenTerminal/Scripts/SampleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class SampleCommand
{
[Command("debug", "Debugs a sample line in Unity Console")]
[TerminalCommand("debug", "Debugs a sample line in Unity Console")]
public void SampleDebug(string input)
{
Debug.Log(input);
Expand Down
4 changes: 2 additions & 2 deletions Assets/OpenTerminal/Scripts/Terminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ private string ExecuteCommand(string inputText)
foreach (var method in terminalMethods.methods)
{
foreach (object attribute in method.GetCustomAttributes(true)) // Returns all 3 of my attributes.
if (attribute is CommandAttribute)
if (attribute is TerminalCommandAttribute)
{
CommandAttribute attr = (CommandAttribute)attribute;
TerminalCommandAttribute attr = (TerminalCommandAttribute)attribute;
if (attr.commandName == command)
{
if (registered) Debug.LogError(TerminalStrings.MULTIPLE_COMMAND_NAMES + command);
Expand Down
6 changes: 3 additions & 3 deletions Assets/OpenTerminal/Scripts/TerminalAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System;
using UnityEngine;
[AttributeUsage(AttributeTargets.Method)]
public class CommandAttribute : Attribute
public class TerminalCommandAttribute : Attribute
{
public string commandName;
public string commandDesc;

public CommandAttribute(string name)
public TerminalCommandAttribute(string name)
{
commandName = name;
}
public CommandAttribute(string name, string desc)
public TerminalCommandAttribute(string name, string desc)
{
commandName = name;
commandDesc = desc;
Expand Down
22 changes: 11 additions & 11 deletions Assets/OpenTerminal/Scripts/TerminalMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ public class TerminalMethods
public TerminalMethods()
{
methods = new List<MethodInfo>();
var assembly = System.AppDomain.CurrentDomain.Load("Assembly-CSharp");
methods = assembly
.GetTypes()
.SelectMany(x => x.GetMethods())
.Where(y => y.GetCustomAttributes(true).OfType<CommandAttribute>().Any()).ToList();
foreach (var method in methods)

foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var attribute in method.GetCustomAttributes(true))
foreach (var method in assembly.GetTypes().SelectMany(x => x.GetMethods()).Where(y => y.GetCustomAttributes(true).OfType<TerminalCommandAttribute>().Any()).ToList())
{
if (attribute is CommandAttribute) //Does not pass
methods.Add(method)
foreach (var attribute in method.GetCustomAttributes(true))
{
CommandAttribute attr = (CommandAttribute)attribute;
methodNames.Add(attr.commandName);
if (attribute is TerminalCommandAttribute) //Does not pass
{
TerminalCommandAttribute attr = (TerminalCommandAttribute)attribute;
methodNames.Add(attr.commandName);
}
}
}
}
Expand All @@ -32,4 +32,4 @@ public string[] GetCommandsContaining(string input)
{
return methodNames.Where(k => k.Contains(input)).ToArray();
}
}
}

0 comments on commit e9413f0

Please sign in to comment.