Esempio n. 1
0
    public UnitInstance FillGameObjectValues(GameObject Obj, MapLua.SaveLua.Army.Unit Source, MapLua.SaveLua.Army.UnitsGroup Group, Vector3 position, Quaternion rotation)
    {
        Obj.name = Source.Name;

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

        //UInst.Owner = Owner;
        UInst.Owner     = Source;
        Source.Instance = UInst;
        //Group.Units.Add(Source);
        UInst.orders       = Source.orders;
        UInst.platoon      = Source.platoon;
        UInst.UnitRenderer = this;
        UInst.SetMatrix(UInst.GetSnapPosition(position), rotation);
        UInst.ArmyColor = Group.Owner.ArmyColor;

        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);
    }
Esempio n. 2
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);
    }
    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          = UnitInstance.RotationFromScmapRotation(Source.Orientation);

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

        return(FillGameObjectValues(Obj, Source, Group, position, rotation));
    }
    public UnitInstance FillGameObjectValues(GameObject Obj, MapLua.SaveLua.Army.Unit Source, MapLua.SaveLua.Army.UnitsGroup Group, Vector3 position, Quaternion rotation)
    {
        if (Obj.transform.childCount > 0)
        {
            foreach (Transform child in Obj.transform)
            {
                Destroy(child.gameObject);
            }
        }

        Obj.name = Source.Name;

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

        //UInst.Owner = Owner;
        UInst.Owner     = Source;
        Source.Instance = UInst;
        //Group.Units.Add(Source);
        UInst.orders       = Source.orders;
        UInst.platoon      = Source.platoon;
        UInst.UnitRenderer = this;
        UInst.SetMatrix(UInst.GetSnapPosition(position), rotation);
        UInst.ArmyColor = Group.Owner.ArmyColor;

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

        if (BP.HasTermac)
        {
            if (BP.Termac_Albedo != null)
            {
                DecalsInfo.CreateGameObjectFromDecal(BP.Termac_Albedo);
                BP.Termac_Albedo.Obj.tr.parent        = UInst.transform;
                BP.Termac_Albedo.Obj.tr.localPosition = Vector3.zero;
            }

            if (BP.Termac_Normal != null)
            {
                DecalsInfo.CreateGameObjectFromDecal(BP.Termac_Normal);
                BP.Termac_Normal.Obj.tr.parent        = UInst.transform;
                BP.Termac_Normal.Obj.tr.localPosition = Vector3.zero;
            }
        }

        AddInstance(UInst);
        return(UInst);
    }