public void Load(InputManagerSerializer dick) { forceOverrideSave = true; for (int i = 0; i < dick.nodes.Length; i++) { //Cree les node visual en settant tout bien les public var puis call CreateLinkVisualsForList() sur allnodes Type type = dick.nodes[i].GetAssociatedVisualClass(); GameObject go = new GameObject(type.ToString()); NodeVisual comp = (NodeVisual)go.AddComponent(type); comp.host = this; // comp.caster = caster; comp.canvas = editorUI; comp.doStart = false; comp.node = dick.nodes[i]; RectTransform rect = comp.gameObject.AddComponent <RectTransform>(); rect.SetParent(editorUI.transform, false); allNodes.Add(rect); } StartCoroutine(LoadWait(allNodes, dick.positions)); StartCoroutine(LinkVisualCreationWait(allNodes)); }
public void CreateSelectedNodeAndHide() { Type nodeType; try { nodeType = list[selected.GetText()]; } catch (KeyNotFoundException) { return; } MethodInfo getVisual = nodeType.GetMethod("GetAssociatedVisualClass"); var node = Activator.CreateInstance(nodeType); Type visualType = (Type)getVisual.Invoke(node, null); NodeVisual.Create(visualType, host, new Vector2(UnityEngine.Input.mousePosition.x / Screen.width, UnityEngine.Input.mousePosition.y / Screen.height), spawnNodeIn.gameObject, true); gameObject.SetActive(false); }
internal void RemoveNode(NodeVisual node) { for (int i = 0; i < serializer.nodes.Length; i++) { if (serializer.tmpNodes[i] == node.node) { serializer.tmpNodes.RemoveAt(i); serializer.tmpPos.RemoveAt(i); serializer.PrepareForSerialization(); if (node.GetType() == typeof(GroupOutputNodeVisual)) { groupOuts.Remove((GroupOutputNodeVisual)node); } else if (node.GetType() == typeof(GroupInputNodeVisual)) { groupIns.Remove((GroupInputNodeVisual)node); } //if it's an input/output remove it from list return; } } Debug.LogError("Couldn't remove node " + node.node); }
private void DrawCurveReferences(Rect start, Rect end, NodeVisual visual, DependencyDirection direction) { var xOffset = start.position.x > end.position.x ? 10 : -10; var startPos = new Vector3( start.x + start.width * 0.5f, start.y + start.height, 0 ); var endPos = new Vector3( end.x + end.width * 0.5f + xOffset, end.y, 0 ); var startTan = startPos + Vector3.up * 25; var endTan = endPos + Vector3.down * 75; for (var i = 1; i < 4; i++) { var shadow = new Color32(visual.LineShadowColor.r, visual.LineShadowColor.g, visual.LineShadowColor.b, (byte)Mathf.Clamp(i * 30f, 0, 255)); Handles.DrawBezier(startPos, endPos, startTan, endTan, shadow, null, i * 2); } Handles.DrawBezier(startPos, endPos, startTan, endTan, visual.LineColor, null, 3); var arrowSize = 14; var arrowPosition = startPos + new Vector3(-arrowSize / 2, -2); if (direction == DependencyDirection.Down) { arrowPosition = endPos + new Vector3(-arrowSize / 2, -12); } DrawArrow(arrowPosition, arrowSize, GetArrowByDirection(direction), visual); }
public override void OnSceneViewGUI(SceneView sceneView) { if (EdgeVisual.Visible && EdgeVisual.MouseOver) { return; } // 1. Find target game object. if (m_collectedData == null) { if (GetChild <SelectGameObjectTool>() == null) { SelectGameObjectTool selectGameObjectTool = new SelectGameObjectTool(); selectGameObjectTool.OnSelect = go => { m_collectedData = new CollectedData() { Target = go }; }; AddChild(selectGameObjectTool); } } // 2. Select edge on target game object. else if (!m_collectedData.SelectedEdge.Valid) { Raycast.Hit hit = Raycast.Test(m_collectedData.Target, HandleUtility.GUIPointToWorldRay(Event.current.mousePosition)); if (hit.ClosestEdge.Valid) { m_collectedData.CurrentEdge = hit.ClosestEdge; } } // 3. Find point on edge - hold ctrl for "no-snap" mode. else if (!m_collectedData.PointOnEdgeGiven) { Vector3 pointOnEdge = FindClosestPointOnEdge(m_collectedData.SelectedEdge.Edge); if (Event.current.control) { m_collectedData.PointOnEdge = pointOnEdge; } else { float snapValue = 0.5f * HandleUtility.GetHandleSize(pointOnEdge); float closestDistance = float.PositiveInfinity; Vector3 closestPoint = pointOnEdge; Vector3[] predefinedPoints = FindPredefinedEdgePoints(m_collectedData.SelectedEdge.Edge).ToArray(); // Given set of predefined points along the edge, finds the // closest to the mouse ray (i.e., the actual point on the edge). foreach (var point in predefinedPoints) { float distanceToPoint = Vector3.Distance(pointOnEdge, point); if (distanceToPoint < snapValue && distanceToPoint < closestDistance) { closestPoint = point; closestDistance = distanceToPoint; } } m_collectedData.PointOnEdge = closestPoint; } } // 4. Find direction. else if (!m_collectedData.DirectionGiven) { if (GetChild <DirectionTool>() == null) { DirectionTool directionTool = new DirectionTool(m_collectedData.PointOnEdge, m_collectedData.SelectedEdge.Edge.Direction, m_collectedData.SelectedEdge.Edge.Normal); directionTool.OnSelect += (position, rotation) => { m_collectedData.DirectionRotation = rotation; m_collectedData.DirectionGiven = true; }; AddChild(directionTool); } } // 5. Done, fire callback with result and remove us. else { MeshUtils.Edge orgEdge = m_collectedData.SelectedEdge.Edge; Result resultingData = new Result() { Target = m_collectedData.Target, Edge = new MeshUtils.Edge(m_collectedData.PointOnEdge + 0.5f * orgEdge.Length * (m_collectedData.DirectionRotation * Vector3.back), m_collectedData.PointOnEdge + 0.5f * orgEdge.Length * (m_collectedData.DirectionRotation * Vector3.forward), m_collectedData.DirectionRotation * Vector3.up, MeshUtils.Edge.EdgeType.Triangle), Position = m_collectedData.PointOnEdge, Rotation = m_collectedData.DirectionRotation }; OnEdgeFound(resultingData); PerformRemoveFromParent(); return; } EdgeVisual.Visible = m_collectedData != null && m_collectedData.CurrentEdge.Valid; if (EdgeVisual.Visible) { const float edgeRadius = 0.035f; const float defaultAlpha = 0.25f; const float mouseOverAlpha = 0.65f; EdgeVisual.SetTransform(m_collectedData.CurrentEdge.Edge.Start, m_collectedData.CurrentEdge.Edge.End, edgeRadius); if (m_collectedData.CurrentEdge.Edge.Type == MeshUtils.Edge.EdgeType.Triangle) { EdgeVisual.Color = new Color(Color.yellow.r, Color.yellow.g, Color.yellow.b, defaultAlpha); EdgeVisual.MouseOverColor = new Color(Color.yellow.r, Color.yellow.g, Color.yellow.b, mouseOverAlpha); } else if (m_collectedData.CurrentEdge.Edge.Type == MeshUtils.Edge.EdgeType.Principal) { EdgeVisual.Color = new Color(Color.red.r, Color.red.g, Color.red.b, defaultAlpha); EdgeVisual.MouseOverColor = new Color(Color.red.r, Color.red.g, Color.red.b, mouseOverAlpha); } } NodeVisual.Visible = EdgeVisual.Visible && m_collectedData.SelectedEdge.Valid; if (NodeVisual.Visible) { const float nodeRadius = 0.040f; NodeVisual.SetTransform(m_collectedData.PointOnEdge, Quaternion.identity, nodeRadius); // The user doesn't have to hit the node sphere. if (Manager.HijackLeftMouseClick()) { OnPointClick(null, NodeVisual); } } }
private void OnRightClickSplatSelect(string selected) { if (firstSelectSplat) { firstSelectSplat = false; } else { Destroy(splatRightClick.gameObject); switch (selected) { case "del": { DeleteSelectedNodes(); } break; case "group": { //delete the extra links like in copy //group nodes and delete GroupNodeVisual nv = (GroupNodeVisual)NodeVisual.Create(typeof(GroupNodeVisual), this, new Vector2(Input.mousePosition.x / Screen.width, Input.mousePosition.y / Screen.height), editorUI, false); nv.node = nv.GetNode(); GroupNode groupNode = (GroupNode)nv.node; nv.initClip = clipboard; nv.initClipPos = clipboardPos; VisualEditor.BackEnd.Input[] ins; VisualEditor.BackEnd.Output[] outs; Type[] inTypes; Vector2[] inPos; Vector2[] outPos; CopySelectedNodesForGrouping(out ins, out outs, out inTypes, out inPos, out outPos); List <VisualEditor.BackEnd.Node> clipTmp = new List <VisualEditor.BackEnd.Node>(clipboard); List <Vector2> clipPosTmp = new List <Vector2>(clipboardPos); //create inputs and outputs group nodes for (int i = 0; i < ins.Length; i++) { //TODO quand la node a un input adaptatif ca marche po GroupInputNode node = new GroupInputNode(); node.BeginSetup(); node.SetDataType(inTypes[i]); if (node.outputs[0].ConnectToDiscreet(ins[i])) { clipTmp.Add(node); Vector2 pos = inPos[i] - new Vector2(500f, 0f); while (clipPosTmp.Contains(pos)) //prevent nodes from being on top of each other { pos -= new Vector2(0f, 150f); } clipPosTmp.Add(pos); } else { Debug.Log("in not good"); node.Delete(); } } for (int i = 0; i < outs.Length; i++) { GroupOutputNode node = new GroupOutputNode(); node.BeginSetup(); if (outs[i].ConnectToDiscreet(node.inputs[0])) { clipTmp.Add(node); Vector2 pos = outPos[i] + new Vector2(500f, 0f); while (clipPosTmp.Contains(pos)) { pos -= new Vector2(0f, 150f); } clipPosTmp.Add(pos); } else { Debug.Log("out not good"); node.Delete(); } } InputManager.clipboard = clipTmp.ToArray(); InputManager.clipboardPos = clipPosTmp.ToArray(); groupNode.BeginSetup(); //manually startup the node //delete selected since they have been placed in the group RectTransform[] copy = selectedNodes.ToArray(); for (int i = 0; i < copy.Length; i++) { copy[i].GetComponent <NodeVisual>().Delete(); } } break; case "dis": { for (int i = 0; i < selectedNodes.Count; i++) { NodeVisual n = selectedNodes[i].GetComponent <NodeVisual>(); n.SetEnable(!n.node.enabled); } } break; } } }