Пример #1
0
        public void PlatformEnabled(DiContainer container)
        {
            container.Inject(this);
            bool activeSelf = gameObject.activeSelf;

            gameObject.SetActive(false);

            if (_instancedMaterialLightWithId is null && _tubeBloomPrePassLightWithId is null)
            {
                Mesh mesh = GetComponent <MeshFilter>().mesh;
                if (mesh.vertexCount == 0)
                {
                    _tubeBloomPrePassLightWithId = gameObject.AddComponent <TubeBloomPrePassLightWithId>();
                    TubeBloomPrePassLight tubeBloomPrePassLight = gameObject.AddComponent <TubeBloomPrePassLight>();
                    GameObject            boxLight = new("BoxLight");
                    boxLight.SetActive(false);
                    Transform boxLightTransform = boxLight.transform;
                    boxLightTransform.transform.SetParent(transform);
                    boxLightTransform.transform.localRotation = Quaternion.Euler(Vector3.zero);
                    MeshFilter meshFilter = boxLight.AddComponent <MeshFilter>();
                    meshFilter.mesh = Mesh;
                    MeshRenderer renderer = boxLight.AddComponent <MeshRenderer>();
                    renderer.sharedMaterial = _materialSwapper !.TransparentGlowMaterial;
                    ParametricBoxController parametricBoxController = boxLight.AddComponent <ParametricBoxController>();
                    _meshRendererAccessor(ref parametricBoxController)               = renderer;
                    _centerAccessor(ref tubeBloomPrePassLight)                       = center;
                    _parametricBoxControllerAccessor(ref tubeBloomPrePassLight)      = parametricBoxController;
                    _mainEffectPostProcessEnabledAccessor(ref tubeBloomPrePassLight) = _postProcessEnabled;
                    tubeBloomPrePassLight.width  = width * 2;
                    tubeBloomPrePassLight.length = length;
                    tubeBloomPrePassLight.bloomFogIntensityMultiplier = bloomFogIntensityMultiplier;
                    _tubeBloomPrePassLightAccessor(ref _tubeBloomPrePassLightWithId) = tubeBloomPrePassLight;
                    BloomPrePassLight bloomPrePassLight = tubeBloomPrePassLight;
                    _lightTypeAccessor(ref bloomPrePassLight) = BloomPrePassLight.bloomLightsDict.Keys.First(static x => x.name == "AddBloomPrePassLightType");
 internal void Init(Track track, float noteLinesDistance, TrackLaneRing trackLaneRing, ParametricBoxController parametricBoxController)
 {
     _track                   = track;
     _noteLinesDistance       = noteLinesDistance;
     _trackLaneRing           = trackLaneRing;
     _parametricBoxController = parametricBoxController;
 }
Пример #3
0
        internal void GameAwake(LightWithIdManager lightManager)
        {
            GetComponent <MeshRenderer>().enabled = false;
            if (GetComponent <MeshFilter>().mesh.vertexCount == 0)
            {
                tubeBloomLight = Instantiate(Prefab);
                tubeBloomLight.transform.parent = transform;
                PlatformManager.SpawnedObjects.Add(tubeBloomLight.gameObject);

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

                tubeBloomLight.gameObject.SetActive(false);

                TubeBloomPrePassLightWithId lightWithId = tubeBloomLight.GetComponent <TubeBloomPrePassLightWithId>();
                if (lightWithId)
                {
                    lightWithId.SetField("_tubeBloomPrePassLight", tubeBloomLight);
                    ((LightWithIdMonoBehaviour)lightWithId).SetField("_ID", (int)lightsID);
                    ((LightWithIdMonoBehaviour)lightWithId).SetField("_lightManager", lightManager);
                }

                tubeBloomLight.SetField("_width", width * 2);
                tubeBloomLight.SetField("_length", length);
                tubeBloomLight.SetField("_center", center);
                tubeBloomLight.SetField("_transform", tubeBloomLight.transform);
                tubeBloomLight.SetField("_maxAlpha", 0.1f);
                tubeBloomLight.SetField("_bloomFogIntensityMultiplier", fogIntensityMultiplier);

                ParametricBoxController parabox = tubeBloomLight.GetComponentInChildren <ParametricBoxController>();
                tubeBloomLight.SetField("_parametricBoxController", parabox);

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

                SetColorToDefault();
                tubeBloomLight.gameObject.SetActive(true);
            }
            else
            {
                // swap for <3
                PlatformManager.InactiveHeart.SetActive(false);
                iHeartBeatSaber = Instantiate(PlatformManager.InactiveHeart);
                PlatformManager.SpawnedObjects.Add(iHeartBeatSaber);
                iHeartBeatSaber.transform.parent     = transform;
                iHeartBeatSaber.transform.position   = transform.position;
                iHeartBeatSaber.transform.localScale = Vector3.one;
                iHeartBeatSaber.transform.rotation   = transform.rotation;
                InstancedMaterialLightWithId lightWithId = iHeartBeatSaber.GetComponent <InstancedMaterialLightWithId>();
                ((LightWithIdMonoBehaviour)lightWithId).SetField("_ID", (int)lightsID);
                ((LightWithIdMonoBehaviour)lightWithId).SetField("_lightManager", lightManager);
                lightWithId.SetField("_minAlpha", 0f);
                iHeartBeatSaber.GetComponent <MeshFilter>().mesh = GetComponent <MeshFilter>().mesh;
                iHeartBeatSaber.SetActive(true);
            }
        }
Пример #4
0
        private static ParametricBoxControllerParameters GetParameters(ParametricBoxController parametricBoxController)
        {
            if (!TransformParameters.TryGetValue(parametricBoxController, out ParametricBoxControllerParameters parameters))
            {
                parameters = new ParametricBoxControllerParameters();
                TransformParameters.Add(parametricBoxController, parameters);
            }

            return(parameters);
        }
Пример #5
0
        private static Vector3 GetTransformPosition(Vector3 @default, ParametricBoxController parametricBoxController)
        {
            if (ParametricBoxControllerParameters.TransformParameters.TryGetValue(parametricBoxController, out ParametricBoxControllerParameters parameters))
            {
                if (parameters.Position.HasValue)
                {
                    return(parameters.Position.Value);
                }
            }

            return(@default);
        }
 internal static void HandleTrackData(
     GameObject gameObject,
     dynamic gameObjectData,
     IReadonlyBeatmapData beatmapData,
     float noteLinesDistance,
     TrackLaneRing trackLaneRing,
     ParametricBoxController parametricBoxController)
 {
     if (NoodleController.NoodleExtensionsActive)
     {
         Track track = NoodleExtensions.Animation.AnimationHelper.GetTrackPreload(gameObjectData, beatmapData);
         if (track != null)
         {
             GameObjectTrackController trackController = gameObject.AddComponent <GameObjectTrackController>();
             trackController.Init(track, noteLinesDistance, trackLaneRing, parametricBoxController);
         }
     }
 }
Пример #7
0
 internal static void SetTransformPosition(ParametricBoxController parametricBoxController, Vector3 position)
 {
     GetParameters(parametricBoxController).Position = position;
 }
Пример #8
0
 internal static void SetTransformScale(ParametricBoxController parametricBoxController, Vector3 scale)
 {
     GetParameters(parametricBoxController).Scale = scale;
 }
Пример #9
0
        internal static void Init(CustomBeatmapData customBeatmapData, float noteLinesDistance)
        {
            List <dynamic> environmentData = Trees.at(customBeatmapData.customData, ENVIRONMENT);

            GetAllGameObjects();
            if (environmentData != null)
            {
                RingRotationOffsets.Clear();
                ParametricBoxControllerParameters.TransformParameters.Clear();

                if (Settings.ChromaConfig.Instance.PrintEnvironmentEnhancementDebug)
                {
                    ChromaLogger.Log($"=====================================");
                }

                foreach (dynamic gameObjectData in environmentData)
                {
                    string id = Trees.at(gameObjectData, ID);

                    string       lookupString = Trees.at(gameObjectData, LOOKUPMETHOD);
                    LookupMethod lookupMethod = (LookupMethod)Enum.Parse(typeof(LookupMethod), lookupString);

                    int?dupeAmount = (int?)Trees.at(gameObjectData, DUPLICATIONAMOUNT);

                    bool?active = (bool?)Trees.at(gameObjectData, ACTIVE);

                    Vector3?scale         = GetVectorData(gameObjectData, SCALE);
                    Vector3?position      = GetVectorData(gameObjectData, POSITION);
                    Vector3?rotation      = GetVectorData(gameObjectData, OBJECTROTATION);
                    Vector3?localPosition = GetVectorData(gameObjectData, LOCALPOSITION);
                    Vector3?localRotation = GetVectorData(gameObjectData, LOCALROTATION);

                    List <GameObjectInfo> foundObjects = LookupID(id, lookupMethod);
                    if (Settings.ChromaConfig.Instance.PrintEnvironmentEnhancementDebug)
                    {
                        ChromaLogger.Log($"ID [\"{id}\"] using method [{lookupMethod:G}] found:");
                        foundObjects.ForEach(n => ChromaLogger.Log(n.FullID));
                    }

                    List <GameObjectInfo> gameObjectInfos;

                    if (dupeAmount.HasValue)
                    {
                        gameObjectInfos = new List <GameObjectInfo>();
                        foreach (GameObjectInfo gameObjectInfo in foundObjects)
                        {
                            if (Settings.ChromaConfig.Instance.PrintEnvironmentEnhancementDebug)
                            {
                                ChromaLogger.Log($"Duplicating [{gameObjectInfo.FullID}]:");
                            }

                            GameObject gameObject = gameObjectInfo.GameObject;
                            Transform  parent     = gameObject.transform.parent;
                            Scene      scene      = gameObject.scene;

                            for (int i = 0; i < dupeAmount.Value; i++)
                            {
                                List <IComponentData> componentDatas = new List <IComponentData>();
                                ComponentInitializer.PrefillComponentsData(gameObject.transform, componentDatas);
                                GameObject newGameObject = UnityEngine.Object.Instantiate(gameObject);
                                ComponentInitializer.PostfillComponentsData(newGameObject.transform, gameObject.transform, componentDatas);
                                SceneManager.MoveGameObjectToScene(newGameObject, scene);
                                newGameObject.transform.SetParent(parent, true);
                                ComponentInitializer.InitializeComponents(newGameObject.transform, gameObject.transform, _gameObjectInfos, componentDatas);
                                gameObjectInfos.AddRange(_gameObjectInfos.Where(n => n.GameObject == newGameObject));
                            }
                        }
                    }
                    else
                    {
                        gameObjectInfos = foundObjects;
                    }

                    foreach (GameObjectInfo gameObjectInfo in gameObjectInfos)
                    {
                        GameObject gameObject = gameObjectInfo.GameObject;

                        if (active.HasValue)
                        {
                            gameObjectInfo.GameObject.SetActive(active.Value);
                        }

                        Transform transform = gameObject.transform;

                        if (scale.HasValue)
                        {
                            transform.localScale = scale.Value;
                        }

                        if (position.HasValue)
                        {
                            transform.position = position.Value * noteLinesDistance;
                        }

                        if (rotation.HasValue)
                        {
                            transform.eulerAngles = rotation.Value;
                        }

                        if (localPosition.HasValue)
                        {
                            transform.localPosition = localPosition.Value * noteLinesDistance;
                        }

                        if (localRotation.HasValue)
                        {
                            transform.localEulerAngles = localRotation.Value;
                        }

                        // Handle TrackLaneRing
                        TrackLaneRing trackLaneRing = gameObject.GetComponent <TrackLaneRing>();
                        if (trackLaneRing != null)
                        {
                            if (position.HasValue || localPosition.HasValue)
                            {
                                _positionOffsetAccessor(ref trackLaneRing) = transform.localPosition;
                                _posZAccessor(ref trackLaneRing) = 0;
                            }

                            if (rotation.HasValue || localRotation.HasValue)
                            {
                                RingRotationOffsets[trackLaneRing] = transform.localRotation;
                                _rotZAccessor(ref trackLaneRing) = 0;
                            }
                        }

                        // Handle ParametricBoxController
                        ParametricBoxController parametricBoxController = gameObject.GetComponent <ParametricBoxController>();
                        if (parametricBoxController != null)
                        {
                            if (position.HasValue || localPosition.HasValue)
                            {
                                ParametricBoxControllerParameters.SetTransformPosition(parametricBoxController, transform.localPosition);
                            }

                            if (scale.HasValue)
                            {
                                ParametricBoxControllerParameters.SetTransformScale(parametricBoxController, transform.localScale);
                            }
                        }

                        if (NoodleExtensionsInstalled)
                        {
                            GameObjectTrackController.HandleTrackData(gameObject, gameObjectData, customBeatmapData, noteLinesDistance, trackLaneRing, parametricBoxController);
                        }
                    }

                    if (Settings.ChromaConfig.Instance.PrintEnvironmentEnhancementDebug)
                    {
                        ChromaLogger.Log($"=====================================");
                    }
                }
            }

            LegacyEnvironmentRemoval.Init(customBeatmapData);
        }
        internal static void Init(CustomBeatmapData customBeatmapData, float noteLinesDistance)
        {
            IEnumerable <Dictionary <string, object?> >?environmentData = customBeatmapData.customData.Get <List <object> >(ENVIRONMENT)?.Cast <Dictionary <string, object?> >();

            GetAllGameObjects();

            RingRotationOffsets = new Dictionary <TrackLaneRing, Quaternion>();
            AvoidancePosition   = new Dictionary <BeatmapObjectsAvoidance, Vector3>();
            AvoidanceRotation   = new Dictionary <BeatmapObjectsAvoidance, Quaternion>();
            ParametricBoxControllerParameters.TransformParameters = new Dictionary <ParametricBoxController, ParametricBoxControllerParameters>();

            if (environmentData != null)
            {
                RingRotationOffsets.Clear();
                ParametricBoxControllerParameters.TransformParameters.Clear();

                if (Settings.ChromaConfig.Instance !.PrintEnvironmentEnhancementDebug)
                {
                    Plugin.Logger.Log($"=====================================");
                }

                foreach (Dictionary <string, object?> gameObjectData in environmentData)
                {
                    string id = gameObjectData.Get <string>(ID) ?? throw new InvalidOperationException("Id was not defined.");

                    string       lookupString = gameObjectData.Get <string>(LOOKUPMETHOD) ?? throw new InvalidOperationException("Lookup method was not defined.");
                    LookupMethod lookupMethod = (LookupMethod)Enum.Parse(typeof(LookupMethod), lookupString);

                    int?dupeAmount = gameObjectData.Get <int?>(DUPLICATIONAMOUNT);

                    bool?active = gameObjectData.Get <bool?>(ACTIVE);

                    Vector3?scale         = GetVectorData(gameObjectData, SCALE);
                    Vector3?position      = GetVectorData(gameObjectData, POSITION);
                    Vector3?rotation      = GetVectorData(gameObjectData, OBJECTROTATION);
                    Vector3?localPosition = GetVectorData(gameObjectData, LOCALPOSITION);
                    Vector3?localRotation = GetVectorData(gameObjectData, LOCALROTATION);

                    int?lightID = gameObjectData.Get <int?>(LIGHTID);

                    List <GameObjectInfo> foundObjects = LookupID(id, lookupMethod);
                    if (Settings.ChromaConfig.Instance !.PrintEnvironmentEnhancementDebug)
                    {
                        if (foundObjects.Count > 0)
                        {
                            Plugin.Logger.Log($"ID [\"{id}\"] using method [{lookupMethod:G}] found:");
                            foundObjects.ForEach(n => Plugin.Logger.Log(n.FullID));
                        }
                        else
                        {
                            Plugin.Logger.Log($"ID [\"{id}\"] using method [{lookupMethod:G}] found nothing.", IPA.Logging.Logger.Level.Error);
                        }
                    }

                    List <GameObjectInfo> gameObjectInfos;

                    if (dupeAmount.HasValue)
                    {
                        gameObjectInfos = new List <GameObjectInfo>();
                        foreach (GameObjectInfo gameObjectInfo in foundObjects)
                        {
                            if (Settings.ChromaConfig.Instance !.PrintEnvironmentEnhancementDebug)
                            {
                                Plugin.Logger.Log($"Duplicating [{gameObjectInfo.FullID}]:");
                            }

                            GameObject gameObject = gameObjectInfo.GameObject;
                            Transform  parent     = gameObject.transform.parent;
                            Scene      scene      = gameObject.scene;

                            for (int i = 0; i < dupeAmount.Value; i++)
                            {
                                List <IComponentData> componentDatas = new List <IComponentData>();
                                ComponentInitializer.PrefillComponentsData(gameObject.transform, componentDatas);
                                GameObject newGameObject = UnityEngine.Object.Instantiate(gameObject);
                                ComponentInitializer.PostfillComponentsData(newGameObject.transform, gameObject.transform, componentDatas);
                                SceneManager.MoveGameObjectToScene(newGameObject, scene);
                                newGameObject.transform.SetParent(parent, true);
                                ComponentInitializer.InitializeComponents(newGameObject.transform, gameObject.transform, _gameObjectInfos, componentDatas, lightID);

                                List <GameObjectInfo> gameObjects = _gameObjectInfos.Where(n => n.GameObject == newGameObject).ToList();
                                gameObjectInfos.AddRange(gameObjects);

                                if (Settings.ChromaConfig.Instance !.PrintEnvironmentEnhancementDebug)
                                {
                                    gameObjects.ForEach(n => Plugin.Logger.Log(n.FullID));
                                }
                            }
                        }
                    }
                    else
                    {
                        if (lightID.HasValue)
                        {
                            Plugin.Logger.Log($"LightID requested but no duplicated object to apply to.", IPA.Logging.Logger.Level.Error);
                        }

                        gameObjectInfos = foundObjects;
                    }

                    foreach (GameObjectInfo gameObjectInfo in gameObjectInfos)
                    {
                        GameObject gameObject = gameObjectInfo.GameObject;

                        if (active.HasValue)
                        {
                            gameObjectInfo.GameObject.SetActive(active.Value);
                        }

                        Transform transform = gameObject.transform;

                        if (scale.HasValue)
                        {
                            transform.localScale = scale.Value;
                        }

                        if (position.HasValue)
                        {
                            transform.position = position.Value * noteLinesDistance;
                        }

                        if (rotation.HasValue)
                        {
                            transform.eulerAngles = rotation.Value;
                        }

                        if (localPosition.HasValue)
                        {
                            transform.localPosition = localPosition.Value * noteLinesDistance;
                        }

                        if (localRotation.HasValue)
                        {
                            transform.localEulerAngles = localRotation.Value;
                        }

                        // Handle TrackLaneRing
                        TrackLaneRing trackLaneRing = gameObject.GetComponent <TrackLaneRing>();
                        if (trackLaneRing != null)
                        {
                            if (position.HasValue || localPosition.HasValue)
                            {
                                _positionOffsetAccessor(ref trackLaneRing) = transform.localPosition;
                                _posZAccessor(ref trackLaneRing) = 0;
                            }

                            if (rotation.HasValue || localRotation.HasValue)
                            {
                                RingRotationOffsets[trackLaneRing] = transform.localRotation;
                                _rotZAccessor(ref trackLaneRing) = 0;
                            }
                        }

                        // Handle ParametricBoxController
                        ParametricBoxController parametricBoxController = gameObject.GetComponent <ParametricBoxController>();
                        if (parametricBoxController != null)
                        {
                            if (position.HasValue || localPosition.HasValue)
                            {
                                ParametricBoxControllerParameters.SetTransformPosition(parametricBoxController, transform.localPosition);
                            }

                            if (scale.HasValue)
                            {
                                ParametricBoxControllerParameters.SetTransformScale(parametricBoxController, transform.localScale);
                            }
                        }

                        // Handle BeatmapObjectsAvoidance
                        BeatmapObjectsAvoidance beatmapObjectsAvoidance = gameObject.GetComponent <BeatmapObjectsAvoidance>();
                        if (beatmapObjectsAvoidance != null)
                        {
                            if (position.HasValue || localPosition.HasValue)
                            {
                                AvoidancePosition[beatmapObjectsAvoidance] = transform.localPosition;
                            }

                            if (rotation.HasValue || localRotation.HasValue)
                            {
                                AvoidanceRotation[beatmapObjectsAvoidance] = transform.localRotation;
                            }
                        }

                        GameObjectTrackController.HandleTrackData(gameObject, gameObjectData, customBeatmapData, noteLinesDistance, trackLaneRing, parametricBoxController, beatmapObjectsAvoidance);
                    }

                    if (Settings.ChromaConfig.Instance !.PrintEnvironmentEnhancementDebug)
                    {
                        Plugin.Logger.Log($"=====================================");
                    }
                }
            }

            try
            {
                LegacyEnvironmentRemoval.Init(customBeatmapData);
            }
            catch (Exception e)
            {
                Plugin.Logger.Log("Could not run Legacy Enviroment Removal");
                Plugin.Logger.Log(e);
            }
        }