static GhostAuthoringComponentEditor() { GhostComponentDefaults = new Dictionary <string, GhostAuthoringComponent.GhostComponent>(); var comp = new GhostAuthoringComponent.GhostComponent { name = "Translation", server = true, interpolatedClient = true, predictedClient = true, isManual = false, fields = new GhostAuthoringComponent.GhostComponentField[1] }; comp.fields[0] = new GhostAuthoringComponent.GhostComponentField { name = "Value", interpolate = true, quantization = 10 }; GhostComponentDefaults.Add(comp.name, comp); comp = new GhostAuthoringComponent.GhostComponent { name = "Rotation", server = true, interpolatedClient = true, predictedClient = true, isManual = false, fields = new GhostAuthoringComponent.GhostComponentField[1] }; comp.fields[0] = new GhostAuthoringComponent.GhostComponentField { name = "Value", interpolate = true, quantization = 1000 }; GhostComponentDefaults.Add(comp.name, comp); comp = new GhostAuthoringComponent.GhostComponent { name = "CurrentSimulatedPosition", server = false, interpolatedClient = true, predictedClient = true, isManual = false, fields = new GhostAuthoringComponent.GhostComponentField[0] }; GhostComponentDefaults.Add(comp.name, comp); comp = new GhostAuthoringComponent.GhostComponent { name = "CurrentSimulatedRotation", server = false, interpolatedClient = true, predictedClient = true, isManual = false, fields = new GhostAuthoringComponent.GhostComponentField[0] }; GhostComponentDefaults.Add(comp.name, comp); }
static string GetShortName(GhostAuthoringComponent.GhostComponent comp) { var shortName = comp.ShortName.Replace("+", ""); if (comp.entityIndex != 0) { shortName = "Child" + (comp.entityIndex - 1) + shortName; } return(shortName); }
static GhostAuthoringComponentEditor() { GhostDefaultOverrides = new Dictionary <string, GhostAuthoringComponent.GhostComponent>(); var comp = new GhostAuthoringComponent.GhostComponent { name = "Unity.NetCode.CurrentSimulatedPosition", server = false, interpolatedClient = true, predictedClient = true, sendDataTo = GhostAuthoringComponent.ClientSendType.All, manualFieldList = false, fields = new GhostAuthoringComponent.GhostComponentField[0] }; GhostDefaultOverrides.Add(comp.name, comp); comp = new GhostAuthoringComponent.GhostComponent { name = "Unity.NetCode.CurrentSimulatedRotation", server = false, interpolatedClient = true, predictedClient = true, sendDataTo = GhostAuthoringComponent.ClientSendType.All, manualFieldList = false, fields = new GhostAuthoringComponent.GhostComponentField[0] }; GhostDefaultOverrides.Add(comp.name, comp); comp = new GhostAuthoringComponent.GhostComponent { name = "Unity.Transforms.Translation", interpolatedClient = true, predictedClient = true, server = true, fields = new GhostAuthoringComponent.GhostComponentField[] { new GhostAuthoringComponent.GhostComponentField { name = "Value", quantization = 100, interpolate = true } }, manualFieldList = false, entityIndex = 0 }; GhostDefaultOverrides.Add(comp.name, comp); comp = new GhostAuthoringComponent.GhostComponent { name = "Unity.Transforms.Rotation", interpolatedClient = true, predictedClient = true, server = true, fields = new GhostAuthoringComponent.GhostComponentField[] { new GhostAuthoringComponent.GhostComponentField { name = "Value", quantization = 1000, interpolate = true } }, manualFieldList = false, entityIndex = 0 }; GhostDefaultOverrides.Add(comp.name, comp); }
static void AddToComponentList(GhostAuthoringComponent self, List <GhostAuthoringComponent.GhostComponent> newComponents, Dictionary <string, int> toDelete, World tempWorld, Entity convertedEntity, int entityIndex) { var typeProviders = new List <GhostSnapshotValue>(); typeProviders.AddRange(GhostSnapshotValue.GameSpecificTypes); typeProviders.AddRange(GhostSnapshotValue.DefaultTypes); var compTypes = tempWorld.EntityManager.GetComponentTypes(convertedEntity); compTypes.Sort(default(ComponentNameComparer)); for (int i = 0; i < compTypes.Length; ++i) { var managedType = compTypes[i].GetManagedType(); if (managedType == typeof(Prefab) || managedType == typeof(LinkedEntityGroup)) { continue; } GhostAuthoringComponent.GhostComponent newComponent; if (GhostDefaultOverrides.TryGetValue(managedType.FullName, out newComponent)) { newComponent.fields = (GhostAuthoringComponent.GhostComponentField[])newComponent.fields.Clone(); } else { var fields = new List <GhostAuthoringComponent.GhostComponentField>(); foreach (var componentField in managedType.GetFields()) { var attr = componentField.GetCustomAttributes <GhostDefaultFieldAttribute>().ToArray(); if (attr.Length > 0) { bool valid = true; foreach (var valueType in typeProviders) { if (valueType.CanProcess(componentField, managedType.FullName, componentField.Name)) { if (attr[0].Quantization < 0 && valueType.SupportsQuantization) { Debug.LogError(String.Format( "{0}.{1} is of type {2} which requires quantization factor to be specified - ignoring field", managedType.FullName, componentField.Name, componentField.FieldType)); valid = false; } if (attr[0].Quantization > 1 && !valueType.SupportsQuantization) { Debug.LogError(String.Format( "{0}.{1} is of type {2} which does not support quantization - ignoring field", managedType.FullName, componentField.Name, componentField.FieldType)); valid = false; } break; } } if (valid) { // If type requires quantization not specifying quantization is an error (log + ignore field) fields.Add(new GhostAuthoringComponent.GhostComponentField { name = componentField.Name, quantization = attr[0].Quantization, interpolate = attr[0].Interpolate }); } } } newComponent = new GhostAuthoringComponent.GhostComponent { name = managedType.FullName, interpolatedClient = true, predictedClient = true, server = true, fields = fields.ToArray(), manualFieldList = false }; var compAttr = managedType.GetCustomAttributes <GhostDefaultComponentAttribute>().ToArray(); if (compAttr.Length > 0) { newComponent.server = (compAttr[0].TargetType & GhostDefaultComponentAttribute.Type.Server) != 0; newComponent.interpolatedClient = (compAttr[0].TargetType & GhostDefaultComponentAttribute.Type.InterpolatedClient) != 0; newComponent.predictedClient = (compAttr[0].TargetType & GhostDefaultComponentAttribute.Type.PredictedClient) != 0; } } if (toDelete.TryGetValue(entityIndex + managedType.FullName, out var compIdx)) { var fields = newComponent.fields; newComponent = self.Components[compIdx]; if (!self.Components[compIdx].manualFieldList) { newComponent.fields = fields; } toDelete.Remove(entityIndex + managedType.FullName); } if (entityIndex > 0) { // Stripping components on child entities is not supported newComponent.server = true; newComponent.interpolatedClient = true; newComponent.predictedClient = true; } newComponent.entityIndex = entityIndex; newComponents.Add(newComponent); } }