BigBoyConst
BigBoyConst
CC#
Created by BigBoyConst on 3/25/2025 in #help
Serializing a Function in Unity using AnimationCurve
Hey there guys, I'm working on a game with Unity right now and I have a few classes which basically represent certain types of functions that I want to use in some contexts. What i would like to know is if there is a way to translate my functions into animation curves (ideally using a custom attribute such as SerializeCurveAttribute) so that I can use Unity's built-in serialization for said curves. I'm not quite sure how to go about this, as I've barely written any attributes, and the decompiled code for Unity's SerializeField literally contains nothing. Here is the code for my curve classes:
public interface ICurve
{
float Evaluate(float t);
}

public struct NormalCurve : ICurve
{
readonly float width;
readonly float maxValue;
readonly float minValue;

public NormalCurve(float width, float min, float max)
{
this.width = width;
maxValue = max;
minValue = min;
}

public float Evaluate(float value)
{
return Mathf.Max(
Mathf.Exp(-Mathf.Pow(value, 2f) / width) * (maxValue - minValue) +
minValue - 0.01f,
minValue);
}
}

public struct PropulsionCurve : ICurve
{
public float maxVelocity;
public float maxForce;

private readonly float coefficient;

public PropulsionCurve(float v_max = 100f, float f_max = 5f)
{
maxVelocity = v_max;
maxForce = f_max;
coefficient = f_max / (v_max * v_max);
}

public float Evaluate(float x) => Mathf.Min(coefficient * x * x, maxForce);
}
public interface ICurve
{
float Evaluate(float t);
}

public struct NormalCurve : ICurve
{
readonly float width;
readonly float maxValue;
readonly float minValue;

public NormalCurve(float width, float min, float max)
{
this.width = width;
maxValue = max;
minValue = min;
}

public float Evaluate(float value)
{
return Mathf.Max(
Mathf.Exp(-Mathf.Pow(value, 2f) / width) * (maxValue - minValue) +
minValue - 0.01f,
minValue);
}
}

public struct PropulsionCurve : ICurve
{
public float maxVelocity;
public float maxForce;

private readonly float coefficient;

public PropulsionCurve(float v_max = 100f, float f_max = 5f)
{
maxVelocity = v_max;
maxForce = f_max;
coefficient = f_max / (v_max * v_max);
}

public float Evaluate(float x) => Mathf.Min(coefficient * x * x, maxForce);
}
1 replies
CC#
Created by BigBoyConst on 2/26/2024 in #help
✅ Editing audio file metadata with TagLib Sharp
Hey there! I'm trying to make a program that streamlines the process of editing file metadata for my music while also giving me a chance to learn something, and I'm running into this problem when I want to set the artist of the track: The way it's stored in TagLib is using a property TagLib.File.Tag.Performers, which is an array of strings. It's initialized to be of length zero, which makes sense, but when I try to set it to a new nonempty array of strings, it just doesn't work, which then leads me to getting an IndexOutOfRangeException when I inevitably want to set the first value in that array. I may be making a very very stupid mistake but nonetheless I thought i'd ask. I don't want to post my code unless someone asks because it's actual programming gore and I know it. Thanks in advance!
15 replies
CC#
Created by BigBoyConst on 1/31/2024 in #help
Setting a template project
Hey I have a small question. I have a file which contains a lot of functions that I use often in programming and I wanted to set a sort of "template project" to start from every time I make a new solution. This template would just have nullable disabled, have the reference already added to the aforementioned file and also have set implicit usings for said file. I wasn't able to find anything useful online related to this, but my teacher told me it was possible
14 replies
CC#
Created by BigBoyConst on 12/17/2023 in #help
Graphs OOP app
Hey there, I wanted to ask if the structure for my OOP-based graphs interface made sense or if there are some places I can change things. I want to emphasise beforehand that, althought I know i could simply represent a graph using the adjacency matrix, I want my interface to be more intuitive that hand-typing a random matrix, so I wanted to store it as a List of nodes and edges. (if there's a better way please let me know) Anyways, the current structure for my program goes a little something like this: - When it comes to edges, I have an abstract class for an arbitrary edge, from which 2 different classes will inherit: Directed edges (Arc) and undirected edges (UEdge). I'm representing the type of edge using an EdgeType enum. Also, for the endpoints, I'm simply representing it as a Tuple<Node, Node> - The Node class is one that im not sure what to put inside, for the moment all that I have in the node class is an integer for its index in the graph. - The Graph class is an abstract class from which 3 classes will inherit: DiGraph (Directed Graph), UGraph (Undirected Graph) and PGraph (Ponderated graph, a graph in which each edge has a value i.e. the use case of Djikstra's algorithm). This class would have a List<Edge> called Edges for all the edges in the graph, and a List<Node> called Nodes for all the Nodes. Nodes wouldn't be taken as an argument in the constructor, since I could just extract the nodes from the edges and then set the list equal to those in the constructor. I don't wanna try and plan out everything beforehand because I feel like i'll get overwhelmed, so I would appreciate if you guys told me if this structure makes sense so far or if there are some things i could fix so they dont bite me in the ass later down the line. Thanks in advance!
9 replies