public bool StrokeModularPlacable(StrokeModularPiece Piece, ModularStrokeSetData SetData) { List <object> GenData = new List <object> (); GenData.Add(this); GenData.Add(Piece); GenData.Add(SetData); Statemachine.changeState(new StrokePlacableObject(), GenData); // change to stroke placable object return(true); }
} // 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); }