Example #1
0
    void ReplaceObjectsByName(string name, bool isContain)
    {
        if (string.IsNullOrEmpty(name))
        {
            return;
        }
        List <ReplaceData> replaceDatas = new List <ReplaceData>();

        Transform[] all = Object.FindObjectsOfType <Transform>();
        foreach (var item in all)
        {
            //Debug.LogError(item.name);
            ReplaceData replaceData = new ReplaceData();
            replaceData.old = item.gameObject;
            if (!isContain && item.gameObject.name == name)
            {
                ReplaceOne(replaceData);
                replaceDatas.Add(replaceData);
            }
            else if (isContain && item.gameObject.name.Contains(name))
            {
                ReplaceOne(replaceData);
                replaceDatas.Add(replaceData);
            }
        }
        HandleReplaceData(replaceDatas);
    }
Example #2
0
 public static List <Object> ReplaceReferenceInProject(ReplaceData data)
 {
     return(ReplaceReferenceInProject(new List <ReplaceData>()
     {
         data
     }));
 }
Example #3
0
 public static List <Object> ReplaceReference(ReplaceData data, string[] paths)
 {
     return(ReplaceReference(new List <ReplaceData>()
     {
         data
     }, paths));
 }
Example #4
0
        private void VerifyReplace(VimRegexOptions options, string pattern, string input, string replace, string result)
        {
            var regex = VimRegexFactory.Create(pattern, options);

            Assert.IsTrue(regex.IsSome());

            var noMagic     = VimRegexOptions.NoMagic == (options & VimRegexOptions.NoMagic);
            var replaceData = new ReplaceData(Environment.NewLine, !noMagic, 1);

            Assert.AreEqual(result, regex.Value.ReplaceAll(input, replace, replaceData));
        }
Example #5
0
        private void BtnAdd_Click(object sender, RoutedEventArgs e)
        {
            ReplaceData data = new ReplaceData()
            {
                From = "1", To = "1"
            };

            ReplaceDatas.Add(data);
            gridReplace.ItemsSource = null;
            gridReplace.ItemsSource = ReplaceDatas;
        }
Example #6
0
    public void ReplaceOne(ReplaceData replaceData)
    {
        GameObject replace = (GameObject)PrefabUtility.InstantiatePrefab(tonewPrefab);

        replace.transform.SetParent(replaceData.old.transform.parent);
        replace.transform.localPosition = replaceData.old.transform.localPosition;
        replace.transform.localRotation = replaceData.old.transform.localRotation;
        replace.transform.localScale    = replaceData.old.transform.localScale;
        replaceData.replace             = replace;
        replaceData.index = replaceData.old.transform.GetSiblingIndex();
    }
    public void Add(Shader shader, string name, string tag, RenderTexture rt)
    {
        var data = new ReplaceData
        {
            shader = shader,
            name   = name,
            tag    = tag,
            rt     = rt
        };

        _replacements.Add(data);
    }
 public void Render(ReplaceData replacement)
 {
     _cam.targetTexture = replacement.rt;
     if (!replacement.shader)
     {
         _cam.Render();
     }
     else
     {
         _cam.RenderWithShader(replacement.shader, replacement.tag);
     }
     _cam.targetTexture = null;
 }
Example #9
0
 private string GetStringFromData(ReplaceData data)
 {
     switch (data)
     {
         case ReplaceData.speedInKMH:
             const float msToKmh = 3.6f; // meters per second to kilometers per hour
             return System.Math.Round(Player.PlayerInfo.CurrentPlayer.Speed * msToKmh, 2).ToString("F0") + " km/h";
         case ReplaceData.speedInMS:
             return System.Math.Round(Player.PlayerInfo.CurrentPlayer.Speed, 2).ToString("F0") + " m/s";
         case ReplaceData.liftDragCf:
             return "L:" + System.Math.Round(Player.PlayerInfo.CurrentPlayer.LeftLiftCf, 2) + ", D:" + System.Math.Round(Player.PlayerInfo.CurrentPlayer.LeftDragCf, 2) + " | ...";
         default:
             return "error";
     }
 }
 private string GetStringFromData(ReplaceData data)
 {
     switch (data)
     {
         case ReplaceData.speedInKMH:
             const float msToKmh = 3.6f; // meters per second to kilometers per hour
             return System.Math.Round(Player.PlayerInfo.CurrentPlayer.Speed * msToKmh, 2).ToString("F0") + " km/h";
         case ReplaceData.speedInMS:
             return System.Math.Round(Player.PlayerInfo.CurrentPlayer.Speed, 2).ToString("F0") + " m/s";
         case ReplaceData.angleOfAttack:
             return System.Math.Round(Player.PlayerInfo.CurrentPlayer.LeftAngle, 2) + " | " + System.Math.Round(Player.PlayerInfo.CurrentPlayer.RightAngle, 2);
         default:
             return "error";
     }
 }
Example #11
0
    void ReplaceObjects()
    {
        if (tonewPrefab == null)
        {
            return;
        }
        Object[]           objects      = Selection.objects;
        List <ReplaceData> replaceDatas = new List <ReplaceData>();

        foreach (Object item in objects)
        {
            GameObject  temp        = (GameObject)item;
            ReplaceData replaceData = new ReplaceData();
            replaceData.old = temp;
            ReplaceOne(replaceData);
            replaceDatas.Add(replaceData);
        }
        HandleReplaceData(replaceDatas);
    }
Example #12
0
 private void InitDataIfNeeded()
 {
     if (!data)
     {
         data           = ScriptableObject.CreateInstance <ReplaceData>();
         serializedData = null;
     }
     // If data was not wrapped into SerializedObject, wrap it
     if (serializedData == null)
     {
         serializedData     = new SerializedObject(data);
         replaceObjectField = null;
     }
     // If prefab field was not assigned as SerializedProperty, assign it
     if (replaceObjectField == null)
     {
         replaceObjectField = serializedData.FindProperty("replacementPrefab");
     }
 }
Example #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Element"></param>
        /// <param name="Old"></param>
        /// <param name="New"></param>
        private void ReplaceDefinition(JObject Element, List <ReplaceData> Replace)
        {
            JToken Ref = Element["$ref"];

            if (Ref != null)
            {
                String Value = Ref.Value <String>();

                for (Int32 I = 0; I < Replace.Count; I++)
                {
                    ReplaceData Item = Replace[I];
                    if (Value == Item.Old)
                    {
                        Element["$ref"] = new JValue(Item.New);
                        break;
                    }
                }
            }

            var Names = new List <String>(Element.Count);

            foreach (KeyValuePair <String, JToken> Child in Element)
            {
                Names.Add(Child.Key);
            }

            for (Int32 I = 0; I < Names.Count; I++)
            {
                JToken Item = Element[Names[I]];

                if (Item is JObject JChild)
                {
                    this.ReplaceDefinition(JChild, Replace);
                }
                else if (Item is JArray A)
                {
                    this.ReplaceDefinition(A, Replace);
                }
            }
        }
Example #14
0
        private void VerifyReplace(VimRegexOptions options, string pattern, string input, string replace, string result)
        {
            var regex = VimRegexFactory.Create(pattern, options);
            Assert.IsTrue(regex.IsSome());

            var noMagic = VimRegexOptions.NoMagic == (options & VimRegexOptions.NoMagic);
            var replaceData = new ReplaceData(Environment.NewLine, !noMagic, 1);
            Assert.AreEqual(result, regex.Value.ReplaceAll(input, replace, replaceData));
        }
Example #15
0
        private static void ApplicationUpdate()
        {
            bool notComplete = listReplace.Where(x => x.Value.processIndex >= 0).Count() > 0;

            if (lstThreads.Count <= 0 && notComplete)
            {
                foreach (KeyValuePair <string, ProcessReplaceData> item in listReplace)
                {
                    if (item.Value.processIndex >= 0)
                    {
                        ReplaceData a = item.Value.datas[item.Value.processIndex--];
                        a.isTerrian = a.asset.type == FR2_AssetType.TERRAIN;
                        if (a.isTerrian)
                        {
                            a.terrainData =
                                AssetDatabase.LoadAssetAtPath(a.asset.assetPath, typeof(Object)) as TerrainData;
                        }

                        var thread = new Thread(
                            delegate()
                        {
                            lock (a)
                            {
                                a.isSucess = a.asset.ReplaceReference(a.from, a.to, a.terrainData);
                                // Debug.Log(a.asset.assetPath+" "+ a.isSucess);
                            }
                        });
                        lstThreads.Add(thread);
                        thread.Start();
                    }
                }
            }

            for (int i = lstThreads.Count - 1; i >= 0; i--)
            {
                if (!lstThreads[i].IsAlive)
                {
                    lstThreads.RemoveAt(i);
                }
            }

            foreach (KeyValuePair <string, ProcessReplaceData> item in listReplace)
            {
                List <ReplaceData> lst = item.Value.datas;
                for (var i = 0; i < lst.Count; i++)
                {
                    ReplaceData data = lst[i];
                    if (!data.isUpdated && data.isSucess)
                    {
                        data.isUpdated = true;
                        if (data.isTerrian)
                        {
                            EditorUtility.SetDirty(data.terrainData);
                            AssetDatabase.SaveAssets();
                            data.terrainData = null;
                            FR2_Unity.UnloadUnusedAssets();
                        }
                        else
                        {
                            AssetDatabase.ImportAsset(data.asset.assetPath, ImportAssetOptions.Default);
                        }
                    }
                }
            }


            if (lstThreads.Count <= 0 && !notComplete)             //complete
            {
                var guidsRefreshed = new HashSet <string>();
                EditorApplication.update -= ApplicationUpdate;
                foreach (KeyValuePair <string, ProcessReplaceData> item in listReplace)
                {
                    List <ReplaceData> lst = item.Value.datas;
                    for (var i = 0; i < lst.Count; i++)
                    {
                        ReplaceData data = lst[i];
                        if (data.isSucess && !guidsRefreshed.Contains(data.asset.guid))
                        {
                            guidsRefreshed.Add(data.asset.guid);
                            FR2_Cache.Api.RefreshAsset(data.asset.guid, true);
                        }
                    }
                }

                lstThreads  = null;
                listReplace = null;
                FR2_Cache.Api.RefreshSelection();
                FR2_Cache.Api.Check4Usage();
                // EditorUtility.SetDirty(FR2_Cache.Api);
                AssetDatabase.Refresh();
                IsMergeProcessing = false;
            }
        }
Example #16
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            PropertyDescriptor property        = context.DataContext.GetProperties()[ExcelCreate.GetExcelAppTag];
            Excel::Application excelApp        = property.GetValue(context.DataContext) as Excel::Application;
            string             cellName_Begin  = CellName_Begin.Get(context);
            string             cellName_End    = CellName_End.Get(context);
            int               cellRow_Begin    = CellRow_Begin.Get(context);
            int               cellColumn_Begin = CellColumn_Begin.Get(context);
            int               cellRow_End      = CellRow_End.Get(context);
            int               cellColumn_End   = CellColumn_End.Get(context);
            string            findData         = FindData.Get(context);
            string            replaceData      = ReplaceData.Get(context);
            object            obj = null;
            Excel::Range      range1, range2;
            Excel::_Worksheet sheet     = null;
            Excel::_Worksheet currSheet = null;

            Excel.XlLookAt lookAt = IsCellMatch ? Excel.XlLookAt.xlWhole : Excel.XlLookAt.xlPart;
            if (SheetName.Get(context) != null)
            {
                sheet = excelApp.ActiveWorkbook.Sheets[SheetName];
            }
            else
            {
                sheet = excelApp.ActiveSheet;
            }

            try
            {
                if (AllSheets)  //全部工作表
                {
                    int sheetCount = excelApp.ActiveWorkbook.Worksheets.Count;
                    for (int i = 1; i < sheetCount + 1; i++)
                    {
                        if (AllRange)
                        {
                            excelApp.ActiveWorkbook.Worksheets[i].Range["A1", "IV65535"].Replace(obj, replaceData, lookAt, Type.Missing, IsTextTransform, isSemiFull);
                        }
                        else
                        {
                            currSheet = excelApp.ActiveWorkbook.Worksheets[i];
                            range1    = cellName_Begin == null ? currSheet.Cells[cellRow_Begin, cellColumn_Begin] : currSheet.Range[cellName_Begin];
                            range2    = cellName_End == null ? currSheet.Cells[cellRow_End, cellColumn_End] : currSheet.Range[cellName_End];
                            currSheet.Range[range1, range2].Replace(findData, replaceData, lookAt, Type.Missing, IsTextTransform, isSemiFull);
                        }
                    }
                }
                else
                {
                    if (AllRange)    //全部区域
                    {
                        sheet.Range["A1", "IV65535"].Replace(findData, replaceData, lookAt, Type.Missing, IsTextTransform, isSemiFull);
                    }
                    else
                    {
                        range1 = cellName_Begin == null ? sheet.Cells[cellRow_Begin, cellColumn_Begin] : sheet.Range[cellName_Begin];
                        range2 = cellName_End == null ? sheet.Cells[cellRow_End, cellColumn_End] : sheet.Range[cellName_End];
                        sheet.Range[range1, range2].Replace(findData, replaceData, lookAt, Type.Missing, IsTextTransform, isSemiFull);
                    }
                }

                /* 资源回收释放 */
                System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet);
                sheet = null;
                if (currSheet != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(currSheet);
                    currSheet = null;
                }
                GC.Collect();
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "EXCEL查找替换过程出错", e.Message);
                new CommonVariable().realaseProcessExit(excelApp);
            }
            m_Delegate = new runDelegate(Run);
            return(m_Delegate.BeginInvoke(callback, state));
        }
Example #17
0
 private void OnEnable()
 {
     m_target = (ReplaceData)target;
 }