Skip to content
This repository has been archived by the owner on Jan 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #8 from Juce-Assets/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillemsc authored Nov 20, 2020
2 parents 951b5f1 + 58752b5 commit 2a45244
Show file tree
Hide file tree
Showing 13 changed files with 252 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/greetings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: 'Thanks for contributing to Juce-Feedbacks'' first issue'
pr-message: 'Hey, this is your fist contribuition to Juce-Feedbacks! Thank you very much, as you help making a better tool for everyone :)'' first pr'
pr-message: 'Hey, this is your fist contribuition to Juce-Feedbacks! Thank you very much, as you help making a better tool for everyone :). If you want to chat or discuss anything more in-depth, feel free to join the Discord: https://discord.gg/dbG7zKA'' first pr'
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
## [Unreleased]

### Features
- Global acces to FeedbackPlayers through a singleton and an id

### Bug Fixes

Expand Down
8 changes: 8 additions & 0 deletions Editor/Icons.meta

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

Binary file added Editor/Icons/Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 92 additions & 0 deletions Editor/Icons/Icon.png.meta

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

8 changes: 8 additions & 0 deletions Examples/Exam.meta

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

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Read the [Contribution Guide](https://github.com/Juce-Assets/Juce-Feedbacks/wiki
## Minimum Requirements
- Unity 2019.3.2

## Installing from the AssetStore
Download the package directly from the AssetStore [here](http://u3d.as/26H3)

## Installing via UnityPackage
Download the latest [release](https://github.com/Juce-Assets/Juce-Feedbacks/releases/latest).

Expand All @@ -41,3 +44,6 @@ And that's all, with that you should be ready to go!

## Usage
Read the [Usage Guide](https://github.com/Juce-Assets/Juce-Feedbacks/wiki/Usage-Guide) for more information.

## Upcoming features
- [On Development (Progress: 0%)] Global acces to FeedbackPlayers through a singleton and an id. (Estimated Release: 27-11-2020)
2 changes: 1 addition & 1 deletion Runtime/Feedbacks/Feedback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public abstract class Feedback : MonoBehaviour

[SerializeField] private string userData = default;

[Header("Scripting")]
[Header(FeedbackSectionsUtils.ScriptingSection)]
[SerializeField] private ScriptUsageProperty scriptUsage = default;

public bool Expanded { get => expanded; set => expanded = value; }
Expand Down
62 changes: 57 additions & 5 deletions Runtime/FeedbacksPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,29 @@ public class FeedbacksPlayer : MonoBehaviour
[SerializeField] [HideInInspector] private List<Feedback> feedbacks = new List<Feedback>();

[SerializeField] private bool executeOnAwake = default;
[SerializeField] private ScriptUsageProperty scriptUsage = default;
[SerializeField] private LoopProperty loop = default;

private SequenceTween currMainSequence;

internal ScriptUsageProperty RegisteredScriptUsage;

public bool IsPlaying { get; private set; }
public IReadOnlyList<Feedback> Feedbacks => feedbacks;

public ScriptUsageProperty ScriptUsage => scriptUsage;
public LoopProperty Loop => loop;

public event Action<string> OnEventTrigger;

private void Awake()
{
if (Application.isPlaying)
{
TryRegister();
}
}

private void Start()
{
if (Application.isPlaying)
Expand All @@ -32,6 +46,11 @@ private void Start()

private void OnDestroy()
{
if (Application.isPlaying)
{
TryUnregister();
}

CleanUp();
}

Expand All @@ -40,7 +59,6 @@ private void CleanUp()
foreach (Feedback feedback in feedbacks)
{
#if UNITY_EDITOR

if (Application.isPlaying)
{
Destroy(feedback);
Expand All @@ -52,17 +70,46 @@ private void CleanUp()
DestroyImmediate(feedback);
};
}

#else

Destroy(feedback);

#endif
}

feedbacks.Clear();
}

private void TryRegister()
{
if (!scriptUsage.UsedByScript)
{
return;
}

bool success = JuceFeedbacks.Instance.RegisterFeedbacksPlayerUsedByScript(this);

if (success)
{
RegisteredScriptUsage = scriptUsage;
}
}

private void TryUnregister()
{
if (RegisteredScriptUsage == null)
{
return;
}

if (!RegisteredScriptUsage.UsedByScript)
{
return;
}

JuceFeedbacks.Instance.UnregisterFeedbacksPlayerUsedByScript(RegisteredScriptUsage.IdUsedByScript);

RegisteredScriptUsage = null;
}

private void TryExecuteOnAwake()
{
if (!executeOnAwake)
Expand Down Expand Up @@ -94,7 +141,7 @@ public void Play(Action onFinish = null)
{
Feedback currFeedback = feedbacks[i];

if(currFeedback == null)
if (currFeedback == null)
{
UnityEngine.Debug.LogError($"There is a null {nameof(Feedback)} on the GameObject {gameObject.name}", gameObject);
continue;
Expand Down Expand Up @@ -165,6 +212,11 @@ public void Restart()
currMainSequence.Restart();
}


/// <summary>
/// Returns the <typeparamref name="Feedback"/> found, which has the Used By Script toggled, and the Id Used By Script defined on the editor.
/// Returns null if not found.
/// </summary>
public T GetFeedback<T>(string id) where T : Feedback
{
Type lookingForType = typeof(T);
Expand Down
2 changes: 1 addition & 1 deletion Runtime/FeedbacksPlayer.cs.meta

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

65 changes: 65 additions & 0 deletions Runtime/JuceFeedbacks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Juce.Utils.Singletons;
using System;
using System.Collections.Generic;

namespace Juce.Feedbacks
{
public class JuceFeedbacks : AutoStartMonoSingleton<JuceFeedbacks>
{
private readonly Dictionary<string, FeedbacksPlayer> feedbackPlayersUsedByScript = new Dictionary<string, FeedbacksPlayer>();

internal bool RegisterFeedbacksPlayerUsedByScript(FeedbacksPlayer feedbacksPlayer)
{
if (!feedbacksPlayer.ScriptUsage.UsedByScript)
{
return false;
}

if (string.IsNullOrEmpty(feedbacksPlayer.ScriptUsage.IdUsedByScript))
{
UnityEngine.Debug.LogError($"Trying to register a {nameof(FeedbacksPlayer)}, but the Id Used By Script is empty. " +
$"Please set an id or untoggle Used By Script.", feedbacksPlayer);

return false;
}

if (feedbackPlayersUsedByScript.ContainsKey(feedbacksPlayer.ScriptUsage.IdUsedByScript))
{
UnityEngine.Debug.LogError($"Trying to register a {nameof(FeedbacksPlayer)}, but the Id Used By Script " +
$"'{feedbacksPlayer.ScriptUsage.IdUsedByScript}' is already used by " +
$"another {nameof(FeedbacksPlayer)}. Please set an Id Used By Script that's unique.", feedbacksPlayer);

return false;
}

feedbackPlayersUsedByScript.Add(feedbacksPlayer.ScriptUsage.IdUsedByScript, feedbacksPlayer);

return true;
}

internal void UnregisterFeedbacksPlayerUsedByScript(string id)
{
feedbackPlayersUsedByScript.Remove(id);
}

/// <summary>
/// Returns the <typeparamref name="FeedbacksPlayer"/> found, which has the Used By Script toggled, and the Id Used By Script defined on the editor.
/// Returns null if not found.
/// </summary>
public static FeedbacksPlayer GetFeedbacksPlayer(string id)
{
Instance.feedbackPlayersUsedByScript.TryGetValue(id, out FeedbacksPlayer feedbacksPlayer);

return feedbacksPlayer;
}

/// <summary>
/// Outs the <typeparamref name="FeedbacksPlayer"/> found, which has the Used By Script toggled, and the Id Used By Script defined on the editor.
/// Returns false if not found.
/// </summary>
public static bool TryGetFeedbacksPlayer(string id, out FeedbacksPlayer feedbacksPlayer)
{
return Instance.feedbackPlayersUsedByScript.TryGetValue(id, out feedbacksPlayer);
}
}
}
11 changes: 11 additions & 0 deletions Runtime/JuceFeedbacks.cs.meta

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

1 change: 1 addition & 0 deletions Runtime/Utils/FeedbackSectionsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public static class FeedbackSectionsUtils
{
public const string ScriptingSection = "Scripting";
public const string TargetSection = "Target";
public const string ValuesSection = "Values";
public const string TimingSection = "Timing";
Expand Down

0 comments on commit 2a45244

Please sign in to comment.