Esempio n. 1
0
            public GraphicInfo(GameObject obj)
            {
                var graphic = obj.GetComponent <LeapGraphic>();

                hasFired       = true;
                _wasAttached   = graphic.isAttachedToGroup;
                _attachedGroup = graphic.attachedGroup;
            }
        /// <summary>
        /// Should be called at the start of the test.  The argument is
        /// the name of the prefab to spawn, or the name of a gameobject
        /// in the current scene to load.  This object should have a
        /// graphic renderer component attached to the root.
        ///
        /// This method will automatically populate the following fields:
        ///  - renderer : with the reference to the renderer on the base of the prefab
        ///  - oneGraphic : with a reference to one graphic that exists in the prefab, if any
        ///  - firstGroup : the first group attached to the renderer
        ///  - secondGroup : the second group attached to the renderer, if any
        /// </summary>
        protected override void InitTest(string objectName)
        {
            base.InitTest(objectName);

            renderer = testObj.GetComponent <LeapGraphicRenderer>();

            oneGraphic = renderer.GetComponentInChildren <LeapGraphic>(includeInactive: true);

            firstGroup = renderer.groups[0];

            secondGroup = renderer.groups.Count > 1 ? renderer.groups[1] : null;
        }
Esempio n. 3
0
        IEnumerator ChangeSpacesCoroutine(LeapGraphicRenderer newRenderer)
        {
            // remove all graphics
            for (int i = 0; i < allGraphics.Length; i++)
            {
                if (allGraphics[i].attachedGroup != null)
                {
                    string attachedGroupName = allGraphics[i].attachedGroup.name;
                    bool   didRemove         = (allGraphics[i].attachedGroup != null) ? allGraphics[i].attachedGroup.TryRemoveGraphic(allGraphics[i]) : false;

                    if (!didRemove)
                    {
                        Debug.LogError("Tried to detach graphic: " + allGraphics[i].name + " from group " + attachedGroupName);
                    }
                }
                else
                {
                    //Debug.LogError("Couldn't detach graphic: " + allGraphics[i].name + " because it had no attached group.");
                }
            }

            transform.SetParent(newRenderer.transform);

            yield return(new WaitForEndOfFrame());

            for (int i = 0; i < allGraphics.Length; i++)
            {
                // find the render group by name
                LeapGraphicGroup group  = newRenderer.FindGroup(allGraphicsInfo[i].favoriteGroupName);
                bool             didAdd = group.TryAddGraphic(allGraphics[i]);
                if (!didAdd)
                {
                    Debug.LogError("Failed to attach graphic " + allGraphics[i].name + " to group " + group.name);
                }
            }

            if (SpaceChanged != null)
            {
                SpaceChanged(this, currentRenderer.gameObject, newRenderer.gameObject);
            }

            currentRenderer = newRenderer;
        }
        /// <summary>
        /// Should be called at the start of the test.  The argument is
        /// the name of the prefab to spawn, or the name of a gameobject
        /// in the current scene to load.  This object should have a
        /// graphic renderer component attached to the root.
        ///
        /// This method will automatically populate the following fields:
        ///  - renderer : with the reference to the renderer on the base of the prefab
        ///  - oneGraphic : with a reference to one graphic that exists in the prefab, if any
        ///  - firstGroup : the first group attached to the renderer
        ///  - secondGroup : the second group attached to the renderer, if any
        /// </summary>
        protected void InitTest(string objectName)
        {
            GameObject obj = null;

            for (int i = 0; i < SceneManager.sceneCount; i++)
            {
                var scene = SceneManager.GetSceneAt(i);

                obj = scene.GetRootGameObjects().
                      Query().
                      FirstOrDefault(g => g.name == objectName);

                if (obj != null)
                {
                    obj.SetActive(true);
                    break;
                }
            }

            if (obj == null)
            {
                var prefab = EditorResources.Load <GameObject>(objectName);

                if (prefab == null)
                {
                    throw new Exception("Could not find an object or prefab with the name " + objectName);
                }

                obj = UnityEngine.Object.Instantiate(prefab);
            }

            renderer = obj.GetComponent <LeapGraphicRenderer>();

            oneGraphic = renderer.GetComponentInChildren <LeapGraphic>(includeInactive: true);

            firstGroup = renderer.groups[0];

            secondGroup = renderer.groups.Count > 1 ? renderer.groups[1] : null;
        }
    public override void OnInspectorGUI()
    {
        LeapGraphicGroup mainGroup   = null;
        LeapGraphicGroup sharedGroup = null;

        if (targets.Query().All(g => g.isAttachedToGroup))
        {
            var mainRenderer = targets[0].attachedGroup.renderer;
            if (targets.Query().All(g => g.attachedGroup.renderer == mainRenderer))
            {
                mainGroup = targets[0].attachedGroup;
                if (targets.Query().All(g => g.attachedGroup == mainGroup))
                {
                    sharedGroup = mainGroup;
                }
            }
        }

        drawScriptAndGroupGui(mainGroup);

        base.OnInspectorGUI();

        drawFeatureData(sharedGroup);
    }
    protected void drawScriptAndGroupGui(LeapGraphicGroup mainGroup)
    {
        using (new GUILayout.HorizontalScope()) {
            drawScriptField();

            if (mainGroup == null)
            {
                return;
            }

            string buttonText;
            if (!targets.Query().All(g => g.attachedGroup == mainGroup))
            {
                buttonText = "-";
            }
            else
            {
                buttonText = mainGroup.name;
            }

            if (GUILayout.Button(buttonText, EditorStyles.miniButton, GUILayout.Width(60)))
            {
                GenericMenu groupMenu = new GenericMenu();
                int         index     = 0;
                foreach (var group in mainGroup.renderer.groups.Query().Where(g => g.renderingMethod.IsValidGraphic(targets[0])))
                {
                    groupMenu.AddItem(new GUIContent(index.ToString() + ": " + group.name), false, () => {
                        bool areFeaturesUnequal = false;
                        var typesA = group.features.Query().Select(f => f.GetType()).ToList();
                        foreach (var graphic in targets)
                        {
                            var typesB = graphic.attachedGroup.features.Query().Select(f => f.GetType()).ToList();
                            //if (!Utils.AreEqualUnordered(typesA, typesB)) {
                            //  areFeaturesUnequal = true;
                            //  break;
                            //}
                        }

                        if (areFeaturesUnequal && LeapGraphicPreferences.promptWhenGroupChange)
                        {
                            if (!EditorUtility.DisplayDialog("Features Are Different!",
                                                             "The group you are moving to has a different feature set than the current group, " +
                                                             "this can result in data loss!  Are you sure you want to change group?",
                                                             "Continue",
                                                             "Cancel"))
                            {
                                return;
                            }
                        }

                        foreach (var graphic in targets)
                        {
                            serializedObject.ApplyModifiedProperties();
                            if (graphic.attachedGroup.TryRemoveGraphic(graphic))
                            {
                                group.TryAddGraphic(graphic);
                            }

                            EditorUtility.SetDirty(graphic);
                            EditorUtility.SetDirty(group.renderer);

                            serializedObject.SetIsDifferentCacheDirty();
                            serializedObject.Update();
                        }

                        mainGroup.renderer.editor.ScheduleRebuild();
                    });
                    index++;
                }
                groupMenu.ShowAsContext();
            }
        }
    }
    protected void drawFeatureData(LeapGraphicGroup sharedGroup)
    {
        using (new ProfilerSample("Draw Leap Gui Graphic Editor")) {
            if (targets.Length == 0)
            {
                return;
            }
            var mainGraphic = targets[0];

            if (mainGraphic.featureData.Count == 0)
            {
                return;
            }

            if (mainGraphic.attachedGroup != null)
            {
                SpriteAtlasUtil.ShowInvalidSpriteWarning(mainGraphic.attachedGroup.features);
            }

            int maxGraphics = LeapGraphicPreferences.graphicMax;
            if (targets.Query().Any(e => e.attachedGroup != null && e.attachedGroup.graphics.IndexOf(e) >= maxGraphics))
            {
                string noun         = targets.Length == 1 ? "This graphic" : "Some of these graphics";
                string rendererName = targets.Length == 1 ? "its renderer" : "their renderers";
                EditorGUILayout.HelpBox(noun + " may not be properly displayed because there are too many graphics on " + rendererName + ".  " +
                                        "Either lower the number of graphics or increase the maximum graphic count by visiting " +
                                        "Edit->Preferences.", MessageType.Warning);
            }

            //If we are not all attached to the same group we cannot show features
            if (!targets.Query().Select(g => g.attachedGroup).AllEqual())
            {
                return;
            }

            EditorGUILayout.Space();

            using (new GUILayout.HorizontalScope()) {
                EditorGUILayout.LabelField("Feature Data: ", EditorStyles.boldLabel);

                if (sharedGroup != null)
                {
                    var meshRendering = sharedGroup.renderingMethod as LeapMesherBase;
                    if (meshRendering != null && meshRendering.IsAtlasDirty && !EditorApplication.isPlaying)
                    {
                        if (GUILayout.Button("Refresh Atlas", GUILayout.MaxHeight(EditorGUIUtility.singleLineHeight)))
                        {
                            meshRendering.RebuildAtlas(new ProgressBar());
                            sharedGroup.renderer.editor.ScheduleRebuild();
                        }
                    }
                }
            }

            for (int i = 0; i < _featureTable.arraySize; i++)
            {
                var idIndex  = _featureTable.GetArrayElementAtIndex(i);
                var dataProp = MultiTypedListUtil.GetReferenceProperty(_featureList, idIndex);
                EditorGUILayout.LabelField(LeapGraphicTagAttribute.GetTagName(dataProp.type));

                if (mainGraphic.attachedGroup != null)
                {
                    currentFeature = mainGraphic.attachedGroup.features[i];
                }

                EditorGUI.indentLevel++;

                EditorGUILayout.PropertyField(dataProp, includeChildren: true);

                EditorGUI.indentLevel--;

                currentFeature = null;
            }

            serializedObject.ApplyModifiedProperties();
        }
    }