private void SetLocalTransform(ModularPiece piece) { if (piece != null) { // set rotation Vector3 EulerAngles = new Vector3(0, piece.transform.eulerAngles.y, 0); // unparent local grid center GridCenterHolder.transform.SetParent(null); // unparent all objects foreach (ModularPiece p in Pieces) { p.transform.SetParent(null); } // make local adjustments this.NoneOffsettedRotation = Quaternion.Euler(EulerAngles); // reparent childs foreach (ModularPiece p in Pieces) { p.transform.SetParent(transform); } // reparent local grid center GridCenterHolder.transform.SetParent(transform); } }
public void PlaceNewModularPiece(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) { ModularPlacableObject NewPlacableObject = (ModularPlacableObject)InitStoreItem(Piece, Scale, RotationOffset, InitRotation, InitPosition); 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 GameManager.I.Modular.ScopedSet.AddModularPiece(PlacedPiece); // place new modular piece with last rotation PlaceNewModularPiece(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 Statemachine.changeState(new ModularSpectate(), this); }, SnapTypes.Default, ExtraData, Interrupt); // place new created store modular piece GameManager.I.Modular.ScopedSet.RegisterPlacingObject(NewPlacableObject); // register new placable object to be placed inside building }
public void RenderProperty(string[] VarNames, bool[] Dependencies, string[] Titles, string[] Tooltips, RenderGUI[] OnRenders) { for (int i = 0; i < VarNames.Length; i++) { if (Dependencies [i]) // should render { object val = Piece.GetVariableValue <object>(VarNames[i]); // value of var OnRenders[i] (val, new GUIContent(Titles[i], Tooltips[i]), (returned) => { if (GUI.changed) { for (int x = 0; x < targets.Length; x++) // set pieces { Modular.ModularPiece piece = (Modular.ModularPiece)targets[x]; piece.SetVariableValue <object>(VarNames[i], returned); } } }); // on render if (ShowHelp) { EditorGUILayout.HelpBox(Tooltips[i], MessageType.Info); } } } }
public override ModularPlacableObject Duplicate() { ModularPiece DuplicatedPiece = (ModularPiece)base.Duplicate(); DuplicatedPiece.Initialize(ParentSet); // initialize modular set DuplicatedPiece.InitializeID(ID); DuplicatedPiece.InitializeTextureData(this.CurrentTextureKeys); DuplicatedPiece.InitializeColors(this.Colors); this.ParentSet.AddModularPiece(DuplicatedPiece); // add duplicated piece to modular sets DuplicatedPiece.RegisterUndoable(); return(DuplicatedPiece); }
public AxisBounds GetBoundaryIncludingPiece(ModularPiece Piece) { if (OriginPiece == null) { return(Piece.Bounds); } TempBounds = new AxisBounds(Bounds, false); TempBounds.LastMax = Bounds.LastMax; TempBounds.LastMin = Bounds.LastMin; TempBounds.LocalEncapsulate(Piece.Bounds); return(TempBounds); }
public ModularPiece InitStoreItem(ModularPieceSaveData PieceSaveData) { ModularPieceData PieceData = GameManager.I.Modular.FindPiece(PieceSaveData.ID); // find modular piece if (PieceData != null) { ModularPiece piece = InitStoreItem(PieceData, PieceSaveData.LocalScale, Vector3.zero, PieceSaveData.LocalEulerAngles, PieceSaveData.LocalPosition); piece.InitializeTextureData(PieceSaveData.TextureDataKeys); piece.InitializeColors(PieceSaveData.Colors); // initialize colors return(piece); } return(null); }
public ModularPieceSaveData(ModularPiece Piece) : base(Piece) { this.ID = Piece.ID; TextureDataKeys = Piece.CurrentTextureKeys; if (Piece.Colors.Length > 0) { Colors = new Color[Piece.Colors.Length]; for (int i = 0; i < Piece.Colors.Length; i++) { Colors [i] = Piece.Colors [i].Color; } } }
// publics public void AddModularPiece(ModularPiece piece) { piece.transform.SetParent(transform); // reparent piece _Pieces.Add(piece); // add piece to set if (OriginPiece == piece) // just added origin piece { CalculateGridCenter(); // calculate grid center } UpdatePieceRestrictions(piece); // add modular piece restriction UpdateModularSet(); // update modular set AddModularPieceRenderer(piece); // add to render set }
private ReorderableList RenderList(Modular.ModularPiece Data) { ReorderableList List = new ReorderableList(Data.TextureArrays, typeof(ModularTextureArray.ModularTextureArraySetting), true, true, true, true); List.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, "Texture Arrays"); }; List.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { if (Data.TextureArrays[index].TextureArray != null) { float Width = rect.width; float ThreeFourth = Width * 0.75f; // draw int slider float HalfOfHalf = ThreeFourth * 0.5f; int Max = Data.TextureArrays[index].TextureArray.Textures.Count - 1; EditorGUI.LabelField(new Rect( rect.position.x, rect.position.y, HalfOfHalf, rect.height ), index + ": " + Data.TextureArrays[index].TextureArray.Textures[Data.TextureArrays[index].DefaultIndex].Name); Data.TextureArrays[index].DefaultIndex = EditorGUI.IntSlider(new Rect( rect.position.x + HalfOfHalf, rect.position.y, HalfOfHalf, rect.height ), Data.TextureArrays[index].DefaultIndex, 0, Max); // Draw texture array input Data.TextureArrays[index].TextureArray = (ModularTextureArray)EditorGUI.ObjectField(new Rect( rect.position.x + ThreeFourth, rect.position.y, Width * 0.25f, rect.height ), Data.TextureArrays[index].TextureArray, typeof(ModularTextureArray), false); } else { Data.TextureArrays[index].TextureArray = (ModularTextureArray)EditorGUI.ObjectField(rect, Data.TextureArrays[index].TextureArray, typeof(ModularTextureArray), false); } rect.y += 2; }; return(List); }
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 bool RemoveModularPiece(ModularPiece piece) { if (OriginPiece == piece) // removing origin piece from pieces { _Pieces.Remove(piece); // remove piece from pieces CalculateGridCenter(); // calculate grid center } else { _Pieces.Remove(piece); // remove piece from pieces } if (!Editing && _Pieces.Count == 0) { Destroy(); return(false); } // destroy self UpdateRestrictions(); // update all restrictions UpdateModularSet(); return(true); }
public ModularPiece InitStoreItem(ModularPieceData Piece, Vector3 Scale, Vector3 RotationOffset = default(Vector3), Vector3 InitRotation = default(Vector3), Vector3 InitPosition = default(Vector3)) { if (Piece != null) { GameObject obj = Piece.Prefab; // pick base object // instantiate item ModularPiece piece = GameObject.Instantiate(obj, InitPosition, Quaternion.identity).GetComponent <ModularPiece> (); piece.gameObject.name = Piece.Name; piece.InitializeID(Piece.Key); piece.InitializeTextureData(); piece.InitializeColors(); piece.transform.localScale = Scale; piece.transform.localPosition = InitPosition; piece.NoneOffsettedRotation = Quaternion.Euler(InitRotation); // set rotation with rotation property piece.RotationOffset = Quaternion.Euler(RotationOffset); // set rotation offset piece.Initialize(GameManager.I.Modular.ScopedSet); // initialize piece data return(piece); } return(null); }
public void AddModularPiece(ModularPiece piece, ModularPlacableData Trans) { piece.Initialize(this); // initialize piece cause isnt placed by system piece.transform.SetParent(transform); // reparent piece _Pieces.Add(piece); // add piece to set piece.LocalPosition = Trans.LocalPosition; piece.transform.localEulerAngles = Trans.LocalEulerAngles; piece.transform.localScale = Trans.LocalScale; AddModularPieceRenderer(piece); // add to render set UpdatePieceRestrictions(piece); // add modular piece restriction if (Editing) { piece.InitializeEditable(); } else { piece.InitializePlaced(Management.GameManager.I.Modular.ModularPieceLayer); piece.OnPlaced(); } // if is in editing mode, initialize as editable piece }
public override void OnInspectorGUI() { Piece = (Modular.ModularPiece)target; // target Modular.ModularPiece[] Pieces = new Modular.ModularPiece[targets.Length]; RenderHeader("Modular piece boundary settings"); RenderProperty <Vector3, Modular.ModularPiece> ("BoundSize", "Boundary size", "The Bound size variable determins the boundary extends of the modular piece. Make sure this value is as close as possible to the origional shape of the mesh.", (val, GUIContent, returnCallback) => { returnCallback.Invoke((Vector3)EditorGUILayout.Vector3Field(GUIContent, (Vector3)val)); }); RenderProperty <Vector3, Modular.ModularPiece> ("BoundsOffset", "Boundary offset", "The Bounds offset variable determines how much the center of the boundary should be offsetted compared to the pivot of the modular piece.", (val, GUIContent, returnCallback) => { returnCallback.Invoke((Vector3)EditorGUILayout.Vector3Field(GUIContent, (Vector3)val)); }); RenderProperty <bool, Modular.ModularPiece> ("AlignableItem", "Alignable Object", "Can other objects align to this object. If turn to false when fast placing items, they will pass through this object", (val, GUIContent, returnCallback) => { returnCallback.Invoke((bool)EditorGUILayout.Toggle(GUIContent, (bool)val)); }); RenderHeader("Modular piece global settings"); RenderProperty <Modular.ModularPiece.DirectionTypes, Modular.ModularPiece> ("UpDirection", "Up Direction", "The up direction variable determins what side of the object is Up. For example when aligning a object to a surface normal the up axis will determine what side is up.", (val, GUIContent, returnCallback) => { returnCallback.Invoke((Modular.ModularPiece.DirectionTypes)EditorGUILayout.EnumPopup(GUIContent, (Modular.ModularPiece.DirectionTypes)val)); }); RenderProperty <Modular.SnapTypes, Modular.ModularPiece> ("GridSnapType", "Grid Snap Type", "The Grid snaptype variable determins the snap type to use by default for this modular piece. Center aligns to the center. Edge alignes to the edges of the grid and freeform doesnt align. Default takes the default snap type of this modular piece.", (val, GUIContent, returnCallback) => { returnCallback.Invoke((Modular.SnapTypes)EditorGUILayout.EnumPopup(GUIContent, (Modular.SnapTypes)val)); }); RenderProperty <Modular.ModularPiece.GridCutTypes, Modular.ModularPiece> ("GridCutType", "Grid Cut Type", "Determines wheter an object should cut out of the grid or not", (val, GUIContent, returnCallback) => { returnCallback.Invoke((Modular.ModularPiece.GridCutTypes)EditorGUILayout.EnumPopup(GUIContent, (Modular.ModularPiece.GridCutTypes)val)); }); RenderProperty <Modular.ModularPiece.GridCutTypes, Modular.ModularPiece> ("GrassCutType", "Grass Cut Type", "Determines wheter an object should cut out of the grass or not", (val, GUIContent, returnCallback) => { returnCallback.Invoke((Modular.ModularPiece.GridCutTypes)EditorGUILayout.EnumPopup(GUIContent, (Modular.ModularPiece.GridCutTypes)val)); }); RenderHeader("Modular piece grid settings"); RenderProperty( new string[] { "RealMaxSize", "CustomRealMaxSize" }, new bool[] { true, (Piece.RealMaxSize == Modular.SnapAxis.Custom) }, new string[] { "Real Max Size: " + Piece.RealScale, "Custom size" }, new string[] { "The real max size variable determins the real maximal size of this object. You can pick a bounds axis or set a custom size.", "Sets the custom maximal size of this object" }, new RenderGUI[] { (val, context, returncall) => { returncall((Modular.SnapAxis)EditorGUILayout.EnumPopup(context, (Modular.SnapAxis)val)); }, (val, context, returncall) => { returncall((float)EditorGUILayout.Slider((float)val, 0, (Piece.BoundSize.GetHighestAxis() * 2))); } } ); RenderProperty( new string[] { "GridMaxSize", "CustomMaxSize" }, new bool[] { true, (Piece.GridMaxSize == Modular.SnapAxis.Custom) }, new string[] { "Grid Max size: " + Piece.Scale, "Custom size" }, new string[] { "The grid max variable determins the maximal grid size of this object. You can pick a bounds axis or set a custom size.", "Sets the custom maximal size of this object" }, new RenderGUI[] { (val, context, returncall) => { returncall((Modular.SnapAxis)EditorGUILayout.EnumPopup(context, (Modular.SnapAxis)val)); }, (val, context, returncall) => { returncall((float)EditorGUILayout.Slider((float)val, 0, (Piece.BoundSize.GetHighestAxis() * 2))); } } ); RenderProperty( new string[] { "GridMinSize", "CustomMinSize" }, new bool[] { true, (Piece.GridMinSize == Modular.SnapAxis.Custom) }, new string[] { "Grid Min size: " + Piece.MinScale, "Custom size" }, new string[] { "The grid min variable determins the minimal grid size of this object. You can pick a bounds axis or set a custom size.", "Sets the custom minimal size of this object" }, new RenderGUI[] { (val, context, returncall) => { returncall((Modular.SnapAxis)EditorGUILayout.EnumPopup(context, (Modular.SnapAxis)val)); }, (val, context, returncall) => { returncall((float)EditorGUILayout.Slider((float)val, 0, (Piece.BoundSize.GetHighestAxis() * 2))); } } ); RenderHeader("Texture Array Settings"); RenderProperty <bool, Modular.ModularPiece> ("UseTextureArray", "Use Texture Array", "Determines if you want to use a texture array or not", (val, GUIContent, returnCallback) => { returnCallback.Invoke((bool)EditorGUILayout.Toggle(GUIContent, (bool)val)); }); if (Piece.UseTextureArray) { EditorGUILayout.Space(); for (int i = 0; i < TextureList.Count; i++) { serializedObject.Update(); TextureList [i].DoLayoutList(); serializedObject.ApplyModifiedProperties(); } } else { GUILayout.Space(Space); } RenderHeader("Auto settings", false); #region Toggle help button if (GUILayout.Button(new GUIContent("Auto generate piece", "Auto generates all values and auto fills the render set"), GUILayout.Width(200))) { for (int i = 0; i < targets.Length; i++) { Modular.ModularPiece piece = (Modular.ModularPiece)targets[i]; piece.AutoFillRenderSet(); // auto calc values piece.AutoCalculateValues(); // auto calc values } } RenderHeader("Extra settings"); if (GUILayout.Button(new GUIContent("Auto calculate values", "Auto calculate all values of the modular piece. Like boundsize, min, max,etc..."), GUILayout.Width(200))) { for (int i = 0; i < targets.Length; i++) { Modular.ModularPiece piece = (Modular.ModularPiece)targets[i]; piece.AutoCalculateValues(); // auto calc values } } if (GUILayout.Button(new GUIContent("Auto fill RenderSet", "Auto fills the render set"), GUILayout.Width(200))) { for (int i = 0; i < targets.Length; i++) { Modular.ModularPiece piece = (Modular.ModularPiece)targets[i]; piece.AutoFillRenderSet(); // auto calc values } } if (GUILayout.Button(new GUIContent((!ShowHelp)?"Show help boxes":"Hide help boxes", "Toggles the help windows"), GUILayout.Width(200))) { ShowHelp = !ShowHelp; } #endregion SceneView.RepaintAll(); // repait scene }
public void AddModularPieceRenderer(ModularPiece Piece) { RenderSet.AddRenderObject(Piece.RenderSet); }
} // 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 ModularPlacableData(ModularPiece ModularObject) { this.LocalPosition = ModularObject.LocalPosition; this.LocalScale = ModularObject.transform.localScale; this.LocalEulerAngles = ModularObject.transform.localEulerAngles; }
public void PlaceModularPiece(ModularPiece Piece, Delegates.GenericDataCallbak PlacedCallback, System.Action <object[]> OnCanceled, System.Func <ModularPlacableObject, bool> CanPlace) { PlaceModularPlacable((ModularPlacableObject)Piece, PlacedCallback, CanPlace, OnCanceled); }
private void OnEnable() { Modular.ModularPiece TempData = (Modular.ModularPiece)target; TextureList.Clear(); TextureList.Add(RenderList(TempData)); }