Пример #1
0
        public virtual void Set(LevelBackgroundData data, LevelBackgroundData.ElementData element, int index)
        {
            this.Element = element;

            SortingGroup.sortingLayerName = "Background"; //TODO, don't hard code
            SortingGroup.sortingOrder     = index;

            Bounds = Tools.Bounds.FromRenderer(element.Prefab);

            Panels = new GameObject[data.Copies];

            var totalWidth = Bounds.size.x * (Panels.Length - 1);

            for (int i = 0; i < Panels.Length; i++)
            {
                var panel = Instantiate(element.Prefab, transform);

                panel.name = element.Prefab.name + " " + (i + 1).ToString();

                var rate = i / (Panels.Length - 1f);

                panel.transform.localPosition = new Vector3(Mathf.Lerp(-totalWidth / 2f, totalWidth / 2f, rate), 0f, 0f);
            }
        }
Пример #2
0
        public virtual LevelBackgroundTemplate CreateTemplate(LevelBackgroundData data, LevelBackgroundData.ElementData element, int index)
        {
            var instance = new GameObject(element.Prefab.name);

            instance.transform.SetParent(transform);

            instance.transform.localPosition    = Vector3.zero;
            instance.transform.localEulerAngles = Vector3.zero;
            instance.transform.localScale       = Vector3.one;

            var script = instance.AddComponent <LevelBackgroundTemplate>();

            script.Init();
            script.Set(data, element, index);

            return(script);
        }