public PlanPiecePrefab(Piece piece) : base(piece.gameObject.name + PlannedSuffix, piece.gameObject.name, PlanHammerPieceTableName)
        {
            this.originalPiece                  = piece;
            Piece.m_name                        = Localization.instance.Localize("$item_plan_piece_name", originalPiece.m_name);
            Piece.m_description                 = Localization.instance.Localize("$item_plan_piece_description", originalPiece.m_name);
            Piece.m_resources                   = new Piece.Requirement[0];
            Piece.m_craftingStation             = null;
            Piece.m_placeEffect.m_effectPrefabs = new EffectList.EffectData[0];
            Piece.m_comfort                     = 0;
            Piece.m_canBeRemoved                = true;

            Piece.m_category                = originalPiece.m_category;
            Piece.m_groundOnly              = originalPiece.m_groundOnly;
            Piece.m_groundPiece             = originalPiece.m_groundPiece;
            Piece.m_icon                    = originalPiece.m_icon;
            Piece.m_inCeilingOnly           = originalPiece.m_inCeilingOnly;
            Piece.m_isUpgrade               = originalPiece.m_isUpgrade;
            Piece.m_haveCenter              = originalPiece.m_haveCenter;
            Piece.m_dlc                     = originalPiece.m_dlc;
            Piece.m_allowAltGroundPlacement = originalPiece.m_allowAltGroundPlacement;
            Piece.m_allowedInDungeons       = originalPiece.m_allowedInDungeons;

            this.PieceTable = PlanHammerPieceTableName;

            WearNTear wearNTear = PiecePrefab.GetComponent <WearNTear>();

            if (wearNTear == null)
            {
                wearNTear = PiecePrefab.AddComponent <WearNTear>();
            }

            wearNTear.m_noSupportWear       = true;
            wearNTear.m_noRoofWear          = false;
            wearNTear.m_autoCreateFragments = false;
            wearNTear.m_supports            = true;
            wearNTear.m_hitEffect           = new EffectList();
            wearNTear.m_destroyedEffect     = new EffectList();
            wearNTear.m_destroyNoise        = 0f;
            wearNTear.m_hitNoise            = 0f;

            PlanPiece planPieceScript = PiecePrefab.AddComponent <PlanPiece>();

            planPieceScript.originalPiece = originalPiece;
            planToOriginalMap.Add(Piece, originalPiece);
            if (logComponents)
            {
                StringBuilder sb = new StringBuilder("Components in prefab: " + PiecePrefab.name + "\n");
                sb.Append("Components in prefab: " + PiecePrefab.name + "\n");
                sb.Append($" Prefab: {PiecePrefab.name} -> {PiecePrefab.gameObject}\n");
                foreach (Component component in PiecePrefab.GetComponents <Component>())
                {
                    sb.Append($" {component.GetType()} -> {component.name}\n");
                }
                Jotunn.Logger.LogWarning(sb.ToString());
            }

            DisablePiece(PiecePrefab);
        }
 /// <summary>
 ///     Custom piece created as an "empty" primitive.<br />
 ///     Will be added to the <see cref="global::PieceTable"/> provided by name.
 /// </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 = "pieceTable" >
 ///     Name of the <see cref="global::PieceTable"/> the custom piece should be added to.
 ///     Can by the "internal" or the <see cref="GameObject"/>s name (e.g. "_PieceTableHammer" or "Hammer")
 /// </param>
 public CustomPiece(string name, bool addZNetView, string pieceTable)
 {
     PiecePrefab = PrefabManager.Instance.CreateEmptyPrefab(name, addZNetView);
     if (PiecePrefab)
     {
         Piece        = PiecePrefab.AddComponent <Piece>();
         Piece.m_name = name;
     }
     PieceTable = pieceTable;
 }
        /// <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);
            }
        }
Exemple #4
0
        //TODO: constructors for cloned / empty prefabs with configs.


        /// <summary>
        ///     Custom piece created as an "empty" primitive.<br />
        ///     Will be added to the <see cref="global::PieceTable"/> provided by name.<br />
        ///     At least the name and the icon of the ItemDrop must be edited after creation.
        /// </summary>
        /// <param name="name">Name of the new prefab. Must be unique.</param>
        /// <param name = "pieceTable" >
        ///     Name of the <see cref="global::PieceTable"/> the custom piece should be added to.
        ///     Can by the "internal" or the <see cref="GameObject"/>s name (e.g. "_PieceTableHammer" or "Hammer")
        /// </param>
        /// <param name="addZNetView">If true a ZNetView component will be added to the prefab for network sync.</param>
        public CustomPiece(string name, string pieceTable, bool addZNetView = true)
        {
            PiecePrefab = PrefabManager.Instance.CreateEmptyPrefab(name, addZNetView);
            if (PiecePrefab)
            {
                Piece = PiecePrefab.AddComponent <Piece>();
                if (name[0] != LocalizationManager.TokenFirstChar)
                {
                    Piece.m_name = LocalizationManager.TokenFirstChar + name;
                }
                else
                {
                    Piece.m_name = name;
                }
            }
            PieceTable = pieceTable;
        }