Esempio n. 1
0
        /*
         * Sets the group of this BC, its position in the gorup, and places the object where it must be
         */
        /*
         * public void setObjectGroup (BeyondGroup g , Vector3Int p , cellSide cs , bool firstObject=false)
         * { // TODO should make that more robust : what if g is null ?
         *  unsetObjectGroup();
         *  if (g!=null)
         *  {
         *      beyondGroup = g ;
         *      groupPosition = p ;
         *      side = cs ;
         *      // The first object should not be offset or rotated by the group, since it sets the group position and rotation
         *      if (!firstObject)
         *      {
         *          // Rotate the pivot offset by the group's rotation
         *          Vector3 rotatedPivotOffset = template.pivotOffset ;
         *          rotatedPivotOffset = g.rotation * rotatedPivotOffset ;
         *          // Then  by the sideRotation
         *          rotatedPivotOffset = sideRotation(cs) * rotatedPivotOffset ;
         *
         *          // Move the object to its template offset position
         *          transform.position += rotatedPivotOffset;
         *
         *          // Rotate the object by the group's rotation + its cellSide rotation
         *          transform.rotation = g.rotation * sideRotation(cs) ;
         *      }
         *      g.addBeyondComponent(this);
         *  }
         * }
         */

        public void SetBCinGroup(BeyondGroup g, Vector3Int p, bool firstObject = false)
        { // TODO should make that more robust : what if g is null ?
            unsetObjectGroup();
            if (g != null)
            {
                beyondGroup   = g;
                groupPosition = p;

                // If this template can only be on a specific side, use it, otherwise determine the side based on the rotation of the BC
                side = (template.fixedSide == null) ? getSideByRotation(this, g, p) : (cellSide)template.fixedSide;

                //TODO : Maybe I need one last check based on side : is there really no object here on the same postion and rotation

                // The first object should not be offset or rotated by the group, since it sets the group position and rotation
                if (!firstObject)
                {
                    // Rotate the cell's position to apply the group's rotation
                    Vector3 rotatedCellPosition = Utility.RotateAroundPoint(p, Vector3.zero, g.rotation);
                    // Rotate the pivot's position to apply the group's rotation and the side's rotation
                    Vector3 rotatedPivotOffset = Utility.RotateAroundPoint(template.pivotOffset, Vector3.zero, sideRotation(side) * g.rotation);
                    Vector3 ObjectPosition     = g.position + rotatedCellPosition + rotatedPivotOffset;

                    transform.position = ObjectPosition;
                    // Rotate the object by the group's rotation + its cellSide rotation
                    transform.rotation = g.rotation * sideRotation(side);
                }
                g.addBeyondComponent(this);
            }
        }
Esempio n. 2
0
        public void CreateNewBeyondGroup(BeyondComponent bc, string name = null)
        {
            if (name == null)
            { // Auto give name
                name = String.Format("Group {0:0000}", place.beyondGroups.Count);
            }
            // bc.transform.position - bc.template.pivotOffset : THIS IS ESSENTIAL - This allows us to properly set the pivot of the group
            BeyondGroup group = new BeyondGroup(name, bc.transform.position - bc.template.pivotOffset, bc.transform.rotation);

            if (bc != null)
            {
                group.addBeyondComponent(bc);
                // Vector3Int.zero because the first object in a group is at position [0,0,0]
                bc.SetBCinGroup(group, Vector3Int.zero, true);
            }
            place.beyondGroups.Add(group);
        }