Beispiel #1
0
        /// <summary>
        /// Resets to normal node.
        /// </summary>
        public void ResetToNormalNode()
        {
            _linkA = _linkB = null;

            _mode = ChainProcessorEditorModeEnum.Normal;
            EditorUtility.SetDirty(_processor.gameObject);
        }
Beispiel #2
0
        public virtual bool CheackConnectingOutputType(Type type, int inputIdex)
        {
            ChainLink link  = null;
            Type      _type = GetType(link);

            return(type == _type);
        }
        public virtual ChainLink FabricateChainLink(Order order)
        {
            ChainLink link = null;

            switch (order.Type)
            {
            case INPUT:
                link = GetChainInput(order);
                break;

            case OUTPUT:
                link = GetChainOutput(order);
                break;
            }

                        #if UNITY_EDITOR
            if (link != null)
            {
                Rect newRect = link.LinkRect;
                newRect.position = order.Position;
                Vector2 size = new Vector2(100, 100);
                newRect.size  = size;
                link.LinkRect = newRect;
            }
                        #endif

            return(link);
        }
Beispiel #4
0
        /// <summary>
        /// Normals the mode operations.
        /// </summary>
        private void NormalModeOperations()
        {
            if (_currentEvent.type == EventType.MouseDown &&
                _currentEvent.button == Right_Mouse_Button)
            {
                _currentMousePositon = _currentEvent.mousePosition;
                _linkA = FindLink(_currentMousePositon);

                if (_linkA != null)
                {
                    _nodeContextMenu.ShowAsContext();
                }
                else
                {
                    _edytorContextMenu.ShowAsContext();
                }

                _currentEvent.Use();
            }

            if (_currentEvent.type == EventType.MouseDown &&
                _currentEvent.button == Left_Mouse_Button)
            {
                _currentMousePositon = _currentEvent.mousePosition;
                _linkA = FindLink(_currentMousePositon);

                ChainLink link  = null;
                int       index = 0;
                FindLinkByHook(
                    _currentMousePositon,
                    1,
                    out link,
                    out index);

                if (link != null)
                {
                    _linkA = link;
                    SwithToConnectMode();
                }
            }

            if (_currentEvent.type == EventType.KeyDown &&
                _currentEvent.keyCode == KeyCode.Delete)
            {
                if (_linkA != null)
                {
                    DeleteNode();
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Finds the link by hook.
        /// </summary>
        /// <param name="position">Position to cheack.</param>
        /// <param name="hookType">Hook type input (0) or output (1).</param>
        /// <param name="link">Variable for link if found.</param>
        /// <param name="index">Variable for index of that node.</param>
        private void FindLinkByHook(Vector2 position, int hookType, out ChainLink link, out int index)
        {
            link  = null;
            index = -1;

            bool nodeClicked = false;

            for (int i = 0; i < Links.Count; i++)
            {
                Rect[] rects = null;
                switch (hookType)
                {
                case 0:
                    rects = Links [i].GetInputHooksRects();
                    break;

                case 1:
                    rects = Links [i].GetOutputHookRects();
                    break;
                }

                if (rects == null)
                {
                    continue;
                }

                for (int j = 0; j < rects.Length; j++)
                {
                    nodeClicked = rects[j].Contains(position);
                    if (nodeClicked)
                    {
                        index = j;
                        link  = Links [i];
                        break;
                    }
                }

                if (nodeClicked)
                {
                    break;
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Creates the node.
        /// </summary>
        /// <param name="obj">Order object.</param>
        private void CreateNode(object obj)
        {
            if (obj is Order)
            {
                Order order = obj as Order;
                order.Position = _currentMousePositon;

                ChainLink link = Factory.FabricateChainLink(order);
                if (link != null)
                {
                    if (link is ChainInput)
                    {
                        _processor.Inputs.Add(link as ChainInput);
                    }

                    if (link is ChainOutput)
                    {
                        _processor.Outputs.Add(link as ChainOutput);
                    }
                    _processor.LinkList.Add(link);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Deletes the node.
        /// </summary>
        /// <param name="obj">Link object.</param>
        private void DeleteNode(object obj = null)
        {
            ChainLink link = _linkA;

            if (link == null)
            {
                return;
            }

            int index = _processor.LinkList.IndexOf(link);

            for (int i = 0; i < _processor.LinkList.Count; i++)
            {
                if (i != index)
                {
                    ChainLink _link = _processor.LinkList [i];

                    for (int j = 0; j < _link.Inputs.Length; j++)
                    {
                        if (_link.Inputs[j] == link)
                        {
                            _link.Inputs[j] = null;
                        }
                    }

                    for (int j = 0; j < _link.Outputs.Count; j++)
                    {
                        _link.Outputs.RemoveAt(j);
                    }
                }
            }

            if (index >= 0)
            {
                _processor.LinkList.RemoveAt(index);
            }

            if (link is ChainOutput)
            {
                ChainOutput output = link as ChainOutput;
                index = _processor.Outputs.IndexOf(output);

                if (index >= 0)
                {
                    _processor.Outputs.RemoveAt(index);
                }
            }

            if (link is ChainInput)
            {
                ChainInput input = link as ChainInput;
                index = _processor.Inputs.IndexOf(input);

                if (index >= 0)
                {
                    _processor.Inputs.RemoveAt(index);
                }
            }

            DestroyImmediate(link);
            Repaint();
        }