private void CreateDetail(BinaryReader reader) { int id = reader.ReadInt32(); int parentID = reader.ReadInt32(); string model = reader.ReadString(); var pos = reader.ReadVector3(); var rot = reader.ReadQuaternion(); Shape shape = null; bool hasShape = reader.ReadBoolean(); if (hasShape == true) { var shapeSize = reader.ReadVector3(); shape = DetailHelper.CreateShape(shapeSize); } var parent = this.world.GetDetail(parentID); DetailObject obj = new DetailObject(parent, id, shape); obj.Position = pos; obj.Rotation = rot; obj.Model = model.Length > 0 ? model : null; this.world.RegisterDetail(obj); }
private DetailObject CreateDetailInstance( Dictionary <DetailTemplate, DetailObject> mapping, Dictionary <BehaviourTemplate, Behaviour> behaviours, DetailTemplate template, DetailObject parent) { Vector3 pos = Vector3.Zero; if (template.Position != null) { pos = template.GetPosition(); } Shape shape = null; if (template.Shape != null) { shape = DetailHelper.CreateShape(template.Shape.GetSize()); } DetailObject root = this.CreateDetail(template.Model, pos, parent, shape); if (template.Rotation != null) { root.Rotation = template.GetRotation(); } if (template.Children != null) { foreach (var child in template.Children) { CreateDetailInstance(mapping, behaviours, child, root); } } mapping.Add(template, root); if (template.Behaviours != null) { foreach (var behav in template.Behaviours) { var type = Type.GetType(behav.Class); if (type.IsSubclassOf(typeof(Behaviour)) == false) { throw new InvalidOperationException("Invalid behaviour type: " + behav.Class); } Behaviour behaviour = root.CreateBehaviour(type, true); behaviours.Add(behav, behaviour); } } return(root); }