示例#1
0
        // ======================================================================
        // Common Creation
        // ----------------------------------------------------------------------
        public iCS_EditorObject CreatePort(string name, int parentId, Type valueType, VSObjectType portType, int index = -1)
        {
            int id     = GetNextAvailableId();
            var parent = EditorObjects[parentId];

            if (index == -1)
            {
                if (portType == VSObjectType.TriggerPort)
                {
                    index = (int)iCS_PortIndex.Trigger;
                }
                if (portType == VSObjectType.EnablePort)
                {
                    index = GetNextAvailableEnablePortIndex(parent);
                }
                else
                {
                    index = GetNextDynamicOrProposedPortIndex(parent);
                }
            }
            iCS_EditorObject port = iCS_EditorObject.CreateInstance(id, name, valueType, parentId, portType, this);

            port.PortIndex = index;
            if (parent.IsPort)
            {
                //            port.LocalOffset= parent.LocalOffset;
                port.CollisionOffset = parent.CollisionOffset;
            }
            else
            {
                var globalPos = parent.GlobalPosition;
                //          port.GlobalPosition= globalPos;
                port.CollisionOffsetFromGlobalPosition = globalPos;
            }
            // Set initial port edge.
            if (port.IsEnablePort)
            {
                port.Edge = iCS_EdgeEnum.Top;
            }
            else if (port.IsTriggerPort)
            {
                port.Edge = iCS_EdgeEnum.Bottom;
            }
            else if (port.IsInputPort)
            {
                port.Edge = iCS_EdgeEnum.Left;
            }
            else if (port.IsDataPort)
            {
                port.Edge = iCS_EdgeEnum.Right;
            }
            else
            {
                port.UpdatePortEdge();
            }
            port.CleanupPortEdgePosition();
            return(EditorObjects[id]);
        }