public void AsyncLoadModularSet(ModularSetData SetData, Utils.Delegates.GenericDataCallbak InitModularPiece) { // set base settings this.gameObject.name = SetData.SetName; this._BoundsCenterOffset = SetData.BoundsCenterOffset; // set center offset this.Bounds = new AxisBounds((transform.position + _BoundsCenterOffset).ToWorldRotationFull(Bounds.LocalTransRotation, Bounds.LocalTransPosition), SetData.BoundSize, this.transform, false); this.GridCenterHolder.transform.localPosition = SetData.LocalGridCenter; // init modular pieces StartCoroutine(AsyncLoadPieces(SetData, InitModularPiece)); // start load coroutinte }
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
private IEnumerator AsyncLoadPieces(ModularSetData SetData, Utils.Delegates.GenericDataCallbak InitModularPiece) { int FramesWait = Mathf.CeilToInt((float)(SetData.Pieces.Length / Management.GameManager.I.Modular.LoadingFrameDuration)); int count = FramesWait; for (int i = 0; i < SetData.Pieces.Length; i++) { ModularPieceSaveData Piece = SetData.Pieces [i]; InitModularPiece.Invoke(new object[] { this, Piece }); // invoke callback with piece and current set count--; if (count <= 0) { count = FramesWait; yield return(null); } } // is done with loading AutoFillRenderSet(); // auto fill }
public ModularSet InitModularSet(ModularSetData SetData, ModularSet ReferenceSet, bool InitInEditMode = false) { return(InitModularSetCore(InitNewModularSet(ReferenceSet), SetData, InitInEditMode)); }
public ModularSet InitModularSet(ModularSetData SetData, Vector3 InitPosition, Quaternion InitRotation, Vector3 InitScale, bool InitInEditMode = false) { return(InitModularSetCore(InitNewModularSet(InitPosition, InitRotation, InitScale), SetData, InitInEditMode)); }
// private voids public ModularSet InitModularSet(ModularSetData SetData, bool InitInEditMode = false) { return(InitModularSet(SetData, SetData.Transform.LocalPosition, Quaternion.Euler(SetData.Transform.LocalEulerAngles), SetData.Transform.LocalScale, InitInEditMode)); }