protected override YAMLMappingNode ExportYAMLRoot(IExportContainer container) { YAMLMappingNode node = base.ExportYAMLRoot(container); TransformLayout layout = container.Layout.Transform; node.Add(layout.LocalRotationName, LocalRotation.ExportYAML(container)); node.Add(layout.LocalPositionName, LocalPosition.ExportYAML(container)); node.Add(layout.LocalScaleName, LocalScale.ExportYAML(container)); node.Add(layout.ChildrenName, Children.ExportYAML(container)); node.Add(layout.FatherName, Father.ExportYAML(container)); node.Add(layout.RootOrderName, RootOrder); node.Add(layout.LocalEulerAnglesHintName, LocalEulerAnglesHint.ExportYAML(container)); return(node); }
IEnumerator EvaluateBatch(int batchIndex, Phenotype[] batch, Orientations orientation) { IList <EvaluationBehaviour> evaluations = new List <EvaluationBehaviour>(); var layout = new TransformLayout(28.0f, 18.0f, batchSize, Mathf.FloorToInt(Mathf.Sqrt(batchSize))) .GetEnumerator(); foreach (var phenotype in batch) { layout.MoveNext(); var t = PoolManager.Pools["Evaluations"].Spawn(prefab, layout.Current, Quaternion.identity, transform); var controllerBehaviour = t.GetComponent <ControllerBehaviour>(); controllerBehaviour.Network = NetworkPorts.FromGenotype(phenotype.Genotype); var evaluationBehaviour = t.GetComponent <EvaluationBehaviour>(); evaluationBehaviour.Phenotype = phenotype; evaluationBehaviour.BeginTrial(orientation, Time.time); evaluations.Add(evaluationBehaviour); } // Wait for evaluations to complete while (evaluations.Any(ev => !ev.IsComplete)) { if (BestEvaluation != null) { var ordered = evaluations.OrderByDescending(ev => ev.CurrentTrial.Fitness); var best = ordered.First(); BestEvaluation(best); } yield return(new WaitForFixedUpdate()); } // Cleanup List <Transform> children = new List <Transform>(transform.childCount); foreach (Transform child in transform) { if (child.gameObject.activeInHierarchy) { children.Add(child); } } foreach (Transform child in children) { PoolManager.Pools["Evaluations"].Despawn(child, null); } }
public override IEnumerable <PPtr <Object> > FetchDependencies(DependencyContext context) { foreach (PPtr <Object> asset in base.FetchDependencies(context)) { yield return(asset); } TransformLayout layout = context.Layout.Transform; foreach (PPtr <Object> asset in context.FetchDependencies(Children, layout.ChildrenName)) { yield return(asset); } yield return(context.FetchDependency(Father, layout.FatherName)); }
IEnumerator EvaluateBatch(int batchIndex, Phenotype[] batch, Orientations orientation) { IList<EvaluationBehaviour> evaluations = new List<EvaluationBehaviour>(); var layout = new TransformLayout(28.0f, 18.0f, batchSize, Mathf.FloorToInt(Mathf.Sqrt(batchSize))) .GetEnumerator(); foreach (var phenotype in batch) { layout.MoveNext(); var t = PoolManager.Pools["Evaluations"].Spawn(prefab, layout.Current, Quaternion.identity, transform); var controllerBehaviour = t.GetComponent<ControllerBehaviour>(); controllerBehaviour.Network = NetworkPorts.FromGenotype(phenotype.Genotype); var evaluationBehaviour = t.GetComponent<EvaluationBehaviour>(); evaluationBehaviour.Phenotype = phenotype; evaluationBehaviour.BeginTrial(orientation, Time.time); evaluations.Add(evaluationBehaviour); } // Wait for evaluations to complete while (evaluations.Any(ev => !ev.IsComplete)) { if (BestEvaluation != null) { var ordered = evaluations.OrderByDescending(ev => ev.CurrentTrial.Fitness); var best = ordered.First(); BestEvaluation(best); } yield return new WaitForFixedUpdate(); } // Cleanup List<Transform> children = new List<Transform>(transform.childCount); foreach (Transform child in transform) { if (child.gameObject.activeInHierarchy) { children.Add(child); } } foreach (Transform child in children) { PoolManager.Pools["Evaluations"].Despawn(child, null); } }
public static void Convert(IExportContainer container, Transform origin, Transform instance) { ComponentConverter.Convert(container, origin, instance); instance.LocalRotation = origin.LocalRotation; instance.LocalPosition = origin.LocalPosition; instance.LocalScale = origin.LocalScale; instance.Children = origin.Children.ToArray(); instance.Father = origin.Father; #if UNIVERSAL TransformLayout exlayout = container.ExportLayout.Transform; if (exlayout.HasRootOrder) { instance.RootOrder = GetRootOrder(container, origin); } if (exlayout.HasLocalEulerAnglesHint) { instance.LocalEulerAnglesHint = GetLocalEulerAnglesHint(container, origin); } #endif }
public override void Write(AssetWriter writer) { base.Write(writer); LocalRotation.Write(writer); LocalPosition.Write(writer); LocalScale.Write(writer); Children.Write(writer); Father.Write(writer); #if UNIVERSAL TransformLayout layout = writer.Layout.Transform; if (layout.HasRootOrder) { writer.Write(RootOrder); } if (layout.HasLocalEulerAnglesHint) { LocalEulerAnglesHint.Write(writer); } #endif }
public override void Read(AssetReader reader) { base.Read(reader); LocalRotation.Read(reader); LocalPosition.Read(reader); LocalScale.Read(reader); Children = reader.ReadAssetArray <PPtr <Transform> >(); Father.Read(reader); #if UNIVERSAL TransformLayout layout = reader.Layout.Transform; if (layout.HasRootOrder) { RootOrder = reader.ReadInt32(); } if (layout.HasLocalEulerAnglesHint) { LocalEulerAnglesHint.Read(reader); } #endif }