public static void ReparrentUnit(GameObject obj, int Type) { if (obj == null || FirstSelected == null) { return; } UnitInstance uinst = obj.GetComponent <UnitInstance>(); if (uinst == null) { return; } uinst.Owner.Parent.RemoveUnit(uinst.Owner); FirstSelected.Source.AddUnit(uinst.Owner); uinst.ArmyColor = uinst.Owner.Parent.Owner.ArmyColor; uinst.IsWreckage = FirstSelected.Source.IsWreckage ? 1 : 0; uinst.UpdateMatrix(); }
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) { List <OzoneDecals.OzoneDecal> TarmacInstances = new List <OzoneDecals.OzoneDecal>(); 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; TarmacInstances.Add(BP.Termac_Albedo.Obj); } 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; TarmacInstances.Add(BP.Termac_Normal.Obj); } UInst.Tarmacs = TarmacInstances.ToArray(); } UInst.UpdateMatrix(); AddInstance(UInst); return(UInst); }