Esempio n. 1
0
        public void Clear(Prefab prefab, bool clearSpawned = false)
        {
            if (!pools.ContainsKey(prefab))
            {
                return;
            }

            var pool = pools[prefab];

            pool.ForEachReverse(go =>
            {
                if (clearSpawned || (!go.activeInHierarchy && !go.activeSelf))
                {
#if UNITY_EDITOR
                    if (UnityEditor.EditorApplication.isPlaying)
                    {
                        GameObject.Destroy(go);
                    }
                    else
                    {
                        GameObject.DestroyImmediate(go);
                    }
#else
                    GameObject.Destroy(go);
#endif

                    pool.Remove(go);
                }
            });
        }
Esempio n. 2
0
        public void Recycle(GameObject target)
        {
            List <GameObject> pool = null;

            foreach (var kvp in pools)
            {
                var prefabPool = kvp.Value;

                if (prefabPool.Contains(target))
                {
                    pool = prefabPool;
                    break;
                }
            }

            if (pool != null)
            {
                target.SetActive(false);
                target.transform.SetParent(container.transform, true);
            }
            else
            {
                GameObject.Destroy(target);
            }
        }
Esempio n. 3
0
    private System.Collections.IEnumerator destroy()
    {
        /* TODO Play a VFX? */

        /* XXX: Forcefully move the entity away from any close entity before
         * destroying it, to avoid glitching the physics. */
        this.transform.position = new Vec3(0.0f, -10.0f, 0.0f);
        yield return(new UnityEngine.WaitForFixedUpdate());

        GO.Destroy(this.gameObject);
    }
        static void OnScriptReload()
        {
            var temp = new GameObject("Temp");

            try
            {
                var types = TypeUtility.AllTypes.Where(t => t.Is<MonoBehaviour>());

                foreach (var type in types)
                {
                    var attribute = type.GetAttribute<ExecutionOrderAttribute>(true);

                    if (attribute != null)
                    {
                        var behaviour = temp.AddComponent(type) as MonoBehaviour;
                        behaviour.SetExecutionOrder(attribute.Order);
                    }
                }
            }
            finally { temp.Destroy(); }
        }
Esempio n. 5
0
        public void Shrink(Prefab prefab, int maxSize, bool clearSpawned = false)
        {
            if (!pools.ContainsKey(prefab))
            {
                return;
            }

            var pool  = pools[prefab];
            var total = clearSpawned ? pool.Count : Count(prefab);

            pool.ForEachReverse(go =>
            {
                if (total <= maxSize)
                {
                    return;
                }

                if (!go.activeInHierarchy && !go.activeSelf)
                {
                    GameObject.Destroy(go);
                    pool.Remove(go);
                    --total;
                }
            });

            if (clearSpawned && total > maxSize)
            {
                pool.ForEachReverse(go =>
                {
                    if (total <= maxSize)
                    {
                        return;
                    }

                    GameObject.Destroy(go);
                    pool.Remove(go);
                    --total;
                });
            }
        }
Esempio n. 6
0
 public void Unload()
 {
     ClearAll(true);
     GameObject.Destroy(container);
 }
Esempio n. 7
0
    private void setupUi()
    {
        Transform   t;
        UiTransform parent;
        GO          template;
        GO          thumbTemplate;
        float       rowOffset;
        int         w, h;
        const Axis  vert = Axis.Vertical;

        parent = this.Content.parent.GetComponent <UiTransform>();

        w            = (int)this.Content.rect.width;
        this.numCols = LevelSelectMenu.getNumSlots(w, this.ThumbBorder,
                                                   this.ThumbSpacing, this.ThumbSize);

        this.numRows = this.numItems / this.numCols;
        if (this.numItems % this.numCols != 0)
        {
            this.numRows++;
        }

        h  = this.numRows * (this.ThumbSpacing + this.ThumbSize);
        h += this.ThumbBorder * 2 - this.ThumbSpacing;
        this.Content.SetSizeWithCurrentAnchors(vert, h);

        this.rowSelector = new Image[this.numRows];
        template         = new GO($"RowSelector");
        this.thumbnails  = new RawImage[this.numItems];
        thumbTemplate    = new GO($"Thumbnail");
        t         = this.RowView.transform;
        w         = (int)(this.RowView.rect.width / 2);
        h         = (int)(this.RowView.rect.height / this.numRows);
        rowOffset = h * 0.05f;
        for (int y = 0; y < this.numRows; y++)
        {
            GO    newGo;
            Image img;
            float _x = w * 0.25f;
            float _y = (float)(y * h) - rowOffset;
            float _w = w * 0.75f;
            float _h = h * 0.9f;

            newGo               = LevelSelectMenu.spawnCopy(template, t, _x, _y, _w, _h);
            img                 = newGo.AddComponent <Image>();
            img.color           = this.OtherRowsColor;
            this.rowSelector[y] = img;

            for (int x = 0; x < this.numCols; x++)
            {
                RawImage  rimg;
                Transform _t = this.Content.transform;
                int       i  = x + y * this.numCols;

                if (i > this.numItems)
                {
                    break;
                }

                _x = this.ThumbBorder + x * (this.ThumbSize + this.ThumbSpacing);
                _y = this.ThumbBorder + y * (this.ThumbSize + this.ThumbSpacing);
                _w = this.ThumbSize;
                _h = this.ThumbSize;

                newGo = LevelSelectMenu.spawnCopy(thumbTemplate, _t,
                                                  _x, _y, _w, _h);
                rimg               = newGo.AddComponent <RawImage>();
                rimg.texture       = LevelSelectMenu.cache[i].tex;
                rimg.material      = LevelSelectMenu.cache[i].mat;
                this.thumbnails[i] = rimg;
            }
        }
        GO.Destroy(template);
        GO.Destroy(thumbTemplate);
    }