예제 #1
0
        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))
            {
                Debug.Log($"PO Cloning failed: object not found");
                MoveItTool.POProcessing--;
                yield break;
            }

            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);

            if (retrieve == null)
            {
                Debug.Log($"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
                };

                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);
                Debug.Log($"Cloned PO {original.m_procObj.Id} to #{clone.Id}");
            }
            catch (Exception e)
            {
                Debug.Log($"Exception when cloning PO:\n{e}");
            }

            yield return(new WaitForSeconds(0.25f));

            MoveItTool.POProcessing--;
        }
예제 #2
0
        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();
        }