NewN_UAVPlane/Assets/Zion/Scripts/Sync1/FunctionSync_Scale.cs

64 lines
1.5 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.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 注意1.此脚本和动画共用时,需要注意动画激活时,缩放会被锁死,无法移动。
/// 2.有控制权才能移动,结束后需释放控制权(控制权专属除外)
/// </summary>
public class FunctionSync_Scale : OneValueSyncObject
{
/// <summary>
/// 是否有控制权
/// </summary>
public bool isControl=false;
private void Start()
{
Init();
}
public void Init()
{
if(!hasInit)
{
InitDynamic("Scale_" + gameObject.name, null, ValueType.Vector3);
myvector3 = transform.localScale;
}
}
/// <summary>
/// 获取控制权
/// </summary>
public void GetControl()
{
isControl = true;
}
/// <summary>
/// 释放控制权
/// </summary>
public void ReleaseControl()
{
isControl = false;
myvector3 = transform.localScale;
SendSync();
}
[DisplayOnly]
public float OnceTime = 0.1f;
private void LateUpdate()
{
if (!GameManage.Instance.is单机模式)
{
if (!isControl)
{
transform.localScale = myvector3;
}
else
{
if (Vector3.Distance(myvector3, transform.localScale) > OnceTime)
{
myvector3 = transform.localScale;
SendSync();
}
}
}
}
}