mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 08:47:37 +02:00
Discord rich presence
This commit is contained in:
50
Assets/Scripts/Common/Parallax.cs
Normal file
50
Assets/Scripts/Common/Parallax.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace RhythmHeavenMania.Common
|
||||
{
|
||||
public class Parallax : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Vector2 parallaxEffectMultiplier;
|
||||
|
||||
private Transform camTransform;
|
||||
private Vector3 lastCamPos;
|
||||
public float textureUnitSizeX;
|
||||
|
||||
public bool sprite = true;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
camTransform = Camera.main.transform;
|
||||
lastCamPos = camTransform.position;
|
||||
/*if (sprite)
|
||||
{
|
||||
Sprite sprite = GetComponent<SpriteRenderer>().sprite;
|
||||
Texture2D texture = sprite.texture;
|
||||
textureUnitSizeX = texture.width / sprite.pixelsPerUnit;
|
||||
}
|
||||
else
|
||||
{
|
||||
Image image = GetComponent<Image>();
|
||||
Texture texture = image.mainTexture;
|
||||
textureUnitSizeX = texture.width / image.pixelsPerUnit;
|
||||
}*/
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
Vector3 deltaMovement = camTransform.position - lastCamPos;
|
||||
transform.position += new Vector3(deltaMovement.x * parallaxEffectMultiplier.x, deltaMovement.y * parallaxEffectMultiplier.y, 0);
|
||||
lastCamPos = camTransform.position;
|
||||
|
||||
if (Mathf.Abs(camTransform.position.x - transform.position.x) >= textureUnitSizeX)
|
||||
{
|
||||
float offsetPosX = (camTransform.position.x - transform.position.x) % textureUnitSizeX;
|
||||
transform.position = new Vector3(camTransform.position.x + offsetPosX, transform.position.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Common/Parallax.cs.meta
Normal file
11
Assets/Scripts/Common/Parallax.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eaa95a9ff0cbc6c47a89367e6da5c7bd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
34
Assets/Scripts/Common/Scroll.cs
Normal file
34
Assets/Scripts/Common/Scroll.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RhythmHeavenMania.Common
|
||||
{
|
||||
public class Scroll : MonoBehaviour
|
||||
{
|
||||
public float scrollSpeedX;
|
||||
public float scrollSpeedY;
|
||||
Vector3 startPos;
|
||||
|
||||
public float lengthX;
|
||||
public float lengthY = 43.20976f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
startPos = transform.localPosition;
|
||||
UpdatePos();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
UpdatePos();
|
||||
}
|
||||
|
||||
private void UpdatePos()
|
||||
{
|
||||
float newPosX = Mathf.Repeat(Time.time * scrollSpeedX, lengthX);
|
||||
float newPosY = Mathf.Repeat(Time.time * scrollSpeedY, lengthY);
|
||||
transform.localPosition = startPos + new Vector3(1 * newPosX, 1 * newPosY);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Common/Scroll.cs.meta
Normal file
11
Assets/Scripts/Common/Scroll.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 45eb7daf344474546ba5079bf18eae01
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
110
Assets/Scripts/DiscordController.cs
Normal file
110
Assets/Scripts/DiscordController.cs
Normal file
@ -0,0 +1,110 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Text;
|
||||
using Discord;
|
||||
using System;
|
||||
|
||||
namespace RhythmHeavenMania.DiscordRPC
|
||||
{
|
||||
public class DiscordController : MonoBehaviour
|
||||
{
|
||||
public Discord.Discord discord;
|
||||
|
||||
public static DiscordController instance { get; set; }
|
||||
|
||||
private long lastStartTime;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// instance = this;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
DontDestroyOnLoad(this.gameObject);
|
||||
}
|
||||
|
||||
private void OnApplicationQuit()
|
||||
{
|
||||
Disconnect();
|
||||
}
|
||||
|
||||
public void Connect()
|
||||
{
|
||||
discord = new Discord.Discord(DiscordRPC.clientID, (System.UInt64)Discord.CreateFlags.Default);
|
||||
}
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
if (discord != null)
|
||||
{
|
||||
discord.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateActivity(string stateText, string stateDetails, bool updateTime = false)
|
||||
{
|
||||
var activityManager = discord.GetActivityManager();
|
||||
var activity = new Activity { };
|
||||
|
||||
|
||||
activity = new Activity
|
||||
{
|
||||
State = stateText,
|
||||
Details = stateDetails,
|
||||
Assets =
|
||||
{
|
||||
LargeImage = "logo",
|
||||
LargeText = "Rhythm Heaven Mania is based on the Rhythm Heaven series that attempts to recreate every minigame with customizability!"
|
||||
},
|
||||
Instance = true,
|
||||
};
|
||||
|
||||
if (updateTime == true)
|
||||
{
|
||||
lastStartTime = DateTimeOffset.Now.ToUnixTimeSeconds();
|
||||
activity.Timestamps.Start = lastStartTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
activity.Timestamps.Start = lastStartTime;
|
||||
}
|
||||
|
||||
activityManager.UpdateActivity(activity, (result) => {
|
||||
if (result == Discord.Result.Ok)
|
||||
{
|
||||
Debug.Log("Update Success!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Update Failed");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void ClearActivity()
|
||||
{
|
||||
var activityManager = discord.GetActivityManager();
|
||||
activityManager.ClearActivity((result) => {
|
||||
if (result == Discord.Result.Ok)
|
||||
{
|
||||
Debug.Log("Clear Success!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Clear Failed");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (discord != null)
|
||||
{
|
||||
discord.RunCallbacks();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/DiscordController.cs.meta
Normal file
11
Assets/Scripts/DiscordController.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4fda65d1df0676c49913aaa4c138c6f5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
39
Assets/Scripts/DiscordRPC.cs
Normal file
39
Assets/Scripts/DiscordRPC.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace RhythmHeavenMania.DiscordRPC
|
||||
{
|
||||
public class DiscordRPC : MonoBehaviour
|
||||
{
|
||||
public static long clientID = 937480118518042675;
|
||||
|
||||
private static void DiscordControllerCheck()
|
||||
{
|
||||
if (DiscordController.instance == null)
|
||||
{
|
||||
var discordController = new GameObject("DiscordController");
|
||||
var di = discordController.AddComponent<DiscordController>();
|
||||
DiscordController.instance = di;
|
||||
di.Connect();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Connect()
|
||||
{
|
||||
DiscordControllerCheck();
|
||||
DiscordController.instance.Connect();
|
||||
}
|
||||
|
||||
public static void UpdateActivity(string state = null, string details = null, bool updateTime = false)
|
||||
{
|
||||
DiscordControllerCheck();
|
||||
DiscordController.instance.UpdateActivity(details, state, updateTime);
|
||||
}
|
||||
|
||||
public static void Disconnect()
|
||||
{
|
||||
DiscordControllerCheck();
|
||||
DiscordController.instance.Disconnect();
|
||||
Destroy(DiscordController.instance.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/DiscordRPC.cs.meta
Normal file
11
Assets/Scripts/DiscordRPC.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 896ff10d4b52e8c42ad72ec0545f8389
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -18,19 +18,16 @@ namespace RhythmHeavenMania
|
||||
private List<GameObject> preloadedGames = new List<GameObject>();
|
||||
public List<GameObject> SoundObjects = new List<GameObject>();
|
||||
|
||||
|
||||
[Header("Components")]
|
||||
public TextAsset txt;
|
||||
public Camera GameCamera, CursorCam;
|
||||
public CircleCursor CircleCursor;
|
||||
[HideInInspector] public GameObject GamesHolder;
|
||||
|
||||
|
||||
[Header("Games")]
|
||||
public string currentGame;
|
||||
Coroutine currentGameSwitchIE;
|
||||
|
||||
|
||||
[Header("Properties")]
|
||||
public int currentEvent, currentTempoEvent;
|
||||
public float startOffset;
|
||||
@ -38,6 +35,10 @@ namespace RhythmHeavenMania
|
||||
public float startBeat;
|
||||
private GameObject currentGameO;
|
||||
public bool autoplay;
|
||||
public int BeatmapEntities()
|
||||
{
|
||||
return Beatmap.entities.Count + Beatmap.tempoChanges.Count;
|
||||
}
|
||||
|
||||
public static GameManager instance { get; private set; }
|
||||
private EventCaller eventCaller;
|
||||
|
@ -98,7 +98,7 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
|
||||
if (dispensing)
|
||||
{
|
||||
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(dispensedBeat, 2.35f);
|
||||
holder.transform.position = dispenseCurve.GetPoint(normalizedBeatAnim);
|
||||
holder.transform.localPosition = dispenseCurve.GetPoint(normalizedBeatAnim);
|
||||
spriteHolder.transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(0f, -1440f, normalizedBeatAnim));
|
||||
|
||||
/*if (PlayerInput.Pressed())
|
||||
@ -112,7 +112,7 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
|
||||
else if (kicked.enabled)
|
||||
{
|
||||
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(kicked.startBeat, 1.5f);
|
||||
holder.transform.position = kickCurve.GetPoint(normalizedBeatAnim);
|
||||
holder.transform.localPosition = kickCurve.GetPoint(normalizedBeatAnim);
|
||||
if (!lastKickLeft)
|
||||
{
|
||||
spriteHolder.transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(lastSpriteRot, lastSpriteRot - 360f, normalizedBeatAnim));
|
||||
@ -141,7 +141,7 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
|
||||
else if (highKicked.enabled)
|
||||
{
|
||||
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(highKicked.startBeat, 1.8f);
|
||||
holder.transform.position = highKickCurve.GetPoint(normalizedBeatAnim);
|
||||
holder.transform.localPosition = highKickCurve.GetPoint(normalizedBeatAnim);
|
||||
spriteHolder.transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(lastSpriteRot, lastSpriteRot + 360f, normalizedBeatAnim));
|
||||
|
||||
// if (state.perfect) Debug.Break();
|
||||
@ -165,7 +165,7 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
|
||||
else if (toe.enabled)
|
||||
{
|
||||
float normalizedBeatAnim = Conductor.instance.GetLoopPositionFromBeat(toe.startBeat, 1.85f);
|
||||
holder.transform.position = toeCurve.GetPoint(normalizedBeatAnim);
|
||||
holder.transform.localPosition = toeCurve.GetPoint(normalizedBeatAnim);
|
||||
spriteHolder.transform.eulerAngles = new Vector3(0, 0, Mathf.Lerp(lastSpriteRot, -860f, normalizedBeatAnim));
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,8 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
|
||||
[Header("Components")]
|
||||
[SerializeField] private GameObject ballRef;
|
||||
[SerializeField] private Kicker kicker;
|
||||
[SerializeField] private GameObject Background;
|
||||
[SerializeField] private Sprite[] backgroundSprite;
|
||||
|
||||
[Header("Properties")]
|
||||
[SerializeField] private bool ballDispensed;
|
||||
@ -22,11 +24,29 @@ namespace RhythmHeavenMania.Games.SpaceSoccer
|
||||
instance = this;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
for (int x = 0; x < Random.Range(9, 12); x++)
|
||||
{
|
||||
for (int y = 0; y < Random.Range(6, 9); y++)
|
||||
{
|
||||
GameObject test = new GameObject("test");
|
||||
test.transform.parent = Background.transform;
|
||||
test.AddComponent<SpriteRenderer>().sprite = backgroundSprite[Random.Range(0, 2)];
|
||||
test.GetComponent<SpriteRenderer>().sortingOrder = -50;
|
||||
test.transform.localPosition = new Vector3(Random.Range(-15f, 15f), Random.Range(-15f, 15f));
|
||||
test.transform.localScale = new Vector3(0.52f, 0.52f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (ballDispensed)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void Dispense(float beat)
|
||||
|
@ -50,6 +50,7 @@ namespace RhythmHeavenMania.Editor
|
||||
[Header("Properties")]
|
||||
private bool changedMusic = false;
|
||||
private string currentRemixPath = "";
|
||||
private int lastEditorObjectsCount = 0;
|
||||
|
||||
public static Editor instance { get; private set; }
|
||||
|
||||
@ -84,6 +85,8 @@ namespace RhythmHeavenMania.Editor
|
||||
Tooltip.AddTooltip(MusicSelectBTN.gameObject, "Music Select");
|
||||
Tooltip.AddTooltip(EditorSettingsBTN.gameObject, "Editor Settings <color=#adadad>[Ctrl+Shift+O]</color>");
|
||||
Tooltip.AddTooltip(EditorThemeBTN.gameObject, "Editor Theme");
|
||||
|
||||
UpdateEditorStatus(true);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
@ -173,6 +176,13 @@ namespace RhythmHeavenMania.Editor
|
||||
SaveRemix(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (lastEditorObjectsCount != GameManager.instance.BeatmapEntities())
|
||||
{
|
||||
UpdateEditorStatus(false);
|
||||
}
|
||||
|
||||
lastEditorObjectsCount = GameManager.instance.BeatmapEntities();
|
||||
}
|
||||
|
||||
public static Sprite GameIcon(string name)
|
||||
@ -358,6 +368,12 @@ namespace RhythmHeavenMania.Editor
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
private void UpdateEditorStatus(bool updateTime)
|
||||
{
|
||||
DiscordRPC.DiscordRPC.UpdateActivity("In Editor", $"Objects: {GameManager.instance.Beatmap.entities.Count + GameManager.instance.Beatmap.tempoChanges.Count}", updateTime);
|
||||
}
|
||||
|
||||
public string GetJson()
|
||||
{
|
||||
string json = string.Empty;
|
||||
|
Reference in New Issue
Block a user