public void SetMemberCorrectlyConvertsToJson() { var setMember = new SetMember <string>(new List <string> { "basho", "google", "yahoo" }); setMember.ToString().ShouldEqual(SetMemberJson); }
public void Parse() { var current = _reader.BaseStream.Position; _reader.BaseStream.Seek(_offset, SeekOrigin.Begin); bool parsing = true; bool branched = false; int branchBytes = 0; while (parsing) { //now reader the instructions var type = _reader.ReadByteAsEnum <InstructionType>(); var aligned = InstructionAlignment.IsAligned(type); if (aligned) { var padding = _reader.Align(4); if (padding > 0) { Items.Add(new Padding(padding)); if (branched) { branchBytes -= (int)padding; if (branchBytes <= 0) { branched = false; branchBytes = 0; } } } } InstructionBase instruction = null; List <Value> parameters = new List <Value>(); switch (type) { case InstructionType.ToNumber: instruction = new ToNumber(); break; case InstructionType.NextFrame: instruction = new NextFrame(); break; case InstructionType.Play: instruction = new Play(); break; case InstructionType.Stop: instruction = new Stop(); break; case InstructionType.Add: instruction = new Add(); break; case InstructionType.Subtract: instruction = new Subtract(); break; case InstructionType.Multiply: instruction = new Multiply(); break; case InstructionType.Divide: instruction = new Divide(); break; case InstructionType.Not: instruction = new Not(); break; case InstructionType.StringEquals: instruction = new StringEquals(); break; case InstructionType.Pop: instruction = new Pop(); break; case InstructionType.ToInteger: instruction = new ToInteger(); break; case InstructionType.GetVariable: instruction = new GetVariable(); break; case InstructionType.SetVariable: instruction = new SetVariable(); break; case InstructionType.StringConcat: instruction = new StringConcat(); break; case InstructionType.GetProperty: instruction = new GetProperty(); break; case InstructionType.SetProperty: instruction = new SetProperty(); break; case InstructionType.Trace: instruction = new Trace(); break; case InstructionType.Delete: instruction = new Delete(); break; case InstructionType.Delete2: instruction = new Delete2(); break; case InstructionType.DefineLocal: instruction = new DefineLocal(); break; case InstructionType.CallFunction: instruction = new CallFunction(); break; case InstructionType.Return: instruction = new Return(); break; case InstructionType.NewObject: instruction = new NewObject(); break; case InstructionType.InitArray: instruction = new InitArray(); break; case InstructionType.InitObject: instruction = new InitObject(); break; case InstructionType.TypeOf: instruction = new InitObject(); break; case InstructionType.Add2: instruction = new Add2(); break; case InstructionType.LessThan2: instruction = new LessThan2(); break; case InstructionType.Equals2: instruction = new Equals2(); break; case InstructionType.ToString: instruction = new ToString(); break; case InstructionType.PushDuplicate: instruction = new PushDuplicate(); break; case InstructionType.GetMember: instruction = new GetMember(); break; case InstructionType.SetMember: instruction = new SetMember(); break; case InstructionType.Increment: instruction = new Increment(); break; case InstructionType.Decrement: instruction = new Decrement(); break; case InstructionType.CallMethod: instruction = new CallMethod(); break; case InstructionType.Enumerate2: instruction = new Enumerate2(); break; case InstructionType.EA_PushThis: instruction = new PushThis(); break; case InstructionType.EA_PushZero: instruction = new PushZero(); break; case InstructionType.EA_PushOne: instruction = new PushOne(); break; case InstructionType.EA_CallFunc: instruction = new CallFunc(); break; case InstructionType.EA_CallMethodPop: instruction = new CallMethodPop(); break; case InstructionType.BitwiseXOr: instruction = new BitwiseXOr(); break; case InstructionType.Greater: instruction = new Greater(); break; case InstructionType.EA_PushThisVar: instruction = new PushThisVar(); break; case InstructionType.EA_PushGlobalVar: instruction = new PushGlobalVar(); break; case InstructionType.EA_ZeroVar: instruction = new ZeroVar(); break; case InstructionType.EA_PushTrue: instruction = new PushTrue(); break; case InstructionType.EA_PushFalse: instruction = new PushFalse(); break; case InstructionType.EA_PushNull: instruction = new PushNull(); break; case InstructionType.EA_PushUndefined: instruction = new PushUndefined(); break; case InstructionType.GotoFrame: instruction = new GotoFrame(); parameters.Add(Value.FromInteger(_reader.ReadInt32())); break; case InstructionType.GetURL: instruction = new GetUrl(); parameters.Add(Value.FromString(_reader.ReadStringAtOffset())); parameters.Add(Value.FromString(_reader.ReadStringAtOffset())); break; case InstructionType.SetRegister: instruction = new SetRegister(); parameters.Add(Value.FromInteger(_reader.ReadInt32())); break; case InstructionType.ConstantPool: { instruction = new ConstantPool(); var count = _reader.ReadUInt32(); var constants = _reader.ReadFixedSizeArrayAtOffset <uint>(() => _reader.ReadUInt32(), count); foreach (var constant in constants) { parameters.Add(Value.FromConstant(constant)); } } break; case InstructionType.GotoLabel: instruction = new GotoLabel(); parameters.Add(Value.FromString(_reader.ReadStringAtOffset())); break; case InstructionType.DefineFunction2: { instruction = new DefineFunction2(); var name = _reader.ReadStringAtOffset(); var nParams = _reader.ReadUInt32(); var nRegisters = _reader.ReadByte(); var flags = _reader.ReadUInt24(); //list of parameter strings var paramList = _reader.ReadFixedSizeListAtOffset <FunctionArgument>(() => new FunctionArgument() { Register = _reader.ReadInt32(), Parameter = _reader.ReadStringAtOffset(), }, nParams); parameters.Add(Value.FromString(name)); parameters.Add(Value.FromInteger((int)nParams)); parameters.Add(Value.FromInteger((int)nRegisters)); parameters.Add(Value.FromInteger((int)flags)); foreach (var param in paramList) { parameters.Add(Value.FromInteger(param.Register)); parameters.Add(Value.FromString(param.Parameter)); } //body size of the function parameters.Add(Value.FromInteger(_reader.ReadInt32())); //skip 8 bytes _reader.ReadUInt64(); } break; case InstructionType.PushData: { instruction = new PushData(); var count = _reader.ReadUInt32(); var constants = _reader.ReadFixedSizeArrayAtOffset <uint>(() => _reader.ReadUInt32(), count); foreach (var constant in constants) { parameters.Add(Value.FromConstant(constant)); } } break; case InstructionType.BranchAlways: instruction = new BranchAlways(); if (!branched) { branchBytes = _reader.ReadInt32(); parameters.Add(Value.FromInteger(branchBytes)); if (branchBytes > 0) { branchBytes += (int)instruction.Size + 1; branched = true; } } else { parameters.Add(Value.FromInteger(_reader.ReadInt32())); } break; case InstructionType.GetURL2: instruction = new GetUrl2(); break; case InstructionType.DefineFunction: { instruction = new DefineFunction(); var name = _reader.ReadStringAtOffset(); //list of parameter strings var paramList = _reader.ReadListAtOffset <string>(() => _reader.ReadStringAtOffset()); parameters.Add(Value.FromString(name)); parameters.Add(Value.FromInteger(paramList.Count)); foreach (var param in paramList) { parameters.Add(Value.FromString(param)); } //body size of the function parameters.Add(Value.FromInteger(_reader.ReadInt32())); //skip 8 bytes _reader.ReadUInt64(); } break; case InstructionType.BranchIfTrue: instruction = new BranchIfTrue(); if (!branched) { branchBytes = _reader.ReadInt32(); parameters.Add(Value.FromInteger(branchBytes)); if (branchBytes > 0) { branchBytes += (int)instruction.Size + 1; branched = true; } } else { parameters.Add(Value.FromInteger(_reader.ReadInt32())); } break; case InstructionType.GotoFrame2: instruction = new GotoFrame2(); parameters.Add(Value.FromInteger(_reader.ReadByte())); break; case InstructionType.EA_PushString: instruction = new PushString(); //the constant id that should be pushed parameters.Add(Value.FromString(_reader.ReadStringAtOffset())); break; case InstructionType.EA_PushConstantByte: instruction = new PushConstantByte(); //the constant id that should be pushed parameters.Add(Value.FromConstant(_reader.ReadByte())); break; case InstructionType.EA_GetStringVar: instruction = new GetStringVar(); parameters.Add(Value.FromString(_reader.ReadStringAtOffset())); break; case InstructionType.EA_SetStringVar: instruction = new SetStringMember(); parameters.Add(Value.FromString(_reader.ReadStringAtOffset())); break; case InstructionType.EA_GetStringMember: instruction = new GetStringMember(); parameters.Add(Value.FromString(_reader.ReadStringAtOffset())); break; case InstructionType.EA_SetStringMember: instruction = new SetStringMember(); parameters.Add(Value.FromString(_reader.ReadStringAtOffset())); break; case InstructionType.EA_PushValueOfVar: instruction = new PushValueOfVar(); //the constant id that should be pushed parameters.Add(Value.FromConstant(_reader.ReadByte())); break; case InstructionType.EA_GetNamedMember: instruction = new GetNamedMember(); parameters.Add(Value.FromConstant(_reader.ReadByte())); break; case InstructionType.EA_CallNamedFuncPop: instruction = new CallNamedFuncPop(); parameters.Add(Value.FromConstant(_reader.ReadByte())); break; case InstructionType.EA_CallNamedFunc: instruction = new CallNamedFunc(); parameters.Add(Value.FromConstant(_reader.ReadByte())); break; case InstructionType.EA_CallNamedMethodPop: instruction = new CallNamedMethodPop(); parameters.Add(Value.FromConstant(_reader.ReadByte())); break; case InstructionType.EA_PushFloat: instruction = new PushFloat(); parameters.Add(Value.FromFloat(_reader.ReadSingle())); break; case InstructionType.EA_PushByte: instruction = new PushByte(); parameters.Add(Value.FromInteger(_reader.ReadByte())); break; case InstructionType.EA_PushShort: instruction = new PushShort(); parameters.Add(Value.FromInteger(_reader.ReadUInt16())); break; case InstructionType.End: instruction = new End(); if (!branched) { parsing = false; } break; case InstructionType.EA_CallNamedMethod: instruction = new CallNamedMethod(); parameters.Add(Value.FromConstant(_reader.ReadByte())); break; case InstructionType.Var: instruction = new Var(); break; default: throw new InvalidDataException("Unimplemented bytecode instruction:" + type.ToString()); } if (instruction != null) { instruction.Parameters = parameters; Items.Add(instruction); } if (branched) { branchBytes -= (int)instruction.Size + 1; if (branchBytes <= 0) { branched = false; } } } _reader.BaseStream.Seek(current, SeekOrigin.Begin); }
public static InstructionCollection Parse(Stream input, long instructionsPosition) { var instructions = new SortedList <int, InstructionBase>(); using (var helper = new InstructionParseHelper(input, instructionsPosition)) { var reader = helper.GetReader(); while (helper.CanParse(instructions)) { //now reader the instructions var instructionPosition = helper.CurrentPosition; var type = reader.ReadByteAsEnum <InstructionType>(); var requireAlignment = InstructionAlignment.IsAligned(type); if (requireAlignment) { reader.Align(4); } InstructionBase instruction = null; var parameters = new List <Value>(); switch (type) { case InstructionType.ToNumber: instruction = new ToNumber(); break; case InstructionType.NextFrame: instruction = new NextFrame(); break; case InstructionType.Play: instruction = new Play(); break; case InstructionType.Stop: instruction = new Stop(); break; case InstructionType.Add: instruction = new Add(); break; case InstructionType.Subtract: instruction = new Subtract(); break; case InstructionType.Multiply: instruction = new Multiply(); break; case InstructionType.Divide: instruction = new Divide(); break; case InstructionType.Not: instruction = new Not(); break; case InstructionType.StringEquals: instruction = new StringEquals(); break; case InstructionType.Pop: instruction = new Pop(); break; case InstructionType.ToInteger: instruction = new ToInteger(); break; case InstructionType.GetVariable: instruction = new GetVariable(); break; case InstructionType.SetVariable: instruction = new SetVariable(); break; case InstructionType.StringConcat: instruction = new StringConcat(); break; case InstructionType.GetProperty: instruction = new GetProperty(); break; case InstructionType.SetProperty: instruction = new SetProperty(); break; case InstructionType.Trace: instruction = new Trace(); break; case InstructionType.Random: instruction = new RandomNumber(); break; case InstructionType.Delete: instruction = new Delete(); break; case InstructionType.Delete2: instruction = new Delete2(); break; case InstructionType.DefineLocal: instruction = new DefineLocal(); break; case InstructionType.CallFunction: instruction = new CallFunction(); break; case InstructionType.Return: instruction = new Return(); break; case InstructionType.Modulo: instruction = new Modulo(); break; case InstructionType.NewObject: instruction = new NewObject(); break; case InstructionType.InitArray: instruction = new InitArray(); break; case InstructionType.InitObject: instruction = new InitObject(); break; case InstructionType.TypeOf: instruction = new TypeOf(); break; case InstructionType.Add2: instruction = new Add2(); break; case InstructionType.LessThan2: instruction = new LessThan2(); break; case InstructionType.Equals2: instruction = new Equals2(); break; case InstructionType.ToString: instruction = new ToString(); break; case InstructionType.PushDuplicate: instruction = new PushDuplicate(); break; case InstructionType.GetMember: instruction = new GetMember(); break; case InstructionType.SetMember: instruction = new SetMember(); break; case InstructionType.Increment: instruction = new Increment(); break; case InstructionType.Decrement: instruction = new Decrement(); break; case InstructionType.CallMethod: instruction = new CallMethod(); break; case InstructionType.Enumerate2: instruction = new Enumerate2(); break; case InstructionType.EA_PushThis: instruction = new PushThis(); break; case InstructionType.EA_PushZero: instruction = new PushZero(); break; case InstructionType.EA_PushOne: instruction = new PushOne(); break; case InstructionType.EA_CallFunc: instruction = new CallFunc(); break; case InstructionType.EA_CallMethodPop: instruction = new CallMethodPop(); break; case InstructionType.BitwiseXOr: instruction = new BitwiseXOr(); break; case InstructionType.Greater: instruction = new Greater(); break; case InstructionType.EA_PushThisVar: instruction = new PushThisVar(); break; case InstructionType.EA_PushGlobalVar: instruction = new PushGlobalVar(); break; case InstructionType.EA_ZeroVar: instruction = new ZeroVar(); break; case InstructionType.EA_PushTrue: instruction = new PushTrue(); break; case InstructionType.EA_PushFalse: instruction = new PushFalse(); break; case InstructionType.EA_PushNull: instruction = new PushNull(); break; case InstructionType.EA_PushUndefined: instruction = new PushUndefined(); break; case InstructionType.GotoFrame: instruction = new GotoFrame(); parameters.Add(Value.FromInteger(reader.ReadInt32())); break; case InstructionType.GetURL: instruction = new GetUrl(); parameters.Add(Value.FromString(reader.ReadStringAtOffset())); parameters.Add(Value.FromString(reader.ReadStringAtOffset())); break; case InstructionType.SetRegister: instruction = new SetRegister(); parameters.Add(Value.FromInteger(reader.ReadInt32())); break; case InstructionType.ConstantPool: { instruction = new ConstantPool(); var count = reader.ReadUInt32(); var constants = reader.ReadFixedSizeArrayAtOffset <uint>(() => reader.ReadUInt32(), count); foreach (var constant in constants) { parameters.Add(Value.FromConstant(constant)); } } break; case InstructionType.GotoLabel: instruction = new GotoLabel(); parameters.Add(Value.FromString(reader.ReadStringAtOffset())); break; case InstructionType.DefineFunction2: { instruction = new DefineFunction2(); var name = reader.ReadStringAtOffset(); var nParams = reader.ReadUInt32(); var nRegisters = reader.ReadByte(); var flags = reader.ReadUInt24(); //list of parameter strings var paramList = reader.ReadFixedSizeListAtOffset <FunctionArgument>(() => new FunctionArgument() { Register = reader.ReadInt32(), Parameter = reader.ReadStringAtOffset(), }, nParams); parameters.Add(Value.FromString(name)); parameters.Add(Value.FromInteger((int)nParams)); parameters.Add(Value.FromInteger((int)nRegisters)); parameters.Add(Value.FromInteger((int)flags)); foreach (var param in paramList) { parameters.Add(Value.FromInteger(param.Register)); parameters.Add(Value.FromString(param.Parameter)); } //body size of the function parameters.Add(Value.FromInteger(reader.ReadInt32())); //skip 8 bytes reader.ReadUInt64(); } break; case InstructionType.PushData: { instruction = new PushData(); var count = reader.ReadUInt32(); var constants = reader.ReadFixedSizeArrayAtOffset <uint>(() => reader.ReadUInt32(), count); foreach (var constant in constants) { parameters.Add(Value.FromConstant(constant)); } } break; case InstructionType.BranchAlways: { instruction = new BranchAlways(); var offset = reader.ReadInt32(); parameters.Add(Value.FromInteger(offset)); helper.ReportBranchOffset(offset); } break; case InstructionType.GetURL2: instruction = new GetUrl2(); break; case InstructionType.DefineFunction: { instruction = new DefineFunction(); var name = reader.ReadStringAtOffset(); //list of parameter strings var paramList = reader.ReadListAtOffset <string>(() => reader.ReadStringAtOffset()); parameters.Add(Value.FromString(name)); parameters.Add(Value.FromInteger(paramList.Count)); foreach (var param in paramList) { parameters.Add(Value.FromString(param)); } //body size of the function parameters.Add(Value.FromInteger(reader.ReadInt32())); //skip 8 bytes reader.ReadUInt64(); } break; case InstructionType.BranchIfTrue: { instruction = new BranchIfTrue(); var offset = reader.ReadInt32(); parameters.Add(Value.FromInteger(offset)); helper.ReportBranchOffset(offset); } break; case InstructionType.GotoFrame2: instruction = new GotoFrame2(); parameters.Add(Value.FromInteger(reader.ReadInt32())); break; case InstructionType.EA_PushString: instruction = new PushString(); //the constant id that should be pushed parameters.Add(Value.FromString(reader.ReadStringAtOffset())); break; case InstructionType.EA_PushConstantByte: instruction = new PushConstantByte(); //the constant id that should be pushed parameters.Add(Value.FromConstant(reader.ReadByte())); break; case InstructionType.EA_GetStringVar: instruction = new GetStringVar(); parameters.Add(Value.FromString(reader.ReadStringAtOffset())); break; case InstructionType.EA_SetStringVar: instruction = new SetStringVar(); parameters.Add(Value.FromString(reader.ReadStringAtOffset())); break; case InstructionType.EA_GetStringMember: instruction = new GetStringMember(); parameters.Add(Value.FromString(reader.ReadStringAtOffset())); break; case InstructionType.EA_SetStringMember: instruction = new SetStringMember(); parameters.Add(Value.FromString(reader.ReadStringAtOffset())); break; case InstructionType.EA_PushValueOfVar: instruction = new PushValueOfVar(); //the constant id that should be pushed parameters.Add(Value.FromConstant(reader.ReadByte())); break; case InstructionType.EA_GetNamedMember: instruction = new GetNamedMember(); parameters.Add(Value.FromConstant(reader.ReadByte())); break; case InstructionType.EA_CallNamedFuncPop: instruction = new CallNamedFuncPop(); parameters.Add(Value.FromConstant(reader.ReadByte())); break; case InstructionType.EA_CallNamedFunc: instruction = new CallNamedFunc(); parameters.Add(Value.FromConstant(reader.ReadByte())); break; case InstructionType.EA_CallNamedMethodPop: instruction = new CallNamedMethodPop(); parameters.Add(Value.FromConstant(reader.ReadByte())); break; case InstructionType.EA_PushFloat: instruction = new PushFloat(); parameters.Add(Value.FromFloat(reader.ReadSingle())); break; case InstructionType.EA_PushByte: instruction = new PushByte(); parameters.Add(Value.FromInteger(reader.ReadByte())); break; case InstructionType.EA_PushShort: instruction = new PushShort(); parameters.Add(Value.FromInteger(reader.ReadUInt16())); break; case InstructionType.End: instruction = new End(); break; case InstructionType.EA_CallNamedMethod: instruction = new CallNamedMethod(); parameters.Add(Value.FromConstant(reader.ReadByte())); break; case InstructionType.Var: instruction = new Var(); break; case InstructionType.EA_PushRegister: instruction = new PushRegister(); parameters.Add(Value.FromInteger(reader.ReadByte())); break; case InstructionType.EA_PushConstantWord: instruction = new PushConstantWord(); parameters.Add(Value.FromConstant(reader.ReadUInt16())); break; case InstructionType.EA_CallFuncPop: instruction = new CallFunctionPop(); break; case InstructionType.StrictEqual: instruction = new StrictEquals(); break; default: throw new InvalidDataException("Unimplemented bytecode instruction:" + type.ToString()); } if (instruction != null) { instruction.Parameters = parameters; instructions.Add(instructionPosition, instruction); } } } return(new InstructionCollection(instructions)); }
public void SetMemberCorrectlyConvertsToJson() { var setMember = new SetMember<string>(new List<string> { "basho", "google", "yahoo" }); setMember.ToString().ShouldEqual(SetMemberJson); }
void showClub(ClubDetailInfo club) { Transform me = transform.Find("me"); Transform bottom = transform.Find("bottom"); //setActive (transform, "top/btn_save", mAdmin); setActive(me, "btn_mail", mAdmin); if (mAdmin) { setBtnEvent(transform, "top/btn_edit", () => { SetClub sc = getPage <SetClub>("PSetClub"); sc.UpdateEvents += refresh; sc.enter(mClubID); }); setBtnEvent(me, "btn_mail", () => { ClubMessage cm = getPage <ClubMessage>("PClubMessage"); cm.enter(mClubID); }); } setText(me, "name", club.name); setText(me, "hc", club.member_num + " / " + club.max_member_num); setIcon(me, "icon", club.logo); Transform grid = transform.Find("items/grid_ign"); Transform creator = grid.GetChild(0); setBtnEvent(grid.GetChild(1), null, () => { if (mAdmin) { SetMember sm = getPage <SetMember>("PSetMember"); sm.enter(mClubID); } else { Rank rk = getPage <Rank>("PRank"); rk.enter(mClubID); } }); setText(grid.GetChild(2), "desc", club.desc); setActive(grid.GetChild(2), "btn_edit", mAdmin); setText(grid.GetChild(3), "id", "" + club.id); setText(creator, "name", club.owner.name); setIcon(creator, "icon", club.owner.logo); setBtnEvent(grid.GetChild(3), "btn_share", () => { GameObject root = GameObject.Find("UI Root"); GameObject share = root.transform.Find("PShare").gameObject; share.SetActive(true); //share.GetComponent<Share>().club_id = club.id; share.GetComponent <LuaBehaviour>().setIntValue("club_id", club.id); }); Transform auto = grid.GetChild(4); setToggleEvent(auto, "auto_start", null); setToggle(auto, "auto_start", club.auto_start); auto.GetComponentInChildren <Collider>().enabled = mAdmin; Debug.Log("enabled=" + mAdmin); if (mAdmin) { setToggleEvent(auto, "auto_start", val => { Debug.Log("audo_start changed, val=" + val); setAutoStart(val); }); } setText(bottom, "create_time", "创建于" + PUtils.formatTime(club.create_time)); setBtnEvent(bottom, "btn_exit", () => { onBtnExit(mClubID); }); grid.GetComponent <UIGrid> ().Reposition(); grid.GetComponentInParent <UIScrollView> ().ResetPosition(); }
public bool Equals(SetMember other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return other.NextState == NextState && Equals(other.Content, Content); }
private static void CopyMember(Type currentObjType, Type memberType, string memberName, object destObj, object destValue, object sourceValue, SetMember setMember) { if (destValue == sourceValue) { return; } // Logger.Log("SpeedrunTool", $"currentObjType={currentObjType}\tmemberType={memberType}\tmemberName={memberName}\tdestValue={destValue}\tsourceValue={sourceValue}\tdestObj={destObj}"); if (sourceValue == null) { // Component 需要从Entity中移除(适用于第六章 Boss 会在 Sprite 和 PlayerSprite 之间切换,使字段变为 null) if (destValue is Component component) { component.RemoveSelf(); } // null 也是有意义的 setMember(destObj, currentObjType, memberName, null); return; } if (memberType.IsSimple()) { // 简单类型直接复制 setMember(destObj, currentObjType, memberName, sourceValue); } else if (memberType.IsList(out Type genericType)) { bool destValueIsNull = destValue == null; destValue = CopyList(destValue, sourceValue, genericType); if (destValueIsNull) { setMember(destObj, currentObjType, memberName, destValue); } } else if (memberType.IsArray && memberType.GetElementType() is Type elementType) { // 一维数组且数量相同 if (destValue is Array destArray && destArray.Rank == 1 && sourceValue is Array sourceArray && destArray.Length == sourceArray.Length) { for (int i = 0; i < destArray.Length; i++) { if (elementType.IsSimple()) { destArray.SetValue(sourceArray.GetValue(i), i); } else { TryCopyObject(destArray.GetValue(i), sourceArray.GetValue(i)); } } } } else if (memberType.IsHashSet(out Type hashElementType)) { if (destValue == null) { destValue = Activator.CreateInstance(memberType); setMember(destObj, currentObjType, memberName, destValue); } if (hashElementType.IsSimple()) { // 列表里是简单数据,则清除后全部加入 destValue.InvokeMethod("Clear"); if (sourceValue is IEnumerable sourceEnumerable) { IEnumerator enumerator = sourceEnumerable.GetEnumerator(); while (enumerator.MoveNext()) { destValue.InvokeMethod("Add", enumerator.Current); } } } else if (hashElementType.IsSameOrSubclassOf(typeof(Entity))) { // Player.triggersInside Hashset<Trigger> destValue.InvokeMethod("Clear"); if (sourceValue is IEnumerable sourceEnumerable) { IEnumerator enumerator = sourceEnumerable.GetEnumerator(); while (enumerator.MoveNext() && enumerator.Current.TryFindOrCloneObject() is Entity entity) { destValue.InvokeMethod("Add", entity); } } } } else if (destValue is Stack <IEnumerator> destEnumerators && sourceValue is Stack <IEnumerator> sourceEnumerators) { // 用于恢复 Coroutine Stack <IEnumerator> temp = new Stack <IEnumerator>(); foreach (IEnumerator functionCall in sourceEnumerators) { if (TryFindOrCloneObject(functionCall) is IEnumerator destFunctionCall) { temp.Push(destFunctionCall); } } destEnumerators.Clear(); foreach (IEnumerator enumerator in temp) { destEnumerators.Push(enumerator); } } else { // 复杂类型 if (destValue != null) { // 不为空则复制里面的值 TryCopyObject(destValue, sourceValue); } else { // 为空则根据情况创建新实例或者查找当前场景的实例S destValue = TryFindOrCloneObject(sourceValue); if (destValue != null) { setMember(destObj, currentObjType, memberName, destValue); } else { Logger.Log("SpeedrunTool", $"TryFindOrCloneObject Faild: currentObjType={currentObjType}\tmemberType={memberType}\tmemberName={memberName}\tdestValue=null\tsourceValue={sourceValue}\tdestObj={destObj}"); } } } }
public FuncTransform(SetMember <T, TValue> setMember) { _setMember = setMember; }