Friday, July 8, 2022
HomeGame Developmentunity - Find out how to make that if includeChildren is fake...

unity – Find out how to make that if includeChildren is fake to have the ability to verify every single particular person toggle of the include1 array of toggles?


The issue is within the loop when i set the includeChildren bool to false once more i am unable to then choose particular person toggles from the include1 array as a result of includeChildren set the include1[i] to false on a regular basis.

if(includeChildren)
                    {
                        include1[i] = true;
                    }
                    else
                    {
                        include1[i] = false;
                    }

                    include1[i] = EditorGUILayout.Toggle("Embrace Kids", include1[i], GUILayout.ExpandWidth(true));

The total script :

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing System.Linq;
utilizing UnityEditor;
utilizing UnityEngine;

public class RenameSelected : EditorWindow
{
    personal static readonly Vector2Int dimension = new Vector2Int(500, 500);
    personal string childrenPrefix;
    personal int startIndex;
    personal bool showPosition = false;
    personal bool includeChildren = false;
    personal bool[] include1;
    personal bool a = false;
    personal GameObject[] objects;
    personal Vector2 scrollPos;

    [MenuItem("GameObject/Rename Selected")]
    public static void Init()
    {
        EditorWindow window = GetWindow<RenameSelected>();
        window.minSize = dimension;
        window.maxSize = dimension;
    }

    personal void OnSelectionChange()
    {
        objects = Choice.gameObjects;
    }

    personal void OnEnable()
    {
        objects = Choice.gameObjects;
        include1 = new bool[objects.Length];
    }

    public void OnGUI()
    {
        GUILayout.Area(10);
        childrenPrefix = EditorGUILayout.TextField("Rename prefix", childrenPrefix);
        startIndex = EditorGUILayout.IntField("Begin index", startIndex);
        includeChildren = EditorGUILayout.Toggle("Embrace Kids", includeChildren);

        if (objects.Size == 0)
        {
            showPosition = false;
        }
        GUILayout.Area(20);
        EditorGUI.BeginChangeCheck();
        EditorGUILayout.GetControlRect(true, 16f, EditorStyles.foldout);
        Rect foldRect = GUILayoutUtility.GetLastRect();
        if (Occasion.present.sort == EventType.MouseUp && foldRect.Accommodates(Occasion.present.mousePosition))
        {
            showPosition = !showPosition;
            GUI.modified = true;
            Occasion.present.Use();
        }

        showPosition = EditorGUI.Foldout(foldRect, showPosition, "Objects");
        GUILayout.Area(2);

        if (showPosition)
        {
            EditorGUI.indentLevel++;

            scrollPos =
            EditorGUILayout.BeginScrollView(scrollPos);
            for (int i = 0; i < objects.Size; i++)
            {
                EditorGUIUtility.labelWidth = 50;

                EditorGUILayout.BeginHorizontal();
                {
                    GUILayoutOption[] choices = { GUILayout.MaxWidth(300.0f), GUILayout.MinWidth(300.0f) };
                    objects[i] = (GameObject)EditorGUILayout.ObjectField(i.ToString(), objects[i], typeof(GameObject), true, choices);
                    EditorGUIUtility.labelWidth = 112;
                    
                    if(includeChildren)
                    {
                        include1[i] = true;
                    }
                    else
                    {
                        include1[i] = false;
                    }

                    include1[i] = EditorGUILayout.Toggle("Embrace Kids", include1[i], GUILayout.ExpandWidth(true));
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndScrollView();

            EditorGUI.indentLevel--;
        }

        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Rename Objects"))
        {
            
        }

        Repaint();
    }
}

I attempted this too however the identical outcome i am unable to verify the toggle bins particular person in any respect :

if (includeChildren)
                    {
                        include1[i] = true;
                    }
                    else
                    {
                        if(include1[i] != false)
                        {
                            include1[i] = false;
                        }
                    }

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments