163 lines
4.0 KiB
C#
163 lines
4.0 KiB
C#
using System.Collections.Generic;
|
|
using Superlazy;
|
|
using UnityEngine;
|
|
|
|
public abstract class ZoneViewComponent : MonoBehaviour
|
|
{
|
|
private ZoneView zoneView;
|
|
|
|
protected SLEntity Entity => zoneView.Entity;
|
|
|
|
public void Init(ZoneView zoneView)
|
|
{
|
|
this.zoneView = zoneView;
|
|
Init();
|
|
}
|
|
|
|
public abstract void Init();
|
|
}
|
|
|
|
public interface IZoneView
|
|
{
|
|
bool UseSceneLight { get; }
|
|
float Outline { get; }
|
|
int Layer { get; }
|
|
|
|
Transform Root { get; }
|
|
|
|
SLEntity Entity { get; }
|
|
|
|
float WorldHeight { get; }
|
|
}
|
|
|
|
public class ZoneView : MonoBehaviour, IZoneView
|
|
{
|
|
public SLGame Game { get; private set; }
|
|
public SLSystem System { get; private set; }
|
|
|
|
public float WorldScale { get; set; } = 1;
|
|
public Vector2 WorldOffset { get; set; } = Vector2.zero;
|
|
public float WorldHeight { get; set; } = 0;
|
|
|
|
public bool UseSceneLight => true;
|
|
public float Outline => 16; // TODO: 시스템화
|
|
public int Layer => gameObject.layer;
|
|
|
|
public SLEntity Entity { get; set; }
|
|
public Transform Root => transform;
|
|
|
|
private readonly Dictionary<int, UnitView> bindUnits = new Dictionary<int, UnitView>();
|
|
|
|
private readonly List<UnitView> addUnits = new List<UnitView>();
|
|
|
|
private readonly List<ZoneViewComponent> zoneViewComponents = new List<ZoneViewComponent>();
|
|
|
|
public void Init(SLEntity zoneRoot, string zoneViewRoot)
|
|
{
|
|
Entity = zoneRoot;
|
|
UnitView.InitGlobal();
|
|
EffectView.InitGlobal();
|
|
|
|
var componentTypes = new List<System.Type>();
|
|
componentTypes.CreateTypeList<ZoneViewComponent>();
|
|
foreach (var t in componentTypes)
|
|
{
|
|
var component = gameObject.AddComponent(t) as ZoneViewComponent;
|
|
zoneViewComponents.Add(component);
|
|
component.Init(this);
|
|
}
|
|
}
|
|
|
|
public void Message(Unit unit, string eventName, SLEntity context)
|
|
{
|
|
if (context["CancelMessage"]) return;
|
|
|
|
if (eventName == "AddUnit")
|
|
{
|
|
AddUnitView(unit, context["Handle"]);
|
|
}
|
|
|
|
if (unit == null)
|
|
{
|
|
gameObject.SendMessage(eventName, context, SendMessageOptions.DontRequireReceiver);
|
|
}
|
|
else
|
|
{
|
|
if (bindUnits.ContainsKey(unit.Entity["Handle"]))
|
|
{
|
|
bindUnits[unit.Entity["Handle"]].SendMessage(eventName, context, SendMessageOptions.DontRequireReceiver);
|
|
}
|
|
else
|
|
{
|
|
SLLog.Error($"Cant Find UnitView {unit.Entity["Handle"]}", this);
|
|
}
|
|
}
|
|
|
|
if (eventName == "RemoveUnit")
|
|
{
|
|
RemoveUnitView(context["Handle"]);
|
|
}
|
|
}
|
|
|
|
protected void AddUnitView(Unit unit, int handle)
|
|
{
|
|
var newUnit = UnitView.MakeUnit(this, unit.Entity);
|
|
|
|
bindUnits[handle] = newUnit;
|
|
addUnits.Add(newUnit);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
foreach (var unit in addUnits)
|
|
{
|
|
unit.Update();
|
|
}
|
|
addUnits.Clear();
|
|
|
|
//
|
|
//UpdateSkillCells();
|
|
}
|
|
|
|
protected void RemoveUnitView(int handle)
|
|
{
|
|
UnitView.RemoveUnit(bindUnits[handle]);
|
|
|
|
bindUnits.Remove(handle);
|
|
}
|
|
|
|
public UnitView GetUnit(int handle)
|
|
{
|
|
return bindUnits[handle];
|
|
}
|
|
|
|
private void Effect(SLEntity context)
|
|
{
|
|
var position = context["Position"].ToVector3();
|
|
var forward = context["Forward"].ToVector3();
|
|
|
|
if (forward.magnitude != 0)
|
|
{
|
|
var rotation = Quaternion.LookRotation(forward, Vector3.up);
|
|
EffectView.MakeEffect(this, context["Effect"], context, position, rotation, Vector3.one);
|
|
}
|
|
else
|
|
{
|
|
EffectView.MakeEffect(this, context["Effect"], context, position, Quaternion.identity, Vector3.one);
|
|
}
|
|
}
|
|
|
|
private void RemoveEffect(SLEntity context)
|
|
{
|
|
EffectView.RemoveEffect(context["EffectID"]);
|
|
}
|
|
|
|
private void SetBattleEffect(SLEntity context)
|
|
{
|
|
SLGame.Event(context["Effect"], context);
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
}
|
|
} |