private void Sweep()
 {
     while (tempColliders.Count > 0)
     {
         DestroyableHelper.Destroy(tempColliders.Pop());
     }
 }
Exemple #2
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)
                    {
                        DestroyableHelper.Destroy(this);
                    }
                }
            }
        }
Exemple #3
0
        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 (destructible.IsOnStartSplit == true)
            {
                if (child != null)
                {
                    child.transform.SetParent(null, false);

                    child = DestroyableHelper.Destroy(child);
                }

                if (tempChild != null)
                {
                    tempChild = DestroyableHelper.Destroy(tempChild);
                }
            }
        }
Exemple #4
0
        public void CombineData(byte[] prevData, int prevWidth, int prevHeight)
        {
            var dataX      = Rect.MinX;
            var dataY      = Rect.MinY;
            var dataWidth  = Rect.SizeX;
            var dataHeight = Rect.SizeY;

            if (Data != null && Data.Length >= dataWidth * dataHeight && prevData != null && prevData.Length >= prevWidth * prevHeight)
            {
                for (var y = 0; y < dataHeight; y++)
                {
                    for (var x = 0; x < dataWidth; x++)
                    {
                        var prevX = x + dataX;
                        var prevY = y + dataY;
                        var dataI = x + y * dataWidth;

                        if (prevX >= 0 && prevY >= 0 && prevX < prevWidth && prevY < prevHeight)
                        {
                            var prevI = prevX + prevY * prevWidth;
                            var dataA = DestroyableHelper.ConvertAlpha(Data[dataI]);
                            var prevA = DestroyableHelper.ConvertAlpha(prevData[prevI]);

                            Data[dataI] = DestroyableHelper.ConvertAlpha(dataA * prevA);
                        }
                        else
                        {
                            Data[dataI] = 0;
                        }
                    }
                }
            }
        }
Exemple #5
0
        public override void OnInspectorGUI()
        {
            EditorGUI.BeginChangeCheck();
            {
                Target  = (T)target;
                Targets = targets.Select(t => (T)t).ToArray();

                Separator();

                OnInspector();

                Separator();

                serializedObject.ApplyModifiedProperties();
            }
            if (EditorGUI.EndChangeCheck() == true)
            {
                GUI.changed = true; Repaint();

                foreach (var t in Targets)
                {
                    DestroyableHelper.SetDirty(t);
                }
            }
        }
Exemple #6
0
 public void DestroyChild()
 {
     if (child != null)
     {
         child = DestroyableHelper.Destroy(child);
     }
 }
Exemple #7
0
        protected void DirtyEach(System.Action <T> update)
        {
            foreach (var t in Targets)
            {
                update(t);

                DestroyableHelper.SetDirty(t);
            }
        }
Exemple #8
0
        public virtual void OnSceneGUI()
        {
            Target = (T)target;

            OnScene();

            if (GUI.changed == true)
            {
                DestroyableHelper.SetDirty(target);
            }
        }
Exemple #9
0
        protected virtual void Awake()
        {
            if (this.GetComponent <Collider2D>() != null)
            {
                var collider2Ds = this.GetComponents <Collider2D>();

                for (var i = collider2Ds.Length - 1; i >= 0; i--)
                {
                    DestroyableHelper.Destroy(collider2Ds[i]);
                }
            }
        }
Exemple #10
0
        public void AddTriangle(DestroyableVector2Operator a, DestroyableVector2Operator b, DestroyableVector2Operator c)
        {
            if (a.Y != b.Y || a.Y != c.Y)
            {
                //var z = (a.V + b.V + c.V) / 3.0f;
                //var z1 = Vector3.MoveTowards(a.V, z, 1.0f);
                //var z2 = Vector3.MoveTowards(b.V, z, 1.0f);
                //var z3 = Vector3.MoveTowards(c.V, z, 1.0f);

                //Debug.DrawLine(z1, z2, Color.red, 10.0f);
                //Debug.DrawLine(z2, z3, Color.red, 10.0f);
                //Debug.DrawLine(z3, z1, Color.red, 10.0f);


                if (b.Y > a.Y)
                {
                    DestroyableHelper.Swap(ref a, ref b);
                }
                if (c.Y > a.Y)
                {
                    DestroyableHelper.Swap(ref c, ref a);
                }
                if (c.Y > b.Y)
                {
                    DestroyableHelper.Swap(ref b, ref c);
                }

                var fth = a.Y - c.Y;
                var tth = a.Y - b.Y;
                var bth = b.Y - c.Y;

                var inx = c.X + (a.X - c.X) * DestroyableHelper.Divide(bth, fth);
                var d   = new DestroyableVector2Operator((int)inx, b.Y);

                var abs = DestroyableHelper.Divide(a.X - b.X, tth);
                var ads = DestroyableHelper.Divide(a.X - d.X, tth);

                AddTriangle(b.X, d.X, abs, ads, b.Y, 1, tth);

                var cbs = DestroyableHelper.Divide(c.X - b.X, bth);
                var cds = DestroyableHelper.Divide(c.X - d.X, bth);

                AddTriangle(b.X, d.X, cbs, cds, b.Y, -1, bth);
            }
        }
Exemple #11
0
        public void AddTriangle(float l, float r, float ls, float rs, int y, int s, int c)
        {
            if (l > r)
            {
                DestroyableHelper.Swap(ref l, ref r);
                DestroyableHelper.Swap(ref ls, ref rs);
            }

            for (var i = 0; i < c; i++)
            {
                var il = Mathf.FloorToInt(l);
                var ir = Mathf.CeilToInt(r);

                for (var x = il; x < ir; x++)
                {
                    AddPixel(x, y);
                }

                y += s;
                l += ls;
                r += rs;
            }
        }
Exemple #12
0
        protected void DrawDefault(string propertyPath, bool autoApply = true)
        {
            EditorGUI.BeginChangeCheck();
            {
                EditorGUILayout.BeginVertical(DestroyableHelper.NoError);
                {
                    EditorGUILayout.PropertyField(serializedObject.FindProperty(propertyPath), true);
                }
                EditorGUILayout.EndVertical();
            }
            if (EditorGUI.EndChangeCheck() == true)
            {
                if (autoApply == true)
                {
                    serializedObject.ApplyModifiedProperties();
                }

                for (var i = Targets.Length - 1; i >= 0; i--)
                {
                    DestroyableHelper.SetDirty(Targets[i]);
                }
            }
        }
Exemple #13
0
 private void MarkDirty()
 {
     Each(t => DestroyableHelper.SetDirty(t));
 }
Exemple #14
0
        protected bool Button(string text)
        {
            var rect = DestroyableHelper.Reserve();

            return(GUI.Button(rect, text));
        }
 private void DestroyFixture()
 {
     DestroyableHelper.Destroy(gameObject);
 }