Esempio n. 1
0
        private void Start()
        {
            envHider   = new EnvironmentHider();
            matSwapper = new MaterialSwapper();
            matSwapper.GetMaterials();

            CreateAllPlatforms();

            // Retrieve saved path from player prefs if it exists
            if (PlayerPrefs.HasKey("CustomPlatformPath"))
            {
                string savedPath = PlayerPrefs.GetString("CustomPlatformPath");
                // Check if this path was loaded and update our platform index
                for (int i = 0; i < bundlePaths.Count; i++)
                {
                    if (savedPath == bundlePaths.ElementAt(i))
                    {
                        platformIndex = i;
                    }
                }
            }

            PlatformUI.OnLoad();
            if (platforms.ElementAt(platformIndex) != null)
            {
                Log("Loading platforms.");
                //Finds and hides the environment after it loads.
                StartCoroutine(envHider.WaitForAndFindEnvironment(platforms.ElementAt(platformIndex)));
            }
        }
Esempio n. 2
0
        private void Start()
        {
            envHider   = new EnvironmentHider();
            matSwapper = new MaterialSwapper();
            matSwapper.GetMaterials();

            CreateAllPlatforms();

            // Retrieve saved path from player prefs if it exists
            if (PlayerPrefs.HasKey("CustomPlatformPath"))
            {
                string savedPath = PlayerPrefs.GetString("CustomPlatformPath");
                // Check if this path was loaded and update our platform index
                for (int i = 0; i < bundlePaths.Count; i++)
                {
                    if (savedPath == bundlePaths.ElementAt(i))
                    {
                        platformIndex = i;
                    }
                }
            }

            PlatformUI.OnLoad();
            if (platforms.ElementAt(platformIndex) != null)
            {
                // Find environment parts after scene change
                envHider.FindEnvironment();

                envHider.HideObjectsForPlatform(platforms.ElementAt(platformIndex));
            }
        }
            /// <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]);
            }
Esempio n. 4
0
 public AssetLoader(DiContainer container, Assembly assembly, [Inject(Id = "CustomPlatforms")] Transform anchor, MaterialSwapper materialSwapper)
 {
     _container       = container;
     _assembly        = assembly;
     _anchor          = anchor;
     _materialSwapper = materialSwapper;
 }
 private void Update()
 {
     if (activePlatform != null && activePlatform.GetComponentInChildren <Spectrogram>() != null)
     {
         if (activePlatform.GetComponentInChildren <Spectrogram>().transform.childCount != 0)
         {
             MaterialSwapper.ReplaceMaterials(activePlatform.gameObject);
         }
     }
 }
Esempio n. 6
0
 public PlatformSpawner(SiraLog siraLog, System.Random random, MaterialSwapper materialSwapper, AssetLoader assetLoader, EnvironmentHider environmentHider, PlatformManager platformManager, GameScenesManager gameScenesManager, LobbyGameStateModel lobbyGameStateModel)
 {
     _siraLog             = siraLog;
     _random              = random;
     _materialSwapper     = materialSwapper;
     _assetLoader         = assetLoader;
     _environmentHider    = environmentHider;
     _platformManager     = platformManager;
     _gameScenesManager   = gameScenesManager;
     _lobbyGameStateModel = lobbyGameStateModel;
 }
Esempio n. 7
0
        /// <summary>
        /// Loads AssetBundles and populates the platforms array with CustomPlatform objects
        /// </summary>
        public CustomPlatform[] CreateAllPlatforms(Transform parent)
        {
            if (matSwapper == null)
            {
                matSwapper = new MaterialSwapper();
            }

            string customPlatformsFolderPath = Path.Combine(Environment.CurrentDirectory, customFolder);

            // 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");

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

            // 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";
            defaultPlatform.icon             = Resources.FindObjectsOfTypeAll <Sprite>().Where(x => x.name == "LvlInsaneCover").FirstOrDefault();
            platforms.Add(defaultPlatform);
            bundlePaths.Add("");

            // Populate the platforms array
            for (int i = 0; i < allBundlePaths.Length; i++)
            {
                AssetBundle bundle = AssetBundle.LoadFromFile(allBundlePaths[i]);
                if (bundle == null)
                {
                    continue;
                }

                Log("Loading: " + Path.GetFileName(allBundlePaths[i]));

                CustomPlatform newPlatform = LoadPlatform(bundle, parent);

                if (newPlatform != null)
                {
                    platforms.Add(newPlatform);
                    bundlePaths.Add(allBundlePaths[i]);
                    Log("Loaded: " + newPlatform.name);
                }
            }

            return(platforms.ToArray());
        }
Esempio n. 8
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);
         }
     }
 }
Esempio n. 9
0
 public AssetLoader(DiContainer container, PluginMetadata pluginMetadata, MaterialSwapper materialSwapper)
 {
     _container        = container;
     _pluginMetadata   = pluginMetadata;
     _materialSwapper  = materialSwapper;
     _heartTask        = CreateHeartAsync();
     _playersPlaceTask = CreatePlayersPlaceAsync();
     using Stream defaultCoverStream  = GetEmbeddedResource("CustomFloorPlugin.Assets.LvlInsaneCover.png");
     DefaultPlatformCover             = defaultCoverStream.ReadTexture2D().ToSprite();
     using Stream fallbackCoverStream = GetEmbeddedResource("CustomFloorPlugin.Assets.FeetIcon.png");
     FallbackCover           = fallbackCoverStream.ReadTexture2D().ToSprite();
     MultiplayerLightEffects = new GameObject("LightEffects").AddComponent <LightEffects>();
 }
Esempio n. 10
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()));
             }
         }
     }
 }
Esempio n. 11
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);
        }
Esempio n. 12
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);
            }
        }
Esempio n. 13
0
        private void Start()
        {
            envHider   = new EnvironmentHider();
            matSwapper = new MaterialSwapper();
            matSwapper.GetMaterials();

            CreateAllPlatforms();

            // Retrieve saved path from player prefs if it exists
            if (ModPrefs.HasKey(CustomFloorPlugin.PluginName, "CustomPlatformPath"))
            {
                string savedPath = ModPrefs.GetString(CustomFloorPlugin.PluginName, "CustomPlatformPath");
                // Check if this path was loaded and update our platform index
                for (int i = 0; i < bundlePaths.Count; i++)
                {
                    if (savedPath == bundlePaths.ElementAt(i))
                    {
                        platformIndex = i;
                    }
                }
            }
            PlatformUI.OnLoad();
            HideEnvironment();
        }
Esempio n. 14
0
        private void AddManagers(GameObject go, GameObject root)
        {
            // Replace materials for this object
            MaterialSwapper.ReplaceMaterialsForGameObject(go);

            // Add a tube light manager if there are tube light descriptors
            if (go.GetComponentInChildren <TubeLight>(true) != null)
            {
                TubeLightManager tlm = root.GetComponent <TubeLightManager>();
                if (tlm == null)
                {
                    tlm = root.AddComponent <TubeLightManager>();
                }
                tlm.CreateTubeLights(go);
            }

            // Rotation effect manager
            if (go.GetComponentInChildren <RotationEventEffect>(true) != null)
            {
                RotationEventEffectManager rotManager = root.GetComponent <RotationEventEffectManager>();
                if (rotManager == null)
                {
                    rotManager = root.AddComponent <RotationEventEffectManager>();
                }
                rotManager.CreateEffects(go);
            }

            // Add a trackRing controller if there are track ring descriptors
            if (go.GetComponentInChildren <TrackRings>(true) != null)
            {
                foreach (TrackRings trackRings in go.GetComponentsInChildren <TrackRings>(true))
                {
                    GameObject ringPrefab = trackRings.trackLaneRingPrefab;

                    // Add managers to prefabs (nesting)
                    AddManagers(ringPrefab, root);
                }

                TrackRingsManagerSpawner trms = root.GetComponent <TrackRingsManagerSpawner>();
                if (trms == null)
                {
                    trms = root.AddComponent <TrackRingsManagerSpawner>();
                }
                trms.CreateTrackRings(go);
            }

            // Add spectrogram manager
            if (go.GetComponentInChildren <Spectrogram>(true) != null)
            {
                foreach (Spectrogram spec in go.GetComponentsInChildren <Spectrogram>(true))
                {
                    GameObject colPrefab = spec.columnPrefab;
                    AddManagers(colPrefab, root);
                }

                SpectrogramColumnManager specManager = go.GetComponent <SpectrogramColumnManager>();
                if (specManager == null)
                {
                    specManager = go.AddComponent <SpectrogramColumnManager>();
                }
                specManager.CreateColumns(go);
            }

            if (go.GetComponentInChildren <SpectrogramMaterial>(true) != null)
            {
                // Add spectrogram materials manager
                SpectrogramMaterialManager specMatManager = go.GetComponent <SpectrogramMaterialManager>();
                if (specMatManager == null)
                {
                    specMatManager = go.AddComponent <SpectrogramMaterialManager>();
                }
                specMatManager.UpdateMaterials();
            }


            if (go.GetComponentInChildren <SpectrogramAnimationState>(true) != null)
            {
                // Add spectrogram animation state manager
                SpectrogramAnimationStateManager specAnimManager = go.GetComponent <SpectrogramAnimationStateManager>();
                if (specAnimManager == null)
                {
                    specAnimManager = go.AddComponent <SpectrogramAnimationStateManager>();
                }
                specAnimManager.UpdateAnimationStates();
            }

            // Add Song event manager
            if (go.GetComponentInChildren <SongEventHandler>(true) != null)
            {
                foreach (SongEventHandler handler in go.GetComponentsInChildren <SongEventHandler>())
                {
                    SongEventManager manager = handler.gameObject.AddComponent <SongEventManager>();
                    manager._songEventHandler = handler;
                }
            }

            // Add EventManager
            if (go.GetComponentInChildren <EventManager>(true) != null)
            {
                foreach (EventManager em in go.GetComponentsInChildren <EventManager>())
                {
                    PlatformEventManager pem = em.gameObject.AddComponent <PlatformEventManager>();
                    pem._EventManager = em;
                }
            }
        }
Esempio n. 15
0
        internal static IEnumerator <WaitForEndOfFrame> ReplaceAllMaterialsAfterOneFrame()
        {
            yield return(new WaitForEndOfFrame());

            MaterialSwapper.ReplaceAllMaterials();
        }
 public PlatformLoader(SiraLog siraLog, MaterialSwapper materialSwapper)
 {
     _siraLog         = siraLog;
     _materialSwapper = materialSwapper;
     _pathTaskPairs   = new Dictionary <string, Task <CustomPlatform?> >();
 }
Esempio n. 17
0
 public void Construct(MaterialSwapper materialSwapper, [InjectOptional] BeatmapCallbacksController beatmapCallbacksController)
 {
     _materialSwapper            = materialSwapper;
     _beatmapCallbacksController = beatmapCallbacksController;
 }
Esempio n. 18
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);
                    }
Esempio n. 19
0
 public void Construct(MaterialSwapper materialSwapper, [InjectOptional] LightWithIdManager lightWithIdManager)
 {
     _materialSwapper    = materialSwapper;
     _lightWithIdManager = lightWithIdManager;
 }
Esempio n. 20
0
 public void Construct(MaterialSwapper materialSwapper, [InjectOptional] BasicSpectrogramData basicSpectrogramData)
 {
     _materialSwapper      = materialSwapper;
     _basicSpectrogramData = basicSpectrogramData;
 }
Esempio n. 21
0
 public void Construct(MaterialSwapper materialSwapper, [Inject(Id = "PostProcessEnabled")] BoolSO postProcessEnabled, [InjectOptional] LightWithIdManager lightWithIdManager)
 {
     _materialSwapper    = materialSwapper;
     _postProcessEnabled = postProcessEnabled;
     _lightWithIdManager = lightWithIdManager;
 }
Esempio n. 22
0
        /// <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;
        }