Exemple #1
0
        private void InitializePreviewObjects(CustomMaterial customMaterial, Transform transform)
        {
            if (customMaterial.GameObject)
            {
                materialObject = CreatePreviewMaterial(customMaterial.GameObject, transform);

                if (materialObject)
                {
                    // Fix irregular model scales (in most cases)
                    foreach (Transform child in materialObject.GetComponentsInChildren <Transform>(false))
                    {
                        if (child)
                        {
                            child.localScale    = Vector3.one;
                            child.localPosition = Vector3.zero;
                        }
                    }

                    materialObject.transform.localScale = new Vector3(10f, 37.5f, 75f);
                    if (customMaterial.Descriptor.ReplaceMesh)
                    {
                        // Account for custom mesh scale being weird in previews
                        materialObject.transform.localScale *= 0.025f;
                    }

                    Renderer renderer = materialObject.gameObject?.GetComponentInChildren <Renderer>();
                    MaterialUtils.SetMaterialsColor(renderer?.materials, colorManager.GetObstacleEffectColor());
                }
            }
        }
        private static void Postfix(ref ObstacleController __instance, StretchableObstacle ____stretchableObstacle, ref SimpleColorSO ____color)
        {
            try
            {
                CustomMaterial customMaterial = MaterialAssetLoader.CustomMaterialObjects[MaterialAssetLoader.SelectedMaterial];
                if (customMaterial.FileName != "DefaultMaterials")
                {
                    Renderer mesh  = __instance.gameObject.GetComponentInChildren <Renderer>();
                    Color    color = ____color.color;

                    if (customMaterial.Descriptor.Overlay)
                    {
                        GameObject overlay = MeshUtils.CreateOverlay(mesh, customMaterial.MaterialRenderer, customMaterial.Descriptor.OverlayOffset);
                        MaterialUtils.SetMaterialsColor(overlay?.GetComponent <Renderer>().materials, color);
                        if (customMaterial.Descriptor.ReplaceMesh)
                        {
                            MeshUtils.ReplaceMesh(overlay.GetComponent <MeshFilter>(), customMaterial.MaterialMeshFilter, customMaterial.Descriptor.MeshScaleMultiplier);
                            if (!customMaterial.Descriptor.ReplaceOnlyOverlayMesh)
                            {
                                MeshUtils.ReplaceMesh(__instance.gameObject.GetComponentInChildren <MeshFilter>(), customMaterial.MaterialMeshFilter, customMaterial.Descriptor.MeshScaleMultiplier);
                            }
                        }
                    }
                    else
                    {
                        MaterialUtils.ReplaceRenderer(mesh, customMaterial.MaterialRenderer);
                        MaterialUtils.SetMaterialsColor(mesh?.materials, color);
                        if (customMaterial.Descriptor.ReplaceMesh)
                        {
                            MeshUtils.ReplaceMesh(__instance.gameObject.GetComponentInChildren <MeshFilter>(), customMaterial.MaterialMeshFilter, customMaterial.Descriptor.MeshScaleMultiplier);
                        }
                    }
                }

                if (!Configuration.EnableObstacleFrame)
                {
                    ParametricBoxFrameController frame = ____stretchableObstacle.GetPrivateField <ParametricBoxFrameController>("_obstacleFrame");
                    frame.enabled = false;
                }
            }
            catch (Exception ex)
            {
                Logger.log.Error(ex);
            }
        }