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.
 
 
 
 
 
 

138 lines
3.7 KiB

using UnityEngine;
namespace CoreGame.Render
{
[Combat]
public class TransformProxy : ProxyBase
{
internal Transform value;
internal Transform root;
internal bool isStop = true;
public Vector2 position;
public Vector2 direction; // = Vector2.right;
internal float renderSpeed = 5;
internal Vector2 lastPosition;
internal Vector2 lastDirection;
internal bool hasInitFlush;
internal Vector2[] cachePos = new Vector2[2];
internal Vector2[] cacheDir = new Vector2[2];
public void Flush()
{
// lastPosition = position;
// lastDirection = direction;
// m_TimeAcc = 0;
}
public void Flush2()
{
lastPosition = position;
lastDirection = direction;
}
public Vector3 GetRenderPosition()
{
if (!value)
{
return lastPosition;
}
return value.position;
}
public void OnAssetLoaded()
{
Sync();
}
// [Obsolete]
public void RenderSync(float dt)
{
//
// if (!root) return;
// if (ent.hasBlackboard && ent.blackboard.inverseDir)
// root.localRotation = forward.x < 0 ? Quaternion.identity : Quaternion.Euler(0, 180, 0);
// else
// root.localRotation = forward.x > 0 ? Quaternion.identity : Quaternion.Euler(0, 180, 0);
}
public void Sync()
{
if (!value) return;
var woldPos = new Vector3(position.x, position.y, 0);
var forward = new Vector3(direction.x, direction.y, 0);
if (ent.hasBullet)
{
var rotation = Quaternion.LookRotation(Vector3.forward, forward);
value.SetPositionAndRotation(woldPos, rotation);
return;
}
value.position = woldPos;
if (!root) return;
if (ent.hasBlackboard && ent.blackboard.inverseDir)
root.localRotation = forward.x < 0 ? Quaternion.identity : Quaternion.Euler(0, 180, 0);
else
root.localRotation = direction.x > 0 ? Quaternion.identity : Quaternion.Euler(0, 180, 0);
}
public void AddPosition(Vector2 delta)
{
if(ent.hasLogicTransform)
return;
position += delta;
}
public void SetRenderSpeed(float speed)
{
// renderSpeed = speed;
}
public void SetPosition(Vector2 pos)
{
if(ent.hasLogicTransform)
return;
position = pos;
}
public void SetDirection(Vector2 dir)
{
if(ent.hasLogicTransform)
return;
direction = dir;
}
public void SetLocalScale(Vector2 pos)
{
if (value)
value.localScale = new Vector3(pos.x, pos.y, 1);
}
public Vector2 GetLocalScale()
{
if (value)
return new Vector2(value.localScale.x, value.localScale.y);
return Vector2.one;
}
protected override void Initialize(GameObject go, CombatEntity ent)
{
value = go.transform;
root = value.Find("Object");
}
protected override void OnReset()
{
value = null;
root = null;
position = Vector2.zero;
direction = Vector2.right;
renderSpeed = 0;
lastPosition = Vector2.zero;
lastDirection = Vector2.right;
hasInitFlush = false;
}
}
}