-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
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,20 @@ | ||
{ | ||
"name": "BetterConditions.Editor", | ||
"rootNamespace": "Better.Conditions.EditorAddons", | ||
"references": [ | ||
"GUID:01df13aca8d01e24a911bcc3e8277031", | ||
"GUID:6adbd2a12d24f5d429f7ea1b1086e835", | ||
"GUID:fe96bdec06a75af4184a0252929f642e" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Arcueid D'athemon (https://github.com/uurha) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Better Conditions | ||
|
||
[![openupm](https://img.shields.io/npm/v/com.tdw.better.conditions?label=openupm®istry_uri=https://package.openupm.com)](https://openupm.com/packages/com.tdw.better.conditions/) | ||
|
||
## Install | ||
[How to install](https://github.com/uurha/BetterPluginCollection/wiki/How-to-install) |
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,18 @@ | ||
{ | ||
"name": "BetterConditions.Runtime", | ||
"rootNamespace": "Better.Conditions.Runtime", | ||
"references": [ | ||
"GUID:01df13aca8d01e24a911bcc3e8277031", | ||
"GUID:8bd4b41f8da90144d9006c4d926c9679", | ||
"GUID:35101f455c979e94c9a0a4793484b7fd" | ||
], | ||
"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.
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,144 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Better.Commons.Runtime.Conditions; | ||
using Better.Commons.Runtime.Utility; | ||
|
||
namespace Better.Commons.Runtime.Extensions | ||
{ | ||
public static class ConditionExtensions | ||
{ | ||
public static void Rebuild(this IEnumerable<Condition> self) | ||
{ | ||
if (self == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(self)); | ||
return; | ||
} | ||
|
||
foreach (var condition in self) | ||
{ | ||
condition.Rebuild(); | ||
} | ||
} | ||
|
||
public static bool Validate(this IEnumerable<Condition> self, bool logException = Condition.DefaultLogException) | ||
{ | ||
if (self == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(self)); | ||
return false; | ||
} | ||
|
||
foreach (var condition in self) | ||
{ | ||
if (!condition.Validate(logException)) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public static bool InvokeAll(this IEnumerable<Condition> self) | ||
{ | ||
if (self == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(self)); | ||
return false; | ||
} | ||
|
||
foreach (var condition in self) | ||
{ | ||
if (!condition.Invoke()) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public static bool SafeInvokeAll(this IEnumerable<Condition> self, bool logException = Condition.DefaultLogException) | ||
{ | ||
if (self == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(self)); | ||
return false; | ||
} | ||
|
||
foreach (var condition in self) | ||
{ | ||
if (!condition.SafeInvoke(logException)) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public static bool InvokeAny(this IEnumerable<Condition> self) | ||
{ | ||
if (self == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(self)); | ||
return false; | ||
} | ||
|
||
foreach (var condition in self) | ||
{ | ||
if (condition.Invoke()) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public static bool SafeInvokeAny(this IEnumerable<Condition> self, bool logException = Condition.DefaultLogException) | ||
{ | ||
if (self == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(self)); | ||
return false; | ||
} | ||
|
||
foreach (var condition in self) | ||
{ | ||
if (condition.SafeInvoke(logException)) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public static void CollectValidated(this ICollection<Condition> self, IEnumerable<Condition> source, bool logException = true) | ||
{ | ||
if (self == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(self)); | ||
return; | ||
} | ||
|
||
if (source == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(source)); | ||
return; | ||
} | ||
|
||
foreach (var condition in source) | ||
{ | ||
if (condition.Validate(logException) | ||
&& !self.Contains(condition)) | ||
{ | ||
self.Add(condition); | ||
} | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,12 @@ | ||
using System; | ||
|
||
namespace Better.Commons.Runtime.Conditions | ||
{ | ||
[Serializable] | ||
public abstract class ApplicationCondition<TState> : StateCondition<TState> | ||
{ | ||
protected ApplicationCondition(TState targetState) : base(targetState) | ||
{ | ||
} | ||
} | ||
} |
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,22 @@ | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace Better.Commons.Runtime.Conditions | ||
{ | ||
[Serializable] | ||
public class FocusedApplicationCondition : ApplicationCondition<bool> | ||
{ | ||
public FocusedApplicationCondition(bool state) : base(state) | ||
{ | ||
} | ||
|
||
public FocusedApplicationCondition() : this(true) | ||
{ | ||
} | ||
|
||
public override bool Invoke() | ||
{ | ||
return Application.isFocused == TargetState; | ||
} | ||
} | ||
} |
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,22 @@ | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace Better.Commons.Runtime.Conditions | ||
{ | ||
[Serializable] | ||
public class PlatformApplicationCondition : ApplicationCondition<RuntimePlatform> | ||
{ | ||
public PlatformApplicationCondition(RuntimePlatform state) : base(state) | ||
{ | ||
} | ||
|
||
protected PlatformApplicationCondition() : this(RuntimePlatform.WindowsEditor) | ||
{ | ||
} | ||
|
||
public override bool Invoke() | ||
{ | ||
return Application.platform == TargetState; | ||
} | ||
} | ||
} |
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,22 @@ | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace Better.Commons.Runtime.Conditions | ||
{ | ||
[Serializable] | ||
public class SystemLanguageCondition : ApplicationCondition<SystemLanguage> | ||
{ | ||
public SystemLanguageCondition(SystemLanguage state) : base(state) | ||
{ | ||
} | ||
|
||
protected SystemLanguageCondition() : this(SystemLanguage.English) | ||
{ | ||
} | ||
|
||
public override bool Invoke() | ||
{ | ||
return Application.systemLanguage == TargetState; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.