102 lines
2.1 KiB
C#
102 lines
2.1 KiB
C#
using UnityEngine;
|
|
|
|
[AddComponentMenu("Modifiers/Warps/Bind")]
|
|
public class MegaWarpBind : MegaModifier
|
|
{
|
|
public GameObject SourceWarpObj;
|
|
|
|
private GameObject current;
|
|
|
|
public float decay;
|
|
|
|
private MegaWarp warp;
|
|
|
|
public override string ModName()
|
|
{
|
|
return "WarpBind";
|
|
}
|
|
|
|
public override string GetHelpURL()
|
|
{
|
|
return "?page_id=576";
|
|
}
|
|
|
|
[ContextMenu("Add To Siblings")]
|
|
public void AddSiblings()
|
|
{
|
|
Transform parent = base.transform.parent;
|
|
MegaModifyObject component = GetComponent<MegaModifyObject>();
|
|
for (int i = 0; i < parent.childCount; i++)
|
|
{
|
|
Transform child = parent.GetChild(i);
|
|
MegaWarpBind component2 = child.gameObject.GetComponent<MegaWarpBind>();
|
|
if (!component2)
|
|
{
|
|
component2 = child.gameObject.AddComponent<MegaWarpBind>();
|
|
MegaModifyObject component3 = child.gameObject.GetComponent<MegaModifyObject>();
|
|
component3.NormalMethod = component.NormalMethod;
|
|
component2.SetTarget(SourceWarpObj);
|
|
}
|
|
}
|
|
}
|
|
|
|
public override Vector3 Map(int i, Vector3 p)
|
|
{
|
|
p = tm.MultiplyPoint3x4(p);
|
|
p = warp.Map(i, p);
|
|
return invtm.MultiplyPoint3x4(p);
|
|
}
|
|
|
|
public override bool ModLateUpdate(MegaModContext mc)
|
|
{
|
|
return Prepare(mc);
|
|
}
|
|
|
|
public override bool Prepare(MegaModContext mc)
|
|
{
|
|
if (SourceWarpObj != current)
|
|
{
|
|
current = SourceWarpObj;
|
|
warp = null;
|
|
}
|
|
if (SourceWarpObj != null)
|
|
{
|
|
if (warp == null)
|
|
{
|
|
warp = SourceWarpObj.GetComponent<MegaWarp>();
|
|
}
|
|
if (warp != null && warp.Enabled)
|
|
{
|
|
tm = base.transform.localToWorldMatrix;
|
|
invtm = tm.inverse;
|
|
return warp.Prepare(decay);
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void SetTarget(GameObject go)
|
|
{
|
|
SourceWarpObj = go;
|
|
}
|
|
|
|
public override void Modify(MegaModifiers mc)
|
|
{
|
|
for (int i = 0; i < verts.Length; i++)
|
|
{
|
|
Vector3 p = tm.MultiplyPoint3x4(verts[i]);
|
|
p = warp.Map(i, p);
|
|
sverts[i] = invtm.MultiplyPoint3x4(p);
|
|
}
|
|
}
|
|
|
|
public override void ModStart(MegaModifiers mc)
|
|
{
|
|
if (SourceWarpObj != null && SourceWarpObj != current)
|
|
{
|
|
current = SourceWarpObj;
|
|
warp = SourceWarpObj.GetComponent<MegaWarp>();
|
|
}
|
|
}
|
|
}
|