コード例 #1
0
 /// <summary>
 /// Called whenever this graphic is attached to a specific group.  This method
 /// is only called at edit time!
 /// </summary>
 public virtual void OnAttachedToGroup(LeapGraphicGroup group, LeapSpaceAnchor anchor)
 {
     if (!Application.isPlaying)
     {
         _graphic._preferredRendererType = group.renderingMethod.GetType();
     }
 }
コード例 #2
0
        /// <summary>
        /// Called by the system to notify that a previous notification that this
        /// graphic would be attached has been cancelled due to a call to TryRemoveGraphic.
        /// </summary>
        public virtual void CancelWillBeAttached()
        {
            Assert.IsTrue(_willBeAttached);
            Assert.IsNotNull(_groupToBeAttachedTo);

            _willBeAttached      = false;
            _groupToBeAttachedTo = null;
        }
コード例 #3
0
        /// <summary>
        /// Called by the system to notify that this graphic will be attached within
        /// the next frame. This is only called at runtime.
        /// </summary>
        public virtual void NotifyWillBeAttached(LeapGraphicGroup toBeAttachedTo)
        {
            Assert.IsFalse(_willBeAttached);
            Assert.IsNull(_groupToBeAttachedTo);

            _willBeAttached      = true;
            _groupToBeAttachedTo = toBeAttachedTo;
        }
コード例 #4
0
            /// <summary>
            /// Creates a new group for this graphic renderer, and assigns it the
            /// given rendering method.  This is an editor only api, as creating new
            /// groups cannot be done at runtime.
            /// </summary>
            public void CreateGroup(Type rendererType)
            {
                AssertHelper.AssertEditorOnly();
                Assert.IsNotNull(rendererType);

                var group = new LeapGraphicGroup(_renderer, rendererType);

                _renderer._selectedGroup = _renderer._groups.Count;
                _renderer._groups.Add(group);
            }
コード例 #5
0
 public override SupportInfo GetSupportInfo(LeapGraphicGroup group)
 {
     if (!group.renderingMethod.IsValidGraphic <LeapMeshGraphicBase>())
     {
         return(SupportInfo.Error("Blend shapes require a renderer that supports mesh graphics."));
     }
     else
     {
         return(SupportInfo.FullSupport());
     }
 }
コード例 #6
0
        /// <summary>
        /// Tries to add the given graphic to any group attached to this graphic.  First, it
        /// will try to be attached to a group that has its preferred renderer type, and if
        /// there are multiple such groups it will choose the group with the smallest graphic
        /// count.
        ///
        /// If no group has the preferred renderer type, it will try to attach to a group
        /// that supports this type of graphic, again choosing the group with the smallest
        /// graphic count.
        ///
        /// If no such group is found, the attach will fail and this method will return false.
        /// </summary>
        public bool TryAddGraphic(LeapGraphic graphic)
        {
            LeapGraphicGroup targetGroup = null;

            //First try to attatch to a group that is preferred
            Type preferredType = graphic.preferredRendererType;

            if (preferredType != null)
            {
                foreach (var group in groups)
                {
                    Type rendererType = group.renderingMethod.GetType();
                    if (preferredType == rendererType || rendererType.IsSubclassOf(preferredType))
                    {
                        if (targetGroup == null || group.toBeAttachedCount < targetGroup.toBeAttachedCount)
                        {
                            targetGroup = group;
                        }
                    }
                }
            }

            if (targetGroup != null && targetGroup.TryAddGraphic(graphic))
            {
                return(true);
            }

            //If we failed, try to attach to a group that will take us
            foreach (var group in groups)
            {
                if (group.renderingMethod.IsValidGraphic(graphic))
                {
                    if (targetGroup == null || group.toBeAttachedCount < targetGroup.toBeAttachedCount)
                    {
                        targetGroup = group;
                    }
                }
            }

            if (targetGroup != null && targetGroup.TryAddGraphic(graphic))
            {
                return(true);
            }

            return(false);
        }
コード例 #7
0
        public override SupportInfo GetSupportInfo(LeapGraphicGroup group)
        {
            foreach (var feature in group.features)
            {
                if (feature == this)
                {
                    continue;
                }

                var channelFeature = feature as ICustomChannelFeature;
                if (channelFeature != null && channelFeature.channelName == channelName)
                {
                    return(SupportInfo.Error("Cannot have two custom channels with the same name."));
                }
            }

            return(SupportInfo.FullSupport());
        }
コード例 #8
0
        /// <summary>
        /// Called by the system when this graphic is attached to a group.  This method is
        /// invoked both at runtime and at edit time.
        /// </summary>
        public virtual void OnAttachedToGroup(LeapGraphicGroup group, LeapSpaceAnchor anchor)
        {
#if UNITY_EDITOR
            editor.OnAttachedToGroup(group, anchor);
#endif
            _willBeAttached      = false;
            _groupToBeAttachedTo = null;

            _attachedRenderer   = group.renderer;
            _attachedGroupIndex = _attachedRenderer.groups.IndexOf(group);
            _anchor             = anchor;

            patchReferences();

            if (OnAttachedToGroupEvent != null)
            {
                OnAttachedToGroupEvent(group);
            }
        }
コード例 #9
0
        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);
        }
コード例 #10
0
 public EditorApi(LeapGraphicGroup group)
 {
     _group = group;
 }
コード例 #11
0
ファイル: LeapGraphicRenderer.cs プロジェクト: ccdump/Paint-1
        /// <summary>
        /// Tries to add the given graphic to any group attached to this graphic.  First, it
        /// will try to be attached to a group that has its preferred renderer type, and if
        /// there are multiple such groups it will choose the group with the smallest graphic
        /// count.
        ///
        /// If no group has the preferred renderer type, it will try to attach to a group
        /// that supports this type of graphic, again choosing the group with the smallest
        /// graphic count.
        ///
        /// If no such group is found, the attach will fail and this method will return false.
        /// </summary>
        public bool TryAddGraphic(LeapGraphic graphic)
        {
            LeapGraphicGroup targetGroup = null;

            //First just try to attach to a group that is its favorite
            foreach (var group in groups)
            {
                if (group.name == graphic.favoriteGroupName)
                {
                    if (group.TryAddGraphic(graphic))
                    {
                        return(true);
                    }
                }
            }

            //Then try to attatch to a group that is of the preferred type
            //Choose the preferred group with the least graphics
            Type preferredType = graphic.preferredRendererType;

            if (preferredType != null)
            {
                foreach (var group in groups)
                {
                    Type rendererType = group.renderingMethod.GetType();
                    if (preferredType == rendererType ||
                        rendererType.IsSubclassOf(preferredType))
                    {
                        if (targetGroup == null || group.toBeAttachedCount < targetGroup.toBeAttachedCount)
                        {
                            targetGroup = group;
                        }
                    }
                }
            }

            if (targetGroup != null && targetGroup.TryAddGraphic(graphic))
            {
                return(true);
            }

            //If we failed, just try to attach to any group that will take us
            foreach (var group in groups)
            {
                if (group.renderingMethod.IsValidGraphic(graphic))
                {
                    if (targetGroup == null || group.toBeAttachedCount < targetGroup.toBeAttachedCount)
                    {
                        targetGroup = group;
                    }
                }
            }

            if (targetGroup != null && targetGroup.TryAddGraphic(graphic))
            {
                return(true);
            }

            //Unable to find any group that would accept the graphic :(
            return(false);
        }
コード例 #12
0
        /// <summary>
        /// Called by the system to notify that this graphic will be detached within
        /// the next frame. This is only called at runtime.
        /// </summary>
        public virtual void NotifyWillBeDetached(LeapGraphicGroup toBeDetachedFrom)
        {
            Assert.IsFalse(_willBeDetached);

            _willBeDetached = true;
        }
コード例 #13
0
 public virtual SupportInfo GetSupportInfo(LeapGraphicGroup group)
 {
     return(SupportInfo.FullSupport());
 }
コード例 #14
0
        protected void drawScriptAndGroupGui(LeapGraphicGroup mainGroup)
        {
            using (new GUILayout.HorizontalScope()) {
                drawScriptField();

                Color originalColor = GUI.color;
                try {
                    string buttonText;
                    if (!targets.Query().All(g => g.attachedGroup == mainGroup))
                    {
                        buttonText = "-";
                    }
                    else if (mainGroup == null)
                    {
                        buttonText = "None";
                        GUI.color  = Color.yellow;
                    }
                    else
                    {
                        buttonText = mainGroup.name;
                    }

                    var renderer = targets.Query().
                                   Select(t => t.GetComponentInParent <LeapGraphicRenderer>()).
                                   UniformOrDefault();

                    if (GUILayout.Button(buttonText, EditorStyles.miniButton, GUILayout.Width(60)))
                    {
                        GenericMenu groupMenu = new GenericMenu();
                        groupMenu.AddItem(new GUIContent("None"), false, () => {
                            foreach (var graphic in targets)
                            {
                                serializedObject.ApplyModifiedProperties();
                                graphic.TryDetach();

                                EditorUtility.SetDirty(graphic);

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

                        if (renderer != null)
                        {
                            int index = 0;
                            foreach (var group in 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)
                                    {
                                        if (!graphic.isAttachedToGroup)
                                        {
                                            continue;
                                        }

                                        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.isAttachedToGroup)
                                        {
                                            if (graphic.TryDetach())
                                            {
                                                group.TryAddGraphic(graphic);
                                            }
                                        }
                                        else
                                        {
                                            group.TryAddGraphic(graphic);
                                        }

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

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

                                    renderer.editor.ScheduleRebuild();
                                });
                                index++;
                            }
                        }

                        groupMenu.ShowAsContext();
                    }
                } finally {
                    GUI.color = originalColor;
                }
            }
        }
コード例 #15
0
        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();
            }
        }