Ejemplo n.º 1
0
        /// <summary>
        /// Initializes the Node. This is called by the NodeEditor automatically when a Node is created
        /// </summary>
        /// <param name="position"></param>
        /// <param name="style"></param>
        /// <param name="selectedStyle"></param>
        /// <param name="inPointStyle"></param>
        /// <param name="outPointStyle"></param>
        /// <param name="OnClickInPoint"></param>
        /// <param name="OnClickOutPoint"></param>
        /// <param name="OnRemove"></param>
        public void Init(Vector2 position, GUIStyle style, GUIStyle selectedStyle, GUIStyle inPointStyle, GUIStyle outPointStyle, ConnectionPoint <T, TData> .DelOnClickConnectionPoint OnClickInPoint, ConnectionPoint <T, TData> .DelOnClickConnectionPoint OnClickOutPoint, DelOnRemoveNode OnRemove)
        {
            // set position
            NodeRect.position = position;

            // set styles
            _defaultNodeStyle  = style;
            _selectedNodeStyle = selectedStyle;
            _style             = _defaultNodeStyle;

            // add delegate
            OnRemoveNode += OnRemove;

            _contextMenuEntries = new Dictionary <string, GenericMenu.MenuFunction>();
            AddContextMenuEntrie("Remove Node", () => OnClickRemoveNode());

            // setup connection points
            InPoints  = new ConnectionPoint <T, TData> [InPoints.Length];
            OutPoints = new ConnectionPoint <T, TData> [OutPoints.Length];
            for (int i = 0; i < InPoints.Length; ++i)
            {
                InPoints[i] = new ConnectionPoint <T, TData>(this as T, ConnectionPointType.IN, i, InPoints.Length, inPointStyle, OnClickInPoint);
            }

            for (int i = 0; i < OutPoints.Length; ++i)
            {
                OutPoints[i] = new ConnectionPoint <T, TData>(this as T, ConnectionPointType.OUT, i, OutPoints.Length, outPointStyle, OnClickOutPoint);
            }

            // if the node has no ID yet, get one from the editor
            if (ID == -1)
            {
                ID = Editor.NextNodeID;
            }

            // Initialize the Data
            TData dat = new TData();

            dat.ID              = ID;
            dat.Width           = NodeRect.width;
            dat.PreferredHeight = _preferredHeight;
            Data = Editor.AddNodeToData(dat);
            Data.PositionInEditor = NodeRect.position;

            // if the data has no inputs yet, create them
            if (Data.Inputs == null)
            {
                Data.Inputs = new ConnectionPointData[InPoints.Length];
            }

            // if the data has no outputs yet, create them
            if (Data.Outputs == null)
            {
                Data.Outputs = new ConnectionPointData[OutPoints.Length];
            }

            // add some callbacks
            OnDrag       += newPos => Data.PositionInEditor = newPos;
            OnRemoveNode += n => Editor.DeleteNodeFromData(Data);

            Editor.OnConnectionMade    += SaveConnection;
            Editor.OnConnectionRemoved += DeleteConnection;


            Init();
        }