doc
parent
dd583d2ed0
commit
862be13435
|
@ -9,7 +9,7 @@
|
|||
config_version=4
|
||||
|
||||
_global_script_classes=[ {
|
||||
"base": "Reference",
|
||||
"base": "Node2D",
|
||||
"class": "MyClass",
|
||||
"language": "GDScript",
|
||||
"path": "res://script/demo02_base/MyClass.gd"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://script/demo02_base/base.gd" type="Script" id=1]
|
||||
[ext_resource path="res://script/demo02_base/base1.gd" type="Script" id=1]
|
||||
|
||||
[node name="Node2D" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
|
@ -0,0 +1,6 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://script/demo02_base/base2.gd" type="Script" id=1]
|
||||
|
||||
[node name="Node2D" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
|
@ -0,0 +1,6 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://script/demo02_base/base3.gd" type="Script" id=1]
|
||||
|
||||
[node name="Node2D" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
|
@ -0,0 +1,4 @@
|
|||
extends Reference
|
||||
|
||||
# 表示B对象
|
||||
var b
|
|
@ -0,0 +1,4 @@
|
|||
extends Reference
|
||||
|
||||
# 表示A对象
|
||||
var a
|
|
@ -0,0 +1,4 @@
|
|||
extends Node2D
|
||||
|
||||
func _to_string():
|
||||
print("This is C Node2!")
|
|
@ -0,0 +1,5 @@
|
|||
# 如果没有继承任何类,则默认继承Reference
|
||||
extends Reference
|
||||
|
||||
func _to_string():
|
||||
print("This is C Reference!")
|
|
@ -1,4 +1,4 @@
|
|||
# extends Node2D
|
||||
extends Node2D
|
||||
|
||||
const StringUtils = preload("res://zfoo/util/StringUtils.gd")
|
||||
|
||||
|
@ -60,7 +60,7 @@ func typeInfo():
|
|||
print(StringUtils.format(template, [TYPE_DICTIONARY, typeof(dict), dict]))
|
||||
print(StringUtils.format(template, [TYPE_DICTIONARY, typeof(FOOD), FOOD]))
|
||||
print(StringUtils.format(template, [TYPE_DICTIONARY, typeof(FOOD.GOOD), FOOD.GOOD]))
|
||||
print(self is Reference)
|
||||
print(self is Node)
|
||||
print(a is Dog) # 类似于instanceof
|
||||
|
||||
func some_function(param1, param2):
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
extends Node2D
|
||||
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
export var a = 1
|
||||
export var b:NodePath
|
||||
|
@ -8,7 +9,7 @@ export(String, FILE) var e
|
|||
export(String, FILE, "*.txt") var d
|
||||
export(Resource) var f
|
||||
export(Color, RGB) var g
|
||||
var arr = []
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
print("new一个对象--------------------------------")
|
||||
|
@ -36,24 +37,4 @@ func _ready():
|
|||
print("内部类测试--------------------------------")
|
||||
myClass.innerClassTest()
|
||||
|
||||
print("垃圾回收--------------------------------")
|
||||
# 如果一个类没有指明继承哪个类,则默认继承Reference(可以被自动的垃圾回收,类似其他语言的那种垃圾回收),非常重要的知识点
|
||||
for i in range(10000):
|
||||
var instance = MyClass.new()
|
||||
arr.append(instance)
|
||||
# instance.unreference()
|
||||
# 立即释放对象
|
||||
# instance.free()
|
||||
# 放在队列里,等系统统一释放对象,推荐
|
||||
# instance.queue_free()
|
||||
print("立即输出数组的第一位内容:")
|
||||
var firstElement = arr[0]
|
||||
print(arr[0])
|
||||
|
||||
var frame = 0
|
||||
func _process(delta):
|
||||
frame = frame + 1
|
||||
if frame == 300:
|
||||
print("等待一会数组的第一位内容")
|
||||
arr[0].typeInfo()
|
||||
print(typeof(arr[0]))
|
|
@ -0,0 +1,46 @@
|
|||
extends Node2D
|
||||
|
||||
const CNode = preload("res://script/demo02_base/CNode.gd")
|
||||
const CReference = preload("res://script/demo02_base/CReference.gd")
|
||||
|
||||
# monitor初探
|
||||
func _ready():
|
||||
#nodeTest()
|
||||
#nodeFreeTest()
|
||||
#nodeQueueFreeTest()
|
||||
#referenceTest()
|
||||
#referenceFreeTest()
|
||||
referencUnreferenceTest()
|
||||
pass
|
||||
|
||||
|
||||
func nodeTest():
|
||||
for i in range(10000):
|
||||
var instance = CNode.new()
|
||||
|
||||
|
||||
func nodeFreeTest():
|
||||
for i in range(10000):
|
||||
var instance = CNode.new()
|
||||
instance.free()
|
||||
|
||||
# queue_free效率更高
|
||||
func nodeQueueFreeTest():
|
||||
for i in range(10000):
|
||||
var instance = CNode.new()
|
||||
instance.queue_free()
|
||||
|
||||
func referenceTest():
|
||||
for i in range(10000):
|
||||
var instance = CReference.new()
|
||||
|
||||
|
||||
func referenceFreeTest():
|
||||
for i in range(10000):
|
||||
var instance = CReference.new()
|
||||
instance.free()
|
||||
|
||||
func referencUnreferenceTest():
|
||||
for i in range(10000):
|
||||
var instance = CReference.new()
|
||||
instance.unreference()
|
|
@ -0,0 +1,39 @@
|
|||
extends Node2D
|
||||
|
||||
const A = preload("res://script/demo02_base/A.gd")
|
||||
const B = preload("res://script/demo02_base/B.gd")
|
||||
|
||||
func _ready():
|
||||
#referenceTest()
|
||||
#referenceCycleTest()
|
||||
#referenceUnreference1Test()
|
||||
referenceUnreference2Test()
|
||||
pass
|
||||
|
||||
|
||||
func referenceTest():
|
||||
var a = A.new()
|
||||
var b = B.new()
|
||||
|
||||
func referenceCycleTest():
|
||||
var a = A.new()
|
||||
var b = B.new()
|
||||
a.b = b
|
||||
b.a = a
|
||||
|
||||
|
||||
func referenceUnreference1Test():
|
||||
var a = A.new()
|
||||
var b = B.new()
|
||||
a.b = b
|
||||
b.a = a
|
||||
a.unreference()
|
||||
b.unreference()
|
||||
|
||||
func referenceUnreference2Test():
|
||||
var a = A.new()
|
||||
var b = B.new()
|
||||
a.b = b
|
||||
b.a = a
|
||||
a.b.unreference()
|
||||
b.a.unreference()
|
Loading…
Reference in New Issue