예제 #1
0
 public void DeselectTile()
 {
     selectedObject = null;
     selectedIcon.transform.parent = null;
     selectedIcon.SetActive(false);
     if (taskActionBarInstance)
     {
         Destroy(taskActionBarInstance.gameObject);
     }
     if (buildingActionBarInstance)
     {
         Destroy(buildingActionBarInstance.gameObject);
     }
     if (wallActionBarInstance)
     {
         Destroy(wallActionBarInstance.gameObject);
     }
     if (factoryActionBarInstance)
     {
         Destroy(factoryActionBarInstance.gameObject);
     }
     if (haulableActionBarInstance)
     {
         Destroy(haulableActionBarInstance.gameObject);
     }
 }
예제 #2
0
 // Called on events that should destroy the menu
 void DestroyMenus(TaskableBase taskable)
 {
     if (taskable == selectedObject)
     {
         DeselectTile();
     }
 }
예제 #3
0
    public void SelectTile(TaskableBase tile)
    {
        DeselectTile();

        selectedObject = tile;
        selectedIcon.SetActive(true);
        selectedIcon.transform.parent   = selectedObject.transform;
        selectedIcon.transform.position = selectedObject.transform.position;

        BuildingBase buildingObject = tile.GetComponent <BuildingBase>();
        WallBase     wallObject     = tile.GetComponent <WallBase>();
        HaulableBase haulObject     = tile.GetComponent <HaulableBase>();

        if (buildingObject)
        {
            if (buildingObject.currentTask)
            {
                taskActionBarInstance = Instantiate(taskActionBarPrefab, transform);
                taskActionBarInstance.Setup(buildingObject);
            }
            else
            {
                buildingActionBarInstance = Instantiate(buildingActionBarPrefab, transform);
                buildingActionBarInstance.Setup(buildingObject);

                FactoryBase factoryObject = buildingObject.GetComponent <FactoryBase>();
                if (factoryObject)
                {
                    factoryActionBarInstance = Instantiate(factoryActionBarPrefab, transform);
                    factoryActionBarInstance.Setup(factoryObject);
                }
            }
        }
        else if (wallObject)
        {
            if (wallObject.currentTask)
            {
                taskActionBarInstance = Instantiate(taskActionBarPrefab, transform);
                taskActionBarInstance.Setup(wallObject);
            }
            else
            {
                wallActionBarInstance = Instantiate(wallActionBarPrefab, transform);
                wallActionBarInstance.Setup(wallObject);
            }
        }
        else if (haulObject)
        {
            if (haulObject.currentTask)
            {
                taskActionBarInstance = Instantiate(taskActionBarPrefab, transform);
                taskActionBarInstance.Setup(haulObject);
            }
            else
            {
                haulableActionBarInstance = Instantiate(haulableActionBarPrefab, transform);
                haulableActionBarInstance.Setup(haulObject);
            }
        }
    }
예제 #4
0
    public void Setup(TaskableBase taskable)
    {
        this.taskable = taskable;
        prioritizeButton.onClick.AddListener(() => PrioritizeAction());
        cancelButton.onClick.AddListener(() => CancelAction());

        RefreshUI();
    }
예제 #5
0
    public static void TriggerEvent(string eventName, TaskableBase location)
    {
        TileEvent thisEvent = null;

        if (instance.tileEventDictionary.TryGetValue(eventName, out thisEvent))
        {
            thisEvent.Invoke(location);
        }
    }
예제 #6
0
    void CheckWallDestroyed(TaskableBase destroyedObject)
    {
        WallBase wall = destroyedObject.GetComponent <WallBase>();

        if (wall)
        {
            if (TilemapManager.instance.wallTilemap.WorldToCell(wall.transform.position) ==
                TilemapManager.instance.depositTilemap.WorldToCell(this.transform.position))
            {
                DestroySelf();
            }
        }
    }
예제 #7
0
    public void CheckForNewSpawner(TaskableBase tileBase)
    {
        Vector3Int location = TilemapManager.instance.wallTilemap.WorldToCell(tileBase.transform.position);
        GameObject locObj   = TilemapManager.instance.floorTilemap.GetInstantiatedObject(location);

        if (locObj)
        {
            EnemySpawner enemySpawner = locObj.GetComponent <EnemySpawner>();
            if (enemySpawner)
            {
                spawnPoints.Add(enemySpawner);
            }
        }
    }
예제 #8
0
    // Extends the camera bounds to include the given location
    void SetBounds(TaskableBase tileBase)
    {
        Vector3 location = tileBase.transform.position;

        if (location.x > topRight.x)
        {
            topRight = new Vector2(location.x, topRight.x);
        }
        if (location.y > topRight.y)
        {
            topRight = new Vector2(topRight.x, location.y);
        }
        if (location.x < bottomLeft.x)
        {
            bottomLeft = new Vector2(location.x, bottomLeft.y);
        }
        if (location.y < bottomLeft.y)
        {
            bottomLeft = new Vector2(bottomLeft.x, location.y);
        }
    }
예제 #9
0
 public virtual void Setup(TaskableBase target)
 {
     this.target             = target;
     this.transform.position = target.transform.position;
     EventManager.TriggerEvent("TaskCreated", target);
 }
예제 #10
0
 // For now just triggers a full recheck of the path, could make this smarter though
 public void UpdatePath(TaskableBase tileBase)
 {
     triggerPathRefresh = true;
 }
예제 #11
0
    // Called on events that should refresh the menu
    void RefreshMenus(TaskableBase taskable)
    {
        if (taskable && taskable == selectedObject)
        {
            if (taskable.currentTask)
            {
                // Create or update task action bar
                if (taskActionBarInstance)
                {
                    taskActionBarInstance.RefreshUI();
                }
                else
                {
                    taskActionBarInstance = Instantiate(taskActionBarPrefab, transform);
                    taskActionBarInstance.Setup(selectedObject);
                }

                // clean up building and wall action bars
                if (buildingActionBarInstance)
                {
                    Destroy(buildingActionBarInstance.gameObject);
                }
                if (wallActionBarInstance)
                {
                    Destroy(wallActionBarInstance.gameObject);
                }
                if (factoryActionBarInstance)
                {
                    Destroy(factoryActionBarInstance.gameObject);
                }
                if (haulableActionBarInstance)
                {
                    Destroy(haulableActionBarInstance.gameObject);
                }
            }
            else
            {
                // Clean up task action bar
                if (taskActionBarInstance)
                {
                    Destroy(taskActionBarInstance.gameObject);
                }

                // refresh building and wall action bars
                BuildingBase buildingObject = taskable.GetComponent <BuildingBase>();
                WallBase     wallObject     = taskable.GetComponent <WallBase>();
                HaulableBase haulObject     = taskable.GetComponent <HaulableBase>();
                if (buildingObject)
                {
                    if (buildingActionBarInstance)
                    {
                        buildingActionBarInstance.RefreshUI();
                    }
                    else
                    {
                        buildingActionBarInstance = Instantiate(buildingActionBarPrefab, transform);
                        buildingActionBarInstance.Setup(buildingObject);
                    }
                    FactoryBase factoryObject = buildingObject.GetComponent <FactoryBase>();
                    if (factoryObject)
                    {
                        if (factoryActionBarInstance)
                        {
                            factoryActionBarInstance.RefreshUI();
                        }
                        else
                        {
                            factoryActionBarInstance = Instantiate(factoryActionBarPrefab, transform);
                            factoryActionBarInstance.Setup(factoryObject);
                        }
                    }
                }
                else if (wallObject)
                {
                    if (wallActionBarInstance)
                    {
                        wallActionBarInstance.RefreshUI();
                    }
                    else
                    {
                        wallActionBarInstance = Instantiate(wallActionBarPrefab, transform);
                        wallActionBarInstance.Setup(wallObject);
                    }
                }
                else if (haulObject)
                {
                    if (haulableActionBarInstance)
                    {
                        haulableActionBarInstance.RefreshUI();
                    }
                    else
                    {
                        haulableActionBarInstance = Instantiate(haulableActionBarPrefab, transform);
                        haulableActionBarInstance.Setup(haulObject);
                    }
                }
            }
        }
    }
예제 #12
0
    ////////////////////
    // BUILD TRACKING //
    ////////////////////

    void AddBuildingToList(TaskableBase newBuilding)
    {
        buildingList.Add(newBuilding.GetComponent <BuildingBase>());
    }
예제 #13
0
 void RemoveBuildingFromList(TaskableBase oldBuilding)
 {
     buildingList.Remove(oldBuilding.GetComponent <BuildingBase>());
 }
예제 #14
0
 public override void Setup(TaskableBase target)
 {
     base.Setup(target);
     owner = target.GetComponent <BuildingBase>();
 }