コード例 #1
0
        void OnGUI()
        {
            replaceMode = GUILayout.Toggle(replaceMode, "Replace");

            if (replaceMode)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("To be replaced: ");
                toBeReplaced = EditorGUILayout.TextArea(toBeReplaced);
                GUILayout.EndHorizontal();
                GUILayout.Space(10f);
            }

            iterationMode = GUILayout.Toggle(iterationMode, "Add iteration numbers");

            if (iterationMode)
            {
                GUILayout.BeginHorizontal();

                GUILayout.Label("Number string: ");
                iterationDigits = EditorGUILayout.IntField(iterationDigits);
                if (iterationDigits < 1)
                {
                    iterationDigits = 1;
                }

                GUILayout.Label("(" + FStringMethods.IntToString(1, iterationDigits) + ")");

                GUILayout.Label("Start from: ");
                iterationStartFrom = EditorGUILayout.IntField(iterationStartFrom);

                GUILayout.EndHorizontal();

                GUILayout.Space(10f);

                GUILayout.BeginHorizontal();
                GUILayout.Label("Prefix: ");
                iterationPrefix = EditorGUILayout.TextArea(iterationPrefix);

                GUILayout.Label("Suffix: ");
                iterationSuffix = EditorGUILayout.TextArea(iterationSuffix);

                GUILayout.EndHorizontal();
                GUILayout.Space(10f);
            }

            GUILayout.BeginHorizontal();
            GUILayout.Label("Target name: ");
            targetName = EditorGUILayout.TextArea(targetName);
            GUILayout.EndHorizontal();

            GUILayout.Space(10f);

            if (GUILayout.Button("Rename " + Selection.objects.Length + " objects!"))
            {
                RenameThem();
            }
        }
コード例 #2
0
        /// <summary>
        /// Checking if inside animator clipName state exist and with 'exactClipName' false it will check all variants of clipName, uppercase / lowercase etc.
        /// </summary>
        public void AddClip(Animator animator, string clipName, bool exactClipName = false)
        {
            if (!animator)
            {
                Debug.LogError("No animator!");
                return;
            }

            string existing = "";

            if (!exactClipName) // Checking if animation state exists with different variants for clipName word
            {
                if (FAnimatorMethods.StateExists(animator, clipName))
                {
                    existing = clipName;
                }
                else
                if (FAnimatorMethods.StateExists(animator, FStringMethods.CapitalizeFirstLetter(clipName)))
                {
                    existing = FStringMethods.CapitalizeFirstLetter(clipName);
                }
                else
                if (FAnimatorMethods.StateExists(animator, clipName.ToLower()))
                {
                    existing = clipName.ToLower();
                }
                else
                if (FAnimatorMethods.StateExists(animator, clipName.ToUpper()))
                {
                    existing = clipName.ToUpper();
                }
            }
            else // Checking if state with provided exact name exists inside animator
            {
                if (FAnimatorMethods.StateExists(animator, clipName))
                {
                    existing = clipName;
                }
            }

            if (existing == "")
            {
                Debug.LogWarning("Clip with name " + clipName + " not exists in animator from game object " + animator.gameObject.name);
            }
            else // Adding clip hash to dictionary if it exists inside animator
            {
                if (!ContainsKey(clipName))
                {
                    Add(clipName, Animator.StringToHash(existing));
                }
            }
        }
コード例 #3
0
        static void RenameThem()
        {
            if (Selection.objects.Length == 0)
            {
                Debug.LogError("No selected objects!");
                return;
            }

            Object[] objects = Selection.objects;

            GameObject gameObjectCheck = objects[0] as GameObject;
            int        i = iterationStartFrom;

            if (gameObjectCheck)
            {
                if (!replaceMode)
                {
                    foreach (GameObject o in objects)
                    {
                        o.name = targetName;
                        if (iterationMode)
                        {
                            o.name += iterationPrefix + FStringMethods.IntToString(i, iterationDigits) + iterationSuffix;
                        }
                        i++;
                    }
                }
                else
                {
                    foreach (GameObject o in objects)
                    {
                        o.name = o.name.Replace(toBeReplaced, targetName);
                        if (iterationMode)
                        {
                            o.name += iterationPrefix + FStringMethods.IntToString(i, iterationDigits) + iterationSuffix;
                        }
                        i++;
                    }
                }
            }
            else
            {
                foreach (Object o in objects)
                {
                    string newName = o.name;

                    if (!replaceMode)
                    {
                        newName = targetName;

                        // We need to add iteration because there can be conflicts with same file names

                        if (!iterationMode)
                        {
                            newName += FStringMethods.IntToString(i, iterationDigits);
                        }
                        else
                        {
                            newName += iterationPrefix + FStringMethods.IntToString(i, iterationDigits) + iterationSuffix;
                        }

                        i++;
                    }
                    else
                    {
                        newName = newName.Replace(toBeReplaced, targetName);

                        if (iterationMode)
                        {
                            newName += iterationPrefix + FStringMethods.IntToString(i, iterationDigits) + iterationSuffix;
                        }
                        i++;
                    }

                    AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(o), newName);
                }
            }
        }