public static void LinkTexture(string texGuid, string arrGuid, bool isAlpha = false)
        {
                        #if UNITY_EDITOR
            string userDataTag = "TexArr_textureArray_as" + (isAlpha? "Source" : "Alpha");
            UnityEditor.AssetImporter importer = AssetsExtensions.GetImporter(texGuid);

            if (importer == null)
            {
                Debug.Log("Could not get importer for " + UnityEditor.AssetDatabase.GUIDToAssetPath(texGuid) + " to assign texture");
                return;
            }

            string[] texData = AssetsExtensions.GetUserData(importer, userDataTag);
            if (!texData.Contains(arrGuid))             //not already signed as used
            {
                ArrayTools.Add(ref texData, arrGuid);
                AssetsExtensions.SetUserData(texGuid, userDataTag, texData, reload: false);
            }

            //writing hash for the newly assigned textures
            string    path    = UnityEditor.AssetDatabase.GUIDToAssetPath(texGuid);
            Texture2D tex     = UnityEditor.AssetDatabase.LoadAssetAtPath <Texture2D>(path);
            string    texHash = tex.GetHash().ToString();                                            //tex.imageContentsHash.ToString();
            AssetsExtensions.SetUserData(importer, "Hash", new string[] { texHash }, reload: false); //will write only if hash changed
                        #endif
        }
Beispiel #2
0
        public void OnLayerGUI(Layout layout, int num)
        {
            ObjectType block = array[num];

            layout.margin += 5; layout.rightMargin += 5;

            int numToRemove = -1;

            for (int i = 0; i < block.prefabs.Length; i++)
            {
                layout.Par();
                layout.Field(ref block.prefabs[i], rect: layout.Inset(layout.field.width - 20 - layout.margin - layout.rightMargin));
                if (layout.Button(icon:"DPLayout_Remove", rect:layout.Inset(20)))
                {
                    numToRemove = i;
                }
                layout.Par(3);
            }

            if (numToRemove >= 0)
            {
                ArrayTools.RemoveAt(ref block.prefabs, numToRemove);
            }

            layout.Par();
            layout.Inset(layout.field.width - 20 - layout.margin - layout.rightMargin);
            if (layout.Button(icon: "DPLayout_Add", rect: layout.Inset(20)))
            {
                ArrayTools.Add(ref block.prefabs, null);
            }

            layout.Par(4);
            layout.margin -= 5; layout.rightMargin -= 5;
        }
 public void WriteTrack(Vector3 pos)
 {
     if (track == null || track.Length == 0)
     {
         track = new Vector3[1000];
     }
     if (timeTrack == null || timeTrack.Length == 0)
     {
         timeTrack = new float[1000];
     }
     ArrayTools.Add(ref track, pos);
     ArrayTools.Add(ref timeTrack, deltaTime);
     ArrayTools.RemoveAt(ref track, 0);
     ArrayTools.RemoveAt(ref timeTrack, 0);
 }
        public void Add(Texture2D tex, Texture2D al)
        {
                        #if UNITY_EDITOR
            ArrayTools.Add(ref srcArr, new SrcLayer());
            TextureArrayTools.Add(ref texArr, new Texture2D(texArr.width, texArr.height));

            if (tex != null)
            {
                SetSource(tex, srcArr.Length - 1, isAlpha: false, saveSources: false);
            }
            if (al != null)
            {
                SetSource(al, srcArr.Length - 1, isAlpha: true, saveSources: false);
            }

            SaveSources();
                        #endif
        }
Beispiel #5
0
		static void CreateVoxeland (bool infinite=true) 
		{
			GameObject go = new GameObject();
			go.name = "Voxeland";

			Voxeland voxeland = go.AddComponent<Voxeland>();
			voxeland.chunks = new ChunkGrid<Chunk>();
			voxeland.chunkSize = 30;
			Voxeland.instances.Add(voxeland);
			
			//adding empty layer 
			voxeland.landTypes = new LandTypeList();

			ArrayTools.Add(ref voxeland.landTypes.array, new BlockType()); 
			voxeland.landTypes.array[0].mainTex = TextureExtensions.ColorTexture(2,2,new Color(0.666f, 0.666f, 0.666f, 0.5f), linear:false);
			#if UNITY_2017_3_OR_NEWER
			voxeland.landTypes.array[0].bumpMap = TextureExtensions.ColorTexture(2,2,new Color(0.5f, 0.5f, 0.5f, 1f), linear:true);
			#else
			voxeland.landTypes.array[0].bumpMap = TextureExtensions.ColorTexture(2,2,new Color(0.5f, 0.5f, 0.5f, 0.5f), linear:true);
			#endif

			//voxeland.landTypes.mainTexArray = new Texture2DArray(1024, 1024, 1, TextureFormat.DXT5, true) { name = "Albedo Height Array" };
			//voxeland.landTypes.mainTexArray.SetTexture( TextureExtensions.ColorTexture(1024,1024,Color.gray), 0);
			//voxeland.landTypes.bumpMapArray = new Texture2DArray(1024, 1024, 1, TextureFormat.DXT5, true, linear:true) { name = "Normals Array" };
			//voxeland.landTypes.bumpMapArray.SetTexture( TextureExtensions.ColorTexture(1024,1024,new Color(0.5f,0.5f,0.5f,0.5f)), 0);

			voxeland.landTypes.selected = 0;

			//adding empty grass
			voxeland.grassTypes = new GrassTypeList();
			voxeland.grassTypes.selected = -1;

			//objects
			voxeland.objectsTypes = new ObjectTypeList();
			voxeland.objectsTypes.selected = -1;

			//data
			voxeland.data = ScriptableObject.CreateInstance<Data>(); 
			voxeland.data.areas = new ChunkGrid<Data.Area>();
			voxeland.data.areaSize = 512;

			//materials
			voxeland.material = Voxeland.GetDefaultLandMaterial();
			voxeland.farMaterial = Voxeland.GetDefaultFarMaterial();
			voxeland.grassMaterial = Voxeland.GetDefaultGrassMaterial();

			voxeland.landTypes.ApplyToMaterial(voxeland.material);
			voxeland.landTypes.ApplyToMaterial(voxeland.farMaterial, horizon:true);
			voxeland.grassTypes.ApplyToMaterial(voxeland.grassMaterial);

			if (voxeland.horizon != null) voxeland.horizon.meshRenderer.sharedMaterial = voxeland.farMaterial;
			
			//highlight
			if (voxeland.highlight == null) //could be created on de-prefab in onenable
			{
				voxeland.highlight = Highlight.Create(voxeland);
				voxeland.highlight.material = Voxeland.GetDefaultHighlightMaterial(); //new Material( Shader.Find("Voxeland/Highlight") );
			}

			//static and infinite
			if (infinite)
			{
				voxeland.playmodeSizeMode = Voxeland.SizeMode.DynamicInfinite;
				voxeland.editorSizeMode = Voxeland.SizeMode.DynamicInfinite;

				voxeland.saveMeshes = false;

				voxeland.horizon = Horizon.Create(voxeland);
			}
			else
			{
				voxeland.playmodeSizeMode = Voxeland.SizeMode.Static;
				voxeland.editorSizeMode = Voxeland.SizeMode.Static;

				voxeland.saveMeshes = true;  
			}

			//generators
			voxeland.data.generator.noiseGen.enabled = true;
			voxeland.data.generator.noiseGenB.enabled = false;
			voxeland.data.generator.noiseGenB.seed = 1234;
			voxeland.data.generator.noiseGenB.high = 0.1f;
			voxeland.data.generator.curveGen.enabled = true;
			voxeland.data.generator.blurGen.enabled = true;

			//registering undo
			Undo.RegisterCreatedObjectUndo (go, "Voxeland Create");
			EditorUtility.SetDirty(go);
		}
Beispiel #6
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();
                }
            }
        }