// ---------------------------------------------------------------------- public static void DeletePropertiesWizardElement(iCS_EditorObject parent, LibraryObject libraryObject) { #if DEBUG Debug.Log("iCanScript: Delete Instance Element => " + libraryObject.displayString); #endif if (parent == null || libraryObject == null) { return; } var iStorage = parent.IStorage; OpenTransaction(iStorage); try { SendStartRelayoutOfTree(iStorage); iStorage.AnimateGraph(null, _ => { iStorage.PropertiesWizardDestroy(parent, libraryObject); iStorage.ForcedRelayoutOfTree(); } ); SendEndRelayoutOfTree(iStorage); } catch (System.Exception) { CancelTransaction(iStorage); return; } CloseTransaction(iStorage, "Delete " + libraryObject.nodeName); }
// ------------------------------------------------------------------- /// Moves the cursor to the next sibling under the same parent. /// /// @return _true_ if a next sibling exists. _false_ otherwise. /// public bool MoveToNextSibling() { var parent = myCursor.parent; if (parent == null) { return(false); } var siblings = parent.children; if (siblings == null) { return(false); } int idx = siblings.IndexOf(myCursor); if (idx < 0) { return(false); } do { if (idx >= siblings.Count - 1) { return(false); } myCursor = siblings[idx + 1] as LibraryObject; ++idx; } while(!ShouldShow(myCursor)); return(true); }
// ====================================================================== // Menu context constructors. // ---------------------------------------------------------------------- public iCS_MenuContext(string command, LibraryObject libraryObject = null) { // All other fields are filled-in on a need bases. Command = command; HiddenCommand = command; myLibraryObject = libraryObject; }
// ------------------------------------------------------------------- /// Advises that a mouse down was performed on the given key. /// /// @param key The library object on which a mouse down occured. /// @param mouseInScreenPoint The position of the mouse. /// @param screenArea The screen area used to display the library object. /// public void MouseDownOn(object key, Vector2 mouseInScreenPoint, Rect screenArea) { if (key == null) { return; } mySelected = key as LibraryObject; }
// ------------------------------------------------------------------------- public void PropertiesWizardDestroy(iCS_EditorObject module, LibraryObject libraryObject) { iCS_EditorObject func = PropertiesWizardFindFunction(module, libraryObject); if (func != null) { DestroyInstance(func); } }
// ================================================================================= // Helpers // --------------------------------------------------------------------------------- static string GetVariableName(LibraryObject libraryObject) { var rawName = libraryObject.rawName; if (rawName.StartsWith("set_") || rawName.StartsWith("get_")) { rawName = rawName.Substring(4); } return(NameUtility.ToDisplayName(rawName)); }
static string GetTypeName(LibraryObject libraryObject) { var type = GetVariableType(libraryObject); if (type == null) { return(null); } return(NameUtility.ToDisplayName(iCS_Types.TypeName(type))); }
// ------------------------------------------------------------------- /// Moves the cursor to the parent object. /// /// @return _true_ if the cursor was moved. _false_ otherwise. /// public bool MoveToParent() { var parent = myCursor.parent; if (parent == null) { return(false); } myCursor = parent as LibraryObject; return(true); }
// --------------------------------------------------------------------------------- /// Creates a visual script node from the given library object. /// /// @param libraryObject The library object from which to create a visual node. /// @param iStorage The storage in which to put the created node. /// @return _true_ if instance was created. _false_ otherwise. /// bool CreateInstance(LibraryObject libraryObject, iCS_IStorage iStorage) { if (libraryObject is LibraryType) { var libraryType = libraryObject as LibraryType; iStorage.CreatePropertyWizardNode(-1, libraryType.type); return(true); } var node = iStorage.CreateNode(-1, libraryObject); return(node != null); }
// ================================================================================= // Drag events. // --------------------------------------------------------------------------------- /// Creates a drag and drop object with a node created from the selecct library /// object. /// /// @param libraryObject The user selected library object. /// void StartDragAndDrop(LibraryObject libraryObject) { // -- Just return if nothing is selected. -- if (libraryObject == null) { return; } // -- Don't allow to drag & drop for libary root and namespace. -- if (libraryObject is LibraryRoot) { return; } if (libraryObject is LibraryRootNamespace) { return; } if (libraryObject is LibraryChildNamespace) { return; } // -- Build drag object. -- GameObject go = new GameObject(libraryObject.nodeName); go.hideFlags = HideFlags.HideAndDontSave; var visualScriptRoot = iCS_DynamicCall.AddLibrary(go); iCS_IStorage iStorage = new iCS_IStorage(visualScriptRoot); if (iStorage == null) { Debug.LogWarning("iCanScript: Cannot create iStorage. Contact support."); } // -- Create node for each known library type. -- if (CreateInstance(libraryObject, iStorage)) { // -- Commit changes to drag & drop storage. -- iStorage.SaveStorage(); // -- Complete the drag information. -- DragAndDrop.PrepareStartDrag(); DragAndDrop.objectReferences = new UnityEngine.Object[1] { go }; DragAndDrop.StartDrag(libraryObject.nodeName); } // -- Release temporary game object in 60 seconds. -- iCS_AutoReleasePool.AutoRelease(go, 60f); }
// ------------------------------------------------------------------- /// Determine if the curent library object requires a foldout. /// /// @return _true_ if current library object requires a foldout. /// _false_ otherwise. /// bool ShouldUseFoldout(LibraryObject libraryObject) { if (libraryObject == null) { return(false); } if (libraryObject is LibraryRootNamespace) { return(true); } if (libraryObject is LibraryChildNamespace) { return(true); } if (libraryObject is LibraryType) { return(true); } return(false); }
// ------------------------------------------------------------------- /// Moves the cursor to the first child. /// /// @return _true_ if the cursor was moved. _false_ otherwise. /// public bool MoveToFirstChild() { var siblings = myCursor.children; if (siblings == null || siblings.Count == 0) { return(false); } int idx = 0; do { if (idx >= siblings.Count) { return(false); } myCursor = siblings[idx] as LibraryObject; ++idx; } while(!ShouldShow(myCursor)); return(true); }
static Type GetVariableType(LibraryObject libraryObject) { var libraryField = libraryObject as LibraryField; if (libraryField != null) { return(libraryField.fieldType); } var libraryGetProperty = libraryObject as LibraryPropertyGetter; if (libraryGetProperty != null) { return(libraryGetProperty.returnType); } var librarySetProperty = libraryObject as LibraryPropertySetter; if (librarySetProperty != null) { return(librarySetProperty.parameters[0].ParameterType); } return(null); }
public static string GetHelpTitle(LibraryObject libraryObject) { string title = "<iCS_highlight>" + libraryObject.nodeName + "</iCS_highlight>"; string typeName = null; string className = null; if (libraryObject is LibraryMemberInfo) { var memberInfo = libraryObject as LibraryMemberInfo; className = iCS_Types.TypeName(memberInfo.declaringType); } if (libraryObject is LibraryField) { typeName = "Property of " + className; } else if (libraryObject is LibraryProperty) { typeName = "Property of " + className; } else if (libraryObject is LibraryConstructor) { typeName = "Variable Builder"; } else if (libraryObject is LibraryFunction) { typeName = "Function of " + className; } else if (libraryObject is LibraryEventHandler) { typeName = "Event Handler for " + className; } else if (libraryObject is LibraryType) { typeName = "Class Instance"; } return("<b>" + typeName + " " + title + "</b>"); }
// ---------------------------------------------------------------------- /// Extracts all functions of a given type. /// /// @param type The type from which to extract. /// static void ExtractFunctions(LibraryType parentType, Type type) { foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static)) { ++myNbOfFunctions; var methodName = method.Name; var parameters = method.GetParameters(); LibraryObject libraryObject = null; if (methodName.StartsWith("get_") && parameters.Length == 0) { libraryObject = new LibraryPropertyGetter(method); } else if (methodName.StartsWith("set_") && parameters.Length == 1) { libraryObject = new LibraryPropertySetter(method); } else { libraryObject = new LibraryFunction(method); } parentType.AddChild(libraryObject); } }
// ---------------------------------------------------------------------- // OK public static iCS_EditorObject CreateFunctionCallNode(iCS_EditorObject parent, Vector2 globalPos, LibraryObject libraryObject) { #if SHOW_DEBUG Debug.Log("iCanScript: Create Function => " + libraryObject.displayString); #endif if (parent == null || libraryObject == null) { return(null); } if (!IsCreationAllowed()) { return(null); } var iStorage = parent.IStorage; OpenTransaction(iStorage); iCS_EditorObject function = null; try { iStorage.AnimateGraph(null, _ => { function = iStorage.CreateNode(parent.InstanceId, libraryObject); function.SetInitialPosition(globalPos); iStorage.ForcedRelayoutOfTree(); iStorage.ReduceCollisionOffset(); } ); } catch (System.Exception) { CancelTransaction(iStorage); return(null); } if (function == null) { CancelTransaction(iStorage); return(null); } var name = libraryObject.nodeName; CloseTransaction(iStorage, "Create " + name); SystemEvents.AnnounceVisualScriptElementAdded(function); return(function); }
// =================================================================== // Tree View Data Source Extensions // ------------------------------------------------------------------- /// Initializes the cursor position. public void Reset() { myCursor = database; }
// ---------------------------------------------------------------------- public iCS_EditorObject PropertiesWizardFindFunction(iCS_EditorObject module, LibraryObject libraryObject) { iCS_EditorObject foundNode = null; module.ForEachChildNode( n => { if (n.DisplayName == libraryObject.nodeName) { foundNode = n; } } ); return(foundNode); }
// ====================================================================== public iCS_EditorObject PropertiesWizardCreate(iCS_EditorObject module, LibraryObject libraryObject) { if (PropertiesWizardFindFunction(module, libraryObject) != null) { return(null); } Rect moduleRect = module.GlobalRect; iCS_EditorObject func = CreateNode(module.InstanceId, libraryObject); func.SetInitialPosition(new Vector2(0.5f * (moduleRect.x + moduleRect.xMax), moduleRect.yMax)); ForEachChildDataPort(func, port => { string modulePortName = port.DisplayName; if (!port.IsTargetOrSelfPort) { modulePortName = libraryObject.nodeName; } if (port.IsInputPort) { // Special case for "instance". if (port.IsTargetPort) { iCS_EditorObject classPort = PropertiesWizardGetInputThisPort(module); if (classPort != null) { SetSource(port, classPort); } else { Debug.LogWarning("iCanScript: Unable to find 'this' input port in class module: " + module.DisplayName); } } else { iCS_EditorObject classPort = PropertiesWizardGetPort(module, modulePortName, VSObjectType.InDynamicDataPort); if (classPort == null) { classPort = CreatePort(modulePortName, module.InstanceId, port.RuntimeType, VSObjectType.InDynamicDataPort); SetSource(port, classPort); } else { SetSource(port, classPort); } } } else { // Special case for "instance". if (port.IsTargetOrSelfPort) { } else { iCS_EditorObject classPort = PropertiesWizardGetPort(module, modulePortName, VSObjectType.OutDynamicDataPort); if (classPort == null) { classPort = CreatePort(modulePortName, module.InstanceId, port.RuntimeType, VSObjectType.OutDynamicDataPort); SetSource(classPort, port); } else { SetSource(classPort, port); } } } } ); func.Iconize(); return(func); }
public VariablePair(LibraryObject inputComponent, bool inputActive, LibraryObject outputComponent, bool outputActive) { InputControlPair = new ControlPair(inputComponent, inputActive); OutputControlPair = new ControlPair(outputComponent, outputActive); }
public ControlPair(LibraryObject libraryObject, bool isActive = false) { Component = libraryObject; IsActive = isActive; }
// ------------------------------------------------------------------- /// Determines if type member should be shown. /// /// @param libraryObject Library object to test. /// @return _true_ if it should be shown. _false_ otherwise. /// bool ShouldShow(LibraryObject libraryObject) { return(libraryObject.isVisible); }
// ---------------------------------------------------------------------- // OK public static iCS_EditorObject CreatePropertiesWizardElement(iCS_EditorObject parent, LibraryObject libraryObject) { #if DEBUG Debug.Log("iCanScript: Create Instance Element => " + libraryObject.displayString); #endif if (parent == null) { return(null); } var iStorage = parent.IStorage; iCS_EditorObject instance = null; OpenTransaction(iStorage); try { SendStartRelayoutOfTree(iStorage); iStorage.AnimateGraph(null, _ => { instance = iStorage.PropertiesWizardCreate(parent, libraryObject); instance.SetInitialPosition(parent.GlobalPosition); instance.Iconize(); iStorage.ForcedRelayoutOfTree(); } ); SendEndRelayoutOfTree(iStorage); } catch (System.Exception) { instance = null; } if (instance == null) { CancelTransaction(iStorage); return(null); } CloseTransaction(iStorage, "Create " + libraryObject.nodeName); return(instance); }
// ---------------------------------------------------------------------- static iCS_EditorObject CreateAttachedMethod(iCS_EditorObject port, iCS_IStorage iStorage, Vector2 globalPos, LibraryObject libraryObject) { iCS_EditorObject newNodeParent = iStorage.GetNodeAt(globalPos); if (newNodeParent == null) { return(null); } if (!newNodeParent.IsKindOfPackage || newNodeParent.IsBehaviour) { return(null); } // FIXME: Animation & force layout sometime conflict. // Open a transaction for multi-operations iCS_UserCommands.OpenTransaction(iStorage); iCS_EditorObject method = null; iStorage.AnimateGraph(null, _ => { if (newNodeParent.IsInstanceNode) { method = iCS_UserCommands.CreatePropertiesWizardElement(newNodeParent, libraryObject); } else { method = iCS_UserCommands.CreateFunctionCallNode(newNodeParent, globalPos, libraryObject); } // Inverse effective data flow if new node is inside port parent. bool isConsumerPort = port.IsInputPort; var portParent = port.ParentNode; if (portParent.IsParentOf(method)) { isConsumerPort = !isConsumerPort; } iCS_EditorObject attachedPort = null; iCS_EditorObject providerPort = null; iCS_EditorObject consumerPort = null; if (isConsumerPort) { iCS_EditorObject[] outputPorts = Prelude.filter(x => iCS_Types.IsA(port.RuntimeType, x.RuntimeType), iStorage.GetChildOutputDataPorts(method)); // Connect if only one possibility. if (outputPorts.Length == 1) { attachedPort = outputPorts[0]; consumerPort = port; providerPort = attachedPort; } else { var bestPort = GetClosestMatch(port, outputPorts); if (bestPort != null) { attachedPort = bestPort; consumerPort = port; providerPort = bestPort; } } } else { iCS_EditorObject[] inputPorts = Prelude.filter(x => iCS_Types.IsA(x.RuntimeType, port.RuntimeType), iStorage.GetChildInputDataPorts(method)); // Connect if only one posiibility if (inputPorts.Length == 1) { attachedPort = inputPorts[0]; consumerPort = attachedPort; providerPort = port; } // Multiple choices exist so try the one with the closest name. else { var bestPort = GetClosestMatch(port, inputPorts); if (bestPort != null) { attachedPort = bestPort; consumerPort = bestPort; providerPort = port; } } } // Position attached port and layout binding. if (attachedPort != null && consumerPort != null && providerPort != null) { iStorage.AutoLayoutPort(attachedPort, port.GlobalPosition, attachedPort.ParentNode.GlobalPosition); iStorage.SetAndAutoLayoutNewDataConnection(consumerPort, providerPort); } iStorage.ForcedRelayoutOfTree(); } ); iCS_UserCommands.CloseTransaction(iStorage, "Create => " + libraryObject.nodeName); return(method); }