示例#1
0
文件: TypeParser.cs 项目: kkdevs/sb3u
 public void CopyToRootClass(UType dest)
 {
     for (int i = 1; i < Members.Count; i++)
     {
         Members[i].CopyTo(((UClass)dest).Members[i]);
     }
 }
示例#2
0
 public override void CopyTo(UType dest)
 {
     for (int i = 0; i < Members.Count; i++)
     {
         Members[i].CopyTo(((UClass)dest).Members[i]);
     }
 }
示例#3
0
        UClass GenerateType(AssetCabinet.TypeDefinition typeDef)
        {
            UClass cls = new UClass(typeDef.definitions.type, typeDef.definitions.identifier);

            for (int i = 0; i < typeDef.definitions.children.Length; i++)
            {
                AssetCabinet.TypeDefinitionString memberDef = typeDef.definitions.children[i];
                UType member = GetMember(memberDef);
                cls.Members.Add(member);
            }
            return(cls);
        }
示例#4
0
        public override void CopyTo(UType dest)
        {
            ((Uarray)dest).Value = new UType[Value.Length];
            Type            t    = Members[1].GetType();
            ConstructorInfo info = t.GetConstructor(new Type[] { t });

            for (int i = 0; i < Value.Length; i++)
            {
                ((Uarray)dest).Value[i] = (UType)info.Invoke(new object[] { dest.Members[1] });
                Value[i].CopyTo(((Uarray)dest).Value[i]);
            }
        }
示例#5
0
文件: TypeParser.cs 项目: kkdevs/sb3u
        public static void Delete(Uarray arr, int pos)
        {
            int len = arr.Value != null ? arr.Value.Length : 0;

            if (len == 0)
            {
                return;
            }
            len--;
            UType[] newValue = new UType[len];
            for (int i = 0; i < len; i++)
            {
                newValue[i] = arr.Value[i < pos ? i : i + 1];
            }
            arr.Value = newValue;
        }
示例#6
0
文件: TypeParser.cs 项目: kkdevs/sb3u
        public static void InsertBelow(Uarray arr, int pos)
        {
            pos++;
            int len = arr.Value != null ? arr.Value.Length : 0;

            UType[] newValue = new UType[len + 1];
            for (int i = 0; i < len; i++)
            {
                newValue[i < pos ? i : i + 1] = arr.Value[i];
            }
            Type            t    = arr.Members[1].GetType();
            ConstructorInfo info = t.GetConstructor(new Type[] { t });

            newValue[pos] = (UType)info.Invoke(new object[] { arr.Members[1] });
            arr.Value     = newValue;
        }
示例#7
0
        UType GetMember(AssetCabinet.TypeDefinitionString member)
        {
            switch (member.type)
            {
            case "char":
                return(new Uchar(member.identifier));

            case "bool":
            case "UInt8":
                return(new Uint8(member.identifier));

            case "int":
                return(new Uint32(member.identifier));

            case "unsigned int":
                return(new Uuint32(member.identifier));

            case "float":
                return(new Ufloat(member.identifier));
            }

            UType cls;

            if (member.type.StartsWith("PPtr<") && member.type.EndsWith(">"))
            {
                cls = new UPPtr(file, member.identifier);
            }
            else if (member.type == "Array")
            {
                cls = new Uarray();
            }
            else
            {
                cls = new UClass(member.type, member.identifier);
            }
            for (int i = 0; i < member.children.Length; i++)
            {
                AssetCabinet.TypeDefinitionString memberDef = member.children[i];
                UType submember = GetMember(memberDef);
                cls.Members.Add(submember);
            }
            return(cls);
        }
示例#8
0
文件: TypeParser.cs 项目: kkdevs/sb3u
 public static void UpdatePointersUType(UType t)
 {
     if (t is UPPtr)
     {
         UPPtr p = (UPPtr)t;
         p.Value.Refresh();
     }
     else if (t is Uarray)
     {
         Uarray a = (Uarray)t;
         for (int i = 0; i < a.Value.Length; i++)
         {
             UpdatePointersUType(a.Value[i]);
         }
     }
     else if (t is UClass)
     {
         UpdatePointersUClass((UClass)t);
     }
 }
示例#9
0
文件: TypeParser.cs 项目: kkdevs/sb3u
 public static void MovePointersUType(UType t, Component old, Component replacement, AssetCabinet destFile)
 {
     if (t is UPPtr)
     {
         UPPtr p = (UPPtr)t;
         if (p.Value.asset == old || p.Value.asset is NotLoaded && ((NotLoaded)p.Value.asset).replacement == old)
         {
             p.Value = new PPtr <Object>(replacement, destFile);
         }
     }
     else if (t is Uarray)
     {
         Uarray a = (Uarray)t;
         for (int i = 0; i < a.Value.Length; i++)
         {
             MovePointersUType(a.Value[i], old, replacement, destFile);
         }
     }
     else if (t is UClass)
     {
         MovePointersUClass((UClass)t, old, replacement, destFile);
     }
 }
示例#10
0
        public void SetString(string str)
        {
            if (ClassName != "string")
            {
                return;
            }

            Uarray arr = (Uarray)Members[0];

            byte[]  bytes = UTF8Encoding.UTF8.GetBytes(str);
            UType[] Chars;
            if (arr.Value == null || bytes.Length != arr.Value.Length)
            {
                Chars = new UType[bytes.Length];
                if (arr.Value != null)
                {
                    for (int i = 0; i < Math.Min(bytes.Length, arr.Value.Length); i++)
                    {
                        Chars[i] = arr.Value[i];
                    }
                }
                arr.Value = Chars;
            }
            else
            {
                Chars = arr.Value;
            }
            for (int i = 0; i < bytes.Length; i++)
            {
                if (Chars[i] == null)
                {
                    Chars[i] = new Uchar();
                }
                ((Uchar)Chars[i]).Value = bytes[i];
            }
        }
示例#11
0
 public override void CopyTo(UType dest)
 {
     ((Uchar)dest).Value = Value;
 }
示例#12
0
 public abstract void CopyTo(UType dest);
示例#13
0
        public override void CopyTo(UType dest)
        {
            Component asset = null;

            if (Value.asset != null)
            {
                string name = AssetCabinet.ToString(Value.asset);
                asset = ((UPPtr)dest).file.Bundle.FindComponent(name, Value.asset.classID2);
                if (asset == null)
                {
                    switch (Value.asset.classID2)
                    {
                    case UnityClassID.GameObject:
                        if (((UPPtr)dest).Value == null)
                        {
                            Report.ReportLog("Warning! Unset MonoBehaviour to GameObject " + name);
                            break;
                        }
                        return;

                    case UnityClassID.MonoBehaviour:
                        if (((MonoBehaviour)Value.asset).m_GameObject.instance != null)
                        {
                            Transform trans = Operations.FindFrame(name, AnimatorRoot);
                            if (trans != null)
                            {
                                AssetCabinet.TypeDefinition srcDef = this.file.Types.Find
                                                                     (
                                    delegate(AssetCabinet.TypeDefinition def)
                                {
                                    return(def.typeId == (int)((MonoBehaviour)Value.asset).classID1);
                                }
                                                                     );
                                bool found       = false;
                                var  m_Component = trans.m_GameObject.instance.m_Component;
                                for (int i = 0; i < m_Component.Count; i++)
                                {
                                    if (m_Component[i].Value.asset != null && m_Component[i].Value.asset.classID2 == UnityClassID.MonoBehaviour)
                                    {
                                        AssetCabinet.TypeDefinition destDef = ((UPPtr)dest).file.Types.Find
                                                                              (
                                            delegate(AssetCabinet.TypeDefinition def)
                                        {
                                            return(def.typeId == (int)((MonoBehaviour)m_Component[i].Value.asset).classID1);
                                        }
                                                                              );
                                        if (AssetCabinet.CompareTypes(destDef, srcDef))
                                        {
                                            asset = m_Component[i].Value.asset;
                                            found = true;
                                            break;
                                        }
                                    }
                                }
                                if (!found)
                                {
                                    asset = ((MonoBehaviour)Value.asset).Clone(((UPPtr)dest).file);
                                    trans.m_GameObject.instance.AddLinkedComponent((LinkedByGameObject)asset);
                                }
                            }
                            else
                            {
                                Report.ReportLog("Error! MonoBehaviour reference to " + name + " lost. Member " + Name);
                            }
                        }
                        else
                        {
                            asset = ((MonoBehaviour)Value.asset).Clone(((UPPtr)dest).file);
                        }
                        break;

                    case UnityClassID.MonoScript:
                        asset = ((MonoScript)Value.asset).Clone(((UPPtr)dest).file);
                        break;

                    case UnityClassID.Transform:
                        asset = Operations.FindFrame(name, AnimatorRoot);
                        if (asset == null)
                        {
                            Report.ReportLog("Warning! Transform reference to " + name + " lost. Member " + Name);
                        }
                        break;

                    case UnityClassID.Texture2D:
                        asset = ((Texture2D)Value.asset).Clone(((UPPtr)dest).file);
                        break;

                    default:
                        Report.ReportLog("Warning! MonoBehaviour reference to " + Value.asset.classID2 + " " + name + " unhandled. Member " + Name);
                        break;
                    }
                }
            }
            ((UPPtr)dest).Value = new PPtr <Object>(asset);
        }
示例#14
0
文件: TypeParser.cs 项目: kkdevs/sb3u
 public override void CopyTo(UType dest)
 {
     ((Udouble)dest).Value = Value;
 }
示例#15
0
        public static void CreateMember(ref int line, UType utype, int arrayIndex, TreeNodeCollection nodes)
        {
            if (utype is UClass)
            {
                if (((UClass)utype).ClassName == "string")
                {
                    CreateTreeNode(line, nodes, utype.Name, " (string)", ((UClass)utype).GetString(), arrayIndex);
                }
                else if (((UClass)utype).ClassName == "Vector2f")
                {
                    string value = ((Ufloat)((UClass)utype).Members[0]).Value.ToFloatString()
                                   + ", " + ((Ufloat)((UClass)utype).Members[1]).Value.ToFloatString();
                    CreateTreeNode(line, nodes, utype.Name, " (Vector2f)", value, arrayIndex);
                }
                else if (((UClass)utype).ClassName == "Vector3f")
                {
                    string value = ((Ufloat)((UClass)utype).Members[0]).Value.ToFloatString()
                                   + ", " + ((Ufloat)((UClass)utype).Members[1]).Value.ToFloatString()
                                   + ", " + ((Ufloat)((UClass)utype).Members[2]).Value.ToFloatString();
                    CreateTreeNode(line, nodes, utype.Name, " (Vector3f)", value, arrayIndex);
                }
                else if (((UClass)utype).ClassName == "Vector4f")
                {
                    string value = ((Ufloat)((UClass)utype).Members[0]).Value.ToFloatString()
                                   + ", " + ((Ufloat)((UClass)utype).Members[1]).Value.ToFloatString()
                                   + ", " + ((Ufloat)((UClass)utype).Members[2]).Value.ToFloatString()
                                   + ", " + ((Ufloat)((UClass)utype).Members[3]).Value.ToFloatString();
                    CreateTreeNode(line, nodes, utype.Name, " (Vector4f)", value, arrayIndex);
                }
                else if (((UClass)utype).ClassName == "Quaternionf")
                {
                    string value = ((Ufloat)((UClass)utype).Members[0]).Value.ToFloatString()
                                   + ", " + ((Ufloat)((UClass)utype).Members[1]).Value.ToFloatString()
                                   + ", " + ((Ufloat)((UClass)utype).Members[2]).Value.ToFloatString()
                                   + ", " + ((Ufloat)((UClass)utype).Members[3]).Value.ToFloatString();
                    CreateTreeNode(line, nodes, utype.Name, " (Quaternionf)", value, arrayIndex);
                }
                else if (((UClass)utype).ClassName == "ColorRGBA" && ((UClass)utype).Members.Count == 4)
                {
                    string value = ((Ufloat)((UClass)utype).Members[0]).Value.ToFloatString()
                                   + ", " + ((Ufloat)((UClass)utype).Members[1]).Value.ToFloatString()
                                   + ", " + ((Ufloat)((UClass)utype).Members[2]).Value.ToFloatString()
                                   + ", " + ((Ufloat)((UClass)utype).Members[3]).Value.ToFloatString();
                    CreateTreeNode(line, nodes, utype.Name, " (ColorRGBA)", value, arrayIndex);
                }
                else
                {
                    TreeNode classNode = CreateTreeNode(line, nodes, utype.Name, " " + ((UClass)utype).ClassName, null, arrayIndex, false);
                    line++;
                    for (int i = 0; i < ((UClass)utype).Members.Count; i++)
                    {
                        CreateMember(ref line, ((UClass)utype).Members[i], -1, classNode.Nodes);
                    }
                    line--;
                }
            }
            else if (utype is UPPtr)
            {
                UPPtr     ptr   = (UPPtr)utype;
                Component asset = ptr.Value != null ? ptr.Value.asset : null;
                CreateTreeNode(line, nodes, utype.Name, " (PPtr<" + (asset != null ? asset.classID().ToString() : "") + ">)",
                               ptr.Value != null ? (asset != null ? asset is NotLoaded ? ((NotLoaded)asset).Name : AssetCabinet.ToString(asset) : String.Empty) + " PathID=" + ptr.Value.m_PathID : null, arrayIndex);
            }
            else if (utype is Uarray)
            {
                TreeNode arrayNode = CreateTreeNode(line, nodes, "", "Array size " + (((Uarray)utype).Value != null ? ((Uarray)utype).Value.Length : 0), null, arrayIndex, false);
                arrayNode.Tag = utype;
                line++;

                if (((Uarray)utype).Value != null)
                {
                    for (int i = 0; i < ((Uarray)utype).Value.Length; i++)
                    {
                        CreateMember(ref line, ((Uarray)utype).Value[i], i, arrayNode.Nodes);
                    }
                }
                line--;
            }
            else if (utype is Ufloat)
            {
                CreateTreeNode(line, nodes, utype.Name, " (float)", ((Ufloat)utype).Value.ToFloatString(), arrayIndex);
            }
            else if (utype is Udouble)
            {
                CreateTreeNode(line, nodes, utype.Name, " (double)", ((Udouble)utype).Value.ToDoubleString(), arrayIndex);
            }
            else if (utype is Uint8)
            {
                CreateTreeNode(line, nodes, utype.Name, " (int8)", ((Uint8)utype).Value.ToString(), arrayIndex);
            }
            else if (utype is Uint16)
            {
                CreateTreeNode(line, nodes, utype.Name, " (int16)", ((Uint16)utype).Value.ToString(), arrayIndex);
            }
            else if (utype is Uuint16)
            {
                CreateTreeNode(line, nodes, utype.Name, " (uint16)", ((Uuint16)utype).Value.ToString(), arrayIndex);
            }
            else if (utype is Uint32)
            {
                CreateTreeNode(line, nodes, utype.Name, " (int32)", ((Uint32)utype).Value.ToString(), arrayIndex);
            }
            else if (utype is Uuint32)
            {
                CreateTreeNode(line, nodes, utype.Name, " (uint32)", ((Uuint32)utype).Value.ToString(), arrayIndex);
            }
            else if (utype is Uint64)
            {
                CreateTreeNode(line, nodes, utype.Name, " (int64)", ((Uint64)utype).Value.ToString(), arrayIndex);
            }
            else if (utype is Uuint64)
            {
                CreateTreeNode(line, nodes, utype.Name, " (uint64)", ((Uuint64)utype).Value.ToString(), arrayIndex);
            }
            else
            {
                CreateTreeNode(line, nodes, utype.Name, " " + utype.GetType() + " unhandled", null, arrayIndex, false);
            }
            line++;
        }
示例#16
0
文件: TypeParser.cs 项目: kkdevs/sb3u
 public override void CopyTo(UType dest)
 {
     ((Uint64)dest).Value = Value;
 }
示例#17
0
        public static bool ArrayOperation(UType utype, ref int currentLine, int actionLine, Uarray.action func)
        {
            if (utype is UClass)
            {
                switch (((UClass)utype).ClassName)
                {
                case "string":
                case "Vector2f":
                case "Vector3f":
                case "Vector4f":
                case "Quaternionf":
                    break;

                default:
                    if (((UClass)utype).ClassName == "ColorRGBA" && ((UClass)utype).Members.Count == 4)
                    {
                        break;
                    }
                    currentLine++;
                    for (int i = 0; i < ((UClass)utype).Members.Count; i++)
                    {
                        if (ArrayOperation(((UClass)utype).Members[i], ref currentLine, actionLine, func))
                        {
                            return(true);
                        }
                    }
                    currentLine--;
                    break;
                }
            }
            else if (utype is UPPtr)
            {
            }
            else if (utype is Uarray)
            {
                if (currentLine == actionLine)
                {
                    Uarray arr = (Uarray)utype;
                    if (func == Uarray.Delete && (arr.Value == null || arr.Value.Length == 0))
                    {
                        currentLine = -1;
                        return(true);
                    }
                    func((Uarray)utype, -1);
                    return(true);
                }
                currentLine++;
                for (int i = 0; i < ((Uarray)utype).Value.Length; i++)
                {
                    if (currentLine == actionLine)
                    {
                        func((Uarray)utype, i);
                        return(true);
                    }
                    if (ArrayOperation(((Uarray)utype).Value[i], ref currentLine, actionLine, func))
                    {
                        return(true);
                    }
                }
                currentLine--;
            }
            else if (utype is Ufloat || utype is Udouble ||
                     utype is Uint8 ||
                     utype is Uint16 || utype is Uuint16 ||
                     utype is Uint32 || utype is Uuint32 ||
                     utype is Uint64 || utype is Uuint64)
            {
            }
            else
            {
                Report.ReportLog(currentLine + " " + utype.Name + " " + utype.GetType() + " unhandled");
            }
            currentLine++;
            return(false);
        }
示例#18
0
 public override void CopyTo(UType dest)
 {
     Component asset = null;
     if (Value.asset != null)
     {
         string name = AssetCabinet.ToString(Value.asset);
         asset = ((UPPtr)dest).file.Bundle.FindComponent(name, Value.asset.classID2);
         if (asset == null)
         {
             switch (Value.asset.classID2)
             {
             case UnityClassID.GameObject:
                 if (((UPPtr)dest).Value == null)
                 {
                     Report.ReportLog("Warning! Unset MonoBehaviour to GameObject " + name);
                     break;
                 }
                 return;
             case UnityClassID.MonoBehaviour:
                 if (((MonoBehaviour)Value.asset).m_GameObject.instance != null)
                 {
                     Transform trans = Operations.FindFrame(name, AnimatorRoot);
                     if (trans != null)
                     {
                         AssetCabinet.TypeDefinition srcDef = this.file.Types.Find
                         (
                             delegate(AssetCabinet.TypeDefinition def)
                             {
                                 return def.typeId == (int)((MonoBehaviour)Value.asset).classID1;
                             }
                         );
                         bool found = false;
                         var m_Component = trans.m_GameObject.instance.m_Component;
                         for (int i = 0; i < m_Component.Count; i++)
                         {
                             if (m_Component[i].Value.asset != null && m_Component[i].Value.asset.classID2 == UnityClassID.MonoBehaviour)
                             {
                                 AssetCabinet.TypeDefinition destDef = ((UPPtr)dest).file.Types.Find
                                 (
                                     delegate(AssetCabinet.TypeDefinition def)
                                     {
                                         return def.typeId == (int)((MonoBehaviour)m_Component[i].Value.asset).classID1;
                                     }
                                 );
                                 if (AssetCabinet.CompareTypes(destDef, srcDef))
                                 {
                                     asset = m_Component[i].Value.asset;
                                     found = true;
                                     break;
                                 }
                             }
                         }
                         if (!found)
                         {
                             asset = ((MonoBehaviour)Value.asset).Clone(((UPPtr)dest).file);
                             trans.m_GameObject.instance.AddLinkedComponent((LinkedByGameObject)asset);
                         }
                     }
                     else
                     {
                         Report.ReportLog("Error! MonoBehaviour reference to " + name + " lost. Member " + Name);
                     }
                 }
                 else
                 {
                     asset = ((MonoBehaviour)Value.asset).Clone(((UPPtr)dest).file);
                 }
                 break;
             case UnityClassID.MonoScript:
                 asset = ((MonoScript)Value.asset).Clone(((UPPtr)dest).file);
                 break;
             case UnityClassID.Transform:
                 asset = Operations.FindFrame(name, AnimatorRoot);
                 if (asset == null)
                 {
                     Report.ReportLog("Warning! Transform reference to " + name + " lost. Member " + Name);
                 }
                 break;
             case UnityClassID.Texture2D:
                 asset = ((Texture2D)Value.asset).Clone(((UPPtr)dest).file);
                 break;
             default:
                 Report.ReportLog("Warning! MonoBehaviour reference to " + Value.asset.classID2 + " " + name + " unhandled. Member " + Name);
                 break;
             }
         }
     }
     ((UPPtr)dest).Value = new PPtr<Object>(asset);
 }
示例#19
0
 public override void CopyTo(UType dest)
 {
     ((Ufloat)dest).Value = Value;
 }
示例#20
0
 public abstract void CopyTo(UType dest);
示例#21
0
文件: TypeParser.cs 项目: kkdevs/sb3u
        UType GetMember(AssetCabinet.TypeDefinitionString member)
        {
            switch (member.type)
            {
            case "char":
                return(new Uchar(member.identifier, member.align()));

            case "bool":
            case "SInt8":
            case "UInt8":
                return(new Uint8(member.identifier, member.align()));

            case "SInt16":
                return(new Uint16(member.identifier, member.align()));

            case "UInt16":
                return(new Uuint16(member.identifier, member.align()));

            case "int":
                return(new Uint32(member.identifier, member.align()));

            case "unsigned int":
                return(new Uuint32(member.identifier, member.align()));

            case "int64":
                return(new Uint64(member.identifier, member.align()));

            case "UInt64":
                return(new Uuint64(member.identifier, member.align()));

            case "float":
                return(new Ufloat(member.identifier, member.align()));

            case "double":
                return(new Udouble(member.identifier, member.align()));
            }

            UType cls;

            if (member.type.StartsWith("PPtr<") && member.type.EndsWith(">"))
            {
                cls = new UPPtr(file, member.identifier, member.type, member.align());
            }
            else if (member.type == "Array")
            {
                cls = new Uarray(member.align());
            }
            else
            {
                if (member.type == "StreamedResource")
                {
                    cls = new UStreamedResource(member.type, member.identifier, member.align(), file);
                }
                else
                {
                    cls = new UClass(member.type, member.identifier, member.align());
                }
                if (member.children.Length == 0)
                {
                    Report.ReportLog("Warning! " + member.identifier + " has no members!");
                }
            }
            for (int i = 0; i < member.children.Length; i++)
            {
                AssetCabinet.TypeDefinitionString memberDef = member.children[i];
                UType submember = GetMember(memberDef);
                cls.Members.Add(submember);
            }
            return(cls);
        }
示例#22
0
 public override void CopyTo(UType dest)
 {
     ((Uuint32)dest).Value = Value;
 }
示例#23
0
 public override void CopyTo(UType dest)
 {
     ((Uuint32)dest).Value = Value;
 }
示例#24
0
 public override void CopyTo(UType dest)
 {
     for (int i = 0; i < Members.Count; i++)
     {
         Members[i].CopyTo(((UClass)dest).Members[i]);
     }
 }
示例#25
0
 public override void CopyTo(UType dest)
 {
     ((Ufloat)dest).Value = Value;
 }
示例#26
0
 public static bool SetAttributes(UType utype, ref int currentLine, int lineToChange, string value, AssetCabinet file)
 {
     if (utype is UClass)
     {
         if (((UClass)utype).ClassName == "string")
         {
             if (currentLine == lineToChange)
             {
                 ((UClass)utype).SetString(value);
                 return(true);
             }
         }
         else if (((UClass)utype).ClassName == "Vector2f")
         {
             if (currentLine == lineToChange)
             {
                 string[] sArr = value.Split(',');
                 ((Ufloat)((UClass)utype).Members[0]).Value = Single.Parse(sArr[0]);
                 ((Ufloat)((UClass)utype).Members[1]).Value = Single.Parse(sArr[1]);
                 return(true);
             }
         }
         else if (((UClass)utype).ClassName == "Vector3f")
         {
             if (currentLine == lineToChange)
             {
                 string[] sArr = value.Split(',');
                 ((Ufloat)((UClass)utype).Members[0]).Value = Single.Parse(sArr[0]);
                 ((Ufloat)((UClass)utype).Members[1]).Value = Single.Parse(sArr[1]);
                 ((Ufloat)((UClass)utype).Members[2]).Value = Single.Parse(sArr[2]);
                 return(true);
             }
         }
         else if (((UClass)utype).ClassName == "Vector4f")
         {
             if (currentLine == lineToChange)
             {
                 string[] sArr = value.Split(',');
                 ((Ufloat)((UClass)utype).Members[0]).Value = Single.Parse(sArr[0]);
                 ((Ufloat)((UClass)utype).Members[1]).Value = Single.Parse(sArr[1]);
                 ((Ufloat)((UClass)utype).Members[2]).Value = Single.Parse(sArr[2]);
                 ((Ufloat)((UClass)utype).Members[3]).Value = Single.Parse(sArr[3]);
                 return(true);
             }
         }
         else if (((UClass)utype).ClassName == "Quaternionf")
         {
             if (currentLine == lineToChange)
             {
                 string[] sArr = value.Split(',');
                 ((Ufloat)((UClass)utype).Members[0]).Value = Single.Parse(sArr[0]);
                 ((Ufloat)((UClass)utype).Members[1]).Value = Single.Parse(sArr[1]);
                 ((Ufloat)((UClass)utype).Members[2]).Value = Single.Parse(sArr[2]);
                 ((Ufloat)((UClass)utype).Members[3]).Value = Single.Parse(sArr[3]);
                 return(true);
             }
         }
         else if (((UClass)utype).ClassName == "ColorRGBA" && ((UClass)utype).Members.Count == 4)
         {
             if (currentLine == lineToChange)
             {
                 string[] sArr = value.Split(',');
                 ((Ufloat)((UClass)utype).Members[0]).Value = Single.Parse(sArr[0]);
                 ((Ufloat)((UClass)utype).Members[1]).Value = Single.Parse(sArr[1]);
                 ((Ufloat)((UClass)utype).Members[2]).Value = Single.Parse(sArr[2]);
                 ((Ufloat)((UClass)utype).Members[3]).Value = Single.Parse(sArr[3]);
                 return(true);
             }
         }
         else
         {
             currentLine++;
             for (int i = 0; i < ((UClass)utype).Members.Count; i++)
             {
                 if (SetAttributes(((UClass)utype).Members[i], ref currentLine, lineToChange, value, file))
                 {
                     return(true);
                 }
             }
             currentLine--;
         }
     }
     else if (utype is UPPtr)
     {
         if (currentLine == lineToChange)
         {
             Int64     pathID = Int64.Parse(value);
             Component comp   = pathID != 0 ? file.findComponent[pathID] : null;
             ((UPPtr)utype).Value = new PPtr <Object>(comp);
             return(true);
         }
     }
     else if (utype is Uarray)
     {
         currentLine++;
         for (int i = 0; i < ((Uarray)utype).Value.Length; i++)
         {
             if (SetAttributes(((Uarray)utype).Value[i], ref currentLine, lineToChange, value, file))
             {
                 return(true);
             }
         }
         currentLine--;
     }
     else if (utype is Ufloat)
     {
         if (currentLine == lineToChange)
         {
             ((Ufloat)utype).Value = Single.Parse(value);
             return(true);
         }
     }
     else if (utype is Udouble)
     {
         if (currentLine == lineToChange)
         {
             ((Udouble)utype).Value = Double.Parse(value);
             return(true);
         }
     }
     else if (utype is Uint8)
     {
         if (currentLine == lineToChange)
         {
             ((Uint8)utype).Value = Byte.Parse(value);
             return(true);
         }
     }
     else if (utype is Uint16)
     {
         if (currentLine == lineToChange)
         {
             ((Uint16)utype).Value = Int16.Parse(value);
             return(true);
         }
     }
     else if (utype is Uuint16)
     {
         if (currentLine == lineToChange)
         {
             ((Uuint16)utype).Value = UInt16.Parse(value);
             return(true);
         }
     }
     else if (utype is Uint32)
     {
         if (currentLine == lineToChange)
         {
             ((Uint32)utype).Value = Int32.Parse(value);
             return(true);
         }
     }
     else if (utype is Uuint32)
     {
         if (currentLine == lineToChange)
         {
             ((Uuint32)utype).Value = UInt32.Parse(value);
             return(true);
         }
     }
     else if (utype is Uint64)
     {
         if (currentLine == lineToChange)
         {
             ((Uint64)utype).Value = Int64.Parse(value);
             return(true);
         }
     }
     else if (utype is Uuint64)
     {
         if (currentLine == lineToChange)
         {
             ((Uuint64)utype).Value = UInt64.Parse(value);
             return(true);
         }
     }
     else
     {
         Report.ReportLog(currentLine + " " + utype.Name + " " + utype.GetType() + " unhandled");
     }
     currentLine++;
     return(false);
 }
示例#27
0
 public override void CopyTo(UType dest)
 {
     ((Uchar)dest).Value = Value;
 }
示例#28
0
        public void SetString(string str)
        {
            if (ClassName != "string")
            {
                return;
            }

            Uarray arr = (Uarray)Members[0];
            byte[] bytes = UTF8Encoding.UTF8.GetBytes(str);
            UType[] Chars;
            if (arr.Value == null || bytes.Length != arr.Value.Length)
            {
                Chars = new UType[bytes.Length];
                if (arr.Value != null)
                {
                    for (int i = 0; i < Math.Min(bytes.Length, arr.Value.Length); i++)
                    {
                        Chars[i] = arr.Value[i];
                    }
                }
                arr.Value = Chars;
            }
            else
            {
                Chars = arr.Value;
            }
            for (int i = 0; i < bytes.Length; i++)
            {
                if (Chars[i] == null)
                {
                    Chars[i] = new Uchar();
                }
                ((Uchar)Chars[i]).Value = bytes[i];
            }
        }
示例#29
0
文件: TypeParser.cs 项目: kkdevs/sb3u
        public override void CopyTo(UType dest)
        {
            Component asset = null;

            if (Value.asset != null)
            {
                string name = AssetCabinet.ToString(Value.asset);
                asset = ((UPPtr)dest).file.Bundle.FindComponent(name, Value.asset.classID());
                if (asset == null)
                {
                    switch (Value.asset.classID())
                    {
                    case UnityClassID.GameObject:
                        if (((UPPtr)dest).Value == null)
                        {
                            GameObject gObj = (GameObject)Value.asset;
                            if (gObj != null)
                            {
                                Transform trans = gObj.FindLinkedComponent(typeof(Transform));
                                trans = AnimatorRoot != null?Operations.FindFrame(trans.GetTransformPath(), AnimatorRoot) : null;

                                if (trans != null)
                                {
                                    asset = trans.m_GameObject.instance;
                                    break;
                                }
                            }
                            Report.ReportLog("Warning! Losing PPtr<" + Value.asset.classID() + "> " + Name + " to " + name);
                            break;
                        }
                        return;

                    case UnityClassID.Light:
                        GameObject gameObj = ((Light)Value.asset).m_GameObject.instance;
                        if (gameObj != null)
                        {
                            Transform trans = gameObj.FindLinkedComponent(typeof(Transform));
                            trans = AnimatorRoot != null?Operations.FindFrame(trans.GetTransformPath(), AnimatorRoot) : null;

                            if (trans != null)
                            {
                                asset = trans.m_GameObject.instance.FindLinkedComponent(UnityClassID.Light);
                            }
                            else
                            {
                                foreach (Component a in ((UPPtr)dest).file.Components)
                                {
                                    if (a.classID() == UnityClassID.Light)
                                    {
                                        string n = a is NotLoaded ? ((NotLoaded)a).Name : AssetCabinet.ToString(a);
                                        if (n == name)
                                        {
                                            asset = a;
                                            Report.ReportLog("Warning! Unsharp search for PPtr<" + Value.asset.classID() + "> " + Name + " to " + name + " found PathID=" + a.pathID);
                                            break;
                                        }
                                    }
                                }
                                if (asset == null)
                                {
                                    Report.ReportLog("Warning! Losing PPtr<" + Value.asset.classID() + "> " + Name + " to " + name);
                                }
                            }
                        }
                        break;

                    case UnityClassID.MonoBehaviour:
                        gameObj = ((MonoBehaviour)Value.asset).m_GameObject.instance;
                        if (gameObj != null)
                        {
                            Transform trans = gameObj.FindLinkedComponent(typeof(Transform));
                            trans = AnimatorRoot != null?Operations.FindFrame(trans.GetTransformPath(), AnimatorRoot) : null;

                            if (trans != null)
                            {
                                AssetCabinet.TypeDefinition srcDef =
                                    this.file.VersionNumber < AssetCabinet.VERSION_5_5_0
                                                                        ? this.file.Types.Find
                                    (
                                        delegate(AssetCabinet.TypeDefinition def)
                                {
                                    return(def.typeId == (int)((MonoBehaviour)Value.asset).classID1);
                                }
                                    )
                                                                        : this.file.Types[(int)((MonoBehaviour)Value.asset).classID1];
                                bool found       = false;
                                var  m_Component = trans.m_GameObject.instance.m_Component;
                                for (int i = 0; i < m_Component.Count; i++)
                                {
                                    if (m_Component[i].Value.asset != null && m_Component[i].Value.asset.classID() == UnityClassID.MonoBehaviour)
                                    {
                                        AssetCabinet.TypeDefinition destDef =
                                            ((UPPtr)dest).file.VersionNumber < AssetCabinet.VERSION_5_5_0
                                                                                        ? ((UPPtr)dest).file.Types.Find
                                            (
                                                delegate(AssetCabinet.TypeDefinition def)
                                        {
                                            return(def.typeId == (int)((MonoBehaviour)m_Component[i].Value.asset).classID1);
                                        }
                                            )
                                                                                        : ((UPPtr)dest).file.Types[(int)((MonoBehaviour)m_Component[i].Value.asset).classID1];
                                        if (AssetCabinet.CompareTypes(destDef, srcDef))
                                        {
                                            asset = m_Component[i].Value.asset;
                                            found = true;
                                            break;
                                        }
                                    }
                                }
                                if (!found)
                                {
                                    asset = ((MonoBehaviour)Value.asset).Clone(((UPPtr)dest).file);
                                    trans.m_GameObject.instance.AddLinkedComponent((LinkedByGameObject)asset);
                                }
                            }
                            else
                            {
                                Report.ReportLog("Error! Reference to " + Value.asset.classID() + " " + name + " lost. Member " + Name);
                            }
                        }
                        else
                        {
                            asset = ((MonoBehaviour)Value.asset).Clone(((UPPtr)dest).file);
                        }
                        break;

                    case UnityClassID.MonoScript:
                        asset = ((MonoScript)Value.asset).Clone(((UPPtr)dest).file);
                        break;

                    case UnityClassID.Sprite:
                        asset = ((Sprite)Value.asset).Clone(((UPPtr)dest).file);
                        break;

                    case UnityClassID.Transform:
                        asset = AnimatorRoot != null?Operations.FindFrame(((Transform)Value.asset).GetTransformPath(), AnimatorRoot) : null;

                        if (asset == null)
                        {
                            Report.ReportLog("Warning! Reference to " + UnityClassID.Transform + " " + name + " lost. Member " + Name);
                        }
                        break;

                    case UnityClassID.Material:
                        asset = ((Material)Value.asset).Clone(((UPPtr)dest).file);
                        break;

                    case UnityClassID.MeshRenderer:
                    case UnityClassID.SkinnedMeshRenderer:
                        asset = AnimatorRoot != null?Operations.FindMesh(AnimatorRoot, name) : null;

                        if (asset == null)
                        {
                            Report.ReportLog("Warning! Reference to " + Value.asset.classID() + " " + name + " lost. Member " + Name);
                        }
                        break;

                    case UnityClassID.Texture2D:
                        asset = ((Texture2D)Value.asset).Clone(((UPPtr)dest).file);
                        break;

                    case UnityClassID.Cubemap:
                        asset = ((Cubemap)Value.asset).Clone(((UPPtr)dest).file);
                        break;

                    default:
                        if (Value.asset is LoadedByTypeDefinition)
                        {
                            LoadedByTypeDefinition loadedByTypeDef = (LoadedByTypeDefinition)Value.asset;
                            PPtr <GameObject>      gameObjPtr      = loadedByTypeDef.m_GameObject;
                            if (gameObjPtr == null)
                            {
                                AssetCabinet file = ((UPPtr)dest).file;
                                foreach (Component a in file.Components)
                                {
                                    if (a.classID() == loadedByTypeDef.classID() &&
                                        (a is NotLoaded ? ((NotLoaded)a).Name : AssetCabinet.ToString(a)) == loadedByTypeDef.m_Name)
                                    {
                                        asset = a;

                                        file = null;
                                        break;
                                    }
                                }
                                if (file != null)
                                {
                                    asset = loadedByTypeDef.Clone(file);
                                }
                            }
                            else
                            {
                                Transform srcTrans  = gameObjPtr.instance.FindLinkedComponent(typeof(Transform));
                                Transform destTrans = AnimatorRoot != null?Operations.FindFrame(srcTrans.GetTransformPath(), AnimatorRoot) : null;

                                if (destTrans != null)
                                {
                                    asset = destTrans.m_GameObject.instance.FindLinkedComponent(loadedByTypeDef.classID());
                                }
                                else
                                {
                                    foreach (Component a in ((UPPtr)dest).file.Components)
                                    {
                                        if (a.classID() == Value.asset.classID())
                                        {
                                            string n = a is NotLoaded ? ((NotLoaded)a).Name : AssetCabinet.ToString(a);
                                            if (n == name)
                                            {
                                                asset = a;
                                                Report.ReportLog("Warning! Unsharp search for PPtr<" + Value.asset.classID() + "> " + Name + " to " + name + " found PathID=" + a.pathID);
                                                break;
                                            }
                                        }
                                    }
                                    if (asset == null)
                                    {
                                        Report.ReportLog("Warning! Losing PPtr<" + Value.asset.classID() + "> " + Name + " to " + name);
                                    }
                                }
                            }
                        }
                        else
                        {
                            Report.ReportLog("Warning! Reference to " + Value.asset.classID() + " " + name + " unhandled. Member " + Name);
                        }
                        break;
                    }
                }
            }
            ((UPPtr)dest).Value = new PPtr <Object>(asset);
        }
示例#30
0
 public override void CopyTo(UType dest)
 {
     ((Uarray)dest).Value = new UType[Value.Length];
     Type t = Members[1].GetType();
     ConstructorInfo info = t.GetConstructor(new Type[] { t });
     for (int i = 0; i < Value.Length; i++)
     {
         ((Uarray)dest).Value[i] = (UType)info.Invoke(new object[] { dest.Members[1] });
         Value[i].CopyTo(((Uarray)dest).Value[i]);
     }
 }