/// <summary> /// Replicate entire gameobject as only empty gameobjects and colliders. /// </summary> internal static Ghost CreateRewindGhost(IHaunted haunted) { Scene holdscene = SceneManager.GetActiveScene(); SceneManager.SetActiveScene(ghostScene); /// Create the root of the Ghost GameObject ghostGO = new GameObject("ghst." + haunted.GameObject.name); #if !UNITY_2019_1_OR_NEWER /// For old physx these ghosts are in the main scene, and need to be protected from scene changes Object.DontDestroyOnLoad(ghostGO); #endif SceneManager.SetActiveScene(holdscene); /// Add the Ghost component Ghost ghost = ghostGO.AddComponent <Ghost>(); /// TEST widget #if UNITY_EDITOR || DEVELOPMENT_BUILD var widgetYGO = GameObject.CreatePrimitive(PrimitiveType.Cylinder); Object.DestroyImmediate(widgetYGO.GetComponent <Collider>()); widgetYGO.transform.localScale = new Vector3(.1f, 3f, .1f); widgetYGO.transform.parent = ghostGO.transform; var widgetXGO = Object.Instantiate(widgetYGO, ghost.transform); widgetYGO.transform.Rotate(0f, 0f, 90f); var debugCross = new GameObject("Debug Cross"); debugCross.hideFlags = HideFlags.HideInHierarchy; debugCross.transform.parent = ghostGO.transform; widgetXGO.transform.parent = debugCross.transform; widgetYGO.transform.parent = debugCross.transform; ghost.debugRenderers = ghost.GetComponentsInChildren <Renderer>(); ghost.ShowDebugCross(false); #endif /// Initialize the Ghost component ghost.Initialize(haunted); colliderCount = 0; /// Start the recursion process CloneChildrenAndColliders(haunted.GameObject, ghostGO, ghost); return(ghost); }
public void Initialize(IHaunted haunted) { this.haunted = haunted; var iViewID = haunted.GameObject.GetComponent <IHasNetworkID>(); viewID = (iViewID != null) ? iViewID.ViewID : 0; /// Clone the RBs var hRB = haunted.GameObject.GetComponent <Rigidbody>(); var hRB2D = haunted.GameObject.GetComponent <Rigidbody2D>(); if (hRB) { rb = gameObject.AddComponent <Rigidbody>().GetCopyOf(hRB); } else if (hRB2D) { rb2d = gameObject.AddComponent <Rigidbody2D>().GetCopyOf(hRB2D); } }