Ejemplo n.º 1
0
        /// <summary>
        /// Colorize a Note based on a ColorManager and CustomNote configuration
        /// </summary>
        /// <param name="color">Color</param>
        /// <param name="colorStrength">Color strength</param>
        /// <param name="noteObject">Note to colorize</param>
        public static void ColorizeCustomNote(Color color, float colorStrength, GameObject noteObject)
        {
            if (!noteObject || color == null)
            {
                return;
            }

            Color noteColor = color * colorStrength;

            IEnumerable <Transform> childTransforms = noteObject.GetComponentsInChildren <Transform>();

            foreach (Transform childTransform in childTransforms)
            {
                DisableNoteColorOnGameobject colorDisabled = childTransform.GetComponent <DisableNoteColorOnGameobject>();
                if (!colorDisabled)
                {
                    Renderer childRenderer = childTransform.GetComponent <Renderer>();
                    if (childRenderer)
                    {
                        childRenderer.material.SetColor("_Color", noteColor);
                    }
                }
            }
            MaterialPropertyBlockController materialPropertyBlockController = noteObject.GetComponent <MaterialPropertyBlockController>(); // Set the color of material property block controllers, for the replaced note shader

            if (materialPropertyBlockController != null)
            {
                materialPropertyBlockController.materialPropertyBlock.SetColor("_Color", noteColor);
                materialPropertyBlockController.ApplyChanges();
            }
        }
Ejemplo n.º 2
0
        public async void PlatformEnabled(DiContainer container)
        {
            container.Inject(this);
            bool activeSelf = gameObject.activeSelf;

            if (activeSelf)
            {
                gameObject.SetActive(false);
            }

            if (_instancedMaterialLightWithId is null)
            {
                Mesh mesh = GetComponent <MeshFilter>().mesh;
                if (mesh.vertexCount == 0)
                {
                    float y = (0.5f - center) * length * 2;
                    mesh.vertices = new Vector3[]
                    {
                        new(-width, (y - length) / 2, -width),
                        new(width, (y - length) / 2, -width),
                        new(width, (y + length) / 2, -width),
                        new(-width, (y + length) / 2, -width),
                        new(-width, (y + length) / 2, width),
                        new(width, (y + length) / 2, width),
                        new(width, (y - length) / 2, width),
                        new(-width, (y - length) / 2, width)
                    };

                    mesh.triangles = _triangles;
                }

                (_, _, Material opaqueGlowMaterial) = await _materialSwapper !.MaterialsTask;
                Renderer renderer = GetComponent <Renderer>();
                renderer.sharedMaterial = opaqueGlowMaterial;
                MaterialPropertyBlockController materialPropertyBlockController = gameObject.AddComponent <MaterialPropertyBlockController>();
                materialPropertyBlockController.SetField("_renderers", new[] { renderer });
                MaterialPropertyBlockColorSetter materialPropertyBlockColorSetter = gameObject.AddComponent <MaterialPropertyBlockColorSetter>();
                materialPropertyBlockColorSetter.materialPropertyBlockController = materialPropertyBlockController;
                materialPropertyBlockColorSetter.SetField("_property", "_Color");
                _instancedMaterialLightWithId = gameObject.AddComponent <InstancedMaterialLightWithId>();
                _instancedMaterialLightWithId.SetField("_materialPropertyBlockColorSetter", materialPropertyBlockColorSetter);
                _instancedMaterialLightWithId.SetField("_intensity", 1.25f);
                ((LightWithIdMonoBehaviour)_instancedMaterialLightWithId).SetField("_ID", (int)lightsID);
                _instancedMaterialLightWithId.ColorWasSet(color);
                BloomPrePassBackgroundNonLightRenderer bloomPrePassBackgroundNonLightRenderer = gameObject.AddComponent <BloomPrePassBackgroundNonLightRenderer>();
                bloomPrePassBackgroundNonLightRenderer.SetField("_renderer", renderer);
                ((BloomPrePassBackgroundNonLightRendererCore)bloomPrePassBackgroundNonLightRenderer).SetField("_keepDefaultRendering", true);
                ((BloomPrePassNonLightPass)bloomPrePassBackgroundNonLightRenderer).SetField("_executionTimeType", BloomPrePassNonLightPass.ExecutionTimeType.BeforeBlur);
            }

            ((LightWithIdMonoBehaviour)_instancedMaterialLightWithId).SetField("_lightManager", _lightWithIdManager);
            if (activeSelf)
            {
                gameObject.SetActive(true);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a MaterialPropertyBlockController to the root of the gameObject. Only selects renderers with specific shaders.
        /// </summary>
        /// <param name="gameObject"></param>
        public static void AddMaterialPropertyBlockController(GameObject gameObject)
        {
            List <Renderer> rendererList = new List <Renderer>();

            foreach (Renderer renderer in gameObject.GetComponentsInChildren <Renderer>())
            {
                if (renderer.material.shader.name.ToLower() == "custom/notehd") // only get the replaced note shader
                {
                    rendererList.Add(renderer);
                }
            }
            if (rendererList.Count > 0)
            {
                MaterialPropertyBlockController newController = gameObject.AddComponent <MaterialPropertyBlockController>();
                ReflectionUtil.SetField <MaterialPropertyBlockController, Renderer[]>(newController, "_renderers", rendererList.ToArray());
            }
        }
Ejemplo n.º 4
0
        public static void SetNoteColour(ColorNoteVisuals noteVis, Color c)
        {
            SpriteRenderer ____arrowGlowSpriteRenderer  = noteVis.GetField <SpriteRenderer>("_arrowGlowSpriteRenderer");
            SpriteRenderer ____circleGlowSpriteRenderer = noteVis.GetField <SpriteRenderer>("_circleGlowSpriteRenderer");
            MaterialPropertyBlockController ____materialPropertyBlockController = noteVis.GetField <MaterialPropertyBlockController>("_materialPropertyBlockController");

            if (____arrowGlowSpriteRenderer != null)
            {
                ____arrowGlowSpriteRenderer.color = c;
            }
            if (____circleGlowSpriteRenderer != null)
            {
                ____circleGlowSpriteRenderer.color = c;
            }
            MaterialPropertyBlock block = ____materialPropertyBlockController.materialPropertyBlock;

            block.SetColor(noteVis.GetField <int>("_colorID"), c);
        }
Ejemplo n.º 5
0
 public void Setup(List <AnimationFrameInfo> frameInformations, MaterialPropertyBlockController propertyBlockController)
 {
     FrameInformations       = frameInformations;
     PropertyBlockController = propertyBlockController;
 }
Ejemplo n.º 6
0
        public void OnUpdate()
        {
            this._noteDebris        = UnityEngine.Object.FindObjectsOfType <NoteDebris>();
            this._noteMeshCutDebris = UnityEngine.Object.FindObjectsOfType <NoteMeshCutDebris>();
            this._beatEffects       = UnityEngine.Object.FindObjectsOfType <BeatEffect>();

            // rate limit color note visual update to increase performance
            _colorNoteVisualUpdateCounter += 1;
            if (_colorNoteVisualUpdateCounter > _colorNoteVisualUpdateRate)
            {
                this._colorNoteVisuals = UnityEngine.Object.FindObjectsOfType <ColorNoteVisuals>();

                _colorNoteVisualUpdateCounter = 0;
                Console.WriteLine(_colorNoteVisualUpdateCounter);
                foreach (ColorNoteVisuals cnv in _colorNoteVisuals)
                {
                    // Console.WriteLine("J");
                    MaterialPropertyBlockController mbpc = ReflectionUtil.GetPrivateField <MaterialPropertyBlockController>(cnv, "_materialPropertyBlockController");
                    NoteController    nc = ReflectionUtil.GetPrivateField <NoteController>(cnv, "_noteController");
                    NoteData.NoteType nt = nc.noteData.noteType;
                    if (nt == NoteData.NoteType.NoteA)
                    {
                        // Console.WriteLine("M");
                        mbpc.materialPropertyBlock.SetColor("_Color", this._leftColor.ColorWithAlpha(.8f));
                    }
                    else if (nt == NoteData.NoteType.NoteB)
                    {
                        // Console.WriteLine("N");
                        mbpc.materialPropertyBlock.SetColor("_Color", this._rightColor.ColorWithAlpha(.8f));
                    }
                    // Console.WriteLine("L");
                }
            }

            foreach (NoteDebris nd in _noteDebris)
            {
                // Console.WriteLine("O");
                MaterialPropertyBlockController mbpc = ReflectionUtil.GetPrivateField <MaterialPropertyBlockController>(nd, "_materialPropertyBlockController");
                MaterialPropertyBlock           mbp  = mbpc.materialPropertyBlock;
                Color c = mbp.GetColor("_Color");

                if (CheckIsUnchangedRed(c))
                {
                    // Console.WriteLine("P");
                    mbp.SetColor("_Color", this._leftColor.ColorWithAlpha(.8f));
                }
                else if (CheckIsUnchangedBlue(c))
                {
                    // Console.WriteLine("Q");
                    mbp.SetColor("_Color", this._rightColor.ColorWithAlpha(.8f));
                }
                // Console.WriteLine("R");
            }

            foreach (NoteMeshCutDebris nd in _noteMeshCutDebris)
            {
                // Console.WriteLine("S");
                MaterialPropertyBlockController mbpc = ReflectionUtil.GetPrivateField <MaterialPropertyBlockController>(nd, "_materialPropertyBlockController");
                MaterialPropertyBlock           mbp  = mbpc.materialPropertyBlock;
                Color c = mbp.GetColor("_CutoutEdgeColor");

                if (CheckIsUnchangedRed(c))
                {
                    // Console.WriteLine("T");
                    mbp.SetColor("_CutoutEdgeColor", this._leftColor.ColorWithAlpha(.8f));
                }
                else if (CheckIsUnchangedBlue(c))
                {
                    // Console.WriteLine("U");
                    mbp.SetColor("_CutoutEdgeColor", this._rightColor.ColorWithAlpha(.8f));
                }
                // Console.WriteLine("V");
            }

            foreach (XWeaponTrail wt in _weaponTrails)
            {
                // Console.WriteLine("W");
                Color c = ReflectionUtil.GetPrivateField <Color>(wt, "MyColor");

                if (CheckIsUnchangedRed(c))
                {
                    // Console.WriteLine("X");
                    ReflectionUtil.SetPrivateField(wt, "MyColor", this._leftColor.ColorWithAlpha(.8f));
                }
                else if (CheckIsUnchangedBlue(c))
                {
                    // Console.WriteLine("Y");
                    ReflectionUtil.SetPrivateField(wt, "MyColor", this._rightColor.ColorWithAlpha(.8f));
                }
                // Console.WriteLine("Z");
            }

            foreach (BeatEffect be in _beatEffects)
            {
                // Console.WriteLine("AA");
                SpriteRenderer[] srs = ReflectionUtil.GetPrivateField <SpriteRenderer[]>(be, "_spriteRenderers");

                foreach (SpriteRenderer sr in srs)
                {
                    Color c = sr.color;
                    if (CheckIsUnchangedRed(c))
                    {
                        // Console.WriteLine("AB");
                        sr.color = this._leftColor;
                    }
                    else if (CheckIsUnchangedBlue(c))
                    {
                        // Console.WriteLine("AC");
                        sr.color = this._rightColor;
                    }
                    // Console.WriteLine("AD");
                }
            }
        }