1
TNet 3 Support / Re: TNManager.Create'ed objects doesn't initialize
« on: June 14, 2014, 08:25:48 AM »
Thanks for the reply!
I changed my code to look like this:
...but now TNet complains that "The game object was not found in the TNManager's list of objects." I tried adding the ThrowAwaySack prefab to TNManager, and while the error message went away a) I don't think that's the right colution (or is it?) and b) the ThrowAwaySack wasn't instantiated because OnCreate() is never run.
What am I doing wrong?
I changed my code to look like this:
- void Start () {
- playerCamera = PlayerController.instance.playerCamera;
- throwAwaySackResource = (GameObject)Resources.Load( "Prefabs/ThrowAwaySack" );
- }
- public void OnDragEnd ( dfControl source, dfDragEventArgs args ) {
- // Create a new ThrowAwaySack
- this.Create( throwAwaySackResource, playerCamera.transform.position, Quaternion.identity, false, args );
- // Mark as dropped
- args.State = dfDragDropState.Dropped;
- }
- }
- static public void Create ( GameObject prefab, Vector3 pos, Quaternion rot, bool persistent, dfDragEventArgs args ) {
- TNManager.CreateEx( 10, persistent, prefab, pos, rot, args );
- }
- [RCC(10)]
- static GameObject OnCreate ( GameObject prefab, Vector3 pos, Quaternion rot, dfDragEventArgs args ) {
- GameObject go = Instantiate( prefab, pos, rot ) as GameObject;
- // Populate the ThrowAwaySack's inventory
- InventoryController throwAwaySackInventoryController = go.GetComponent<InventoryController>();
- SlotPanelController slotPanelController = (SlotPanelController)args.Data;
- Slot sourceSlot = slotPanelController.slot;
- int itemsAdded = throwAwaySackInventoryController.AddItems( sourceSlot.items[0], sourceSlot.items.Count );
- sourceSlot.RemoveItems( sourceSlot.items[0], itemsAdded );
- return go;
- }
...but now TNet complains that "The game object was not found in the TNManager's list of objects." I tried adding the ThrowAwaySack prefab to TNManager, and while the error message went away a) I don't think that's the right colution (or is it?) and b) the ThrowAwaySack wasn't instantiated because OnCreate() is never run.
What am I doing wrong?