Class: U3d::Asset
- Inherits:
-
Object
- Object
- U3d::Asset
- Defined in:
- lib/u3d/asset.rb
Overview
U3d::Asset provides you with a way to easily manipulate an search for assets in Unity Projects
Instance Attribute Summary collapse
-
#guid ⇒ Object
readonly
Returns the value of attribute guid.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#meta_path ⇒ Object
readonly
Returns the value of attribute meta_path.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
- #extension ⇒ Object
- #guid_references ⇒ Object
- #hash ⇒ Object
-
#initialize(path, unity_project = nil) ⇒ Asset
constructor
A new instance of Asset.
- #inspect ⇒ Object
- #name_references ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(path, unity_project = nil) ⇒ Asset
Returns a new instance of Asset.
39 40 41 42 43 44 45 46 47 |
# File 'lib/u3d/asset.rb', line 39 def initialize(path, unity_project = nil) raise ArgumentError, "No file at #{path}" unless File.exist?(path) @path = path = "#{path}.meta" = YAML.safe_load(File.read()) @guid = ['guid'] @unity_project = unity_project end |
Instance Attribute Details
#guid ⇒ Object (readonly)
Returns the value of attribute guid.
37 38 39 |
# File 'lib/u3d/asset.rb', line 37 def guid @guid end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
37 38 39 |
# File 'lib/u3d/asset.rb', line 37 def end |
#meta_path ⇒ Object (readonly)
Returns the value of attribute meta_path.
37 38 39 |
# File 'lib/u3d/asset.rb', line 37 def end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
37 38 39 |
# File 'lib/u3d/asset.rb', line 37 def path @path end |
Class Method Details
.glob(pattern, unity_project_path = Dir.pwd) ⇒ Object
31 32 33 34 |
# File 'lib/u3d/asset.rb', line 31 def glob(pattern, unity_project_path = Dir.pwd) unity_project = U3d::UnityProject.new(unity_project_path) Dir.glob(pattern).reject { |path| File.extname(path) == '.meta' || !File.file?(path) }.map { |path| Asset.new(path, unity_project) } end |
Instance Method Details
#eql?(other) ⇒ Boolean
67 68 69 70 71 |
# File 'lib/u3d/asset.rb', line 67 def eql?(other) return false unless other.is_a? Asset other.guid == @guid end |
#extension ⇒ Object
63 64 65 |
# File 'lib/u3d/asset.rb', line 63 def extension File.extname(@path) end |
#guid_references ⇒ Object
49 50 51 52 53 54 |
# File 'lib/u3d/asset.rb', line 49 def guid_references @guid_references ||= U3dCore::CommandExecutor.execute( command: "grep -rl #{@guid} #{grep_reference_root}", print_command: false ).split("\n").reject { |f| f == }.map { |path| Asset.new(path) } end |
#hash ⇒ Object
73 74 75 |
# File 'lib/u3d/asset.rb', line 73 def hash @guid.to_i end |
#inspect ⇒ Object
81 82 83 |
# File 'lib/u3d/asset.rb', line 81 def inspect to_s end |
#name_references ⇒ Object
56 57 58 59 60 61 |
# File 'lib/u3d/asset.rb', line 56 def name_references @name_references ||= U3dCore::CommandExecutor.execute( command: "grep -rl #{File.basename(@path, extension)} #{grep_reference_root} --include=*.cs", print_command: false ).split("\n").map { |path| Asset.new(path) } end |
#to_s ⇒ Object
77 78 79 |
# File 'lib/u3d/asset.rb', line 77 def to_s "#{@guid}:#{@path}" end |