Exemplo n.º 1
0
    private static void DrawAtlasEditor(OCAtlas atlas)
    {
        GUILayout.BeginVertical(GUI.skin.box);
        Material material = (Material)EditorGUILayout.ObjectField("Material", atlas.Material, typeof(Material), true);

        atlas.Material = material;

        int w = EditorGUILayout.IntField("Width", atlas.Width);

        if (w < 1)
        {
            w = 1;
        }
        atlas.Width = w;

        int h = EditorGUILayout.IntField("Height", atlas.Height);

        if (h < 1)
        {
            h = 1;
        }
        atlas.Height = h;

        bool alpha = EditorGUILayout.Toggle("Alpha", atlas.IsAlpha);

        atlas.IsAlpha = alpha;
        GUILayout.EndVertical();
    }
Exemplo n.º 2
0
        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Accessors and Mutators

        //---------------------------------------------------------------------------



        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Public Member Functions

        //---------------------------------------------------------------------------

        public virtual void Init(OCBlockSet blockSet)
        {
            _atlas = blockSet.GetAtlas(_atlasID);
            if (_atlas != null)
            {
                _alpha = _atlas.IsAlpha;
            }
        }
    private static XmlNode WriteAtlas(OCAtlas atlas, XmlDocument document)
    {
        XmlNode node = document.CreateElement("OCAtlas");

        FieldInfo[] fields = GetFields(atlas.GetType());
        foreach (FieldInfo field in fields)
        {
            if (field.FieldType.IsSubclassOf(typeof(UnityEngine.Object)))
            {
                XmlNode childNode = WriteAssetField(field, atlas, document);
                node.AppendChild(childNode);
            }
            else
            {
                XmlNode childNode = WriteField(field, atlas, document);
                node.AppendChild(childNode);
            }
        }
        return(node);
    }
Exemplo n.º 4
0
	//---------------------------------------------------------------------------

	#endregion

	//---------------------------------------------------------------------------

	#region Accessors and Mutators

	//---------------------------------------------------------------------------
		

			
	//---------------------------------------------------------------------------

	#endregion

	//---------------------------------------------------------------------------

	#region Public Member Functions

	//---------------------------------------------------------------------------

	public virtual void Init(OCBlockSet blockSet) {
		_atlas = blockSet.GetAtlas(_atlasID);
		if(_atlas != null) _alpha = _atlas.IsAlpha;
	}
Exemplo n.º 5
0
    private static void DrawFaceEditor(ref int face, OCAtlas atlas, ref UnityEngine.Matrix4x4 matrix)
    {
        UnityEngine.GUILayout.BeginVertical(UnityEngine.GUI.skin.box);
        UnityEngine.Texture texture = atlas.Texture;
        UnityEngine.Rect    rect    = UnityEngine.GUILayoutUtility.GetAspectRect((float)texture.width / texture.height);
        UnityEngine.GUILayout.EndVertical();

        UnityEngine.Matrix4x4 rectMatrix    = UnityEngine.Matrix4x4.Scale(new UnityEngine.Vector3(rect.width, rect.height, 0)) * matrix;
        UnityEngine.Matrix4x4 invRectMatrix = matrix.inverse * UnityEngine.Matrix4x4.Scale(new UnityEngine.Vector3(1 / rect.width, 1 / rect.height, 0));
        UnityEngine.Matrix4x4 invertY       = UnityEngine.Matrix4x4.TRS(new UnityEngine.Vector2(0, 1), UnityEngine.Quaternion.identity, new UnityEngine.Vector2(1, -1));

        bool mouseInRect = rect.Contains(UnityEngine.Event.current.mousePosition);

        UnityEngine.GUI.BeginGroup(rect);
        {
            UnityEngine.Vector2 mouse = invRectMatrix.MultiplyPoint(UnityEngine.Event.current.mousePosition);             // local mouse [0..1]

            if (UnityEngine.Event.current.type == UnityEngine.EventType.Repaint)
            {
                UnityEngine.Rect texturePosition = Mul(new UnityEngine.Rect(0, 0, 1, 1), rectMatrix);
                UnityEngine.Rect faceRet         = atlas.ToRect(face);
                faceRet = Mul(faceRet, rectMatrix * invertY);
                UnityEngine.GUI.DrawTexture(texturePosition, texture);
                BlockEditorUtils.DrawRect(faceRet, UnityEngine.Color.green);
            }

            if (UnityEngine.Event.current.type == UnityEngine.EventType.MouseDown && UnityEngine.Event.current.button == 0 && mouseInRect)
            {
                UnityEngine.Vector2 invMouse = invertY.MultiplyPoint(mouse);
                if (invMouse.x >= 0 && invMouse.x <= 1 && invMouse.y >= 0 && invMouse.y <= 1)
                {
                    int posX = UnityEngine.Mathf.FloorToInt(invMouse.x * atlas.Width);
                    int posY = UnityEngine.Mathf.FloorToInt(invMouse.y * atlas.Height);
                    face = posY * atlas.Width + posX;

                    UnityEngine.GUI.changed = true;
                    UnityEngine.Event.current.Use();
                }
            }

            if (UnityEngine.Event.current.type == UnityEngine.EventType.MouseDrag && UnityEngine.Event.current.button == 1 && mouseInRect)
            {
                UnityEngine.Vector3 delta = UnityEngine.Event.current.delta;
                delta.x /= rect.width;
                delta.y /= rect.height;

                UnityEngine.Matrix4x4 offsetMatrix = UnityEngine.Matrix4x4.TRS(delta, UnityEngine.Quaternion.identity, UnityEngine.Vector3.one);
                matrix = offsetMatrix * matrix;

                UnityEngine.GUI.changed = true;
                UnityEngine.Event.current.Use();
            }

            if (UnityEngine.Event.current.type == UnityEngine.EventType.ScrollWheel && mouseInRect)
            {
                float s = 0.95f;
                if (UnityEngine.Event.current.delta.y < 0)
                {
                    s = 1.0f / s;
                }

                UnityEngine.Matrix4x4 offsetMatrix = UnityEngine.Matrix4x4.TRS(mouse, UnityEngine.Quaternion.identity, UnityEngine.Vector3.one);
                matrix *= offsetMatrix;

                UnityEngine.Matrix4x4 scaleMatrix = UnityEngine.Matrix4x4.Scale(UnityEngine.Vector3.one * s);
                matrix *= scaleMatrix;

                offsetMatrix = UnityEngine.Matrix4x4.TRS(-mouse, UnityEngine.Quaternion.identity, UnityEngine.Vector3.one);
                matrix      *= offsetMatrix;

                UnityEngine.GUI.changed = true;
                UnityEngine.Event.current.Use();
            }
        }
        UnityEngine.GUI.EndGroup();
    }