public void Paste(InstanceID original, InstanceID target, int id) { InstanceID cloneID = target; cloneID.NetLane = (uint)id + 1; MoveItTool.PO.visibleObjects.Add(cloneID.NetLane, GetPOById((uint)id + 1)); MoveableProc cloneInstance = new MoveableProc(cloneID) { }; Action.selection.Add(cloneInstance); if (ActionQueue.instance.current is CloneActionBase ca) { ca.m_clones.Add(cloneInstance); ca.m_origToClone.Add(new MoveableProc(original), cloneInstance); } else { Log.Debug($"Current action is {ActionQueue.instance.current.GetType()}, not CloneActionBase"); } MoveItTool.SetToolState(); MoveItTool.instance.ProcessSensitivityMode(false); Log.Info($"Cloned PO {original.NetLane} to #{cloneInstance.id.NetLane} (new method)"); }
public IEnumerator <object> RetrieveClone(MoveableProc original, Vector3 position, float angle, Action action) { const uint MaxAttempts = 1000_000; CloneAction ca = (CloneAction)action; Type[] types = new Type[] { tPO, tPO.MakeByRefType(), typeof(uint).MakeByRefType() }; object[] paramList = new[] { original.m_procObj.GetProceduralObject(), null, null }; MethodInfo retrieve = tPOMoveIt.GetMethod("TryRetrieveClone", BindingFlags.Public | BindingFlags.Static, null, types, null); uint c = 0; while (c < MaxAttempts && !(bool)retrieve.Invoke(null, paramList)) { //if (c % 100 == 0) //{ // BindingFlags f = BindingFlags.Static | BindingFlags.Public; // object queueObj = tPOMoveIt.GetField("queuedCloning", f).GetValue(null); // int queueCount = (int)queueObj.GetType().GetProperty("Count").GetValue(queueObj, null); // object doneObj = tPOMoveIt.GetField("doneCloning", f).GetValue(null); // int doneCount = (int)doneObj.GetType().GetProperty("Count").GetValue(doneObj, null); //} c++; yield return(new WaitForSeconds(0.05f)); } if (c == MaxAttempts) { throw new Exception($"Failed to clone object #{original.m_procObj.Id}! [PO-F4]"); } PO_Object clone = new PO_Object(paramList[1]) { POColor = original.m_procObj.POColor }; InstanceID cloneID = default; cloneID.NetLane = clone.Id; MoveItTool.PO.visibleObjects.Add(cloneID.NetLane, clone); MoveableProc cloneInstance = new MoveableProc(cloneID) { position = position, angle = angle }; Action.selection.Add(cloneInstance); ca.m_clones.Add(cloneInstance); ca.m_origToClone.Add(original, cloneInstance); MoveItTool.SetToolState(); MoveItTool.instance.ProcessSensitivityMode(false); yield return(new WaitForSeconds(0.25f)); Debug.Log($"Cloned PO {original.m_procObj.Id} to #{clone.Id}"); MoveItTool.POProcessing--; }
internal void Clone(MoveableProc original, Vector3 position, float angle, Action action) { if (!Enabled) { return; } Logic.Clone(original, position, angle, action); }
public IEnumerator <object> RetrieveClone(uint originalId, Vector3 position, float angle, Action action) { const uint MaxAttempts = 1000_000; var original = GetPOById(originalId).GetProceduralObject(); Type[] types = new Type[] { tPO, tPO.MakeByRefType(), typeof(uint).MakeByRefType() }; object[] paramList = new[] { original, null, null }; MethodInfo retrieve = tPOMoveIt.GetMethod("TryRetrieveClone", BindingFlags.Public | BindingFlags.Static, null, types, null); uint c = 0; while (c < MaxAttempts && !(bool)retrieve.Invoke(null, paramList)) { if (c % 100 == 0) { BindingFlags f = BindingFlags.Static | BindingFlags.Public; object queueObj = tPOMoveIt.GetField("queuedCloning", f).GetValue(null); int queueCount = (int)queueObj.GetType().GetProperty("Count").GetValue(queueObj, null); object doneObj = tPOMoveIt.GetField("doneCloning", f).GetValue(null); int doneCount = (int)doneObj.GetType().GetProperty("Count").GetValue(doneObj, null); } c++; yield return(new WaitForSeconds(0.05f)); } if (c == MaxAttempts) { throw new Exception($"Failed to clone object #{originalId}! [PO-F4]"); } IPO_Object clone = new PO_ObjectEnabled(paramList[1]); InstanceID cloneID = default; cloneID.NetLane = clone.Id; MoveItTool.PO.visibleObjects.Add(cloneID.NetLane, clone); MoveableProc cloneInstance = new MoveableProc(cloneID) { position = position, angle = angle }; Action.selection.Add(cloneInstance); ((CloneAction)action).m_clones.Add(cloneInstance); //MoveItTool.PO.SelectionAdd(cloneInstance); MoveItTool.instance.ToolState = MoveItTool.ToolStates.Default; yield return(new WaitForSeconds(0.25f)); Debug.Log($"Cloned {originalId} to #{clone.Id}"); MoveItTool.POProcessing = false; }
public override void Do() { if (!firstRun) { return; // TODO this disables Redo } m_clones.Clear(); m_oldSelection = new HashSet <Instance>(selection); //string msg = "Selection\n"; //foreach (Instance i in m_oldSelection) //{ // msg += $"{i.id.Prop}:{i.Info.Name}\n"; //} //Debug.Log(msg); //Debug.Log($"state: {MoveItTool.instance.ToolState}"); //if (MoveItTool.instance.ToolState != MoveItTool.ToolStates.Default) //{ // return; //} foreach (InstanceState instanceState in m_states) { Instance instance = instanceState.instance; if (!((instance is MoveableBuilding || instance is MoveableProp) || !instance.isValid)) { continue; } IPO_Object obj = MoveItTool.PO.ConvertToPO(instance); if (obj == null) { continue; } MoveItTool.PO.visibleObjects.Add(obj.Id, obj); InstanceID instanceID = default(InstanceID); instanceID.NetLane = obj.Id; MoveableProc mpo = new MoveableProc(instanceID); m_clones.Add(mpo); mpo.angle = instance.angle; mpo.position = instance.position; selection.Add(mpo); selection.Remove(instance); instance.Delete(); } }
public void DoImplementation() { if (!firstRun) { return; // Disables Redo } m_clones.Clear(); m_oldSelection = new HashSet <Instance>(); foreach (InstanceState instanceState in m_states) { Instance instance = instanceState.instance; lock (instance.data) { if (!instance.isValid) { continue; } if (!(instance is MoveableBuilding || instance is MoveableProp)) { m_oldSelection.Add(instance); continue; } IPO_Object obj = MoveItTool.PO.ConvertToPO(instance); if (obj == null) { continue; } MoveItTool.PO.visibleObjects.Add(obj.Id, obj); InstanceID instanceID = default; instanceID.NetLane = obj.Id; MoveableProc mpo = new MoveableProc(instanceID); m_clones.Add(mpo); mpo.angle = instance.angle; mpo.position = instance.position; selection.Add(mpo); selection.Remove(instance); instance.Delete(); } } MoveItTool.m_debugPanel.UpdatePanel(); }
internal void MapGroupClones(HashSet <InstanceState> m_states, CloneActionBase action) { action.m_POGroupMap = new Dictionary <PO_Group, PO_Group>(); foreach (InstanceState state in m_states) { if (state is ProcState poState) { MoveableProc mpo = (MoveableProc)poState.instance; if (mpo.m_procObj.Group is null) { continue; } if (!action.m_POGroupMap.ContainsKey(mpo.m_procObj.Group)) { action.m_POGroupMap.Add(mpo.m_procObj.Group, new PO_Group()); } } } }
public IEnumerator <object> RetrieveClone(MoveableProc original, Vector3 position, float angle, Action action) { const uint MaxAttempts = 100_000; CloneActionBase ca = (CloneActionBase)action; if (!(original.m_procObj is PO_Object)) { Log.Info($"PO Cloning failed: object not found"); MoveItTool.POProcessing--; yield break; } Type[] types = new Type[] { tPO, tPO.MakeByRefType(), typeof(uint).MakeByRefType() }; object originalObject = original.m_procObj.GetProceduralObject(); object[] paramList = new[] { originalObject, null, null }; MethodInfo retrieve = tPOMoveIt.GetMethod("TryRetrieveClone", BindingFlags.Public | BindingFlags.Static, null, types, null); if (retrieve == null) { Log.Info($"PO Cloning failed: retrieve not found"); MoveItTool.POProcessing--; yield break; } uint c = 0; while (c < MaxAttempts && !(bool)retrieve.Invoke(null, paramList)) { //if (c % 100 == 0) //{ // BindingFlags f = BindingFlags.Static | BindingFlags.Public; // object queueObj = tPOMoveIt.GetField("queuedCloning", f).GetValue(null); // int queueCount = (int)queueObj.GetType().GetProperty("Count").GetValue(queueObj, null); // object doneObj = tPOMoveIt.GetField("doneCloning", f).GetValue(null); // int doneCount = (int)doneObj.GetType().GetProperty("Count").GetValue(doneObj, null); //} c++; yield return(new WaitForSeconds(0.05f)); } if (c == MaxAttempts) { throw new Exception($"Failed to clone object #{original.m_procObj.Id}! [PO-F4]"); } try { PO_Object clone = new PO_Object(paramList[1]) { POColor = original.m_procObj.POColor }; if (original.m_procObj.Group != null && action is CloneActionBase cloneAction) { if (!cloneAction.m_POGroupMap.ContainsKey(original.m_procObj.Group)) { Log.Debug($"Clone Error: {original.m_procObj.Id}'s group isn't in group map"); } else { clone.Group = cloneAction.m_POGroupMap[original.m_procObj.Group]; clone.Group.AddObject(clone); if (original.m_procObj.isGroupRoot()) { clone.Group.SetNewRoot(clone); } } } InstanceID cloneID = default; cloneID.NetLane = clone.Id; MoveItTool.PO.visibleObjects.Add(cloneID.NetLane, clone); MoveableProc cloneInstance = new MoveableProc(cloneID) { position = position, angle = angle }; Action.selection.Add(cloneInstance); ca.m_clones.Add(cloneInstance); ca.m_origToClone.Add(original, cloneInstance); MoveItTool.SetToolState(); MoveItTool.instance.ProcessSensitivityMode(false); Log.Info($"Cloned PO {original.m_procObj.Id} to #{clone.Id}"); } catch (Exception e) { Log.Error($"Exception when cloning PO:\n{e}"); } yield return(new WaitForSeconds(0.25f)); MoveItTool.POProcessing--; }
//public uint Clone(ProcState original, Vector3 position, float angle) //{ // // Create an empty PO object that integration will manipulate // //PrefabInfo prefab = PrefabCollection<BuildingInfo>.FindLoaded(original.prefabName); // //if (prefab is null) // //{ // // prefab = PrefabCollection<PropInfo>.FindLoaded(original.prefabName); // //} // object raw = tPOLogic.Assembly.CreateInstance("ProceduralObjects.Classes.ProceduralObject"); // int id = (int)tPUtils.GetMethod("GetNextUnusedId").Invoke(null, new[] { tPOLogic.GetField("proceduralObjects").GetValue(POLogic) }); // tPO.GetField("id").SetValue(raw, id); // object POlist = tPOLogic.GetField("proceduralObjects").GetValue(POLogic); // POlist.GetType().GetMethod("Add", new Type[] { tPO }).Invoke(POlist, new[] { raw }); // return (uint)id + 1; //} public void Clone(MoveableProc original, Vector3 position, float angle, Action action) { MoveItTool.POProcessing++; tPOMoveIt.GetMethod("CallPOCloning", new Type[] { tPO }).Invoke(null, new[] { original.m_procObj.GetProceduralObject() }); StartCoroutine(RetrieveClone(original, position, angle, action)); }
public override void Do() { if (!firstRun) { return; // Disables Redo } m_clones.Clear(); m_oldSelection = new HashSet <Instance>(); foreach (InstanceState instanceState in m_states) { Instance instance = instanceState.instance; lock (instance.data) { if (!instance.isValid) { continue; } if (!(instance is MoveableBuilding || instance is MoveableProp)) { m_oldSelection.Add(instance); continue; } PO_Object obj = null; try { obj = MoveItTool.PO.ConvertToPO(instance); if (obj == null) { continue; } MoveItTool.PO.visibleObjects.Add(obj.Id, obj); } catch (ArgumentException e) { string s = ""; foreach (var kv in MoveItTool.PO.visibleObjects) { s += $"{kv.Key}, "; } Log.Debug($"ArgumentException:\n{e}\n\n{(obj == null ? "<null>" : obj.Id.ToString())}\n\n{MoveItTool.PO.visibleObjects.Count}: {s}"); } InstanceID instanceID = default; instanceID.NetLane = obj.Id; MoveableProc mpo = new MoveableProc(instanceID); m_clones.Add(mpo); mpo.angle = instance.angle; mpo.position = instance.position; selection.Add(mpo); selection.Remove(instance); instance.Delete(); } } MoveItTool.m_debugPanel.UpdatePanel(); }