コード例 #1
0
    public GridLocation getDoorPositionOnBlueprint(ObjectRotation roomRotation, RoomBlueprint selectedRoomBlueprint, GridLocation door)
    {
        GridLocation rawDoorPositionOnBlueprint = door;

        switch (roomRotation)
        {
        case ObjectRotation.Rotation0:
            return(door);

        case ObjectRotation.Rotation90:
            return(new GridLocation(
                       rawDoorPositionOnBlueprint.UpLeft, //swapped axis on purpose
                       selectedRoomBlueprint.RightUpAxisLength - rawDoorPositionOnBlueprint.UpRight));

        case ObjectRotation.Rotation180:
            return(new GridLocation(
                       selectedRoomBlueprint.RightUpAxisLength - rawDoorPositionOnBlueprint.UpRight - 1,
                       selectedRoomBlueprint.LeftUpAxisLength - rawDoorPositionOnBlueprint.UpLeft));

        case ObjectRotation.Rotation270:
            return(new GridLocation(
                       selectedRoomBlueprint.LeftUpAxisLength - rawDoorPositionOnBlueprint.UpLeft, //swapped axis on purpose
                       selectedRoomBlueprint.RightUpAxisLength - rawDoorPositionOnBlueprint.UpRight));

        default:
            Logger.Error("Unknown RoomRotation given {0}", roomRotation);
            return(new GridLocation());
        }
    }
コード例 #2
0
    public bool TryBuildPlot(ObjectRotation roomRotation, RoomBlueprint selectedRoomBlueprint, GridLocation doorPositionOnExistingRoom)
    {
        for (int k = 0; k < selectedRoomBlueprint.DoorLocations.Length; k++)
        {
            GridLocation doorPositionOnBlueprint = getDoorPositionOnBlueprint(roomRotation, selectedRoomBlueprint, selectedRoomBlueprint.DoorLocations[k]);

            //Logger.Log("doorPositionOnExistingRoom {0}, {1} - doorPositionOnBlueprint {2} with rotation {3} is {4}, {5}",
            //    doorPositionOnExistingRoom.UpRight, doorPositionOnExistingRoom.UpLeft, selectedRoomBlueprint.RoomName, roomRotation, doorPositionOnBlueprint.UpRight, doorPositionOnBlueprint.UpLeft);
            if ((doorPositionOnExistingRoom.UpRight == doorPositionOnBlueprint.UpRight) && (doorPositionOnExistingRoom.UpLeft == doorPositionOnBlueprint.UpLeft))
            {
                continue;
            }

            GridLocation blueprintRoomStartPosition = new GridLocation(doorPositionOnExistingRoom.UpRight - doorPositionOnBlueprint.UpRight, (doorPositionOnExistingRoom.UpLeft - doorPositionOnBlueprint.UpLeft));

            if (blueprintRoomStartPosition.UpLeft % 3 != 0 || blueprintRoomStartPosition.UpRight % 3 != 0)
            {
                Logger.Log(Logger.Building, "This room cannot be built because it would not start on a (large) tile location. Its start position would be {0}, {1}. Skip. ", blueprintRoomStartPosition.UpRight, blueprintRoomStartPosition.UpLeft);
                continue;
            }

            Vector2 blueprintRoomStartPositionVector = GridHelper.GridToVectorLocation((int)blueprintRoomStartPosition.UpRight, (int)blueprintRoomStartPosition.UpLeft);
            //Logger.Log("the blueprintRoomStartPosition would be {0}, {1}", blueprintRoomStartPosition.UpRight, (int)blueprintRoomStartPosition.UpLeft);
            //Logger.Log("the blueprintRoomStartPositionVector would be {0}, {1}", blueprintRoomStartPositionVector.x, blueprintRoomStartPositionVector.y);

            if (GetPlotIsAvailable(selectedRoomBlueprint, blueprintRoomStartPositionVector, roomRotation))
            {
                BuildMenuWorldSpaceContainer.Instance.CreateBuildingPlot(_builderManager.BuildPlotPrefab, selectedRoomBlueprint, blueprintRoomStartPositionVector, roomRotation);
                Logger.Log(Logger.Building, "Created plot for building at {0}, {1}", blueprintRoomStartPositionVector.x, blueprintRoomStartPositionVector.y);
                return(true);
            }
        }
        return(false);
    }
コード例 #3
0
    public static Sprite GetRoomIcon(string name, ObjectRotation rotation)
    {
        string roomName = name.Replace(" ", "");

        if (rotation == ObjectRotation.Rotation0 || rotation == ObjectRotation.Rotation90)
        {
            Sprite roomIcon = Resources.Load <Sprite>("Icons/Rooms/" + roomName + "Rotation0");
            if (roomIcon == null)
            {
                Logger.Error(Logger.Building, "Could not find or load icon for {0}-{1}", name, rotation);
                return(Resources.Load <Sprite>("Icons/Rooms/Room1Rotation0"));
            }
            return(roomIcon);
        }
        else
        {
            Sprite roomIcon = Resources.Load <Sprite>("Icons/Rooms/" + roomName + "Rotation180");
            if (roomIcon == null)
            {
                Logger.Error(Logger.Building, "Could not find or load icon for {0}-{1}", name, rotation);
                return(Resources.Load <Sprite>("Icons/Rooms/Room1Rotation0"));
            }
            return(roomIcon);
        }
    }
コード例 #4
0
 public static Offset <RotatorPartial> ToFlatBuffer(this ObjectRotation rotation, FlatBufferBuilder builder)
 {
     RotatorPartial.StartRotatorPartial(builder);
     RotatorPartial.AddPitch(builder, Float.CreateFloat(builder, rotation.Pitch));
     RotatorPartial.AddYaw(builder, Float.CreateFloat(builder, rotation.Yaw));
     RotatorPartial.AddRoll(builder, Float.CreateFloat(builder, rotation.Roll));
     return(RotatorPartial.EndRotatorPartial(builder));
 }
コード例 #5
0
 /// <summary>
 /// Exports this game object to file
 /// </summary>
 /// <param name="BW">Open Writer</param>
 public override void Export(BinaryWriter BW)
 {
     base.Export(BW);
     BW.Write(UnknownInt);
     ObjectRotation.Export(BW);
     ObjectPosition.Export(BW);
     ObjectScale.Export(BW);
     BW.Write(UnknownHeaderEnd);
 }
コード例 #6
0
        IEnumerator handleObjectRotation(ObjectRotation data)
        {
            yield return(new WaitForSeconds(data.delay));

            for (; ;)
            {
                data.objToRotate.transform.Rotate(new Vector3(0f, 0f, data.RotationValue * Time.fixedDeltaTime));
                yield return(null);
            }
        }
コード例 #7
0
 private void Awake()
 {
     ButtonMapping();
     controllerCustomization.gameObject.SetActive(false);
     _objectMovement = GetComponent <ObjectMovement>();
     _objectRotation = GetComponent <ObjectRotation>();
     _useWeapon      = GetComponent <UseWeapon>();
     _shield         = GetComponent <Shield>();
     _options        = FindObjectOfType <Options>();
 }
コード例 #8
0
 private void SetPointerImageScale(ObjectRotation rotation)
 {
     if (rotation == ObjectRotation.Rotation90 || rotation == ObjectRotation.Rotation270)
     {
         PointerImage.rectTransform.localScale = new Vector3(-1f, 1f, 1f);
     }
     else
     {
         PointerImage.rectTransform.localScale = new Vector3(1f, 1f, 1f);
     }
 }
コード例 #9
0
    public void SetPointerImage(Sprite sprite, ObjectRotation rotation)
    {
        SetPointerImageScale(rotation);
        SetPointerImageSize(PointerImage);

        PointerImage.sprite         = sprite;
        PointerImage.enabled        = true;
        PointerImage.preserveAspect = true;

        IsDraggingIcon           = true;
        _rotationRoomOnLastHover = rotation;
    }
コード例 #10
0
 public UID?CreateBuilding(BuildingType buildingType, GridPosition position, ObjectRotation rotation, bool _, int visualID = -1, Action <UID> additionalAction = null, List <InventoryComponent2.ResourceAmount> initialInventoryData = null, bool putInitialInventoryInPreProduction = false)
 {
     try
     {
         CreativeEntityManager.Instance.SuppressDestroyEntity++;
         return(this.Vanilla.CreateBuilding(buildingType, position, rotation, true, visualID, additionalAction, initialInventoryData, putInitialInventoryInPreProduction));
     }
     finally
     {
         CreativeEntityManager.Instance.SuppressDestroyEntity--;
     }
 }
コード例 #11
0
    //This enemy were supposed to have different behaviour based on attack. Fire was a must, to then do damage and ice would double the HP (one time) and cannon kills it.
    private void Start()
    {
        _player    = GameObject.FindGameObjectWithTag("Player");
        _rnaBullet = Resources.Load <GameObject>("Prefabs/RNABullet");

        _movement       = new Vector2(1f, 1f);
        _objectMovement = GetComponent <ObjectMovement>();
        _objectRotation = GetComponent <ObjectRotation>();
        _state          = State.MOVING;
        _playerPosition = new Vector3(_player.transform.position.x, _player.transform.position.y, _player.transform.position.z);
        _heathDrop      = Resources.Load <GameObject>("Prefabs/PickUp");
    }
コード例 #12
0
 private void Start()
 {
     _rigidbody2D                      = GetComponent <Rigidbody2D>();
     _objectMovement                   = GetComponent <ObjectMovement>();
     _objectRotation                   = GetComponent <ObjectRotation>();
     _spriteRenderer                   = GetComponent <SpriteRenderer>();
     _sprite                           = Resources.Load <Sprite>("Sprites/Antibody");
     _spriteRenderer.sprite            = _sprite;
     _spriteRenderer.flipY             = true;
     _rigidbody2D.transform.localScale = new Vector3(_spriteSize, _spriteSize);
     _player                           = GameObject.FindGameObjectWithTag("Player");
     _playerPosition                   = new Vector3(_player.transform.position.x, _player.transform.position.y, _player.transform.position.z);
 }
コード例 #13
0
    public void Awake()
    {
        initialQuat = transform.rotation;
        oRotation   = GetComponent <ObjectRotation>();

        EventManager.instance.addEventListener(AssetEvent.ON_BACK_TO_ALL_VIEW, this.gameObject, "OnShowAllAssembly");
        vInitialPositions = new Vector3[vGo.Length];
        vInitialScale     = new Vector3[vGo.Length];
        vInitialQuat      = new Quaternion[vGo.Length];
        for (int i = 0; i < vGo.Length; i++)
        {
            vInitialPositions[i] = vGo[i].transform.position;
            vInitialScale[i]     = vGo[i].transform.localScale;
            vInitialQuat[i]      = vGo[i].transform.localRotation;
        }
    }
コード例 #14
0
    public void Setup(RoomBlueprint room, Vector2 startingPoint, ObjectRotation roomRotation)
    {
        if (BuilderManager.Instance.BuildingPlotLocations.ContainsValue(startingPoint))
        {
            return;
        }

        PlotRotation  = roomRotation;
        RoomBlueprint = room;
        StartingPoint = new Vector3(startingPoint.x, startingPoint.y, 1);

        double rightUpAxisLength = PlotRotation == ObjectRotation.Rotation0 || PlotRotation == ObjectRotation.Rotation180 ? room.RightUpAxisLength : room.LeftUpAxisLength;
        double leftUpAxisLength  = PlotRotation == ObjectRotation.Rotation0 || PlotRotation == ObjectRotation.Rotation180 ? room.LeftUpAxisLength : room.RightUpAxisLength;

        // == counter clockwise, starting at bottom
        Vector2 point1 = GridHelper.GridToVectorLocation(StartingPoint, (int)rightUpAxisLength, 0);
        Vector2 point2 = GridHelper.GridToVectorLocation(point1, 0, (int)-leftUpAxisLength);
        Vector2 point3 = GridHelper.GridToVectorLocation(point2, (int)-rightUpAxisLength, 0);

        SetColliderPath(new Vector2[] { StartingPoint, point1, point2, point3, StartingPoint });

        double midpointRightUpAxisLength = rightUpAxisLength / 2;
        double midpointLeftUpAxisLength  = leftUpAxisLength / 2;

        if (rightUpAxisLength / 2 - Math.Truncate(rightUpAxisLength / 2) != 0)
        {
            midpointRightUpAxisLength += 1.5f;
        }
        if (leftUpAxisLength / 2 - Math.Truncate(leftUpAxisLength / 2) != 0)
        {
            midpointLeftUpAxisLength -= 1.5f;
        }

        Vector2 midGridPoint = GridHelper.GridToVectorLocation(
            StartingPoint,
            (int)midpointRightUpAxisLength,
            -(int)midpointLeftUpAxisLength
            );

        if (!BuilderManager.Instance.BuildingPlotLocations.ContainsKey(midGridPoint))
        {
            BuilderManager.Instance.BuildingPlotLocations.Add(midGridPoint, StartingPoint);
        }

        CreateMesh(new Vector2[] { StartingPoint, point1, point2, point3 });
    }
コード例 #15
0
    private void LoadRoomPrefabs()
    {
        for (int i = 0; i < RegisteredRooms.Count; i++)
        {
            RoomName roomName = RegisteredRooms[i];
            Dictionary <ObjectRotation, GameObject> RoomPrefabs = new Dictionary <ObjectRotation, GameObject>();

            foreach (ObjectRotation rotation in ObjectRotation.GetValues(typeof(ObjectRotation)))
            {
                GameObject roomPrefab = (GameObject)Resources.Load("Prefabs/Scenery/Rooms/" + roomName + "/" + roomName + rotation, typeof(GameObject));
                if (roomPrefab != null)
                {
                    RoomPrefabs.Add(rotation, roomPrefab);
                }
            }

            RegisteredRoomPrefabs.Add(roomName, RoomPrefabs);
        }
    }
コード例 #16
0
    public void CreateBuildingPlot(GameObject buildingPlot, RoomBlueprint roomBlueprint, Vector2 startingPoint, ObjectRotation roomRotation)
    {
        if (BuilderManager.Instance.BuildingPlots.ContainsKey(startingPoint))
        {
            return;
        }

        BuildingPlot plot = Instantiate(buildingPlot, transform).GetComponent <BuildingPlot>();

        BuilderManager.Instance.BuildingPlots.Add(startingPoint, plot);
        //Logger.Log("The starting points for this plot should be {0}", startingPoint);

        plot.Setup(roomBlueprint, startingPoint, roomRotation);
    }
コード例 #17
0
 private void Start()
 {
     obj_1 = platform_1.GetComponentInChildren <ObjectRotation>();
     obj_2 = platform_2.GetComponentInChildren <ObjectRotation>();
 }
コード例 #18
0
 public void Initialise(RoomObjectBlueprint roomObjectBlueprint, ObjectRotation roomObjectRotation, Room parentRoom)
 {
     RoomObjectBlueprint = roomObjectBlueprint;
     RoomObjectRotation  = roomObjectRotation;
     ParentRoom          = parentRoom;
 }
コード例 #19
0
    // check all tiles where the plot would be drawn if the building tile is available. Only draw a plot when all tiles are available
    public bool GetPlotIsAvailable(RoomBlueprint roomBlueprint, Vector2 roomStartingPoint, ObjectRotation roomRotation)
    {
        int rightUpAxisLength = roomRotation == ObjectRotation.Rotation0 || roomRotation == ObjectRotation.Rotation180 ?
                                roomBlueprint.RightUpAxisLength : roomBlueprint.LeftUpAxisLength;
        int leftUpAxisLength = roomRotation == ObjectRotation.Rotation0 || roomRotation == ObjectRotation.Rotation180 ?
                               roomBlueprint.LeftUpAxisLength : roomBlueprint.RightUpAxisLength;
        Vector2 plotLocationStartingPoint = GridHelper.GridToVectorLocation(roomStartingPoint, 0, 0);
        Vector2 point1 = GridHelper.GridToVectorLocation(plotLocationStartingPoint, rightUpAxisLength, 0);
        Vector2 point2 = GridHelper.GridToVectorLocation(point1, 0, -leftUpAxisLength);
        Vector2 point3 = GridHelper.GridToVectorLocation(point2, -rightUpAxisLength, 0);

        List <BuildingTile> roomSquareTiles = _builderManager.BuildingTiles.FindAll(tile =>
                                                                                    tile.StartingPoint.x >= point3.x &&
                                                                                    tile.StartingPoint.x <= point1.x &&
                                                                                    tile.StartingPoint.y <= point2.y &&
                                                                                    tile.StartingPoint.y >= plotLocationStartingPoint.y
                                                                                    );

        BuildingTile startingTile = roomSquareTiles.FirstOrDefault(t => t.StartingPoint == plotLocationStartingPoint);

        if (startingTile.IsAvailable == Availability.Unavailable)
        {
            return(false);
        }

        bool isAvailable = true;

        for (int i = 0; i <= rightUpAxisLength - 3; i += 3)
        {
            for (int j = 0; j <= leftUpAxisLength - 3; j += 3)
            {
                BuildingTile tile = GetBuildingTileForAvailability(i, j, plotLocationStartingPoint, roomSquareTiles);

                //if (i == 0 || i == rightUpAxisLength || j == 0 || j == leftUpAxisLength)
                //{
                //    // skip tiles that are at the edge because they may overlap with the walls of adjacent rooms
                //    continue;
                //}

                if (tile == null)
                {
                    Logger.Error(Logger.Building, "Could not find tile at {0}", GridHelper.GridToVectorLocation(plotLocationStartingPoint, i, -j));
                }

                if (tile.IsAvailable == Availability.Unavailable)
                {
                    isAvailable = false;
                    break;
                }
            }
        }

        return(isAvailable);
    }
コード例 #20
0
    /// <summary>
    /// Using the param tColRow, this function goes through all the objects in the given 10x10 sector and verifies if their position
    ///		is equal to tPos which is the current mouse position or mobile tap input position.
    /// If the player is trying to add a block and an object is found with the same position as tPos,
    ///		the player won't be able to add a new block since the spot is already taken.
    ///	If the player is trying to delete a block and an object is found with the same position as tPos,
    ///		the object will be deleted.
    /// </summary>
    /// <param name="tColRow">
    ///		This is 10x10 the sector in which the object to add / delete is in.
    ///		Used to reduce the load when parsing through existing objects since instead of going through all existing objects,
    ///			it only goes through a 10x10 section.
    /// </param>
    /// <param name="tPos">Position of the object to add / delete.</param>
    /// <param name="isAdd">Is the player trying to add a block or delete one.</param>
    private void AddDeleteTile(int[] tColRow, float[] tPos, bool isAdd)
    {
        Vector3 rotation = Vector3.zero;

        for (int i = 0; i < LevelManager.Instance.levelData.objectList[tColRow[0]][tColRow[1]].Count; i++)
        {
            if (LevelManager.Instance.levelData.objectList[tColRow[0]][tColRow[1]][i].transform.position == new Vector3(tPos[0], tPos[1], 0.0f))
            {
                if (isAdd)
                {
                    isAdd = false;
                    if (objType == 3 && objId == 7)
                    {
                        Tile tTile = LevelManager.Instance.serializedData.objectList[tColRow[0]][tColRow[1]][i];
                        if (tTile.type != 3 && tTile.type != 0)
                        {
                            LevelManager.Instance.DeleteObject(tColRow, i);
                            StartCoroutine(PassableEndFrame(tPos, tColRow, tTile.type, tTile.id));
                        }
                    }
                    else
                    {
                        if (LevelEditorInputs.Rotate())
                        {
                            int tRotation = ObjectRotation.GetObectRotation(LevelManager.Instance.levelData.objectList[tColRow[0]][tColRow[1]][i].name);
                            if (tRotation < 0)
                            {
                                //if(LevelManager.Instance.levelData.objectList[tColRow[0]][tColRow[1]][i].tag == "Enemies")
                                //	LevelManager.Instance.levelData.objectList[tColRow[0]][tColRow[1]][i].GetComponent<EnemyAI>().Flip();
                                //else {
                                rotation    = LevelManager.Instance.levelData.objectList[tColRow[0]][tColRow[1]][i].transform.localScale;
                                rotation.x *= tRotation;
                                LevelManager.Instance.levelData.objectList[tColRow[0]][tColRow[1]][i].transform.localScale  = rotation;
                                LevelManager.Instance.serializedData.objectList[tColRow[0]][tColRow[1]][i].horizontalMirror = (rotation.x < 0);
                                //}
                            }
                            else if (tRotation > 0)
                            {
                                rotation    = LevelManager.Instance.levelData.objectList[tColRow[0]][tColRow[1]][i].transform.localEulerAngles;
                                rotation.z += tRotation;
                                LevelManager.Instance.levelData.objectList[tColRow[0]][tColRow[1]][i].transform.localEulerAngles = rotation;
                                LevelManager.Instance.serializedData.objectList[tColRow[0]][tColRow[1]][i].rotation = rotation.z;
                            }
                            else if (LevelManager.Instance.serializedData.objectList[tColRow[0]][tColRow[1]][i].type == 4 &&
                                     LevelManager.Instance.serializedData.objectList[tColRow[0]][tColRow[1]][i].id == 11)
                            {
                                LevelManager.Instance.levelData.objectList[tColRow[0]][tColRow[1]][i].transform.GetChild(0).gameObject.SetActive(true);
                            }
                        }
                    }
                }
                else
                {
                    LevelManager.Instance.DeleteObject(tColRow, i);
                }
            }
        }
        if (isAdd)
        {
            if (objType == 3 && objId == 9)
            {
                SetCursor(true);
                glitchUI.TeleportUI(tPos);
            }
            else if (objType != 3 || objId != 7)
            {
                LevelManager.Instance.AddObject(tPos, tColRow, objType, objId);
            }
        }
    }
コード例 #21
0
 public static void Update(this ObjectRotation rotation, Rotator partial)
 {
     rotation.Pitch = partial.Pitch;
     rotation.Yaw   = partial.Yaw;
     rotation.Roll  = partial.Roll;
 }
コード例 #22
0
 private void Awake()
 {
     _camera         = Camera.main;
     _objectRotation = FindObjectOfType <ObjectRotation>();
     _zoomController = FindObjectOfType <ZoomController>();
 }
コード例 #23
0
    public void BuildRoom(RoomBlueprint roomBlueprint, BuildingTileBuilder buildingTileBuilder, BuildingPlotBuilder buildingPlotBuilder, Vector2 startingPoint, ObjectRotation roomRotation)
    {
        GameObject roomGO = GameManager.Instance.InstantiatePrefab(BuilderManager.Instance.RegisteredRoomPrefabs[roomBlueprint.RoomName][roomRotation], BuilderManager.Instance.RoomsContainer.transform, startingPoint);

        Room room = roomGO.GetComponent <Room>();

        room.RoomRotation  = roomRotation;
        room.RoomBlueprint = roomBlueprint;
        room.Initialise();
        room.RoomObjectsContainer.InitialiseRoomObjects();
        RoomManager.Instance.AddRoom(room);

        int rightUpAxisLength = roomRotation == ObjectRotation.Rotation0 || roomRotation == ObjectRotation.Rotation180 ?
                                roomBlueprint.RightUpAxisLength : roomBlueprint.LeftUpAxisLength;
        int leftUpAxisLength = roomRotation == ObjectRotation.Rotation0 || roomRotation == ObjectRotation.Rotation180 ?
                               roomBlueprint.LeftUpAxisLength : roomBlueprint.RightUpAxisLength;

        Vector2 point1 = GridHelper.GridToVectorLocation(startingPoint, rightUpAxisLength, 0);
        Vector2 point2 = GridHelper.GridToVectorLocation(point1, 0, -leftUpAxisLength);
        Vector2 point3 = GridHelper.GridToVectorLocation(point2, -rightUpAxisLength, 0);

        Dictionary <Direction, Vector2> roomCorners = new Dictionary <Direction, Vector2>()
        {
            { Direction.Down, startingPoint },
            { Direction.Right, point1 },
            { Direction.Up, point2 },
            { Direction.Left, point3 },
        };

        room.SetupCorners(roomCorners);
        room.SetupCollider();
        room.SetGraphUpdateScenePoints();

        // the sprites should already be part of the room prefab. The scripts should be on the sprites. But on start() of the room, all scripts should be initalised and added to the room's []
        //room.SetupRoomObjects();

        buildingTileBuilder.UpdateBuildingTiles(room);

        FollowUpRoomBuilding(roomBlueprint, roomCorners, buildingPlotBuilder);
        room.UpdateRoomNavhMesh();
    }
コード例 #24
0
 public void BuildRoom(RoomBlueprint roomBlueprint, Vector2 startingPoint, ObjectRotation roomRotation)
 {
     _roomBuilder.BuildRoom(roomBlueprint, _buildingTileBuilder, _buildingPlotBuilder, startingPoint, roomRotation);
 }