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
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(CScript obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Example #4
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(CScript obj)
 {
     return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }