Skip to content

Commit 006338f

Browse files
[animgraph] Added animgraph.Resource, fixed compilation
1 parent 741357a commit 006338f

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

hrt/animgraph/AnimGraphInstance.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class AnimGraphInstance extends h3d.anim.Animation {
5656
}
5757

5858
public function getParam(name: String) : Null<Float> {
59-
return parameterMap.get(name);
59+
return parameterMap.get(name)?.runtimeValue;
6060
}
6161

6262
public function resetParam(name: String) {

hrt/animgraph/Resource.hx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package hrt.animgraph;
2+
3+
@:access(hrt.prefab.AnimGraph)
4+
class Resource extends hxd.res.Resource {
5+
6+
var animGraph : AnimGraph;
7+
var cacheVersion : Int;
8+
var isWatched : Bool;
9+
10+
function loadData() {
11+
var isBSON = entry.fetchBytes(0,1).get(0) == 'H'.code;
12+
return isBSON ? new hxd.fmt.hbson.Reader(entry.getBytes(),false).read() : haxe.Json.parse(entry.getText());
13+
}
14+
15+
override function watch( onChanged: Null<Void -> Void> ) {
16+
if( entry == null )
17+
return;
18+
if( onChanged == null ) {
19+
super.watch(null);
20+
isWatched = false;
21+
return;
22+
}
23+
isWatched = true;
24+
super.watch(function() {
25+
if( animGraph != null ) {
26+
var data = try loadData() catch( e : Dynamic ) return; // parsing error (conflict ?)
27+
animGraph.reload(data);
28+
}
29+
onChanged();
30+
});
31+
}
32+
33+
public function load() : hrt.animgraph.AnimGraph {
34+
if( animGraph != null && cacheVersion == CACHE_VERSION )
35+
return animGraph;
36+
var data = loadData();
37+
animGraph = Std.downcast(@:privateAccess hrt.prefab.Prefab.createFromDynamic(data, new hrt.prefab.ContextShared(entry.path, false)), hrt.animgraph.AnimGraph);
38+
cacheVersion = CACHE_VERSION;
39+
watch(function() {}); // auto lib reload
40+
return animGraph;
41+
}
42+
43+
public function loadAnim() : AnimGraphInstance {
44+
return load().getAnimation();
45+
}
46+
47+
public static var CACHE_VERSION = 0;
48+
}

0 commit comments

Comments
 (0)