Example #1
0
        public void tellTransformStructure(CSteamID steamID, byte x, byte y, uint instanceID, Vector3 point, byte angle_x, byte angle_y, byte angle_z)
        {
            StructureRegion structureRegion;

            if (base.channel.checkServer(steamID) && StructureManager.tryGetRegion(x, y, out structureRegion))
            {
                if (!Provider.isServer && !structureRegion.isNetworked)
                {
                    return;
                }
                StructureData structureData = null;
                StructureDrop structureDrop = null;
                ushort        num           = 0;
                while ((int)num < structureRegion.drops.Count)
                {
                    if (structureRegion.drops[(int)num].instanceID == instanceID)
                    {
                        if (Provider.isServer)
                        {
                            structureData = structureRegion.structures[(int)num];
                        }
                        structureDrop = structureRegion.drops[(int)num];
                        break;
                    }
                    num += 1;
                }
                if (structureDrop == null)
                {
                    return;
                }
                structureDrop.model.position = point;
                structureDrop.model.rotation = Quaternion.Euler((float)(angle_x * 2), (float)(angle_y * 2), (float)(angle_z * 2));
                byte b;
                byte b2;
                if (Regions.tryGetCoordinate(point, out b, out b2) && (x != b || y != b2))
                {
                    StructureRegion structureRegion2 = StructureManager.regions[(int)b, (int)b2];
                    structureRegion.drops.RemoveAt((int)num);
                    if (structureRegion2.isNetworked || Provider.isServer)
                    {
                        structureRegion2.drops.Add(structureDrop);
                    }
                    else if (!Provider.isServer)
                    {
                        Object.Destroy(structureDrop.model.gameObject);
                    }
                    if (Provider.isServer)
                    {
                        structureRegion.structures.RemoveAt((int)num);
                        structureRegion2.structures.Add(structureData);
                    }
                }
                if (Provider.isServer)
                {
                    structureData.point   = point;
                    structureData.angle_x = angle_x;
                    structureData.angle_y = angle_y;
                    structureData.angle_z = angle_z;
                }
            }
        }
 // Token: 0x06002EB3 RID: 11955 RVA: 0x001309B4 File Offset: 0x0012EDB4
 private void Update()
 {
     if (!this.isBuilding)
     {
         return;
     }
     this.ray = MainCamera.instance.ScreenPointToRay(Input.mousePosition);
     Physics.Raycast(this.ray, out this.worldHit, 256f, RayMasks.EDITOR_WORLD);
     Physics.Raycast(this.ray, out this.buildableHit, 256f, RayMasks.EDITOR_BUILDABLE);
     Physics.Raycast(this.ray, out this.logicHit, 256f, RayMasks.VIEWMODEL);
     if (GUIUtility.hotControl == 0)
     {
         if (Input.GetKey(ControlsSettings.secondary))
         {
             this.handleType = EDragType.NONE;
             if (this.isDragging)
             {
                 this._dragStart  = Vector2.zero;
                 this._dragEnd    = Vector2.zero;
                 this._isDragging = false;
                 if (this.onDragStopped != null)
                 {
                     this.onDragStopped();
                 }
                 this.clearSelection();
             }
             return;
         }
         if (this.handleType != EDragType.NONE)
         {
             if (!Input.GetKey(ControlsSettings.primary))
             {
                 this.applySelection();
                 this.handleType = EDragType.NONE;
             }
             else
             {
                 if (this.handleType == EDragType.TRANSFORM_X)
                 {
                     this.transformGroup(this.handle.right, this.handle.up);
                 }
                 else if (this.handleType == EDragType.TRANSFORM_Y)
                 {
                     this.transformGroup(this.handle.up, this.handle.right);
                 }
                 else if (this.handleType == EDragType.TRANSFORM_Z)
                 {
                     this.transformGroup(this.handle.forward, this.handle.up);
                 }
                 else if (this.handleType == EDragType.PLANE_X)
                 {
                     this.planeGroup(this.handle.right);
                 }
                 else if (this.handleType == EDragType.PLANE_Y)
                 {
                     this.planeGroup(this.handle.up);
                 }
                 else if (this.handleType == EDragType.PLANE_Z)
                 {
                     this.planeGroup(this.handle.forward);
                 }
                 if (this.handleType == EDragType.ROTATION_X)
                 {
                     this.rotateGroup(this.handle.right, Vector3.right);
                 }
                 else if (this.handleType == EDragType.ROTATION_Y)
                 {
                     this.rotateGroup(this.handle.up, Vector3.up);
                 }
                 else if (this.handleType == EDragType.ROTATION_Z)
                 {
                     this.rotateGroup(this.handle.forward, Vector3.forward);
                 }
             }
         }
         if (Input.GetKeyDown(ControlsSettings.tool_0))
         {
             this.dragMode = EDragMode.TRANSFORM;
         }
         if (Input.GetKeyDown(ControlsSettings.tool_1))
         {
             this.dragMode = EDragMode.ROTATE;
         }
         if (Input.GetKeyDown(KeyCode.B) && this.selection.Count > 0 && Input.GetKey(KeyCode.LeftControl))
         {
             this.copyPosition = this.handle.position;
             this.copyRotation = this.handle.rotation;
         }
         if (Input.GetKeyDown(KeyCode.N) && this.selection.Count > 0 && this.copyPosition != Vector3.zero && Input.GetKey(KeyCode.LeftControl))
         {
             this.pointSelection();
             this.handle.position = this.copyPosition;
             this.handle.rotation = this.copyRotation;
             this.updateGroup();
             this.applySelection();
         }
         if (this.handleType == EDragType.NONE)
         {
             if (Input.GetKeyDown(ControlsSettings.primary))
             {
                 if (this.logicHit.transform != null && (this.logicHit.transform.name == "Arrow_X" || this.logicHit.transform.name == "Arrow_Y" || this.logicHit.transform.name == "Arrow_Z" || this.logicHit.transform.name == "Plane_X" || this.logicHit.transform.name == "Plane_Y" || this.logicHit.transform.name == "Plane_Z" || this.logicHit.transform.name == "Circle_X" || this.logicHit.transform.name == "Circle_Y" || this.logicHit.transform.name == "Circle_Z"))
                 {
                     this.mouseOrigin     = Input.mousePosition;
                     this.transformOrigin = this.handle.position;
                     this.rotateOrigin    = this.handle.rotation;
                     this.handleOffset    = this.logicHit.point - this.handle.position;
                     this.pointSelection();
                     if (this.logicHit.transform.name == "Arrow_X")
                     {
                         this.handleType = EDragType.TRANSFORM_X;
                     }
                     else if (this.logicHit.transform.name == "Arrow_Y")
                     {
                         this.handleType = EDragType.TRANSFORM_Y;
                     }
                     else if (this.logicHit.transform.name == "Arrow_Z")
                     {
                         this.handleType = EDragType.TRANSFORM_Z;
                     }
                     else if (this.logicHit.transform.name == "Plane_X")
                     {
                         this.handleType = EDragType.PLANE_X;
                     }
                     else if (this.logicHit.transform.name == "Plane_Y")
                     {
                         this.handleType = EDragType.PLANE_Y;
                     }
                     else if (this.logicHit.transform.name == "Plane_Z")
                     {
                         this.handleType = EDragType.PLANE_Z;
                     }
                     else if (this.logicHit.transform.name == "Circle_X")
                     {
                         this.rotateInverted = (Vector3.Dot(this.logicHit.point - this.handle.position, MainCamera.instance.transform.up) < 0f);
                         this.handleType     = EDragType.ROTATION_X;
                     }
                     else if (this.logicHit.transform.name == "Circle_Y")
                     {
                         this.rotateInverted = (Vector3.Dot(this.logicHit.point - this.handle.position, MainCamera.instance.transform.up) < 0f);
                         this.handleType     = EDragType.ROTATION_Y;
                     }
                     else if (this.logicHit.transform.name == "Circle_Z")
                     {
                         this.rotateInverted = (Vector3.Dot(this.logicHit.point - this.handle.position, MainCamera.instance.transform.up) < 0f);
                         this.handleType     = EDragType.ROTATION_Z;
                     }
                 }
                 else
                 {
                     Transform transform = this.buildableHit.transform;
                     if (transform != null && (transform.CompareTag("Barricade") || transform.CompareTag("Structure")))
                     {
                         InteractableDoorHinge component = transform.GetComponent <InteractableDoorHinge>();
                         if (component != null)
                         {
                             transform = component.transform.parent.parent;
                         }
                         if (Input.GetKey(ControlsSettings.modify))
                         {
                             if (this.containsSelection(transform))
                             {
                                 this.removeSelection(transform);
                             }
                             else
                             {
                                 this.addSelection(transform);
                             }
                         }
                         else if (this.containsSelection(transform))
                         {
                             this.clearSelection();
                         }
                         else
                         {
                             this.clearSelection();
                             this.addSelection(transform);
                         }
                     }
                     else
                     {
                         if (!this.isDragging)
                         {
                             this._dragStart.x = PlayerUI.window.mouse_x;
                             this._dragStart.y = PlayerUI.window.mouse_y;
                         }
                         if (!Input.GetKey(ControlsSettings.modify))
                         {
                             this.clearSelection();
                         }
                     }
                 }
             }
             else if (Input.GetKey(ControlsSettings.primary) && this.dragStart.x != 0f)
             {
                 this._dragEnd.x = PlayerUI.window.mouse_x;
                 this._dragEnd.y = PlayerUI.window.mouse_y;
                 if (this.isDragging || Mathf.Abs(this.dragEnd.x - this.dragStart.x) > 50f || Mathf.Abs(this.dragEnd.x - this.dragStart.x) > 50f)
                 {
                     int num  = (int)this.dragStart.x;
                     int num2 = (int)this.dragStart.y;
                     if (this.dragEnd.x < this.dragStart.x)
                     {
                         num = (int)this.dragEnd.x;
                     }
                     if (this.dragEnd.y < this.dragStart.y)
                     {
                         num2 = (int)this.dragEnd.y;
                     }
                     int num3 = (int)this.dragEnd.x;
                     int num4 = (int)this.dragEnd.y;
                     if (this.dragStart.x > this.dragEnd.x)
                     {
                         num3 = (int)this.dragStart.x;
                     }
                     if (this.dragStart.y > this.dragEnd.y)
                     {
                         num4 = (int)this.dragStart.y;
                     }
                     if (this.onDragStarted != null)
                     {
                         this.onDragStarted(num, num2, num3, num4);
                     }
                     if (!this.isDragging)
                     {
                         this._isDragging = true;
                         this.dragable.Clear();
                         byte region_x = Player.player.movement.region_x;
                         byte region_y = Player.player.movement.region_y;
                         if (Regions.checkSafe((int)region_x, (int)region_y))
                         {
                             for (int i = 0; i < BarricadeManager.plants.Count; i++)
                             {
                                 BarricadeRegion barricadeRegion = BarricadeManager.plants[i];
                                 for (int j = 0; j < barricadeRegion.drops.Count; j++)
                                 {
                                     BarricadeDrop barricadeDrop = barricadeRegion.drops[j];
                                     if (!(barricadeDrop.model == null))
                                     {
                                         Vector3 newScreen = MainCamera.instance.WorldToScreenPoint(barricadeDrop.model.position);
                                         if (newScreen.z >= 0f)
                                         {
                                             newScreen.y = (float)Screen.height - newScreen.y;
                                             this.dragable.Add(new EditorDrag(barricadeDrop.model, newScreen));
                                         }
                                     }
                                 }
                             }
                             for (int k = (int)(region_x - 1); k <= (int)(region_x + 1); k++)
                             {
                                 for (int l = (int)(region_y - 1); l <= (int)(region_y + 1); l++)
                                 {
                                     if (Regions.checkSafe((int)((byte)k), (int)((byte)l)))
                                     {
                                         for (int m = 0; m < BarricadeManager.regions[k, l].drops.Count; m++)
                                         {
                                             BarricadeDrop barricadeDrop2 = BarricadeManager.regions[k, l].drops[m];
                                             if (!(barricadeDrop2.model == null))
                                             {
                                                 Vector3 newScreen2 = MainCamera.instance.WorldToScreenPoint(barricadeDrop2.model.position);
                                                 if (newScreen2.z >= 0f)
                                                 {
                                                     newScreen2.y = (float)Screen.height - newScreen2.y;
                                                     this.dragable.Add(new EditorDrag(barricadeDrop2.model, newScreen2));
                                                 }
                                             }
                                         }
                                         for (int n = 0; n < StructureManager.regions[k, l].drops.Count; n++)
                                         {
                                             StructureDrop structureDrop = StructureManager.regions[k, l].drops[n];
                                             if (structureDrop != null)
                                             {
                                                 Vector3 newScreen3 = MainCamera.instance.WorldToScreenPoint(structureDrop.model.position);
                                                 if (newScreen3.z >= 0f)
                                                 {
                                                     newScreen3.y = (float)Screen.height - newScreen3.y;
                                                     this.dragable.Add(new EditorDrag(structureDrop.model, newScreen3));
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     if (!Input.GetKey(ControlsSettings.modify))
                     {
                         for (int num5 = 0; num5 < this.selection.Count; num5++)
                         {
                             if (!(this.selection[num5].transform == null))
                             {
                                 Vector3 vector = MainCamera.instance.WorldToScreenPoint(this.selection[num5].transform.position);
                                 if (vector.z < 0f)
                                 {
                                     this.removeSelection(this.selection[num5].transform);
                                 }
                                 else
                                 {
                                     vector.y = (float)Screen.height - vector.y;
                                     if (vector.x < (float)num || vector.y < (float)num2 || vector.x > (float)num3 || vector.y > (float)num4)
                                     {
                                         this.removeSelection(this.selection[num5].transform);
                                     }
                                 }
                             }
                         }
                     }
                     for (int num6 = 0; num6 < this.dragable.Count; num6++)
                     {
                         EditorDrag editorDrag = this.dragable[num6];
                         if (!(editorDrag.transform == null))
                         {
                             if (!(editorDrag.transform.parent == this.group))
                             {
                                 if (editorDrag.screen.x >= (float)num && editorDrag.screen.y >= (float)num2 && editorDrag.screen.x <= (float)num3 && editorDrag.screen.y <= (float)num4)
                                 {
                                     this.addSelection(editorDrag.transform);
                                 }
                             }
                         }
                     }
                 }
             }
             if (this.selection.Count > 0 && Input.GetKeyDown(ControlsSettings.tool_2) && this.worldHit.transform != null)
             {
                 this.pointSelection();
                 this.handle.position = this.worldHit.point;
                 if (Input.GetKey(ControlsSettings.snap))
                 {
                     this.handle.position += this.worldHit.normal * this.snapTransform;
                 }
                 this.updateGroup();
                 this.applySelection();
             }
         }
     }
     if (Input.GetKeyUp(ControlsSettings.primary) && this.dragStart.x != 0f)
     {
         this._dragStart = Vector2.zero;
         if (this.isDragging)
         {
             this._dragEnd    = Vector2.zero;
             this._isDragging = false;
             if (this.onDragStopped != null)
             {
                 this.onDragStopped();
             }
         }
     }
 }
Example #3
0
 public static bool tryGetInfo(Transform structure, out byte x, out byte y, out ushort index, out StructureRegion region, out StructureDrop drop)
 {
     x      = 0;
     y      = 0;
     index  = 0;
     region = null;
     drop   = null;
     if (StructureManager.tryGetRegion(structure, out x, out y, out region))
     {
         index = 0;
         while ((int)index < region.drops.Count)
         {
             if (structure == region.drops[(int)index].model)
             {
                 drop = region.drops[(int)index];
                 return(true);
             }
             index += 1;
         }
     }
     return(false);
 }