Veilheim/Blueprints/Blueprint.cs
/// <summary>
///     Instantiate all pieces from this prefab under the stub piece
///     to generate a new piece representing the blueprint
/// </summary>
/// <param name="baseObject"></param>
/// <returns></returns>
Instantiate all pieces from this prefab under the stub piece
to generate a new piece representing the blueprint
Instantiate all pieces from this prefab under the stub piece to generate a new piece representing the blueprint
private bool GhostInstantiate(GameObject baseObject)
        {
            var ret = true;
            ZNetView.m_forceDisableInit = true;
            try
            {
                var pieces = new List<PieceEntry>(m_pieceEntries);
                var maxX = pieces.Max(x => x.posX);
                var maxZ = pieces.Max(x => x.posZ);
                var tf = baseObject.transform;
                tf.rotation = Camera.main.transform.rotation;
                var quat = new Quaternion();
                quat.eulerAngles = new Vector3(0, tf.rotation.eulerAngles.y, 0);
                tf.SetPositionAndRotation(tf.position, quat);
                tf.position -= tf.right * (maxX / 2f);
                tf.position += tf.forward * 5f;
                var prefabs = new Dictionary<string, GameObject>();
                foreach (var piece in pieces.GroupBy(x => x.name).Select(x => x.FirstOrDefault()))
                {
                    var go = PrefabManager.Instance.GetPrefab(piece.name);
                    go.transform.SetPositionAndRotation(go.transform.position, quat);
                    prefabs.Add(piece.name, go);
                }
                var nulls = prefabs.Values.Count(x => x == null);
                if (nulls > 0)
                {
                    throw new Exception($"{nulls} nulls found");
                }
                foreach (var piece in pieces)
                {
                    var pos = tf.position + tf.right * piece.GetPosition().x + tf.forward * piece.GetPosition().z +
                      new Vector3(0, piece.GetPosition().y, 0);
                    var q = new Quaternion();
                    q.eulerAngles = new Vector3(0, tf.transform.rotation.eulerAngles.y + piece.GetRotation().eulerAngles.y);
                    var child = Object.Instantiate(prefabs[piece.name], pos, q);
                    child.transform.SetParent(baseObject.transform);
                    foreach (var component in child.GetComponentsInChildren<MonoBehaviour>())
                    {
                        Object.Destroy(component);
                    }
                    ShaderHelper.UpdateTextures(child, ShaderHelper.ShaderState.Floating);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError($"Error while instantiating: {ex}");
                ret = false;
            }
            finally
            {
                ZNetView.m_forceDisableInit = false;
            }
            return ret;
        }
private bool GhostInstantiate ( GameObject baseObject ) { var ret = true ; ZNetView . m_forceDisableInit = true ; try { var pieces = new List < PieceEntry > ( m_pieceEntries ) ; var maxX = pieces . Max ( x => x . posX ) ; var maxZ = pieces . Max ( x => x . posZ ) ; var tf = baseObject . transform ; tf . rotation = Camera . main . transform . rotation ; var quat = new Quaternion ( ) ; quat . eulerAngles = new Vector3 ( 0 , tf . rotation . eulerAngles . y , 0 ) ; tf . SetPositionAndRotation ( tf . position , quat ) ; tf . position -= tf . right * ( maxX / 2f ) ; tf . position += tf . forward * 5f ; var prefabs = new Dictionary < string , GameObject > ( ) ; foreach ( var piece in pieces . GroupBy ( x => x . name ) . Select ( x => x . FirstOrDefault ( ) ) ) { var go = PrefabManager . Instance . GetPrefab ( piece . name ) ; go . transform . SetPositionAndRotation ( go . transform . position , quat ) ; prefabs . Add ( piece . name , go ) ; } var nulls = prefabs . Values . Count ( x => x == null ) ; if ( nulls > 0 ) { throw new Exception ( $" { nulls }  nulls found " ) ; } foreach ( var piece in pieces ) { var pos = tf . position + tf . right * piece . GetPosition ( ) . x + tf . forward * piece . GetPosition ( ) . z + new Vector3 ( 0 , piece . GetPosition ( ) . y , 0 ) ; var q = new Quaternion ( ) ; q . eulerAngles = new Vector3 ( 0 , tf . transform . rotation . eulerAngles . y + piece . GetRotation ( ) . eulerAngles . y ) ; var child = Object . Instantiate ( prefabs [ piece . name ] , pos , q ) ; child . transform . SetParent ( baseObject . transform ) ; foreach ( var component in child . GetComponentsInChildren < MonoBehaviour > ( ) ) { Object . Destroy ( component ) ; } ShaderHelper . UpdateTextures ( child , ShaderHelper . ShaderState . Floating ) ; } } catch ( Exception ex ) { Logger . LogError ( $" Error while instantiating:  { ex } " ) ; ret = false ; } finally { ZNetView . m_forceDisableInit = false ; } return ret ; }
Instantiate all pieces from this prefab under the stub piece
to generate a new piece representing the blueprint
Instantiate all pieces from this prefab under the stub piece to generate a new piece representing the blueprint
// Get max x/z from blueprint pieces // Get rotation relative to the camera // Get all distinct pieces // Check if all distinct pieces are found // Instantiate all pieces for the ghost prefab // A Ghost doesn't need fancy scripts // A Ghost also has to look like one
None
baseObject
GameObject
None