/// <summary>
            /// Changes to a specific <see cref="CustomPlatform"/>
            /// </summary>
            /// <param name="index">The index of the new <see cref="CustomPlatform"/> in the list <see cref="AllPlatforms"/></param>
            internal static void InternalChangeToPlatform(int index)
            {
                Log("Switching to " + AllPlatforms[index].name);
                if (!GetCurrentEnvironment().name.StartsWith("Menu", STR_INV))
                {
                    platformSpawned = true;
                }
                activePlatform?.gameObject.SetActive(false);
                NotifyPlatform(activePlatform, NotifyType.Disable);
                DestroyCustomObjects();

                if (index != 0)
                {
                    activePlatform = AllPlatforms[index % AllPlatforms.Count];
                    activePlatform.gameObject.SetActive(true);
                    AddManagers(activePlatform);
                    NotifyPlatform(activePlatform, NotifyType.Enable);
                    SpawnCustomObjects();
                    EnvironmentArranger.RearrangeEnvironment();
                    MaterialSwapper.ReplaceMaterials(activePlatform.gameObject);
                }
                else
                {
                    activePlatform = null;
                }
                EnvironmentHider.HideObjectsForPlatform(AllPlatforms[index]);
            }
 private void Update()
 {
     if (activePlatform != null && activePlatform.GetComponentInChildren <Spectrogram>() != null)
     {
         if (activePlatform.GetComponentInChildren <Spectrogram>().transform.childCount != 0)
         {
             MaterialSwapper.ReplaceMaterials(activePlatform.gameObject);
         }
     }
 }
Exemple #3
0
 private void Start()
 {
     foreach (TrackLaneRingsManager trackLaneRingsManager in trackLaneRingsManagers)
     {
         TrackLaneRing[] rings = trackLaneRingsManager.GetField <TrackLaneRing[], TrackLaneRingsManager>("_rings");
         foreach (TrackLaneRing ring in rings)
         {
             PlatformManager.SpawnedObjects.Add(ring.gameObject);
             MaterialSwapper.ReplaceMaterials(ring.gameObject);
         }
     }
 }
Exemple #4
0
 /// <summary>
 /// Enables or spawns all registered custom objects, as required by the selected <see cref="CustomPlatform"/>
 /// </summary>
 private void SpawnPlatform(GameObject platform)
 {
     platform.gameObject.SetActive(true);
     _materialSwapper.ReplaceMaterials(platform.gameObject);
     if (_lobbyGameStateModel.gameState == MultiplayerGameState.Game)
     {
         _assetLoader.MultiplayerLightEffects.PlatformEnabled(_container);
     }
     foreach (INotifyPlatformEnabled notifyEnable in platform.GetComponentsInChildren <INotifyPlatformEnabled>(true))
     {
         notifyEnable.PlatformEnabled(_container);
     }
 }
Exemple #5
0
 private void Start()
 {
     foreach (TrackLaneRingsManager trackLaneRingsManager in trackLaneRingsManagers)
     {
         TrackLaneRing[] rings = trackLaneRingsManager.GetField <TrackLaneRing[], TrackLaneRingsManager>("_rings");
         foreach (TrackLaneRing ring in rings)
         {
             ring.transform.parent = transform;
             PlatformManager.SpawnedObjects.Add(ring.gameObject);
             MaterialSwapper.ReplaceMaterials(ring.gameObject);
             foreach (TubeLight tubeLight in ring.GetComponentsInChildren <TubeLight>())
             {
                 tubeLight.GameAwake(FindLightWithIdManager(GetCurrentEnvironment()));
             }
         }
     }
 }
Exemple #6
0
        /// <summary>
        /// Loads AssetBundles and populates the platforms array with CustomPlatform objects
        /// </summary>
        public static List <CustomPlatform> CreateAllPlatforms(Transform parent)
        {
            string customPlatformsFolderPath = Path.Combine(Environment.CurrentDirectory, FOLDER);

            // Create the CustomPlatforms folder if it doesn't already exist
            if (!Directory.Exists(customPlatformsFolderPath))
            {
                Directory.CreateDirectory(customPlatformsFolderPath);
            }

            // Find AssetBundles in our CustomPlatforms directory
            string[] allBundlePaths = Directory.GetFiles(customPlatformsFolderPath, "*.plat");

            List <CustomPlatform> platforms = new List <CustomPlatform>();

            // Create a dummy CustomPlatform for the original platform
            CustomPlatform defaultPlatform = new GameObject("Default Platform").AddComponent <CustomPlatform>();

            defaultPlatform.transform.parent = parent;
            defaultPlatform.platName         = "Default Environment";
            defaultPlatform.platAuthor       = "Beat Saber";
            Texture2D texture = Resources.FindObjectsOfTypeAll <Texture2D>().First(x => x.name == "LvlInsaneCover");

            defaultPlatform.icon = Sprite.Create(texture, new Rect(0f, 0f, texture.width, texture.height), new Vector2(0.5f, 0.5f));
            platforms.Add(defaultPlatform);
            // Populate the platforms array
            Log("[START OF PLATFORM LOADING SPAM]-------------------------------------");
            int j = 0;

            for (int i = 0; i < allBundlePaths.Length; i++)
            {
                j++;
                CustomPlatform newPlatform = LoadPlatformBundle(allBundlePaths[i], parent);
                if (newPlatform != null)
                {
                    platforms.Add(newPlatform);
                }
            }
            Log("[END OF PLATFORM LOADING SPAM]---------------------------------------");
            // Replace materials for all renderers
            MaterialSwapper.ReplaceMaterials(SCENE);

            return(platforms);
        }
Exemple #7
0
        /// <summary>
        /// Creates <see cref="SpectrogramColumns"/> for each <see cref="Spectrogram"/> on the given <paramref name="gameObject"/>
        /// </summary>
        /// <param name="gameObject">What <see cref="GameObject"/> to create <see cref="SpectrogramColumns"/> for</param>
        internal void CreateColumns(GameObject gameObject)
        {
            spectrogramColumns = new List <SpectrogramColumns>();
            columnDescriptors  = new List <Spectrogram>();

            Spectrogram[] localDescriptors = gameObject.GetComponentsInChildren <Spectrogram>(true);
            foreach (Spectrogram spec in localDescriptors)
            {
                SpectrogramColumns specCol = spec.gameObject.AddComponent <SpectrogramColumns>();
                PlatformManager.SpawnedComponents.Add(specCol);

                MaterialSwapper.ReplaceMaterials(spec.columnPrefab);

                specCol._columnPrefab = spec.columnPrefab;
                specCol._separator    = spec.separator;
                specCol._minHeight    = spec.minHeight;
                specCol._maxHeight    = spec.maxHeight;
                specCol._columnWidth  = spec.columnWidth;
                specCol._columnDepth  = spec.columnDepth;

                spectrogramColumns.Add(specCol);
                columnDescriptors.Add(spec);
            }
        }
Exemple #8
0
                    SharedCoroutineStarter.instance.StartCoroutine(WaitAndReplaceMaterials()); //Waiting until the end of the Frame to prevent the Materials of Spectrograms not being replaced ("White Spectrograms Bug").
                    static IEnumerator <WaitForEndOfFrame> WaitAndReplaceMaterials()
                    {
                        yield return(new WaitForEndOfFrame());

                        MaterialSwapper.ReplaceMaterials(activePlatform.gameObject);
                    }
        /// <summary>
        /// Asynchronously loads a <see cref="CustomPlatform"/> from a specified file path
        /// </summary>
        internal IEnumerator <AsyncOperation> LoadFromFileAsync(string fullPath, Action <CustomPlatform, string> callback)
        {
            if (!File.Exists(fullPath))
            {
                throw new FileNotFoundException("File could not be found", fullPath);
            }

            using FileStream fileStream = File.OpenRead(fullPath);

            AssetBundleCreateRequest assetBundleCreateRequest = AssetBundle.LoadFromStreamAsync(fileStream);

            yield return(assetBundleCreateRequest);

            if (!assetBundleCreateRequest.isDone || !assetBundleCreateRequest.assetBundle)
            {
                throw new FileLoadException("File coulnd not be loaded", fullPath);
            }

            AssetBundleRequest platformAssetBundleRequest = assetBundleCreateRequest.assetBundle.LoadAssetAsync("_CustomPlatform");

            yield return(platformAssetBundleRequest);

            if (!platformAssetBundleRequest.isDone || !platformAssetBundleRequest.asset)
            {
                assetBundleCreateRequest.assetBundle.Unload(true);
                throw new FileLoadException("File coulnd not be loaded", fullPath);
            }

            assetBundleCreateRequest.assetBundle.Unload(false);

            GameObject platformPrefab = (GameObject)platformAssetBundleRequest.asset;

            foreach (AudioListener al in platformPrefab.GetComponentsInChildren <AudioListener>())
            {
                GameObject.DestroyImmediate(al);
            }

            CustomPlatform customPlatform = platformPrefab.GetComponent <CustomPlatform>();

            if (customPlatform == null)
            {
                // Check for old platform
                global::CustomPlatform legacyPlatform = platformPrefab.GetComponent <global::CustomPlatform>();
                if (legacyPlatform != null)
                {
                    // Replace legacyplatform component with up to date one
                    customPlatform                     = platformPrefab.AddComponent <CustomPlatform>();
                    customPlatform.platName            = legacyPlatform.platName;
                    customPlatform.platAuthor          = legacyPlatform.platAuthor;
                    customPlatform.hideDefaultPlatform = true;
                    // Remove old platform data
                    GameObject.Destroy(legacyPlatform);
                }
                else
                {
                    // no customplatform component, abort
                    GameObject.Destroy(platformPrefab);
                    yield break;
                }
            }

            customPlatform.name     = customPlatform.platName + " by " + customPlatform.platAuthor;
            customPlatform.fullPath = fullPath;

            using MD5 md5 = MD5.Create();
            byte[] hash = md5.ComputeHash(fileStream);
            customPlatform.platHash = BitConverter.ToString(hash).Replace("-", string.Empty).ToLowerInvariant();

            MaterialSwapper.ReplaceMaterials(customPlatform.gameObject);

            callback(customPlatform, fullPath);

            GameObject.Destroy(platformPrefab);

            yield break;
        }