IEnumerator PingPongMove(ColliderProxy2D comp, LVector3 sPos, LVector3 ePos, float time)
        {
            float timer      = 0;
            var   degFloat   = Random.Range(1.0f - degFloatRate, 1.0f + degFloatRate).ToLFloat();
            var   sizeFloat1 = Random.Range(1.0f - sizeFloatRate, 1.0f + sizeFloatRate).ToLFloat();
            var   sizeFloat2 = Random.Range(1.0f - sizeFloatRate, 1.0f + sizeFloatRate).ToLFloat();
            var   obb        = comp.Collider as OBB;
            var   aabb       = comp.Collider as AABB;
            var   circle     = comp.Collider as Circle;
            var   startDeg   = comp.deg;
            var   endDeg     = startDeg + degFloat * (rawRotateDeg.ToLFloat());

            var startRadius = comp.Collider.radius;
            var endRandius  = sizeFloat1 * rawSize.ToLFloat();
            var rawSizeVec  = LVector2.one;
            var endSizeVec  = LVector2.one;

            if (circle == null)
            {
                rawSizeVec = obb != null ? obb.size : aabb.size;
                endSizeVec = new LVector2(sizeFloat1 * rawSize.ToLFloat(), sizeFloat2 * rawSize.ToLFloat());
            }

            while (true)
            {
                timer += Time.deltaTime;
                if (timer > time)
                {
                    break;
                }

                var timeRate = (timer / time).ToLFloat();
                //change position
                comp.SetPosition(LVector3.Lerp(sPos, ePos, timeRate));
                var collider = comp.Collider;
                //change rotation
                if (aabb == null)
                {
                    comp.SetRotation(LMath.Lerp(startDeg, endDeg, timeRate));
                }

                //change size
                if (circle != null)
                {
                    circle.radius = LMath.Lerp(startRadius, endRandius, timeRate);
                }

                if (aabb != null)
                {
                    aabb.size = LVector2.Lerp(rawSizeVec, endSizeVec, timeRate);
                }

                if (obb != null)
                {
                    obb.size = LVector2.Lerp(rawSizeVec, endSizeVec, timeRate);
                }

                yield return(null);
            }

            StartCoroutine(PingPongMove(comp, ePos, sPos,
                                        rawMoveTime * Random.Range(1.0f - timeFloatRate, 1.0f + timeFloatRate)));
        }
Beispiel #2
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            owner = (ColliderProxy2D)target;
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Type:");
                if (int.TryParse(GUILayout.TextField(addTypeID.ToString()), out int idx))
                {
                    addTypeID = idx;
                    addTypeID = Mathf.Clamp(addTypeID, 0, 2);
                }

                GUILayout.Label("removeIdx:");
                if (int.TryParse(GUILayout.TextField(removeIdx.ToString()), out int _idx))
                {
                    removeIdx = Mathf.Clamp(_idx, 0, owner.allOffsets.Count - 1);
                }

                GUILayout.EndHorizontal();
            }
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("+"))
                {
                    BaseShaper2D shape = null;
                    var          type  = (EShape2D)addTypeID;
                    if (type == EShape2D.Circle)
                    {
                        owner.AddCircle(LVector2.zero, owner.transform.position.ToLVector3(), 1.ToLFloat());
                    }
                    else if (type == EShape2D.AABB)
                    {
                        owner.AddAABB(LVector2.zero, owner.transform.position.ToLVector3(), LVector2.one);
                    }
                    else if (type == EShape2D.OBB)
                    {
                        owner.AddOBB(LVector2.zero, owner.transform.position.ToLVector3(), LVector2.one, 01.ToLFloat());
                    }
                }

                if (GUILayout.Button("-"))
                {
                    if (removeIdx >= owner.allOffsets.Count)
                    {
                        return;
                    }
                    owner.Remove(removeIdx);
                }

                GUILayout.EndHorizontal();
            }
            //Draw Property
            {
                var count = owner.allOffsets.Count;
                for (int i = 0; i < count; i++)
                {
                    var shape  = owner.allColliders[i];
                    var circle = shape as Circle;
                    if (circle != null)
                    {
                        ShowCircle(circle, i);
                    }

                    var aabb = shape as AABB;
                    if (aabb != null)
                    {
                        ShowAABB(aabb, i);
                    }

                    var obb = shape as OBB;
                    if (obb != null)
                    {
                        ShowOBB(obb, i);
                    }
                }
            }
        }