private void UpdatePieceRestrictions(ModularPlacableObject Placable)
        {
            PositionRestriction     = ((int)PositionRestriction < (int)Placable.PositionRestriction)?Placable.PositionRestriction:PositionRestriction;       // position restrictions
            Scalable                = (!Placable.Scalable)?Placable.Scalable:Scalable;                                                                       // scaling restriction
            RotationStepRestriction = (Placable.RotationStepRestriction > RotationStepRestriction)?Placable.RotationStepRestriction:RotationStepRestriction; // rotation step restrictions
            RotationRestriction     = ((int)RotationRestriction < (int)Placable.RotationRestriction)?Placable.RotationRestriction:RotationRestriction;       // Rotation restrictions
            SpaceRestriction        = ((int)SpaceRestriction < (int)Placable.SpaceRestriction)?Placable.SpaceRestriction:SpaceRestriction;                   // Space restrictions

            if (Placable.PositionRestriction != PositionRestrictions.None)
            {
                PositionGridRestriction = (PositionGridRestriction < Placable.Scale) ? Placable.Scale : PositionGridRestriction;                 // set position grid restriction
            }
        }
        public void SelectPlacableObjects(GameObject[] Objects, object[] CustomData = default(object[]))
        {
            List <ModularPlacableObject> ModularPieces = new List <ModularPlacableObject>();

            for (int i = 0; i < Objects.Length; i++)
            {
                ModularPlacableObject Placable = (ModularPlacableObject)Objects [i].GetComponent(typeof(ModularPlacableObject));
                if (Placable != null)
                {
                    ModularPieces.Add(Placable);
                }
            }
            SelectPlacableObjects(ModularPieces.ToArray(), CustomData);
        }
        public ModularPlacableObject[] OverlappingPieces(ModularPlacableObject piece, float?range = null, bool CheckDefine = false)
        {
            List <ModularPlacableObject> Overlapping = new List <ModularPlacableObject> ();
            AxisBounds b = piece.Bounds;

            for (int i = 0; i < Pieces.Count; i++)
            {
                ModularPlacableObject Add = piece.StackTest(Pieces [i], range, CheckDefine);
                if (Add != null)
                {
                    Overlapping.Add(Add);
                }
            }

            return(Overlapping.ToArray());
        }
Exemplo n.º 4
0
        // overlapping checks
        public ModularPlacableObject[] OverlappingObjects(LayerMask Layer, float?Range, bool CheckDefines)
        {
            List <ModularPlacableObject> Overlapping = new List <ModularPlacableObject> ();

            Collider[] OverlappingColliders = Physics.OverlapSphere(Position, Scale);
            foreach (Collider col in OverlappingColliders)
            {
                ModularPlacableObject TempObj = (ModularPlacableObject)col.gameObject.GetComponent(typeof(ModularPlacableObject));
                if (TempObj != null && TempObj != this && TempObj.gameObject.layer == Layer.ToLayer())
                {
                    // has found a object
                    ModularPlacableObject Add = this.StackTest(TempObj, Range, CheckDefines);
                    if (Add != null)
                    {
                        Overlapping.Add(Add);
                    }
                }
            }

            return(Overlapping.ToArray());
        }
        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
        }
        public void ReplaceModularPlacable(ModularPlacableObject Placable)
        {
            PlaceModularPlacable(Placable, (object[] data) => {
                ModularPlacableObject Placed = data.Find <ModularPlacableObject>();
                Placed.OnPlaced();

                // placed
                Statemachine.changeState(new ModularSpectate(), this);
                GameManager.I.Utils.ChangeUndoable(Placed.gameObject);                 // register undo change
            }, (ModularPlacableObject Obj) => {
                return(true);
            }, (data) => {
                ModularPlacableObject Placed = data.Find <ModularPlacableObject>();
                Placed.OnPlaced();

                // cancel
                Statemachine.changeState(new ModularSpectate(), this);
                GameManager.I.Utils.ChangeUndoable(Placed.gameObject); // register undo change
            });
            Placable.OnDeplaced();                                     // deplace placable
            Placable.RemoveFromGrid();
        }
Exemplo n.º 7
0
 public TextureLink(ModularTextureData Texture, ModularTextureArray Array, ModularPlacableObject ModularPlacable, Utils.RenderSet Set, int SetID)
 {
     this._Texture        = Texture;
     this._Array          = Array;
     this.ModularPlacable = ModularPlacable;
     AddRenderTuple(Set, SetID);
 }
Exemplo n.º 8
0
        public virtual ModularPlacableObject Duplicate()
        {
            ModularPlacableObject DuplicateModularPlacable = GameObject.Instantiate(this.gameObject, this.transform.position, this.transform.rotation).GetComponent <ModularPlacableObject>();

            return(DuplicateModularPlacable);
        }
 public ModularPlacableData(ModularPlacableObject ModularObject)
 {
     this.LocalPosition    = ModularObject.LocalPosition;
     this.LocalScale       = ModularObject.transform.localScale;
     this.LocalEulerAngles = ModularObject.transform.localEulerAngles;
 }
Exemplo n.º 10
0
 public void DeregisterPlacingObject()
 {
     PlacingObject = null;
 }
Exemplo n.º 11
0
 public void RegisterPlacingObject(ModularPlacableObject piece)
 {
     PlacingObject = piece;
 }
        public static ModularPlacableObject StackTest(this ModularPlacableObject Test, ModularPlacableObject Target, float?range, bool CheckDefine)
        {
            AxisBounds b = Test.Bounds;

            if (Target.gameObject.activeSelf)
            {
                if (range != null)
                {
                    if (Target != Test && Target.Bounds.LocalIntersects(b) && Vector3.Distance(Target.Position, Test.Position) < range)
                    {
                        if (CheckDefine)
                        {
                            if (Test.DefinesBoundarys && Test.DefinesBoundarys == Target.DefinesBoundarys || !Test.DefinesBoundarys)                               // only stack if is stackable on this piece
                            {
                                return(Target);
                            }
                        }
                        else
                        {
                            return(Target);
                        }
                    }
                }
                else if (Target != Test && Target.Bounds.LocalIntersects(b))
                {
                    return(Target);
                }
            }
            return(null);            // if didnt pass the tests return null
        }