void MakeMeshSkinned(SkinnedMeshRenderer renderer) { var mesh = renderer.sharedMesh; if (mesh == null) { ErrorList.add("The mesh on " + renderer.gameObject.FullName() + " is null"); return; } if (!mesh.isReadable) { ErrorList.add("Can't read the car mesh " + mesh.name + " on " + renderer.gameObject.FullName() + "You must allow reading on it's unity inspector !"); return; } if (mesh.vertices.Length == mesh.boneWeights.Length) { return; } var bones = new BoneWeight[mesh.vertices.Length]; for (int i = 0; i < bones.Length; i++) { bones[i].weight0 = 1; } mesh.boneWeights = bones; var t = renderer.transform; var bindPoses = new Matrix4x4[1] { t.worldToLocalMatrix *renderer.transform.localToWorldMatrix }; mesh.bindposes = bindPoses; renderer.bones = new Transform[1] { t }; }
public void Initialize(IManager manager, string ipcIdentifier) { try { var harmony = HarmonyInstance.Create("com.Larnin.CustomCar"); harmony.PatchAll(Assembly.GetExecutingAssembly()); } catch (Exception e) { Console.Out.WriteLine(e.ToString()); } try { CarInfos carInfos = new CarInfos(); carInfos.collectInfos(); CarBuilder builder = new CarBuilder(); builder.createCars(carInfos); } catch (Exception e) { ErrorList.add("An error occured while trying to load cars assets"); Console.Out.WriteLine(e.ToString()); } //disable loging cars //LogCarPrefabs.logCars(); Events.MainMenu.Initialized.Subscribe(data => { if (ErrorList.haveErrors()) { ErrorList.show(); } }); }
void addMaterialColorChanger(ColorChanger colorChanger, Transform t) { Renderer r = t.GetComponent <Renderer>(); if (r == null) { return; } var uniformChangers = new List <ColorChanger.UniformChanger>(); for (int i = 0; i < t.childCount; i++) { var o = t.GetChild(i).gameObject; var name = o.name.ToLower(); if (!name.StartsWith("#")) { continue; } name = name.Remove(0, 1); //remove # var s = name.Split(';'); if (s.Length == 0) { continue; } if (!s[0].Contains("color")) { continue; } if (s.Length != 6) { ErrorList.add(s[0] + " property on " + t.gameObject.FullName() + " must have 5 arguments"); continue; } var uniformChanger = new ColorChanger.UniformChanger(); int materialIndex = 0; int.TryParse(s[1], out materialIndex); uniformChanger.materialIndex_ = materialIndex; uniformChanger.colorType_ = colorType(s[2]); uniformChanger.name_ = uniformName(s[3]); float multiplier = 0; float.TryParse(s[4], out multiplier); uniformChanger.mul_ = multiplier; uniformChanger.alpha_ = s[5].ToLower() == "true"; uniformChangers.Add(uniformChanger); } if (uniformChangers.Count == 0) { return; } var renderChanger = new ColorChanger.RendererChanger(); renderChanger.renderer_ = r; renderChanger.uniformChangers_ = uniformChangers.ToArray(); var renders = colorChanger.rendererChangers_.ToList(); renders.Add(renderChanger); colorChanger.rendererChangers_ = renders.ToArray(); }
void fillMaterialInfos(Renderer r, string[] matNames, List <MaterialPropertyExport>[] matProperties) { int childCount = r.transform.childCount; for (int i = 0; i < childCount; i++) { var name = r.transform.GetChild(i).name.ToLower(); if (!name.StartsWith("#")) { continue; } name = name.Remove(0, 1); var s = name.Split(';'); if (s.Length == 0) { continue; } if (s[0].Contains("mat")) { if (s.Length != 3) { ErrorList.add(s[0] + " property on " + r.gameObject.FullName() + " must have 2 arguments"); continue; } int index = 0; if (!int.TryParse(s[1], out index)) { ErrorList.add("First argument of " + s[0] + " on " + r.gameObject.FullName() + " property must be a number"); continue; } if (index < matNames.Length) { matNames[index] = s[2]; } } else if (s[0].Contains("export")) { if (s.Length != 5) { ErrorList.add(s[0] + " property on " + r.gameObject.FullName() + " must have 4 arguments"); continue; } int index = 0; if (!int.TryParse(s[1], out index)) { ErrorList.add("First argument of " + s[0] + " on " + r.gameObject.FullName() + " property must be a number"); continue; } if (index >= matNames.Length) { continue; } MaterialPropertyExport p = new MaterialPropertyExport(); bool found = false; foreach (MaterialPropertyExport.PropertyType pType in Enum.GetValues(typeof(MaterialPropertyExport.PropertyType))) { if (s[2] == pType.ToString().ToLower()) { found = true; p.type = pType; break; } } if (!found) { ErrorList.add("The property " + s[2] + " on " + r.gameObject.FullName() + " is not valid"); continue; } if (!int.TryParse(s[3], out p.fromID)) { p.fromName = s[3]; } if (!int.TryParse(s[4], out p.toID)) { p.toName = s[4]; } matProperties[index].Add(p); } } }