Esempio n. 1
0
        public void CloneFieldsFrom(Node _old)
        {
            //        Dictionary<string, SharedVariable> m_SVLookUp=new Dictionary<string,SharedVariable>();
            Type oldType  = _old.GetType(); // typeof(PlayerBTTweaks);
            Type thisType = this.GetType(); // typeof(PlayerBTTweaks);

            FieldInfo[] my_Fields = thisType.GetFields(BindingFlags.Public | BindingFlags.Instance);
            FieldInfo[] oldFields = oldType.GetFields(BindingFlags.Public | BindingFlags.Instance);
            foreach (var m in oldFields)
            {
                //TODO can probably automate this somewhat finding reference types
                if (m.MemberType == MemberTypes.Field && m.FieldType.FullName.Contains("AnimationCurve"))
                {
                    foreach (var n in my_Fields)
                    {
                        if (n.Name == m.Name)
                        {
                            AnimationCurve oldCurve = (AnimationCurve)m.GetValue(_old);

                            n.SetValue(this, new AnimationCurve((Keyframe[])oldCurve.keys.Clone()));
                        }
                    }
                }
                else
                if (m.MemberType == MemberTypes.Field && m.FieldType.FullName.Contains("Gradient"))
                {
                    foreach (var n in my_Fields)
                    {
                        if (n.Name == m.Name)
                        {
                            Gradient oldGradient = (Gradient)m.GetValue(_old);
                            Gradient newGradient = new Gradient();
                            newGradient.SetKeys((GradientColorKey[])oldGradient.colorKeys.Clone(), (GradientAlphaKey[])oldGradient.alphaKeys);

                            n.SetValue(this, newGradient);
                        }
                    }
                }
                else
                if (m.MemberType == MemberTypes.Field &&
                    (m.FieldType.FullName.Contains("Boolean") ||
                     m.FieldType.FullName.Contains("Int32") ||
                     m.FieldType.FullName.Contains("Color") ||
                     m.FieldType.FullName.Contains("TexMode")))
                {
                    foreach (var n in my_Fields)
                    {
                        if (n.Name == m.Name)
                        {
                            n.SetValue(this, m.GetValue(_old));
                        }
                    }
                }
                else
                if (m.MemberType == MemberTypes.Field && m.FieldType.FullName.Contains("FloatRemap"))
                {
                    foreach (var n in my_Fields)
                    {
                        if (n.Name == m.Name)                             // && !n.Name.StartsWith("Input") && !n.Name.StartsWith("Output") && !n.Name.StartsWith("nodeKnobs") && !n.Name.StartsWith("calculated") && !n.Name.StartsWith("rect")))
                        {
                            FloatRemap fr = (FloatRemap)m.GetValue(_old); //its a struct this makes a copy

                            //remove all replace input links


                            if (fr.m_ReplaceWithInput && fr.m_Replacement != null)
                            {
                                //wont find itfr.m_Replacement = n.FindExistingInputByName(_label);
                                var oldReplacement = fr.m_Replacement;
                                fr.m_Replacement = CreateInput(oldReplacement.name, "Float");
                            }
                            else
                            {
                                fr.m_ReplaceWithInput = false;
                                fr.m_Replacement      = null;
                            }


                            n.SetValue(this, fr);
                        }
                    }
                }
            }
        }