private void SetPortCount() { // Keep one open slot at the bottom of the input list // Adjust the active signal index if necessary if (dynamicConnectionPorts.Count > targetPortCount) { for (int i = 0; i < dynamicConnectionPorts.Count - 1; i++) { var port = (ValueConnectionKnob)dynamicConnectionPorts[i]; if (!port.connected()) { DeleteConnectionPort(i); if (activeSignalIndex > i) { activeSignalIndex--; } else if (activeSignalIndex == i) { activeSignalIndex = 0; } } } } else if (dynamicConnectionPorts.Count < targetPortCount) { ValueConnectionKnobAttribute outKnobAttribs = new ValueConnectionKnobAttribute("Add input", Direction.In, typeof(float)); while (dynamicConnectionPorts.Count < targetPortCount) { CreateValueConnectionKnob(outKnobAttribs); } } }
private void ProcessResponse(string apiResponse) { var responseObj = JsonUtility.FromJson <ApiResponse>(apiResponse); bool changed = false; Debug.LogFormat("Parsed response: {0}", responseObj.values); if (responseObj.values.Count == dynamicConnectionPorts.Count) { for (int i = 0; i < responseObj.values.Count; i++) { if (dynamicConnectionPorts[i].name != responseObj.values[i].name) { changed = true; break; } } } else { changed = true; } if (changed) { for (int i = dynamicConnectionPorts.Count - 1; i >= 0; i--) { DeleteConnectionPort(i); } outKnobs.Clear(); foreach (var pair in responseObj.values) { ValueConnectionKnobAttribute outKnobAttribs = new ValueConnectionKnobAttribute(pair.name, Direction.Out, typeof(float)); var knob = CreateValueConnectionKnob(outKnobAttribs); outKnobs[pair.name] = knob; } } { foreach (var pair in responseObj.values) { values[pair.name] = pair.value; } } }
public void LoadTextures() { //var foo = ConnectionPortStyles.GetPortStyle("tex"); ValueConnectionKnobAttribute outKnobAttribs = new ValueConnectionKnobAttribute("Output", Direction.Out, typeof(Texture), NodeSide.Bottom); var texStyle = ConnectionPortStyles.GetPortStyle(outKnobAttribs.StyleID); this.TimedDebug("texStyleID: " + outKnobAttribs.StyleID, 2); texStyle.SetColor(Color.yellow); textures = new List <Texture2D>(Resources.LoadAll <Texture2D>("StaticTextures")); if (texKnobs == null) { texKnobs = new SerialDict <string, ValueConnectionKnob>(); } if (texNames == null) { texNames = new List <string>(); } List <string> loadedValues = new List <string>(textures.Select(t => t.name)); HashSet <string> removedValues = new HashSet <string>(texNames); removedValues.ExceptWith(loadedValues); HashSet <string> addedValues = new HashSet <string>(loadedValues); addedValues.ExceptWith(texNames); //Rewire connection ports from loaded strings foreach (string texName in texNames) { texKnobs[texName] = (ValueConnectionKnob)dynamicConnectionPorts[texNames.IndexOf(texName)]; } //Remove any ports for textures that were removed foreach (string texName in removedValues) { dynamicConnectionPorts.Remove(texKnobs[texName]); } // Add ports for any textures that were added foreach (string texName in addedValues) { texKnobs[texName] = CreateValueConnectionKnob(outKnobAttribs); texNames.Add(texName); } }