Esempio n. 1
0
        protected virtual void OnDisable()
        {
            cachedDestructible.OnRebuilt    -= HandleRebuilt;
            cachedDestructible.OnModified   -= HandleModified;
            cachedDestructible.OnSplitStart -= HandleSplitStart;
            cachedDestructible.OnSplitEnd   -= HandleSplitEnd;

            if (child != null)
            {
                child.SetActive(false);
            }

            // If the collider was disabled while splitting then run this special code to destroy the children
            if (cachedDestructible.IsOnStartSplit == true)
            {
                if (child != null)
                {
                    child.transform.SetParent(null, false);

                    child = D2dHelper.Destroy(child);
                }

                if (tempChild != null)
                {
                    tempChild = D2dHelper.Destroy(tempChild);
                }
            }
        }
 public void DestroyChild()
 {
     if (child != null)
     {
         child = D2dHelper.Destroy(child);
     }
 }
        private void Rebuild()
        {
            Destroy();

            var alphaTex = destructible.AlphaTex;

            if (alphaTex != null)
            {
                var spriteRenderer = child.GetComponent <SpriteRenderer>();
                var sprite         = Sprite.Create(alphaTex, new Rect(0, 0, alphaTex.width, alphaTex.height), Vector2.zero, 1.0f, 0, SpriteMeshType.FullRect);

                if (spriteRenderer == null)
                {
                    spriteRenderer = child.AddComponent <SpriteRenderer>();
                }

                spriteRenderer.sprite = sprite;

                polygonCollider2D = child.AddComponent <PolygonCollider2D>();

                polygonCollider2D.enabled        = IsDefaultPolygonCollider2D(polygonCollider2D) == false;
                polygonCollider2D.isTrigger      = IsTrigger;
                polygonCollider2D.sharedMaterial = Material;

                D2dHelper.Destroy(sprite);
                D2dHelper.Destroy(spriteRenderer);
            }
        }
        protected virtual void OnDisable()
        {
            destructible.OnAlphaDataReplaced.RemoveListener(OnAlphaDataReplaced);
            destructible.OnAlphaDataModified.RemoveListener(OnAlphaDataModified);
            destructible.OnAlphaDataSubset.RemoveListener(OnAlphaDataSubset);
            destructible.OnStartSplit.RemoveListener(OnStartSplit);
            destructible.OnEndSplit.RemoveListener(OnEndSplit);

            if (child != null)
            {
                child.SetActive(false);
            }

            // If the collider was disabled while splitting then run this special code to destroy the children
            if (destructible.IsOnStartSplit == true)
            {
                if (child != null)
                {
                    child.transform.SetParent(null, false);

                    child = D2dHelper.Destroy(child);
                }

                if (tempChild != null)
                {
                    tempChild = D2dHelper.Destroy(tempChild);
                }
            }
        }
Esempio n. 5
0
        protected virtual void Update()
        {
            Life -= Time.deltaTime;

            if (Life > 0.0f)
            {
                if (Fade == true)
                {
                    UpdateFade();
                }

                if (Shrink == true)
                {
                    UpdateShrink();
                }
            }
            else if (target != null)
            {
                D2dHelper.Destroy(target);
            }
            else
            {
                D2dHelper.Destroy(gameObject);
            }
        }
Esempio n. 6
0
        public void UpdateFixtures()
        {
            if (Fixtures.Count > 0)
            {
                for (var i = Fixtures.Count - 1; i >= 0; i--)
                {
                    var fixture = Fixtures[i];

                    if (FixtureIsConnected(fixture) == false)
                    {
                        Fixtures.RemoveAt(i);
                    }
                }

                if (Fixtures.Count == 0)
                {
                    if (OnAllFixturesRemoved != null)
                    {
                        OnAllFixturesRemoved.Invoke();
                    }

                    if (AutoDestroy == true)
                    {
                        D2dHelper.Destroy(this);
                    }
                }
            }
        }
 private void SweepColliders()
 {
     while (colliderPool.Count > 0)
     {
         D2dHelper.Destroy(colliderPool.Pop());
     }
 }
Esempio n. 8
0
        private void Sweep()
        {
            for (var i = unusedColliders.Count - 1; i >= 0; i--)
            {
                D2dHelper.Destroy(unusedColliders[i]);
            }

            unusedColliders.Clear();
        }
Esempio n. 9
0
        protected override void OnDisable()
        {
            base.OnDisable();

            if (CachedSpriteRenderer.sprite == clonedSprite)
            {
                CachedSpriteRenderer.sprite = originalSprite;
            }

            clonedSprite   = D2dHelper.Destroy(clonedSprite);
            originalSprite = null;
        }
Esempio n. 10
0
        protected virtual void Awake()
        {
            // Auto destroy all default collider2Ds
            if (GetComponent <Collider2D>() != null)
            {
                var collider2Ds = GetComponents <Collider2D>();

                for (var i = collider2Ds.Length - 1; i >= 0; i--)
                {
                    D2dHelper.Destroy(collider2Ds[i]);
                }
            }
        }
Esempio n. 11
0
        public void Rebuild()
        {
            if (CachedDestructible.Ready == true)
            {
                UpdateBeforeBuild();

                DoRebuild();
            }
            else
            {
                child = D2dHelper.Destroy(child);
            }
        }
Esempio n. 12
0
        public void Clear()
        {
            ready              = false;
            alphaSharpness     = 0.0f;
            alphaTex           = D2dHelper.Destroy(alphaTex);
            alphaData          = null;
            alphaWidth         = 0;
            alphaHeight        = 0;
            alphaCount         = 0;
            originalAlphaCount = 0;

            AlphaModified.Clear();

            NotifyRebuilt();
        }
        protected virtual void Update()
        {
            Life -= Time.deltaTime;

            if (Life <= 0.0f)
            {
                Life = 0.0f;

                D2dHelper.Destroy(gameObject);
            }
            else
            {
                UpdateFade();
            }
        }
Esempio n. 14
0
        public void UpdateFixtures()
        {
            if (fixtures != null && fixtures.Count > 0)
            {
                if (cachedDestructible == null)
                {
                    cachedDestructible = GetComponentInParent <D2dDestructible>();
                }

                if (cachedDestructible != null)
                {
                    for (var i = fixtures.Count - 1; i >= 0; i--)
                    {
                        var fixture = fixtures[i];

                        if (FixtureIsConnected(fixture) == false)
                        {
                            fixtures.RemoveAt(i);
                        }
                    }

                    if (fixtures.Count == 0)
                    {
                        if (OnAllDetached != null)
                        {
                            OnAllDetached.Invoke();
                        }

                        if (AutoDestroy == true)
                        {
                            D2dHelper.Destroy(this);
                        }
                    }
                }
            }
        }
Esempio n. 15
0
 protected virtual void OnDestroy()
 {
     D2dHelper.Destroy(clonedSprite);
 }
Esempio n. 16
0
 private void DestroyFixture()
 {
     D2dHelper.Destroy(gameObject);
 }
Esempio n. 17
0
        private void UpdateTiles()
        {
            var tileCount = 0;

            if (Prefab != null && Prefab.Size.x > 0.0f && Prefab.Size.y > 0.0f)
            {
                if (mainCamera == null)
                {
                    mainCamera = Camera.main;
                }

                if (mainCamera != null && mainCamera.orthographic == true)
                {
                    var width  = Mathf.CeilToInt(mainCamera.orthographicSize * mainCamera.aspect / Prefab.Size.x);
                    var height = Mathf.CeilToInt(mainCamera.orthographicSize / Prefab.Size.y);

                    if (TileAxis == Axes.Horizontal)
                    {
                        height = 0;
                    }
                    if (TileAxis == Axes.Vertical)
                    {
                        width = 0;
                    }

                    for (var y = -height; y <= height; y++)
                    {
                        for (var x = -width; x <= width; x++)
                        {
                            // Expand tile array?
                            if (tileCount == Tiles.Count)
                            {
                                Tiles.Add(null);
                            }

                            // Get tile at this index
                            var tile = Tiles[tileCount];

                            // Create tile?
                            if (tile == null)
                            {
                                tile = Instantiate(Prefab);

                                tile.enabled = false;

                                tile.transform.SetParent(transform, false);

                                Tiles[tileCount] = tile;
                            }

                            if (OverrideSorting == true)
                            {
                                tile.UpdateRenderer(SortingOrder);
                            }

                            // Update this tile
                            tile.Offset.X = x;
                            tile.Offset.Y = y;

                            tile.UpdatePosition(Offset);

                            // Increment tile count
                            tileCount += 1;
                        }
                    }
                }
            }

            // Remove unused tiles
            for (var i = Tiles.Count - 1; i >= tileCount; i--)
            {
                var tile = Tiles[i];

                if (tile != null)
                {
                    D2dHelper.Destroy(tile.gameObject);
                }

                Tiles.RemoveAt(i);
            }
        }
Esempio n. 18
0
 private void Destroy()
 {
     polygonCollider2D = D2dHelper.Destroy(polygonCollider2D);
 }
Esempio n. 19
0
 protected virtual void Destroy()
 {
     D2dHelper.Destroy(alphaTex);
 }