public ModularSet InitNewModularSet(Vector3 InitPosition, Quaternion InitRotation, Vector3 InitScale)
        {
            ModularSet NewSet = InitNewModularSet();              // init new set

            NewSet.transform.localPosition = InitPosition;
            NewSet.transform.localScale    = InitScale;
            NewSet.NoneOffsettedRotation   = InitRotation;
            return(NewSet);
        }
Esempio n. 2
0
 public ModularSetData(ModularSet Set)
 {
     Transform               = new ModularPlacableData(Set.transform.position, Set.transform.rotation.eulerAngles, Set.transform.localScale); // init transform
     this.Pieces             = Set.PieceData;                                                                                                 // set pieces data
     this.SetName            = Set.Name;
     this._Price             = 0;
     this.BoundSize          = Set.Bounds.size;
     this.LocalGridCenter    = Set.LocalGridCenter;
     this.BoundsCenterOffset = Set.BoundsCenterOffset;
 }
        public ModularSet InitNewModularSet(ModularSet ValueReference)
        {
            ModularSet NewSet = InitNewModularSet();              // init new set

            NewSet.Position              = ValueReference.Position;
            NewSet.RotationOffset        = ValueReference.RotationOffset;
            NewSet.NoneOffsettedRotation = ValueReference.NoneOffsettedRotation;
            NewSet.transform.rotation    = ValueReference.transform.rotation;
            NewSet.transform.localScale  = ValueReference.transform.localScale;
            return(NewSet);
        }
        public override ModularPlacableObject Duplicate()
        {
            ModularSetStoreData SetData = new ModularSetStoreData(this);
            ModularSet          NewSet  = Management.GameManager.I.Modular.ModularBuildingSystem.InitNewModularSet(this);

            NewSet.AsyncLoadModularSet(SetData, (object[] Data) => {
                ModularSet Set = (ModularSet)Data[0];                                                                                                 // get set data
                ModularPieceSaveData PieceData = (ModularPieceSaveData)Data[1];                                                                       // get piece data
                Set.AddModularPiece(Management.GameManager.I.Modular.ModularBuildingSystem.InitStoreItem(PieceData), (ModularPlacableData)PieceData); // add store item
            });
            NewSet.gameObject.layer = this.gameObject.layer;                                                                                          // set layer
            NewSet.RegisterUndoable();                                                                                                                // register as undoable
            return(NewSet);
        }
Esempio n. 5
0
 public void AutoStack(StackTypes StackType, ModularSet ParentSet)
 {
     if (StackType != StackTypes.Disabled)
     {
         if (GridPosChanged)                   // only stack if grid pos has changed
         {
             while (AutoStackSingle(ParentSet.OverlappingPieces(this, (StackType == StackTypes.Boundary) ? null : (float?)this.MinScale, true)))
             {
             }                         // stack until stacking is no longer possible
             _LastStackY = Position.y; // set last stack position
         }
         else
         {
             PlaceAtPos(new Vector3(Position.x, _LastStackY, Position.z), Vector3.zero, false);                    // place at position. Dont update last grid position. It will override the actual last grid position to the free from one
         }
     }
 }
        private ModularSet InitModularSetCore(ModularSet NewSet, ModularSetData SetData, bool InitInEditMode = false)
        {
            if (InitInEditMode)
            {
                NewSet.InitializeEditable();
            }                                                                   // init in edit mode
            NewSet.AsyncLoadModularSet(SetData, (object[] Data) => {
                ModularSet Set = (ModularSet)Data[0];                           // get set data
                ModularPieceSaveData PieceData = (ModularPieceSaveData)Data[1]; // get piece data

                ModularPiece Piece = InitStoreItem(PieceData);                  // init store item to modular piece
                if (Piece != null)                                              // only add when piece is not null
                {
                    Set.AddModularPiece(Piece, (ModularPlacableData)PieceData); // add store item
                }
            });
            return(NewSet);
        }         // core function for init modular set
        public void PlaceModularPieceAsSet(ModularPieceData Piece, Vector3 Scale, System.Func <ModularPlacableObject, bool> CanPlace, Vector3 RotationOffset = default(Vector3), Vector3 InitRotation = default(Vector3), Vector3 InitPosition = default(Vector3), object[] ExtraData = default(object[]), bool Interrupt = false)
        {
            ModularSet Set = InitNewModularSet();                                                                                                     // create new modular set

            Set.InitializeEditable();                                                                                                                 // init as editable
            GameManager.I.Modular.ScopedSet = Set;                                                                                                    // set new scoped set
            ModularPlacableObject NewPlacableObject = (ModularPlacableObject)InitStoreItem(Piece, Scale, RotationOffset, InitRotation, InitPosition); // init modular piece afther setting the scoped set

            PlaceModularPlacable(NewPlacableObject, (object[] data) => {
                // on object is placed
                ModularPiece PlacedPiece  = (ModularPiece)data.Find <ModularPiece>();                                                                  // get modular piece
                LocalGridSystem LocalGrid = (LocalGridSystem)data.Find <LocalGridSystem>();                                                            // get last local grid
                PlacePlacableObject.PlaceObjectCache Cache = (PlacePlacableObject.PlaceObjectCache)data.Find <PlacePlacableObject.PlaceObjectCache>(); // get last state cache
                PlacedPiece.InitializeEditable();                                                                                                      // initialize editable modular piece
                PlacedPiece.OnPlaced();                                                                                                                // call on placed callback

                // Economy
                int Price = GameManager.I.Economy.EvaluateModularPiece(Piece);
                GameManager.I.Economy.RemoveMoney(Price);
                GameManager.I.Economy.SpawnMoneyIndicator(PlacedPiece.transform.position, Price);

                // add piece to set
                Set.AddModularPiece(PlacedPiece);
                Set.Name = PlacedPiece.name;
                Set.FinalizeSet(GameManager.I.Modular.ModularPieceLayer, true);                 // finalize set

                // place new modular piece with last rotation
                PlaceModularPieceAsSet(Piece, Scale, CanPlace, PlacedPiece.RotationOffset.eulerAngles, PlacedPiece.NoneOffsettedRotation.eulerAngles, PlacedPiece.transform.position, new object[] { LocalGrid, Cache });
            }, CanPlace, (Data) => {
                // on canceled
                GameManager.I.Modular.ScopedSet.DeregisterPlacingObject();       // de register object
                ModularPlacableObject PlacableObject = (ModularPlacableObject)Data.Find <ModularPlacableObject>();
                PlacableObject.Destroy();                                        // destroy on cancle
                Set.FinalizeSet(GameManager.I.Modular.ModularPieceLayer, false); // finalize set

                Statemachine.changeState(new ModularSpectate(), this);
            }, SnapTypes.Default, ExtraData, Interrupt);          // place new created store modular piece
            Set.RegisterPlacingObject(NewPlacableObject);         // register new placable object to be placed inside building
        }
        }         // core function for init modular set

        public bool StrokeModularPlacable(ModularPieceData PieceData, System.Action <ModularPlacableObject> OnPlaced, System.Func <int, bool> CanPlace)
        {
            if (PieceData != null)
            {
                // init new modular set
                GameManager.I.Modular.ScopedSet = InitNewModularSet();
                GameManager.I.Modular.ScopedSet.InitializeEditable();

                // place
                HashSet <ModularSet> AffectedSets = new HashSet <ModularSet> ();
                if (PieceData.Prefab != null && PieceData.Prefab.GetComponent <StrokeModularPiece> () != null)
                {
                    StrokeModularPiece   StrokePiece = PieceData.Prefab.GetComponent <StrokeModularPiece> (); // get stroke piece from prefab
                    ModularStrokeSetData StrokeSet   = GameManager.I.Modular.FindStrokeSet(PieceData.Key);
                    if (StrokeSet != null)                                                                    // if there is found a strokeset
                    {
                        return(StrokeModularPlacable(PieceData, (ModularPlacableObject Placable) => {         // on deleted
                            if (typeof(ModularPiece).IsAssignableFrom(Placable.GetType()))
                            {
                                ModularPiece Piece = (ModularPiece)Placable;
                                ModularSet ParentSet = Piece.ParentSet;
                                if (ParentSet != null)
                                {
                                    bool NotDestoryed = ParentSet.RemoveModularPiece(Piece);                   // remove piece from set
                                    if (!AffectedSets.Contains(ParentSet))                                     // add set to affected sets
                                    {
                                        AffectedSets.Add(ParentSet);
                                    }
                                    else if (!NotDestoryed)
                                    {
                                        AffectedSets.Remove(ParentSet);
                                    }
                                }
                            }
                        }, OnPlaced, (object[] Data) => {                     // on cancel
                            if (!AffectedSets.Contains(GameManager.I.Modular.ScopedSet))
                            {
                                AffectedSets.Add(GameManager.I.Modular.ScopedSet);
                            }
                            foreach (ModularSet Set in AffectedSets)
                            {
                                Set.FinalizeSet(Management.GameManager.I.Modular.ModularPieceLayer);
                            }                            // Update render sets of affected modular sets
                            Statemachine.changeState(new ModularSpectate(), this);
                        }, (StrokeType Type) => {        // return information
                            return StrokeSet.FindStrokePieceComponent(Type);
                        }, (StrokeType Type) => {        // return new instance
                            ModularPieceData Piece = StrokeSet.FindPiece(Type);
                            if (Piece == null)
                            {
                                Piece = PieceData;
                            }
                            var Object = InitStoreItem(Piece, Vector3.one);
                            Object.InitializeEditable();
                            GameManager.I.Modular.ScopedSet.AddModularPiece(Object);                             // add piece to set
                            return Object;
                        }, CanPlace));
                    }
                }
            }
            return(false);
        }
 public ModularSet InitModularSet(ModularSetData SetData, ModularSet ReferenceSet, bool InitInEditMode = false)
 {
     return(InitModularSetCore(InitNewModularSet(ReferenceSet), SetData, InitInEditMode));
 }
 public void PlaceModularSet(ModularSet ModularSet, Delegates.GenericDataCallbak PlacedCallback, System.Action <object[]> OnCanceled, System.Func <ModularPlacableObject, bool> CanPlace, object[] ExtraData = default(object[]), bool Interrupt = false)
 {
     PlaceModularPlacable((ModularPlacableObject)ModularSet, PlacedCallback, CanPlace, OnCanceled, SnapTypes.Default, ExtraData, Interrupt);
 }
 public void Initialize(ModularSet Set)
 {
     this._ParentSet = Set;
 }
Esempio n. 12
0
 public ModularSetStoreData(ModularSet Set, Texture2D Image) : base(Set)
 {
     this._Image      = Image.ToSprite();        // convert image to sprite
     this.Base64Image = Image.ToBase64();        // convert image to base 64
 }
Esempio n. 13
0
 public ModularSetStoreData(ModularSet Set) : base(Set)
 {
 }