Ejemplo n.º 1
0
        private static string folderToSavePrefabs = "";//set on OptimizeShader();

        //creates a new optimizable shader and initializes it with an initial object.
        //the initial object is needed as we need to parse the standard shader in case there is one.
        public OptimizableShader(string name, OptimizableObject initialObject, bool combineObject)
        {
            optimizedObjects   = new List <Tuple <GameObject, int> >();
            shaderName         = "";//by default
            objectsToOptimize  = new List <OptimizableObject>();
            combineMeshesFlags = new List <bool>();

            cacheAtlasSizeNoReuseTextures = NO_CACHED;
            cacheAtlasSizeReuseTextures   = NO_CACHED;


            //if the initial object is not null this means we have to check if the initial object has a standard shader
            if (initialObject != null)
            {
                AddObject(initialObject, combineObject);
                if (Utils.IsShaderStandard(name))
                {
                    standardShader = true;
                    shaderName     = Utils.ParseStandardShaderName(initialObject.ObjectMaterial);
                }
                else//shader is a normal shader, no need to parse its name
                {
                    standardShader = false;
                    shaderName     = name;
                }
            }
        }
Ejemplo n.º 2
0
        private uint GetKey(OptimizableObject opt)
        {
            uint   textureKey;
            string text = GetUniqueIdentifier(opt);

            textureKey = Utils.CalculateMD5Hash(text);
            return(textureKey);
        }
Ejemplo n.º 3
0
 //adds an object to the objects list.
 //WARNING: this doesnt care if the optimizable object obj matches the shader name
 // of this object.
 // Later on the ObjSorter.cs->SortObjects() organizes them to match
 public void AddObject(OptimizableObject obj)
 {
     /*if(shaderName != "" && obj != null && shaderName != obj.ShaderName) {
      *  Debug.LogWarning("ERROR: Adding obj to a not matching optimizable shader");
      *  return;
      * }*/
     objects.Add(obj);
 }
Ejemplo n.º 4
0
        public void RemoveObject(OptimizableObject obj)
        {
            if (!objects.Remove(obj))
            {
                Debug.LogError("Couldnt remove object");
            }
//      else
//          Debug.Log("Added obj");
        }
Ejemplo n.º 5
0
        //this is used when we want to know if a texture exists already or not (for calculating atlases sizes on the GUI)
        public void AddTextureRef(OptimizableObject opt)
        {
            uint textureKey    = GetKey(opt);
            Rect dummyPosition = new Rect(0, 0, 0, 0);

            if (!knownTextureRefs.ContainsKey(textureKey))
            {
                knownTextureRefs.Add(textureKey, dummyPosition);
            }
        }
Ejemplo n.º 6
0
        public void AddTextureRef(OptimizableObject opt, Rect positionInAtlas, int indexOfTexture)
        {
            uint textureKey = GetKey(opt);

            if (!knownTextureRefs.ContainsKey(textureKey))
            {
                knownTextureRefs.Add(textureKey, positionInAtlas);
                textureRefsIndexes.Add(indexOfTexture);
            }
        }
Ejemplo n.º 7
0
        public bool TextureRefExists(OptimizableObject opt)
        {
            uint textureKey = GetKey(opt);

            if (knownTextureRefs.ContainsKey(textureKey))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 8
0
        private uint GetKey(OptimizableObject opt)
        {
            uint textureKey;

            if (opt.MainTexture == null)
            {
                textureKey = Utils.CalculateMD5Hash(opt.GetColor().ToString());
            }
            else
            {
                textureKey = Utils.CalculateMD5Hash(AssetDatabase.GetAssetPath(opt.MainTexture));    //TODO ADD OFFSET + SCALE, but thinkg same texture, diff tiles on any of the materials, what would happen...
            }
            return(textureKey);
        }
Ejemplo n.º 9
0
        //Quick sort for organizing textures sizes.
        //ascending order
        private static void SortTexturesBySize(int left, int right, int position)
        {
            int leftHold  = left;
            int rightHold = right;
            OptimizableObject pivotObj = optimizableShaders[position].Objects[left];
            int pivot = pivotObj.TextureArea;

            while (left < right)
            {
                while ((optimizableShaders[position].Objects[right].TextureArea >= pivot) && (left < right))
                {
                    right--;
                }

                if (left != right)
                {
                    optimizableShaders[position].Objects[left] = optimizableShaders[position].Objects[right];
                    left++;
                }

                while ((optimizableShaders[position].Objects[left].TextureArea <= pivot) && (left < right))
                {
                    left++;
                }

                if (left != right)
                {
                    optimizableShaders[position].Objects[right] = optimizableShaders[position].Objects[left];
                    right--;
                }
            }
            optimizableShaders[position].Objects[left] = pivotObj;
            pivot = left;
            left  = leftHold;
            right = rightHold;

            if (left < pivot)
            {
                SortTexturesBySize(left, pivot - 1, position);
            }

            if (right > pivot)
            {
                SortTexturesBySize(pivot + 1, right, position);
            }
        }
Ejemplo n.º 10
0
        //gets a concatenated string of paths of the different textures the object has.
        //TODO ADD OFFSET + SCALE, but thinkg same texture, diff tiles on any of the materials, what would happen...
        private string GetUniqueIdentifier(OptimizableObject opt)
        {
            string           uniqueStringID = "";
            List <Texture2D> objTextures    = ShaderManager.Instance.GetTexturesForObject(opt.ObjectMaterial, opt.ShaderName);

            for (int i = 0; i < objTextures.Count; i++)
            {
                if (objTextures[i] != null)
                {
                    uniqueStringID += AssetDatabase.GetAssetPath(objTextures[i]);
                }
            }
            if (uniqueStringID == "")
            {
                uniqueStringID = opt.GetColor().ToString();
            }
            return(uniqueStringID);
        }
Ejemplo n.º 11
0
        //Adds an object to optimizableShaders[0], later on SortObjects() re organizes the objects inside.
        // Maybe SortObjects() can dissapear and AddObjects adds objects to the correct shader. think about this..
        public static void AddObject(GameObject g)
        {
            OptimizableObject optObj = new OptimizableObject(g);

            optimizableShaders[0].AddObject(optObj);
        }
Ejemplo n.º 12
0
        public Rect GetTextureRefPosition(OptimizableObject opt)
        {
            uint textureKey = GetKey(opt);

            return(knownTextureRefs[textureKey]);
        }
Ejemplo n.º 13
0
 public void SetObjectAtIndex(int index, OptimizableObject obj)
 {
     objects[index] = obj;
 }
Ejemplo n.º 14
0
 public void SetObjectAtIndex(int index, OptimizableObject obj, bool combineObj)
 {
     objectsToOptimize[index]  = obj;
     combineMeshesFlags[index] = combineObj;
 }
Ejemplo n.º 15
0
 // adds an object to the objects list.
 // WARNING: this doesnt care if the optimizable object obj matches the shader name
 // of this object.
 // Later on the ObjSorter.cs->SortObjects() organizes them to match
 public void AddObject(OptimizableObject obj, bool combineObj)
 {
     objectsToOptimize.Add(obj);
     combineMeshesFlags.Add(combineObj);
 }