You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

58 lines
1.5 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UIElements;
namespace Game {
public enum ModType { Nerf, Buff }
public enum ModEffect { Speed, Border }
public class ActiveModification {
public ModificationProperties Properties { get; set; }
public IEnumerator Process(VisualElement panel, List<ActiveModification> modifications) {
modifications.Add(this);
VisualElement element = GameUI.AddModification(panel, this);
float doNothingTime = Properties.activeDuration * 0.7f;
float animateTime = Properties.activeDuration * 0.3f;
yield return new WaitForSeconds(doNothingTime);
float current = 0;
while (current < animateTime) {
current += Time.deltaTime;
element.style.opacity = new StyleFloat(1 - current / animateTime);
yield return null;
}
element.RemoveFromHierarchy();
modifications.Remove(this);
}
}
public class Modification : NetworkBehaviour {
public ModificationProperties Properties { get; set; }
private IEnumerator Start() {
gameObject.AddComponent<SpriteRenderer>().sprite = Properties.image;
yield return new WaitForSeconds(Properties.pickupDuration);
Destroy(gameObject);
}
private void OnTriggerEnter2D(Collider2D other) {
Player p = other.GetComponent<Ball>().LastContactPlayer;
if (p != null) {
Destroy(gameObject);
ActiveModification mod = new() {Properties = Properties};
p.StartCoroutine(mod.Process(p.Panel, p.Modifications));
}
}
}
}