// ------------------------------------------------------------------------- public bool ToggleMultiSelection(iCS_EditorObject obj) { if (!IsMultiSelectionAllowed(obj)) { return(false); } if (IsSelectedOrMultiSelected(obj)) { RemoveFromSelectedObjects(obj); return(false); } // Ignore display root if selected if (P.length(mySelectedObjects) == 1 && mySelectedObjects[0] == DisplayRoot) { mySelectedObjects.Clear(); } // Update SelectedObject if multi-select list is empty. if (P.length(mySelectedObjects) == 0) { SelectedObject = obj; } else { AddToSelectedObjects(obj); } return(true); }
public Type[] GetParamTypes(List <iCS_EngineObject> engineObjects) { iCS_EngineObject[] ports = GetChildPortsExcludingControlPorts(engineObjects); Type[] result = new Type[NbOfParams]; for (int i = 0; i < P.length(result); ++i) { result[i] = ports[i].RuntimeType; } return(result); }
// ---------------------------------------------------------------------- private void ResolveCollisionOnChildrenImp(iCS_EditorObject[] children, ref Rect[] childRect) { // Resolve collisions. int r = 0; bool didCollide = true; while (didCollide) { didCollide = false; iCS_EditorObject lowest = null; for (int i = 0; i < children.Length - 1; ++i) { var c1 = children[i]; for (int j = i + 1; j < P.length(children); ++j) { var c2 = children[j]; if (c1.ResolveCollisionBetweenTwoNodes(c2, ref childRect[i], ref childRect[j])) { didCollide = true; #if NEW_COLLISION if (c1.LayoutPriority < c2.LayoutPriority) { c2.LayoutPriority = c1.LayoutPriority + 1; } if (c2.LayoutPriority < c1.LayoutPriority) { c1.LayoutPriority = c2.LayoutPriority + 1; } #else --c1.LayoutPriority; --c2.LayoutPriority; #endif } if (c1.LayoutPriority > c2.LayoutPriority) { lowest = c1; } else if (c2.LayoutPriority > c1.LayoutPriority) { lowest = c2; } } } if (++r > 10) { if (lowest == null || lowest.LayoutPriority <= 1) { break; } lowest.LayoutPriority = lowest.LayoutPriority - 1; r = 0; } } }
// ---------------------------------------------------------------------- public static void AddEngineObject(iCS_IVisualScriptData vsd, iCS_EngineObject toAdd) { // Try to find an available empty slot. int emptySlot = P.findFirst(o => o.InstanceId == -1, (i, o) => i, -1, vsd.EngineObjects); // Grow engine object array if no free slot exists. if (emptySlot != -1) { toAdd.InstanceId = emptySlot; vsd.EngineObjects[emptySlot] = toAdd; return; } toAdd.InstanceId = P.length(vsd.EngineObjects); vsd.EngineObjects.Add(toAdd); }
// ====================================================================== // Collision Functions // ---------------------------------------------------------------------- // Resolves the collision between children. "true" is returned if a // collision has occured. // ---------------------------------------------------------------------- public void ResolveCollisionOnChildrenNodes() { // Get a snapshot of the children state. var children = BuildListOfVisibleChildNodes(c => !c.IsFloating); var childPos = P.map(n => n.LocalAnchorPosition + n.WrappingOffset, children); var childRect = P.map(n => BuildRect(n.LocalAnchorPosition + n.WrappingOffset, n.LocalSize), children); // Resolve collisions. ResolveCollisionOnChildrenImp(children, ref childRect); // Update child position. for (int i = 0; i < P.length(children); ++i) { children[i].CollisionOffset = PositionFrom(childRect[i]) - childPos[i]; } }
// ---------------------------------------------------------------------- void CanvasMenu(iCS_EditorObject selectedObject, iCS_IStorage iStorage) { // Don't show any menu if behaviour not visible. if (selectedObject.IsIconizedInLayout || selectedObject.IsFoldedInLayout) { return; } iCS_MenuContext[] menu = new iCS_MenuContext[3]; menu[0] = new iCS_MenuContext(VariableCreationStr); menu[1] = new iCS_MenuContext(FunctionCreationStr); menu[2] = new iCS_MenuContext(NestedTypeCreationStr); // Add Unity message handlers var baseType = CodeGenerationUtility.GetBaseType(iStorage); if (iCS_Types.IsA <MonoBehaviour>(baseType)) { var libraryType = LibraryController.LibraryDatabase.GetLibraryType(typeof(MonoBehaviour)); var eventHandlers = libraryType.GetMembers <LibraryEventHandler>(); int len = P.length(eventHandlers); int idx = GrowMenuBy(ref menu, len); for (int i = 0; i < len; ++i) { var eventHandler = eventHandlers[i]; string nodeName = eventHandler.nodeName; string displayString = eventHandler.displayString; if (iCS_AllowedChildren.CanAddChildNode(nodeName, VSObjectType.InstanceMessage, selectedObject, iStorage)) { menu[idx + i] = new iCS_MenuContext(String.Concat("+ " + AddUnityEventStr, displayString), eventHandler); } else { menu[idx + i] = new iCS_MenuContext(String.Concat("#+ " + AddUnityEventStr, displayString), eventHandler); } } } ShowMenu(menu, selectedObject, iStorage); }
// ------------------------------------------------------------------- /// Determines if errors are reported for the function call. public bool IsInError(int objectId) { return(P.length(ErrorController.GetErrorsFor(myServiceKey, myVisualScript, objectId)) != 0); }
// ---------------------------------------------------------------------- public static bool HasADestination(iCS_IVisualScriptData vsd, iCS_EngineObject port) { return(P.length(GetConsumerPorts(vsd, port)) != 0); }
public static float FuzzyCompare(string s1, string s2) { int l1 = P.length(s1); int l2 = P.length(s2); bool[] used = new bool[l2]; for (int i = 0; i < l2; ++i) { used[i] = false; } const float kExactMatch = 1f; const float kNoneCaseMatch = 0.9f; const float kOutOfOrderFactor = 0.5f; const float kInOrderFactor = 0.75f; float accum = 0f; int nextIdx = 0; for (int i = 0; i < l1; ++i) { var c1 = s1[i]; // First verify for exact match. float exactScore = 0f; int exactIdx = -1; for (int j = nextIdx; j < l2; ++j) { if (!used[j] && c1 == s2[j]) { if (j == nextIdx) { exactScore = kExactMatch; } else { exactScore = kExactMatch * kInOrderFactor; } exactIdx = j; break; } } if (exactIdx == -1) { for (int j = 0; j < nextIdx; ++j) { if (!used[j] && c1 == s2[j]) { exactScore = kExactMatch * kOutOfOrderFactor; exactIdx = j; break; } } } // Verify for case mismatch. float nonExactScore = 0f; int nonExactIdx = -1; Char uc1 = Char.ToUpper(c1); for (int j = nextIdx; j < l2; ++j) { if (!used[j] && uc1 == Char.ToUpper(s2[j])) { if (j == nextIdx) { nonExactScore = kNoneCaseMatch; } else { nonExactScore = kNoneCaseMatch * kInOrderFactor; } nonExactIdx = j; break; } } if (nonExactIdx == -1) { for (int j = 0; j < nextIdx; ++j) { if (!used[j] && uc1 == Char.ToUpper(s2[j])) { nonExactScore = kNoneCaseMatch * kOutOfOrderFactor; nonExactIdx = j; break; } } } // Go to next if not found. if (exactIdx == -1 && nonExactIdx == -1) { continue; } if (exactScore >= nonExactScore) { used[exactIdx] = true; accum += 2f * exactScore; nextIdx = exactIdx + 1; } else { used[nonExactIdx] = true; accum += 2f * nonExactScore; nextIdx = nonExactIdx + 1; } } return(accum / ((float)(l1 + l2))); }