Exemple #1
0
        public void DestroyUnits(List <GameObject> MarkerObjects, bool RegisterUndo = true)
        {
            int Count = MarkerObjects.Count;

            if (RegisterUndo && MarkerObjects.Count > 0)
            {
                List <SaveLua.Army.UnitsGroup> AllGroups = new List <SaveLua.Army.UnitsGroup>();

                for (int i = 0; i < Count; i++)
                {
                    UnitInstance uinst = MarkerObjects[i].GetComponent <UnitInstance>();
                    if (!AllGroups.Contains(uinst.Owner.Parent))
                    {
                        AllGroups.Add(uinst.Owner.Parent);
                    }
                }
                Undo.RegisterUndo(new UndoHistory.HistoryUnitsRemove(), new UndoHistory.HistoryUnitsRemove.UnitsRemoveParam(AllGroups.ToArray()));
            }

            for (int i = 0; i < Count; i++)
            {
                //DestroyImmediate(MarkerObjects[i]);
                SaveLua.Army.Unit u = MarkerObjects[i].GetComponent <UnitInstance>().Owner;
                u.ClearInstance();
                if (u.Parent != null)
                {
                    u.Parent.RemoveUnit(u);
                }
            }

            SelectionManager.Current.CleanSelection();
            GoToSelection();
        }
Exemple #2
0
        public void ReplaceSelected()
        {
            if (FirstSelected == null)
            {
                ShowGroupError();

                return;
            }

            if (string.IsNullOrEmpty(SelectedUnit.CodeName))
            {
                ShowUnitError();
                return;
            }

            List <SaveLua.Army.UnitsGroup> AllGroups = new List <SaveLua.Army.UnitsGroup>();
            List <GameObject> AllObjects             = SelectionManager.GetAllSelectedGameobjects();
            int Count = AllObjects.Count;

            if (Count == 0)
            {
                return;
            }

            for (int i = 0; i < Count; i++)
            {
                UnitInstance uinst = AllObjects[i].GetComponent <UnitInstance>();
                if (!AllGroups.Contains(uinst.Owner.Parent))
                {
                    AllGroups.Add(uinst.Owner.Parent);
                }
            }
            Undo.RegisterUndo(new UndoHistory.HistoryUnitsRemove(), new UndoHistory.HistoryUnitsRemove.UnitsRemoveParam(AllGroups.ToArray()));


            Vector3[]    Positions = new Vector3[Count];
            Quaternion[] Rotations = new Quaternion[Count];
            Vector3[]    Scales    = new Vector3[Count];

            for (int i = 0; i < Count; i++)
            {
                UnitInstance uinst = AllObjects[i].GetComponent <UnitInstance>();

                Positions[i] = uinst.transform.position;
                Rotations[i] = uinst.transform.rotation;
                Scales[i]    = uinst.transform.localScale;

                SaveLua.Army.Unit u = uinst.Owner;

                u.ClearInstance();
                u.Parent.RemoveUnit(u);
            }

            Place(Positions, Rotations, Scales, false);
            GoToSelection();
        }