forked from loongly/PureScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestBehaviourScript.cs
More file actions
140 lines (112 loc) · 3.55 KB
/
Copy pathTestBehaviourScript.cs
File metadata and controls
140 lines (112 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestBehaviourScript : MonoBehaviour
{
public GameObject testObj;
public Transform testTrans;
private Vector3 moveTarget;
// Start is called before the first frame update
void Start()
{
testObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
testTrans = testObj.transform;
moveTarget = new Vector3(1, 0, 0);
Debug.LogError($"==== name: {this.name} tag:{gameObject.tag}" );
StartCoroutine(RunCoroutineTest("teststr",1));
StartCoroutine(StartTestGC());
TestGetComponent();
}
// Update is called once per frame
void Update()
{
var curPos = testTrans.position;
if (curPos.x > 6)
moveTarget = Vector3.left;
else if (curPos.x < -6)
moveTarget = Vector3.right;
testTrans.Rotate(Vector3.up, 1);
testTrans.position = curPos + moveTarget * Time.deltaTime* 3;
}
IEnumerator RunCoroutineTest(string str, int a = 1)
{
Debug.LogError("===== RunCoroutineTest ===== " + str);
int testValue = 2;
yield return null;
Debug.LogError("FFF");
yield return StartCoroutine(TestSecendEnumerator());
Debug.LogError("00" + str);
yield return new WaitForEndOfFrame();
Debug.LogError("AAA" + str);
yield return new WaitForSeconds(2.0f);
int tv = 2;
Debug.LogError("BBB");
float end = Time.time + 3.0f;
yield return new WaitUntil(() => Time.time > end);
Debug.LogError("CCC");
yield return new WaitForSeconds(3.0f);
yield return 0;
Debug.LogError("DDD");
yield return new CostomWait(Time.time + 3.0f);
Debug.LogError("EEE");
yield return null;
yield return StartCoroutine(TestSecendEnumerator());
Debug.LogError("FFF");
yield return null;
Debug.LogError("GG");
}
IEnumerator TestSecendEnumerator()
{
Debug.LogError("TestSecendEnumerator >>");
yield return new WaitForSeconds(1.0f);
Debug.LogError("aaaa");
// yield return null;
Debug.LogError("bbbb");
yield return new WaitForSeconds(5.0f);
Debug.LogError("ccc");
}
public class CostomWait : CustomYieldInstruction
{
float waitTime;
public CostomWait(float time)
{
waitTime = time;
}
public override bool keepWaiting
{
get
{
return Time.time < waitTime;
}
}
}
IEnumerator StartTestGC()
{
var obj = GameObject.CreatePrimitive(PrimitiveType.Capsule);
obj.AddComponent<TestGC>().Info = "Test1";
obj.AddComponent<TestGC>().Info = "Test2";
yield return new WaitForSeconds(3.0f);
Destroy(obj);
yield return new WaitForSeconds(1.0f);
System.GC.Collect();
}
private void OnDestroy()
{
Debug.LogError("== TestBehaviourScript OnDestroy");
}
~TestBehaviourScript()
{
Debug.LogError("~TestBehaviourScript");
}
void TestGetComponent()
{
Debug.LogError("== TestGetMonoBehaviour == " + testObj.name);
var scrpit = gameObject.GetComponent<TestBehaviourScript>();
Debug.LogError("== isequl: " + (scrpit == this));
var cps = gameObject.GetComponents<MonoBehaviour>();
foreach (var cp in cps)
{
Debug.LogError("cp: " + cp.GetType().Name);
}
}
}