Пример #1
0
 public void ResetPrefs(EffectDiscriptor effectDiscriptor)
 {
     Prefs.ReadPrefs();
     if (effectDiscriptor.Author == "MyName" || string.IsNullOrEmpty(effectDiscriptor.Author))
     {
         effectDiscriptor.Author = Prefs.PreferredAuthorName;
     }
 }
Пример #2
0
        public async void SetRefs()
        {
            hasFullSetRefs = true;
            Plugin.Log.Info("SetRefs " + CurrentScene.name);
            WeatherDataRoot weatherInfo = await WeatherFinder.GetWeatherData();

            MeshRenderer[] mrs = Resources.FindObjectsOfTypeAll <MeshRenderer>();
            //Plugin.Log.Info("SetRefs 1");
            if (CurrentScene.name == Plugin.menu)
            {
                BundleLoader.WeatherPrefab.SetActive(PluginConfig.Instance.enabledInMenu);
            }
            if (CurrentScene.name == Plugin.game)
            {
                BundleLoader.WeatherPrefab.SetActive(PluginConfig.Instance.enabledInGameplay);
            }
            BundleLoader.effects.Clear();
            for (int x = 0; x < weatherInfo.weather.Length; x++)
            {
                WeatherData data = weatherInfo.weather[x];
                EffectModel.EnableEffect(data.main, true);
            }
            for (int i = 0; i < gameObject.transform.childCount; i++)
            {
                //Plugin.Log.Info(i.ToString());
                Transform Child = gameObject.transform.GetChild(i);
                Child.gameObject.SetActive(true);

                EffectDiscriptor efd       = Child.gameObject.GetComponent <EffectDiscriptor>();
                string           NameToUse = EffectModel.GetNameWithoutSceneName(efd.EffectName);
                Child.gameObject.GetComponentsInChildren <AudioSource>().ToList().ForEach((AudioSource s) => { s.volume = PluginConfig.Instance.audioSFXVolume; });
                efd.gameObject.SetActive(true);
                efd.transform.GetChild(0).gameObject.SetActive(true);
                Effect eff = new Effect(efd, Child.gameObject, PluginConfig.Instance.enabledEffects.Any((string str) => { return(str == efd.EffectName); }));

                if (MiscConfig.hasObject(NameToUse))
                {
                    //Plugin.Log.Info("Misc Config has Object! " + NameToUse);
                    MiscConfigObject Object = MiscConfig.ReadObject(NameToUse);
                    eff.showInMenu = Object.showInMenu;
                    eff.showInGame = Object.showInGame;
                }
                else
                {
                    MiscConfig.Add(new MiscConfigObject(NameToUse, eff.showInMenu, eff.showInGame));
                    MiscConfig.Write();
                }
                eff.SetActiveRefs();
                BundleLoader.effects.Add(eff);
                //Plugin.Log.Info("Replacing " + mrs.Length.ToString    ());
                for (int x = 0; x < mrs.Length; x++)
                {
                    MeshRenderer mr = mrs[x];
                    if (mr.material.name.Contains("Note") || mr.gameObject.name.Contains("building") || mr.gameObject.name.Contains("speaker"))
                    {
                        eff.TrySetNoteMateral(mr);
                    }
                    else
                    {
                        continue;
                    }
                }
            }
        }
Пример #3
0
    private void BuildAssetBundle(BuildTarget Target, string Ext)
    {
        EffectDiscriptor effectDiscriptor = (EffectDiscriptor)serializedObject.targetObject;
        string           name             = Regex.Replace(effectDiscriptor.EffectName, @"\s+", "");

        if (autoGrabCover)
        {
            effectDiscriptor.coverImage = getTexture2D(screenshotCamera, 1024, 1024);
        }
        GameObject prefab = new GameObject("Effect");

        Selection.activeGameObject.transform.SetParent(prefab.transform);
        PrefabUtility.SaveAsPrefabAsset(prefab, "Assets/Effect.prefab");

        TextAsset effectJson = new TextAsset(JsonUtility.ToJson(effectDiscriptor.GetJSON(), true));

        AssetDatabase.CreateAsset(effectJson, "Assets/effectJson.asset");
        string coverPath = Path.Combine(Application.dataPath, "Covers", name + "Cover.png");

        if (!Directory.Exists(Path.GetDirectoryName(coverPath)))
        {
            Directory.CreateDirectory(Path.GetDirectoryName(coverPath));
        }
        File.WriteAllBytes(coverPath, effectDiscriptor.coverImage.EncodeToPNG());

        AssetDatabase.CreateAsset(effectDiscriptor.coverImage, "Assets/Covers/" + name + "Cover.asset");

        AssetBundleBuild assetBundleBuild = default;

        assetBundleBuild.assetNames = new string[]
        {
            "Assets/Effect.prefab",
            "Assets/effectJson.asset",
            "Assets/Covers/" + name + "Cover.asset",
        };
        string path = Path.Combine(Application.dataPath, "EffectResult", effectDiscriptor.EffectName + Ext);

        if (!Directory.Exists(Path.GetDirectoryName(path)))
        {
            Directory.CreateDirectory(Path.GetDirectoryName(path));
        }
        //if (string.IsNullOrEmpty(path)) return;
        assetBundleBuild.assetBundleName = Path.GetFileName(path);
        if (File.Exists(path))
        {
            File.Delete(path);
        }
        BuildPipeline.BuildAssetBundles(Path.GetDirectoryName(path), new AssetBundleBuild[] { assetBundleBuild }, 0, Target);
        EditorPrefs.SetString("currentBuildingAssetBundlePath", Path.GetDirectoryName(path));
        //Cleanup

        AssetDatabase.DeleteAsset("Assets/Effect.prefab");
        AssetDatabase.DeleteAsset("Assets/effectJson.asset");
        AssetDatabase.DeleteAsset("Assets/Covers/" + name + "Cover.asset");


        if (CopyToBeatSaberFolder)
        {
            if (!Directory.Exists(Path.Combine(Prefs.BeatSaberPath, "UserData", "Weather", "Effects")))
            {
                Directory.CreateDirectory(Path.Combine(Prefs.BeatSaberPath, "UserData", "Weather", "Effects"));
            }
            string copyPath = Path.Combine(Prefs.BeatSaberPath, "UserData", "Weather", "Effects", effectDiscriptor.EffectName + Ext);
            if (File.Exists(copyPath))
            {
                File.Delete(copyPath);
            }
            File.Copy(path, copyPath);
        }
        effectDiscriptor.transform.parent = null;
        DestroyImmediate(prefab);
        DeleteDirectory(Path.GetDirectoryName(path));
        File.Delete(Path.GetDirectoryName(path) + ".meta");
        AssetDatabase.Refresh();
    }
Пример #4
0
    public override void OnInspectorGUI()
    {
        base.DrawDefaultInspector();
        EffectDiscriptor effectDiscriptor = (EffectDiscriptor)serializedObject.targetObject;

        ResetPrefs(effectDiscriptor);
        GUILayout.Space(15f);
        EditorGUILayout.LabelField("Export", EditorStyles.boldLabel);
        if (GUILayout.Button("Build " + effectDiscriptor.EffectName))
        {
            if (PC)
            {
                BuildAssetBundle(BuildTarget.StandaloneWindows, ".effect");
            }

            if (Quest)
            {
                BuildAssetBundle(BuildTarget.Android, ".qeffect");
            }
        }
        PC    = GUILayout.Toggle(PC, "Include PC Export");
        Quest = GUILayout.Toggle(Quest, "Include Quest Export");
        CopyToBeatSaberFolder = GUILayout.Toggle(CopyToBeatSaberFolder, "Copy Result To BeatSaber Folder");
        autoGrabCover         = GUILayout.Toggle(autoGrabCover, "Automatically Grab Cover");

        if (CopyToBeatSaberFolder)
        {
            if (Prefs.BeatSaberPath == "")
            {
                EditorGUILayout.LabelField("    Prefs Beatsaber path is empty! Please set it in Weather/Exporter Prefs or your effect won't be copied", EditorStyles.boldLabel);
            }

            if (!PC)
            {
                EditorGUILayout.LabelField("    Won't export for PC, result Won't be copied!", EditorStyles.boldLabel);
            }
        }
        else
        {
            EditorGUILayout.LabelField(string.Format("  Not Copying, result will be in, {0} and .QEffect", Path.GetFullPath(Path.Combine(Application.dataPath, "EffectResult", effectDiscriptor.EffectName + ".Effect"))), EditorStyles.boldLabel);
        }

        if (autoGrabCover)
        {
            if (Camera.main == null)
            {
                EditorGUILayout.LabelField("    Wants to grab cover automatically but there is no camera!", EditorStyles.boldLabel);
            }
        }

        Transform NotesShader = effectDiscriptor.transform.Find("NotesShader");

        if (NotesShader)
        {
            MeshRenderer mr;
            if ((mr = NotesShader.GetComponent <MeshRenderer>()) == null)
            {
                EditorGUILayout.LabelField("Has NotesShader Object but it doesn't have a MeshRenderer!", EditorStyles.boldLabel);
            }
            else if (mr.sharedMaterials.Length == 0 || mr.sharedMaterials[0] == null)
            {
                EditorGUILayout.LabelField("Has NotesShader Object with MeshRenderer but there are no materials assigned!", EditorStyles.boldLabel);
            }
        }

        LogConfig = GUILayout.Toggle(LogConfig, "Log Effect JSON");

        GUILayout.Space(15f);
        EditorGUILayout.LabelField("Prefs", EditorStyles.boldLabel);
        EditorGUILayout.LabelField("You can change your prefs on the top right in Weather/Exporter Prefs", EditorStyles.label);
        if (GUILayout.Button("Reload Prefs"))
        {
            Prefs.ReadPrefs();
            ResetPrefs(effectDiscriptor);
        }

        GUILayout.Space(15f);
        EditorGUILayout.LabelField("Misc", EditorStyles.boldLabel);
        if (GUILayout.Button("Add Note Shader Copy"))
        {
            if (NotesShader)
            {
                return;
            }
            GameObject NotesShaderNew = new GameObject("NotesShader", typeof(MeshRenderer));
            NotesShaderNew.transform.SetParent(effectDiscriptor.transform);
        }
        if (rt == null || screenshotCamera == null)
        {
            if (GUILayout.Button("Add Screen shot Camera"))
            {
                if (NotesShader)
                {
                    return;
                }
                GameObject Camera = new GameObject("CoverCamera", typeof(Camera));
                Camera.tag = "MainCamera";
                Camera.transform.position = new Vector3(5f, 9.5f, -5.5f);
                Camera.transform.rotation = Quaternion.Euler(45f, -45f, 0f);
                Camera cam = Camera.GetComponent <Camera>();
                cam.clearFlags      = CameraClearFlags.Color;
                cam.backgroundColor = Color.black;
                cam.targetTexture   = Resources.FindObjectsOfTypeAll <RenderTexture>().First((RenderTexture rt) => { return(rt.name == "DoNotTouch"); });
                rt = cam.targetTexture;
                screenshotCamera = cam;
            }
        }
    }
Пример #5
0
        public static void LoadFromBundle(AsyncOperation bundleRequest, string filePath)
        {
            AssetBundle bundle    = (bundleRequest as AssetBundleCreateRequest).assetBundle;
            TextAsset   json      = bundle.LoadAsset <TextAsset>("assets/effectJson.asset");
            Sprite      Cover     = null;
            string      coverPath = "";

            foreach (string path in bundle.GetAllAssetNames())
            {
                if (path.StartsWith("assets/covers/"))
                {
                    coverPath = path;
                }
            }
            if (coverPath != "")
            {
                try
                {
                    Texture2D coverTex = bundle.LoadAsset <Texture2D>(coverPath);
                    Cover = Sprite.Create(coverTex, new Rect(0, 0, coverTex.width, coverTex.height), new Vector2(0, 0), 100f);
                }
                catch
                {
                    Cover = DefaultTex;
                }
            }
            else
            {
                Cover = DefaultTex;
            }

            GameObject Eff = Object.Instantiate(bundle.LoadAsset <GameObject>("assets/Effect.prefab"), WeatherPrefab.transform);

            Eff.SetActive(false);
            TempDesc_0_1_2 EfdTemp = null;

            try
            {
                EfdTemp = JsonUtility.FromJson <TempDesc_0_1_2>(json.text);
            }
            catch
            {
                try
                {
                    TempDesc_0_1_1 EfdOld1 = JsonUtility.FromJson <TempDesc_0_1_1>(json.text);
                    EfdTemp = new TempDesc_0_1_2(EfdOld1.Author, EfdOld1.EffectName, EfdOld1.WorksInMenu, true);
                }
                catch
                {
                    string fileName = Path.GetFileNameWithoutExtension(filePath);
                    Plugin.Log.Error(string.Format("{0} Failed To Load! Json: {1}", fileName, json.text));
                }
            }
            EffectDiscriptor Efd = Eff.AddComponent <EffectDiscriptor>();

            Efd.Author      = EfdTemp.Author;
            Efd.EffectName  = EfdTemp.EffectName;
            Efd.WorksInMenu = EfdTemp.WorksInMenu;
            Efd.WorksInGame = EfdTemp.WorksInGame;
            Efd.coverImage  = Cover;
        }
Пример #6
0
 public Effect(EffectDiscriptor _effectDiscriptor, GameObject _gameObject, bool _enabled)
 {
     Desc       = _effectDiscriptor;
     gameObject = _gameObject;
     enabled    = _enabled;
 }