Пример #1
0
    //private static GameObject _tmpStub;//Заглушка для плавной анимации перетаскивания
    //private static Animator _stubAnimator;


    //private GameObject m_DraggingIcon;
    //private RectTransform m_DraggingPlane;

    //___________________________________
    /// <summary>
    /// Фабричный метод
    /// 1) находит нужный префаб и род.объект, куда его цеплять (если соответствующие стат.поля ==null)
    /// 2) создает новый GameObject из префаба, проставляет ему род.объект, привязывает к нему SBuilding из входного параметра
    /// 3) находит или генерит анимированную заглушку для плавного перемещения объектов в очереди (если у класс уже её не хранит)
    /// </summary>
    /// <param name="info"></param>
    /// <returns></returns>
    public static GameObject InstantiateQueueElement(/*BuildingInProgressInfo*/ IInProgressInfo info /*SBuilding myBuilding*/)
    {
        //1) находит нужный префаб и куда его цеплять
        if (_queuePrefab == null)
        {
            _queuePrefab = Resources.Load <GameObject>("_default_queueLine");
        }
        if (_content == null)
        {
            _content = CityGUIManager.creationQueue;
        }
        //_content = GameObject.Find("QueueContent");

        //2) создает новый GameObject из префаба, проставляет ему род.объект, привязывает к нему SBuilding из входного параметра
        GameObject           result          = Instantiate(_queuePrefab, _content.transform);
        CreationQueueElement tmpQueueElement = result.GetComponent <CreationQueueElement>();

        tmpQueueElement._progressBar     = result.GetComponentInChildren <Slider>();
        tmpQueueElement._turnsToComplete = result.transform.Find("TurnsToComplete").GetComponent <Text>();
        tmpQueueElement._progressInfo    = info;

        tmpQueueElement._progressBar.value    = tmpQueueElement._progressInfo.ProgressPercent;
        tmpQueueElement._turnsToComplete.text = tmpQueueElement._progressInfo.StepToComplete.ToString();

        if (tmpQueueElement._progressInfo == null)
        {
            Debug.Log("Всё плохо");
        }
        else
        {
            Debug.Log(tmpQueueElement._progressInfo.ToString());
        }
        //tmpQueueElement.building = myBuilding;
        //tmpQueueElement.

        //CreationQueueElement queueElement = where.AddComponent<CreationQueueElement>();

        //3) находит или генерит анимированную заглушку для плавного перемещения объектов в очереди(если у класс уже её не хранит)
        //if (_tmpStub == null)//сначала ищем по иерархии
        //    _tmpStub = GameObject.Find("tmpStub");
        //if (_tmpStub == null)//если Find не нашел объект, создадим ручками из префаба
        //    _tmpStub = Instantiate(Resources.Load<GameObject>("tmpStub"), _content.transform);

        //if (_stubAnimator == null)
        //    _stubAnimator = _tmpStub.GetComponent<Animator>();
        //_tmpStub.transform.SetAsLastSibling();

        return(result);
    }
    void InstantiateBuildingsInProgress(City city)
    {
        //Debug.Log(city.ToString());
        if (_displayedQueueElements != null)
        {
            foreach (GameObject gObj in _displayedQueueElements)
            {
                Destroy(gObj);
            }
            _displayedQueueElements.Clear();
        }   //зачистим список
        else
        {
            _displayedQueueElements = new List <GameObject>();
        }

        List <BuildingInProgressInfo> buildingInfoList = city.BuildingSystem.GetBuildingOrderForCity();

        foreach (BuildingInProgressInfo info in buildingInfoList)
        {
            _displayedQueueElements.Add(CreationQueueElement.InstantiateQueueElement(info));
        }
    }