Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mackysoft committed May 19, 2020
0 parents commit 8f5aa85
Show file tree
Hide file tree
Showing 45 changed files with 2,451 additions and 0 deletions.
70 changes: 70 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/

# MemoryCaptures can get excessive in size.
# They also could contain extremely sensitive data
/[Mm]emoryCaptures/

# Asset meta data should only be ignored when the corresponding asset is also ignored
!/[Aa]ssets/**/*.meta

# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*

# Autogenerated Jetbrains Rider plugin
/[Aa]ssets/Plugins/Editor/JetBrains*

# Visual Studio cache directory
.vs/

# Gradle cache directory
.gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
*.unitypackage

# Crashlytics generated file
crashlytics-build.properties

# Packed Addressables
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*

# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*
8 changes: 8 additions & 0 deletions Assets/MackySoft.meta

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

8 changes: 8 additions & 0 deletions Assets/MackySoft/MackySoft.Modiferty.meta

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

8 changes: 8 additions & 0 deletions Assets/MackySoft/MackySoft.Modiferty/Scripts.meta

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Linq;

namespace MackySoft.Modiferty {
public static class IModifiablePropertyExtensions {

public static bool Contains<T> (this IReadOnlyModifiableProperty<T> source,IModifier<T> modifier) {
return source.Modifiers.Contains(modifier);
}

/// <summary>
/// Shortcut of <see cref="IModifiableProperty{T}.Modifiers"/>.Add(modifier);
/// </summary>
public static void Add<T> (this IModifiableProperty<T> source,IModifier<T> modifier) {
source.Modifiers.Add(modifier);
}

/// <summary>
/// Shortcut of <see cref="IModifiableProperty{T}.Modifiers"/>.Remove(modifier);
/// </summary>
public static bool Remove<T> (this IModifiableProperty<T> source,IModifier<T> modifier) {
return source.Modifiers.Remove(modifier);
}

/// <summary>
/// Shortcut of <see cref="IModifiableProperty{T}.Modifiers"/>.Clear();
/// </summary>
public static void Clear<T> (this IModifiableProperty<T> source) {
source.Modifiers.Clear();
}

}

}

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

18 changes: 18 additions & 0 deletions Assets/MackySoft/MackySoft.Modiferty/Scripts/IModifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace MackySoft.Modiferty {

public interface IModifier<T> {

/// <summary>
/// <para> Priority of evaluation. </para>
/// <para> See: <see cref="ModifierList{T}.Evaluate(T)"/> </para>
/// </summary>
int Priority { get; }

/// <summary>
/// Evaluate the value.
/// </summary>
/// <param name="value"> Value to be modified. </param>
T Evaluate (T value);

}
}
11 changes: 11 additions & 0 deletions Assets/MackySoft/MackySoft.Modiferty/Scripts/IModifier.cs.meta

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "MackySoft.Modiferty",
"references": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using UnityEngine;

namespace MackySoft.Modiferty {

public interface IReadOnlyModifiableProperty<T> {

/// <summary>
/// Base value before the evaluation.
/// </summary>
T BaseValue { get; }

/// <summary>
/// List of <see cref="IModifier{T}"/> to evaluate base value.
/// </summary>
IReadOnlyModifierList<T> Modifiers { get; }

/// <summary>
/// <para> Whether has modifiers. </para>
/// <para> This is used to avoid creating unnecessary ModifierList. </para>
/// </summary>
bool HasModifiers { get; }

/// <summary>
/// Evaluate the base value by modifiers.
/// </summary>
T Evaluate ();

}

public interface IModifiableProperty<T> : IReadOnlyModifiableProperty<T> {

/// <summary>
/// Base value before the evaluation.
/// </summary>
new T BaseValue { get; set; }

/// <summary>
/// List of <see cref="IModifier{T}"/> to evaluate base value.
/// </summary>
new IModifierList<T> Modifiers { get; }

}

[Serializable]
public class ModifieableProperty<T> : IModifiableProperty<T> {

[SerializeField]
T m_BaseValue;

[NonSerialized]
ModifierList<T> m_Modifiers;

public T BaseValue {
get => m_BaseValue;
set => m_BaseValue = value;
}

public IModifierList<T> Modifiers => m_Modifiers ?? (m_Modifiers = new ModifierList<T>());

public bool HasModifiers => (m_Modifiers != null) && (m_Modifiers.Count > 0);

IReadOnlyModifierList<T> IReadOnlyModifiableProperty<T>.Modifiers => Modifiers;

public ModifieableProperty () : this(default) {
}

public ModifieableProperty (T baseValue) {
m_BaseValue = baseValue;
}

public T Evaluate () {
return (m_Modifiers != null) ? m_Modifiers.Evaluate(m_BaseValue) : m_BaseValue;
}

}

}

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

36 changes: 36 additions & 0 deletions Assets/MackySoft/MackySoft.Modiferty/Scripts/ModifierList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace MackySoft.Modiferty {

public interface IReadOnlyModifierList<T> : IReadOnlyList<IModifier<T>> {

/// <summary>
/// Evaluate the value.
/// </summary>
/// <param name="value"> Value to be modified. </param>
T Evaluate (T value);

}

public interface IModifierList<T> : IList<IModifier<T>>, IReadOnlyModifierList<T> {
new int Count { get; }
}

[Serializable]
public class ModifierList<T> : Collection<IModifier<T>>, IModifierList<T> {

public T Evaluate (T value) {
if (Items.Count > 0) {
foreach (IModifier<T> modifier in Items.OrderByDescending(m => m.Priority)) {
value = modifier.Evaluate(value);
}
}
return value;
}

}

}
11 changes: 11 additions & 0 deletions Assets/MackySoft/MackySoft.Modiferty/Scripts/ModifierList.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 Assets/MackySoft/MackySoft.Modiferty/Scripts/Modifiers.meta

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

namespace MackySoft.Modiferty {
public class CreateModifier<T> : IModifier<T> {

public Func<T,T> ModifyMethod { get; set; }
public int Priority { get; set; }

public CreateModifier (Func<T,T> modifyMethod) {
ModifyMethod = modifyMethod;
}

public T Evaluate (T value) {
return ModifyMethod.Invoke(value);
}

}

}

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

Loading

0 comments on commit 8f5aa85

Please sign in to comment.