Constant-velocity joint mod [Spaar`s Modloader][v0.42b]

#1
I have just finished my first mod :)
I don't fully understand what I have done, but it works! (never programmed with C# and Unity before)
Now I understand what I did:)


The mod just adds a toggle button to the ball joint, that locks the Z axis.

Installation:
1. Install spaar's modloader.
2. Put the dll in the mods folder.

Changelog:
-release
-performance upgrade
-performance upgrade
-updated to v0.2
-changed how my mods work
-updated to v0.27
-update to v0.4
-update to v0.42b

Image:
constant-velocityJoint.jpg


I hope you like it!

Donwload:
Constant-velocity joints.dll
 

Attachments

Last edited:
#4
It worked on my computer but it also fails on my mobilephone.
It could be too big.

It looks like mobile phones have problems with images on the forum.(my avatar has no transparancy)
 
#5
Is this every time the case? Or just when you don't close the properties window before simulating?
I have similar problems with no mods but restarting the simulartion or closing the properties window correctly helps.
 

ITR

l̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ֍̫̜̥̭͖̱̟̟͉͙̜̰ͅl̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ
Staff member
#6
Doesn't show up on computer for me. The forum is kinda buggy
 

ITR

l̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ֍̫̜̥̭͖̱̟̟͉͙̜̰ͅl̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ
Staff member
#8
Just a few tips:
Searching through all gameobjects each frame can cause a lot of lag with big machines. Since you only want MyBlockInfo, you can do FindObjectsOfType<MyBlockInfo>(); instead.
However, this will also start causing lag with bigger machines, just not as much, so you could limit it to only do it while the keymapper is open.
 

ITR

l̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ֍̫̜̥̭͖̱̟̟͉͙̜̰ͅl̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ
Staff member
#10
ITR said:
Just a few tips:
Searching through all gameobjects each frame can cause a lot of lag with big machines. Since you only want MyBlockInfo, you can do FindObjectsOfType<MyBlockInfo>(); instead.
However, this will also start causing lag with bigger machines, just not as much, so you could limit it to only do it while the keymapper is open.
What I did with the ModifyExplosionMod was:
HTML:
            if(blockInfoController.menuHolder.gameObject.activeSelf) {
                myBlockInfo = blockInfoController.activeBlockInfoCode;
                if(myBlockInfo!=null) {
                    if(myBlockInfo.blockName=="BOMB") {
                        ModifyExplosionPersonal modifyExplosionPersonal = myBlockInfo.GetComponent<ModifyExplosionPersonal>();
                        if(modifyExplosionPersonal==null) {
                            modifyExplosionPersonal = (myBlockInfo.gameObject.AddComponent<ModifyExplosionPersonal>());

                            myBlockInfo.canToggle = true;
                            myBlockInfo.toggleModeEnabled = false;
                            myBlockInfo.toggleModeName = "Click here to change slider!";

                            myBlockInfo.key1 = "q";
                            myBlockInfo.key1Name = "Detonate";
                            myBlockInfo.canControl = true;

                            myBlockInfo.slider = true;
                            myBlockInfo.sliderMax = 20f;
                            myBlockInfo.sliderMin = -20f;
                            myBlockInfo.sliderValue = 1f;
                            myBlockInfo.sliderName = "Power";

                            blockInfoController.CloseInfo();
                            blockInfoController.OpenInfo(myBlockInfo);
                            return;
                        }
 
#11
Thank you but I get the error " The name 'blockInfoController' does not exist in the current context"
When I make a variable named blockInfoController I have to Initialize it but how?(public BlockInfoController blockInfoController = new BlockInfoController(); didn't work)

HTML:
using System;
using UnityEngine;
using spaar;


namespace meta
{
    [spaar.Mod("Constant-velocity joint", author = "CroCraCri", version = "1.0")]
    public class Mod : MonoBehaviour
    {
        public MyBlockInfo myBlockInfo;
    
        public Mod()
        {
            Debug.Log("The constant-velocity joints are now aviable!");
        }

        public void Update()
        {
            if (blockInfoController.menuHolder.gameObject.activeSelf)
            {
                myBlockInfo = blockInfoController.activeBlockInfoCode;
                if (myBlockInfo != null)
                {
                    if (myBlockInfo.blockName == "BALL JOINT")
                    {
                        BallJointModifier BallJointModifier = myBlockInfo.GetComponent<BallJointModifier>();
                        if (BallJointModifier == null)
                        {
                                myBlockInfo.gameObject.AddComponent<BallJointModifier>();
                                myBlockInfo.canToggle = true;
                                myBlockInfo.toggleModeName = "CONSTANT-VELOCITY JOINT";

                              blockInfoController.CloseInfo();
                              blockInfoController.OpenInfo(myBlockInfo);
                              return;
                        }
                    }
                }
            }
        }
    }
}
 
#12
Every time I edit multiple joint without closing the property's menu. The machine is a prototype of a paradox engine with a gearbox, differential and Your mod helped with the development of independent powered suspension.
 

ITR

l̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ֍̫̜̥̭͖̱̟̟͉͙̜̰ͅl̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ
Staff member
#13
Oh, blockInfoController, is just a variable leading to BlockInfoController.
 

ITR

l̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ֍̫̜̥̭͖̱̟̟͉͙̜̰ͅl̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ
Staff member
#16
CroCraCri said:
ITR I decompiled your mod:)
Now I finally got it to work and updated the mod!
Thank you!
Yeah, sorry, I suddenly had to go. I guess you figured out how to find the BlockInfoController?
 
#17
Yes, but now the saving and loading isn't working:(
I think because it only adds the BallJointModifier when the proprties window is open and not when a machine gets loaded.
 

ITR

l̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ֍̫̜̥̭͖̱̟̟͉͙̜̰ͅl̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ
Staff member
#18
Oh, right, forgot about that >.<
You can make a special exception for it, like, "if bgeL1 is not null, and MyBlockInfo doesn't have the changes, then run the code-check" maybe?
 

ITR

l̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ֍̫̜̥̭͖̱̟̟͉͙̜̰ͅl̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ
Staff member
#19
Oh, right, forgot about that >.<
You can make a special exception for it, like, "if bgeL1 is not null, and MyBlockInfo doesn't have the changes, then run the code-check" maybe?
 
#20
Or just loop through MachineObjectTracker.prefabReferences and look for the ID of the block(44).
This could create less lag and it would allow to save.(I hope)
But i didn't thought about how to get the GameObject!
 
Top