Skip to content

Commit

Permalink
WIP Icons
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Ramberg committed Jun 16, 2019
1 parent 5ba173b commit cb6280a
Show file tree
Hide file tree
Showing 59 changed files with 1,303 additions and 21 deletions.
8 changes: 8 additions & 0 deletions Source/Actions/IGameActionIcon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace UnityAtoms
{
/// <summary>
/// Use in order to determine if this is a GameAction when assigning icons to Atoms.
/// This is hack is necessary because IsAssignableFrom and IsSubclassOf doesn't work without a type constraint 💩
/// </summary>
public interface IGameActionIcon { }
}
11 changes: 11 additions & 0 deletions Source/Actions/IGameActionIcon.cs.meta

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

10 changes: 5 additions & 5 deletions Source/Actions/ScriptableObjectGameAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace UnityAtoms
{
public abstract class GameAction<T1> : ScriptableObject
public abstract class GameAction<T1> : ScriptableObject, IGameActionIcon
{
[HideInInspector]
public Action<T1> Action;
Expand All @@ -20,7 +20,7 @@ public virtual void Do(T1 t1)
}
}

public abstract class GameAction<T1, T2> : ScriptableObject
public abstract class GameAction<T1, T2> : ScriptableObject, IGameActionIcon
{
[HideInInspector]
public Action<T1, T2> Action;
Expand All @@ -37,7 +37,7 @@ public virtual void Do(T1 t1, T2 t2)
}
}

public abstract class GameAction<T1, T2, T3> : ScriptableObject
public abstract class GameAction<T1, T2, T3> : ScriptableObject, IGameActionIcon
{
[HideInInspector]
public Action<T1, T2, T3> Action;
Expand All @@ -54,7 +54,7 @@ public virtual void Do(T1 t1, T2 t2, T3 t3)
}
}

public abstract class GameAction<T1, T2, T3, T4> : ScriptableObject
public abstract class GameAction<T1, T2, T3, T4> : ScriptableObject, IGameActionIcon
{
[HideInInspector]
public Action<T1, T2, T3, T4> Action;
Expand All @@ -71,7 +71,7 @@ public virtual void Do(T1 t1, T2 t2, T3 t3, T4 t4)
}
}

public abstract class GameAction<T1, T2, T3, T4, T5> : ScriptableObject
public abstract class GameAction<T1, T2, T3, T4, T5> : ScriptableObject, IGameActionIcon
{
[HideInInspector]
public Action<T1, T2, T3, T4, T5> Action;
Expand Down
8 changes: 4 additions & 4 deletions Source/Actions/ScriptableObjectGameAction.cs.meta

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

8 changes: 8 additions & 0 deletions Source/Constants/IConstantIcon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace UnityAtoms
{
/// <summary>
/// Use in order to determine if this is a Constant when assigning icons to Atoms.
/// This is hack is necessary because IsAssignableFrom and IsSubclassOf doesn't work without a type constraint 💩
/// </summary>
public interface IConstantIcon { }
}
11 changes: 11 additions & 0 deletions Source/Constants/IConstantIcon.cs.meta

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

8 changes: 4 additions & 4 deletions Source/Constants/IntConstant.cs.meta

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

4 changes: 2 additions & 2 deletions Source/Events/GameEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace UnityAtoms
{
public abstract class GameEvent<T> : ScriptableObject, ISerializationCallbackReceiver
public abstract class GameEvent<T> : ScriptableObject, ISerializationCallbackReceiver, IEventIcon
{
public event Action<T> OnEvent;

Expand Down Expand Up @@ -55,7 +55,7 @@ public void OnAfterDeserialize()
}
}

public abstract class GameEvent<T1, T2> : ScriptableObject, ISerializationCallbackReceiver
public abstract class GameEvent<T1, T2> : ScriptableObject, ISerializationCallbackReceiver, IEventIcon
{
public event Action<T1, T2> OnEvent;

Expand Down
8 changes: 8 additions & 0 deletions Source/Events/IEventIcon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace UnityAtoms
{
/// <summary>
/// Use in order to determine if this is a Event when assigning icons to Atoms.
/// This is hack is necessary because IsAssignableFrom and IsSubclassOf doesn't work without a type constraint 💩
/// </summary>
public interface IEventIcon { }
}
11 changes: 11 additions & 0 deletions Source/Events/IEventIcon.cs.meta

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

8 changes: 8 additions & 0 deletions Source/Functions/IFunctionIcon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace UnityAtoms
{
/// <summary>
/// Use in order to determine if this is a Function when assigning icons to Atoms.
/// This is hack is necessary because IsAssignableFrom and IsSubclassOf doesn't work without a type constraint 💩
/// </summary>
public interface IFunctionIcon { }
}
11 changes: 11 additions & 0 deletions Source/Functions/IFunctionIcon.cs.meta

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

2 changes: 1 addition & 1 deletion Source/Functions/ScriptableObjectFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace UnityAtoms
{
public abstract class GameFunction<R> : ScriptableObject
public abstract class GameFunction<R> : ScriptableObject, IFunctionIcon
{
[HideInInspector]
public Func<R> Func;
Expand Down
8 changes: 8 additions & 0 deletions Source/IconAssignmentPostProcessor.meta

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

68 changes: 68 additions & 0 deletions Source/IconAssignmentPostProcessor/AtomsIconAssignmentProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEditor;

namespace UnityAtoms
{
internal class AtomsIconAssignmentProcessor : IconAssignmentProcessor
{
protected override string IconSearchPath
{
get => System.Environment.CurrentDirectory.Contains("unity-atoms/UnityAtomsTestsAndExamples") ?
Directory.GetParent(Directory.GetParent(Application.dataPath).FullName).FullName :
Directory.GetParent(Application.dataPath).FullName;
}
protected override string IconSearchFilter { get => "atom-icon-"; }
protected override string SettingsPath { get => $"{Application.dataPath}{Path.DirectorySeparatorChar}UnityAtomsIconSettings.json"; }
protected override List<IIconAssigner> IconAssigners { get => new List<IIconAssigner>() { new AtomMonoScriptAssigner() }; }
}

internal class AtomMonoScriptAssigner : IconAssigner<MonoScript>
{
protected override Func<MonoScript, List<IconData>, IconData> SelectIcon
{
get => (script, icons) =>
{
var type = script?.GetClass();
var scriptName = type?.Name;
var inUnityAtomsNS = scriptName != null && type != null && type.Namespace != null && type.Namespace.StartsWith("UnityAtoms");
if (inUnityAtomsNS)
{
if (typeof(IGameActionIcon).IsAssignableFrom(type))
{
return icons.FirstOrDefault((icon) => icon.Name == "atom-icon-purple");
}
else if (typeof(IVariableIcon).IsAssignableFrom(type))
{
return icons.FirstOrDefault((icon) => icon.Name == "atom-icon-orange");
}
else if (typeof(IConstantIcon).IsAssignableFrom(type))
{
return icons.FirstOrDefault((icon) => icon.Name == "atom-icon-teal");
}
else if (typeof(IEventIcon).IsAssignableFrom(type))
{
return icons.FirstOrDefault((icon) => icon.Name == "atom-icon-teal");
}
else if (typeof(IFunctionIcon).IsAssignableFrom(type))
{
return icons.FirstOrDefault((icon) => icon.Name == "atom-icon-lush");
}
else if (typeof(IListenerIcon).IsAssignableFrom(type))
{
return icons.FirstOrDefault((icon) => icon.Name == "atom-icon-piglet");
}
else if (typeof(IListIcon).IsAssignableFrom(type))
{
return icons.FirstOrDefault((icon) => icon.Name == "atom-icon-pinky");
}
}
return null;
};
}
}
}

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

10 changes: 10 additions & 0 deletions Source/IconAssignmentPostProcessor/IIconAssigner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;
using UnityEngine;

namespace UnityAtoms
{
public interface IIconAssigner
{
void Assign(string assetPath, List<IconData> icons, IconAssigmentSettings settings);
}
}
11 changes: 11 additions & 0 deletions Source/IconAssignmentPostProcessor/IIconAssigner.cs.meta

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

18 changes: 18 additions & 0 deletions Source/IconAssignmentPostProcessor/IconAssigmentSetting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using UnityEngine;

namespace UnityAtoms
{
[Serializable]
public class IconAssigmentSetting
{
public IconAssigmentSetting(string assetPath, string iconPath)
{
AssetPath = assetPath;
IconPath = iconPath;
}

public string AssetPath;
public string IconPath;
}
}
11 changes: 11 additions & 0 deletions Source/IconAssignmentPostProcessor/IconAssigmentSetting.cs.meta

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

Loading

0 comments on commit cb6280a

Please sign in to comment.