コード例 #1
0
        private async Task <GameObject> CreateHeartAsync()
        {
            (Vector3[] vertices, int[] triangles) = await Task.Run(() => ParseMesh("CustomFloorPlugin.Assets.Heart.mesh"));

            Mesh mesh = new()
            {
                vertices  = vertices,
                triangles = triangles
            };

            GameObject heart = new("<3");

            heart.SetActive(false);
            heart.AddComponent <MeshRenderer>();
            MeshFilter meshFilter = heart.AddComponent <MeshFilter>();

            meshFilter.mesh = mesh;
            heart.transform.localPosition = new Vector3(-8f, 25f, 26f);
            heart.transform.localRotation = Quaternion.Euler(-100f, 90f, 90f);
            heart.transform.localScale    = new Vector3(25f, 25f, 25f);
            TubeLight tubeLight = heart.AddComponent <TubeLight>();

            tubeLight.color = Color.magenta;
            tubeLight.PlatformEnabled(_container);
            return(heart);
        }
コード例 #2
0
        private void Awake()
        {
            var prefab = Resources.FindObjectsOfTypeAll <TubeBloomPrePassLight>().First(x => x.name == "Neon");

            TubeLight[] localDescriptors = GetComponentsInChildren <TubeLight>(true);

            if (localDescriptors == null)
            {
                return;
            }

            TubeLight tl = this;

            tubeBloomLight = Instantiate(prefab);
            tubeBloomLight.transform.SetParent(tl.transform);
            tubeBloomLight.transform.localRotation = Quaternion.identity;
            tubeBloomLight.transform.localPosition = Vector3.zero;
            tubeBloomLight.transform.localScale    = new Vector3(1 / tl.transform.lossyScale.x, 1 / tl.transform.lossyScale.y, 1 / tl.transform.lossyScale.z);

            if (tl.GetComponent <MeshFilter>().mesh.vertexCount == 0)
            {
                tl.GetComponent <MeshRenderer>().enabled = false;
            }
            else
            {
                // swap for MeshBloomPrePassLight
                tubeBloomLight.gameObject.SetActive(false);
                MeshBloomPrePassLight meshbloom = ReflectionUtil.CopyComponent(tubeBloomLight, typeof(TubeBloomPrePassLight), typeof(MeshBloomPrePassLight), tubeBloomLight.gameObject) as MeshBloomPrePassLight;
                meshbloom.Init(tl.GetComponent <Renderer>());
                tubeBloomLight.gameObject.SetActive(true);
                Destroy(tubeBloomLight);
                tubeBloomLight = meshbloom;
            }

            tubeBloomLight.SetPrivateField("_width", tl.width * 2);
            tubeBloomLight.SetPrivateField("_length", tl.length);
            tubeBloomLight.SetPrivateField("_center", tl.center);
            tubeBloomLight.SetPrivateField("_transform", tubeBloomLight.transform);
            var parabox = tubeBloomLight.GetComponentInChildren <ParametricBoxController>();

            tubeBloomLight.SetPrivateField("_parametricBoxController", parabox);
            var parasprite = tubeBloomLight.GetComponentInChildren <Parametric3SliceSpriteController>();

            tubeBloomLight.SetPrivateField("_dynamic3SliceSprite", parasprite);
            parasprite.Init();
            parasprite.GetComponent <MeshRenderer>().enabled = false;

            tubeBloomLight.color = tl.color * 0.9f;

            var prop = typeof(BSLight).GetField("_ID", BindingFlags.NonPublic | BindingFlags.Instance);

            prop.SetValue(tubeBloomLight, (int)tl.lightsID);

            //tubeBloomLight.InvokePrivateMethod("OnDisable", new object[0]);
            tubeBloomLight.Refresh();
            TubeLightManager.UpdateEventTubeLightList();
        }
コード例 #3
0
        private async Task <GameObject> CreatePlayersPlaceAsync()
        {
            (Vector3[] vertices, int[] triangles) = await Task.Run(() => ParseMesh("CustomFloorPlugin.Assets.PlayersPlace.mesh"));

            Mesh mesh = new()
            {
                vertices  = vertices,
                triangles = triangles
            };

            GameObject playersPlaceCube = GameObject.CreatePrimitive(PrimitiveType.Cube);

            playersPlaceCube.SetActive(false);
            MeshRenderer cubeRenderer = playersPlaceCube.GetComponent <MeshRenderer>();

            (Material darkEnvSimpleMaterial, _, _) = await _materialSwapper.MaterialsTask;
            cubeRenderer.material = darkEnvSimpleMaterial;
            playersPlaceCube.transform.localPosition = new Vector3(0f, -50.0075f, 0f);
            playersPlaceCube.transform.localScale    = new Vector3(3f, 100f, 2f);
            playersPlaceCube.name = "PlayersPlace";

            GameObject playersPlaceMirror = GameObject.CreatePrimitive(PrimitiveType.Plane);

            playersPlaceMirror.name = "Mirror";
            playersPlaceMirror.transform.SetParent(playersPlaceCube.transform);
            playersPlaceMirror.transform.localScale    = new Vector3(0.1f, 0f, 0.1f);
            playersPlaceMirror.transform.localPosition = new Vector3(0f, 0.5001f, 0f);
            TrackMirror trackMirror = playersPlaceMirror.AddComponent <TrackMirror>();

            trackMirror.bumpIntensity = 0.02f;
            using Stream floorStream  = GetEmbeddedResource("CustomFloorPlugin.Assets.Floor.png");
            trackMirror.normalTexture = floorStream.ReadTexture2D();
            trackMirror.PlatformEnabled(_container);

            GameObject playersPlaceFrame = new("Frame");

            playersPlaceFrame.transform.SetParent(playersPlaceCube.transform);
            playersPlaceFrame.AddComponent <MeshRenderer>();
            MeshFilter meshFilter = playersPlaceFrame.AddComponent <MeshFilter>();

            meshFilter.mesh = mesh;
            TubeLight tubeLight = playersPlaceFrame.AddComponent <TubeLight>();

            tubeLight.color = Color.blue;
            tubeLight.PlatformEnabled(_container);

            return(playersPlaceCube);
        }
コード例 #4
0
        private GameObject CreatePlayersPlace()
        {
            GameObject playersPlaceCube = GameObject.CreatePrimitive(PrimitiveType.Cube);

            playersPlaceCube.SetActive(false);
            Transform playersPlaceCubeTransform = playersPlaceCube.transform;

            playersPlaceCubeTransform.SetParent(_anchor);
            MeshRenderer cubeRenderer = playersPlaceCube.GetComponent <MeshRenderer>();

            cubeRenderer.material = _materialSwapper.DarkEnvSimpleMaterial;
            playersPlaceCubeTransform.localPosition = new Vector3(0f, -50.0075f, 0f);
            playersPlaceCubeTransform.localScale    = new Vector3(3f, 100f, 2f);
            playersPlaceCube.name = "PlayersPlace";

            GameObject playersPlaceMirror          = GameObject.CreatePrimitive(PrimitiveType.Plane);
            Transform  playersPlaceMirrorTransform = playersPlaceMirror.transform;

            playersPlaceMirror.name = "Mirror";
            playersPlaceMirrorTransform.SetParent(playersPlaceCubeTransform);
            playersPlaceMirrorTransform.localScale    = new Vector3(0.1f, 0f, 0.1f);
            playersPlaceMirrorTransform.localPosition = new Vector3(0f, 0.5001f, 0f);
            TrackMirror trackMirror = playersPlaceMirror.AddComponent <TrackMirror>();

            trackMirror.bumpIntensity = 0.02f;
            using Stream floorStream  = GetEmbeddedResource("CustomFloorPlugin.Assets.Floor.png");
            trackMirror.normalTexture = floorStream.ReadTexture2D();
            trackMirror.PlatformEnabled(_container);

            GameObject playersPlaceFrame = new("Frame");

            playersPlaceFrame.transform.SetParent(playersPlaceCubeTransform);
            playersPlaceFrame.AddComponent <MeshRenderer>();
            MeshFilter meshFilter = playersPlaceFrame.AddComponent <MeshFilter>();

            meshFilter.mesh = ParseMesh("CustomFloorPlugin.Assets.PlayersPlace.mesh");
            TubeLight tubeLight = playersPlaceFrame.AddComponent <TubeLight>();

            tubeLight.color = Color.blue;
            tubeLight.PlatformEnabled(_container);

            return(playersPlaceCube);
        }
コード例 #5
0
        private void Awake()
        {
            var prefab = Resources.FindObjectsOfTypeAll <TubeBloomPrePassLight>().First(x => x.name == "Neon");

            TubeLight[] localDescriptors = GetComponentsInChildren <TubeLight>(true);

            if (localDescriptors == null)
            {
                return;
            }

            TubeLight tl = this;

            tubeBloomLight = Instantiate(prefab);
            tubeBloomLight.transform.SetParent(tl.transform);
            tubeBloomLight.transform.localRotation = Quaternion.identity;
            tubeBloomLight.transform.localPosition = Vector3.zero;
            tubeBloomLight.transform.localScale    = new Vector3(1 / tl.transform.lossyScale.x, 1 / tl.transform.lossyScale.y, 1 / tl.transform.lossyScale.z);

            if (tl.GetComponent <MeshFilter>().mesh.vertexCount == 0)
            {
                tl.GetComponent <MeshRenderer>().enabled = false;
            }
            else
            {
                // swap for MeshBloomPrePassLight
                tubeBloomLight.gameObject.SetActive(false);
                MeshBloomPrePassLight meshbloom = ReflectionUtil.CopyComponent(tubeBloomLight, typeof(TubeBloomPrePassLight), typeof(MeshBloomPrePassLight), tubeBloomLight.gameObject) as MeshBloomPrePassLight;
                meshbloom.Init(tl.GetComponent <Renderer>());
                tubeBloomLight.gameObject.SetActive(true);
                DestroyImmediate(tubeBloomLight);
                tubeBloomLight = meshbloom;
            }
            tubeBloomLight.gameObject.SetActive(false);

            var lightWithId = tubeBloomLight.GetComponent <LightWithId>();

            if (lightWithId)
            {
                lightWithId.SetPrivateField("_tubeBloomPrePassLight", tubeBloomLight);
                var runtimeFields = typeof(LightWithId).GetTypeInfo().GetRuntimeFields();
                runtimeFields.First(f => f.Name == "_ID").SetValue(lightWithId, (int)tl.lightsID);
                //var lightManagers = Resources.FindObjectsOfTypeAll<LightWithIdManager>();
                //lightManager = lightManagers.FirstOrDefault();

                runtimeFields.First(f => f.Name == "_lighManager").SetValue(lightWithId, lightManager);
            }

            tubeBloomLight.SetPrivateField("_width", tl.width * 2);
            tubeBloomLight.SetPrivateField("_length", tl.length);
            tubeBloomLight.SetPrivateField("_center", tl.center);
            tubeBloomLight.SetPrivateField("_transform", tubeBloomLight.transform);
            tubeBloomLight.SetPrivateField("_maxAlpha", 0.1f);
            var parabox = tubeBloomLight.GetComponentInChildren <ParametricBoxController>();

            tubeBloomLight.SetPrivateField("_parametricBoxController", parabox);
            var parasprite = tubeBloomLight.GetComponentInChildren <Parametric3SliceSpriteController>();

            tubeBloomLight.SetPrivateField("_dynamic3SliceSprite", parasprite);
            parasprite.Init();
            parasprite.GetComponent <MeshRenderer>().enabled = false;
            tubeBloomLight.color = color * 0.9f;

            tubeBloomLight.gameObject.SetActive(true);
            tubeBloomLight.Refresh();
            //TubeLightManager.UpdateEventTubeLightList();
        }
コード例 #6
0
        public static void SetupTubeLight(TubeLight tl, DiContainer _container)
        {
            var prefab = Resources.FindObjectsOfTypeAll <TubeBloomPrePassLight>().First(x => x.name == "Neon");

            // Don't init twice
            if (tl.tubeBloomLight != null)
            {
                return;
            }

            var tubeBloomLight = _container.InstantiatePrefabForComponent <TubeBloomPrePassLight>(prefab);

            tubeBloomLight.name = "Tube Light " + z++;

            tl.tubeBloomLight = tubeBloomLight;
            tubeBloomLight.transform.SetParent(tl.transform);
            tubeBloomLight.transform.localRotation = Quaternion.identity;
            tubeBloomLight.transform.localPosition = Vector3.zero;
            tubeBloomLight.transform.localScale    = new Vector3(1 / tl.transform.lossyScale.x, 1 / tl.transform.lossyScale.y, 1 / tl.transform.lossyScale.z);

            var withId = tubeBloomLight.GetComponent <TubeBloomPrePassLightWithId>();

            if (tl.GetComponent <MeshFilter>().mesh.vertexCount == 0)
            {
                tl.GetComponent <MeshRenderer>().enabled = false;
            }
            else
            {
                // swap for MeshBloomPrePassLight
                tubeBloomLight.gameObject.SetActive(false);

                MeshBloomPrePassLight meshbloom = ReflectionUtil.CopyComponent(tubeBloomLight, typeof(TubeBloomPrePassLight), typeof(MeshBloomPrePassLight), tubeBloomLight.gameObject) as MeshBloomPrePassLight;
                meshbloom.Init(tl.GetComponent <Renderer>());

                MeshBloomPrePassLightWithId meshbloomid = ReflectionUtil.CopyComponent(withId, typeof(TubeBloomPrePassLightWithId), typeof(MeshBloomPrePassLightWithId), withId.gameObject) as MeshBloomPrePassLightWithId;
                Destroy(withId);
                withId = meshbloomid;

                tubeBloomLight.gameObject.SetActive(true);
                Destroy(tubeBloomLight);

                tubeBloomLight = meshbloom;
            }

            var setColorToDefault = Bind(SetColorToDefault, tl, withId);

            tl.onEnable += () => {
                BSEvents.menuSceneLoaded      += setColorToDefault;
                BSEvents.menuSceneLoadedFresh += setColorToDefault;
                setColorToDefault();
            };

            tl.onDisable += () => {
                BSEvents.menuSceneLoaded      -= setColorToDefault;
                BSEvents.menuSceneLoadedFresh -= setColorToDefault;
            };

            var lightType = tubeBloomLight.GetPrivateField <BloomPrePassLightTypeSO>("_lightType", typeof(BloomPrePassLight));

            //tubeBloomLight.SetPrivateField("_lightType", lightType, typeof(BloomPrePassLight));
            tubeBloomLight.SetPrivateField("_registeredWithLightType", lightType, typeof(BloomPrePassLight));

            tubeBloomLight.SetPrivateField("_width", tl.width * 2);
            tubeBloomLight.SetPrivateField("_length", tl.length);
            tubeBloomLight.SetPrivateField("_center", tl.center);
            tubeBloomLight.SetPrivateField("_bloomFogIntensityMultiplier", 0.3f);
            tubeBloomLight.SetPrivateField("_transform", tubeBloomLight.transform);
            var parabox = tubeBloomLight.GetComponentInChildren <ParametricBoxController>();

            tubeBloomLight.SetPrivateField("_parametricBoxController", parabox);
            var parasprite = tubeBloomLight.GetComponentInChildren <Parametric3SliceSpriteController>();

            tubeBloomLight.SetPrivateField("_dynamic3SliceSprite", parasprite);

            parasprite.InvokeMethod("Init");
            parasprite.GetComponent <MeshRenderer>().enabled = false;

            ReflectionUtil.SetPrivateField(withId, "_tubeBloomPrePassLight", tubeBloomLight);
            ReflectionUtil.SetPrivateField(withId, "_ID", (int)tl.lightsID, typeof(LightWithId));
            withId.SetPrivateField("_lightManager", defaultLightWithIdManager, typeof(LightWithId));

            tubeBloomLight.InvokeMethod("Refresh");
        }
コード例 #7
0
 public static void SetColorToDefault(TubeLight tl, TubeBloomPrePassLightWithId tubeBloomLight)
 {
     tubeBloomLight.ColorWasSet(tl.color * 0.9f);
     //tubeBloomLight.Refresh();
 }