Пример #1
0
    protected internal override void CopyScriptableObjects(
        System.Func <ScriptableObject, ScriptableObject> replaceSerializableObject)
    {
        // Get the fields of the specified class.
        FieldInfo[] myField = this.GetType().GetFields();
        foreach (var x in myField)
        {
            // if(x.FieldType is FloatRemap)
            if (x.GetValue(this) is FloatRemap)
            {
                FloatRemap fr = (FloatRemap)x.GetValue(this);  //its a struct this makes a copy
                //                Debug.Log(x + " " + x.FieldType + " " + x.GetType() + " " + x.ReflectedType+" fr val:"+fr.m_Value);

                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(this, fr); //its a god damn struct it needs to be saved back out
            }
        }
    }
Пример #2
0
    public static void ConnectRemapFloats(Node _n, Func <ScriptableObject, ScriptableObject> replaceSerializableObject)
    {
// 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
            }
        }
    }
Пример #3
0
 public FloatRemap(float _val, float _min = 0.0f, float _max = 1.0f)
 {
     m_Value                = _val;
     m_Replacement          = null;
     m_ReplaceWithInput     = false;
     m_ReplaceWithInputNext = m_ReplaceWithInput;
     m_OpenMinMax           = false;
     m_Min  = _min;
     m_Max  = _max;
     m_Mult = 1;
     m_Add  = 0;
 }
Пример #4
0
        private void SaveNewNodeKnob(NodeKnob knob)
        {
            if (mainNodeCanvas.livesInScene)
            {
                return;
            }
            if (!mainNodeCanvas.nodes.Contains(knob.body))
            {
                return;
            }

            CheckCurrentCache();

            NodeEditorSaveManager.AddSubAsset(knob, knob.body);
            foreach (ScriptableObject so in knob.GetScriptableObjects())
            {
                NodeEditorSaveManager.AddSubAsset(so, knob);
            }

            EditorUtility.SetDirty(mainNodeCanvas);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
Пример #5
0
        //Proper way of using this class
        public float SliderLabel(Node _node, string _label)
        {
            if (!m_ReplaceWithInput)
            {
                if (m_Min == 0.0f && m_Max == 0.0f)
                {
                    m_Min = -10f;
                    m_Max = 10.0f;
                }
                m_Min = Mathf.Min(m_Value, m_Min);
                m_Max = Mathf.Max(m_Value, m_Max);
            }
            //using (new EditorGUI.DisabledScope(m_ReplaceWithInput != false))


            //        if (!m_ReplaceWithInput)
            {
                EditorGUILayout.LabelField(_label);

                GUILayout.BeginHorizontal();

                m_ReplaceWithInput = GUILayout.Toggle(m_ReplaceWithInput, m_ReplaceWithInput ? ">>":"<<");
//            if(GUI.enabled)
//                GUI.enabled = !m_ReplaceWithInput;
                m_OpenMinMax = EditorGUILayout.Foldout(m_OpenMinMax, "");
                m_Value      = UnityEditor.EditorGUILayout.Slider(m_Value, m_Min, m_Max);//, sliderOptions);

                GUI.enabled = true;
                GUILayout.EndHorizontal();

                if (m_OpenMinMax)
                {
                    GUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Slider: Min,Max", GUILayout.Width(100));
                    m_Min = EditorGUILayout.FloatField(m_Min);
                    m_Max = EditorGUILayout.FloatField(m_Max);
                    GUILayout.EndHorizontal();
                    if (GUI.enabled)
                    {
                        GUI.enabled = m_ReplaceWithInput;
                    }

                    GUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Input Mult/Add", GUILayout.Width(100));
                    m_Mult = EditorGUILayout.FloatField(m_Mult);
                    m_Add  = EditorGUILayout.FloatField(m_Add);
                    GUILayout.EndHorizontal();
                    GUI.enabled = true;
                }


                //            m_Value = RTEditorGUI.SliderLabel(_label, m_Value, _min, _max); //,new GUIContent("Red", "Float"), m_R);
            }

            if (m_ReplaceWithInput && m_Replacement == null)
            {
                m_Replacement = _node.FindExistingInputByName(_label);
                if (m_Replacement == null)
                {
                    m_Replacement = _node.CreateInput(_label, "Float");
                }
//miked            (m_Replacement as NodeInput).Optional = true;
            }
            if (!m_ReplaceWithInput && m_Replacement != null)
            {
                _node.RemoveInput((m_Replacement as NodeInput));
                m_Replacement = null;
            }
            //        GUI.enabled = m_ReplaceWithInput;

            if (m_ReplaceWithInput && m_Replacement != null)
            {
                GUILayout.BeginHorizontal();
                m_Replacement.name = (string)GUILayout.TextField(m_Replacement.name);
                GUILayout.EndHorizontal();
            }

            if (m_ReplaceWithInput)
            {
                if ((m_Replacement as NodeInput).connection != null)
                {
                    m_Value = (m_Replacement as NodeInput).connection.GetValue <float>();
                }
            }
//        GUI.enabled = true;
            return(m_Value);
        }
Пример #6
0
        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);
        }