예제 #1
0
        private void UpdateStateStop()
        {
            if (Input.GetKeyDown(KeyCode.A))
            {
                if (_selectedIndex - 1 >= 0)
                {
                    ChangeActiveFrame(_selectedIndex - 1);

                    SetTextCurrentFrame();
                }
            }
            else if (Input.GetKeyDown(KeyCode.D))
            {
                if (_selectedIndex + 1 < _frames.Count)
                {
                    ChangeActiveFrame(_selectedIndex + 1);

                    SetTextCurrentFrame();
                }
            }
            else if (Input.GetKeyDown(KeyCode.Backspace))
            {
                if (_selectedIndex < 0 || _frames.Count <= 1)
                    return;

                var oldIndex = _selectedIndex;

                if (_selectedIndex - 1 >= 0)
                {
                    ChangeActiveFrame(_selectedIndex - 1);

                    var frame = _frames[oldIndex];
                    _frames.RemoveAt(oldIndex);
                    Destroy(frame.gameObject);
                }
                else
                {
                    ChangeActiveFrame(_selectedIndex + 1);

                    var frame = _frames[oldIndex];
                    _frames.RemoveAt(oldIndex);
                    Destroy(frame.gameObject);

                    _selectedIndex = 0;
                }

                SetTextCurrentFrame();
            }

            if (EventSystem.current.IsPointerOverGameObject())
                return;

            if (Input.GetMouseButtonDown(1))
            {
                Debug.Log("Create/Delete vertex");
                var mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                var vertex = _vertices.FirstOrDefault(item => item.Collision(mouse));

                if (vertex == null)
                {
                    var item = (GameObject)Instantiate(VertexPrefab, Vector3.zero, Quaternion.identity);
                    item.transform.parent = _currentFrame.transform;
                    item.transform.position = new Vector3(mouse.x, mouse.y, 0);

                    vertex = item.GetComponent<VertexData>();
                    _vertices.Add(vertex);

                    foreach (var frame in _frames)
                    {
                        ChangeItem change;
                        if (!frame.Changes.TryGetValue(vertex.Id, out change))
                        {
                            change = new ChangeItem(vertex.Id);
                            frame.Changes.Add(vertex.Id, change);
                        }
                        change.CurrentPosition = vertex.transform.position;
                    }
                }
                else
                {
                    Destroy(vertex.gameObject);
                    _vertices.Remove(vertex);

                    foreach (var frame in _frames)
                    {
                        frame.Changes.Remove(vertex.Id);
                    }

                    var ribs = _ribs.Where(rib => rib.VertexA.Id == vertex.Id || rib.VertexB.Id == vertex.Id).ToList();

                    foreach (var rib in ribs)
                    {
                        Destroy(rib.gameObject);
                        _ribs.Remove(rib);
                    }
                }
            }
            else if (Input.GetMouseButtonUp(0) && _activeVertex != null && !Input.GetKey(KeyCode.LeftControl))
            {
                Debug.Log("Clear active vertex");
                _activeVertex = null;
            }
            else if (Input.GetMouseButtonDown(0) && _activeVertex != null && Input.GetKey(KeyCode.LeftControl))
            {
                Debug.Log("Create/delete rib");

                var mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                var vertex = _vertices.FirstOrDefault(item => item.Collision(mouse));

                if (vertex != null && vertex != _activeVertex)
                {
                    var rib =
                        _ribs.FirstOrDefault(
                            r =>
                            (r.VertexA.Id == vertex.Id && r.VertexB.Id == _activeVertex.Id) ||
                            (r.VertexB.Id == vertex.Id && r.VertexA.Id == _activeVertex.Id));

                    if (rib == null)
                    {
                        var item = (GameObject)Instantiate(RibPrefab, Vector3.zero, Quaternion.identity);
                        item.transform.parent = _currentFrame.transform;
                        item.transform.position = new Vector3(mouse.x, mouse.y, 0);

                        rib = item.GetComponent<RibData>();
                        rib.VertexA = _activeVertex;
                        rib.VertexB = vertex;

                        _ribs.Add(rib);
                    }
                    else
                    {
                        Destroy(rib.gameObject);
                        _ribs.Remove(rib);
                    }
                }

                _activeVertex = null;
            }
            else if (Input.GetMouseButtonDown(0) && _activeVertex == null)
            {
                Debug.Log("Select vertex");

                var mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                var vertex = _vertices.FirstOrDefault(item => item.Collision(mouse));
                _activeVertex = vertex;
            }
            else if (Input.GetMouseButton(0) && _activeVertex != null && !Input.GetKey(KeyCode.LeftControl))
            {
                Debug.Log("Move vertex");

                var mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                _activeVertex.transform.position = new Vector3(mouse.x, mouse.y, 0);
            }

            if (Input.GetKeyUp(KeyCode.LeftControl) && _activeVertex!=null)
            {
                Debug.Log("Clear active vertex by UpLeftControl");
                _activeVertex = null;
            }
        }
예제 #2
0
        public void AddFrame()
        {
            if (_currentState == GUIState.Play)
                return;

            var frame = (GameObject) Instantiate(FramePrefab, Vector3.zero, Quaternion.identity);
            frame.transform.SetParent(_framesContent.transform);

            frame.transform.localScale = new Vector3(1f, 1f, 1f);
            var position = frame.transform.localPosition;
            frame.transform.localPosition = new Vector3(position.x, position.y, 0);

            var frameInfo = frame.GetComponent<FrameInfo>();
            _frames.Add(frameInfo);

            foreach (var vertex in _vertices)
            {
                ChangeItem change;
                if (!frameInfo.Changes.TryGetValue(vertex.Id, out change))
                {
                    change = new ChangeItem(vertex.Id);
                    frameInfo.Changes.Add(vertex.Id, change);
                }
                change.CurrentPosition = vertex.transform.position;
            }

            if (_frames.Count == 1)
            {
                frameInfo.FrameTime = 0;
                ChangeActiveFrame(0);
            }
        }
예제 #3
0
        private void SaveChangeByFrame()
        {
            if (_selectedIndex < 0)
                return;

            var frame = _frames[_selectedIndex];

            frame.Changes.Clear();

            foreach (var vertex in _vertices)
            {
                ChangeItem item;
                if (!frame.Changes.TryGetValue(vertex.Id, out item))
                {
                    item = new ChangeItem(vertex.Id);
                    frame.Changes.Add(vertex.Id, item);
                }
                item.CurrentPosition = vertex.transform.position;
            }
        }