// Update is called once per frame void Update() { if (_cachedDebug != _debug) { _renderStrategy.SetDebug(_debug); _cachedDebug = _debug; } // If the user changes what kind of rendering they want, update if (_cachedInstanceRendering != _instancedRendering) { ToggleInstancedRendering(); } // If the user changes how many meshes or unique objects they want, create new renderings if (_cachedNumMeshes != _totalNumMeshes || !ArrayEquals(_objs, _cachedObjs)) { InitializeInfo(); _renderStrategy.Destroy(); if (_instancedRendering == true) { _renderStrategy = new Instanced(this.gameObject, _objs, _objMat, _computeShader, _objInfo, _totalNumMeshes); } else { _renderStrategy = new Instantiated(this.gameObject, _objs, _objMat, _computeShader, _objInfo, _totalNumMeshes); } _renderStrategy.SetDebug(_debug); _renderStrategy.SetNormalMapsEnabled(_normalMapsEnabled); _cachedNumMeshes = _totalNumMeshes; _cachedObjs = new GameObject[_objs.Length]; _cachedObjs = (GameObject[])_objs.Clone(); } // IF the user changes whether or not they want to be using normal maps or not if (_cachedNormalMapsEnabled != _normalMapsEnabled) { _renderStrategy.SetNormalMapsEnabled(_normalMapsEnabled); _cachedNormalMapsEnabled = _normalMapsEnabled; } // Update our objects based on our render strategy _renderStrategy.UpdateMeshes(); }
/* * CLASS DOCUMENTATION: ObjRenderer * This class acts as a layer and user interface. It has a series of objects in its slice that move * with it, as well as giving the option to have the objects rendered in different forms: * Instantiated GameObjects * GPU Instanced */ // Use this for initialization void Start() { InitializeInfo(); // Initialize our new RenderStrategy _renderStrategy = new Instantiated(this.gameObject, _objs, _objMat, _computeShader, _objInfo, _totalNumMeshes); _renderStrategy.SetDebug(_debug); _cachedInstanceRendering = _instancedRendering; _cachedNumMeshes = _totalNumMeshes; _cachedObjs = new GameObject[_objs.Length]; _cachedObjs = (GameObject[])_objs.Clone(); _cachedDebug = _debug; _cachedNormalMapsEnabled = _normalMapsEnabled; }