You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
1.9 KiB
93 lines
1.9 KiB
3 years ago
|
using UnityEngine;
|
||
|
using System;
|
||
|
using System.Collections;
|
||
|
using AX.MessageSystem;
|
||
|
|
||
|
public class PK3 : MonoBehaviour
|
||
|
{
|
||
|
const int LoopNumber = 500;
|
||
|
|
||
|
bool isStartDelegate;
|
||
|
bool isStartSendMessage;
|
||
|
|
||
|
int count;
|
||
|
|
||
|
private ProfilerTest profiler;
|
||
|
private long time0;
|
||
|
private long time1;
|
||
|
|
||
|
void Start()
|
||
|
{
|
||
|
profiler = new ProfilerTest();
|
||
|
|
||
|
MessageDispatcher.AddListener("COUNTER", Counter);
|
||
|
}
|
||
|
void OnDestroy()
|
||
|
{
|
||
|
MessageDispatcher.RemoveListener("COUNTER", Counter);
|
||
|
}
|
||
|
void Counter(IMessage message)
|
||
|
{
|
||
|
++count;
|
||
|
}
|
||
|
|
||
|
void UpdateCounter()
|
||
|
{
|
||
|
++count;
|
||
|
}
|
||
|
|
||
|
|
||
|
void Update()
|
||
|
{
|
||
|
if (isStartDelegate)
|
||
|
{
|
||
|
profiler.Start();
|
||
|
|
||
|
MessageDispatcher.SendMessage("COUNTER");
|
||
|
|
||
|
profiler.Stop();
|
||
|
|
||
|
time0 += profiler.ElapsedTicks;
|
||
|
|
||
|
if (count == LoopNumber)
|
||
|
isStartDelegate = false;
|
||
|
}
|
||
|
|
||
|
if (isStartSendMessage)
|
||
|
{
|
||
|
profiler.Start();
|
||
|
|
||
|
this.gameObject.SendMessage("UpdateCounter", SendMessageOptions.DontRequireReceiver);
|
||
|
|
||
|
profiler.Stop();
|
||
|
|
||
|
time1 += profiler.ElapsedTicks;
|
||
|
|
||
|
if (count == LoopNumber)
|
||
|
isStartSendMessage = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void OnGUI()
|
||
|
{
|
||
|
if (GUILayout.Button("**** INVOKE MessageDispatcher ****"))
|
||
|
{
|
||
|
isStartDelegate = true;
|
||
|
|
||
|
time0 = 0;
|
||
|
count = 0;
|
||
|
}
|
||
|
|
||
|
if (GUILayout.Button("SendMessage"))
|
||
|
{
|
||
|
isStartSendMessage = true;
|
||
|
|
||
|
time1 = 0;
|
||
|
count = 0;
|
||
|
}
|
||
|
|
||
|
GUILayout.Label("MessageDispatcher Time: " + TimeSpan.FromTicks(time0).TotalMilliseconds.ToString() + " ms");
|
||
|
GUILayout.Label("U3D SendMessage Time: " + TimeSpan.FromTicks(time1).TotalMilliseconds.ToString() + " ms");
|
||
|
}
|
||
|
}
|