Ejemplo n.º 1
0
    private void KillRemainingBalls()
    {
        var balls = GameObject.FindObjectsOfType <Ball>();

        foreach (var b in balls)
        {
            if (b != null)
            {
                LevelAuthor.SafeDestroy(b.gameObject);
            }
        }
    }
Ejemplo n.º 2
0
    public IEnumerator KillRoutine()
    {
        float t = 0;

        transform.localScale = Vector3.one;
        Vector3 initScale = transform.localScale;

        while (t < manager.KillTime)
        {
            float l     = t / manager.KillTime;
            float scale = manager.KillCurve.Evaluate(l);
            float rot   = Mathf.Lerp(0, 90, l);

            transform.localRotation = Quaternion.Euler(0, 0, rot);
            transform.localScale    = initScale * scale;

            t += Time.deltaTime;
            yield return(null);
        }

        LevelAuthor.SafeDestroy(gameObject);
    }
Ejemplo n.º 3
0
 private void OnDestroy()
 {
     AllShapes?.Remove(this);
     LevelAuthor.ValidateConnections();
 }
Ejemplo n.º 4
0
 public void SpawnOctagon()
 {
     LevelAuthor.CreateShape(UnityEngine.Random.onUnitSphere * 4, ShapeType.OCTAGON);
 }
Ejemplo n.º 5
0
 public void SpawnSquare()
 {
     LevelAuthor.CreateShape(UnityEngine.Random.onUnitSphere * 4, ShapeType.SQUARE);
 }
Ejemplo n.º 6
0
 public void SpawnTriangle()
 {
     LevelAuthor.CreateShape(UnityEngine.Random.onUnitSphere * 4, ShapeType.TRIANGLE);
 }
Ejemplo n.º 7
0
 public void SpawnCircle()
 {
     LevelAuthor.CreateShape(UnityEngine.Random.onUnitSphere * 4, ShapeType.CIRCLE);
 }
Ejemplo n.º 8
0
        private void LateUpdate()
        {
            // Stop editing while playing
            if (GameSystem.Instance && GameSystem.Instance.Sequence.State != SequenceState.STOPPED)
            {
                return;
            }

            var ray = Cam.ScreenPointToRay(Input.mousePosition);

            bool hit = Physics.Raycast(ray, out var hitInfo, float.MaxValue) && hitInfo.collider == collider;

            hovered = dragging || hit;

            var dT = Time.deltaTime;
            var d  = hovered ? 1f : 0f;
            var s  = hovered ? Config.enterSpeed * dT : -Config.exitSpeed * dT;

            if (math.abs(hoverTransition - d) > 0.0001f)
            {
                hoverTransition = math.clamp(hoverTransition + s, 0, 1);

                var c = Config.curve.Evaluate(hoverTransition);
                var g = Config.gradient.Evaluate(hoverTransition);

                line.startWidth = line.endWidth = math.lerp(Config.minWidth, Config.maxWidth, c);
                line.startColor = line.endColor = g;

                for (int i = 0; i < line.positionCount; i++)
                {
                    line.SetPosition(i, directions[i] * math.lerp(Config.minRadius, Config.maxRadius, c));
                }
            }

            if (hovered)
            {
                bool click  = Input.GetMouseButtonDown(0);
                bool hold   = Input.GetMouseButton(0);
                bool rClick = Input.GetMouseButtonDown(1);

                if (!dragging)
                {
                    if (click)
                    {
                        dragging  = true;
                        dragPlane = new Plane(tr.forward, tr.position);
                        dragPlane.Raycast(ray, out float enter);
                        var point = ray.GetPoint(enter);
                        startDragDiff = tr.position - point;
                    }
                }
                else
                {
                    if (!hold)
                    {
                        dragging = false;
                    }
                    else
                    {
                        if (rClick)
                        {
                            LevelAuthor.SafeDestroy(gameObject);
                        }
                        else
                        {
                            if (dragPlane.Raycast(ray, out float enter))
                            {
                                tr.position = (float3)ray.GetPoint(enter) + startDragDiff;
                            }
                        }
                    }
                }
            }

            tr.position = new Vector3(Mathf.FloorToInt(tr.position.x) + 0.5f, Mathf.FloorToInt(tr.position.y) + 0.5f, Mathf.FloorToInt(tr.position.z));
        }
Ejemplo n.º 9
0
    public void Update()
    {
        // Stop editing while playing
        if (GameSystem.Instance && GameSystem.Instance.Sequence.State != SequenceState.STOPPED)
        {
            return;
        }

        var ray = GameSystem.Instance.Cam.ScreenPointToRay(Input.mousePosition);

        switch (state)
        {
        case State.IDLE:

            if (Input.GetMouseButtonDown(1))
            {
                if (Physics.Raycast(ray, out var hitInfo, float.MaxValue))
                {
                    shapeA = hitInfo.transform.GetComponent <Shape>();
                    if (shapeA == null)
                    {
                        break;
                    }

                    state = State.DRAGGING;
                }
            }

            break;

        case State.DRAGGING:
            if (Input.GetMouseButtonUp(1))
            {
                state = State.IDLE;

                if (Physics.Raycast(ray, out var hitInfo, float.MaxValue))
                {
                    shapeB = hitInfo.transform.GetComponent <Shape>();
                    var sun = hitInfo.transform.GetComponent <Sun>();
                    if (shapeB == null)
                    {
                        if (sun == null)
                        {
                            break;
                        }

                        if (GameSystem.Instance.Sun.Data.RemoveOutgoingId(shapeA.Data.Id))
                        {
                            break;
                        }

                        GameSystem.Instance.Sun.Data.AddOutgoingId(shapeA.Data.Id);
#if UNITY_EDITOR
                        if (shapeA)
                        {
                            EditorUtility.SetDirty(shapeA);
                        }
#endif
                        OnConnectionCreated?.Invoke();
                        LevelAuthor.ValidateConnections();
                        break;
                    }

                    if (shapeA.Data.IncomingId == shapeB.Data.Id)
                    {
                        break;
                    }

                    bool shapeBconnectedToSun = false;
                    foreach (var sunOutgoingId in GameSystem.Instance.Sun.Data.OutgoingIds)
                    {
                        if (sunOutgoingId == shapeB.Data.Id)
                        {
                            shapeBconnectedToSun = true;
                            break;
                        }
                    }

                    if (shapeB.Data.IncomingId != Guid.Empty.ToString())
                    {
                        if (shapeB.Data.IncomingId == shapeA.Data.Id)
                        {
                            shapeB.Data.IncomingId = Guid.Empty.ToString();

                            for (int i = 0; i < (int)shapeA.Data.Type; i++)
                            {
                                if (shapeA.Data.OutgoingIds[i] == shapeB.Data.Id)
                                {
                                    shapeA.Data.OutgoingIds[i] = Guid.Empty.ToString();
                                }
                            }
                        }

#if UNITY_EDITOR
                        EditorUtility.SetDirty(shapeB);
                        EditorUtility.SetDirty(shapeA);
#endif
                    }
                    else if (!shapeBconnectedToSun)
                    {
                        int shapeAConnectionIndex = -1;
                        for (int i = 0; i < (int)shapeA.Data.Type; i++)
                        {
                            if (shapeA.Data.OutgoingIds[i] == Guid.Empty.ToString())
                            {
                                shapeAConnectionIndex = i;
                            }
                        }

                        if (shapeAConnectionIndex > -1)
                        {
                            shapeB.Data.IncomingId = shapeA.Data.Id;
                            shapeA.Data.OutgoingIds[shapeAConnectionIndex] = shapeB.Data.Id;
#if UNITY_EDITOR
                            EditorUtility.SetDirty(shapeB);
                            EditorUtility.SetDirty(shapeA);
#endif
                            OnConnectionCreated?.Invoke();
                            LevelAuthor.ValidateConnections();
                        }
                    }
                }
            }

            break;
        }
    }