Exemple #1
0
    void Awake()
    {
        bg = new BuildingGrid(10, 10, BuildingScale);
        GameObject activeBuildingController = new GameObject("BuildingItemController");

        ActiveBuildingController = activeBuildingController.AddComponent <BuildingItemController>();
    }
    public static GameObject CreateGhost(GameObject original, out BuildingGrid grid)
    {
        GameObject ghost = GameObject.Instantiate(original) as GameObject;

        ghost.name  = original.name;
        ghost.layer = GameManager.GhostsLayer;
        grid        = null;

        switch (original.tag)
        {
        case Tags.Unit:
            break;

        case Tags.Building:
        {
            grid = ghost.GetComponent <BuildingGrid>();
            if (grid == null)
            {
                Debug.LogError("Object must contain BuildingGrid script");
            }
            grid.IsGhost = true;
        }
        break;

        default:
            Debug.LogError(string.Format("Tag {0} or {1} is not set", Tags.Unit, Tags.Building));
            break;
        }

        return(ghost);
    }
 public void SetNewBuildItem(GameObject _ItemToPlace, float _Scale, BuildingGrid _Grid)
 {
     OriginalItemToPlace = _ItemToPlace;
     ItemToPlace         = Instantiate(_ItemToPlace);
     SetLayerOnChildren(ItemToPlace, LayerMask.NameToLayer("PlacingObject"));
     Scale         = _Scale;
     grid          = _Grid;
     SavedRotation = 0;
 }
    public static void KillObject(Transform obj, float destroyTime)
    {
        //удаление объекта из списка выделенных объектов каждого игрока
        foreach (Player player in GameManager.Players)
        {
            HumanPlayer humanPlayer = player as HumanPlayer;
            if (humanPlayer != null)
            {
                humanPlayer.ObjectSelector.RemoveFromSelectedObjectList(obj);
            }
        }
        //transform.parent = null;
        RemoveFromPlayerObjectList(obj);
        obj.gameObject.layer = GameManager.DefaultLayer;//ставим layer по умолчанию, чтобы объект больше не влиял на игровой мир

        IKillable AI = obj.GetInterfaceComponent <IKillable>();

        if (AI != null)
        {
            AI.Die();
        }

        UnitFactory unitFactory = obj.GetComponent <UnitFactory>();

        if (unitFactory != null)
        {
            Object.Destroy(unitFactory);
        }

        BuildingGrid grid = obj.GetComponent <BuildingGrid>();

        if (grid != null)
        {
            Object.Destroy(grid);
        }

        Rigidbody rb = obj.rigidbody;

        if (rb != null)
        {
            rb.isKinematic = true;
            Object.Destroy(rb);
        }

        Collider c = obj.collider;

        if (c != null)
        {
            c.enabled = false; //Object.Destroy(c);
        }
        Object.Destroy(obj.gameObject, destroyTime);
    }
    public void StartPlacing(BuildingGrid grid, int price)
    {
        _player.ObjectSelector.Deselect();
        _player.CursorState     = CursorStates.Placing;
        grid.transform.position = new Vector3(0.0f, -10000f, 0.0f);//установка созданного объекта в позицию, невидимую для игроков.

        PlaceableObjectGrid  = grid;
        PlaceableObjectPrice = price;

        PlaceableObjectGrid.collider.isTrigger = true;//отключаем влиения объекта на физику в игре

        //Отключение AI, если есть
        var objectAI = PlaceableObjectGrid.GetComponent <BaseObjectAI>();

        if (objectAI != null)
        {
            objectAI.enabled = false;
        }

        _materialChanger = PlaceableObjectGrid.GetComponent <MaterialChanger>();
        if (_materialChanger != null)
        {
            _materialChanger.SetTransparent(0.6f);
        }

        //добавляем Rigidbody для работы с методами OnTrigger, OnCollision в BuildingGrid
        var objectRigidbody = PlaceableObjectGrid.GetComponent <Rigidbody>();

        if (objectRigidbody == null)
        {
            _hasDefaultRigidbody        = false;
            objectRigidbody             = grid.gameObject.AddComponent <Rigidbody>();
            objectRigidbody.isKinematic = true;
        }
        else
        {
            _hasDefaultRigidbody = true;
        }

        _placingMode = true;
    }
Exemple #6
0
    void Awake()
    {
        _this = this;

        BuildingGrid.SetActive(false);
    }