RemoveAt() static public method

static public RemoveAt ( Array array, int num ) : T[]
array Array
num int
return T[]
Example #1
0
        public void SetPrototypes(Prototype[] prototypes)
        /// Will clear and remove pools that are not in array and add new pools with array prototypes
        /// Will set the pools order exactly as it was given in the array
        {
            //clearing pools with null prefab (rare case)
            for (int i = pools.Length - 1; i >= 0; i--)
            {
                if (pools[i] == null || pools[i].prototype == null || pools[i].prototype.prefab == null || pools[i].prototype.prefab.Equals(null))
                {
                    pools[i].Clear();
                    ArrayTools.RemoveAt(ref pools, i);
                }
            }

            //creating the dictionary of used prototypes/pools
            //TODO: use ClearPrortotypes?
            Dictionary <Prototype, Pool> usedPools = new Dictionary <Prototype, Pool>(pools.Length, new PrototypeComparer());

            for (int i = 0; i < pools.Length; i++)
            {
                if (!usedPools.ContainsKey(pools[i].prototype))                 //avoiding two pools with one prototype (could be created when duplicating obj out node)
                {
                    usedPools.Add(pools[i].prototype, pools[i]);
                }
            }

            //reposition
            Pool[] newPools = new Pool[prototypes.Length];
            for (int i = 0; i < prototypes.Length; i++)
            {
                if (usedPools.TryGetValue(prototypes[i], out Pool pool))
                {
                    usedPools.Remove(prototypes[i]);
                }
                else
                {
                    pool = new Pool(prototypes[i]);
                }

                //other than instantiateClones and allowReposition (they are in comparer) should be copied
                pool.prototype.regardPrefabRotation = prototypes[i].regardPrefabRotation;
                pool.prototype.regardPrefabScale    = prototypes[i].regardPrefabScale;

                newPools[i] = pool;
            }

            //clearing unused
            if (usedPools.Count != 0)
            {
                foreach (var kvp in usedPools)
                {
                    kvp.Value.Clear();
                }
            }

            pools = newPools;
        }
Example #2
0
        public void SetPrototypes(Prototype[] prototypes)
        /// Will clear and remove pools that are not in array and add new pools with array prototypes
        /// Will set the pools order exactly as it was given in the array
        {
            //clearing pools with null prefab (rare case)
            for (int i = pools.Length - 1; i >= 0; i--)
            {
                if (pools[i] == null || pools[i].prototype == null || pools[i].prototype.prefab == null || pools[i].prototype.prefab.Equals(null))
                {
                    pools[i].Clear();
                    ArrayTools.RemoveAt(ref pools, i);
                }
            }

            //creating the dictionary of used prototypes/pools
            //TODO: use ClearPrortotypes?
            Dictionary <Prototype, Pool> usedPools = new Dictionary <Prototype, Pool>(pools.Length, new PrototypeComparer());

            for (int i = 0; i < pools.Length; i++)
            {
                usedPools.Add(pools[i].prototype, pools[i]);
            }

            //reposition
            Pool[] newPools = new Pool[prototypes.Length];
            for (int i = 0; i < prototypes.Length; i++)
            {
                if (usedPools.TryGetValue(prototypes[i], out Pool pool))
                {
                    usedPools.Remove(prototypes[i]);
                }
                else
                {
                    pool = new Pool(prototypes[i]);
                }

                newPools[i] = pool;
            }

            //clearing unused
            if (usedPools.Count != 0)
            {
                foreach (var kvp in usedPools)
                {
                    kvp.Value.Clear();
                }
            }

            pools = newPools;
        }
Example #3
0
        public void Reposition(Prototype[] prototypes, List <Transition>[] drafts)
        {
            //excluding 0-count from input drafts and prototypes
            for (int i = drafts.Length - 1; i > 0; i--)
            {
                if (drafts[i].Count == 0)
                {
                    ArrayTools.RemoveAt(ref prototypes, i); ArrayTools.RemoveAt(ref drafts, i);
                }
            }

            SetPrototypes(prototypes);             //will set the pools count and order as given in prototypes array

            for (int i = 0; i < pools.Length; i++)
            {
                pools[i].Reposition(drafts[i], this.transform);
            }
        }
Example #4
0
        public IEnumerator RepositionRoutine(Prototype[] prototypes, List <Transition>[] drafts)
        {
            //excluding 0-count from input drafts and prototypes
            for (int i = drafts.Length - 1; i >= 0; i--)
            {
                if (drafts[i].Count == 0)
                {
                    ArrayTools.RemoveAt(ref prototypes, i); ArrayTools.RemoveAt(ref drafts, i);
                }
            }

            SetPrototypes(prototypes);             //will set the pools count and order as given in prototypes array

            for (int i = 0; i < pools.Length; i++)
            {
                IEnumerator e = pools[i].RepositionRoutine(drafts[i], this.transform);
                while (e.MoveNext())
                {
                    yield return(null);
                }
            }
        }
Example #5
0
        public static void SetUserData(this UnityEditor.AssetImporter importer, string param, string[] data, bool reload = false)
        {
            char endline = '\n';             //';'

            string userData = importer.userData;

            string[] userDataSplit = userData.Split('\n', ';');

            //preparing new data line
            if (data == null)
            {
                data = new string[0];
            }
            string newDataString = param + ":" + data.ToStringMemberwise(separator: ",");

            //param line number (-1 if not found)
            int numInSplit = -1;

            for (int i = 0; i < userDataSplit.Length; i++)
            {
                if (userDataSplit[i].StartsWith(param + ":"))
                {
                    numInSplit = i;
                }
            }

            //erasing empty data
            if (numInSplit >= 0 && data.Length == 0)
            {
                ArrayTools.RemoveAt(ref userDataSplit, numInSplit);
            }

            //replacing line
            if (numInSplit >= 0 && data.Length != 0)
            {
                userDataSplit[numInSplit] = newDataString;
            }

            //adding new line
            if (numInSplit == -1 && data.Length != 0)
            {
                ArrayTools.Add(ref userDataSplit, newDataString);
            }

            //to string
            string newUserData = "";

            for (int i = 0; i < userDataSplit.Length; i++)
            {
                if (userDataSplit[i].Length == 0)
                {
                    continue;
                }
                newUserData += userDataSplit[i];
                if (i != userDataSplit.Length - 1)
                {
                    newUserData += endline;
                }
            }

            //writing
            if (newUserData != userData)
            {
                importer.userData = newUserData;

                UnityEditor.EditorUtility.SetDirty(importer);
                UnityEditor.AssetDatabase.WriteImportSettingsIfDirty(importer.assetPath);
                if (reload)
                {
                    UnityEditor.AssetDatabase.Refresh();
                }
            }
        }