Exemplo n.º 1
0
        public void OnEnable()
        {
            selected      = Tools.current;
            Tools.current = Tool.None;

            if (!loaded)
            {
                string[] paths = AssetDatabase.GetAllAssetPaths();
                foreach (string path in paths)
                {
                    if (path.StartsWith("Assets") || path.StartsWith("assets"))
                    {
                        AssetDatabase.LoadAssetAtPath(path, typeof(IsoDecoration));
                    }
                }

                IsoDecoration[] isoDecorations = DecorationManager.getInstance().textureList();
                foreach (var id in isoDecorations)
                {
                    if (id.nCols * id.nRows > maxTile)
                    {
                        maxTile = id.nCols * id.nRows;
                    }
                }
                loaded = true;
            }

#if UNITY_EDITOR
            m_LastEditorUpdateTime    = Time.realtimeSinceStartup;
            EditorApplication.update += OnEditorUpdate;
#endif
        }
Exemplo n.º 2
0
 public static DecorationManager getInstance()
 {
     if (instance == null)
     {
         instance = new DecorationManagerInstance();
     }
     return(instance);
 }
Exemplo n.º 3
0
        public void OnInspectorGUI()
        {
            GUIStyle style = new GUIStyle();

            EditorGUILayout.HelpBox("Press left button to put the textures over the faces of the cell. Hold shift and press left button to copy the current texture of the hovering face.", MessageType.None);
            EditorGUILayout.Space();

            parallelDecoration = EditorGUILayout.Toggle("Draw Parallel", parallelDecoration);
            EditorGUILayout.Space();

            autoanimate = EditorGUILayout.Toggle("Auto Animate", autoanimate);

            if (autoanimate)
            {
                FrameRate = float.Parse(EditorGUILayout.TextField("Frame Rate:", FrameRate.ToString()));

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel("Frame Secuence:", GUIStyle.none, titleStyle);
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.HelpBox("Let the frame secuence list empty if you want to use the default frame loop.", MessageType.None);
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();

                EditorGUILayout.BeginVertical();

                GUIContent btt = new GUIContent("Add Frame");
                Rect       btr = GUILayoutUtility.GetRect(btt, style);
                if (GUI.Button(btr, btt))
                {
                    if (FrameSecuence == null)
                    {
                        FrameSecuence = new int[0];
                    }
                    int[] tmpFrameSecuence = new int[FrameSecuence.Length + 1];
                    for (int i = 0; i < FrameSecuence.Length; i++)
                    {
                        tmpFrameSecuence[i] = FrameSecuence[i];
                    }
                    tmpFrameSecuence[tmpFrameSecuence.Length - 1] = 0;
                    FrameSecuence = tmpFrameSecuence;
                }
                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical();
                btt = new GUIContent("Remove Frame");
                btr = GUILayoutUtility.GetRect(btt, style);
                if (GUI.Button(btr, btt))
                {
                    if (FrameSecuence.Length > 0)
                    {
                        if (FrameSecuence == null)
                        {
                            FrameSecuence = new int[0];
                        }
                        int[] tmpFrameSecuence = new int[FrameSecuence.Length - 1];
                        for (int i = 0; i < FrameSecuence.Length - 1; i++)
                        {
                            tmpFrameSecuence[i] = FrameSecuence[i];
                        }
                        FrameSecuence = tmpFrameSecuence;
                    }
                }
                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();

                if (FrameSecuence != null)
                {
                    for (int i = 0; i < FrameSecuence.Length; i++)
                    {
                        FrameSecuence[i] = int.Parse(EditorGUILayout.TextField(i.ToString(), FrameSecuence[i].ToString()));
                    }
                }
            }
            EditorGUILayout.Space();

            EditorGUILayout.PrefixLabel("Decoration Objects", GUIStyle.none, titleStyle);

            GUI.backgroundColor = Color.Lerp(Color.black, Color.gray, 0.5f);

            EditorGUILayout.BeginVertical("Box");

            IsoDecoration[] isoDecorations = DecorationManager.getInstance().textureList();

            int   maxTextures  = 8;
            float anchoTextura = (Screen.width - 30) / maxTextures;

            if (isoDecorations.Length > maxTextures * LTSS)
            {
                scroll = EditorGUILayout.BeginScrollView(scroll, GUILayout.MaxHeight(anchoTextura * LTSS));
            }

            Event e = Event.current;

            int currentTexture = 0;

            foreach (IsoDecoration it in isoDecorations)
            {
                if (it.getTexture() == null)
                {
                    continue;
                }

                if (currentTexture == 0)
                {
                    EditorGUILayout.BeginHorizontal();
                }

                Rect auxRect = GUILayoutUtility.GetRect(anchoTextura, anchoTextura);
                Rect border  = new Rect(auxRect);
                auxRect.x += 2; auxRect.y += 2; auxRect.width -= 4; auxRect.height -= 4;

                if (e.isMouse && border.Contains(e.mousePosition))
                {
                    if (e.type == EventType.MouseDown)
                    {
                        paintingIsoDecoration = it;
                        this.Repaint          = true;
                    }
                }

                if (it == paintingIsoDecoration)
                {
                    EditorGUI.DrawRect(border, Color.yellow);
                }

                Rect  textCoord   = it.getTextCoordsFor(currentTile);
                Rect  textureRect = new Rect(auxRect);
                float ratio       = (textCoord.height * it.getTexture().height) / (textCoord.width * it.getTexture().width);
                if (ratio < 1)
                {
                    float yCenter = auxRect.y + auxRect.height / 2.0f;
                    textureRect = new Rect(auxRect.x, yCenter - (auxRect.height / 2f) * ratio, auxRect.width, auxRect.height * ratio);
                }
                else
                {
                    float inverseRatio = 1 / ratio;
                    float xCenter      = auxRect.x + auxRect.width / 2.0f;
                    textureRect = new Rect(xCenter - (auxRect.width / 2f) * inverseRatio, auxRect.y, auxRect.width * inverseRatio, auxRect.height);
                }

                GUI.DrawTextureWithTexCoords(textureRect, it.getTexture(), textCoord);

                currentTexture++;
                if (currentTexture == maxTextures)
                {
                    EditorGUILayout.EndHorizontal(); currentTexture = 0;
                }
            }

            if (currentTexture != 0)
            {
                GUILayoutUtility.GetRect((maxTextures - currentTexture) * anchoTextura, anchoTextura);
                EditorGUILayout.EndHorizontal();
            }

            if (isoDecorations.Length > maxTextures * LTSS)
            {
                EditorGUILayout.EndScrollView();
            }


            EditorGUILayout.EndVertical();
        }
Exemplo n.º 4
0
 public void setTexture(Texture2D texture)
 {
     this.realTexture = texture;
     DecorationManager.getInstance().update(this);
 }