#lets make a thread
1 messages · Page 1 of 1 (latest)
yo
ok, so this is a solution
let me just pull up some code
So I have this
public static Dictionary<Destination, List<IInjectable>> injected = new Dictionary<Destination, List<IInjectable>>();
and this
using System;
namespace SSSoftware.Network.Shared
{
public interface IInjectable
{
Destination destination
{
get;
}
EntryPoint[] EntryPoints
{
get;
}
object Execute(EntryPoint entryPoint, object obj);
}
}
now here any class can register a Destination (what it is) and multiple Entrypoints (what you want to do)
Destination is the class object right?
I use an Enum but it can be anything you can recognise
like wise EntryPoint is an Enum
so an implementation of this is like
public class Inject : IInjectable
{
public Inject()
{
if (Common.ErrMsg != null)
Common.ErrMsg($"{destination}: Injecting", false);
}
public Destination destination
{
get
{
return Destination.Echo;
}
}
public EntryPoint[] EntryPoints
{
get
{
return new EntryPoint[] { EntryPoint.Init, EntryPoint.Open, EntryPoint.Send, EntryPoint.Receive, EntryPoint.Close };
}
}
public object Execute(EntryPoint entryPoint, object obj)
{
switch (entryPoint)
{
case EntryPoint.Init:
{
ControlData controlData = (ControlData)obj;
Init(controlData);
break;
}
case EntryPoint.Open:
{
PortData portData = (PortData)obj;
return Open(portData);
}
case EntryPoint.Send:
{
Send send = (Send)obj;
return Send(send);
}
case EntryPoint.Receive:
{
byte[] bytes = (byte[])obj;
return Recieve(bytes);
}
case EntryPoint.Close:
{
Close();
break;
}
}
return null;
}
it's basically like my own Invoke system
oh, so basically depending by which value entrypoint is being set to then it changes the methods to call
exactly, and, if you want to serialize the dependencies then you only need to serialize 2 enums, Destination and EntryPoint
ok but what is Destination, another enum?
yes, I have about 30 different applications that use this system and the Destination is the application
very easy and it works brilliantly
I use it mainly for client/server network stuff so I can have dynamic dll's which is something c# does not have by default
Have never used Zenject's Signals in a real project, but it does similar thing, as far as I remember.
But, I still wouldn't rely on it.
I only ever rely on my own code and this is bullet proof
and it works perfectly with Unity which many solutions do not
How many years of experience of C# do you have?
I've been programming c# since c# was first introduced
very much the wrong side of 65
Cool, I usually rely only on well known plugins/addons, like DoTween, Zenject/VContainer, Cinemachine.
Everything else is hand crafted.
beta was 2000 iirc
56? I'm not braining
65 going on 70
wow!
I've been a professional dev for almost 50 years now
I would have never thought, that there (this discord channel) will be someone with so much wisdom.
dev is what I do, so why not use the methods available
that's incredible how discord anonymous message don't give you any context on the person
I mean, I have just 4 years of really light experience of programming, I can't imagine how could be like having 50 years of experience in the industry, like, you feel like you know the environement just like it's your house
Definitely, wish you health then.
I try to teach people the right way to do stuff, but very few people ever listen, they just want quick and easy rather than correct
thanks, I'll be fine as long as I don't run out of cigarettes and red wine, oh, and computers
this thread deserves to be pinned somewhere
nah, code is code, nothing else matters
coming back to the question, what if I want to perform stuff dynamically in the Execute method? Getting the reference of a Quest and then setting its on complete callback
I should still use reflection, since I should get the reference of the methods to being able to call them
On the script that you've shown me you're using a switch to then call the methods that you like, but what about many MonoBehaviours that can create Quests and so assign an individual callback to each one of them?
@neon crown (since as I'm seeing on the right side he left the thread)
Not necessary, you can just add a delegate which is executed in the switch, the point is that the calling program does not have to know anything about what is being called except a Destination and an EntryPoint
oh right