public TextureSource(UnityEngine.Texture2D texture) : this(Texture.WrapTexture(texture))
 {
 }
	private void FeelingMonitorPanel(int id)
	{
		Dictionary<string, float> feelingValueMap = _connector.FeelingValueMap;
		if(feelingValueMap.Count == 0)
		{
			return;
		}

		_scrollPosition = UnityEngine.GUILayout.BeginScrollView(_scrollPosition);

		float feelingBarWidth = UnityEngine.Screen.width * 0.3f;

		_boxStyle = _panelSkin.box;
		lock(feelingValueMap)
		{
			int topOffset = 5;
			foreach(string feeling in feelingValueMap.Keys)
			{
				if(!_isFeelingTextureMapInitialized)
				{
					float r = UnityEngine.Random.value;
					float g = UnityEngine.Random.value;
					float b = UnityEngine.Random.value;
					UnityEngine.Color c = new UnityEngine.Color(r, g, b, 0.6f);
					UnityEngine.Texture2D t = new UnityEngine.Texture2D(1, 1);
					t.SetPixel(0, 0, c);
					t.Apply();
					_feelingTextureMap[feeling] = t;
				}
				float value = feelingValueMap[feeling];

				// Set the texture of background.
				_boxStyle.normal.background = _feelingTextureMap[feeling];
				UnityEngine.GUILayout.BeginHorizontal();
				UnityEngine.GUILayout.Label(feeling + ": ", _panelSkin.label, UnityEngine.GUILayout.MaxWidth(_panel.width * 0.3f));
				UnityEngine.GUILayout.Box("", _boxStyle, UnityEngine.GUILayout.Width(feelingBarWidth * value), UnityEngine.GUILayout.Height(16));
				UnityEngine.GUILayout.EndHorizontal();
				topOffset += 15;
			}
			// We only need to initialize the map at the first time.
			if(!_isFeelingTextureMapInitialized)
			{
				_isFeelingTextureMapInitialized = true;
			}
		}

		UnityEngine.GUILayout.EndScrollView();
	}
        int UnityEngineSprite_m_Create_xlua_st_(RealStatePtr L, int gen_param_count)
        {
            ObjectTranslator translator = this;


            if (gen_param_count == 3 && translator.Assignable <UnityEngine.Texture2D>(L, 1) && translator.Assignable <UnityEngine.Rect>(L, 2) && translator.Assignable <UnityEngine.Vector2>(L, 3))
            {
                UnityEngine.Texture2D _texture = (UnityEngine.Texture2D)translator.GetObject(L, 1, typeof(UnityEngine.Texture2D));
                UnityEngine.Rect      _rect; translator.Get(L, 2, out _rect);
                UnityEngine.Vector2   _pivot; translator.Get(L, 3, out _pivot);

                UnityEngine.Sprite gen_ret = UnityEngine.Sprite.Create(_texture, _rect, _pivot);
                translator.Push(L, gen_ret);



                return(1);
            }
            if (gen_param_count == 4 && translator.Assignable <UnityEngine.Texture2D>(L, 1) && translator.Assignable <UnityEngine.Rect>(L, 2) && translator.Assignable <UnityEngine.Vector2>(L, 3) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4))
            {
                UnityEngine.Texture2D _texture = (UnityEngine.Texture2D)translator.GetObject(L, 1, typeof(UnityEngine.Texture2D));
                UnityEngine.Rect      _rect; translator.Get(L, 2, out _rect);
                UnityEngine.Vector2   _pivot; translator.Get(L, 3, out _pivot);
                float _pixelsPerUnit = (float)LuaAPI.lua_tonumber(L, 4);

                UnityEngine.Sprite gen_ret = UnityEngine.Sprite.Create(_texture, _rect, _pivot, _pixelsPerUnit);
                translator.Push(L, gen_ret);



                return(1);
            }
            if (gen_param_count == 5 && translator.Assignable <UnityEngine.Texture2D>(L, 1) && translator.Assignable <UnityEngine.Rect>(L, 2) && translator.Assignable <UnityEngine.Vector2>(L, 3) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 5))
            {
                UnityEngine.Texture2D _texture = (UnityEngine.Texture2D)translator.GetObject(L, 1, typeof(UnityEngine.Texture2D));
                UnityEngine.Rect      _rect; translator.Get(L, 2, out _rect);
                UnityEngine.Vector2   _pivot; translator.Get(L, 3, out _pivot);
                float _pixelsPerUnit = (float)LuaAPI.lua_tonumber(L, 4);
                uint  _extrude       = LuaAPI.xlua_touint(L, 5);

                UnityEngine.Sprite gen_ret = UnityEngine.Sprite.Create(_texture, _rect, _pivot, _pixelsPerUnit, _extrude);
                translator.Push(L, gen_ret);



                return(1);
            }
            if (gen_param_count == 6 && translator.Assignable <UnityEngine.Texture2D>(L, 1) && translator.Assignable <UnityEngine.Rect>(L, 2) && translator.Assignable <UnityEngine.Vector2>(L, 3) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 5) && translator.Assignable <UnityEngine.SpriteMeshType>(L, 6))
            {
                UnityEngine.Texture2D _texture = (UnityEngine.Texture2D)translator.GetObject(L, 1, typeof(UnityEngine.Texture2D));
                UnityEngine.Rect      _rect; translator.Get(L, 2, out _rect);
                UnityEngine.Vector2   _pivot; translator.Get(L, 3, out _pivot);
                float _pixelsPerUnit = (float)LuaAPI.lua_tonumber(L, 4);
                uint  _extrude       = LuaAPI.xlua_touint(L, 5);
                UnityEngine.SpriteMeshType _meshType; translator.Get(L, 6, out _meshType);

                UnityEngine.Sprite gen_ret = UnityEngine.Sprite.Create(_texture, _rect, _pivot, _pixelsPerUnit, _extrude, _meshType);
                translator.Push(L, gen_ret);



                return(1);
            }
            if (gen_param_count == 7 && translator.Assignable <UnityEngine.Texture2D>(L, 1) && translator.Assignable <UnityEngine.Rect>(L, 2) && translator.Assignable <UnityEngine.Vector2>(L, 3) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 5) && translator.Assignable <UnityEngine.SpriteMeshType>(L, 6) && translator.Assignable <UnityEngine.Vector4>(L, 7))
            {
                UnityEngine.Texture2D _texture = (UnityEngine.Texture2D)translator.GetObject(L, 1, typeof(UnityEngine.Texture2D));
                UnityEngine.Rect      _rect; translator.Get(L, 2, out _rect);
                UnityEngine.Vector2   _pivot; translator.Get(L, 3, out _pivot);
                float _pixelsPerUnit = (float)LuaAPI.lua_tonumber(L, 4);
                uint  _extrude       = LuaAPI.xlua_touint(L, 5);
                UnityEngine.SpriteMeshType _meshType; translator.Get(L, 6, out _meshType);
                UnityEngine.Vector4        _border; translator.Get(L, 7, out _border);

                UnityEngine.Sprite gen_ret = UnityEngine.Sprite.Create(_texture, _rect, _pivot, _pixelsPerUnit, _extrude, _meshType, _border);
                translator.Push(L, gen_ret);



                return(1);
            }
            if (gen_param_count == 8 && translator.Assignable <UnityEngine.Texture2D>(L, 1) && translator.Assignable <UnityEngine.Rect>(L, 2) && translator.Assignable <UnityEngine.Vector2>(L, 3) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 5) && translator.Assignable <UnityEngine.SpriteMeshType>(L, 6) && translator.Assignable <UnityEngine.Vector4>(L, 7) && LuaTypes.LUA_TBOOLEAN == LuaAPI.lua_type(L, 8))
            {
                UnityEngine.Texture2D _texture = (UnityEngine.Texture2D)translator.GetObject(L, 1, typeof(UnityEngine.Texture2D));
                UnityEngine.Rect      _rect; translator.Get(L, 2, out _rect);
                UnityEngine.Vector2   _pivot; translator.Get(L, 3, out _pivot);
                float _pixelsPerUnit = (float)LuaAPI.lua_tonumber(L, 4);
                uint  _extrude       = LuaAPI.xlua_touint(L, 5);
                UnityEngine.SpriteMeshType _meshType; translator.Get(L, 6, out _meshType);
                UnityEngine.Vector4        _border; translator.Get(L, 7, out _border);
                bool _generateFallbackPhysicsShape = LuaAPI.lua_toboolean(L, 8);

                UnityEngine.Sprite gen_ret = UnityEngine.Sprite.Create(_texture, _rect, _pivot, _pixelsPerUnit, _extrude, _meshType, _border, _generateFallbackPhysicsShape);
                translator.Push(L, gen_ret);



                return(1);
            }


            return(LuaAPI.luaL_error(L, "invalid arguments to UnityEngine.Sprite.Create!"));
        }
Example #4
0
 public Bitmap(int width, int height)
 {
     Color    = Color.White;
     uTexture = new UnityEngine.Texture2D(width, height);
 }
        public static UTexture2D LoadFromFile(String fileNamePath, int width, int height, bool mipmap)
        {
            UTexture2D tex         = null;
            bool       validReturn = false;
            bool       dds         = false;

            try
            {
                string path = fileNamePath;
                if (!SIO.File.Exists(fileNamePath))
                {
                    // Look for the file with an appended suffix.
                    for (int i = 0; i < imgSuffixes.Length; i++)
                    {
                        if (SIO.File.Exists(fileNamePath + imgSuffixes[i]))
                        {
                            path = fileNamePath + imgSuffixes[i];
                            dds  = imgSuffixes[i] == ".dds" || imgSuffixes[i] == ".DDS";
                            break;
                        }
                    }
                }

                //File Exists check
                if (SIO.File.Exists(path))
                {
                    try
                    {
                        if (dds)
                        {
                            LoadDXT(out tex, path, mipmap, fileNamePath);
                            validReturn = true;
                        }
                        else
                        {
                            validReturn = (width > 0 && height > 0)
                                                                ? File.Load(out tex, width, height, SIO.File.ReadAllBytes(path))
                                                                : File.Load(out tex, SIO.File.ReadAllBytes(path))
                            ;
                        }
                    }
                    catch (Exception ex)
                    {
                        dbg(ex);
                        throw new Error(ex, "Failed to load the texture: {0} due {1}.", path, ex);
                    }
                }
                else
                {
                    throw new Error("Cannot find texture to load: {0}", fileNamePath);
                }
            }
            catch (Error ex)
            {
                dbg(ex);
                throw ex;
            }
            catch (System.Exception ex)
            {
                dbg(ex);
                throw new Error(ex, "Failed to load (are you missing a file?): {0}", fileNamePath);
            }
            finally
            {
                if (!validReturn)
                {
                    if (null != tex)
                    {
                        UnityEngine.Object.Destroy(tex);                                        // Preventing a memory leak
                    }
                    throw new Error("Invalid content while reading file {0}", fileNamePath);
                }
            }

            return(tex);
        }
Example #6
0
        /// <summary>
        /// A generic object builder that takes the properties from the reader and puts into a
        /// new object of the same type as the destination object
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="destination"></param>
        /// <returns></returns>
        static public T ReflectionObjectBuilder <T>(Object obj)
        {
            //Type sourceType = source.GetType();
            Type destinationType = typeof(T);

            T result = (T)Activator.CreateInstance(destinationType);

            // columns is a list of attribute names in the reader
            var sourceFields = obj.GetType().GetFields();
            var sourceProps  = obj.GetType().GetProperties();

            var destProps  = destinationType.GetProperties();
            var destFields = destinationType.GetFields();

            SRInfoHelper.Log("Mapping to " + destinationType + " : " + destProps.Count() + " and mapping from " + obj.GetType() + " " + sourceProps.Count());

            // We get properties from the destination type instead of the source type
            foreach (PropertyInfo pi in destProps)
            {
                // set pDest to the currently instanced property type
                PropertyInfo pDest   = destinationType.GetProperty(pi.Name);
                var          pSource = sourceProps.Where(s => s.Name == pi.Name).FirstOrDefault();
                var          fSource = sourceFields.Where(s => s.Name == pi.Name).FirstOrDefault();

                if (pSource == null && fSource == null)
                {
                    SRInfoHelper.Log("No source found for propety " + pi.Name + "Skipping");
                    continue;
                }

                if (pSource != null)
                {
                    SRInfoHelper.Log("Property name " + pi.Name + " destination property name " + pSource?.Name);
                }
                else
                {
                    SRInfoHelper.Log("Property name " + pi.Name + " destination field name " + fSource?.Name);
                }

                if (pDest != null && pDest.CanWrite)
                {
                    if (pDest.PropertyType.FullName == "SyndicateMod.DTOs.Sprite")
                    {
                        //SRInfoHelper.Log("Mapping sprite");
                        DTOs.Sprite        destSprite   = (DTOs.Sprite)pDest.GetValue(result, null);
                        UnityEngine.Sprite sourceSprite = new UnityEngine.Sprite();

                        if (pSource != null)
                        {
                            sourceSprite = (UnityEngine.Sprite)pSource.GetValue(obj, null);
                        }
                        else if (fSource != null)
                        {
                            sourceSprite = (UnityEngine.Sprite)fSource.GetValue(obj);
                        }
                        else
                        {
                            continue;
                        }

                        if (sourceSprite == null || sourceSprite.name == null || sourceSprite.name == "")
                        {
                            continue;
                        }

                        SRInfoHelper.Log("Mapping sprite " + sourceSprite.name);

                        DTOs.Sprite mappedSprite = ReflectionObjectBuilder <DTOs.Sprite>(sourceSprite);

                        //SRInfoHelper.Log("Mapped sprite");

                        if (sourceSprite.texture != null)
                        {
                            FileManager.SaveTextureToFile(sourceSprite.texture);
                            mappedSprite.textureName = sourceSprite.texture.name + ".png";
                        }
                        if (sourceSprite.associatedAlphaSplitTexture != null)
                        {
                            FileManager.SaveTextureToFile(sourceSprite.associatedAlphaSplitTexture);
                            mappedSprite.associatedAlphaSplitTextureName = sourceSprite.associatedAlphaSplitTexture.name + ".png";
                        }
                        SRInfoHelper.Log("Saved textures");

                        pDest.SetValue(result, mappedSprite, null);
                        continue;
                    }

                    bool isCollection = pDest.PropertyType.GetInterfaces()
                                        .Any(x => x == typeof(IEnumerable));

                    if (isCollection && pDest.PropertyType.FullName != "System.String")
                    {
                        Type itemType = pDest.PropertyType;
                        if (itemType.IsArray)
                        {
                            itemType = itemType.GetElementType();
                        }
                        //if (pSource.FieldType.GetGenericArguments().Any())
                        //    itemType = pSource.FieldType.GetGenericArguments().FirstOrDefault();

                        SRInfoHelper.Log("Found collection " + pDest.PropertyType + " named " + pDest.Name + " namespace is " + itemType.FullName);

                        if (itemType.FullName.Contains("Syndicate"))
                        {
                            List <DTOs.ModifierData5L> modifiers = new List <DTOs.ModifierData5L>();

                            if (fSource != null)
                            {
                                foreach (var item in (IEnumerable)fSource.GetValue(obj))
                                {
                                    var mappedItem = ReflectionObjectBuilder <DTOs.ModifierData5L>(item);
                                    modifiers.Add(mappedItem);
                                }
                            }
                            else if (pSource != null)
                            {
                                foreach (var item in (IEnumerable)pSource.GetValue(obj, null))
                                {
                                    var mappedItem = ReflectionObjectBuilder <DTOs.ModifierData5L>(item);
                                    modifiers.Add(mappedItem);
                                }
                            }
                            result.SetMemberValue(pi.Name, modifiers.ToArray());
                        }
                        else if (itemType.FullName == "ModifierData5L")
                        {
                            List <ModifierData5L> modifiers = new List <ModifierData5L>();

                            if (fSource != null)
                            {
                                foreach (var item in (IEnumerable)fSource.GetValue(obj))
                                {
                                    var mappedItem = ReflectionObjectBuilder <ModifierData5L>(item);
                                    modifiers.Add(mappedItem);
                                }
                            }
                            else
                            {
                                foreach (var item in (IEnumerable)pSource.GetValue(obj, null))
                                {
                                    var mappedItem = ReflectionObjectBuilder <ModifierData5L>(item);
                                    modifiers.Add(mappedItem);
                                }
                            }
                            result.SetMemberValue(pi.Name, modifiers.ToArray());
                        }
                        else
                        {
                            SRInfoHelper.Log("Processing collection " + pDest.PropertyType);
                            if (fSource != null)
                            {
                                result.SetMemberValue(pi.Name, fSource.GetValue(obj));
                            }
                            else if (pSource != null)
                            {
                                result.SetMemberValue(pi.Name, pSource.GetValue(obj, null));
                            }
                        }
                        //result.SetMemberValue(pi.Name, obj.GetMemberValue(pi.Name));
                    }
                    // Make sure the current property name can be found in the reader
                    else
                    {
                        string value = "";
                        string type  = "";
                        if (pSource != null)
                        {
                            type  = pSource.PropertyType.FullName;
                            value = pSource.GetValue(obj, null).ToString();
                            SRInfoHelper.Log("Found " + type + " named " + pDest.Name + " with value " + value);

                            result.SetMemberValue(pi.Name, pSource.GetValue(obj, null));
                        }
                        else if (fSource != null)
                        {
                            type  = fSource.FieldType.FullName;
                            value = fSource.GetValue(obj).ToString();
                            SRInfoHelper.Log("Found " + type + " named " + pDest.Name + " with value " + value);

                            result.SetMemberValue(pi.Name, fSource.GetValue(obj));
                        }
                    }
                }
            }

            // We get properties from the destination type instead of the source type
            foreach (FieldInfo pi in destFields)
            {
                // set pDest to the currently instanced property type
                FieldInfo fDest = destinationType.GetField(pi.Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

                var pSource = sourceProps.Where(s => s.Name == pi.Name).FirstOrDefault();
                var fSource = sourceFields.Where(s => s.Name == pi.Name).FirstOrDefault();

                if (pSource != null)
                {
                    SRInfoHelper.Log("Field name " + pi.Name + " destination name " + pSource?.Name);
                }
                else
                {
                    SRInfoHelper.Log("Field name " + pi.Name + " destination name " + fSource?.Name);
                }

                if (pSource == null && fSource == null)
                {
                    SRInfoHelper.Log("No source found for field " + pi.Name + "Skipping");
                    continue;
                }

                if (fDest != null && fDest.IsPublic)
                {
                    if (fDest.FieldType.FullName == "UnityEngine.Sprite")
                    {
                        //SRInfoHelper.Log("Mapping sprite");
                        UnityEngine.Sprite destSprite   = (UnityEngine.Sprite)fDest.GetValue(result);
                        Sprite             sourceSprite = new Sprite();

                        if (pSource != null)
                        {
                            sourceSprite = (Sprite)pSource.GetValue(obj, null);
                        }
                        else if (fSource != null)
                        {
                            sourceSprite = (Sprite)fSource.GetValue(obj);
                        }
                        else
                        {
                            continue;
                        }

                        SRInfoHelper.Log("Mapping sprite " + sourceSprite);
                        if (sourceSprite == null || string.IsNullOrEmpty(sourceSprite.textureName))
                        {
                            continue;
                        }

                        UnityEngine.Sprite mappedSprite = ReflectionObjectBuilder <UnityEngine.Sprite>(sourceSprite);

                        SRInfoHelper.Log("Loading textures");

                        UnityEngine.Texture2D texture = null;
                        UnityEngine.Texture2D associatedAlphaSplitTexture = null;

                        if (!string.IsNullOrEmpty(sourceSprite.textureName))
                        {
                            texture = FileManager.LoadTextureFromFile(sourceSprite.textureName);

                            SRInfoHelper.Log("Loaded texture " + texture.name + " size " + texture.height + "x" + texture.width);
                        }
                        if (!string.IsNullOrEmpty(sourceSprite.associatedAlphaSplitTextureName))
                        {
                            associatedAlphaSplitTexture = FileManager.LoadTextureFromFile(sourceSprite.associatedAlphaSplitTextureName);
                            //mappedSprite.associatedAlphaSplitTexture.Resize(texture.width, texture.height);
                            SRInfoHelper.Log("Loaded alpha split texture " + associatedAlphaSplitTexture.name + " size " + associatedAlphaSplitTexture.height + "x" + associatedAlphaSplitTexture.width);

                            //mappedSprite.associatedAlphaSplitTexture.SetPixels(associatedAlphaSplitTexture.GetPixels());
                        }
                        //SRInfoHelper.Log("Creating Texture " + mappedSprite.rect + " " +mappedSprite.pivot);

                        var createdSprite = UnityEngine.Sprite.Create(texture, new UnityEngine.Rect(0, 0, texture.width, texture.height), new UnityEngine.Vector2(16, 16), 100);
                        //createdSprite.textureRect.position = mappedSprite.textureRect.position;
                        SRInfoHelper.Log("Loaded textures");

                        fDest.SetValue(result, createdSprite);
                        continue;
                    }

                    bool isCollection = fDest.FieldType.GetInterfaces()
                                        .Any(x => x == typeof(IEnumerable));

                    if (isCollection && fDest.FieldType.FullName != "System.String")
                    {
                        Type itemType = fDest.FieldType;
                        if (itemType.IsArray)
                        {
                            itemType = itemType.GetElementType();
                        }
                        //if (pSource.FieldType.GetGenericArguments().Any())
                        //    itemType = pSource.FieldType.GetGenericArguments().FirstOrDefault();

                        SRInfoHelper.Log("Found collection " + fDest.FieldType + " named " + fDest.Name + " namespace is " + itemType.FullName);

                        if (itemType.FullName.Contains("Syndicate"))
                        {
                            List <DTOs.ModifierData5L> modifiers = new List <DTOs.ModifierData5L>();

                            if (fSource != null)
                            {
                                foreach (var item in (IEnumerable)fSource.GetValue(obj))
                                {
                                    var mappedItem = ReflectionObjectBuilder <DTOs.ModifierData5L>(item);
                                    modifiers.Add(mappedItem);
                                }
                            }
                            else
                            {
                                foreach (var item in (IEnumerable)pSource.GetValue(obj, null))
                                {
                                    var mappedItem = ReflectionObjectBuilder <DTOs.ModifierData5L>(item);
                                    modifiers.Add(mappedItem);
                                }
                            }

                            fDest.SetValue(result, modifiers.ToArray());
                        }
                        else if (itemType.FullName == "ModifierData5L")
                        {
                            List <ModifierData5L> modifiers = new List <ModifierData5L>();

                            if (fSource != null)
                            {
                                foreach (var item in (IEnumerable)fSource.GetValue(obj))
                                {
                                    var mappedItem = ReflectionObjectBuilder <ModifierData5L>(item);
                                    modifiers.Add(mappedItem);
                                }
                            }
                            else
                            {
                                foreach (var item in (IEnumerable)pSource.GetValue(obj, null))
                                {
                                    var mappedItem = ReflectionObjectBuilder <ModifierData5L>(item);
                                    modifiers.Add(mappedItem);
                                }
                            }
                            fDest.SetValue(result, modifiers.ToArray());
                            //result.SetMemberValue(pi.Name, modifiers.ToArray());
                        }
                        else
                        {
                            if (pSource != null)
                            {
                                fDest.SetValue(result, pSource.GetValue(obj, null));
                            }
                            else if (fSource != null)
                            {
                                fDest.SetValue(result, fSource.GetValue(obj));
                            }
                        }
                        //result.SetMemberValue(pi.Name, obj.GetMemberValue(pi.Name));
                    }
                    // Make sure the current property name can be found in the reader
                    else
                    {
                        string value;
                        string type;
                        if (pSource != null)
                        {
                            type  = pSource.PropertyType.FullName;
                            value = pSource.GetValue(obj, null).ToString();
                            SRInfoHelper.Log("Found type of " + type + " named " + fDest.Name + " with value " + value);

                            fDest.SetValue(result, pSource.GetValue(obj, null));
                        }
                        else if (fSource != null)
                        {
                            type  = fSource.FieldType.FullName;
                            value = fSource.GetValue(obj).ToString();
                            SRInfoHelper.Log("Found " + type + " named " + fDest.Name + " with value " + value);
                            result.SetMemberValue(pi.Name, fSource.GetValue(obj));
                        }
                    }
                }
            }

            return(result);
        }
Example #7
0
 public Bitmap(UnityEngine.Texture2D original)
 {
     Color    = Color.White;
     uTexture = original;
 }
Example #8
0
 public CreatureHud2D()
 {
     _circleTexture = UnityEngine.Resources.Load <UnityEngine.Texture2D>("texture/circle");
     _circleStyle   = new UnityEngine.GUIStyle();
     _circleStyle.normal.background = _circleTexture;
 }
Example #9
0
        private void Rebuild2DCGCollider()
        {
            try {
                Init();
                if (!initialized)
                {
                    return;
                }

                float ppu = GetPPU();                                                   // get pixels per unit from GameSettings
                SpriteFactory.SF2DColliderGenHelper.Data data = script.CheckCollider(); // get the data we need from the helper script
                if (data == null)
                {
                    throw new System.Exception();
                }


                UnityEngine.Component alphaMeshCollider = script.GetComponent("AlphaMeshCollider");
                if (alphaMeshCollider == null)
                {
                    throw new System.Exception("No AlphaMeshCollider component was found on Sprite! If you have removed the 2D Collider Gen collider, please remove the helper component");
                }
                System.Type type_alphaMeshCollider = alphaMeshCollider.GetType();

                // Verify the 2D Collider Gen fields we need exist
                Verify2DCGFields(type_alphaMeshCollider);

                // Get the serialized objects
                UnityEditor.SerializedObject   so = new UnityEditor.SerializedObject(alphaMeshCollider);
                UnityEditor.SerializedProperty sp;
                so.Update();

                // CUSTOM TEX
                sp = so.FindProperty("mRegionIndependentParameters.mCustomTex");
                if (sp == null)
                {
                    FieldException("Required field not found!");
                }

                UnityEngine.Texture2D tex = FindFrameTexture(data.masterSprite);
                if (tex == null)
                {
                    UnityEngine.Debug.LogWarning("Frame texture not found! 2D Collider Gen mesh collider will not generate correctly.");
                }
                sp.objectReferenceValue = tex;

                // CUSTOM SCALE
                sp = so.FindProperty("mRegionIndependentParameters.mCustomScale");
                if (sp == null)
                {
                    FieldException("Required field not found!");
                }

                UnityEngine.Vector2 scale = data.pixelScale / ppu; // convert pixel scale to units
                sp.vector2Value = scale;                           // update scale

                // FLIP
                UnityEngine.Vector2 offset = data.unitOffset; // get offset which is affected by flip

                // FLIP X
                sp = so.FindProperty("mRegionIndependentParameters.mFlipHorizontal");
                if (sp == null)
                {
                    FieldException("Required field not found!");
                }

                if (sp.boolValue != data.isFlippedX)
                {
                    sp.boolValue = data.isFlippedX;
                }
                if (data.isFlippedX)
                {
                    offset.x *= -1.0f;
                }

                // FLIP Y
                sp = so.FindProperty("mRegionIndependentParameters.mFlipVertical");
                if (sp == null)
                {
                    FieldException("Required field not found!");
                }

                if (sp.boolValue != data.isFlippedY)
                {
                    sp.boolValue = data.isFlippedY;
                }
                if (data.isFlippedY)
                {
                    offset.y *= -1.0f;
                }

                // CUSTOM OFFSET
                sp = so.FindProperty("mRegionIndependentParameters.mCustomOffset");
                if (sp == null)
                {
                    FieldException("Required field not found!");
                }

                sp.vector3Value = offset; // update offset

                // Finish up with the serialized object
                so.ApplyModifiedProperties();

                // Rebuild the 2DCG collider
                type_alphaMeshCollider.InvokeMember("RecalculateCollider", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.InvokeMethod, null, alphaMeshCollider, null);
            } catch (System.Exception e) {
                UnityEngine.Debug.LogError(e.Message);
                UnityEngine.Debug.LogError("STACK TRACE: " + e.StackTrace);
            }
        }
Example #10
0
 protected override void OnUpdate()
 {
     Entities.WithAll <ChunkMap>().ForEach((Entity e, ref ChunkMap chunkMap) =>
     {
         if (chunkMap.dirty == 2)
         {
             // create texture
             UnityEngine.Texture2D mapTexture = new UnityEngine.Texture2D(
                 chunkMap.width, chunkMap.height,
                 UnityEngine.Experimental.Rendering.DefaultFormat.LDR,
                 //UnityEngine.Experimental.Rendering.DefaultFormat.HDR,
                 UnityEngine.Experimental.Rendering.TextureCreationFlags.None);
             if (mapTexture == null)
             {
                 World.EntityManager.RemoveComponent <ChunkMap>(e);
                 //UnityEngine.Debug.LogError("Map Texture [" + chunkMap.chunkPosition +  "] created for chunk was null.");
                 return;
             }
             mapTexture.filterMode      = UnityEngine.FilterMode.Point;
             UnityEngine.Color[] pixels = new UnityEngine.Color[chunkMap.width * chunkMap.height];
             mapTexture.name            = "ChunkMap_" + chunkMap.chunkPosition.x + "_" + chunkMap.chunkPosition.y + "_" + chunkMap.chunkPosition.z;
             int xzIndex = 0;
             for (int i = 0; i < chunkMap.width; i++)
             {
                 for (int j = 0; j < chunkMap.height; j++)
                 {
                     //int xzIndex = i + j * chunkMap.height;
                     byte voxel = chunkMap.topVoxels[xzIndex];
                     if (voxel == 0)
                     {
                         pixels[xzIndex] = UnityEngine.Color.black;
                     }
                     else if (voxel == 1)
                     {
                         pixels[xzIndex] = UnityEngine.Color.green;
                     }
                     else if (voxel == 2)
                     {
                         pixels[xzIndex] = UnityEngine.Color.red;
                     }
                     else if (voxel == 3)
                     {
                         pixels[xzIndex] = UnityEngine.Color.blue;
                     }
                     else if (voxel == 4)
                     {
                         pixels[xzIndex] = UnityEngine.Color.yellow;
                     }
                     else
                     {
                         pixels[xzIndex] = UnityEngine.Color.magenta;
                     }
                     int height = (int)chunkMap.heights[xzIndex];
                     //float colorBrightness = 3 * ((float)height / (float)chunkMap.highestHeight);
                     pixels[xzIndex] *= ((float)height / 64);                             //math.min(1, colorBrightness);
                     xzIndex++;
                 }
             }
             mapTexture.SetPixels(pixels);
             mapTexture.Apply();
             //Bootstrap.instance.debugMaps.Add(mapTexture);
             float2 mapPosition = new float2(chunkMap.chunkPosition.x, chunkMap.chunkPosition.z);
             if (maps.ContainsKey(mapPosition))
             {
                 if (maps[mapPosition] != null)
                 {
                     UnityEngine.GameObject.Destroy(maps[mapPosition]);
                 }
                 maps.Remove(mapPosition);
             }
             maps.Add(mapPosition, mapTexture);
             World.EntityManager.RemoveComponent <ChunkMap>(e);
         }
     });
 }
Example #11
0
        public void Bake()
        {
            var tSize = TextureSize;
            _bakedTexture = new Bitmap(tSize.Width, tSize.Height);

            // Clear baked texture with transparent color.
            for (int y = 0; y < _bakedTexture.Height; y++)
                for (int x = 0; x < _bakedTexture.Width; x++)
                    _bakedTexture.SetPixel(x, y, Color.Transparent);

            int xOffset = 0;
            for (int i = 0; i < Text.Length; i++)
            {
                if (_font.textureList.ContainsKey(Text[i]) == false) continue;
                var textC = _font.textureList[Text[i]];
                if (textC == null) continue;

                float _scale = _charSettings[i].Scale;
                Color _foreColor = _charSettings[i].ForeColor;

                float cX = xOffset + textC.OffsetX * _scale;
                float cY = GetCursor() - textC.OffsetY * _scale;
                float cW = textC.Texture.Width * _scale;
                float cH = textC.Texture.Height * _scale;
                float cA = textC.Advance * _scale;

                if (cW <= 0 || cH <= 0)
                {
                    // Skip
                }
                else
                {
                    var origPixels = textC.Texture.uTexture.GetPixels32();
                    var newTexture = new UnityEngine.Texture2D(textC.Texture.Width, textC.Texture.Height);
                    newTexture.name = "backedGlyphTexture";
                    newTexture.SetPixels32(origPixels);
                    newTexture.Apply();
                    // Scale texture if needed.
                    if ((int)cW != newTexture.width || (int)cH != newTexture.height)
                    {
                        TextureScaler.scale(newTexture, (int)cW, (int)cH);
                        //TextureScale.Bilinear(newTexture, (int)cW, (int)cH);
                        newTexture.Apply();
                    }

                    var newImagePixels = newTexture.GetPixels32();
                    for (int p = 0; p < newImagePixels.Length; p++)
                    {
                        // BlendMode: Multiply
                        var origColor = Color.FromUColor(newImagePixels[p]);
                        var blendColorA = (float)(origColor.A * _foreColor.A) / 255;
                        var blendColorR = (float)(origColor.R * _foreColor.R) / 255;
                        var blendColorG = (float)(origColor.G * _foreColor.G) / 255;
                        var blendColorB = (float)(origColor.B * _foreColor.B) / 255;
                        var blendColor = Color.FromArgb((int)blendColorA, (int)blendColorR, (int)blendColorG, (int)blendColorB);
                        newImagePixels[p] = blendColor.ToUColor();
                    }

                    _bakedTexture.uTexture.SetPixels32((int)cX, (int)cY, newTexture.width, newTexture.height, newImagePixels);
                }

                xOffset += (int)cA;
            }

            _bakedTexture.Apply();

            if (AutoSize)
                Size = tSize;
        }
Example #12
0
 private BitmapImplementation(UnityEngine.Texture2D bitmap)
 {
     Bitmap = bitmap;
 }
Example #13
0
 private BitmapImplementation(UnityEngine.Color32[] data, int width, int height)
 {
     Bitmap = new UnityEngine.Texture2D(width, height);
     Bitmap.SetPixels32(data);
 }
Example #14
0
 public Texture2D(UnityEngine.Texture2D unityTexture)
 {
     // TODO: Complete member initialization
     this.unityTexture = unityTexture;
 }
Example #15
0
 /** BGオンテクスチャ。設定。
  */
 public void SetBgOnTexture(UnityEngine.Texture2D a_texture)
 {
     this.bg_on_sprite.SetTexture(a_texture);
 }
        /** CoroutineMain
         */
        public System.Collections.IEnumerator CoroutineMain(Fee.File.OnFileCoroutine_CallBackInterface a_callback_interface, Fee.File.Path a_path)
        {
            //result
            this.result = null;

            //ロード。
            byte[] t_result_binary = null;
            {
                //開始。
                {
                    do
                    {
                        try{
                            bool t_result = Fee.Platform.Platform.GetInstance().LoadAndroidContentFile_Start(a_path);
                            if (t_result == true)
                            {
                                //成功。
                                break;
                            }
                            else
                            {
                                //キャンセルチェック。
                                if (a_callback_interface != null)
                                {
                                    if (a_callback_interface.OnFileCoroutine(0.0f) == false)
                                    {
                                        //エラー。
                                        this.result = new ResultType(null, "Cancel : LoadAndroidContentTextureFile : " + a_path.GetPath());
                                        yield break;
                                    }
                                }
                            }
                        }catch (System.Exception t_exception) {
                            //エラー。
                            this.result = new ResultType(null, "Unknown Error : LoadAndroidContentTextureFile : " + a_path.GetPath() + " : " + t_exception.Message);
                            yield break;
                        }

                        yield return(null);
                    }while(true);
                }

                //読み込み中。
                {
                    do
                    {
                        try{
                            if (Fee.Platform.Platform.GetInstance().LoadAndroidContentFile_IsComplate() == true)
                            {
                                byte[] t_result = Fee.Platform.Platform.GetInstance().LoadAndroidContentFile_GetResult();

                                if (t_result == null)
                                {
                                    //エラー。
                                    this.result = new ResultType(null, "Load Error : LoadAndroidContentTextureFile : " + a_path.GetPath());
                                    yield break;
                                }

                                //成功。
                                t_result_binary = t_result;
                                break;
                            }
                            else
                            {
                                //キャンセルチェック。
                                {
                                    if (a_callback_interface != null)
                                    {
                                        if (a_callback_interface.OnFileCoroutine(0.0f) == false)
                                        {
                                            Fee.Platform.Platform.GetInstance().LoadAndroidContentFile_Cancel();
                                        }
                                    }
                                }
                            }
                        }catch (System.Exception t_exception) {
                            //エラー。
                            this.result = new ResultType(null, "Load Error : LoadAndroidContentTextureFile : " + a_path.GetPath() + " : " + t_exception.Message);
                            yield break;
                        }

                        yield return(null);
                    }while(true);

                    //終了。
                    Fee.Platform.Platform.GetInstance().LoadAndroidContentFile_End();
                }
            }

            //コンバート。
            UnityEngine.Texture2D t_result_texture = null;
            {
                try{
                    UnityEngine.Texture2D t_result = BinaryToTexture2D.Convert(t_result_binary);

                    if (t_result == null)
                    {
                        //エラー。
                        this.result = new ResultType(null, "Convert Error : LoadAndroidContentTextureFile : " + a_path.GetPath());
                        yield break;
                    }

                    t_result_texture = t_result;
                }catch (System.Exception t_exception) {
                    //エラー。
                    this.result = new ResultType(null, "Convert Error : LoadAndroidContentTextureFile : " + a_path.GetPath() + " : " + t_exception.Message);
                    yield break;
                }
            }

            //成功。
            this.result = new ResultType(t_result_texture, null);
            yield break;
        }
 /// <summary>
 ///     Show the button texture
 /// </summary>
 /// <param name="texture">
 ///     A <see cref="UnityEngine.Texture2D" />
 /// </param>
 /// <returns>
 ///     A <see cref="System.Boolean" />
 /// </returns>
 protected bool ShowButtonTexture(UnityEngine.Texture2D texture)
 {
     return(UnityEngine.GUILayout.Button(texture, UnityEngine.GUILayout.MaxWidth(texture.width),
                                         UnityEngine.GUILayout.MaxHeight(texture.height)));
 }
Example #18
0
        /** 1枚のマップチップテクスチャーを分割する。
         *
         *      a_use_count == true : 重複する場合に名前を最後にカウントを付ける。
         *
         */
        public static void Parse(UnityEngine.Texture2D a_texture, int a_tip_pixsize, Fee.File.Path a_assets_path, bool a_use_count)
        {
            if (a_texture != null)
            {
                if (a_tip_pixsize > 0)
                {
                    if (((a_texture.width % a_tip_pixsize) != 0) || ((a_texture.height % a_tip_pixsize) != 0))
                    {
                        Tool.EditorLogError("Size Error");
                    }

                    int t_xx_max = a_texture.width / a_tip_pixsize;
                    int t_yy_max = a_texture.height / a_tip_pixsize;

                    for (int yy = 0; yy < t_yy_max; yy++)
                    {
                        for (int xx = 0; xx < t_xx_max; xx++)
                        {
                            //テクスチャー作成。
                            UnityEngine.Texture2D t_new_texture = Fee.EditorTool.AssetTool.CreateTextureFromTexture(a_texture, xx * a_tip_pixsize, yy * a_tip_pixsize, a_tip_pixsize, a_tip_pixsize);

                            //PNGコンバート。
                            byte[] t_binary = UnityEngine.ImageConversion.EncodeToPNG(t_new_texture);

                            //MD5.
                            string t_md5 = Fee.MD5.MD5.CalcMD5(t_binary, 0, t_binary.Length);

                            if (a_use_count == true)
                            {
                                //パス。
                                Fee.File.Path t_path = null;
                                {
                                    int t_count = 0;
                                    while (true)
                                    {
                                        if (t_count <= 0)
                                        {
                                            t_path = new File.Path(a_assets_path, t_md5 + ".png", Fee.File.Path.SEPARATOR);
                                        }
                                        else
                                        {
                                            t_path = new File.Path(a_assets_path, t_md5 + "_" + t_count.ToString() + ".png", Fee.File.Path.SEPARATOR);
                                        }

                                        //ファイル出力。
                                        if (Fee.EditorTool.AssetTool.IsExistFile(t_path) == false)
                                        {
                                            Fee.EditorTool.AssetTool.WriteBinaryFile(t_path, t_binary);
                                            break;
                                        }

                                        t_count++;
                                    }
                                }
                            }
                            else
                            {
                                //パス。
                                Fee.File.Path t_path = new Fee.File.Path(a_assets_path, t_md5 + ".png", Fee.File.Path.SEPARATOR);

                                //ファイル出力。
                                if (Fee.EditorTool.AssetTool.IsExistFile(t_path) == false)
                                {
                                    Fee.EditorTool.AssetTool.WriteBinaryFile(t_path, t_binary);
                                }
                            }
                        }
                    }
                }
                else
                {
                    Tool.EditorLogError("Error");
                }
            }
            else
            {
                Tool.EditorLogError("Error");
            }
        }
Example #19
0
            public AlphaPicker(int w, int h)
            {
                Alpha = 1;
                Size = new Size(w, h);

                _image = new UnityEngine.Texture2D(w, h);
                for (int i = 0; i < w; i++)
                {
                    int rgb = (int)(((float)i / w) * 255);
                    Color currentColor = Color.FromArgb(rgb, rgb, rgb);
                    for (int k = 0; k < h; k++)
                    {
                        _image.SetPixel(i, k, currentColor.ToUColor());
                    }
                }
                _image.Apply();

                Owner.UpClick += Application_UpClick;
            }
Example #20
0
        public unsafe UnityEngine.Texture2D RenderIntoTexture(char c)
        {
            int code;

            FT.FT_FaceRec facerec = FT.HandleToRecord<FT.FT_FaceRec>(face_);
            IntPtr slot = facerec.glyph;

            code = FT.FT_Load_Char(face_, c, FT.FT_LOAD_RENDER/*|FT.FT_LOAD_TARGET_NORMAL*/);
            if (code != 0) { return null; }

            FT.FT_GlyphSlotRec slotrec = FT.HandleToRecord<FT.FT_GlyphSlotRec>(slot);
            FTSharp.FT.FT_Bitmap  ftbm=slotrec.bitmap;

            UnityEngine.Texture2D texbuffer=new UnityEngine.Texture2D(ftbm.width,ftbm.rows,UnityEngine.TextureFormat.ARGB32,false);
            if (((int)ftbm.pixel_mode)!=2) {
            UnityEngine.Debug.LogError("Unsupported bitmap depth :"+((int)ftbm.pixel_mode).ToString());
            return null;
            }
            //  FT_PIXEL_MODE_MONO,
            //FT_PIXEL_MODE_GRAY,

            UnityEngine.Color32 [] clrs=texbuffer.GetPixels32();
            int i=0;

              // UNSAFE DOES NOT WORK IN THE WEB PLAYER !
            for (int y=0;y<ftbm.rows;y++) {
            int j=(((ftbm.rows-(1+y))*ftbm.pitch));
            byte * bo=((byte *)ftbm.buffer);
            for (int x=0;x<ftbm.width;x++) {
              clrs[i].a=clrs[i].r=clrs[i].g=clrs[i].b=(bo[j+x]);
              i++;
            }
            }
            texbuffer.SetPixels32(clrs);
            texbuffer.Apply();
            return texbuffer;
        }
Example #21
0
 public Bitmap(UnityEngine.Texture2D original, Color color)
 {
     Color    = color;
     uTexture = original;
 }
Example #22
0
 /** リクエスト。セーブローカル。テクスチャファイル。
  */
 public void RequestSaveLocalTextureFile(Path a_relative_path, UnityEngine.Texture2D a_texture)
 {
     this.request_type    = RequestType.SaveLocalTextureFile;
     this.request_path    = a_relative_path;
     this.request_texture = a_texture;
 }
Example #23
0
        /** CoroutineMain
         */
        public System.Collections.IEnumerator CoroutineMain(Fee.AssetBundleList.OnAssetBundleListCoroutine_CallBackInterface a_callback_interface, string a_assetbundle_name, string a_asset_name)
        {
            //result
            this.result = new ResultType();

            AssetBundleItem t_assetbundle_item = Fee.AssetBundleList.AssetBundleList.GetInstance().GetAssetBundleItem(a_assetbundle_name);

            if (t_assetbundle_item == null)
            {
                //失敗。
                this.result.errorstring = "Coroutine_LoadAssetBundleItemTextureFile : " + a_assetbundle_name;
                yield break;
            }

            if (t_assetbundle_item.assetbundle_dummy != null)
            {
                //ダミーアセットバンドルが設定されている。

                string t_path;
                if (t_assetbundle_item.assetbundle_dummy.asset_list.TryGetValue(a_asset_name, out t_path) == true)
                {
                    Fee.File.Item t_item = Fee.File.File.GetInstance().RequestLoad(File.File.LoadRequestType.LoadResourcesTextureFile, new File.Path(t_path));

                    do
                    {
                        if (a_callback_interface != null)
                        {
                            a_callback_interface.OnAssetBundleListCoroutine(t_item.GetResultProgress());
                        }
                        yield return(null);
                    }while(t_item.IsBusy() == true);

                    UnityEngine.Texture2D t_texture = null;

                    if (t_item.GetResultAssetType() == Asset.AssetType.Texture)
                    {
                        if (t_item.GetResultAssetTexture() != null)
                        {
                            t_texture = t_item.GetResultAssetTexture();
                        }
                    }

                    if (t_texture == null)
                    {
                        //失敗。
                        this.result.errorstring = "Coroutine_LoadAssetBundleItemTextureFile : " + a_assetbundle_name;
                        yield break;
                    }

                    this.result.asset_file = new Asset.Asset(Asset.AssetType.Texture, t_texture);
                }
                else
                {
                    //失敗。
                    this.result.errorstring = "Coroutine_LoadAssetBundleItemTextureFile : " + a_assetbundle_name;
                    yield break;
                }
            }
            else if (t_assetbundle_item.assetbundle_raw != null)
            {
                UnityEngine.AssetBundleRequest t_request = t_assetbundle_item.assetbundle_raw.LoadAssetAsync(a_asset_name);

                if (t_request == null)
                {
                    //失敗。
                    this.result.errorstring = "Coroutine_LoadAssetBundleItemTextureFile : " + a_assetbundle_name;
                    yield break;
                }

                do
                {
                    if (a_callback_interface != null)
                    {
                        a_callback_interface.OnAssetBundleListCoroutine(t_request.progress);
                    }
                    yield return(null);
                }while(t_request.isDone == false);

                UnityEngine.Texture2D t_texture = t_request.asset as UnityEngine.Texture2D;

                if (t_texture == null)
                {
                    //失敗。
                    this.result.errorstring = "Coroutine_LoadAssetBundleItemTextureFile : " + a_assetbundle_name;
                    yield break;
                }

                this.result.asset_file = new Asset.Asset(Asset.AssetType.Texture, t_texture);
            }
            else
            {
                Tool.Assert(false);
            }

            //失敗。
            this.result.errorstring = "Coroutine_LoadAssetBundleItemTextureFile : " + a_assetbundle_name;
            yield break;
        }
Example #24
0
        /** CoroutineMain
         */
        public System.Collections.IEnumerator CoroutineMain(Fee.File.OnFileCoroutine_CallBackInterface a_callback_interface, Fee.File.Path a_path)
        {
            //result
            this.result = null;

            //taskprogress_
            this.taskprogress = 0.0f;

            //ロード。
            byte[] t_result_binary = null;
            {
                //キャンセルトークン。
                Fee.TaskW.CancelToken t_cancel_token = new Fee.TaskW.CancelToken();

                //タスク起動。
                using (Fee.TaskW.Task <Task_LoadLocalBinaryFile.ResultType> t_task = Task_LoadLocalBinaryFile.Run(this, a_path, t_cancel_token)){
                    //終了待ち。
                    do
                    {
                        //キャンセルチェック。
                        {
                            if (a_callback_interface != null)
                            {
                                if (a_callback_interface.OnFileCoroutine(this.taskprogress) == false)
                                {
                                    t_cancel_token.Cancel();
                                }
                            }
                        }

                        yield return(null);
                    }while(t_task.IsEnd() == false);

                    //結果。
                    Task_LoadLocalBinaryFile.ResultType t_result = t_task.GetResult();

                    if (t_result.errorstring != null)
                    {
                        //エラー。
                        this.result = new ResultType(null, t_result.errorstring);
                        yield break;
                    }

                    if (t_task.IsSuccess() == false)
                    {
                        //エラー。
                        this.result = new ResultType(null, "Task Error : LoadLocalTextureFile : " + a_path.GetPath());
                        yield break;
                    }

                    if (t_result.binary == null)
                    {
                        //エラー。
                        this.result = new ResultType(null, "Unknown Error : LoadLocalTextureFile : " + a_path.GetPath());
                        yield break;
                    }

                    //成功。
                    t_result_binary = t_result.binary;
                }
            }

            //コンバート。
            UnityEngine.Texture2D t_result_texture = null;
            {
                t_result_texture = BinaryToTexture2D.Convert(t_result_binary);
                if (t_result_texture == null)
                {
                    //エラー。
                    this.result = new ResultType(null, "Convert Error : LoadLocalTextureFile : " + a_path.ToString());
                    yield break;
                }
            }

            //成功。
            this.result = new ResultType(t_result_texture, null);
            yield break;
        }
Example #25
0
 /// <summary>
 /// Draws the object on the specified <see cref="UnityEngine.Texture2D"/>.
 /// </summary>
 /// <param name="texture">The texture on which to draw the object.</param>
 /// <param name="xLeft">The X axis lower bound.</param>
 /// <param name="xRight">The X axis upper bound.</param>
 /// <param name="yBottom">The Y axis lower bound.</param>
 /// <param name="yTop">The Y axis upper bound.</param>
 public override void Draw(ref UnityEngine.Texture2D texture, float xLeft, float xRight, float yBottom, float yTop)
 => this.Draw(ref texture, xLeft, xRight, yBottom, yTop, ZMin, ZMax);
Example #26
0
 /** SetTexture
  */
 public void SetTexture(UnityEngine.Texture2D a_texture)
 {
     this.asset_type   = AssetType.Texture;
     this.asset_object = a_texture;
 }
Example #27
0
 public Bitmap(int width, int height)
 {
     Color = Color.White;
     uTexture = new UnityEngine.Texture2D(width, height);
 }
Example #28
0
        public void Bake()
        {
            var tSize = TextureSize;

            _bakedTexture = new Bitmap(tSize.Width, tSize.Height);

            // Clear baked texture with transparent color.
            for (int y = 0; y < _bakedTexture.Height; y++)
            {
                for (int x = 0; x < _bakedTexture.Width; x++)
                {
                    _bakedTexture.SetPixel(x, y, Color.Transparent);
                }
            }

            int xOffset = 0;

            for (int i = 0; i < Text.Length; i++)
            {
                if (_font.textureList.ContainsKey(Text[i]) == false)
                {
                    continue;
                }
                var textC = _font.textureList[Text[i]];
                if (textC == null)
                {
                    continue;
                }

                float _scale     = _charSettings[i].Scale;
                Color _foreColor = _charSettings[i].ForeColor;

                float cX = xOffset + textC.OffsetX * _scale;
                float cY = GetCursor() - textC.OffsetY * _scale;
                float cW = textC.Texture.Width * _scale;
                float cH = textC.Texture.Height * _scale;
                float cA = textC.Advance * _scale;

                if (cW <= 0 || cH <= 0)
                {
                    // Skip
                }
                else
                {
                    var origPixels = textC.Texture.uTexture.GetPixels32();
                    var newTexture = new UnityEngine.Texture2D(textC.Texture.Width, textC.Texture.Height);
                    newTexture.name = "backedGlyphTexture";
                    newTexture.SetPixels32(origPixels);
                    newTexture.Apply();
                    // Scale texture if needed.
                    if ((int)cW != newTexture.width || (int)cH != newTexture.height)
                    {
                        TextureScaler.scale(newTexture, (int)cW, (int)cH);
                        //TextureScale.Bilinear(newTexture, (int)cW, (int)cH);
                        newTexture.Apply();
                    }

                    var newImagePixels = newTexture.GetPixels32();
                    for (int p = 0; p < newImagePixels.Length; p++)
                    {
                        // BlendMode: Multiply
                        var origColor   = Color.FromUColor(newImagePixels[p]);
                        var blendColorA = (float)(origColor.A * _foreColor.A) / 255;
                        var blendColorR = (float)(origColor.R * _foreColor.R) / 255;
                        var blendColorG = (float)(origColor.G * _foreColor.G) / 255;
                        var blendColorB = (float)(origColor.B * _foreColor.B) / 255;
                        var blendColor  = Color.FromArgb((int)blendColorA, (int)blendColorR, (int)blendColorG, (int)blendColorB);
                        newImagePixels[p] = blendColor.ToUColor();
                    }

                    _bakedTexture.uTexture.SetPixels32((int)cX, (int)cY, newTexture.width, newTexture.height, newImagePixels);
                }

                xOffset += (int)cA;
            }

            _bakedTexture.Apply();

            if (AutoSize)
            {
                Size = tSize;
            }
        }
Example #29
0
        /** リクエスト。セーブ。テクスチャファイル。
         */
        public Item RequestSaveTextureFile(SaveRequestType a_request_type, Path a_relative_path, UnityEngine.Texture2D a_texture)
        {
            switch (a_request_type)
            {
            case SaveRequestType.SaveLocalTextureFile:
            {
                WorkItem t_work_item = new WorkItem();
                t_work_item.RequestSaveLocalTextureFile(a_relative_path, a_texture);
                this.add_list.Add(t_work_item);
                return(t_work_item.GetItem());
            } break;
            }

            Tool.Assert(false);
            return(null);
        }
Example #30
0
 public Bitmap(int width, int height)
 {
     tex = new UnityEngine.Texture2D(width, height, UnityEngine.TextureFormat.RGB24, false);
 }
Example #31
0
 /** BGノーマルテクスチャ。設定。
  */
 public void SetBgNormalTexture(UnityEngine.Texture2D a_texture)
 {
     this.bg_normal_sprite.SetTexture(a_texture);
 }
        static int _m_Create_xlua_st_(RealStatePtr L)
        {
            ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);



            int __gen_param_count = LuaAPI.lua_gettop(L);

            try {
                if (__gen_param_count == 3 && translator.Assignable <UnityEngine.Texture2D>(L, 1) && translator.Assignable <UnityEngine.Rect>(L, 2) && translator.Assignable <UnityEngine.Vector2>(L, 3))
                {
                    UnityEngine.Texture2D texture = (UnityEngine.Texture2D)translator.GetObject(L, 1, typeof(UnityEngine.Texture2D));
                    UnityEngine.Rect      rect; translator.Get(L, 2, out rect);
                    UnityEngine.Vector2   pivot; translator.Get(L, 3, out pivot);

                    UnityEngine.Sprite __cl_gen_ret = UnityEngine.Sprite.Create(texture, rect, pivot);
                    translator.Push(L, __cl_gen_ret);



                    return(1);
                }
                if (__gen_param_count == 4 && translator.Assignable <UnityEngine.Texture2D>(L, 1) && translator.Assignable <UnityEngine.Rect>(L, 2) && translator.Assignable <UnityEngine.Vector2>(L, 3) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4))
                {
                    UnityEngine.Texture2D texture = (UnityEngine.Texture2D)translator.GetObject(L, 1, typeof(UnityEngine.Texture2D));
                    UnityEngine.Rect      rect; translator.Get(L, 2, out rect);
                    UnityEngine.Vector2   pivot; translator.Get(L, 3, out pivot);
                    float pixelsPerUnit = (float)LuaAPI.lua_tonumber(L, 4);

                    UnityEngine.Sprite __cl_gen_ret = UnityEngine.Sprite.Create(texture, rect, pivot, pixelsPerUnit);
                    translator.Push(L, __cl_gen_ret);



                    return(1);
                }
                if (__gen_param_count == 5 && translator.Assignable <UnityEngine.Texture2D>(L, 1) && translator.Assignable <UnityEngine.Rect>(L, 2) && translator.Assignable <UnityEngine.Vector2>(L, 3) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 5))
                {
                    UnityEngine.Texture2D texture = (UnityEngine.Texture2D)translator.GetObject(L, 1, typeof(UnityEngine.Texture2D));
                    UnityEngine.Rect      rect; translator.Get(L, 2, out rect);
                    UnityEngine.Vector2   pivot; translator.Get(L, 3, out pivot);
                    float pixelsPerUnit = (float)LuaAPI.lua_tonumber(L, 4);
                    uint  extrude       = LuaAPI.xlua_touint(L, 5);

                    UnityEngine.Sprite __cl_gen_ret = UnityEngine.Sprite.Create(texture, rect, pivot, pixelsPerUnit, extrude);
                    translator.Push(L, __cl_gen_ret);



                    return(1);
                }
                if (__gen_param_count == 6 && translator.Assignable <UnityEngine.Texture2D>(L, 1) && translator.Assignable <UnityEngine.Rect>(L, 2) && translator.Assignable <UnityEngine.Vector2>(L, 3) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 5) && translator.Assignable <UnityEngine.SpriteMeshType>(L, 6))
                {
                    UnityEngine.Texture2D texture = (UnityEngine.Texture2D)translator.GetObject(L, 1, typeof(UnityEngine.Texture2D));
                    UnityEngine.Rect      rect; translator.Get(L, 2, out rect);
                    UnityEngine.Vector2   pivot; translator.Get(L, 3, out pivot);
                    float pixelsPerUnit = (float)LuaAPI.lua_tonumber(L, 4);
                    uint  extrude       = LuaAPI.xlua_touint(L, 5);
                    UnityEngine.SpriteMeshType meshType; translator.Get(L, 6, out meshType);

                    UnityEngine.Sprite __cl_gen_ret = UnityEngine.Sprite.Create(texture, rect, pivot, pixelsPerUnit, extrude, meshType);
                    translator.Push(L, __cl_gen_ret);



                    return(1);
                }
                if (__gen_param_count == 7 && translator.Assignable <UnityEngine.Texture2D>(L, 1) && translator.Assignable <UnityEngine.Rect>(L, 2) && translator.Assignable <UnityEngine.Vector2>(L, 3) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 5) && translator.Assignable <UnityEngine.SpriteMeshType>(L, 6) && translator.Assignable <UnityEngine.Vector4>(L, 7))
                {
                    UnityEngine.Texture2D texture = (UnityEngine.Texture2D)translator.GetObject(L, 1, typeof(UnityEngine.Texture2D));
                    UnityEngine.Rect      rect; translator.Get(L, 2, out rect);
                    UnityEngine.Vector2   pivot; translator.Get(L, 3, out pivot);
                    float pixelsPerUnit = (float)LuaAPI.lua_tonumber(L, 4);
                    uint  extrude       = LuaAPI.xlua_touint(L, 5);
                    UnityEngine.SpriteMeshType meshType; translator.Get(L, 6, out meshType);
                    UnityEngine.Vector4        border; translator.Get(L, 7, out border);

                    UnityEngine.Sprite __cl_gen_ret = UnityEngine.Sprite.Create(texture, rect, pivot, pixelsPerUnit, extrude, meshType, border);
                    translator.Push(L, __cl_gen_ret);



                    return(1);
                }
            } catch (System.Exception __gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e));
            }

            return(LuaAPI.luaL_error(L, "invalid arguments to UnityEngine.Sprite.Create!"));
        }
Example #33
0
 /** BGロックテクスチャ。設定。
  */
 public void SetBgLockTexture(UnityEngine.Texture2D a_texture)
 {
     this.bg_lock_sprite.SetTexture(a_texture);
 }
Example #34
0
 public Texture(string name, UnityEngine.Texture2D unityTexture)
 {
     this.name         = name;
     this.unityTexture = unityTexture;
 }
        public virtual void AssignDefaults()
        {
            // create new skin instance
            var skinHover      = UnityEngine.ScriptableObject.CreateInstance <UnityEngine.GUISkin>();
            var skinSelected   = UnityEngine.ScriptableObject.CreateInstance <UnityEngine.GUISkin>();
            var skinUnselected = UnityEngine.ScriptableObject.CreateInstance <UnityEngine.GUISkin>();

            skinHover.hideFlags      = UnityEngine.HideFlags.HideAndDontSave;
            skinSelected.hideFlags   = UnityEngine.HideFlags.HideAndDontSave;
            skinUnselected.hideFlags = UnityEngine.HideFlags.HideAndDontSave;

            // name the skins
            skinHover.name      = "Hover";
            skinSelected.name   = "Selected";
            skinUnselected.name = "Unselected";

            var tempWwisePath = "Assets/Wwise/Editor/WwiseWindows/TreeViewControl/";

            m_textureBlank = GetTexture(tempWwisePath + "blank.png");
            m_textureGuide = GetTexture(tempWwisePath + "guide.png");
            m_textureLastSiblingCollapsed   = GetTexture(tempWwisePath + "last_sibling_collapsed.png");
            m_textureLastSiblingExpanded    = GetTexture(tempWwisePath + "last_sibling_expanded.png");
            m_textureLastSiblingNoChild     = GetTexture(tempWwisePath + "last_sibling_nochild.png");
            m_textureMiddleSiblingCollapsed = GetTexture(tempWwisePath + "middle_sibling_collapsed.png");
            m_textureMiddleSiblingExpanded  = GetTexture(tempWwisePath + "middle_sibling_expanded.png");
            m_textureMiddleSiblingNoChild   = GetTexture(tempWwisePath + "middle_sibling_nochild.png");
            m_textureNormalChecked          = GetTexture(tempWwisePath + "normal_checked.png");
            m_textureNormalUnchecked        = GetTexture(tempWwisePath + "normal_unchecked.png");
            m_textureSelectedBackground     = GetTexture(tempWwisePath + "selected_background_color.png");

            m_skinHover      = skinHover;
            m_skinSelected   = skinSelected;
            m_skinUnselected = skinUnselected;

            SetBackground(m_skinHover.button, null);
            SetBackground(m_skinHover.toggle, null);
            SetButtonFontSize(m_skinHover.button);
            SetButtonFontSize(m_skinHover.toggle);
            RemoveMargins(m_skinHover.button);
            RemoveMargins(m_skinHover.toggle);
            SetTextColor(m_skinHover.button, UnityEngine.Color.yellow);
            SetTextColor(m_skinHover.toggle, UnityEngine.Color.yellow);

            SetBackground(m_skinSelected.button, m_textureSelectedBackground);
            SetBackground(m_skinSelected.toggle, m_textureSelectedBackground);
            SetButtonFontSize(m_skinSelected.button);
            SetButtonFontSize(m_skinSelected.toggle);
            RemoveMargins(m_skinSelected.button);
            RemoveMargins(m_skinSelected.toggle);
            SetTextColor(m_skinSelected.button, UnityEngine.Color.yellow);
            SetTextColor(m_skinSelected.toggle, UnityEngine.Color.yellow);

            SetBackground(m_skinUnselected.button, null);
            SetBackground(m_skinUnselected.toggle, null);
            SetButtonFontSize(m_skinUnselected.button);
            SetButtonFontSize(m_skinUnselected.toggle);
            RemoveMargins(m_skinUnselected.button);
            RemoveMargins(m_skinUnselected.toggle);

            if (UnityEditor.EditorPrefs.GetInt("UserSkin") == 1)
            {
                // Dark theme
                var darkBgColor = new UnityEngine.Color(51.0f / 255.0f, 51.0f / 255.0f, 51.0f / 255.0f);
                SetTextColor(m_skinUnselected.button, UnityEngine.Color.white);
                SetTextColor(m_skinUnselected.toggle, UnityEngine.Color.white);
                SetBackgroundColor(m_skinUnselected.button, darkBgColor);
                SetBackgroundColor(m_skinUnselected.toggle, darkBgColor);
            }
            else
            {
                // Light theme
                var lightBgColor = new UnityEngine.Color(165.0f / 255.0f, 165.0f / 255.0f, 165.0f / 255.0f);
                SetTextColor(m_skinUnselected.button, UnityEngine.Color.black);
                SetTextColor(m_skinUnselected.toggle, UnityEngine.Color.black);
                SetBackgroundColor(m_skinUnselected.button, lightBgColor);
                SetBackgroundColor(m_skinUnselected.toggle, lightBgColor);
            }
        }
Example #36
0
 // Returns false and nulls |texture| if the file does not exist.
 private bool LoadTextureIfExists(out UnityEngine.Texture texture,
                        String path)
 {
     string full_path =
     KSPUtil.ApplicationRootPath + Path.DirectorySeparatorChar +
     "GameData" + Path.DirectorySeparatorChar +
     "Principia" + Path.DirectorySeparatorChar +
     "assets" + Path.DirectorySeparatorChar +
     path;
     if (File.Exists(full_path)) {
       var texture2d = new UnityEngine.Texture2D(2, 2);
       bool success = texture2d.LoadImage(
       File.ReadAllBytes(full_path));
       if (!success) {
     Log.Fatal("Failed to load texture " + full_path);
       }
       texture = texture2d;
       return true;
     } else {
       texture = null;
       return false;
     }
 }
Example #37
0
 public TextureSource(UnityEngine.Texture2D texture) : this(Texture.WrapTexture(texture,
                                                                                EnsureNativePointer(texture), texture.width, texture.height, texture.mipmapCount))
 {
 }
Example #38
0
            public HuePicker(int w, int h)
            {
                Size = new Size(w, h);

                _image = new UnityEngine.Texture2D(w, h);
                _UpdateImage();

                Owner.UpClick += Application_UpClick;
            }