public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while (_cStream.HasUnreadData) { ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); CNetworkViewId cModuleGunViewId = _cStream.ReadNetworkViewId(); GameObject cModuleGunObject = cModuleGunViewId.GameObject; CToolInterface cToolInterface = cModuleGunObject.GetComponent <CToolInterface>(); CTorchLight cTorchLight = cModuleGunObject.GetComponent <CTorchLight>(); switch (eAction) { case ENetworkAction.TurnOnLight: cTorchLight.SetActive(true); break; case ENetworkAction.TurnOffLight: cTorchLight.SetActive(false); break; case ENetworkAction.ToggleColour: cTorchLight.ToggleColour(); break; default: Debug.LogError("Unknown network action: " + eAction); break; } } }
public void Start() { GetComponent <CToolInterface>().EventPrimaryActiveChange += (_bDown) => { if (_bDown) { s_cSerializeStream.Write((byte)ENetworkAction.OpenDui); s_cSerializeStream.Write(ThisNetworkView.ViewId); } }; GetComponent <CToolInterface>().EventSecondaryActiveChange += (_bDown) => { if (_bDown) { s_cSerializeStream.Write((byte)ENetworkAction.CloseDui); s_cSerializeStream.Write(ThisNetworkView.ViewId); } }; // Register the interaction events m_ToolInterface = gameObject.GetComponent <CToolInterface>(); // Register DUI events m_DUIModuleCreationRoot = m_DUI.GetComponent <CDUIConsole>().DUI.GetComponent <CDUIModuleCreationRoot>(); m_DUIModuleCreationRoot.EventBuildModuleButtonPressed += OnDUIBuildButtonPressed; // Configure DUI m_DUI.transform.position = m_InactiveUITransform.position; m_DUI.transform.rotation = m_InactiveUITransform.rotation; m_DUI.transform.localScale = m_InactiveUITransform.localScale; }
private void UpdateToolPresentation() { // Create a temp module string toolPrefabFile = CNetwork.Factory.GetRegisteredPrefabFile(CToolInterface.GetPrefabType(m_CurrentToolType.Get())); GameObject toolObject = (GameObject)GameObject.Instantiate(Resources.Load("Prefabs/" + toolPrefabFile)); // Destroy the old module if (m_ParentToolObject.transform.childCount != 0) { Destroy(m_ParentToolObject.transform.GetChild(0).gameObject); } // Update the tool info UpdateToolInfo(toolObject.GetComponent <CToolInterface>()); // Destroy the non rendering CUtility.DestroyAllNonRenderingComponents(toolObject); // Add it to the child object toolObject.transform.parent = m_ParentToolObject.transform; // Reset some values CUtility.SetLayerRecursively(toolObject, LayerMask.NameToLayer("UI 3D")); toolObject.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f); toolObject.transform.localRotation = Quaternion.identity; // Set the scale a lot smaller toolObject.transform.localScale = new Vector3(0.8f, 0.8f, 0.8f); }
public static void UnserializeInbound(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream) { while (_cStream.HasUnreadData) { ENetworkAction eAction = (ENetworkAction)_cStream.ReadByte(); CNetworkViewId cModuleGunViewId = _cStream.ReadNetworkViewId(); GameObject cModuleGunObject = cModuleGunViewId.GameObject; CToolInterface cToolInterface = cModuleGunObject.GetComponent <CToolInterface>(); CModuleGunBehaviour cModuleGunBehaviour = cModuleGunObject.GetComponent <CModuleGunBehaviour>(); switch (eAction) { case ENetworkAction.OpenDui: cModuleGunBehaviour.OpenDui(cToolInterface.OwnerPlayerActor.GetComponent <CPlayerInteractor>().TargetActorObject); break; case ENetworkAction.CloseDui: cModuleGunBehaviour.CloseDui(); break; default: Debug.LogError("Unknown network action"); break; } } }
private void SpawnTool(CToolInterface.EType _ToolType) { // Create a new object GameObject NewTool = CNetwork.Factory.CreateObject(CToolInterface.GetPrefabType(_ToolType)); // Set the tool's position NewTool.GetComponent <CNetworkView>().SetPosition(m_ToolSpawnLocation.position); NewTool.GetComponent <CNetworkView>().SetEulerAngles(m_ToolSpawnLocation.eulerAngles); }
private void SpawnTool(CToolInterface.EType _ToolType) { // Create a new object GameObject NewTool = CNetwork.Factory.CreateObject(CToolInterface.GetPrefabType(_ToolType)); // Set the tool's position NewTool.GetComponent<CNetworkView>().SetPosition(m_ToolSpawnLocation.position); NewTool.GetComponent<CNetworkView>().SetEulerAngles(m_ToolSpawnLocation.eulerAngles); }
void RegisterTools() { CToolInterface.RegisterPrefab(CToolInterface.EType.Ratchet, ENetworkPrefab.ToolRatchet); CToolInterface.RegisterPrefab(CToolInterface.EType.CircuitryKit, ENetworkPrefab.ToolCircuitryKit); CToolInterface.RegisterPrefab(CToolInterface.EType.Calibrator, ENetworkPrefab.ToolCalibrator); CToolInterface.RegisterPrefab(CToolInterface.EType.Fluidizer, ENetworkPrefab.ToolFluidizer); CToolInterface.RegisterPrefab(CToolInterface.EType.ModuleCreator, ENetworkPrefab.ToolModuleGun); CToolInterface.RegisterPrefab(CToolInterface.EType.FireExtinguisher, ENetworkPrefab.ToolExtinguisher); CToolInterface.RegisterPrefab(CToolInterface.EType.Norbert, ENetworkPrefab.ToolModuleGun); CToolInterface.RegisterPrefab(CToolInterface.EType.HealingKit, ENetworkPrefab.ToolMedical); CToolInterface.RegisterPrefab(CToolInterface.EType.AK47, ENetworkPrefab.ToolAk47); }
void OnTriggerExit(Collider TriggerObject) { CToolInterface cToolInterface = TriggerObject.GetComponent <CToolInterface>(); if (cToolInterface) { Rigidbody RB = TriggerObject.gameObject.rigidbody; if (RB) { RB.velocity = Vector3.zero; RB.angularVelocity = Vector3.zero; RB.useGravity = true; } } }
void OnTriggerStay(Collider TriggerObject) { CToolInterface cToolInterface = TriggerObject.GetComponent <CToolInterface>(); if (cToolInterface) { Rigidbody RB = TriggerObject.gameObject.rigidbody; if (RB) { RB.useGravity = false; RB.velocity = Vector3.zero; RB.angularVelocity = Vector3.zero; RB.AddForce(transform.right * -2.0f, ForceMode.Impulse); } } }
private void UpdateToolInfo(CToolInterface _tempToolInterface) { // DEBUG: Make a random sentance to describe it string desc = CUtility.LoremIpsum(6, 12, 2, 4, 1); m_SelectedToolType = _tempToolInterface.ToolType; m_SelectedToolCost = 100; // Set the name string name = CUtility.SplitCamelCase(m_SelectedToolType.ToString()); m_ToolNameLabel.text = name; // Set the desc m_ToolDescLabel.text = desc; // Set the cost m_ToolCostLabel.text = m_SelectedToolCost.ToString() + "N"; }
public void PickupTool(GameObject _cInteractableObject) { // Check object exists if (_cInteractableObject != null) { // Find free slot for (uint i = 0; i < ToolCapacity; ++i) { if (GetToolViewId(i) == null) { // Retrieve tool interface script CToolInterface cToolInterface = _cInteractableObject.GetComponent <CToolInterface>(); CNetworkView cToolNetworkView = _cInteractableObject.GetComponent <CNetworkView>(); // Check script found if (cToolInterface == null) { Debug.LogError(string.Format("Target tool does not have the CToolInterface component attached! ObjectName({0})", _cInteractableObject.name)); } else if (cToolInterface.IsHeld) { break; } else { m_acToolsViewId[i].Set(cToolNetworkView.ViewId); cToolInterface.NotifyPickedUp(m_ulOwnerPlayerId); ChangeTool((byte)i); // Commented out by Nathan to avoid extraneous debug information. // Feel free to uncomment for debugging purposes when required. //Debug.Log(string.Format("Picked up tool. PlayerId({0}) ToolObjectName({1}) SlotId({2})", _ulPlayerId, _cInteractableObject.name, i)); } break; } } } }
public void SetSelectedToolType(CToolInterface.EType _ToolType) { m_CurrentToolType.Set(_ToolType); }
public void Start() { GetComponent<CToolInterface>().EventPrimaryActiveChange += (_bDown) => { if (_bDown) { s_cSerializeStream.Write((byte)ENetworkAction.OpenDui); s_cSerializeStream.Write(ThisNetworkView.ViewId); } }; GetComponent<CToolInterface>().EventSecondaryActiveChange += (_bDown) => { if (_bDown) { s_cSerializeStream.Write((byte)ENetworkAction.CloseDui); s_cSerializeStream.Write(ThisNetworkView.ViewId); } }; // Register the interaction events m_ToolInterface = gameObject.GetComponent<CToolInterface>(); // Register DUI events m_DUIModuleCreationRoot = m_DUI.GetComponent<CDUIConsole>().DUI.GetComponent<CDUIModuleCreationRoot>(); m_DUIModuleCreationRoot.EventBuildModuleButtonPressed += OnDUIBuildButtonPressed; // Configure DUI m_DUI.transform.position = m_InactiveUITransform.position; m_DUI.transform.rotation = m_InactiveUITransform.rotation; m_DUI.transform.localScale = m_InactiveUITransform.localScale; }