Exemplo n.º 1
0
 /// Unique id generator for GraphicInstance
 public static int GetUID(
     GraphicDef def,
     Color color,
     Texture2D texture,
     float drawPriority,
     Mesh mesh
     )
 {
     return(def.materialName.GetHashCode() + texture.GetHashCode() + color.GetHashCode() + drawPriority.GetHashCode() + mesh.GetHashCode());
 }
Exemplo n.º 2
0
        /// Get a new graphic instance (or an existing one)
        public static GraphicInstance GetNew(
            GraphicDef def,
            Color color        = default(Color),
            Texture2D texture  = null,
            float drawPriority = -42f,
            Mesh mesh          = null
            )
        {
            Mesh      _mesh     = (mesh == null) ? MeshPool.GetPlaneMesh(def.size) : mesh;
            Color     _color    = (color == default(Color)) ? def.color : color;
            Texture2D _texture  = (texture == null) ? Res.textures[def.textureName] : texture;
            float     _priority = (drawPriority == -42f) ? def.drawPriority : drawPriority;

            int id = GraphicInstance.GetUID(def, _color, _texture, _priority, _mesh);

            if (GraphicInstance.instances.ContainsKey(id))
            {
                return(GraphicInstance.instances[id]);
            }
            GraphicInstance.instances.Add(id, new GraphicInstance(id, def, _mesh, _color, _texture, _priority));
            return(GraphicInstance.instances[id]);
        }
Exemplo n.º 3
0
        /// Create a new graphic instance
        public GraphicInstance(
            int uid,
            GraphicDef def,
            Mesh mesh,
            Color color        = default(Color),
            Texture2D texture  = null,
            float drawPriority = -42f
            )
        {
            this.mesh                 = mesh;
            this.def                  = def;
            this.uid                  = uid;
            this.priority             = drawPriority / -100f;
            this.material             = new Material(Res.materials[def.materialName]);
            this.material.mainTexture = texture;
            this.texture              = texture;

            if (color != default(Color))
            {
                this.SetColor(color);
            }
        }