/// <summary> /// /// </summary> /// <param name="uiRoot"></param> /// <returns></returns> public static DataBuffer GetPrefab(Transform uiRoot) { var ui = uiRoot.GetComponent <Helper.HGUI.UIContext>(); if (ui != null) { DataBuffer db = new DataBuffer(1024); string tn = ui.GetType().Name; var loader = GameBuffer.FindDataLoader(tn); var root = loader.SaveUI(ui, db); FakeStruct fake = new FakeStruct(db, 3); fake[0] = db.AddData(root); var list = AddDataTable(db); int c = list.Count; Int16[] arr = new Int16[c]; for (int i = 0; i < arr.Length; i++) { arr[i] = (Int16)db.AddData(list[i]); } fake[1] = db.AddData(arr); fake[2] = db.AddData(Version); db.fakeStruct = fake; return(db); } return(null); }
public static unsafe FakeStruct LoadFromObject(Component com, DataBuffer buffer) { var img = com as Image; if (img == null) { return(null); } FakeStruct fake = new FakeStruct(buffer, ImageData.ElementSize); ImageData *data = (ImageData *)fake.ip; data->alphaHit = img.alphaHitTestMinimumThreshold; data->fillAmount = img.fillAmount; data->fillCenter = img.fillCenter; data->fillClockwise = img.fillClockwise; data->fillMethod = img.fillMethod; data->fillOrigin = img.fillOrigin; data->preserveAspect = img.preserveAspect; data->type = img.type; data->color = img.color; if (img.sprite != null) { var tn = img.sprite.texture.name; var sn = img.sprite.name; var an = ElementAsset.TxtureFormAsset(img.sprite.texture.name); data->assetName = buffer.AddData(an); data->textureName = buffer.AddData(tn); data->spriteName = buffer.AddData(sn); } if (img.material != null) { data->shader = buffer.AddData(img.material.shader.name); } return(fake); }
public override unsafe FakeStruct LoadFromObject(Component com, DataBuffer buffer) { var sr = com as SpriteMask; if (sr == null) { return(null); } FakeStruct fake = new FakeStruct(buffer, SpriteMaskData.ElementSize); SpriteMaskData *data = (SpriteMaskData *)fake.ip; data->alphaCutoff = sr.alphaCutoff; data->isCustomRangeActive = sr.isCustomRangeActive; data->frontSortingLayerID = sr.frontSortingLayerID; data->frontSortingOrder = sr.frontSortingOrder; data->backSortingLayerID = sr.backSortingLayerID; data->backSortingOrder = sr.backSortingOrder; data->spriteSortPoint = sr.spriteSortPoint; if (sr.sprite != null) { var tn = sr.sprite.texture.name; var sn = sr.sprite.name; var an = ElementAsset.TxtureFormAsset(sr.sprite.texture.name); data->assetName = buffer.AddData(an); data->textureName = buffer.AddData(tn); data->spriteName = buffer.AddData(sn); } return(fake); }
public static unsafe FakeStruct LoadFromObject(Component com, DataBuffer buffer) { var img = com as RawImage; if (img == null) { return(null); } FakeStruct fake = new FakeStruct(buffer, RawImageData.ElementSize); RawImageData *data = (RawImageData *)fake.ip; data->uvRect = img.uvRect; data->color = img.color; if (img.texture != null) { var tn = img.texture.name; var an = ElementAsset.TxtureFormAsset(img.texture.name); data->assetName = buffer.AddData(an); data->textureName = buffer.AddData(tn); } if (img.material != null) { data->shader = buffer.AddData(img.material.shader.name); } return(fake); }
public static unsafe FakeStruct LoadFromObject(Component com, DataBuffer buffer) { var txt = com as Text; if (txt == null) { return(null); } FakeStruct fake = new FakeStruct(buffer, TextData.ElementSize); TextData * data = (TextData *)fake.ip; data->alignByGeometry = txt.alignByGeometry; data->alignment = txt.alignment; data->fontSize = txt.fontSize; data->fontStyle = txt.fontStyle; data->horizontalOverflow = txt.horizontalOverflow; data->lineSpacing = txt.lineSpacing; data->resizeTextForBestFit = txt.resizeTextForBestFit; data->resizeTextMaxSize = txt.resizeTextMaxSize; data->resizeTextMinSize = txt.resizeTextMinSize; data->supportRichText = txt.supportRichText; data->verticalOverflow = txt.verticalOverflow; data->color = txt.color; data->text = buffer.AddData(txt.text); if (txt.font != null) { data->font = buffer.AddData(txt.font.name); } if (txt.material != null) { data->shader = buffer.AddData(txt.material.shader.name); } return(fake); }
public unsafe override void ToBufferData(DataBuffer db, huqiang.Core.UIData.UIElementData *data) { FakeStruct fs = new FakeStruct(db, 3); fs[0] = (int)EventColliderType.Circle; fs.SetFloat(1, Radius); fs.SetFloat(2, Ratio); int type = db.AddData("CircleEventHelper"); int index = db.AddData(fs); data->eve = type << 16 | index; }
public unsafe override object ToBufferData(DataBuffer data) { FakeStruct fake = new FakeStruct(data, TextInputData.ElementSize); TextInputData *sp = (TextInputData *)fake.ip; sp->inputColor = inputColor; sp->tipColor = tipColor; sp->pointColor = pointColor; sp->selectColor = selectColor; sp->inputString = data.AddData(InputString); sp->tipString = data.AddData(TipString); return(fake); }
public static unsafe FakeStruct LoadFromObject(Component com, DataBuffer buffer) { var sr = com as SpriteRenderer; if (sr == null) { return(null); } FakeStruct fake = new FakeStruct(buffer, SpriteRenderData.ElementSize); SpriteRenderData *data = (SpriteRenderData *)fake.ip; data->renderingLayerMask = sr.renderingLayerMask; data->rendererPriority = sr.rendererPriority; data->sortingLayerID = sr.sortingLayerID; data->sortingOrder = sr.sortingOrder; data->allowOcclusionWhenDynamic = sr.allowOcclusionWhenDynamic; data->lightmapIndex = sr.lightmapIndex; data->realtimeLightmapIndex = sr.realtimeLightmapIndex; data->lightmapScaleOffset = sr.lightmapScaleOffset; data->realtimeLightmapScaleOffset = sr.realtimeLightmapScaleOffset; data->reflectionProbeUsage = sr.reflectionProbeUsage; data->lightProbeUsage = sr.lightProbeUsage; data->receiveShadows = sr.receiveShadows; data->motionVectorGenerationMode = sr.motionVectorGenerationMode; data->enabled = sr.enabled; data->shadowCastingMode = sr.shadowCastingMode; data->drawMode = sr.drawMode; data->size = sr.size; data->adaptiveModeThreshold = sr.adaptiveModeThreshold; data->tileMode = sr.tileMode; data->color = sr.color; data->maskInteraction = sr.maskInteraction; data->flipX = sr.flipX; data->flipY = sr.flipY; data->spriteSortPoint = sr.spriteSortPoint; data->sortingLayerName = buffer.AddData(sr.sortingLayerName); if (sr.sprite != null) { var tn = sr.sprite.texture.name; var sn = sr.sprite.name; var an = ElementAsset.TxtureFormAsset(sr.sprite.texture.name); data->assetName = buffer.AddData(an); data->textureName = buffer.AddData(tn); data->spriteName = buffer.AddData(sn); } if (sr.material != null) { data->shaderName = buffer.AddData(sr.material.shader.name); } return(fake); }
public unsafe override void ToBufferData(DataBuffer db, huqiang.Core.UIData.UIElementData *data) { FakeStruct fake = new FakeStruct(db, 5); fake[0] = (int)direction; fake.SetFloat(1, spacing); fake[2] = FixedSize?1:0; fake.SetFloat(3, FixedSizeRatio); fake.SetFloat(4, ItemOffset); int type = db.AddData("StackPanelHelper"); int index = db.AddData(fake); data->composite = type << 16 | index; }
public static unsafe byte[] Save(Transform root) { DataBuffer db = new DataBuffer(1024); FakeStruct fake = new FakeStruct(db, LocalCoordinates.ElementSize); LocalCoordinates *lc = (LocalCoordinates *)fake.ip; lc->Postion = root.localPosition; lc->Rotate = root.localRotation; lc->Scale = root.localScale; lc->Name = db.AddData(root.name); lc->Child = db.AddData(SaveChild(root, db)); db.fakeStruct = fake; return(db.ToBytes()); }
public unsafe override void ToBufferData(DataBuffer db, huqiang.Core.UIData.UIElementData *data) { FakeStruct fake = new FakeStruct(db, SliderInfo.ElementSize); SliderInfo *si = (SliderInfo *)fake.ip; si->StartOffset = StartOffset; si->EndOffset = EndOffset; si->MinScale = MinScale; si->MaxScale = MaxScale; si->direction = direction; int type = db.AddData("SliderHelper"); int index = db.AddData(fake); data->composite = type << 16 | index; }
/// <summary> /// calcualte the discounted advantages for the current sequence of data, and add them to the databuffer /// </summary> protected void ProcessEpisodeHistory(float nextValue, int actorNum) { var advantages = RLUtils.GeneralAdvantageEst(rewardsEpisodeHistory[actorNum].ToArray(), valuesEpisodeHistory[actorNum].ToArray(), RewardDiscountFactor, RewardGAEFactor, nextValue); float[] targetValues = new float[advantages.Length]; for (int i = 0; i < targetValues.Length; ++i) { targetValues[i] = advantages[i] + valuesEpisodeHistory[actorNum][i]; //test //advantages[i] = 1; } //test //targetValues = RLUtils.DiscountedRewards(rewardsEpisodeHistory.ToArray(), RewardDiscountFactor); dataBuffer.AddData(Tuple.Create <string, Array>("State", statesEpisodeHistory[actorNum].ToArray()), Tuple.Create <string, Array>("Action", actionsEpisodeHistory[actorNum].ToArray()), Tuple.Create <string, Array>("ActionProb", actionprobsEpisodeHistory[actorNum].ToArray()), Tuple.Create <string, Array>("TargetValue", targetValues), Tuple.Create <string, Array>("Advantage", advantages) ); statesEpisodeHistory[actorNum].Clear(); rewardsEpisodeHistory[actorNum].Clear(); actionsEpisodeHistory[actorNum].Clear(); actionprobsEpisodeHistory[actorNum].Clear(); valuesEpisodeHistory[actorNum].Clear(); }
public void AddData(Array inputConditions, Array inputTargets) { if (dataBuffer == null) { //create databuffer if not exist yet List <DataBuffer.DataInfo> dataInfos = new List <DataBuffer.DataInfo>(); if (ganReference.HasConditionInput) { dataInfos.Add(new DataBuffer.DataInfo("Condition", typeof(float), ganReference.inputConditionShape)); } dataInfos.Add(new DataBuffer.DataInfo("Target", typeof(float), ganReference.outputShape)); dataBuffer = new DataBuffer(maxDataBufferCount, dataInfos.ToArray()); } //I am not checking the data size here because the dataBuffer.AddData will check it for me....tooo lazy List <ValueTuple <string, Array> > data = new List <ValueTuple <string, Array> >(); if (ganReference.HasConditionInput) { data.Add(new ValueTuple <string, Array>("Condition", inputConditions)); } data.Add(new ValueTuple <string, Array>("Target", inputTargets)); dataBuffer.AddData(data.ToArray()); }
public override void AddExperience(Dictionary <Agent, AgentInfo> currentInfo, Dictionary <Agent, AgentInfo> newInfo, Dictionary <Agent, TakeActionOutput> actionOutput) { var agentList = currentInfo.Keys; foreach (var agent in agentList) { var agentDecision = agent.GetComponent <AgentDependentDecision>(); //only add the data to databuffer if this agent uses decision if (agentDecision != null && agentDecision.useDecision && isCollectingData) { var agentNewInfo = newInfo[agent]; List <ValueTuple <string, Array> > dataToAdd = new List <ValueTuple <string, Array> >(); dataToAdd.Add(ValueTuple.Create <string, Array>("Action", actionOutput[agent].outputAction)); if (currentInfo[agent].stackedVectorObservation.Count > 0) { dataToAdd.Add(ValueTuple.Create <string, Array>("VectorObservation", currentInfo[agent].stackedVectorObservation.ToArray())); } for (int i = 0; i < BrainToTrain.brainParameters.cameraResolutions.Length; ++i) { var res = BrainToTrain.brainParameters.cameraResolutions[i]; Array arrayToAdd = TextureToArray(currentInfo[agent].visualObservations[i], res.blackAndWhite).ExpandDimensions(0); dataToAdd.Add(ValueTuple.Create <string, Array>("VisualObservation" + i, arrayToAdd)); } dataBuffer.AddData(dataToAdd.ToArray()); } } }
private DataBuffer SendStringData(string method, string path, Headers headers, string json, string contentType) { HttpWebRequest httpWReq = CreateWebRequest(method, path, headers, contentType, json.Length); if (httpWReq.Method.ToUpper() != "GET") { using (Stream stream = httpWReq.GetRequestStream()) { var dataBuffer = new DataBuffer(json); stream.Write(dataBuffer.GetBuffer(), 0, (int)dataBuffer.GetBufferSize()); } } HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse(); StatusCode = response.StatusCode; StatusDescription = response.StatusDescription; if (StatusCode == HttpStatusCode.OK) { var stream = response.GetResponseStream(); var binStream = new BinaryReader(stream); var dataBuffer = new DataBuffer(); string jsonRes = String.Empty; dataBuffer.AddData(binStream); return(dataBuffer); } return(null); }
public static unsafe FakeStruct LoadFromObject(Component com, DataBuffer buffer) { var ae = com as BoxCollider2D; if (ae == null) { return(null); } FakeStruct fake = new FakeStruct(buffer, BoxColliderData.ElementSize); BoxColliderData *data = (BoxColliderData *)fake.ip; if (ae.sharedMaterial != null) { data->sharedMaterial = buffer.AddData(ae.sharedMaterial.name); } data->offset = ae.offset; data->usedByComposite = ae.usedByComposite; data->usedByEffector = ae.usedByEffector; data->isTrigger = ae.isTrigger; data->density = ae.density; data->size = ae.size; data->edgeRadius = ae.edgeRadius; data->autoTiling = ae.autoTiling; return(fake); }
public static unsafe FakeStruct LoadFromObject(Component com, DataBuffer buffer) { var obj = com as PolygonCollider2D; if (obj == null) { return(null); } FakeStruct fake = new FakeStruct(buffer, PolygonColliderData.ElementSize); PolygonColliderData *ec = (PolygonColliderData *)fake.ip; if (obj.sharedMaterial != null) { ec->sharedMaterial = buffer.AddData(obj.sharedMaterial.name); } ec->offset = obj.offset; ec->usedByEffector = obj.usedByEffector; ec->isTrigger = obj.isTrigger; ec->density = obj.density; ec->autoTiling = obj.autoTiling; ec->pathCount = obj.pathCount; if (obj.points != null) { ec->points = buffer.AddArray <Vector2>(obj.points); } return(fake); }
static unsafe FakeStructArray SaveSprites(DataBuffer buffer, List <Sprite> sprites) { FakeStructArray array = new FakeStructArray(buffer, SpriteDataS.ElementSize, sprites.Count); float tx = sprites[0].texture.width; float ty = sprites[0].texture.height; for (int i = 0; i < sprites.Count; i++) { var sprite = sprites[i]; string name = sprite.name; SpriteDataS *sp = (SpriteDataS *)array[i]; sp->name = buffer.AddData(name); var sr = sp->rect = sprite.rect; sp->pivot = sprite.pivot; float w = sprite.texture.width; float h = sprite.texture.height; float x = sr.x; float rx = sr.width + x; float y = sr.y; ty = sr.height + y; x /= w; rx /= w; y /= h; ty /= h; sp->uv0.x = x; sp->uv0.y = y; sp->uv1.x = x; sp->uv1.y = ty; sp->uv2.x = rx; sp->uv2.y = ty; sp->uv3.x = rx; sp->uv3.y = y; } return(array); }
public static unsafe FakeStruct LoadFromObject(Component com, DataBuffer buffer) { var ae = com.GetComponent <CompositeCollider2D>(); if (ae == null) { return(null); } FakeStruct fake = new FakeStruct(buffer, CompositeColliderData.ElementSize); CompositeColliderData *data = (CompositeColliderData *)fake.ip; if (ae.sharedMaterial != null) { data->sharedMaterial = buffer.AddData(ae.sharedMaterial.name); } data->offset = ae.offset; data->usedByComposite = ae.usedByComposite; data->usedByEffector = ae.usedByEffector; data->isTrigger = ae.isTrigger; data->density = ae.density; data->geometryType = ae.geometryType; data->generationType = ae.generationType; data->vertexDistance = ae.vertexDistance; return(fake); }
public override unsafe FakeStruct LoadFromObject(Component com, DataBuffer buffer) { var obj = com as EdgeCollider2D; if (obj == null) { return(null); } FakeStruct fake = new FakeStruct(buffer, EdgeColliderData.ElementSize); EdgeColliderData *ec = (EdgeColliderData *)fake.ip; if (obj.sharedMaterial != null) { ec->sharedMaterial = buffer.AddData(obj.sharedMaterial.name); } ec->offset = obj.offset; ec->usedByEffector = obj.usedByEffector; ec->isTrigger = obj.isTrigger; ec->density = obj.density; ec->edgeRadius = obj.edgeRadius; if (obj.points != null) { ec->points = buffer.AddArray <Vector2>(obj.points); } return(fake); }
public unsafe override object ToBufferData(DataBuffer data) { FakeStruct fake = new FakeStruct(data, TextInputData.ElementSize); TextInputData *sp = (TextInputData *)fake.ip; sp->inputColor = inputColor; sp->tipColor = tipColor; sp->pointColor = pointColor; sp->selectColor = selectColor; sp->inputString = data.AddData(InputString); sp->tipString = data.AddData(TipString); sp->CharacterLimit = CharacterLimit; sp->ReadyOnly = ReadyOnly; sp->contentType = contentType; sp->lineType = lineType; return(fake); }
public unsafe override void ToBufferData(DataBuffer db, UITransfromData *data) { FakeStruct fake = new FakeStruct(db, TextInputData.ElementSize); TextInputData *sp = (TextInputData *)fake.ip; sp->inputColor = inputColor; sp->tipColor = tipColor; sp->pointColor = pointColor; sp->selectColor = selectColor; sp->inputString = db.AddData(InputString); sp->tipString = db.AddData(TipString); sp->CharacterLimit = CharacterLimit; sp->ReadyOnly = ReadyOnly; sp->contentType = contentType; sp->lineType = lineType; data->eve = db.AddData(fake); }
public DataBuffer AddToDataBuffer(BrainParameters brainParameter) { List <DataBuffer.DataInfo> allBufferData = new List <DataBuffer.DataInfo>() { new DataBuffer.DataInfo("Action", typeof(float), new int[] { brainParameter.vectorActionSpaceType == SpaceType.continuous ? brainParameter.vectorActionSize[0] : brainParameter.vectorActionSize.Length }) }; if (brainParameter.vectorObservationSize > 0) { allBufferData.Add(new DataBuffer.DataInfo("VectorObservation", typeof(float), new int[] { brainParameter.vectorObservationSize *brainParameter.numStackedVectorObservations })); } for (int i = 0; i < brainParameter.cameraResolutions.Length; ++i) { int width = brainParameter.cameraResolutions[i].width; int height = brainParameter.cameraResolutions[i].height; int channels; if (brainParameter.cameraResolutions[i].blackAndWhite) { channels = 1; } else { channels = 3; } allBufferData.Add(new DataBuffer.DataInfo("VisualObservation" + i, typeof(float), new int[] { height, width, channels })); } allBufferData.Add(new DataBuffer.DataInfo("Reward", typeof(float), new int[] { 1 })); var dataBuffer = new DataBuffer(allBufferData.ToArray()); foreach (EpisodeData episode in episodesHistory) { if (episode.rewardsHistory.Count > 0) { List <ValueTuple <string, Array> > dataToAdd = new List <ValueTuple <string, Array> >(); dataToAdd.Add(ValueTuple.Create <string, Array>("Action", episode.actionsHistory.ToArray())); dataToAdd.Add(ValueTuple.Create <string, Array>("Reward", episode.rewardsHistory.ToArray())); if (episode.vectorObsHistory != null) { dataToAdd.Add(ValueTuple.Create <string, Array>("VectorObservation", episode.vectorObsHistory.ToArray())); } for (int j = 0; j < episode.visualHistory.Count; ++j) { dataToAdd.Add(ValueTuple.Create <string, Array>("VisualObservation" + j, DataBuffer.ListToArray(episode.visualHistory[j]))); } for (int j = 0; j < episode.actionMasksHistory.Count; ++j) { dataToAdd.Add(ValueTuple.Create <string, Array>("ActionMask" + j, episode.actionMasksHistory[j].ToArray())); } dataBuffer.AddData(dataToAdd.ToArray()); } } return(dataBuffer); }
public unsafe override void ToBufferData(DataBuffer db, UITransfromData *data) { FakeStruct fs = new FakeStruct(db, 3); fs[0] = (int)EventColliderType.Circle; fs.SetFloat(1, Radius); fs.SetFloat(2, Ratio); data->eve = db.AddData(fs); }
public unsafe override void ToBufferData(DataBuffer db, huqiang.Core.UIData.UIElementData *data) { if (Points != null) { FakeStruct fs = new FakeStruct(db, 2); fs[0] = (int)EventColliderType.Polygon; if (Points != null) { if (Points.Length > 2) { fs[1] = db.AddArray <Vector2>(Points); } } int type = db.AddData("PolygonEventHelper"); int index = db.AddData(fs); data->eve = type << 16 | index; } }
public unsafe override void ToBufferData(DataBuffer db, UITransfromData *data) { if (Points != null) { FakeStruct fs = new FakeStruct(db, 2); fs[0] = (int)EventColliderType.Polygon; fs[1] = db.AddArray <Vector2>(Points); data->eve = db.AddData(fs); } }
public unsafe override void ToBufferData(DataBuffer db, UITransfromData *data) { FakeStruct fake = new FakeStruct(db, 5); fake[0] = (int)direction; fake.SetFloat(1, spacing); fake[2] = FixedSize?1:0; fake.SetFloat(3, FixedSizeRatio); fake.SetFloat(4, ItemOffset); data->composite = db.AddData(fake); }
public void SendStream(int cmd, int type, byte[] dat) { DataBuffer db = new DataBuffer(4); var fake = new FakeStruct(db, Req.Length); fake[Req.Cmd] = cmd; fake[Req.Type] = type; fake[Req.Args] = db.AddData(dat); db.fakeStruct = fake; link.Send(db.ToBytes(), EnvelopeType.DataBuffer); }
public unsafe override void ToBufferData(DataBuffer db, UITransfromData *data) { FakeStruct fake = new FakeStruct(db, SliderInfo.ElementSize); SliderInfo *si = (SliderInfo *)fake.ip; si->StartOffset = StartOffset; si->EndOffset = EndOffset; si->MinScale = MinScale; si->MaxScale = MaxScale; si->direction = direction; data->composite = db.AddData(fake); }
public unsafe override void ToBufferData(DataBuffer db, huqiang.Core.UIData.UIElementData *data) { FakeStruct fake = new FakeStruct(db, TextInputData.ElementSize); TextInputData *sp = (TextInputData *)fake.ip; sp->inputColor = inputColor; sp->tipColor = tipColor; sp->pointColor = pointColor; sp->selectColor = selectColor; sp->inputString = db.AddData(InputString); sp->tipString = db.AddData(TipString); sp->CharacterLimit = CharacterLimit; sp->ReadyOnly = ReadyOnly; sp->contentType = contentType; sp->lineType = lineType; data->eve = db.AddData(fake); int type = db.AddData("TextInputHelper"); int index = db.AddData(fake); data->eve = type << 16 | index; }