Example #1
0
    public static void Paste(object dest)
    {
        if (dest == null || stored_type == null)
        {
            return;
        }

        if ((dest as MochaInterface.Component).myType == "CScript")
        {
            MochaInterface.CScript        cscript = MochaEditor.CastingHelper.CastTo <MochaInterface.CScript>((MochaInterface.Component)dest);
            MochaScriptSystem.BoundScript bs      = MochaScriptSystem.ScriptSubsystemManaged.getInstance().GetBoundScriptFromCScript(cscript);
            if (bs.scriptObject.GetType() != stored_type)
            {
                MochaEditor.Controls.ModernModalWindow mmw = new MochaEditor.Controls.ModernModalWindow("Copy/Paste types do not match.");
                return;
            }

            foreach (var pi in bs.scriptObject.GetType().GetProperties())
            {
                if (pi.Name == "gameObject")
                {
                    continue;                           //do not copy the gameObject this is bound to
                }
                foreach (CopyPasteData data in clipboard)
                {
                    if (pi.Name == data.name && pi.PropertyType == data.value.GetType())
                    {
                        pi.SetValue(bs.scriptObject, data.value);
                    }
                }
            }
            return;
        }

        if (dest.GetType() != stored_type)
        {
            MochaEditor.Controls.ModernModalWindow mmw = new MochaEditor.Controls.ModernModalWindow("Copy/Paste types do not match.");
            return;
        }

        MochaEditor.PropertyValueConverter pvc = new MochaEditor.PropertyValueConverter();
        var pilist = (ObservableCollection <MochaEditor.PropertyValueConverter.PropertyInfo>)pvc.Convert(dest, null, "Component", null);

        foreach (CopyPasteData data in clipboard)
        {
            foreach (MochaEditor.PropertyValueConverter.PropertyInfo pi in pilist)
            {
                if (pi.PropertyName == data.name && pi.PropertyType == data.value.GetType())
                {
                    pi.PropertyValue = data.value;
                }
            }
        }
    }
Example #2
0
    public static void Copy(object c)
    {
        clipboard.Clear();
        if (c == null)
        {
            return;
        }

        if ((c as MochaInterface.Component).myType == "CScript")
        {
            MochaInterface.CScript        cscript = MochaEditor.CastingHelper.CastTo <MochaInterface.CScript>((MochaInterface.Component)c);
            MochaScriptSystem.BoundScript bs      = MochaScriptSystem.ScriptSubsystemManaged.getInstance().GetBoundScriptFromCScript(cscript);
            stored_type = bs.scriptObject.GetType();
            foreach (var pi in bs.scriptObject.GetType().GetProperties())
            {
                if (pi.Name == "gameObject")
                {
                    continue;                           //do not copy the gameObject this is bound to
                }
                if (pi.GetCustomAttribute <MochaDoNotShow>() != null)
                {
                    continue;
                }
                CopyPasteData pd = new CopyPasteData()
                {
                    name  = pi.Name,
                    value = pi.GetValue(bs.scriptObject)
                };
                clipboard.Add(pd);
            }
            return;
        }

        stored_type = c.GetType();

        MochaEditor.PropertyValueConverter pvc = new MochaEditor.PropertyValueConverter();

        foreach (MochaEditor.PropertyValueConverter.PropertyInfo pi in (ObservableCollection <MochaEditor.PropertyValueConverter.PropertyInfo>)pvc.Convert(c, null, "Component", null))
        {
            CopyPasteData pd = new CopyPasteData()
            {
                name  = pi.PropertyName,
                value = pi.PropertyValue
            };
            clipboard.Add(pd);
        }
    }
Example #3
0
    public static void Copy(object c)
    {
        clipboard.Clear();
        if (c == null)
            return;

        if ((c as MochaInterface.Component).myType == "CScript")
        {
            MochaInterface.CScript cscript = MochaEditor.CastingHelper.CastTo<MochaInterface.CScript>((MochaInterface.Component)c);
            MochaScriptSystem.BoundScript bs = MochaScriptSystem.ScriptSubsystemManaged.getInstance().GetBoundScriptFromCScript(cscript);
            stored_type = bs.scriptObject.GetType();
            foreach (var pi in bs.scriptObject.GetType().GetProperties())
            {
                if (pi.Name == "gameObject") continue;  //do not copy the gameObject this is bound to
                if (pi.GetCustomAttribute<MochaDoNotShow>() != null) continue;
                CopyPasteData pd = new CopyPasteData()
                {
                    name = pi.Name,
                    value = pi.GetValue(bs.scriptObject)
                };
                clipboard.Add(pd);
            }
            return;
        }

        stored_type = c.GetType();

        MochaEditor.PropertyValueConverter pvc = new MochaEditor.PropertyValueConverter();

        foreach (MochaEditor.PropertyValueConverter.PropertyInfo pi in (ObservableCollection<MochaEditor.PropertyValueConverter.PropertyInfo>)pvc.Convert(c, null, "Component", null))
        {
            CopyPasteData pd = new CopyPasteData() {
                name = pi.PropertyName,
                value = pi.PropertyValue
            };
            clipboard.Add(pd);
        }
    }
Example #4
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return null;
            var compack = value as MultiComponentPack;

            List<MultiPropertyPack> pack = new List<MultiPropertyPack>();

            if (compack.merged_components.Count == 0)
                return null;

            MochaInterface.Component c = compack.merged_components[0];

            PropertyValueConverter pvc = new PropertyValueConverter();
            var pi_ret = new ObservableCollection<PropertyValueConverter.PropertyInfo>();
            pi_ret = pvc.Convert(c, null, "Component", null) as ObservableCollection<PropertyValueConverter.PropertyInfo>;

            foreach (var pi in pi_ret)
            {
                MultiPropertyPack ppack = new MultiPropertyPack();
                ppack.merged_data = pi.PropertyValue;
                MultiPropertyInfoWrapper merged_pi = new MultiPropertyInfoWrapper();
                merged_pi.merged_name = pi.PropertyName;
                merged_pi.merged_value = pi.PropertyValue;
                merged_pi.participating_objs = new List<object>();
                foreach (var comp in compack.merged_components)
                    merged_pi.participating_objs.Add(comp);

                PropertyValueConverter.PropertyInfo m_pi = new PropertyValueConverter.PropertyInfo();
                m_pi.PropertyName = "merged_value";
                m_pi.PropertyObj = merged_pi;
                m_pi.propertyInfo = merged_pi.GetType().GetProperty("merged_value");
                m_pi.PropertyType = pi.PropertyType;
                m_pi.PropertyValue = merged_pi.merged_value;

                ppack.merged_propertyinfo = m_pi;
                ppack.participating_components = compack.merged_components;
                pack.Add(ppack);
            }
            return pack;
        }
Example #5
0
    public static void Paste(object dest)
    {
        if (dest == null || stored_type == null)
            return;

        if ((dest as MochaInterface.Component).myType == "CScript")
        {
            MochaInterface.CScript cscript = MochaEditor.CastingHelper.CastTo<MochaInterface.CScript>((MochaInterface.Component)dest);
            MochaScriptSystem.BoundScript bs = MochaScriptSystem.ScriptSubsystemManaged.getInstance().GetBoundScriptFromCScript(cscript);
            if (bs.scriptObject.GetType() != stored_type)
            {
                MochaEditor.Controls.ModernModalWindow mmw = new MochaEditor.Controls.ModernModalWindow("Copy/Paste types do not match.");
                return;
            }

            foreach (var pi in bs.scriptObject.GetType().GetProperties())
            {
                if (pi.Name == "gameObject") continue;  //do not copy the gameObject this is bound to

                foreach (CopyPasteData data in clipboard)
                {
                    if (pi.Name == data.name && pi.PropertyType == data.value.GetType())
                    {
                        pi.SetValue(bs.scriptObject, data.value);
                    }
                }
            }
            return;
        }

        if (dest.GetType() != stored_type)
        {
            MochaEditor.Controls.ModernModalWindow mmw = new MochaEditor.Controls.ModernModalWindow("Copy/Paste types do not match.");
            return;
        }

        MochaEditor.PropertyValueConverter pvc = new MochaEditor.PropertyValueConverter();
        var pilist = (ObservableCollection<MochaEditor.PropertyValueConverter.PropertyInfo>)pvc.Convert(dest, null, "Component", null);
        foreach (CopyPasteData data in clipboard)
        {
            foreach (MochaEditor.PropertyValueConverter.PropertyInfo pi in pilist)
            {
                if (pi.PropertyName == data.name && pi.PropertyType == data.value.GetType())
                {
                    pi.PropertyValue = data.value;
                }
            }
        }
    }