Files
TEngine/Assets/TEngine.Demo/Demo/TEngine.EntityDemo/EntityTestMain.cs
ALEXTANG 74092e6399 事件系统优化更新
事件系统优化更新
1.使用静态代替单例,静态方法调用时候内存地址无需二次偏移定位
2.UI事件在关闭UI时自动反监听
2022-10-26 15:14:04 +08:00

61 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using TEngine.Demo.TEngine.EntityDemo;
using TEngine.Runtime;
using TEngine.Runtime.Entity;
using UnityEngine;
using LightType = TEngine.Demo.TEngine.EntityDemo.LightType;
public class EntityTestMain : MonoBehaviour
{
void Start()
{
//Demo示例监听TEngine流程加载器OnStartGame事件
//抛出这个事件说明框架流程加载完成(热更新,初始化等)
GameEvent.AddEventListener(TEngineEvent.OnStartGame,OnStartGame);
}
private void OnStartGame()
{
Log.Debug("TEngineEvent.OnStartGame");
for (int i = 1; i < 10; i++)
{
//实体数据创建
EntityData entityData= EntityData.Create();
entityData.Position = new Vector3(i, i, 0);
entityData.Rotation = Quaternion.identity;
//实体系统创建实体,自动创建实体组
EntitySystem.Instance.CreateEntity<EntityCube>("Cube",entityData);
}
LightEntityMgr.Instance.CreateLight(LightType.DirectionalLight,Vector3.zero, Quaternion.identity);
}
/// <summary>
/// 实体Cube
/// </summary>
public class EntityCube:EntityLogicEx
{
protected override void OnAttached(EntityLogic childEntity, Transform parentTransform, object userData)
{
base.OnAttached(childEntity, parentTransform, userData);
Log.Info("OnAttached");
}
/// <summary>
/// 实体显示事件
/// </summary>
/// <param name="userData">EntityData</param>
protected override void OnShow(object userData)
{
base.OnShow(userData);
Log.Info("OnShow");
}
protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
{
base.OnUpdate(elapseSeconds, realElapseSeconds);
}
}
}