// Use this for initialization void Awake() { int layer = LayerMask.NameToLayer(layerName); renderSource = GetComponentInChildren <EntityRenderSource>(); if (!Validate(layer)) { return; } renderSource.controller = this; // backwards compatibility renderOutput = GetComponentInChildren <EntityRenderOutput>(); if (renderOutput == null) { GameObject renderOutputGO = GameObject.CreatePrimitive(PrimitiveType.Quad); renderOutputGO.AddComponent <EntityRenderOutput>(); renderOutput = renderOutputGO.GetComponent <EntityRenderOutput>(); renderOutput.transform.parent = transform; renderOutput.GetComponent <MeshRenderer>().material = new Material(Shader.Find("Sprites/Default")); renderOutput.name = "EntityRenderOutput"; GameObject.DestroyImmediate(renderOutput.GetComponent <MeshCollider>()); renderOutput.gameObject.layer = renderSource.gameObject.layer; } renderOutput.controller = this; renderOutputMeshRenderer = renderOutput.GetComponent <MeshRenderer>(); renderOutputMeshRenderer.sortingOrder = orderInLayer; renderOutputMeshRenderer.sortingLayerID = sortingLayer; renderOutput.transform.localPosition = renderSource.transform.localPosition - (Vector3)renderOuputLocalPosition; renderOutput.transform.localScale = new Vector3( textureWidth * outputScale * pixelsPerUnit, textureHeight * outputScale * pixelsPerUnit, 1 ); postProcessor = Instantiate( postProcessorRef, new Vector3(curX + (textureWidth * .5f * pixelsPerUnit) + 1, textureHeight * .5f * pixelsPerUnit, -10), Quaternion.identity ); curX += textureWidth * pixelsPerUnit; postProcessor.SetupTexture(new Vector2Int(textureWidth, textureHeight), depth, filterMode, gameObject.name, pixelsPerUnit); postProcessor.cullingMask = LayerMask.GetMask(layerName); postProcessor.name = string.Format("{0} PostProcessor", gameObject.name); renderSource.transform.parent = postProcessor.transform; renderSource.transform.localPosition = new Vector3(renderOuputLocalPosition.x, renderOuputLocalPosition.y, 10); renderSource.gameObject.layer = LayerMask.NameToLayer(layerName); Transform[] children = renderSource.GetComponentsInChildren <Transform>(); foreach (Transform child in children) { child.gameObject.layer = renderSource.gameObject.layer; } renderOutputMeshRenderer.material.SetTexture("_MainTex", postProcessor.renderTexture); }
public override void OnInspectorGUI() { EntityRenderOutput entity = (EntityRenderOutput)target; EditorGUILayout.Space(); var headerRect = GUILayoutUtility.GetRect(0.0f, 5.0f); headerRect.width = headerTexture.width; headerRect.height = headerTexture.height; GUILayout.Space(headerRect.height); GUI.DrawTexture(headerRect, headerTexture); }