-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for the [Asset] attribute
- Loading branch information
1 parent
ed3dfa1
commit 028d8be
Showing
7 changed files
with
80 additions
and
6 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
namespace ElRaccoone.EntityComponentSystem { | ||
|
||
/// Describes an asset which should be assigned automatically. | ||
[System.AttributeUsage (System.AttributeTargets.Field)] | ||
public class Asset : System.Attribute { | ||
|
||
/// Defines whether the field name should be used for getting the asset from | ||
/// the controller. When set to false, the asset name string will be used | ||
/// instead. | ||
private bool useFieldNameAsAssetName = false; | ||
|
||
/// The asset name will be used when defined that the field name should not | ||
/// be used for finding the asset name. Thus using this asset name property | ||
/// instead. | ||
private string assetName = ""; | ||
|
||
/// Defines the property as an asset, when the controller is done | ||
/// registering, the asset will be fetched from the controller using the | ||
/// name of the property field. | ||
public Asset () { | ||
this.useFieldNameAsAssetName = true; | ||
this.assetName = ""; | ||
} | ||
|
||
/// Defines the property as an asset, when the controller is done | ||
/// registering, the asset will be fetched from the controller using the | ||
/// given asset name. | ||
public Asset(string assetName) { | ||
this.useFieldNameAsAssetName = false; | ||
this.assetName = assetName; | ||
} | ||
|
||
/// Sets the attributes values on an object. | ||
public static void SetAttributeValues (System.Object target) { | ||
var _fields = target.GetType ().GetFields ( | ||
System.Reflection.BindingFlags.Instance | | ||
System.Reflection.BindingFlags.NonPublic); | ||
foreach (var _field in _fields) { | ||
var _assetFieldAttribute = System.Attribute.GetCustomAttribute (_field, typeof (Asset)) as Asset; | ||
if (_assetFieldAttribute != null) | ||
_field.SetValue (target, Controller.Instance.GetAsset( | ||
_assetFieldAttribute.useFieldNameAsAssetName == true ? _field.Name : _assetFieldAttribute.assetName)); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "nl.elraccoone.entity-component-system", | ||
"displayName": "Entity Component System", | ||
"version": "3.6.0", | ||
"version": "3.7.0", | ||
"unity": "2019.1", | ||
"description": "A better approach to game design that allows you to concentrate on the actual problems you are solving: the data and behavior that make up your game. By moving from object-oriented to data-oriented design it will be easier for you to reuse the code and easier for others to understand and work on it." | ||
} |