Exemple #1
0
        private static bool UnGroupGravityFieldsTest()
        {
            GameObject[] selected = Selection.gameObjects;
            if (selected.Length == 0)
            {
                return(false);
            }
            if (!ExtObjectEditor.AreGameObjectInSameScene(selected))
            {
                return(false);
            }
            AttractorGroup parentCommon = null;

            for (int i = 0; i < selected.Length; i++)
            {
                AttractorGroup parent = selected[i].GetComponentInParent <AttractorGroup>();
                if (parent == null)
                {
                    return(false);
                }
                //can't ungroup 2 GravityFieldsAction of 2 different group...
                if (parentCommon != null && parent != parentCommon)
                {
                    return(false);
                }

                parentCommon = parent;
            }
            return(true);
        }
 public static bool IsThereNullCustomObjectInList(this SerializedProperty list)
 {
     for (int i = 0; i < list.arraySize; i++)
     {
         if (ExtObjectEditor.IsTruelyNull(list.GetArrayElementAtIndex(i).GetCustomObject()))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #3
0
        private static void GroupGravityFields()
        {
            GameObject[] selected = Selection.gameObjects;
            if (selected.Length == 0)
            {
                return;
            }

            List <GameObject> selectedWithAttractor = new List <GameObject>(selected.Length);

            for (int i = 0; i < selected.Length; i++)
            {
                Attractor action = selected[i].GetComponentInChildren <Attractor>();
                if (action != null)
                {
                    selectedWithAttractor.Add(selected[i]);
                }
            }

            //first, do not group anything if one of them is already grouped
            for (int i = 0; i < selectedWithAttractor.Count; i++)
            {
                AttractorGroup parent = selectedWithAttractor[i].GetComponentInParent <AttractorGroup>();
                if (parent != null)
                {
                    return;
                }
            }

            Selection.activeGameObject = null;
            Transform commonParent = ExtObjectEditor.FindCommonParent(selectedWithAttractor, selectedWithAttractor[0].transform.parent);

            EditorGUIUtility.PingObject(commonParent);


            GameObject newParent = new GameObject("AttractorGroup");

            newParent.transform.position = ExtVector3.GetMeanOfXPoints(selectedWithAttractor.ToArray(), out Vector3 sizeBoundingBox, true);
            AttractorGroup newGroup = newParent.AddComponent <AttractorGroup>();

            //UnityEditor.Editor splineEditorGeneric = UnityEditor.Editor.CreateEditor(newGroup, typeof(GravityFieldsGroupEditor));
            //GravityFieldsGroupEditor groupEditor = (GravityFieldsGroupEditor)splineEditorGeneric;
            //groupEditor.FillGroupList(selectedWithGravityFieldsAction);

            SetupSiblingOfNewGroup(selectedWithAttractor, commonParent, newParent);


            ExtReflection.SetExpanded(newParent, true);
            ExtReflection.Rename(newParent);
        }
 /// <summary>
 /// Clean  null item (do not remove items, remove only the list)
 /// </summary>
 /// <param name="listToClean"></param>
 /// <returns>true if list changed</returns>
 public static void CleanNullFromList(SerializedProperty listToClean, ref bool hasChanged)
 {
     hasChanged = false;
     if (listToClean == null)
     {
         return;
     }
     for (int i = listToClean.arraySize - 1; i >= 0; i--)
     {
         if (ExtObjectEditor.IsTruelyNull(listToClean.GetArrayElementAtIndex(i).GetCustomObject()))
         {
             listToClean.RemoveAt(i);
             hasChanged = true;
         }
     }
 }
Exemple #5
0
        private static bool GroupGravityFieldsTest()
        {
            GameObject[] selected = Selection.gameObjects;
            //don't if nothing selected
            if (selected.Length == 0)
            {
                return(false);
            }
            if (!ExtObjectEditor.AreGameObjectInSameScene(selected))
            {
                return(false);
            }
            for (int i = 0; i < selected.Length; i++)
            {
                AttractorGroup parent = selected[i].GetComponentInParent <AttractorGroup>();
                if (parent != null)
                {
                    return(false);
                }
            }

            List <GameObject> selectedWithGravityFieldsAction = new List <GameObject>(selected.Length);

            for (int i = 0; i < selected.Length; i++)
            {
                Attractor action = selected[i].GetComponentInChildren <Attractor>();
                if (action != null)
                {
                    selectedWithGravityFieldsAction.Add(selected[i]);
                }
            }
            if (selectedWithGravityFieldsAction.Count == 0)
            {
                return(false);
            }

            return(true);
        }