Esempio n. 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);
    }
    public void SetGroup(MapLua.SaveLua.Army Owner, MapLua.SaveLua.Army.UnitsGroup Data, MapLua.SaveLua.Army.UnitsGroup Parent, bool root)
    {
        this.Owner  = Owner;
        this.Source = Data;
        this.Parent = Parent;
        IsRoot      = root;

        IsExpanded    = Data.Expanded;
        Data.Instance = this;

        if (IsRoot)
        {
            GroupName.text = Owner.Name;
            //NameInputField.SetValue(Owner.Name);
            RemoveButton.SetActive(false);
            //UnitsCount.gameObject.SetActive(false);
        }
        else
        {
            GroupName.text = Source.Name;
            //NameInputField.SetValue(Source.Name);
            RemoveButton.SetActive(true);
            //UnitsCount.gameObject.SetActive(true);
        }
        UpdateValues(Source.Units.Count, Source.UnitGroups.Count);


        RenameEnd();
        Selection.color = ColorNormal;
        GroupName.color = IsRoot ? NameRoot : NameGroup;
    }
    public override void DoRedo()
    {
        MapLua.SaveLua.Army.UnitsGroup[] RemoveOld = new MapLua.SaveLua.Army.UnitsGroup[RegisteredGroup.UnitGroups.Count];
        RegisteredGroup.UnitGroups.CopyTo(RemoveOld);

        for (int i = 0; i < RemoveOld.Length; i++)
        {
            RegisteredGroup.RemoveGroup(AllGroups[i]);
        }

        RegisteredGroup.UnitGroups.Clear();

        for (int i = 0; i < AllGroups.Length; i++)
        {
            //RegisteredGroup.UnitGroups.Add(AllGroups[i]);
            RegisteredGroup.AddGroup(AllGroups[i]);
        }


        Undo.Current.EditMenu.ChangeCategory(7);
        MapLuaParser.Current.UnitsMenu.ChangePage(0);
        MapLuaParser.Current.UnitsMenu.Generate();
        //NewMarkersInfo.Current.ClearCreateNew();
        //MarkersInfo.Current.ChangePage(0);

        //NewMarkersInfo.Current.GoToSelection();
    }
 public override void Register()
 {
     RegisteredGroup = RegisterGroup;
     Name            = RegisteredGroup.NoPrefixName;
     Prefix          = RegisteredGroup.PrefixName;
     Orders          = RegisteredGroup.orders;
     Platoons        = RegisteredGroup.platoon;
 }
    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 override void DoUndo()
 {
     if (!RedoGenerated)
     {
         RegisterGroup = RegisteredGroup;
         HistoryUnitGroupRemove.GenerateRedo(Undo.Current.Prefabs.UnitGroupRemove).Register();
     }
     RedoGenerated = true;
     DoRedo();
 }
Esempio n. 7
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);
    }
    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);
    }
 public static void RegisterGroupChange(MapLua.SaveLua.Army.UnitsGroup source)
 {
     HistoryUnitGroupChange.RegisterGroup = source;
     HistoryUnitGroupChange.GenerateUndo(Current.Prefabs.UnitGroupChange).Register();
 }
 public override void Register()
 {
     RegisteredGroup = RegisterGroup;
     AllGroups       = new MapLua.SaveLua.Army.UnitsGroup[RegisteredGroup.UnitGroups.Count];
     RegisteredGroup.UnitGroups.CopyTo(AllGroups);
 }