Esempio n. 1
0
 static public bool CheckIfRelated(SpritesAtlas a, SpritesAtlas b)
 {
     if (a == null || b == null)
     {
         return(false);
     }
     return(a == b || a.References(b) || b.References(a));
 }
Esempio n. 2
0
 bool References(SpritesAtlas atlas)
 {
     if (atlas == null)
     {
         return(false);
     }
     if (atlas == this)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 3
0
        void DrawAtlas()
        {
            EditorGUILayout.Space();
            ProjectorLight l = target as ProjectorLight;

            GUILayout.Label("Sprite");
            GUILayout.BeginVertical("box");
            GUILayout.BeginHorizontal();
            if (IFPipelineEditorTools.DrawPrefixButton("Atlas"))
            {
                ComponentSelector.Show <SpritesAtlas>(OnSelectAtlas);
            }
            SerializedProperty atlas = IFPipelineEditorTools.DrawProperty("", serializedObject, "spritesAtlas", GUILayout.MinWidth(20f));

            GUILayout.EndHorizontal();

            if (atlas != null)
            {
                SpritesAtlas atl = atlas.objectReferenceValue as SpritesAtlas;
                if (atl != null && atl != l.spritesAtlas)
                {
                    l.spritesAtlas = atl;
                }
                GUILayout.Label("Project Sprite");
                GUILayout.BeginHorizontal();
                SerializedProperty sp = serializedObject.FindProperty("mprojSpriteName");
                IFPipelineEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as SpritesAtlas, sp.stringValue, SelectProjSprite, false);
                GUILayout.EndHorizontal();
                GUILayout.Label("Falloff Sprite");
                GUILayout.BeginHorizontal();
                SerializedProperty spfalloff = serializedObject.FindProperty("mfalloffSpriteName");
                IFPipelineEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as SpritesAtlas, spfalloff.stringValue, SelectFalloffSprite, false);
                GUILayout.EndHorizontal();
            }
            else
            {
                l.mprojSpriteName    = "";
                l.mfalloffSpriteName = "";
                l.falloffSpriteData  = new SpriteData();
                l.projSpriteData     = new SpriteData();
                Tools.SetDirty(serializedObject.targetObject);
            }
            GUILayout.EndVertical();
        }
Esempio n. 4
0
        /// <summary>
        /// Show the sprite selection wizard.
        /// </summary>

        static public void Show(SerializedObject ob, SerializedProperty pro, SpritesAtlas atlas)
        {
            if (instance != null)
            {
                instance.Close();
                instance = null;
            }

            if (ob != null && pro != null && atlas != null)
            {
                SpriteSelector comp = ScriptableWizard.DisplayWizard <SpriteSelector>("Select a Sprite");
                IFPipelineSettings.atlas          = atlas;
                IFPipelineSettings.selectedSprite = pro.hasMultipleDifferentValues ? null : pro.stringValue;
                //comp.mSprite = null;
                comp.mObject   = ob;
                comp.mProperty = pro;
                comp.mCallback = comp.OnSpriteSelection;
            }
        }
Esempio n. 5
0
        override public void OnInspectorGUI()
        {
            SpritesAtlas atlas = target as SpritesAtlas;

            EditorGUILayout.Space();
            GUILayout.BeginVertical("box");

            Texture2D texture = EditorGUILayout.ObjectField("Atlas Texture", atlas.texture, typeof(Texture), false) as Texture2D;

            if (texture)
            {
                if (texture != atlas.texture)
                {
                    Undo.RecordObject(atlas, "Atlas Change");
                    atlas.texture = texture;
                    //atlas.ClearAtlas();
                }
                else
                {
                    Undo.RecordObject(atlas, "Import Sprites");
                    TextAsset text = EditorGUILayout.ObjectField("Sprite Import", null, typeof(TextAsset), false) as TextAsset;
                    if (text != null)
                    {
                        atlas.LoadAllAtlasEntryData(text);
                        EditorUtility.SetDirty(target);
                    }
                }
            }
            else
            {
                //atlas.ClearAtlas();
                atlas.texture = null;
            }
            GUILayout.EndVertical();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(target);
            }
        }
Esempio n. 6
0
        public void RebuildLightsList(List <VisibleLight> visibleLights, CameraData cameraData, PipelineSettings pipelineSettings, ref RenderingData renderingData)
        {
            UnityEngine.Profiling.Profiler.BeginSample("RebuildLightsList");
            lights.Clear();
            var unityLights = visibleLights;

            VisibleLight = 0;
            LightsDataForShadow.Clear();
            bool softShadow         = false;
            int  j                  = 0;
            int  currentShadowIndex = 0;
            int  maxShadowNum       = pipelineSettings.MaxShadowLightsNum;

            for (int i = 0; i < unityLights.Count; ++i)
            {
                var ul = unityLights[i];
                var pl = ul.light.GetComponent <ProjectorLight>();
                if (pl == null)
                {
                    continue;
                }
                lights.Add(pl);
                var ifLight = pl;
                if (ifLight.spritesAtlas != spritesAtlas)
                {
                    spritesAtlas = ifLight.spritesAtlas;
                }
                //矩阵是从右向左乘的,view需要z取反
                Matrix4x4 c2w         = /*Camera.main*/ cameraData.camera.cameraToWorldMatrix * Matrix4x4.Scale(new Vector3(1, 1, -1));// Camera.main.transform.localToWorldMatrix;
                int       shadowIndex = currentShadowIndex;
                if (currentShadowIndex >= maxShadowNum || !ifLight.lightParms_Shadow)
                {
                    shadowIndex = -1;
                }
                LightDataInAll lightDataInAll = ifLight.GetLightData(c2w, shadowIndex);
                NativeLightsBoundList[i] = lightDataInAll.sFiniteLightBound;
                NativeLightsDataList[i]  = lightDataInAll.lightData;
                ++VisibleLight;

                //for shadow
                // TODO  frustum cull
                if (ifLight.lightParms_Shadow && currentShadowIndex < maxShadowNum)
                {
                    LightDataForShadow lightDataForShadow = new LightDataForShadow();
                    lightDataForShadow.lightIndex      = j++;
                    lightDataForShadow.shadowData      = lightDataInAll.shadowData;
                    lightDataForShadow.visibleLight    = ul;
                    lightDataForShadow.projectorLight  = ifLight;
                    lightDataForShadow.unityLightIndex = i;

                    //Matrix4x4 scaleMatrix = Matrix4x4.identity;
                    ////scaleMatrix.m22 = -1.0f;
                    //Matrix4x4 view = scaleMatrix * ul.localToWorld.inverse;
                    //lightDataForShadow.shadowData.viewMatrix = view;

                    LightsDataForShadow.Add(lightDataForShadow);

                    softShadow |= ifLight.softShadow;
                    ++currentShadowIndex;
                }
            }
            renderingData.shadowData.supportsSoftShadows = softShadow;
            culsterDataGenerator.Begin(pipelineSettings);
            culsterDataGenerator.Run(cameraData, pipelineSettings, this);
            lightLoopLightsData.LightsDatasBuf.SetData(LightsDataList);
            tileAndClusterData.itemsIDListBuf.SetData(culsterDataGenerator.ResultItemsIDList);
            tileAndClusterData.clusterNumItemsBuf.SetData(culsterDataGenerator.ResultClusterNumItems);
            culsterDataGenerator.End();
            UnityEngine.Profiling.Profiler.EndSample();
        }
Esempio n. 7
0
        /// <summary>
        /// Draw the custom wizard.
        /// </summary>

        void OnGUI()
        {
            IFPipelineEditorTools.SetLabelWidth(80f);

            if (IFPipelineSettings.atlas == null)
            {
                GUILayout.Label("No Atlas selected.", "LODLevelNotifyText");
            }
            else
            {
                SpritesAtlas atlas = IFPipelineSettings.atlas;
                bool         close = false;
                GUILayout.Label(atlas.name + " Sprites", "LODLevelNotifyText");
                IFPipelineEditorTools.DrawSeparator();

                GUILayout.BeginHorizontal();
                GUILayout.Space(84f);

                string before = IFPipelineSettings.partialSprite;
                string after  = EditorGUILayout.TextField("", before, "SearchTextField");
                if (before != after)
                {
                    IFPipelineSettings.partialSprite = after;
                }

                if (GUILayout.Button("", "SearchCancelButton", GUILayout.Width(18f)))
                {
                    IFPipelineSettings.partialSprite = "";
                    GUIUtility.keyboardControl       = 0;
                }
                GUILayout.Space(84f);
                GUILayout.EndHorizontal();

                Texture2D tex = atlas.texture as Texture2D;

                if (tex == null)
                {
                    GUILayout.Label("The atlas doesn't have a texture to work with");
                    return;
                }

                BetterList <string> sprites = atlas.GetListOfSprites(IFPipelineSettings.partialSprite);

                float size    = 80f;
                float padded  = size + 10f;
                int   columns = Mathf.FloorToInt(Screen.width / padded);
                if (columns < 1)
                {
                    columns = 1;
                }

                int  offset = 0;
                Rect rect   = new Rect(10f, 0, size, size);

                GUILayout.Space(10f);
                mPos = GUILayout.BeginScrollView(mPos);
                int rows = 1;

                while (offset < sprites.size)
                {
                    GUILayout.BeginHorizontal();
                    {
                        int col = 0;
                        rect.x = 10f;

                        for (; offset < sprites.size; ++offset)
                        {
                            SpriteData sprite = atlas.GetSprite(sprites[offset]);
                            if (sprite == null)
                            {
                                continue;
                            }

                            // Button comes first
                            if (GUI.Button(rect, ""))
                            {
                                if (Event.current.button == 0)
                                {
                                    float delta = Time.realtimeSinceStartup - mClickTime;
                                    mClickTime = Time.realtimeSinceStartup;

                                    if (IFPipelineSettings.selectedSprite != sprite.name)
                                    {
                                        //if (mSprite != null)
                                        //{
                                        //    IFPipelineEditorTools.RegisterUndo("Atlas Selection", mSprite);
                                        //    mSprite.MakePixelPerfect();
                                        //    EditorUtility.SetDirty(mSprite.gameObject);
                                        //}

                                        IFPipelineSettings.selectedSprite = sprite.name;
                                        IFPipelineEditorTools.RepaintSprites();
                                        mCallback?.Invoke(sprite.name);
                                    }
                                    else if (delta < 0.5f)
                                    {
                                        close = true;
                                    }
                                }
                                else
                                {
                                    //NGUIContextMenu.AddItem("Edit", false, EditSprite, sprite);
                                    //NGUIContextMenu.AddItem("Delete", false, DeleteSprite, sprite);
                                    //NGUIContextMenu.Show();
                                }
                            }

                            if (Event.current.type == EventType.Repaint)
                            {
                                // On top of the button we have a checkboard grid
                                IFPipelineEditorTools.DrawTiledTexture(rect, IFPipelineEditorTools.backdropTexture);
                                Rect uv = new Rect(sprite.x, sprite.y, sprite.width, sprite.height);
                                uv = Math.ConvertToTexCoords(uv, tex.width, tex.height);

                                // Calculate the texture's scale that's needed to display the sprite in the clipped area
                                float scaleX = rect.width / uv.width;
                                float scaleY = rect.height / uv.height;

                                // Stretch the sprite so that it will appear proper
                                float aspect   = (scaleY / scaleX) / ((float)tex.height / tex.width);
                                Rect  clipRect = rect;

                                if (aspect != 1f)
                                {
                                    if (aspect < 1f)
                                    {
                                        // The sprite is taller than it is wider
                                        float padding = size * (1f - aspect) * 0.5f;
                                        clipRect.xMin += padding;
                                        clipRect.xMax -= padding;
                                    }
                                    else
                                    {
                                        // The sprite is wider than it is taller
                                        float padding = size * (1f - 1f / aspect) * 0.5f;
                                        clipRect.yMin += padding;
                                        clipRect.yMax -= padding;
                                    }
                                }

                                GUI.DrawTextureWithTexCoords(clipRect, tex, uv);

                                // Draw the selection
                                if (IFPipelineSettings.selectedSprite == sprite.name)
                                {
                                    IFPipelineEditorTools.DrawOutline(rect, new Color(0.4f, 1f, 0f, 1f));
                                }
                            }

                            GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f);
                            GUI.contentColor    = new Color(1f, 1f, 1f, 0.7f);
                            GUI.Label(new Rect(rect.x, rect.y + rect.height, rect.width, 32f), sprite.name, "ProgressBarBack");
                            GUI.contentColor    = Color.white;
                            GUI.backgroundColor = Color.white;

                            if (++col >= columns)
                            {
                                ++offset;
                                break;
                            }
                            rect.x += padded;
                        }
                    }
                    GUILayout.EndHorizontal();
                    GUILayout.Space(padded);
                    rect.y += padded + 26;
                    ++rows;
                }
                GUILayout.Space(rows * 26);
                GUILayout.EndScrollView();

                if (close)
                {
                    Close();
                }
            }
        }