public Vector3 ReturnVector3Component(Enums.ComponentType componentType, int entityId) { Vector3 vc; if (componentType == Enums.ComponentType.Position) { if (positions.TryGetValue(entityId, out vc)) { return(vc); } } else if (componentType == Enums.ComponentType.Scale) { if (scales.TryGetValue(entityId, out vc)) { return(vc); } } else if (componentType == Enums.ComponentType.Direction) { if (directions.TryGetValue(entityId, out vc)) { return(vc); } } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } Debug.LogWarning(string.Format("Entity doesn't have component in the wanted component list, entity id : {0} component type: {1}", entityId, componentType)); return(Vector3.zero); }
#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). public bool TryGetValue(TKey key, out TValue?value) #pragma warning restore CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). { if (_dictionary != null) { if (!_dictionary.Contains(key)) { #pragma warning disable CS8653 // A default expression introduces a null value for a type parameter. value = default; #pragma warning restore CS8653 // A default expression introduces a null value for a type parameter. return(false); } else { value = (TValue)_dictionary[key]; return(true); } } #if HAVE_READ_ONLY_COLLECTIONS else if (_readOnlyDictionary != null) { throw new NotSupportedException(); } #endif else { return(GenericDictionary.TryGetValue(key, out value)); } }
public bool TryGetValue(TKey key, [MaybeNull] out TValue value) { if (_dictionary != null) { if (!_dictionary.Contains(key)) { #pragma warning disable CS8653 // A default expression introduces a null value for a type parameter. value = default; #pragma warning restore CS8653 // A default expression introduces a null value for a type parameter. return(false); } else { value = (TValue)_dictionary[key]; return(true); } } #if HAVE_READ_ONLY_COLLECTIONS else if (_readOnlyDictionary != null) { throw new NotSupportedException(); } #endif else { return(GenericDictionary.TryGetValue(key, out value)); } }
public static void Update(GenericDictionary <Components.Movement> movements, GenericDictionary <Vector3> directions, GenericDictionary <Quaternion> rotations, GenericDictionary <float> maxSpeeds) { foreach (KeyValuePair <int, Components.Movement> movement in movements) { float maxSpeed; Quaternion rotation; Vector3 direction; if (directions.TryGetValue(movement.Key, out direction)) { if (maxSpeeds.TryGetValue(movement.Key, out maxSpeed)) { if (rotations.TryGetValue(movement.Key, out rotation)) { movement.Value.velocity = rotation * direction * maxSpeed; } else { movement.Value.velocity = direction * maxSpeed; } } else { movement.Value.velocity = direction; } } else { movement.Value.velocity = Vector3.zero; } } }
//private static UnityAction listener; //public static void Start() { // listener = OnEvent; // EventManager.StartListening(Fudo.Enums.Event.Test, listener); //} //public static void OnEvent() { // Debug.Log("YYYIEEEAHAAA"); //} public static void Update(GenericDictionary <Vector3> positions, GenericDictionary <Components.Movement> movements) { foreach (KeyValuePair <int, Components.Movement> movementComponent in movements) { Vector3 newPos; if (positions.TryGetValue(movementComponent.Key, out newPos)) { positions[movementComponent.Key] = newPos + movementComponent.Value.velocity * Time.deltaTime; } } }
public static void Update(GenericDictionary <Components.Controllable> controllables, GenericDictionary <Vector3> directions) { foreach (KeyValuePair <int, Components.Controllable> controllable in controllables) { Vector3 direction; if (directions.TryGetValue(controllable.Key, out direction)) { direction = new Vector3(controllable.Value.inputAxis.x, 0, controllable.Value.inputAxis.y); directions[controllable.Key] = direction; } } }
public Quaternion ReturnQuaternionComponent(Enums.ComponentType componentType, int entityId) { Quaternion qt; if (componentType == Enums.ComponentType.Rotation) { if (rotations.TryGetValue(entityId, out qt)) { return(qt); } } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } Debug.LogWarning(string.Format("Entity doesn't have component in the wanted component list, entity id : {0} component type: {1}", entityId, componentType)); return(Quaternion.identity); }
public bool ReturnBooleanComponent(Enums.ComponentType componentType, int entityId) { bool bl; if (componentType == Enums.ComponentType.IsVisible) { if (isVisibles.TryGetValue(entityId, out bl)) { return(bl); } } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } Debug.LogWarning(string.Format("Entity doesn't have component in the wanted component list, entity id : {0} component type: {1}", entityId, componentType)); return(false); }
public float ReturnFloatComponent(Enums.ComponentType componentType, int entityId) { float fl; if (componentType == Enums.ComponentType.MaxSpeed) { if (maxSpeeds.TryGetValue(entityId, out fl)) { return(fl); } } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } Debug.LogWarning(string.Format("Entity doesn't have component in the wanted component list, entity id : {0} component type: {1}", entityId, componentType)); return(0); }
public Components.Movement ReturnMovementComponent(Enums.ComponentType componentType, int entityId) { Components.Movement mc; if (componentType == Enums.ComponentType.Movement) { if (movementComponents.TryGetValue(entityId, out mc)) { return(mc); } } else if (componentType == Enums.ComponentType.PreviousFrameMovement) { if (previousFrameMovementComponents.TryGetValue(entityId, out mc)) { return(mc); } } else { throw new ArgumentException("No component lists were found with the given type", "componentType"); } Debug.LogWarning(string.Format("Entity doesn't have component in the wanted component list, entity id : {0} component type: {1}", entityId, componentType)); return(null); }