Veilheim/Blueprints/Blueprint.cs
/// <summary>
///     Instantiate plan prefabs for all distinct pieces in this blueprint.
/// </summary>
/// <returns></returns>
Instantiate plan prefabs for all distinct pieces in this blueprint.
Instantiate plan prefabs for all distinct pieces in this blueprint .
private bool PlanInstantiate()
        {
            var ret = true;
            try
            {
                var pieces = new List<PieceEntry>(m_pieceEntries);
                var prefabs = new Dictionary<string, GameObject>();
                foreach (var piece in pieces.GroupBy(x => x.name).Select(x => x.FirstOrDefault()))
                {
                    string planPrefabName = $"{piece.name}_planned";
                    if (PrefabManager.Instance.GetPrefab(planPrefabName))
                    {
                        continue;
                    }
                    GameObject oldPrefab = PrefabManager.Instance.GetPrefab(piece.name);
                    Piece oldPiece = oldPrefab.GetComponent<Piece>();
                    GameObject newPrefab = PrefabManager.Instance.CreateClonedPrefab(planPrefabName, oldPrefab);
                    foreach (var component in newPrefab.GetComponentsInChildren<MonoBehaviour>())
                    {
                        Object.Destroy(component);
                    }
                    ZNetView zNetView = newPrefab.AddComponent<ZNetView>();
                    zNetView.m_persistent = true;
                    Piece newPiece = newPrefab.AddComponent<Piece>();
                    newPiece.m_name = $"Planned {oldPiece.m_name}";
                    newPiece.m_resources = new Piece.Requirement[0];
                    newPiece.m_craftingStation = null;
                    newPiece.m_placeEffect.m_effectPrefabs = new EffectList.EffectData[0];
                    newPiece.m_comfort = 0;
                    newPiece.m_canBeRemoved = true;
                    WearNTear wearNTear = newPrefab.AddComponent<WearNTear>();
                    wearNTear.m_noSupportWear = true;
                    wearNTear.m_noRoofWear = false;
                    wearNTear.m_autoCreateFragments = false;
                    wearNTear.m_supports = true;
                    wearNTear.m_hitEffect = new EffectList();
                    PlanPiece planPieceScript = newPrefab.AddComponent<PlanPiece>();
                    planPieceScript.originalPiece = oldPiece;
                    PrefabManager.Instance.AddPrefab(newPrefab);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError($"Error while instantiating: {ex}");
                ret = false;
            }
            return ret;
        }
private bool PlanInstantiate ( ) { var ret = true ; try { var pieces = new List < PieceEntry > ( m_pieceEntries ) ; var prefabs = new Dictionary < string , GameObject > ( ) ; foreach ( var piece in pieces . GroupBy ( x => x . name ) . Select ( x => x . FirstOrDefault ( ) ) ) { string planPrefabName = $" { piece . name } _planned " ; if ( PrefabManager . Instance . GetPrefab ( planPrefabName ) ) { continue ; } GameObject oldPrefab = PrefabManager . Instance . GetPrefab ( piece . name ) ; Piece oldPiece = oldPrefab . GetComponent < Piece > ( ) ; GameObject newPrefab = PrefabManager . Instance . CreateClonedPrefab ( planPrefabName , oldPrefab ) ; foreach ( var component in newPrefab . GetComponentsInChildren < MonoBehaviour > ( ) ) { Object . Destroy ( component ) ; } ZNetView zNetView = newPrefab . AddComponent < ZNetView > ( ) ; zNetView . m_persistent = true ; Piece newPiece = newPrefab . AddComponent < Piece > ( ) ; newPiece . m_name = $" Planned  { oldPiece . m_name } " ; newPiece . m_resources = new Piece . Requirement [ 0 ] ; newPiece . m_craftingStation = null ; newPiece . m_placeEffect . m_effectPrefabs = new EffectList . EffectData [ 0 ] ; newPiece . m_comfort = 0 ; newPiece . m_canBeRemoved = true ; WearNTear wearNTear = newPrefab . AddComponent < WearNTear > ( ) ; wearNTear . m_noSupportWear = true ; wearNTear . m_noRoofWear = false ; wearNTear . m_autoCreateFragments = false ; wearNTear . m_supports = true ; wearNTear . m_hitEffect = new EffectList ( ) ; PlanPiece planPieceScript = newPrefab . AddComponent < PlanPiece > ( ) ; planPieceScript . originalPiece = oldPiece ; PrefabManager . Instance . AddPrefab ( newPrefab ) ; } } catch ( Exception ex ) { Logger . LogError ( $" Error while instantiating:  { ex } " ) ; ret = false ; } return ret ; }
Instantiate plan prefabs for all distinct pieces in this blueprint.
Instantiate plan prefabs for all distinct pieces in this blueprint .
// Get all distinct pieces and create plan versions // Check if plan prefab already exists // Clone vanilla prefab // A plan doesn't need fancy scripts // Except the basics // Also add our PlanPiece script // Add to known prefabs
None