public GameObject Construct(AssetReference assetRef, BundleAssetLoadingInfo bundleInfo)
        {
            var asset = BundleManager.LoadAssetFromBundle(bundleInfo, bundleInfo.SpriteName);

            if (asset.GetType() == typeof(Texture2D))
            {
                // "Type checking ew"
                // You're thinking it, I can tell.
                // Through all the horrible things we've done with this project,
                // type checking is where you draw the line?
                var tex = asset as Texture2D;
                if (tex != null)
                {
                    Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f), 128f);
                    return(CreateCardGameObject(assetRef, sprite));
                }
                return(null);
            }
            else
            {
                var gameObject = asset as GameObject;
                if (gameObject != null)
                {
                    GameObject.DontDestroyOnLoad(gameObject);
                    return(gameObject);
                }
            }
            Trainworks.Log(BepInEx.Logging.LogLevel.Warning, "Invalid asset type " + asset.GetType() + " when loading asset: " + bundleInfo.SpriteName);
            return(null);
        }
예제 #2
0
 public static void ApplyImportSettings <T>(BundleAssetLoadingInfo info, ref T @asset) where T : UnityEngine.Object
 {
     if (info.ImportSettings != null)
     {
         ((ISettings <T>)info.ImportSettings).ApplySettings(ref @asset);
     }
 }
예제 #3
0
 /// <summary>
 /// Load an asset from an asset bundle
 /// </summary>
 /// <param name="info">Loading info for the asset</param>
 /// <param name="assetName">Name of the asset to load from the bundle</param>
 /// <returns>The asset specified by the given info as a UnityEngine object</returns>
 public static UnityEngine.Object LoadAssetFromBundle(BundleAssetLoadingInfo info, string assetName)
 {
     if (LoadedAssetBundles.ContainsKey(info.FullPath))
     {
         var asset = LoadedAssetBundles[info.FullPath].LoadAsset(assetName);
         if (asset == null)
         {
             Trainworks.Log(BepInEx.Logging.LogLevel.Warning, "Custom asset: " + assetName + " failed to load from bundle: " + info.FullPath);
         }
         ApplyImportSettings(info, ref asset);
         return(asset);
     }
     Trainworks.Log(BepInEx.Logging.LogLevel.Warning, "Attempting to load asset from non-existent bundle: " + info.FullPath);
     return(null);
 }
예제 #4
0
        public static void RegisterBundle(string assetGUID, BundleAssetLoadingInfo bundleInfo)
        {
            string path = bundleInfo.FullPath;

            if (!LoadedAssetBundles.ContainsKey(path))
            {
                if (File.Exists(path))
                {
                    LoadedAssetBundles[path] = AssetBundle.LoadFromFile(path);
                }
                else
                {
                    Trainworks.Log(BepInEx.Logging.LogLevel.Warning, "Custom asset bundle failed to load from path: " + path);
                }
            }
            var runtimeKey = Hash128.Parse(assetGUID);

            RuntimeKeyToBundleInfo[runtimeKey] = bundleInfo;
        }
예제 #5
0
        public GameObject Construct(AssetReference assetRef, BundleAssetLoadingInfo bundleInfo)
        {
            // Don't recreate
            if (CharacterPrefabDictionary.ContainsKey(bundleInfo.SpriteName))
            {
                return(CharacterPrefabDictionary[bundleInfo.SpriteName]);
            }

            if (CharacterPrefabDictionary.ContainsKey(bundleInfo.ObjectName))
            {
                return(CharacterPrefabDictionary[bundleInfo.ObjectName]);
            }

            // Create a new one if one doesn't exist already
            var tex = BundleManager.LoadAssetFromBundle(bundleInfo, bundleInfo.SpriteName) as Texture2D;

            if (tex != null)
            {
                Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f), 128f);
                sprite.name = "Sprite_" + bundleInfo.SpriteName.Replace("assets/", "").Replace(".png", "");
                if (bundleInfo.ObjectName != null)
                {
                    GameObject gameObject = BundleManager.LoadAssetFromBundle(bundleInfo, bundleInfo.ObjectName) as GameObject;
                    if (gameObject != null)
                    {
                        var spineObj = CreateCharacterGameObject(assetRef, sprite, gameObject);
                        GameObject.DontDestroyOnLoad(spineObj);
                        CharacterPrefabDictionary.Add(bundleInfo.ObjectName, spineObj);
                        return(spineObj);
                    }
                }
                var charObj = CreateCharacterGameObject(assetRef, sprite);
                GameObject.DontDestroyOnLoad(charObj);
                CharacterPrefabDictionary.Add(bundleInfo.SpriteName, charObj);
                return(charObj);
            }
            Trainworks.Log(BepInEx.Logging.LogLevel.Warning, "Invalid sprite name when loading asset: " + bundleInfo.SpriteName);
            return(null);
        }
예제 #6
0
        public void Initialize()
        {
            Trainworks.Trainworks.Log("Initializing");
            Harmony harmony = new Harmony("io.github.crazyjackel.Stoker");

            harmony.PatchAll();
            Logger.Log(BepInEx.Logging.LogLevel.Info, "Initializing AssetBundle");
            //Load Assets
            var assembly = Assembly.GetExecutingAssembly();

            PluginManager.PluginGUIDToPath.TryGetValue("io.github.crazyjackel.Stoker", out basePath);
            info = new BundleAssetLoadingInfo
            {
                PluginPath = basePath,
                FilePath   = bundleName,
            };
            BundleManager.RegisterBundle(GUIDGenerator.GenerateDeterministicGUID(info.FullPath), info);
            Logger.Log(BepInEx.Logging.LogLevel.Info, "Loaded AssetBundle");

            //Instantiate then Hide Canvas
            var GameObj = BundleManager.LoadAssetFromBundle(info, assetName_Canvas) as GameObject;

            Logger.Log(BepInEx.Logging.LogLevel.Info, "Loaded Main Asset: " + GameObj.name);
            Canvas = GameObject.Instantiate(GameObj);
            DontDestroyOnLoad(Canvas);
            Canvas.SetActive(false);

            //Load Prefab to Instantiate Later
            SelectionButtonPrefab = BundleManager.LoadAssetFromBundle(info, assetName_SelectionButton) as GameObject;
            Logger.Log(BepInEx.Logging.LogLevel.Info, "Loaded Button Prefab");

            //Find local Buttons and add Listeners
            //Load Content where to add Selection Buttons
            DeckContent = Canvas.transform.Find($"{name_mainBackground}/{name_secondaryBackground}/{name_viewport}/{name_content}").gameObject;
            Logger.Log(BepInEx.Logging.LogLevel.Info, "Found Deck Content");
            CardDatabaseContent = Canvas.transform.Find($"{name_mainBackground}/{name_secondaryBackground2}/{name_viewport}/{name_content}").gameObject;
            Logger.Log(BepInEx.Logging.LogLevel.Info, "Found Card Database Content");
            RelicDatabaseContent = Canvas.transform.Find($"{name_mainBackground}/{name_secondaryBackground3}/{name_viewport}/{name_content}").gameObject;
            Logger.Log(BepInEx.Logging.LogLevel.Info, "Found Relic Database Content");
            RelicContent = Canvas.transform.Find($"{name_mainBackground}/{name_secondaryBackground4}/{name_viewport}/{name_content}").gameObject;
            Logger.Log(BepInEx.Logging.LogLevel.Info, "Found Relic Content");
            UpgradeContent = Canvas.transform.Find($"{name_mainBackground}/{name_secondaryBackground5}/{name_viewport}/{name_content}").gameObject;
            Logger.Log(BepInEx.Logging.LogLevel.Info, "Found Upgrade Content");
            UpgradeDatabaseContent = Canvas.transform.Find($"{name_mainBackground}/{name_secondaryBackground6}/{name_viewport}/{name_content}").gameObject;
            Logger.Log(BepInEx.Logging.LogLevel.Info, "Found Upgrade Database Content");

            //Get Buttons and Input Fields
            RemoveButton = Canvas.transform.Find($"{name_mainBackground}/{name_removeBackground}/{name_Button}").gameObject;
            Logger.Log(BepInEx.Logging.LogLevel.Info, "Found Remove Button");
            RemoveButton.GetComponent <Button>().onClick.AddListener(AttemptToRemoveSelectedCard);
            AddButton = Canvas.transform.Find($"{name_mainBackground}/{name_addBackground}/{name_Button}").gameObject;
            Logger.Log(BepInEx.Logging.LogLevel.Info, "Found Add Button");
            AddButton.GetComponent <Button>().onClick.AddListener(AttemptToAddSelectedCardData);
            DuplicateButton = Canvas.transform.Find($"{name_mainBackground}/{name_duplicateBackground}/{name_Button}").gameObject;
            Logger.Log(BepInEx.Logging.LogLevel.Info, "Found Duplication Button");
            DuplicateButton.GetComponent <Button>().onClick.AddListener(AttemptToDuplicateSelectedCard);
            AddRelicButton = Canvas.transform.Find($"{name_mainBackground}/{name_addRelicBackground}/{name_Button}").gameObject;
            Logger.Log(BepInEx.Logging.LogLevel.Info, "Found Add Relic Button");
            AddRelicButton.GetComponent <Button>().onClick.AddListener(AttemptToAddSelectedRelicData);
            RemoveRelicButton = Canvas.transform.Find($"{name_mainBackground}/{name_removeRelicBackground}/{name_Button}").gameObject;
            Logger.Log(BepInEx.Logging.LogLevel.Info, "Found Remove Relic Button");
            RemoveRelicButton.GetComponent <Button>().onClick.AddListener(AttemptToRemoveSelectedRelic);
            AddUpgradeButton = Canvas.transform.Find($"{name_mainBackground}/{name_addUpgradeBackground}/{name_Button}").gameObject;
            Logger.Log(BepInEx.Logging.LogLevel.Info, "Found Add Upgrade Button");
            AddUpgradeButton.GetComponent <Button>().onClick.AddListener(AttemptToUpgradeCardState);
            RemoveUpgradeButton = Canvas.transform.Find($"{name_mainBackground}/{name_removeUpgradeBackground}/{name_Button}").gameObject;
            Logger.Log(BepInEx.Logging.LogLevel.Info, "Found Remove Upgrade Button");
            RemoveUpgradeButton.GetComponent <Button>().onClick.AddListener(AttemptToRemoveUpgradeState);
            ImportButton = Canvas.transform.Find($"{name_mainBackground}/{name_importBackground}/{name_Button}").gameObject;
            Logger.Log(BepInEx.Logging.LogLevel.Info, "Found Import Button");
            ImportButton.GetComponent <Button>().onClick.AddListener(LoadFromTxtFile);
            ExportButton = Canvas.transform.Find($"{name_mainBackground}/{name_exportBackground}/{name_Button}").gameObject;
            Logger.Log(BepInEx.Logging.LogLevel.Info, "Found Export Button");
            ExportButton.GetComponent <Button>().onClick.AddListener(ExportStateToTxtFile);
            SearchBar = Canvas.transform.Find($"{name_mainBackground}/{name_searchBarBackground}/{name_searchBar}").gameObject;
            Logger.Log(BepInEx.Logging.LogLevel.Info, "Found Search Bar");
            SearchBar.GetComponent <InputField>().onValueChanged.AddListener(UpdateDatabases);
            FileNameBar = Canvas.transform.Find($"{name_mainBackground}/{name_presetNameBackground}/{name_searchBar}").gameObject;
            Logger.Log(BepInEx.Logging.LogLevel.Info, "Found File Name Bar");
            FileNameBar.GetComponent <InputField>().onValueChanged.AddListener(UpdateFileName);

            Logger.Log(BepInEx.Logging.LogLevel.Info, "Found Elements");
            //Subscribe as Client
            DepInjector.AddClient(this);
            this.Logger.LogInfo("Stoker Plugin Initialized");
        }