public static void GetMountedComponents(MyComponentList addToList, MyObjectBuilder_CubeBlock block) { int topGroupIndex = 0; int topComponentIndex = 0; MyCubeBlockDefinition blockDefinition = null; MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDefinition); if ((blockDefinition != null) && (block != null)) { float integrity = block.IntegrityPercent * blockDefinition.MaxIntegrity; CalculateIndicesInternal(integrity, blockDefinition, ref topGroupIndex, ref topComponentIndex); if ((topGroupIndex < blockDefinition.Components.Length) && (topComponentIndex < blockDefinition.Components[topGroupIndex].Count)) { int amount = topComponentIndex; if (integrity >= 1.525902E-05f) { amount++; } for (int i = 0; i < topGroupIndex; i++) { MyCubeBlockDefinition.Component component = blockDefinition.Components[i]; addToList.AddMaterial(component.Definition.Id, component.Count, component.Count, false); } MyDefinitionId myDefinitionId = blockDefinition.Components[topGroupIndex].Definition.Id; addToList.AddMaterial(myDefinitionId, amount, amount, false); } } }
private static void PasteChildComponent(GameObject gameObj, MyComponentList next) { if (next.gameObjList != null) { foreach (var copiedComponent in next.gameObjList) { if (!copiedComponent) { continue; } UnityEditorInternal.ComponentUtility.CopyComponent(copiedComponent); UnityEditorInternal.ComponentUtility.PasteComponentAsNew(gameObj); } } if (next.nextList != null) { List <Transform> TmpListTrans = new List <Transform>(); foreach (Transform item in gameObj.transform) { TmpListTrans.Add(item); } int i = 0; foreach (var item in next.nextList) { if (i < TmpListTrans.Count) { PasteChildComponent(TmpListTrans[i].gameObject, item); } i++; } } }
public static void DeepCopy(GameObject obj, GameObject target) { MyComponentList pri_my_list = new MyComponentList(); GetAllChilds(obj, ref pri_my_list); PasteChildComponent(target, pri_my_list); }
private static void GetMaterialsSimple(MyCubeBlockDefinition definition, MyComponentList output, int amount = 1) { for (int i = 0; i < definition.Components.Length; ++i) { var component = definition.Components[i]; output.AddMaterial(component.Definition.Id, component.Count * amount, i == 0 ? 1 : 0); } }
public static void GetMountedComponents(MyComponentList addToList, MyObjectBuilder_CubeBlock block) { int topGroup = 0; int topComponent = 0; MyCubeBlockDefinition blockDef = null; MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDef); Debug.Assert(blockDef != null, "Could not find block definition"); if (blockDef == null) { return; } Debug.Assert(block != null, "Getting mounted components of a null block"); if (block == null) { return; } float integrity = block.IntegrityPercent * blockDef.MaxIntegrity; CalculateIndicesInternal(integrity, blockDef, ref topGroup, ref topComponent); Debug.Assert(topGroup < blockDef.Components.Count(), "Component group overflow in CalculateItemRequirements"); if (topGroup >= blockDef.Components.Count()) { return; } Debug.Assert(topComponent < blockDef.Components[topGroup].Count, "Component overflow in CalculateItemRequirements"); if (topComponent >= blockDef.Components[topGroup].Count) { return; } int mountCount = topComponent; if (integrity >= MOUNT_THRESHOLD) { mountCount++; } MyDefinitionId componentId; for (int group = 0; group < topGroup; ++group) { MyCubeBlockDefinition.Component component = blockDef.Components[group]; addToList.AddMaterial(component.Definition.Id, component.Count, component.Count, addToDisplayList: false); } componentId = blockDef.Components[topGroup].Definition.Id; addToList.AddMaterial(componentId, mountCount, mountCount, addToDisplayList: false); }
private static void GetAllChilds(GameObject transformForSearch, ref MyComponentList next) { List <Component> childsOfGameobject = new List <Component>(); next.gameObjList = childsOfGameobject; next.nextList = new List <MyComponentList>(); foreach (var item in transformForSearch.GetComponents <Component>()) { childsOfGameobject.Add(item); } foreach (Transform item in transformForSearch.transform) { MyComponentList tmpnext = new MyComponentList(); GetAllChilds(item.gameObject, ref tmpnext); next.nextList.Add(tmpnext); } return; }