Exemplo n.º 1
0
        public void Delete(PO_Object obj)
        {
            var poList    = tPOLogic.GetField("proceduralObjects", flags).GetValue(POLogic);
            var poSelList = tPOLogic.GetField("pObjSelection", flags).GetValue(POLogic);

            if (obj.isGroupRoot())
            {
                DeleteGroup(obj.Group);
            }

            poList.GetType().GetMethod("Remove", flags, null, new Type[] { tPO }, null).Invoke(poList, new object[] { obj.GetProceduralObject() });
            poSelList.GetType().GetMethod("Remove", flags, null, new Type[] { tPO }, null).Invoke(poSelList, new object[] { obj.GetProceduralObject() });
            if (tPOLogic.GetField("activeIds", flags) != null)
            {
                var activeIds = tPOLogic.GetField("activeIds", flags).GetValue(POLogic);
                activeIds.GetType().GetMethod("Remove", flags, null, new Type[] { typeof(int) }, null).Invoke(activeIds, new object[] { obj.ProcId });
            }
        }
Exemplo n.º 2
0
        public IEnumerator <object> RetrieveClone(MoveableProc original, Vector3 position, float angle, Action action)
        {
            const uint      MaxAttempts = 100_000;
            CloneActionBase ca          = (CloneActionBase)action;
            Single          halfWidth   = 4f;

            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 };
            if (tPO.GetField("halfOverlayDiam") != null) // Get the halfWidth, if it exists
            {
                halfWidth = Math.Max((float)tPO.GetField("halfOverlayDiam").GetValue(originalObject), 2f);
            }
            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 (tPO.GetField("halfOverlayDiam") != null) // Set the halfWidth, if it exists
                {
                    tPO.GetField("halfOverlayDiam").SetValue(clone.GetProceduralObject(), halfWidth);
                }

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