コード例 #1
0
        public void PlaceModularPlacable(
            ModularPlacableObject ModularPlacable,
            Delegates.GenericDataCallbak PlacedCallback,
            System.Func <ModularPlacableObject, bool> CanPlace,
            System.Action <object[]> OnCanceled,
            SnapTypes InitSnapType = SnapTypes.Default,
            object[] ExtraData     = default(object[]),
            bool Interrupt         = false
            )
        {
            List <object> GenData = new List <object> ();

            GenData.Add(this);
            GenData.Add(ModularPlacable);
            GenData.Add(PlacedCallback);
            GenData.Add(OnCanceled);
            GenData.Add(CanPlace);

            if (ExtraData != null)               // add extra data if is not null
            {
                for (int i = 0; i < ExtraData.Length; i++)
                {
                    GenData.Add(ExtraData [i]);
                }
            }

            // add init settings
            GenData.Add(InitSnapType);
            Statemachine.changeState(new PlacePlacableObject(), GenData, Interrupt);
        }
コード例 #2
0
 private void InitDefaultValues()
 {
     SnapType              = ScopedObject.SnapType;
     StackType             = (ScopedObject.DefinesBoundarys)?StackTypes.Center:StackTypes.Disabled;
     AlignToSurface        = (ScopedObject.DefinesBoundarys) ? 3 : 1;
     DetailSettings        = new FastPlaceDetailSettings();
     DetailSettings._Scale = ScopedObject.transform.localScale;
 }
コード例 #3
0
ファイル: SnapToGrid.cs プロジェクト: configare/hispeed
 public SnapToGrid(ref SnapToGrid e)
 {
     fieldWidth = e.fieldWidth;
     coefSnap   = e.coefSnap;
     deltaSnap  = e.deltaSnap;
     snapType   = e.snapType;
     snapPoint  = e.snapPoint;
 }
コード例 #4
0
ファイル: SnapToGrid.cs プロジェクト: configare/hispeed
 /// <summary>
 /// The default constructor sets the following default values:
 ///     FieldWidth = 1.0f;
 ///     SnapRelative = 0.2f;
 ///     SnapDelta = 0.2f;
 ///     SnapType = SnapTypes.Relative;
 /// </summary>
 public SnapToGrid()
 {
     fieldWidth = 1f;
     coefSnap   = 0.2f;
     deltaSnap  = fieldWidth * coefSnap;
     snapType   = SnapTypes.Relative;
     snapPoint  = new PointF();
 }
コード例 #5
0
        public void PlaceAtPos(Vector3 Pos, SnapTypes Snap, Vector3?AlignNormal, Transform Trans = null, Vector3 Offset = default(Vector3), bool UpdateLastPlaced = true)
        {
            PlaceAtPos(Pos, Snap, Trans, Offset, UpdateLastPlaced);

            if (AlignNormal != null)
            {
                AlignToSurface((Vector3)AlignNormal);
            }
        }
コード例 #6
0
 public SnapToGrid(ref SnapToGrid e)
 {
     isLastSnapped = false;
     fieldWidth    = e.fieldWidth;
     coefSnap      = e.coefSnap;
     deltaSnap     = e.deltaSnap;
     snapType      = e.snapType;
     snapPoint     = e.snapPoint;
 }
コード例 #7
0
        private SnapTypes RestrictSnapType(SnapTypes Type)
        {
            switch (PositionRestriction)
            {
            case PositionRestrictions.GridOnly:
                Type = SnapTypes.Center;
                break;
            }

            return(Type);
        }
コード例 #8
0
        public Vector3 CalculateRestrictedPosition(Vector3 Pos, SnapTypes Snap, Transform Trans = null)
        {
            Snap = RestrictSnapType(Snap);              // restrict snap type
            Vector3 FinalPos = Pos;

            switch (Snap)
            {
            case SnapTypes.Cross:
                FinalPos = (Trans)?GetSnapPosition(Pos, Rotation):GetSnapPosition(Pos);                // snap to center of grid points
                break;

            case SnapTypes.Center:
                Vector3 GridOffset = Vector3.zero;
                GridOffset += ((Trans)?Trans.forward: Vector3.forward) * (RestrictedScale / 2);
                GridOffset += ((Trans)?Trans.right:Vector3.right) * (RestrictedScale / 2);
                FinalPos    = (Trans)?GetSnapPosition(Pos, Rotation, GridOffset):GetSnapPosition(Pos, GridOffset);           // snap to center of grid points
                break;

            case SnapTypes.Edge:
                Vector3 Forward      = (Trans) ? Trans.forward : Vector3.forward;                                                                              // get forward
                Vector3 Right        = (Trans) ? Trans.right : Vector3.right;                                                                                  // get right
                Vector3 SnapOffset   = GetEdgeSnapOffset(Forward, Right);                                                                                      // get edge snap offset
                Vector3 GridPosition = (Trans) ? GetSnapPosition(FinalPos, Rotation, SnapOffset) : GetSnapPosition(FinalPos, Quaternion.identity, SnapOffset); // get world or local snap position

                // calculate front or back side of edge
                Vector3 MouseWorldPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.WorldToScreenPoint(FinalPos).z)); // world position of the mouse
                MouseWorldPos.y = 0;                                                                                                                                           // set mouse world pos to 0
                float Side = (Vector3.Dot(transform.forward, (MouseWorldPos - GridPosition)) <= 0) ? -1 : 1;                                                                   // check which edge to take
                SnapOffset = (transform.forward * Side) * (MinScale / 2);                                                                                                      // offset position to be placed on edge
                FinalPos   = GridPosition + SnapOffset;                                                                                                                        // override pos to be the new gridposition
                break;

            default:
                // free form is default
                break;
            }
            return(FinalPos);
        }
コード例 #9
0
        public void PlaceAtPos(Vector3 Pos, SnapTypes Snap, Transform Trans = null, Vector3 Offset = default(Vector3), bool UpdateLastPlaced = true)
        {
            Vector3 FinalPos = Pos;                                                  // temp final position to be edited in this function in order to keep the origional mouse Pos intact

            Trans = (SpaceRestriction == SpaceRestrictions.WorldOnly)? null : Trans; // check space restriction
            Snap  = RestrictSnapType(Snap);                                          // restrict snap type
            Quaternion Rotation = (Trans)? Trans.rotation:Quaternion.identity;

            FinalPos = CalculateRestrictedPosition(FinalPos, Snap, Trans);              // calculate restricted position

            if (UpdateLastPlaced)
            {
                UpdateLastGridPosition(FinalPos, Pos, Rotation, Snap);               // update Last GridPosition
            }

            Position     = FinalPos + Offset; // set position
            LastPosition = Position;          // Update last position

            if (GridPosChanged)               // check if grid position changed
            {
                OnPositionChanged();          // call on position changed
            }
        }
コード例 #10
0
 private void UpdateLastGridPosition(Vector3 PlacedPosition, Vector3 TargetPosition, Quaternion Rotation, SnapTypes TargetType)
 {
     if ((SnapType == SnapTypes.Edge || SnapType == SnapTypes.Center) && TargetType == SnapTypes.Edge)
     {
         // non offsetted grid position
         LastGridPosition = GetSnapPosition(TargetPosition, Rotation);
     }
     else if (SnapType == SnapTypes.Edge && TargetType == SnapTypes.FreeForm || SnapType == SnapTypes.FreeForm && TargetType == SnapTypes.Edge)
     {
         // Place position - GridSnapoffset and default mouse at forward offset
         Vector3 GridPos = PlacedPosition;
         GridPos         -= GetEdgeSnapOffset(Rotation * Vector3.forward, Rotation * Vector3.right) + ((Rotation * Vector3.forward) * MinScale / 2);
         LastGridPosition = GridPos;
     }
     else if (TargetType == SnapTypes.Center)
     {
         LastGridPosition = GetSnapPosition(TargetPosition, Rotation);
     }
     else
     {
         // Last grid position is simply the placed location
         LastGridPosition = PlacedPosition;
     }
 }
コード例 #11
0
        private void InitUI()
        {
            List <UI.Toolbar.HeaderAction> Settings     = new List <UI.Toolbar.HeaderAction> ();
            List <UI.Toolbar.HeaderAction> ColorActions = new List <UI.Toolbar.HeaderAction> ();

            // add actions
            #region Movement actions

            if (ScopedObject.PositionRestriction == PositionRestrictions.None)               // only add settings if doesnt have restrictions
            {
                #region Snap Type Settings
                int SnapTypeIndex = 0;
                if (SnapType == SnapTypes.Cross)
                {
                    SnapTypeIndex = 0;
                }
                else if (SnapType == SnapTypes.Edge)
                {
                    SnapTypeIndex = 1;
                }
                else if (SnapType == SnapTypes.Center)
                {
                    SnapTypeIndex = 2;
                }
                else if (SnapType == SnapTypes.FreeForm)
                {
                    SnapTypeIndex = 3;
                }


                Settings.Add(new UI.Toolbar.HeaderAction(
                                 UI.Toolbar.HeaderActionType.Toggle,
                                 new IconPack.IconType[] {
                    IconPack.IconType.GridCross,
                    IconPack.IconType.GridEdge,
                    IconPack.IconType.GridCenter,
                    IconPack.IconType.NoGrid
                }, new string[] {
                    "Grid cross",
                    "Grid edge",
                    "Grid center",
                    "No grid"
                }, new System.Action <object[]>[] {
                    (objects) => {
                        SnapType = SnapTypes.Cross;
                    },
                    (objects) => {
                        SnapType = SnapTypes.Edge;
                    },
                    (objects) => {
                        SnapType = SnapTypes.Center;
                    },
                    (objects) => {
                        SnapType = SnapTypes.FreeForm;
                    }
                }, SnapTypeIndex, UI.ToolTipComponent.AlignSide.Top
                                 ));

                #endregion
                #region Align To Surface
                Settings.Add(new UI.Toolbar.HeaderAction(
                                 UI.Toolbar.HeaderActionType.Toggle,
                                 new IconPack.IconType[] {
                    IconPack.IconType.AlignStraight,
                    IconPack.IconType.AlignSurface,
                    IconPack.IconType.AlignSet,
                    IconPack.IconType.NoAlign
                }, new string[] {
                    "Align to surface position",
                    "Align to surface",
                    "Align to anything",
                    "Don't align"
                }, new System.Action <object[]>[] {
                    (objects) => {
                        AlignToSurface = 0;
                    },
                    (objects) => {
                        AlignToSurface = 1;
                    },
                    (objects) => {
                        AlignToSurface = 2;
                    },
                    (objects) => {
                        AlignToSurface = 3;
                    }
                }, AlignToSurface, UI.ToolTipComponent.AlignSide.Top
                                 ));
                #endregion
                #region Stack Types
                int StackIndex = 0;
                if (StackType == StackTypes.Center)
                {
                    StackIndex = 1;
                }
                else if (StackType == StackTypes.Disabled)
                {
                    StackIndex = 2;
                }
                Settings.Add(new UI.Toolbar.HeaderAction(
                                 UI.Toolbar.HeaderActionType.Toggle,
                                 new IconPack.IconType[] {
                    IconPack.IconType.BoundaryStacking,
                    IconPack.IconType.CenterStacking,
                    IconPack.IconType.NoStacking
                }, new string[] {
                    "Boundary stacking",
                    "Center stacking",
                    "No stacking"
                }, new System.Action <object[]>[] {
                    (objects) => {
                        StackType = StackTypes.Boundary;
                    },
                    (objects) => {
                        StackType = StackTypes.Center;
                    },
                    (objects) => {
                        StackType = StackTypes.Disabled;
                    }
                }, StackIndex, UI.ToolTipComponent.AlignSide.Top
                                 ));
                #endregion
                #region Local/world Space
                int LocalSetting = (LocalSpace)?0:1;
                Settings.Add(new UI.Toolbar.HeaderAction(
                                 UI.Toolbar.HeaderActionType.Boolean,
                                 new IconPack.IconType[] {
                    IconPack.IconType.LocalSpace,
                    IconPack.IconType.WorldSpace
                }, new string[] {
                    "Local space",
                    "World space"
                }, new System.Action <object[]>[] {
                    (objects) => {
                        LocalSpace = true;
                    },
                    (objects) => {
                        LocalSpace = false;
                    }
                }, LocalSetting, UI.ToolTipComponent.AlignSide.Top
                                 ));
                #endregion
            }

            #region Colors
            ModularPlacableObject.ColorGroup[] ColorGroups = new Modular.ModularPlacableObject[] { ScopedObject }.ColorGroups();
            if (ColorGroups.Length < 8)               // limit colors to 8
            {
                for (int i = 0; i < ColorGroups.Length; i++)
                {
                    ColorActions.Add(InitColorSwatch(ColorGroups, i));
                }
            }
            #endregion


            #endregion

            // create toolbar settings
            UI.Toolbar.ToolbarSettings TempSettings = new UI.Toolbar.ToolbarSettings {
                HeaderSections = new UI.Toolbar.HeaderSection[] {                 // movement actions section
                    new UI.Toolbar.HeaderSection(Settings.ToArray()),
                    new UI.Toolbar.HeaderSection(ColorActions.ToArray())
                },
                ToolbarIconSize    = 28f,
                Title              = "Advanced",
                ScreenPadding      = 52,
                MaxLength          = 40,
                SettingsToolTip    = "Extra",
                TransparentOnHover = true,
                Content            = (ScopedObject.PositionRestriction == PositionRestrictions.None)?new object[] {
                    DetailSettings
                }:new object[0]
            };

            // init toolbar
            if (SettingsBar == null)
            {
                SettingsBar = GameManager.I.UI.InitToolbar(TempSettings, false);
            }
            else
            {
                for (int i = 0; i < SettingsBar.ToolbarSettings.HeaderSections.Length; i++)
                {
                    if (TempSettings.HeaderSections.Length > i)
                    {
                        for (int x = 0; x < SettingsBar.ToolbarSettings.HeaderSections [i].Actions.Length; x++)
                        {
                            if (TempSettings.HeaderSections [i].Actions.Length > x)
                            {
                                SettingsBar.ToolbarSettings.HeaderSections [i].Actions [x].ClickCallbacks = TempSettings.HeaderSections [i].Actions [x].ClickCallbacks;
                            }
                        }
                    }
                }
            }
        }
コード例 #12
0
 private void ToggleSnapping(SnapTypes flags)
 {
     snapStates ^= (uint)flags;
 }
コード例 #13
0
 private bool IsSnappingActive(SnapTypes flags)
 {
     return((snapStates & (uint)flags) != 0);
 }
コード例 #14
0
 private void ClrSnapping(SnapTypes flags)
 {
     snapStates &= ~(uint)flags;
 }
コード例 #15
0
 private void SetSnapping(SnapTypes flags)
 {
     snapStates |= (uint)flags;
 }