Exemplo n.º 1
0
        public void SetInput(InputItem item)
        {
            if (item.inputs.Length != nodes.Length - 1 ||
                inputConnectors == null ||
                inputConnectors.Length < 1)
            {
                return;                           //always have one bias node
            }
            foreach (var ir in inputConnectors)
            {
                if (ir != null)
                {
                    Destroy(ir);
                }
            }

            var input = 0;

            currentInput = item;
            foreach (var node in nodes)
            {
                if (node.input.isBias)
                {
                    continue;
                }

                node.input.SetInput(item.inputs[input]);

                if (input < inputConnectors.Length)
                {
                    c = Instantiate(connector, node.transform);

                    inputConnectors[input] = c;
                    var rn  = node.GetComponent <RectTransform>();
                    var crn = ScreenUtils.GetWorldCorners(rn);

                    c.positionCount = 2;
                    midY            = (crn[2].y + crn[3].y) / 2;
                    c.SetPosition(0, new Vector3(crn[1].x, midY, crn[1].z));

                    var itemNode = item.nodes[input];
                    var ics      = ScreenUtils.GetWorldCorners(itemNode);
                    midY = (ics[2].y + ics[3].y) / 2;
                    c.SetPosition(1, new Vector3(ics[2].x, midY, ics[2].z));

                    input++;
                }
            }

            UpdatePerceptron();
        }
Exemplo n.º 2
0
 private void Awake()
 {
     perceptrons = GetComponentsInChildren <Perceptron>();
     output      = GetComponent <InputItem>();
     outputs     = GetComponentsInChildren <OutputNode>();
 }