Пример #1
0
 // ----------------------------------------------------------------------
 public void Reset()
 {
     // Common
     ObjectType          = VSObjectType.Unknown;
     NodeSpec            = NodeSpecification.Default;
     PortSpec            = PortSpecification.Default;
     InstanceId          = -1;
     ParentId            = -1;
     QualifiedType       = "";
     RawName             = "";
     LocalAnchorPosition = Vector2.zero;
     LayoutPriority      = 0;
     DisplayOption       = iCS_DisplayOptionEnum.Unfolded;
     // Node
     MethodName  = null;
     NbOfParams  = 0;
     IconGUID    = null;
     Description = null;
     // Port
     Edge                = NodeEdge.None;
     SourceId            = -1;
     PortIndex           = -1;
     InitialValueArchive = null;
     // State
     IsEntryState = false;
 }
 public PortInfo(string name, Type valueType, VSObjectType portType, object initialValue)
 {
     Name         = name;
     ValueType    = valueType;
     PortType     = portType;
     InitialValue = initialValue;
 }
 // ----------------------------------------------------------------------
 public static bool CanAddChildNode(string childName, VSObjectType childType, iCS_EditorObject parent, iCS_IStorage iStorage)
 {
     if (parent == null)
     {
         return(false);
     }
     // Only allow valid child for object instances.
     if (parent.IsBehaviour)
     {
         // Don't allow more then one copy of a node in an instance node
         if (IsChildNodePresent(childName, parent, iStorage))
         {
             return(false);
         }
         if (childType == VSObjectType.Package || childType == VSObjectType.InstanceMessage)
         {
             return(true);
         }
         if (childType == VSObjectType.Constructor)
         {
             return(true);
         }
         return(false);
     }
     // Messages are only allow on their object instance.
     if (childType == VSObjectType.InstanceMessage || childType == VSObjectType.StaticMessage)
     {
         return(false);
     }
     // Only allow State node in StateChart.
     if (parent.ObjectType == VSObjectType.StateChart)
     {
         return(childType == VSObjectType.State);
     }
     // Only allow state, transition trigger package & entry/update/exit modules in state.
     if (parent.ObjectType == VSObjectType.State)
     {
         if (childType == VSObjectType.State || childType == VSObjectType.TransitionPackage)
         {
             return(true);
         }
         if (childType == VSObjectType.Package)
         {
             return(NameExistsIn(childName, StateChildNames) && !IsChildNodePresent(childName, parent, iStorage));
         }
     }
     // Allow all but Behaviour & State in module.
     if (parent.IsKindOfPackage)
     {
         if (childType == VSObjectType.Behaviour || childType == VSObjectType.State)
         {
             return(false);
         }
         return(true);
     }
     // Reject all other type of node nesting.
     return(false);
 }
        // ----------------------------------------------------------------------
        iCS_EditorObject GetValidParentNodeUnder(Vector2 point, VSObjectType objType, string objName)
        {
            iCS_EditorObject newParent = IStorage.GetNodeAt(point);

            if (newParent != null && !iCS_AllowedChildren.CanAddChildNode(objName, objType, newParent, IStorage))
            {
                newParent = null;
            }
            return(newParent);
        }
Пример #5
0
 // ======================================================================
 // Initialization
 // ----------------------------------------------------------------------
 public iCS_EngineObject(int id, string name, Type type, int parentId, VSObjectType objectType)
 {
     Reset();
     ObjectType          = objectType;
     InstanceId          = id;
     ParentId            = parentId;
     RawName             = name;
     QualifiedType       = type.AssemblyQualifiedName;
     LocalAnchorPosition = Vector2.zero;
     if (IsDataOrControlPort)
     {
         Edge = IsInputPort ? (IsEnablePort ? NodeEdge.Top : NodeEdge.Left) : NodeEdge.Right;
     }
 }
Пример #6
0
        // ----------------------------------------------------------------------
        iCS_EditorObject PropertiesWizardCreatePortIfNonExisting(iCS_EditorObject module, string portName, Type portType,
                                                                 VSObjectType objType, int portIdx = -1)
        {
            iCS_EditorObject port = PropertiesWizardGetPort(module, portName, objType, portIdx);

            if (port == null)
            {
                port = CreatePort(portName, module.InstanceId, portType, objType);
                if (portIdx != -1)
                {
                    port.PortIndex = portIdx;
                }
            }
            return(port);
        }
Пример #7
0
        // ======================================================================
        // Constructors/Builders
        // ----------------------------------------------------------------------
        // Creates an instance of an editor/engine object pair.
        public static iCS_EditorObject CreateInstance(int id, string name, Type type,
                                                      int parentId, VSObjectType objectType,
                                                      iCS_IStorage iStorage)
        {
            if (id < 0)
            {
                return(null);
            }
            // Create engine object.
            var engineObject = new iCS_EngineObject(id, name, type, parentId, objectType);

            AddEngineObject(id, engineObject, iStorage);
            // Create editor object.
            var editorObject = new iCS_EditorObject(id, iStorage);

            AddEditorObject(id, editorObject);
            RunOnCreated(editorObject);
            return(editorObject);
        }
 // ----------------------------------------------------------------------
 public bool DoesPortExist(iCS_EditorObject node, string portName, Type valueType, VSObjectType portType)
 {
     return(node.UntilMatchingChild(p => p.DisplayName == portName && p.ObjectType == portType && p.RuntimeType == valueType));
 }
Пример #9
0
        // ----------------------------------------------------------------------
        void PropertiesWizardDestroyPortIfNotConnected(iCS_EditorObject module, string portName, VSObjectType objType)
        {
            iCS_EditorObject port = PropertiesWizardGetPort(module, portName, objType);

            if (port != null && port.ProducerPort == null && FindAConnectedPort(port) == null)
            {
                DestroyInstance(port.InstanceId);
            }
        }
Пример #10
0
        // ======================================================================
        // Utilities.
        // ----------------------------------------------------------------------
        iCS_EditorObject PropertiesWizardGetPort(iCS_EditorObject module, string portName, VSObjectType objType, int portId = -1)
        {
            iCS_EditorObject result = null;

            UntilMatchingChildPort(module,
                                   port => {
                if (port.DisplayName == portName && port.ObjectType == objType)
                {
                    if (portId != -1 && port.PortIndex != portId)
                    {
                        return(false);
                    }
                    result = port;
                    return(true);
                }
                return(false);
            }
                                   );
            return(result);
        }
Пример #11
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]);
        }
Пример #12
0
        // ======================================================================
        // Utilities
        // ----------------------------------------------------------------------
        private static iCS_EditorObject _CreatePackage(iCS_EditorObject parent, Vector2 globalPos, string name, VSObjectType objectType = VSObjectType.Package, Type runtimeType = null)
        {
#if SHOW_DEBUG
            Debug.Log("iCanScript: CreatePackage => " + name);
#endif
            if (parent == null)
            {
                return(null);
            }
            if (!IsCreationAllowed())
            {
                return(null);
            }
            var iStorage = parent.IStorage;

            iCS_EditorObject package = null;
            OpenTransaction(iStorage);
            try {
                iStorage.AnimateGraph(null,
                                      _ => {
                    package = iStorage.CreatePackage(parent.InstanceId, name, objectType, runtimeType);
                    package.SetInitialPosition(globalPos);
                    iStorage.ForcedRelayoutOfTree();
                    iStorage.ReduceCollisionOffset();
                    iStorage.SelectedObject = package;
                }
                                      );
            }
            catch (System.Exception e) {
                Debug.Log(e.Message);
                CancelTransaction(iStorage);
                return(null);
            }
            if (package == null)
            {
                CancelTransaction(iStorage);
                return(null);
            }
            CloseTransaction(iStorage, "Create " + name);
            return(package);
        }
Пример #13
0
        // ======================================================================
        // Object creation
        // ----------------------------------------------------------------------
        public static iCS_EditorObject CreatePackage(iCS_EditorObject parent, Vector2 globalPos, string name, VSObjectType objectType = VSObjectType.Package, Type runtimeType = null)
        {
#if SHOW_DEBUG
            Debug.Log("iCanScript: CreatePackage => " + name);
#endif
            var iStorage = parent.IStorage;
            OpenTransaction(iStorage);
            iCS_EditorObject package = null;
            try {
                package = _CreatePackage(parent, globalPos, name, objectType, runtimeType);
            }
            catch (System.Exception) {
                CancelTransaction(iStorage);
                return(null);
            }
            if (package == null)
            {
                CancelTransaction(iStorage);
                return(null);
            }
            CloseTransaction(iStorage, "Create " + name);
            SystemEvents.AnnounceVisualScriptElementAdded(package);
            return(package);
        }