/// <summary> /// Custom piece from a prefab with a <see cref="PieceConfig"/> attached.<br /> /// The members and references from the <see cref="PieceConfig"/> will be referenced by Jötunn at runtime. /// </summary> /// <param name="piecePrefab">The prefab for this custom piece.</param> /// <param name="pieceConfig">The <see cref="PieceConfig"/> for this custom piece.</param> public CustomPiece(GameObject piecePrefab, PieceConfig pieceConfig) { PiecePrefab = piecePrefab; Piece = piecePrefab.GetComponent <Piece>(); PieceTable = pieceConfig.PieceTable; FixReference = true; pieceConfig.Apply(piecePrefab); }
/// <summary> /// Custom piece created as a copy of a vanilla Valheim prefab with a <see cref="PieceConfig"/> attached.<br /> /// The members and references from the <see cref="PieceConfig"/> will be referenced by Jötunn at runtime. /// </summary> /// <param name="name">The new name of the prefab after cloning.</param> /// <param name="baseName">The name of the base prefab the custom item is cloned from.</param> /// <param name="pieceConfig">The <see cref="PieceConfig"/> for this custom piece.</param> public CustomPiece(string name, string baseName, PieceConfig pieceConfig) { PiecePrefab = PrefabManager.Instance.CreateClonedPrefab(name, baseName); if (PiecePrefab) { Piece = PiecePrefab.GetComponent <Piece>(); PieceTable = pieceConfig.PieceTable; FixConfig = true; pieceConfig.Apply(PiecePrefab); } }
/// <summary> /// Custom piece created as an "empty" primitive with a <see cref="PieceConfig"/> attached.<br /> /// The members and references from the <see cref="PieceConfig"/> will be referenced by Jötunn at runtime. /// </summary> /// <param name="name">Name of the new prefab. Must be unique.</param> /// <param name="addZNetView">If true a ZNetView component will be added to the prefab for network sync.</param> /// <param name="pieceConfig">The <see cref="PieceConfig"/> for this custom piece.</param> public CustomPiece(string name, bool addZNetView, PieceConfig pieceConfig) { PiecePrefab = PrefabManager.Instance.CreateEmptyPrefab(name, addZNetView); if (PiecePrefab) { Piece = PiecePrefab.AddComponent <Piece>(); PieceTable = pieceConfig.PieceTable; FixConfig = true; pieceConfig.Apply(PiecePrefab); } }
/// <summary> /// Custom piece from a prefab loaded from an <see cref="AssetBundle"/> with a PieceConfig attached.<br /> /// Will be added to the <see cref="global::PieceTable"/> provided by name. /// </summary> /// <param name="assetBundle">A preloaded <see cref="AssetBundle"/></param> /// <param name="assetName">Name of the prefab in the bundle.</param> /// <param name="pieceConfig">The <see cref="PieceConfig"/> for this custom piece.</param> public CustomPiece(AssetBundle assetBundle, string assetName, PieceConfig pieceConfig) { var piecePrefab = (GameObject)assetBundle.LoadAsset(assetName); if (piecePrefab) { PiecePrefab = piecePrefab; Piece = piecePrefab.GetComponent <Piece>(); PieceTable = pieceConfig.PieceTable; pieceConfig.Apply(piecePrefab); } FixReference = true; }
private void AddInvalidItems() { CustomItem CI = new CustomItem("item_faulty", false); if (CI != null) { CI.ItemDrop.m_itemData.m_shared.m_icons = new Sprite[] { testSprite }; ItemManager.Instance.AddItem(CI); CustomRecipe CR = new CustomRecipe(new RecipeConfig { Item = "item_faulty", Requirements = new RequirementConfig[] { new RequirementConfig { Item = "NotReallyThereResource", Amount = 99 } } }); ItemManager.Instance.AddRecipe(CR); } CustomPiece CP = new CustomPiece("piece_fukup", "Hammer"); if (CP != null) { var piece = CP.Piece; piece.m_icon = testSprite; var prefab = CP.PiecePrefab; // Test faulty resource, do it manually cause there is no config on empty pieces atm var cfg = new PieceConfig { Requirements = new RequirementConfig[] { new RequirementConfig { Item = "StillNotThereResource", Amount = 99 } } }; cfg.Apply(prefab); CP.FixReference = true; PieceManager.Instance.AddPiece(CP); } }
// Add a custom item from an "empty" prefab private void AddEmptyItems() { CustomPiece CP = new CustomPiece("piece_lul", "Hammer"); if (CP != null) { var piece = CP.Piece; piece.m_icon = testSprite; var prefab = CP.PiecePrefab; prefab.GetComponent <MeshRenderer>().material.mainTexture = testTex; // Test station extension, do it manually cause there is no config on empty pieces atm var cfg = new PieceConfig { ExtendStation = "piece_workbench" }; cfg.Apply(prefab); CP.FixReference = true; PieceManager.Instance.AddPiece(CP); } }