Пример #1
0
    public override void OnInspectorGUI()
    {
        EnvironmentElement element = (EnvironmentElement)target;


        if (GUILayout.Button("ApplyToTilemap", GUILayout.Width(200)))
        {
            if (element.tile != null)
            {
                element.tile.SetOccupied(false);
                EditorUtility.SetDirty(element.tile);
            }


            Vector3 pos = element.transform.position;
            pos.y -= 0.1f;
            GameObject collider = M_GameHelper.SGetObjectAtWorldPoint(pos);

            Tile tile = collider.transform.parent.gameObject.GetComponent <Tile>();

            if (tile != null)
            {
                pos   = tile.gameObject.transform.position;
                pos.y = M_MapManager.SGetYDepthValue(pos.z);
                element.transform.position = pos;
                element.tile = tile;
                tile.SetOccupied(true);
                EditorUtility.SetDirty(element);
                EditorUtility.SetDirty(element.tile);
            }
        }
    }
Пример #2
0
 public override void Draw(SpriteBatch sprite_batch)
 {
     for (int i = 0; i < this.Items.Count; i++)
     {
         float layer = (int)H_Drawing.DrawLayers.Foreground / 100.0f + M_MapManager.GetWorldDepth(this.Items[i].Position);
         H_Drawing.DrawSprite(sprite_batch, this.Items[i].Icon, this.Items[i].Position, layer);
     }
 }
Пример #3
0
 /// <summary>
 /// Updates the game variables and managers.
 /// </summary>
 /// <param name="gameTime"></param>
 protected override void Update(GameTime gameTime)
 {
     M_InputManager.Update();
     M_MapManager.Update();
     M_PartyManager.Update();
     M_MenuManager.Update();
     M_MapManager.Update();
     base.Update(gameTime);
 }
Пример #4
0
 /// <summary>
 /// Initalizes the objects and managers in the game.
 /// </summary>
 protected override void Initialize()
 {
     base.Initialize();
     M_ContentManager.Init(Content);
     M_GlobalManager.Init();
     M_TextManager.Init();
     M_InputManager.Init();
     M_PartyManager.Init();
     M_MenuManager.Init();
     I_Inventory.Init();
     M_MapManager.Init();
 }
Пример #5
0
        /// <summary>
        /// Main draw call for the GPU.
        /// </summary>
        /// <param name="gameTime"></param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.White);

            sprite_batch.Begin(SpriteSortMode.FrontToBack);
            M_MapManager.Draw(sprite_batch);
            M_PartyManager.Draw(sprite_batch);
            M_MenuManager.Draw(sprite_batch);
            M_MapManager.Draw(sprite_batch);
            sprite_batch.End();

            base.Draw(gameTime);
        }
Пример #6
0
    public void FixedUpdate()
    {
        if (m_tempBuildingObj == null)
        {
            return;
        }

        Vector3 pos = m_tempBuildingObj.transform.position;

        pos.y -= 0.1f;
        GameObject collider = M_GameHelper.SGetObjectAtWorldPoint(pos);

        if (collider != null)
        {
            if (m_currentMiddleTile != collider.transform.parent.gameObject || m_currentMiddleTile == null)
            {
                foreach (Tile obj in m_tilesHighlighted)
                {
                    obj.HighlightOccupied(false);
                }
                m_tilesHighlighted.Clear();
                m_currentMiddleTile = collider.transform.parent.gameObject;

                Tile tile = collider.transform.parent.gameObject.GetComponent <Tile>();
                if (tile == null)
                {
                    return;
                }

                BuildingPhysics physics = m_tempBuildingComp.GetPhysics();
                bool[]          area    = physics.GetArea();
                int             middleI = physics.GetWidth() / 2;
                int             middleJ = physics.GetHeight() / 2;

                for (int i = 0; i < physics.GetWidth(); i++)
                {
                    for (int j = 0; j < physics.GetHeight(); j++)
                    {
                        int  tempI    = tile.i - (middleI - i);
                        int  tempJ    = tile.j - (middleJ - j);
                        Tile tempTile = M_MapManager.SGetTileObject(tempI, tempJ).GetComponent <Tile>();
                        tempTile.HighlightOccupied(true);
                        m_tilesHighlighted.Add(tempTile);
                    }
                }
            }
        }
    }
Пример #7
0
    /// <summary> Function called when Building is supposed to be placed. </summary>
    private void OnBuildingBuildIconClick()
    {
        // check whether the place is not occupied.
        foreach (Tile tile in m_tilesHighlighted)
        {
            if (tile.IsOccupied())
            {
                return;
            }
        }

        UT_Pair <int, int> cost = M_BuildingManager.SGetBuildingCost(m_tempBuildingComp.GetData().id);

        // Apply cost to the resources
        M_InGameResourcesManager.SAddFood(-cost.first);
        M_InGameResourcesManager.SAddResearch(-cost.second);

        // Mark highlighted tiles as occupied
        foreach (Tile tile in m_tilesHighlighted)
        {
            tile.SetOccupied(true);
            tile.Highlight(false);
        }
        // set final building position
        Vector3 pos = m_currentMiddleTile.transform.position;

        pos.y = M_MapManager.SGetYDepthValue(pos.z);
        m_tempBuildingObj.transform.position = pos;
        // Move to the BUILDINGS group
        M_GameHelper.AddToGroup(m_tempBuildingObj, M_GameHelper.Group.BUILDINGS);

        m_tempBuildingComp.SetActionOnBuildingFinished(ActionOnBuildingFinished);
        // Start in-game building process
        m_tempBuildingComp.StartBuilding();


        m_onBuildingPlacedAction(m_tempBuildingComp);

        // reset values
        m_tempBuildingObj.GetComponent <IBuilding>().GetBuildButton().SetActive(false);
        m_tempBuildingObj   = null;
        m_tempBuildingComp  = null;
        m_currentMiddleTile = null;
        m_tilesHighlighted.Clear();
        M_MiscManager.ShowCancelButton(false);
    }
Пример #8
0
    /// <summary>
    /// Starts building process.
    /// Building is supposed to be placed.
    /// </summary>
    public void StartBuilding(DAT_Building buildingData)
    {
        // prepare position (middle of a screen) and instantiate
        Vector3 pos = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, Camera.main.nearClipPlane));

        pos.y = M_MapManager.SGetHighYDepthValue(pos.z); // set appropriate depth value. (Building has to be above every other obj)
        // Instantiate new building in the TEMP group.
        m_tempBuildingObj  = buildingData.InstantiateBuilding(pos, M_GameHelper.Group.TEMP);
        m_tempBuildingComp = m_tempBuildingObj.GetComponent <IBuilding>();
        // Get build button and activate it.
        m_tempBuildingComp.GetBuildButton().GetComponent <Button>().onClick.AddListener(OnBuildingBuildIconClick);
        m_tempBuildingComp.GetBuildButton().SetActive(true);

        M_MiscManager.RemoveListenersCancelButton();
        M_MiscManager.AddListenerCancelButton(QuitBuilding);
        M_MiscManager.ShowCancelButton(true);
    }
Пример #9
0
        /// <summary>
        /// Draws the character to the screen.
        /// </summary>
        /// <param name="sprite_batch">The sprite batch reference.</param>
        public override void Draw(SpriteBatch sprite_batch)
        {
            UpdateAnimationFrame();

            //Old drawing, no layer inclusion
            //sprite_batch.Draw
            //(
            //    texture: SpriteSheet,
            //    sourceRectangle: new Rectangle(current_frame * sprite_width, (int)direction * sprite_height, sprite_width, sprite_height),
            //    color: Color.White,
            //    position: Helpers.H_Math.VectorLevel(Position)
            //);

            Rectangle cutout       = new Rectangle(current_frame * sprite_width, (int)direction * sprite_height, sprite_width, sprite_height);
            Vector2   new_position = Helpers.H_Math.VectorLevel(Position);
            float     layer        = ((int)this.DrawLayer / 100.0f) + M_MapManager.GetWorldDepth(GetCenterpoint());

            sprite_batch.Draw(SpriteSheet, new_position, cutout, Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, layer);
        }
Пример #10
0
    void Start()
    {
        Debug.Log("GameHelper -> Start()");
        s_instance = this;

        m_camController = Camera.main.GetComponent <CameraController>();
        if (m_camController == null)
        {
            Debug.LogWarning("Couldn't get CameraController from Camera.main!");
        }

        if (dayText == null || foodText == null || researchText == null)
        {
            Debug.LogWarning("One of the TMP_Text objects is not initialized.");
        }
        else
        {
            m_resourcesManager = M_InGameResourcesManager.GetInstance(foodText, dayText, researchText);
        }

        m_buildingManager = M_BuildingManager.Instance;
        m_mapManager      = M_MapManager.Instance;
        m_settlersManager = M_SettlersManager.Instance;
        m_inputManager    = M_InputManager.Instance;
        m_waresManager    = M_WaresManager.Instance;
        m_saveManager     = M_SaveManager.Instance;

        // Load level
        GameObject menuManager = GameObject.FindGameObjectWithTag("MenuManager");

        if (menuManager != null)
        {
            SceneLoader sceneLoader = menuManager.GetComponent <SceneLoader>();
            if (sceneLoader != null)
            {
                if (sceneLoader.gameData == null)
                {
                    LoadLevel(defaultGameData);
                }
                else
                {
                    LoadLevel(sceneLoader.gameData);
                }


                if (sceneLoader.saveId > 0)
                {
                    LoadSave(sceneLoader.saveId);
                }
            }
            else
            {
                Debug.LogWarning("Cannot find " + typeof(SceneLoader).Name + " component!");
            }
        }
        else
        { // Only if we started from Game scene, because MenuManager hasn't been initialized.
            if (defaultGameData != null)
            {
                Debug.LogWarning("Loading using default data .");
                LoadLevel(defaultGameData);
            }
            else
            {
                Debug.LogWarning("Couldn't find either MenuManager or default DAT_Game!");
            }
        }
        ResumeGame();
    }
Пример #11
0
    public void Update()
    {
        switch (SystemInfo.deviceType)
        {
        case DeviceType.Desktop:
            m_currentTrackedModel = M_GameHelper.SGetObjectAtScreenPoint(Input.mousePosition);
            break;

        case DeviceType.Handheld:
            if (Input.touchCount > 0)
            {
                m_currentTrackedModel = M_GameHelper.SGetObjectAtScreenPoint(Input.GetTouch(0).position);
            }
            break;
        }

        if (m_processing)
        {
            m_freezeTimeElapsed += Time.deltaTime;
        }

        if (m_freezeTimeElapsed > CLICK_TIME)
        {
            switch (SystemInfo.deviceType)
            {
            case DeviceType.Desktop:

                if (m_leftButtonDown)
                {
                    m_leftButtDownTimeElapsed += Time.deltaTime;
                }


                if (Input.GetMouseButtonDown(0)) // On Start
                {
                    m_leftButtDownTimeElapsed = 0f;
                    m_leftButtonDown          = true;
                    m_draggingCandidate       = m_currentTrackedModel;

                    // Examine if object should be clicked. if not then skip to dragging examination.
                    if (m_currentTrackedModel != null)
                    {
                        ClickableObject clickable = m_currentTrackedModel.GetComponent <ClickableObject>();
                        DraggableObject draggable = m_currentTrackedModel.GetComponent <DraggableObject>();
                        if (clickable != null && clickable.disabled && draggable != null && draggable.draggingEnabled)
                        {
                            m_leftButtDownTimeElapsed = CLICK_TIME * 2;
                            CameraController.SSetOverallMovement(false);
                            m_currentDraggedObject = m_currentTrackedModel.gameObject.transform.parent.gameObject;
                        }
                    }
                    //
                }
                else if (Input.GetMouseButtonUp(0) && m_leftButtDownTimeElapsed < CLICK_TIME)   // OnClick
                {
                    if (m_currentTrackedModel != null)
                    {
                        ClickableObject comp = m_currentTrackedModel.transform.parent.gameObject.GetComponent <ClickableObject>();
                        if (comp != null)
                        {
                            comp.OnClick();
                        }
                    }
                    m_leftButtonDown          = false;
                    m_leftButtDownTimeElapsed = 0f;
                    m_currentTrackedModel     = null;
                    m_draggingCandidate       = null;
                }
                else if (Input.GetMouseButtonUp(0) && m_leftButtDownTimeElapsed > CLICK_TIME)   // End of dragging
                {
                    m_leftButtonDown          = false;
                    m_leftButtDownTimeElapsed = 0f;
                    m_currentDraggedObject    = null;
                }


                // Examine for dragging
                if (m_currentDraggedObject == null && m_leftButtDownTimeElapsed > CLICK_TIME)
                {
                    // get a parent object
                    if (m_draggingCandidate != null)
                    {
                        m_currentDraggedObject     = m_draggingCandidate.transform.parent.gameObject;
                        m_currentDraggedObjectComp = m_currentDraggedObject.GetComponent <DraggableObject>();
                        if (!(m_currentDraggedObjectComp != null && m_currentDraggedObjectComp.draggingEnabled))
                        {
                            m_currentDraggedObject = null;
                        }
                        m_draggingCandidate = null;
                    }
                }
                else if (m_currentDraggedObject != null)     // Dragging
                {
                    Vector3 temp = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    if (m_currentDraggedObjectComp.keepHighYDepthValue)
                    {
                        temp.y = M_MapManager.SGetHighYDepthValue(temp.z);
                    }
                    else
                    {
                        temp.y = M_MapManager.SGetYDepthValue(temp.z);
                    }
                    m_currentDraggedObject.transform.position = temp;
                }
                break;

            // ------- Handheld --------
            case DeviceType.Handheld:

                StringBuilder stringBuilder = new StringBuilder();

                if (m_leftButtonDown)
                {
                    m_leftButtDownTimeElapsed += Time.deltaTime;
                }


                // Examine for dragging
                if (m_currentDraggedObject == null && m_leftButtDownTimeElapsed > CLICK_TIME)
                {
                    // get a parent object
                    if (m_draggingCandidate != null)
                    {
                        m_currentDraggedObject     = m_draggingCandidate.transform.parent.gameObject;
                        m_currentDraggedObjectComp = m_currentDraggedObject.GetComponent <DraggableObject>();
                        if (!(m_currentDraggedObjectComp != null && m_currentDraggedObjectComp.draggingEnabled))
                        {
                            m_currentDraggedObject = null;
                        }
                        else
                        {
                            CameraController.SSetOverallMovement(false);
                        }
                        m_draggingCandidate = null;
                    }
                }



                if (m_processing)
                {
                    m_freezeTimeElapsed += Time.deltaTime;
                }

                if (m_freezeTimeElapsed > CLICK_TIME)
                {
                    if (Input.touchCount > 0)
                    {
                        Touch touch = Input.GetTouch(0);

                        switch (touch.phase)
                        {
                        case TouchPhase.Began:
                            stringBuilder.AppendLine("Began: " + touch.position);

                            m_leftButtDownTimeElapsed = 0f;
                            m_leftButtonDown          = true;
                            m_draggingCandidate       = m_currentTrackedModel;

                            // Examine if object should be clicked. if not then skip to dragging examination.
                            if (m_currentTrackedModel != null)
                            {
                                ClickableObject clickable = m_currentTrackedModel.GetComponent <ClickableObject>();
                                DraggableObject draggable = m_currentTrackedModel.GetComponent <DraggableObject>();
                                if (clickable != null && clickable.disabled && draggable != null && draggable.draggingEnabled)
                                {
                                    m_leftButtDownTimeElapsed = CLICK_TIME * 2;
                                    CameraController.SSetOverallMovement(false);
                                    m_currentDraggedObject = m_currentTrackedModel.gameObject.transform.parent.gameObject;
                                }
                            }
                            //

                            break;

                        case TouchPhase.Moved:
                            stringBuilder.AppendLine("Moved: " + touch.position);

                            if (m_currentDraggedObject != null)         // Dragging
                            {
                                Vector3 temp = Camera.main.ScreenToWorldPoint(touch.position);
                                if (m_currentDraggedObjectComp.keepHighYDepthValue)
                                {
                                    temp.y = M_MapManager.SGetHighYDepthValue(temp.z);
                                }
                                else
                                {
                                    temp.y = M_MapManager.SGetYDepthValue(temp.z);
                                }
                                m_currentDraggedObject.transform.position = temp;
                            }

                            break;

                        case TouchPhase.Ended:
                            stringBuilder.AppendLine("Ended: " + touch.position);

                            if (m_leftButtDownTimeElapsed < CLICK_TIME)     // OnClick
                            {
                                if (m_currentTrackedModel != null)
                                {
                                    ClickableObject comp = m_currentTrackedModel.transform.parent.gameObject.GetComponent <ClickableObject>();
                                    if (comp != null)
                                    {
                                        comp.OnClick();
                                    }
                                }
                                m_leftButtonDown          = false;
                                m_leftButtDownTimeElapsed = 0f;
                                m_currentTrackedModel     = null;
                                m_draggingCandidate       = null;
                            }
                            else       // End of dragging
                            {
                                m_leftButtonDown          = false;
                                m_leftButtDownTimeElapsed = 0f;
                                m_currentDraggedObject    = null;
                                CameraController.SSetOverallMovement(true);
                            }
                            break;
                        }
                    }
                    else
                    {
                        stringBuilder.AppendLine("No touch");
                    }
                }

                stringBuilder.AppendLine("CurrentDraggedObject: " + (m_currentDraggedObject == null ? "NULL" : m_currentDraggedObject.name));
                stringBuilder.AppendLine("CurrentTrackedModel: " + (m_currentTrackedModel == null ? "NULL" : m_currentTrackedModel.name));
                stringBuilder.AppendLine("DraggingCandidate " + (m_draggingCandidate == null ? "NULL" : m_draggingCandidate.name));
                M_GameHelper.debugText = stringBuilder.ToString();
                break;
            }
        }
    }