Skip to content

Commit

Permalink
Created repository
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedDevStuff committed Sep 29, 2022
0 parents commit 3381c1c
Show file tree
Hide file tree
Showing 8 changed files with 535 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/bin
/lib
/obj
UltraAchievement Core.sln
Binary file not shown.
Binary file added .vs/UltraAchievement Core/v16/.suo
Binary file not shown.
71 changes: 71 additions & 0 deletions Achievement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UltraAchievement;

public class Achievement : MonoBehaviour
{
private float endTimer = 0;
private float startTimer = 0;
private float animTimer;
private bool endTimerStarted = false;
private bool startTimerStarted = false;
private RectTransform rect;
private Image icon;
private Text title,description;

public void InitAchievement(string iconPath, string name = "Achievement", string desc = "Example description")
{
rect = GetComponent<RectTransform>();
title = transform.GetChild(0).GetComponent<Text>();
description = transform.GetChild(1).GetComponent<Text>();
icon = transform.GetChild(2).GetComponent<Image>();
title.text = name;
description.text = desc;
icon.sprite = Core.LoadSprite(iconPath,Vector4.zero,100);
rect.anchoredPosition = new Vector2(400,0);
startTimerStarted = true;
}
public void InitAchievementI(Sprite ico, string name = "Achievement", string desc = "Example description")
{
rect = GetComponent<RectTransform>();
title = transform.GetChild(0).GetComponent<Text>();
description = transform.GetChild(1).GetComponent<Text>();
icon = GetComponentInChildren<Image>();
title.text = name;
description.text = desc;
icon.sprite = ico;
rect.anchoredPosition = new Vector2(400,0);
startTimerStarted = true;
}
void Update()
{
if(startTimerStarted)
{
startTimer += Time.deltaTime;
animTimer += Time.deltaTime * 1.35f;
if (animTimer >= 1) animTimer = 1;
rect.anchoredPosition = new Vector2(Mathf.Lerp(400f, 0f, animTimer),0);
if(startTimer >= 5)
{
animTimer = 0;
endTimerStarted = true;
startTimerStarted = false;
}
}
if(endTimerStarted)
{
endTimer += Time.deltaTime;
animTimer += Time.deltaTime * 1.35f;
if (animTimer >= 1) animTimer = 1;
rect.anchoredPosition = new Vector2(Mathf.Lerp(0f, 400f, animTimer), 0);
if (endTimer >= 5)
{
endTimerStarted = false;
Destroy(this.gameObject);
}
}
}
}
6 changes: 6 additions & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="BepInEx" value="https://nuget.bepinex.dev/v3/index.json" />
</packageSources>
</configuration>
193 changes: 193 additions & 0 deletions Plugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
using BepInEx;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;

namespace UltraAchievement
{
[BepInPlugin("zeddev.ultraachievement.core", "ultraAchievement Core", "1.0.0")]
public class Core : BaseUnityPlugin
{
public static Core current;
private static string path;
private static List<string> obtainedAchievements = new List<string>();
private GameObject overlay;
private GameObject achievementTemplate;
private void Awake()
{
current = this;
path = $"{Application.persistentDataPath}\\achievements.uaf";
if(File.Exists(path))
{
obtainedAchievements = GetAchievements();
}
else File.Create(path);
// For testing purposes only
//UnityEngine.SceneManagement.SceneManager.sceneLoaded += Scene;
Logger.LogInfo($"Loaded UltraAchievement core");
overlay = CreateOverlay();
achievementTemplate = CreateTemplate();

}

public static void ShowAchievement(string iconPath, string name = "Achievement", string desc = "Example description")
{
if(!HasAchievement(name))
{
AddAchievement(name);
GameObject achievement = CreateTemplate();
achievement.GetComponent<RectTransform>().SetParent(current.overlay.GetComponent<RectTransform>());
achievement.GetComponent<Achievement>().InitAchievement(iconPath,name,desc);
}
}
public static void ShowAchievement(Sprite icon, string name = "Achievement", string desc = "Example description")
{
if(!HasAchievement(name))
{
AddAchievement(name);
GameObject achievement = CreateTemplate();
achievement.GetComponent<RectTransform>().SetParent(current.overlay.GetComponent<RectTransform>());
achievement.GetComponent<Achievement>().InitAchievementI(icon,name,desc);
}
}
void Scene(UnityEngine.SceneManagement.Scene scene, UnityEngine.SceneManagement.LoadSceneMode loadSceneMode)
{
if(scene.name.Contains("Menu"))
{
Logger.LogInfo("In Menu");
ShowAchievement($"{Directory.GetCurrentDirectory()}\\BepInEx\\UKMM Mods\\UKUIHelper-v0.7.0\\Sprites\\Sprite.png", "Ultrakillin' Time", "Open Ultrakill");
}
}

public static GameObject CreateTemplate()
{
GameObject blank = CreatePanel();
blank.name = "Achievement";
blank.AddComponent<Achievement>();
blank.transform.position = new Vector3(1000,1000);

GameObject title = CreateText();
title.name = "Title";
RectTransform rect = title.GetComponent<RectTransform>();
rect.SetParent(blank.GetComponent<RectTransform>());
rect.SetAnchor(AnchorPresets.TopLeft);
rect.SetPivot(PivotPresets.TopLeft);
rect.anchoredPosition = new Vector2(0,0);
rect.sizeDelta = new Vector2(300,25);
title.GetComponent<Text>().text = "Title";
title.GetComponent<Text>().fontSize = 20;
title.GetComponent<Text>().fontStyle = FontStyle.Bold;

GameObject desc = CreateText();
desc.name = "Description";
rect = desc.GetComponent<RectTransform>();
rect.SetParent(blank.GetComponent<RectTransform>());
rect.SetAsLastSibling();
rect.SetAnchor(AnchorPresets.TopLeft);
rect.SetPivot(PivotPresets.TopLeft);
rect.anchoredPosition = new Vector2(0,-25);
rect.sizeDelta = new Vector2(300,75);
desc.GetComponent<Text>().text = "Description";
desc.GetComponent<Text>().fontSize = 18;

GameObject icon = CreateImage();
icon.name = "Icon";
rect = icon.GetComponent<RectTransform>();
rect.SetParent(blank.GetComponent<RectTransform>());
rect.SetAsLastSibling();
rect.anchoredPosition = new Vector2(-100,0);
return blank;
}

private static bool HasAchievement(string name)
{
if(obtainedAchievements.Contains(name))
{
return true;
}
else return false;
}
private static void AddAchievement(string name)
{
obtainedAchievements.Add(name);
File.WriteAllLines(path,obtainedAchievements);
}
private List<string> GetAchievements()
{
List<string> achievements = File.ReadAllLines(path).ToList<string>();
return achievements;
}

// Please ignore all the shit below this comment :D

private static GameObject CreateOverlay()
{
GameObject blank = new GameObject();
blank.name = "Achievement Overlay";
blank.AddComponent<Canvas>();
blank.GetComponent<Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
blank.GetComponent<Canvas>().sortingOrder = 1000;
blank.AddComponent<CanvasScaler>();
blank.AddComponent<GraphicRaycaster>();
blank.GetComponent<CanvasScaler>().screenMatchMode = CanvasScaler.ScreenMatchMode.MatchWidthOrHeight;
blank.GetComponent<CanvasScaler>().matchWidthOrHeight = 0f;
blank.GetComponent<CanvasScaler>().referenceResolution = new Vector2(1920,1080);
DontDestroyOnLoad(blank);
return blank;
}
private static GameObject CreatePanel()
{
GameObject blank = CreateImage();
blank.name = "Panel";
RectTransform rect = blank.GetComponent<RectTransform>();
rect.sizeDelta = new Vector2(250,100);
rect.SetAnchor(AnchorPresets.BottomRight);
rect.SetPivot(PivotPresets.BottomRight);
blank.GetComponent<Image>().color = new Color(0.2745f,0.2745f,0.3529f,1f);
return blank;
}
private static GameObject CreateImage()
{
GameObject blank = new GameObject();
blank.name = "Image";
blank.AddComponent<RectTransform>();
RectTransform rect = blank.GetComponent<RectTransform>();
blank.AddComponent<CanvasRenderer>();
rect.sizeDelta = new Vector2(100,100);
rect.SetAnchor(AnchorPresets.TopLeft);
rect.SetPivot(PivotPresets.TopLeft);
blank.AddComponent<Image>();
return blank;
}
private static GameObject CreateText()
{
GameObject blank = new GameObject();
blank.name = "Text";
blank.AddComponent<RectTransform>();
blank.AddComponent<CanvasRenderer>();
RectTransform rect = blank.GetComponent<RectTransform>();
rect.sizeDelta = new Vector2(500, 50);
rect.SetAnchor(AnchorPresets.MiddleCenter);
rect.SetPivot(PivotPresets.MiddleCenter);
blank.AddComponent<Text>();
blank.GetComponent<Text>().text = "Text";
blank.GetComponent<Text>().font = Font.GetDefault();
blank.GetComponent<Text>().fontSize = 30;
blank.GetComponent<Text>().alignment = TextAnchor.UpperLeft;
blank.GetComponent<Text>().color = Color.white;
return blank;
}
public static Sprite LoadSprite(string path, Vector4 border, float pixelsPerUnit)
{
Texture2D texture = new Texture2D(200, 200);
texture.LoadImage(File.ReadAllBytes(path));
return Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f), pixelsPerUnit, 0, SpriteMeshType.Tight, border);
}
}

}
Loading

0 comments on commit 3381c1c

Please sign in to comment.