// ---------------------------------------------------------------- // Events // ---------------------------------------------------------------- public void OnObjectRemovedFromPlay(BoardObject bo) { // Remove it from its lists! allObjects.Remove(bo); if (bo is ExitSpot) { NumExitSpots--; } else { Debug.LogError("Trying to RemoveFromPlay an Object of type " + bo.GetType() + ", but our OnObjectRemovedFromPlay function doesn't recognize this type!"); } }
/// <summary> /// Loads all [CircuitProperties] on the target object /// </summary> public static CircuitPropertyCollection GetProperties(BoardObject target, Action <string> registerChange) { var properties = target.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); var circuitProps = new HashSet <CircuitProp>(); foreach (var property in properties) { var attribute = property.GetCustomAttribute <CircuitPropertyBase>(true); ///If attribute is not found or if property has an [IgnoreCircuitAttributesAttribute] if (attribute == null || property.GetCustomAttribute(typeof(HideCircuitAttributesAttribute), true) != null) { continue; } circuitProps.Add(attribute.ToProp(property, target)); } return(new CircuitPropertyCollection(circuitProps, registerChange)); }
/// <summary> /// Reflectively loads all [CircuitActions] on a target CircuitObject. /// </summary> /// <param name="cleanup">Function to be run after the action is invoked (refresh selections)</param> public static CircuitActionCollection GetActions(BoardObject target, Action <BoardState> cleanup, Action <string> registerChange) { var actions = new HashSet <CircuitAct>(); //Find and register all methods which are circuit actions var methods = target.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (var method in methods) { var attribute = method.GetCustomAttribute <CircuitActionBase>(true); if (attribute == null) { continue; } //If method has IgnoreCircuitAttribute, continue if (method.GetCustomAttributes(typeof(HideCircuitAttributesAttribute), true).Length != 0) { continue; } void action(BoardState state) { //Invoke method with or without state as parameter method.Invoke(target, method.GetParameters().Length == 1 ? new[] { state } : null); cleanup(state); } actions.Add(new CircuitAct(action, attribute)); } //Find and register all properties which are Circuit Actions var properties = target.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); var circuitProps = new List <CircuitProp>(); foreach (var property in properties) { var propertyAttribute = property.GetCustomAttribute <CircuitPropertyDropdownAttribute>(true); var actionAttributes = property.GetCustomAttributes <CircuitDropdownActionAttribute>(true); foreach (var actionAttribute in actionAttributes) { //If attribute is not found or if property has an [IgnoreCircuitAttributesAttribute] if (actionAttribute == null || property.GetCustomAttribute(typeof(HideCircuitAttributesAttribute), true) != null) { continue; } if (propertyAttribute == null) { throw new NotImplementedException("All [CircuitPropertyAction] attributes on a property must also have a [CircuitPropertyDropdown] attribute."); } CircuitProp prop = propertyAttribute.ToProp(property, target); //Increments/decrements the property's value and resets to valueRange.min/max if it goes over/under the valueRange.max/min void action(BoardState state) { int value = prop.valueRange.min + Array.IndexOf(prop.valueNames, prop.Get()); if (actionAttribute.increment) { if (++value > prop.valueRange.max) { if (actionAttribute.behavior == PropertyOverflow.Clip) { value = prop.valueRange.max; } else { value = prop.valueRange.min; } } } else { if (--value < prop.valueRange.min) { if (actionAttribute.behavior == PropertyOverflow.Clip) { value = prop.valueRange.min; } else { value = prop.valueRange.max; } } } prop.Set(prop.valueNames[value - prop.valueRange.min], state.Connections); cleanup(state); } actions.Add(new CircuitAct(action, actionAttribute)); } } return(new CircuitActionCollection(actions, registerChange)); }
// Getters public GameObject GetBoardObjectView(BoardObject sourceObject) { if (sourceObject is BeamGoal) { return(BeamGoalView); } if (sourceObject is BeamSource) { return(BeamSourceView); } if (sourceObject is Crate) { return(CrateView); } if (sourceObject is CrateGoal) { return(CrateGoalView); } if (sourceObject is ExitSpot) { return(ExitSpotView); } if (sourceObject is Player) { return(PlayerView); } if (sourceObject is Voyd) { return(VoydView); } Debug.LogError("Trying to add BoardObjectView from BoardObject, but no clause to handle this type! " + sourceObject.GetType().ToString()); return(null); }
private void DrawSelectedTileProperties() { if (!level.board.IsWithinWalls(selectedTile)) { selectedTile = new Vector2Int(-1, -1); } if (!selectedTile.Equals(new Vector2Int(-1, -1))) { EditorGUILayout.LabelField("Selected Tile: " + selectedTile.ToString()); EditorGUI.indentLevel++; if (level.board.IsWallTile(selectedTile)) { WallObject wallObject = level.board.GetWallObject(selectedTile); int newIndex; int index = findIndex(wallObjectTypes, wallObject.GetType()); if (index != -1) { newIndex = EditorGUILayout.Popup("Object Type", index, wallObjectTypeNames); DrawProperties(wallObject); } else { newIndex = EditorGUILayout.Popup("Object Type", 0, wallObjectTypeNames); } if (newIndex != index) { ReplaceWall(selectedTile, wallObjectTypes[newIndex]); } } else { BoardObject boardObject = level.board.GetBoardObject(selectedTile); int newIndex; int index = 0; if (boardObject) { index = findIndex(boardObjectTypes, boardObject.GetType()); if (index != -1) { newIndex = EditorGUILayout.Popup("Object Type", index, boardObjectTypeNames); DrawProperties(boardObject); } else { newIndex = EditorGUILayout.Popup("Object Type", 0, wallObjectTypeNames); } } else { newIndex = EditorGUILayout.Popup("Object Type", 0, boardObjectTypeNames); } if (newIndex != index) { ReplaceTile(selectedTile, boardObjectTypes[newIndex]); } } EditorGUI.indentLevel--; } }