ppg-snippets icon indicating copy to clipboard operation
ppg-snippets copied to clipboard

Custom Right Click option

Open An4r3w opened this issue 2 years ago • 2 comments

Hello sorry for posting here again a question >.< but I really can't understand how to make a custom right click option for only my custom humans. Can someone help me?

An4r3w avatar Mar 08 '22 14:03 An4r3w

a PhysicalBehaviour has a list of custom context menu buttons. The following code shows how to add buttons. Do note that it only works on objects with a PhysicalBehaviour. The human root object doesn't have one so you'd need to run this script on every limb you want that button to be on.


//assuming Instance is the GameObject, this code will add a "Blow up" button 

var phys = Instance.GetComponent<PhysicalBehaviour>();

var button = new ContextMenuButton("uniqueIdentifierPleaseForGodSake", "Blow up", "Blow up the selection", () => 
{
   ExplosionCreator.Explode(Instance.transform.position, 8);
});

phys.ContextMenuOptions.Buttons.Add(button);


just for clarity, there are quite a lot of context menu button constructors:

    public ContextMenuButton(string identity, string label, string desc, params UnityAction[] actions)l

    public ContextMenuButton(string identity, Func<string> label, string desc, params UnityAction[] actions)l

    public ContextMenuButton(Func<bool> condition, string identity, Func<string> label, string desc, params UnityAction[] actions)l

    public ContextMenuButton(Func<bool> condition, string identity, string label, string desc, params UnityAction[] actions)l

mestiez avatar Mar 08 '22 17:03 mestiez

Hello, thank you! I just do not understand how to run the script on every limb.

An4r3w avatar Mar 08 '22 18:03 An4r3w