Exemple #1
0
        public override Node Create(Vector2 pos)
        {
            Texture1Add node = CreateInstance <Texture1Add> ();

            node.rect = new Rect(pos.x, pos.y, m_NodeWidth, m_NodeHeight);
            node.name = "Add";
            node.CreateInputOutputs();
            m_AddConst    = new FloatRemap(0, -1.0f, 1.0f);
            node.m_OpType = MathOp.Add;
            return(node);
        }
Exemple #2
0
        public static void ConnectRemapFloats(Node _n, Func <ScriptableObject, ScriptableObject> replaceSerializableObject)
        {
            if (_n.name.Contains("::"))
            {
                Regex  r = new Regex(@"\d+::");
                string n = _n.name;
                n = r.Replace(n, "");
                Regex r2 = new Regex(@"::\d+");
                n       = r2.Replace(n, "");
                _n.name = n;
                //Debug.Log(" found :: in name "+_n.name+" after replace "+n);
            }
// Get the fields of the specified class.
            FieldInfo[] myField = _n.GetType().GetFields();
            foreach (var x in myField)
            {
                // if(x.FieldType is FloatRemap)
                if (x.GetValue(_n) is FloatRemap)
                {
                    FloatRemap fr = (FloatRemap)x.GetValue(_n);  //its a struct this makes a copy
                    //                Debug.Log(x + " " + x.FieldType + " " + x.GetType() + " " + x.ReflectedType+" fr val:"+fr.m_Value);
                    if (fr.m_ReplaceWithInput && fr.m_Replacement == null)
                    {
                        Debug.LogError(" wants to be replaced but isnt linked ");
                    }
                    else if (fr.m_Replacement != null)
                    {
                        NodeKnob  knob    = fr.m_Replacement;
                        NodeInput replace = replaceSerializableObject.Invoke(knob) as NodeInput;
                        if (replace != null)
                        {
                            fr.m_Replacement = replace;
                        }
                        else
                        {
                            fr.m_Replacement = null;
                        }
                    }
                    x.SetValue(_n, fr); //its a god damn struct it needs to be saved back out
                }
            }
        }
 protected Texture2MathOp()
 {
     m_Value = new FloatRemap(0.5f, 0, 1);
 }
        bool FixupForSubCanvas()
        {
            if (!string.IsNullOrEmpty(m_CanvasGuid) && m_SubCanvas == null)
            {
                string nodeCanvasPath = AssetDatabase.GUIDToAssetPath(m_CanvasGuid);

                m_SubCanvas = NodeEditorSaveManager.LoadNodeCanvas(nodeCanvasPath, false);
                m_WasCloned = false;
            }

            if (m_SubCanvas != null)
            {
                if (!m_WasCloned)
                {
                    m_SubCanvas = NodeEditorSaveManager.CreateWorkingCopy(m_SubCanvas, false); //miked remove ref
                    m_WasCloned = true;

/* test its making unique nodes
 *                  foreach (Node n in m_SubCanvas.nodes)
 *                  {
 *                      if (n is TextureNode)
 *                      {
 *                          var tnIn = n as TextureNode;
 *                          var was = tnIn.m_TexHeight;
 *                          tnIn.m_TexHeight = Random.Range(1000, 1500);
 *                          Debug.Log("Change sub routines node" + tnIn + "  tex height to  " + tnIn.m_TexHeight + " was " + was);
 *
 *                      }
 *                  }
 */
                }

                List <NodeInput>   needsInput  = new List <NodeInput>();
                List <TextureNode> needsOutput = new List <TextureNode>();
                foreach (Node n in m_SubCanvas.nodes)
                {
                    if (n.Inputs.Count > 0)
                    {
                        if (n is UnityTextureOutput && n.Inputs[0].connection != null)
                        {
                            needsOutput.Add(n as TextureNode);
                        }
                        if (n is UnityTextureOutputMetalicAndRoughness && n.Inputs[0].connection != null)
                        {
                            needsOutput.Add(n as TextureNode);
                        }
                        for (int i = 0; i < n.Inputs.Count; i++)
                        {
                            if (n.Inputs[i].connection == null)
                            {
                                //this node has no input so we will wire it up to ours
                                needsInput.Add(n.Inputs[i]);
                                //                            Debug.Log(" missing input for node "+n+" name "+n.name);
                            }
                        }
                    }
                }
                if (needsOutput.Count > Outputs.Count)
                {
                    while (needsOutput.Count > Outputs.Count)
                    {
                        //                    Debug.Log(" create input "+Inputs.Count);

                        string nname = GetNodeOutputName(needsOutput[Outputs.Count]);

                        CreateOutput("Texture" + Outputs.Count + " " + nname, needsOutput[Outputs.Count].Inputs[0].connection.typeID, NodeSide.Right, 50 + Outputs.Count * 20);
                    }
                }
                if (needsOutput.Count > 0)
                {
                    Outputs[0].name = "Texture0" + " " + GetNodeOutputName(needsOutput[0]);
                }

                if (needsInput.Count > Inputs.Count)
                {
                    int added = 0;



                    for (int index = Inputs.Count; index < needsInput.Count; index++)
                    {
                        string needInputname = needsInput[index].name;
                        //                    Debug.Log(" create input "+Inputs.Count);
                        NodeInput newInput = CreateInput(needInputname, needsInput[index].typeID, NodeSide.Left, 30 + Inputs.Count * 20);
                        if (newInput.typeID == "Float")
                        {
                            var n = Node.Create("inputNode", rect.position - new Vector2(100, 50 - added * 60));
                            added++;
                            InputNode inode = n as InputNode;
                            if (inode != null)
                            {
                                newInput.ApplyConnection(inode.Outputs[0], false);
                                InputNode ip = (InputNode)n;
                                Node      nodeThatNeedsInput = needsInput[index].body;
                                //Use reflection to find the float remap member var that matches the input
                                FieldInfo[] myField = nodeThatNeedsInput.GetType().GetFields();
                                foreach (var x in myField)
                                {
                                    // if(x.FieldType is FloatRemap)
                                    if (x.GetValue(nodeThatNeedsInput) is FloatRemap)
                                    {
                                        FloatRemap fr = (FloatRemap)x.GetValue(nodeThatNeedsInput); //its a struct this makes a copy
                                        //                Debug.Log(x + " " + x.FieldType + " " + x.GetType() + " " + x.ReflectedType+" fr val:"+fr.m_Value);
                                        if (fr.m_ReplaceWithInput && fr.m_Replacement == null)
                                        {
                                            Debug.LogError(" wants to be replaced but isnt linked ");
                                        }
                                        else if (fr.m_Replacement != null)
                                        {
                                            NodeKnob  knob    = fr.m_Replacement;
                                            NodeInput replace = knob as NodeInput;
                                            if (replace != null)
                                            {
                                                if (replace == needsInput[index])
                                                {
                                                    ip.m_Value.Set(fr.m_Value);
                                                    ip.m_Value.m_Min = fr.m_Min;
                                                    ip.m_Value.m_Max = fr.m_Max;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    m_InputsCreated = true;
                    //CreateNewFloatInputs();
                    return(false);
                }
            }
            return(true);
        }