Esempio 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;
                }
            }
        }
Esempio n. 2
0
        private uint GetKey(OptimizableObject opt)
        {
            uint   textureKey;
            string text = GetUniqueIdentifier(opt);

            textureKey = Utils.CalculateMD5Hash(text);
            return(textureKey);
        }
Esempio 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);
 }
Esempio n. 4
0
        public void RemoveObject(OptimizableObject obj)
        {
            if (!objects.Remove(obj))
            {
                Debug.LogError("Couldnt remove object");
            }
//      else
//          Debug.Log("Added obj");
        }
Esempio 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);
            }
        }
Esempio 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);
            }
        }
Esempio n. 7
0
        public bool TextureRefExists(OptimizableObject opt)
        {
            uint textureKey = GetKey(opt);

            if (knownTextureRefs.ContainsKey(textureKey))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        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);
        }
Esempio 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);
            }
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio n. 12
0
        public Rect GetTextureRefPosition(OptimizableObject opt)
        {
            uint textureKey = GetKey(opt);

            return(knownTextureRefs[textureKey]);
        }
Esempio n. 13
0
 public void SetObjectAtIndex(int index, OptimizableObject obj)
 {
     objects[index] = obj;
 }
Esempio n. 14
0
 public void SetObjectAtIndex(int index, OptimizableObject obj, bool combineObj)
 {
     objectsToOptimize[index]  = obj;
     combineMeshesFlags[index] = combineObj;
 }
Esempio 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);
 }