Ejemplo n.º 1
0
        internal virtual void Read(BinaryReader r)
        {
            if (controller == null)
            {
                Debug.LogError("no modifier!");
                return;
            }

            editorPos.x = r.ReadSingle();
            editorPos.y = r.ReadSingle();

            Slot[] _slots = this.slots;
            int    scnt   = r.ReadInt32();

            for (int s = 0; s < scnt; ++s)
            {
                string _name = r.ReadString();
                Slot   slot  = null;
                for (int i = 0; i < _slots.Length; ++i)
                {
                    if (_slots[i].name == _name)
                    {
                        slot = _slots[i];
                        break;
                    }
                }

                if (slot != null)
                {
                    int index = r.ReadInt32();
                    if (index != -1)
                    {
                        slot.input = null;
                        if (index >= 0 && index < controller.nodes.Count)
                        {
                            slot.input = controller.nodes[index];
                        }
                    }
                    else
                    {
                        slot.input = null;
                        slot.value.Read(r);
                    }
                }
                else
                {
                    int index = r.ReadInt32();
                    if (index == -1)
                    {
                        Var v = Var.Null;
                        v.Read(r);
                    }
                }
            }

            PoseSlot[] _poseslots = this.poseslots;
            int        sscnt      = r.ReadInt32();

            for (int s = 0; s < sscnt; ++s)
            {
                string   _name    = r.ReadString();
                PoseSlot poseslot = null;
                for (int i = 0; i < _poseslots.Length; ++i)
                {
                    if (_poseslots[i].name == _name)
                    {
                        poseslot = _poseslots[i];
                        break;
                    }
                }

                int index = r.ReadInt32();
                if (poseslot != null)
                {
                    if (index != -1)
                    {
                        poseslot.input = null;
                        if (index >= 0 && index < controller.posenodes.Count)
                        {
                            poseslot.input = controller.posenodes[index];
                        }
                        if (poseslot.input == this)
                        {
                            poseslot.input = null;
                        }
                    }
                    else
                    {
                        poseslot.input = null;
                        poseslot.value = Pose.Default;
                    }
                }
            }

            int dl = r.ReadInt32();

            data = r.ReadBytes(dl);

            if (this is Modifier)
            {
                ModifierAsset ma = ScriptableObject.CreateInstance <ModifierAsset>();
                ma.modifier = this as Modifier;
                ma.data     = new byte[dl];
                Array.Copy(data, ma.data, dl);
                ma.Load(false);
                ModifierAsset.DestroyImmediate(ma);
            }
        }