Пример #1
0
    public UnitInstance CreateUnitObject(MapLua.SaveLua.Army.Unit Source, MapLua.SaveLua.Army.UnitsGroup Group)
    {
        Vector3    position          = ScmapEditor.ScmapPosToWorld(Source.Position);
        Vector3    RadianOrientation = Vector3.zero;
        Quaternion rotation          = Quaternion.Euler(Source.Orientation * Mathf.Rad2Deg);


        GameObject Obj = Instantiate(UnitsInfo.Current.UnitInstancePrefab, transform) as GameObject;

        Obj.name = Source.Name;

        UnitInstance UInst = Obj.GetComponent <UnitInstance>();

        //UInst.Owner = Owner;
        UInst.Group = Group;
        Group.UnitInstances.Add(UInst);
        UInst.orders       = Source.orders;
        UInst.platoon      = Source.platoon;
        UInst.UnitRenderer = this;
        UInst.SetMatrix(ScmapEditor.SnapToTerrain(position), rotation);

        if (BP.Footprint.x > 0 && BP.Footprint.y > 0)
        {
            UInst.Col.size = new Vector3(BP.Footprint.x * 0.1f, BP.Size.y * 0.1f, BP.Footprint.y * 0.1f);
        }
        else
        {
            UInst.Col.size = BP.Size * 0.1f;
        }
        UInst.Col.center = Vector3.up * (BP.Size.y * 0.05f);

        AddInstance(UInst);
        return(UInst);
    }
Пример #2
0
 public void SnapAction(Transform tr, GameObject Connected)
 {
     UpdateSelectedMatrixes = true;
     if (Connected == null)
     {
         tr.localPosition = ScmapEditor.SnapToTerrain(tr.localPosition);
     }
     else
     {
         tr.localPosition = Connected.GetComponent <UnitInstance>().GetSnapPosition(tr.localPosition);
     }
 }
Пример #3
0
    public Vector3 GetSnapPosition(Vector3 Pos)
    {
        if (UnitRenderer.BP.PhysicsLayerSub)
        {
            Vector3 PositionOnWater = ScmapEditor.SnapToTerrain(Pos, true);
            if (PositionOnWater.y > ScmapEditor.GetWaterLevel())
            {
                return(PositionOnWater);
            }

            Vector3 PositionUnderWater = ScmapEditor.SnapToTerrain(Pos, false);

            if (Mathf.Abs(PositionOnWater.y - PositionUnderWater.y) < UnitRenderer.BP.PhysicsElevation * 0.2f)
            {
                return(Vector3.Lerp(PositionOnWater, PositionUnderWater, 0.5f));
            }

            PositionOnWater.y += UnitRenderer.BP.PhysicsElevation * 0.1f;

            return(PositionOnWater);
        }
        return(ScmapEditor.SnapToTerrain(Pos, UnitRenderer.BP.PhysicsLayerWater));
    }
Пример #4
0
 public Vector3 GetSnapPosition(Vector3 Pos)
 {
     return(ScmapEditor.SnapToTerrain(Pos, UnitRenderer.BP.PhysicsLayerWater));
 }