private void SendEmote(GameClient client, GameObject targetObject, eEmote emoteID, string emoteType) { string messageToSource = null; string messageToTarget = null; string messageToOthers = null; GamePlayer sourcePlayer = client.Player; bool targetMatters = false; if (targetObject != null) { messageToSource = LanguageMgr.GetTranslation(client, string.Format("HorseEmote.{0}.ToSource", emoteType), targetObject.GetName(0, false)); messageToOthers = LanguageMgr.GetTranslation(client, string.Format("HorseEmote.{0}.ToOthers", emoteType), sourcePlayer.Name, targetObject.GetName(0, false), sourcePlayer.GetPronoun(1, false)); if (targetObject is GamePlayer) messageToTarget = LanguageMgr.GetTranslation(client, string.Format("HorseEmote.{0}.ToOthers", emoteType), sourcePlayer.Name, LanguageMgr.GetTranslation(client, "HorseEmote.You"), sourcePlayer.GetPronoun(1, false)); if (messageToSource != "-" && messageToOthers != "-") targetMatters = true; } if (!targetMatters) { targetObject = null; messageToSource = LanguageMgr.GetTranslation(client, string.Format("HorseEmote.{0}.NoTargetToSource", emoteType)); messageToOthers = LanguageMgr.GetTranslation(client, string.Format("HorseEmote.{0}.NoTargetToOthers", emoteType), sourcePlayer.Name, sourcePlayer.GetPronoun(1, false)); } foreach (GamePlayer player in sourcePlayer.GetPlayersInRadius(WorldMgr.VISIBILITY_DISTANCE)) player.Out.SendEmoteAnimation(sourcePlayer, emoteID); SendEmoteMessages(sourcePlayer, targetObject as GamePlayer, messageToSource, messageToTarget, messageToOthers); return; }
public void OnStart() { offPointLightColor = new Color(0.8f, 0.0f, 0.0f, 1.0f); onPointLightColor = new Color(0.0f, 0.8f, 0.0f, 1.0f); // Initialize into the common list GameObject camInMap; Common.AddCameraObjectToList(gameObject, out camInMap, out camInMapArea); CameraInMap inMapScript = GetScript <CameraInMap>(camInMapArea); inMapScript.SetTwin(gameObject); // Set in map to be able to direct to me (camInWorld) if (gameObject == Common.GetRCCarCam()) { inMapScript.isActive = true; // always default RCCar to active } prevXCurrRot = xCurrRot = 0.0f; prevYCurrRot = yCurrRot = 0.0f; UpdateVectors(); if (xRotationLimit == 0.0f && yRotationLimit == 0.0f) { shouldPhysicalCameraRotate = false; } for (uint i = 0; i < gameObject.transform.GetNumberOfChildren(); ++i) { GameObject childObj = gameObject.transform.GetChild(i).gameObject; if (childObj.GetName() == Common.nameForCamLight) { spotlight = childObj.RequireComponent <CLight>(); spotlight.SetDiffuse(new Color(0.706f, 0.96f, 0.714f, 1.0f)); // FFB4FCB6 // spotlight.SetRange(10.0f); // spotlight.SetSpot(10.0f); // spotlight.SetAtt(1.0f); // spotlight.SetLightType(CLight.LIGHTTYPE.SPOTLIGHT); spotlight.setEnabled(false); } else if (childObj.GetName() == Common.nameForCamPointLight) { pointlight = childObj.RequireComponent <CLight>(); SetPointLight(false); pointlight.setEnabled(true); } } mSound = gameObject.RequireComponent <CSound>(); mCamRotateID = mSound.GetUniqueEvent("CAM_ROTATE.vente", 1); }
public void SetBindToPhysicalCamera(GameObject camObj) { gameObjectParentedTo = camObj; gameObjectParentedToName = camObj.GetName(); // load back using CameraRotationLimit's x and y angles SetUpdateLookAtDirAndPosition(); // If the camObj is sticky camera, AND sticky camera is stuck on a non-static object isParentObjStatic = true; if (camObj == Common.GetStickyCamera()) { CTransform wallObj = camObj.transform.GetParent(); if (wallObj != null) { CPhysics phy = wallObj.gameObject.GetComponent<CPhysics>(); if (phy != null && phy.mColliderType != 0) { isParentObjStatic = false; } } } else if (camObj == Common.GetRCCarCam()) { isParentObjStatic = false; } }
public static T GetOrAddComponent <T>(this GameObject obj, string name = null) where T : Component { T t = default; if (name == null) { t = obj.GetComponent <T>(); if (t == null) { t = obj.AddComponent <T>(); } } else { Transform tf = obj.GetName(name); if (tf != null) { t = tf.GetComponent <T>(); if (t == null) { t = tf.gameObject.AddComponent <T>(); } } } return(t); }
private void _AssertPrefab(GameObject prefab) { if (prefab.GetComponent <NetworkView>().IsNullOrDestroyed()) { throw new ArgumentException("prefab '" + prefab.GetName() + "' is missing a root NetworkView component", "prefab"); } }
void OnContact() { Debug.Log("[yellow]Contact Start"); CompCollider col = GetComponent <CompCollider>(); GameObject collided_obj = col.GetCollidedObject(); Vector3 point = col.GetContactPoint(); Vector3 normal = col.GetContactNormal(); // DAMAGE --- Debug.Log("[error] Collided"); if (collided_obj != null && destroyed == false) { /* PLAY AUDIO */ //GetComponent<CompAudio>().PlayEvent("TheonImpact"); //Lock transform to avoid trespassing more than one collider rb.LockTransform(); Debug.Log("[yellow] OnContact"); Debug.Log("[yellow]" + collided_obj.GetName()); } if (destroyed == false) { Destroy(gameObject); destroyed = true; } }
// send emote animation to all visible players and format messages private void SendEmote(GamePlayer sourcePlayer, GameObject targetObject, eEmote emoteID, string[] emoteMessages) { string messageToSource = null; string messageToTarget = null; string messageToOthers = null; if (targetObject == null) { messageToSource = emoteMessages[EMOTE_NOTARGET_TO_SOURCE]; messageToOthers = string.Format(emoteMessages[EMOTE_NOTARGET_TO_OTHERS], sourcePlayer.Name); } else { messageToSource = string.Format(emoteMessages[EMOTE_TO_SOURCE], targetObject.GetName(0, false)); messageToOthers = string.Format(emoteMessages[EMOTE_TO_OTHERS], sourcePlayer.Name, targetObject.GetName(0, false)); if (targetObject is GamePlayer) { messageToTarget = string.Format(emoteMessages[EMOTE_TO_OTHERS], sourcePlayer.Name, YOU); } } foreach (GamePlayer player in sourcePlayer.GetPlayersInRadius(WorldMgr.VISIBILITY_DISTANCE)) { if (!player.IsIgnoring(sourcePlayer)) { player.Out.SendEmoteAnimation(sourcePlayer, emoteID); } } SendEmoteMessages(sourcePlayer, targetObject as GamePlayer, messageToSource, messageToTarget, messageToOthers); return; }
public void SetBindToPhysicalCamera(GameObject camObj) { gameObjectParentedTo = camObj; gameObjectParentedToName = camObj.GetName(); // load back using CameraRotationLimit's x and y angles SetUpdateLookAtDirAndPosition(); // If the camObj is sticky camera, AND sticky camera is stuck on a non-static object isParentObjStatic = true; if (camObj == Common.GetStickyCamera()) { CTransform wallObj = camObj.transform.GetParent(); if (wallObj != null) { CPhysics phy = wallObj.gameObject.GetComponent <CPhysics>(); if (phy != null && phy.mColliderType != 0) { isParentObjStatic = false; } } } else if (camObj == Common.GetRCCarCam()) { isParentObjStatic = false; } }
public static void CMD_AppendNumber(GameObject obj) { IEnumerable <GameObject> objenum = null; if (obj.transform.GetParent() == null) { objenum = EngineManagerViewModel.instance.CurrentGameObjects.AsEnumerable <GameObject>(); } else { Converters.CTransformListToGameObjectListConverter conv = new Converters.CTransformListToGameObjectListConverter(); objenum = (conv.Convert(obj.transform.GetParent().children, null, null, null) as ObservableCollection <GameObject>).AsEnumerable <GameObject>(); } string obj_name = obj.GetName(); for (int i = 0; i < obj_name.Length; ++i) { if (char.IsDigit(obj_name[i])) { obj_name = obj_name.Remove(i); break; } } obj_name = obj_name.Trim(); int index = objenum.Count(new Func <GameObject, bool>((GameObject g) => { return(g.GetName().Contains(obj_name)); })); obj.SetName(obj_name + " " + index.ToString()); }
public void SetDisableCameraToStatic() { gameObjectParentedTo = noiseStatic; gameObjectParentedToName = noiseStatic.GetName(); Vector3 noiseNormal = noiseStatic.transform.GetForwardVector(); gameObject.transform.LookAt(-noiseNormal + gameObject.transform.position); gameObject.transform.SetPosition(noiseStatic.transform.position + 0.8f * noiseNormal); }
public Bar GetByName(string name) { foreach (Bar bar in bars) { if (bar.GetName() == name) { return(bar); } } return(new Bar(0, 0, 0, new List <GameObject>(), "NoSuchBar")); }
/// <summary> /// Creates the default <see cref="Creator"/> for the prefab and returns it. /// </summary> /// <param name="prefab">The prefab that you want to create a creator for.</param> /// <returns>The creator method.</returns> public static Creator CreateDefaultCreator(GameObject prefab) { var views = NetworkInstantiatorUtility.GetComponentsInChildren <NetworkView>(prefab.transform); if (views.Count == 0) { Log.Error(NetworkLogFlags.Instantiate, "Prefab '", prefab.GetName(), "' must at least have one NetworkView"); return(null); } return(_CreateDefaultCreator(prefab, views)); }
public void OnPointerClick(PointerEventData data) { // Der Name des Objektes selected = data.pointerEnter.gameObject; string element = data.pointerEnter.name; //Debug.Log("Clicked on Action: " + element); tree = FindObjectOfType <Skilltree>(); blurEffect.SetActive(true); darkenEffect.SetActive(true); actions = Game.play.GetActions(); foreach (Action action in actions) { if (action.GetId().ToString() == element) { active = action; //Debug.Log("Name: " + action.GetName() + " State: " + action.GetState()); switch (action.GetState()) { case State.Deactivated: ShowDeactivated(action); break; case State.Activated: ShowNormal(action); break; case State.InDevelopement: ShowInDevelopment(action); break; case State.Developed: ShowDeveloped(action); break; } headerText.text = action.GetName(); descrText.text = action.GetDescr(); costs.text = action.PrintCosts(); string eff = action.PrintEffects(); //Debug.Log("Back: " + eff); effects.text = eff; //Debug.Log("After: " + effects.text); status.text = "<b>Status: " + action.GetState().ToString() + "</b>"; requirements.text = action.PrintRequirements(actions); infoBox.SetActive(true); } } }
public int GetButtonIndex(GameObject obj) { if (allButtons.Count == 0) { string objName = ""; for (int i = 0; i < 4; ++i) { objName = Common.prefix; switch (i) { case 0: objName += "TSR2_DoorUnlockPanelStealthA"; break; case 1: objName += "TSR2_DoorUnlockPanelStealthB"; break; case 2: objName += "TSR2_DoorUnlockPanelStealthC"; break; case 3: objName += "TSR2_DoorUnlockPanelStealthD"; break; } GameObject panel = GameObject.GetGameObjectByName(objName); GameObject button = Common.GetChildByName(panel, "DoorUnlockButton"); GameObject buttonTriggered = Common.GetChildByName(button, "0"); allButtons.Add(GetScript <MiniGameFourPlayersButton>(buttonTriggered)); } //allButtons.Add(GetScript<MiniGameFourPlayersButton>(GameObject.GetGameObjectByName(Common.prefix + "TSR2_DoorUnlockPanelStealthB"))); //allButtons.Add(GetScript<MiniGameFourPlayersButton>(GameObject.GetGameObjectByName(Common.prefix + "TSR2_DoorUnlockPanelStealthC"))); //allButtons.Add(GetScript<MiniGameFourPlayersButton>(GameObject.GetGameObjectByName(Common.prefix + "TSR2_DoorUnlockPanelStealthD"))); } for (int i = 0; i < allButtons.Count; ++i) { string objName = ""; switch (i) { case 0: objName = "TSR2_DoorUnlockPanelStealthA"; break; case 1: objName = "TSR2_DoorUnlockPanelStealthB"; break; case 2: objName = "TSR2_DoorUnlockPanelStealthC"; break; case 3: objName = "TSR2_DoorUnlockPanelStealthD"; break; } GameObject panelParent = obj.transform.GetParent().GetParent().gameObject; if (objName == panelParent.GetName()) { return(i); } } Logger.Log("Bad init of minigame 4 player button, name: " + obj.GetName()); return(0); }
public static T GetScript <T>(GameObject g, bool logonerror = true) where T : MochaScript { T ret = MochaScriptSystem.ScriptSubsystemManaged.getInstance().GetScript(g, typeof(T).Name) as T; if (g == null) { Logger.Log("Could not find script " + typeof(T).Name + ", null object passed"); } if (ret == null && g != null && logonerror) { Logger.Log("Could not find script " + typeof(T).Name + " on object " + g.GetName()); } return(ret); }
public GameObjTreeViewItem(GameObject g) { gameObject = g; gameObjectName = g.GetName(); Header = new GameObjectViewItem(); (Header as GameObjectViewItem).DataContext = g; Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { this.Selected += GameObjTreeViewItem_Selected; this.Unselected += GameObjTreeViewItem_Unselected; })); EngineManagerViewModel.instance.SelectedGameObjects.CollectionChanged += SelectedGameObjects_CollectionChanged; }
public int GetButtonIndex(GameObject obj) { if (allButtons.Count == 0) { string objName = ""; for (int i = 0; i < 4; ++i) { objName = Common.prefix; switch (i) { case 0: objName += "TSR2_DoorUnlockPanelStealthA"; break; case 1: objName += "TSR2_DoorUnlockPanelStealthB"; break; case 2: objName += "TSR2_DoorUnlockPanelStealthC"; break; case 3: objName += "TSR2_DoorUnlockPanelStealthD"; break; } GameObject panel = GameObject.GetGameObjectByName(objName); GameObject button = Common.GetChildByName(panel, "DoorUnlockButton"); GameObject buttonTriggered = Common.GetChildByName(button, "0"); allButtons.Add(GetScript<MiniGameFourPlayersButton>(buttonTriggered)); } //allButtons.Add(GetScript<MiniGameFourPlayersButton>(GameObject.GetGameObjectByName(Common.prefix + "TSR2_DoorUnlockPanelStealthB"))); //allButtons.Add(GetScript<MiniGameFourPlayersButton>(GameObject.GetGameObjectByName(Common.prefix + "TSR2_DoorUnlockPanelStealthC"))); //allButtons.Add(GetScript<MiniGameFourPlayersButton>(GameObject.GetGameObjectByName(Common.prefix + "TSR2_DoorUnlockPanelStealthD"))); } for (int i = 0; i < allButtons.Count; ++i) { string objName = ""; switch (i) { case 0: objName = "TSR2_DoorUnlockPanelStealthA"; break; case 1: objName = "TSR2_DoorUnlockPanelStealthB"; break; case 2: objName = "TSR2_DoorUnlockPanelStealthC"; break; case 3: objName = "TSR2_DoorUnlockPanelStealthD"; break; } GameObject panelParent = obj.transform.GetParent().GetParent().gameObject; if (objName == panelParent.GetName()) { return i; } } Logger.Log("Bad init of minigame 4 player button, name: " + obj.GetName()); return 0; }
public static void CMD_AppendNumber(GameObject obj) { IEnumerable<GameObject> objenum = null; if (obj.transform.GetParent() == null) objenum = EngineManagerViewModel.instance.CurrentGameObjects.AsEnumerable<GameObject>(); else { Converters.CTransformListToGameObjectListConverter conv = new Converters.CTransformListToGameObjectListConverter(); objenum = (conv.Convert(obj.transform.GetParent().children,null, null, null) as ObservableCollection<GameObject>).AsEnumerable<GameObject>(); } string obj_name = obj.GetName(); for (int i = 0; i < obj_name.Length; ++i) { if (char.IsDigit(obj_name[i])) { obj_name = obj_name.Remove(i); break; } } obj_name = obj_name.Trim(); int index = objenum.Count(new Func<GameObject,bool>((GameObject g)=>{ return g.GetName().Contains(obj_name); })); obj.SetName(obj_name + " " + index.ToString()); }
public static int CompareCamInWorld(GameObject lhs, GameObject rhs) { return(CompareWordsAfterLength(lhs.GetName(), rhs.GetName(), nameForCamInWorld.Length)); }
// send emote animation to all visible players and format messages private void SendEmote(GamePlayer sourcePlayer, GameObject targetObject, eEmote emoteID, string[] emoteMessages) { string messageToSource = null; string messageToTarget = null; string messageToOthers = null; if (targetObject == null) { messageToSource = emoteMessages[EMOTE_NOTARGET_TO_SOURCE]; messageToOthers = string.Format(emoteMessages[EMOTE_NOTARGET_TO_OTHERS], sourcePlayer.Name); } else { messageToSource = string.Format(emoteMessages[EMOTE_TO_SOURCE], targetObject.GetName(0, false)); messageToOthers = string.Format(emoteMessages[EMOTE_TO_OTHERS], sourcePlayer.Name, targetObject.GetName(0, false)); if (targetObject is GamePlayer) messageToTarget = string.Format(emoteMessages[EMOTE_TO_OTHERS], sourcePlayer.Name, YOU); } foreach (GamePlayer player in sourcePlayer.GetPlayersInRadius(WorldMgr.VISIBILITY_DISTANCE)) if (!player.IsIgnoring(sourcePlayer)) player.Out.SendEmoteAnimation(sourcePlayer, emoteID); SendEmoteMessages(sourcePlayer, targetObject as GamePlayer, messageToSource, messageToTarget, messageToOthers); return; }
public void Tick() { if (!hasInit) { Init(); } while (actionQueue.Count != 0) { EditorAction a = actionQueue.Dequeue(); //Dispatcher.CurrentDispatcher.Invoke(a, DispatcherPriority.Normal); if (a == null) //wait frame { break; } a.a(); if (a.mres != null) { a.mres.Set(); a.mres.Dispose(); } } if (!EditorSubsystem.getInstance().IsTesting()) { //draw grid lines if (EngineCommandBindings.DrawGrid && EngineCommandBindings.GridSize > 0) { Vector3 camPos = EditorSubsystem.getInstance().EditorCamera().gameObject.transform.GetGlobalPosition(); float startX = camPos.X; float startY = camPos.Y; float startZ = camPos.Z; startX = startX - (startX % EngineCommandBindings.GridSize); if (startY > 0) { startY = startY - (startY % EngineCommandBindings.GridSize); } else { startY = startY + (startY % EngineCommandBindings.GridSize); } startZ = startZ - (startZ % EngineCommandBindings.GridSize); for (int y = (int)startY; y <= (int)startY + EngineCommandBindings.gridExtent / 2; y += EngineCommandBindings.GridSize) { //for every y, draw an x,z plane for (int x = (int)startX - EngineCommandBindings.gridExtent; x <= (int)startX + EngineCommandBindings.gridExtent; x += EngineCommandBindings.GridSize) { //draw z Renderer.getInstance().DrawLinePerma(new Vector3(x, y, startZ - EngineCommandBindings.gridExtent), new Vector3(x, y, startZ + EngineCommandBindings.gridExtent), new Color(0.39f, 0.60f, 0.93f, .5f)); for (int z = (int)startZ - EngineCommandBindings.gridExtent; z <= (int)startZ + EngineCommandBindings.gridExtent; z += EngineCommandBindings.GridSize) { //draw x Renderer.getInstance().DrawLinePerma(new Vector3(x - EngineCommandBindings.gridExtent, y, z), new Vector3(x + EngineCommandBindings.gridExtent, y, z), new Color(.4f, .4f, 0.0f, .3f)); } } } } //save occasionally autoSaveTimer += FrameController.DT(); if (autoSaveTimer > 30.0f) { QueueAction(() => { try { StateSerializer ss = new StateSerializer(); ss.DoRecoverySave(); } catch (Exception e) { Logger.Log("FAILED TO SAVE RECOVERY SAVE: " + e.Message); } }); autoSaveTimer = 0; } //occasionally check for available assets ++checkforChangedAssetsTimer; if (checkforChangedAssetsTimer > CHECKFORCHANGEDASSETS_TIME) { AssetManager.getInstance().CheckForChangedAssets(); checkforChangedAssetsTimer = 0; } //do standard updates if (Input.GetIsMouseInWindow(true) && EngineManagerViewModel.instance.EngineEmbedHasVisibility && EngineManagerViewModel.instance._isFocused) { //run sub systems auto_builder.Update(); //set tooltips mouseTooltipText.gameObject.transform.SetPosition(Input.GetMouseX(true) - Engine.getInstance().GetGameWnd().GetWindowWidth() * 0.5f, -(Input.GetMouseY(true) - Engine.getInstance().GetGameWnd().GetWindowHeight() * 0.5f), 0); editorStatusText.gameObject.transform.SetPosition(-Engine.getInstance().GetGameWnd().GetWindowWidth() * 0.49f, Engine.getInstance().GetGameWnd().GetWindowHeight() * 0.44f, 0); editorStatusText.mText = "--- STATUS ---\\n" + "Arrow Keys Snap Prec.: " + arrowSnapPrecision.ToString("0.0") + "\\nFPS: " + (1.0f / FrameController.DT()).ToString("0.0") + "\\n---------------"; CCamera editorCamera = EditorSubsystem.getInstance().EditorCamera(); if (Input.GetTriggered(0, "F2") == 1.0f) { //duplicate EngineCommandBindings.CMD_DuplicateObjects(); } //select objects naively GameObject gobj = GameObject.From(PhysicEngine.getInstance().RayCast3D(editorCamera.gameObject.transform.position, editorCamera.gameObject.transform.GetForwardVector(), editorCamera, Input.GetMouseX(true), Input.GetMouseY(true), 10000.0f)); if (gobj != null && gobj.GetFlag("ArtWidget")) { //select widget's actual object gobj = GameObject.From(EditorSubsystem.getInstance().widgetManager.GetAttachedObjFromWidgetObj(gobj)); } if (gobj != null && !gobj.GetFlag("Widget")) { //show tooltip if mouse over mouseTooltipText.mText = gobj.GetName(); //select if clicked on if (Input.GetTriggered(0, "MouseLClick") == 1.0f) { Application.Current.Dispatcher.Invoke(new Action(() => { try { if (Input.GetHeld(0, "AdditiveMod") == 1.0f) { GameObjectSelectionManager.RequestAdditiveSelect(gobj); } else { GameObjectSelectionManager.RequestSelect(gobj); } } catch (Exception e) { Console.WriteLine("Consumed Error in Hierarchy: " + e.ToString()); } } )); } } else { mouseTooltipText.mText = ""; } //rotate camera and move camera float dt = FrameController.getInstance().GetDeltaTime(); if (Input.GetHeld(0, "MoveFaster") == 1.0f) { dt *= 3; } Vector3 velocityThisFrame = new Vector3(); if (Input.GetHeld(0, "MouseRCLick") == 1.0f) { float dx = 0.25f * (Input.GetMouseDeltaX() * (3.14f / 180.0f)); float dy = 0.25f * (Input.GetMouseDeltaY() * (3.14f / 180.0f)); editorCamera.Pitch(dy); editorCamera.RotateY(dx); float val = Input.GetValue(0, "up"); velocityThisFrame.Z += val; val = Input.GetValue(0, "right"); velocityThisFrame.X += val; val = Input.GetValue(0, "down"); velocityThisFrame.Z -= val; val = Input.GetValue(0, "left"); velocityThisFrame.X -= val; cameraVelocity += velocityThisFrame; //cameraVelocity = cameraVelocity.Add(velocityThisFrame); //MathHelper.Clamp cameraVelocity.X = MathHelper.Clamp(cameraVelocity.X, -6, 6); cameraVelocity.Y = MathHelper.Clamp(cameraVelocity.Y, -6, 6); cameraVelocity.Z = MathHelper.Clamp(cameraVelocity.Z, -6, 6); //cameraVelocity.Clamp(-6.0f, 6.0f); } if (velocityThisFrame.X == 0) { cameraVelocity.X *= 0.9f; } if (velocityThisFrame.Z == 0) { cameraVelocity.Z *= 0.9f; } editorCamera.Walk(cameraVelocity.Z * dt); editorCamera.Strafe(cameraVelocity.X * dt); //look at if (_lookTimer != 0) { _lookTimer += FrameController.DT(); } if (_lookTimer > 1.3f) { _lookTimer = 0; } if (Input.GetTriggered(0, "LookAt") == 1.0f) { if (EngineManagerViewModel.instance.SelectedGameObjects.Count == 0) { return; } GameObject selobj = EngineManagerViewModel.instance.SelectedGameObjects[0]; if (_lookTimer == 0) { _lookTimer = 1; //force the setup if (selobj != null) { editorCamera.gameObject.transform.LookAt(selobj.transform.position); } } else { editorCamera.gameObject.transform.LookAt(selobj.transform.position); Vector3 forw = editorCamera.gameObject.transform.GetForwardVector(); editorCamera.gameObject.transform.SetPosition(selobj.transform.position - (forw * 8)); _lookTimer = 0; } } //arrow keys moving if (Input.GetTriggered(0, "Add") > 0) { arrowSnapPrecision += 0.1f; } if (Input.GetTriggered(0, "Sub") > 0) { arrowSnapPrecision -= 0.1f; } if (Input.GetTriggered(0, "ArrowUp") > 0) { foreach (var selobj in EngineManagerViewModel.instance.SelectedGameObjects) { selobj.transform.SetPositionZ(selobj.transform.position.z + arrowSnapPrecision); } } if (Input.GetTriggered(0, "ArrowDown") > 0) { foreach (var selobj in EngineManagerViewModel.instance.SelectedGameObjects) { selobj.transform.SetPositionZ(selobj.transform.position.z - arrowSnapPrecision); } } if (Input.GetTriggered(0, "ArrowRight") > 0) { foreach (var selobj in EngineManagerViewModel.instance.SelectedGameObjects) { selobj.transform.SetPositionX(selobj.transform.position.x + arrowSnapPrecision); } } if (Input.GetTriggered(0, "ArrowLeft") > 0) { foreach (var selobj in EngineManagerViewModel.instance.SelectedGameObjects) { selobj.transform.SetPositionX(selobj.transform.position.x - arrowSnapPrecision); } } } } }
protected static void RemoveItem(GameObject target, GamePlayer player, InventoryItem item, bool notify) { if (item == null) { log.Error("item is null in RemoveItem:" + Environment.StackTrace); return; } lock (player.Inventory) { if (item != null) { player.Inventory.RemoveItem(item); InventoryLogging.LogInventoryAction(player, target, eInventoryActionType.Quest, item.Template, item.Count); if (target != null) { player.Out.SendMessage("You give the " + item.Name + " to " + target.GetName(0, false), eChatType.CT_System, eChatLoc.CL_SystemWindow); } } else if (notify) { player.Out.SendMessage("You cannot remove the \"" + item.Name + "\" because you don't have it.", eChatType.CT_System, eChatLoc.CL_SystemWindow); } } }
public void HandlePacket(GameClient client, GSPacketIn packet) { if (client.Player == null) { return; } packet.ReadShort(); // id ushort toClientSlot = packet.ReadShort(); ushort fromClientSlot = packet.ReadShort(); ushort itemCount = packet.ReadShort(); // If our toSlot is > 1000 then target is a game object (not a window) with an ObjectID of toSlot - 1000 if (toClientSlot > 1000) { ushort objectId = (ushort)(toClientSlot - 1000); GameObject obj = WorldMgr.GetObjectByIDFromRegion(client.Player.CurrentRegionID, objectId); if (obj == null || obj.ObjectState != GameObject.eObjectState.Active) { client.Out.SendInventorySlotsUpdate(new int[] { fromClientSlot }); client.Out.SendMessage($"Invalid trade target. ({objectId})", eChatType.CT_System, eChatLoc.CL_SystemWindow); return; } GamePlayer tradeTarget = obj as GamePlayer; // If our target is another player we set the tradetarget // trade permissions are done in GamePlayer if (tradeTarget != null) { if (tradeTarget.Client.ClientState != GameClient.eClientState.Playing) { client.Out.SendInventorySlotsUpdate(new int[] { fromClientSlot }); client.Out.SendMessage("Can't trade with inactive players.", eChatType.CT_System, eChatLoc.CL_SystemWindow); return; } if (tradeTarget == client.Player) { client.Out.SendInventorySlotsUpdate(new int[] { fromClientSlot }); client.Out.SendMessage("You can't trade with yourself, silly!", eChatType.CT_System, eChatLoc.CL_SystemWindow); return; } if (!GameServer.ServerRules.IsAllowedToTrade(client.Player, tradeTarget, false)) { client.Out.SendInventorySlotsUpdate(new int[] { fromClientSlot }); return; } } // Is the item we want to move in our backpack? // we also allow drag'n drop from equipped to blacksmith if (fromClientSlot >= (ushort)eInventorySlot.FirstBackpack && fromClientSlot <= (ushort)eInventorySlot.LastBackpack || obj is Blacksmith && fromClientSlot >= (ushort)eInventorySlot.MinEquipable && fromClientSlot <= (ushort)eInventorySlot.MaxEquipable) { if (!obj.IsWithinRadius(client.Player, WorldMgr.GIVE_ITEM_DISTANCE)) { // show too far away message if (obj is GamePlayer player) { client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "PlayerMoveItemRequestHandler.TooFarAway", client.Player.GetName(player)), eChatType.CT_System, eChatLoc.CL_SystemWindow); } else { client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "PlayerMoveItemRequestHandler.TooFarAway", obj.GetName(0, false)), eChatType.CT_System, eChatLoc.CL_SystemWindow); } client.Out.SendInventorySlotsUpdate(new int[] { fromClientSlot }); return; } InventoryItem item = client.Player.Inventory.GetItem((eInventorySlot)fromClientSlot); if (item == null) { client.Out.SendInventorySlotsUpdate(new int[] { fromClientSlot }); client.Out.SendMessage($"Null item (client slot# {fromClientSlot}).", eChatType.CT_System, eChatLoc.CL_SystemWindow); return; } if (obj is GameNPC == false || item.Count == 1) { // see if any event handlers will handle this move client.Player.Notify(GamePlayerEvent.GiveItem, client.Player, new GiveItemEventArgs(client.Player, obj, item)); } // If the item has been removed by the event handlers, return; if (item.OwnerID == null) { client.Out.SendInventorySlotsUpdate(new int[] { fromClientSlot }); return; } // if a player to a GM and item is not dropable then don't allow trade???? This seems wrong. if (client.Account.PrivLevel == (uint)ePrivLevel.Player && tradeTarget != null && tradeTarget.Client.Account.PrivLevel != (uint)ePrivLevel.Player) { if (!item.IsDropable) { client.Out.SendInventorySlotsUpdate(new int[] { fromClientSlot }); client.Out.SendMessage("You can not remove this item!", eChatType.CT_System, eChatLoc.CL_SystemWindow); return; } } if (tradeTarget != null) { // This is a player trade, let trade code handle tradeTarget.ReceiveTradeItem(client.Player, item); client.Out.SendInventorySlotsUpdate(new int[] { fromClientSlot }); return; } if (obj.ReceiveItem(client.Player, item)) { // this object was expecting an item and handled it client.Out.SendInventorySlotsUpdate(new int[] { fromClientSlot }); return; } client.Out.SendInventorySlotsUpdate(new int[] { fromClientSlot }); return; } // Is the "item" we want to move money? For Version 1.78+ if (fromClientSlot >= (int)eInventorySlot.Mithril178 && fromClientSlot <= (int)eInventorySlot.Copper178) { fromClientSlot -= eInventorySlot.Mithril178 - eInventorySlot.Mithril; } // Is the "item" we want to move money? if (fromClientSlot >= (ushort)eInventorySlot.Mithril && fromClientSlot <= (ushort)eInventorySlot.Copper) { int[] money = new int[5]; money[fromClientSlot - (ushort)eInventorySlot.Mithril] = itemCount; long flatMoney = Money.GetMoney(money[0], money[1], money[2], money[3], money[4]); fromClientSlot += eInventorySlot.Mithril178 - eInventorySlot.Mithril; if (!obj.IsWithinRadius(client.Player, WorldMgr.GIVE_ITEM_DISTANCE)) { // show too far away message if (obj is GamePlayer player) { client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "PlayerMoveItemRequestHandler.TooFarAway", client.Player.GetName(player)), eChatType.CT_System, eChatLoc.CL_SystemWindow); } else { client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "PlayerMoveItemRequestHandler.TooFarAway", obj.GetName(0, false)), eChatType.CT_System, eChatLoc.CL_SystemWindow); } client.Out.SendInventorySlotsUpdate(new int[] { fromClientSlot }); return; } if (flatMoney > client.Player.GetCurrentMoney()) { client.Out.SendInventorySlotsUpdate(new int[] { fromClientSlot }); return; } client.Player.Notify(GamePlayerEvent.GiveMoney, client.Player, new GiveMoneyEventArgs(client.Player, obj, flatMoney)); if (tradeTarget != null) { tradeTarget.ReceiveTradeMoney(client.Player, flatMoney); client.Out.SendInventorySlotsUpdate(new int[] { fromClientSlot }); return; } if (obj.ReceiveMoney(client.Player, flatMoney)) { client.Out.SendInventorySlotsUpdate(new int[] { fromClientSlot }); return; } client.Out.SendInventorySlotsUpdate(new int[] { fromClientSlot }); return; } client.Out.SendInventoryItemsUpdate(null); return; } // We did not drop an item on a game object, which means we should have valid from and to slots // since we are moving an item from one window to another. // First check for an active InventoryObject if (client.Player.ActiveInventoryObject != null && client.Player.ActiveInventoryObject.MoveItem(client.Player, fromClientSlot, toClientSlot)) { // ChatUtil.SendDebugMessage(client, "ActiveInventoryObject handled move"); return; } // Do we want to move an item from immediate inventory to immediate inventory or drop on the ground if (((fromClientSlot >= (ushort)eInventorySlot.Ground && fromClientSlot <= (ushort)eInventorySlot.LastBackpack) || (fromClientSlot >= (ushort)eInventorySlot.FirstVault && fromClientSlot <= (ushort)eInventorySlot.LastVault) || (fromClientSlot >= (ushort)eInventorySlot.FirstBagHorse && fromClientSlot <= (ushort)eInventorySlot.LastBagHorse)) && ((toClientSlot >= (ushort)eInventorySlot.Ground && toClientSlot <= (ushort)eInventorySlot.LastBackpack) || (toClientSlot >= (ushort)eInventorySlot.FirstVault && toClientSlot <= (ushort)eInventorySlot.LastVault) || (toClientSlot >= (ushort)eInventorySlot.FirstBagHorse && toClientSlot <= (ushort)eInventorySlot.LastBagHorse))) { // We want to drop the item if (toClientSlot == (ushort)eInventorySlot.Ground) { InventoryItem item = client.Player.Inventory.GetItem((eInventorySlot)fromClientSlot); if (item == null) { client.Out.SendInventorySlotsUpdate(new int[] { fromClientSlot }); client.Out.SendMessage($"Invalid item (slot# {fromClientSlot}).", eChatType.CT_System, eChatLoc.CL_SystemWindow); return; } if (fromClientSlot < (ushort)eInventorySlot.FirstBackpack) { client.Out.SendInventorySlotsUpdate(new int[] { fromClientSlot }); return; } if (!item.IsDropable) { client.Out.SendInventorySlotsUpdate(new int[] { fromClientSlot }); client.Out.SendMessage("You can not drop this item!", eChatType.CT_System, eChatLoc.CL_SystemWindow); return; } if (client.Player.DropItem((eInventorySlot)fromClientSlot)) { client.Out.SendMessage($"You drop {item.GetName(0, false)} on the ground!", eChatType.CT_System, eChatLoc.CL_SystemWindow); return; } client.Out.SendInventoryItemsUpdate(null); return; } client.Player.Inventory.MoveItem((eInventorySlot)fromClientSlot, (eInventorySlot)toClientSlot, itemCount); // ChatUtil.SendDebugMessage(client, "Player.Inventory handled move"); return; } if (((fromClientSlot >= (ushort)eInventorySlot.Ground && fromClientSlot <= (ushort)eInventorySlot.LastBackpack) || (fromClientSlot >= (ushort)eInventorySlot.FirstVault && fromClientSlot <= (ushort)eInventorySlot.LastVault) || (fromClientSlot >= (ushort)eInventorySlot.FirstBagHorse && fromClientSlot <= (ushort)eInventorySlot.LastBagHorse)) && ((toClientSlot == (ushort)eInventorySlot.PlayerPaperDoll || toClientSlot == (ushort)eInventorySlot.NewPlayerPaperDoll) || (toClientSlot >= (ushort)eInventorySlot.Ground && toClientSlot <= (ushort)eInventorySlot.LastBackpack) || (toClientSlot >= (ushort)eInventorySlot.FirstVault && toClientSlot <= (ushort)eInventorySlot.LastVault) || (toClientSlot >= (ushort)eInventorySlot.FirstBagHorse && toClientSlot <= (ushort)eInventorySlot.LastBagHorse))) { InventoryItem item = client.Player.Inventory.GetItem((eInventorySlot)fromClientSlot); if (item == null) { return; } toClientSlot = 0; if (item.Item_Type >= (int)eInventorySlot.MinEquipable && item.Item_Type <= (int)eInventorySlot.MaxEquipable) { toClientSlot = (ushort)item.Item_Type; } if (toClientSlot == 0) { client.Out.SendInventorySlotsUpdate(new int[] { fromClientSlot }); return; } if (toClientSlot == (int)eInventorySlot.LeftBracer || toClientSlot == (int)eInventorySlot.RightBracer) { if (client.Player.Inventory.GetItem(eInventorySlot.LeftBracer) == null) { toClientSlot = (int)eInventorySlot.LeftBracer; } else { toClientSlot = (int)eInventorySlot.RightBracer; } } if (toClientSlot == (int)eInventorySlot.LeftRing || toClientSlot == (int)eInventorySlot.RightRing) { if (client.Player.Inventory.GetItem(eInventorySlot.LeftRing) == null) { toClientSlot = (int)eInventorySlot.LeftRing; } else { toClientSlot = (int)eInventorySlot.RightRing; } } client.Player.Inventory.MoveItem((eInventorySlot)fromClientSlot, (eInventorySlot)toClientSlot, itemCount); // ChatUtil.SendDebugMessage(client, "Player.Inventory handled move (2)"); return; } client.Out.SendInventoryItemsUpdate(null); }
public void OnUpdate() { if (isDoorUnlocked) { return; // Do not need any more updates once it has unlocked the doors } float dt = FrameController.DT(); // If flashing red, do not allow inputs if (isFlashingRed) { flashTimer -= dt; // update timer if (flashTimer <= 0.0f) { flashTimer += FLASH_DURATION; // reset the timer if (flashingState == 1) // if need to set red { pinPadDisplayBg.GetMaterial().SetColor(SharpMocha.RED); flashingState = 2; } else { flashingState = 1; pinPadDisplayBg.GetMaterial().SetColor(baseDisplayColor); if (flashCount++ >= 3) { // Clear the string pinPadDisplay.mText = "---"; currDigitIndex = 0; isFlashingRed = false; } } } } else { // Check if input 3 digits if (currDigitIndex >= 3) { if (pinPadDisplay.mText == CODE) // if correct { // Show green screen pinPadDisplayBg.GetMaterial().SetColor(SharpMocha.GREEN); // Unlock the doors doorScript.isLocked = false; /*Door top = GetScript<Door>(doorTop); * top.isLocked = false; * Door btm = GetScript<Door>(doorBtm); * btm.isLocked = false;*/ isDoorUnlocked = true; sound.PlayIndependentEvent("PINPAD_CONFIRM.vente", false, 0); } else { // Flash red isFlashingRed = true; flashingState = 1; flashTimer = 0.0f; // First update will trigger set to red flashCount = 0; sound.PlayIndependentEvent("PINPAD_DENY.vente", false, 0); } } // Only raycast and check if player is near the keypad Vector3 playerToKeypad = (Vector3)gameObject.transform.position - (Vector3)player.transform.position; if (Vector3.Dot(playerToKeypad, playerToKeypad) < 8.0f * 8.0f) { GameObject pickedObject = playerMouse.RayCastWithTag(Common.tagForPinPad); if (pickedObject != null) { // Mouse over of keypad effect if (playerScript.IsStealthPlayerInteracting()) { String digit = pickedObject.GetName().Substring(pinPadObjName.Length); if (digit.Length != 1) { Logger.Log("pinpad's digit is more than 1 digit!"); } InputPinPad(Convert.ToInt32(digit)); } } } // End of checking if player is near to keypad } }
public override void SendDamageMessages(AttackData ad) { GameObject target = ad.Target; InventoryItem weapon = ad.Weapon; GamePlayer player = Caster as GamePlayer; switch (ad.AttackResult) { case GameLiving.eAttackResult.TargetNotVisible: player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GamePlayer.Attack.NotInView", ad.Target.GetName(0, true)), eChatType.CT_YouHit, eChatLoc.CL_SystemWindow); break; case GameLiving.eAttackResult.OutOfRange: player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GamePlayer.Attack.TooFarAway", ad.Target.GetName(0, true)), eChatType.CT_YouHit, eChatLoc.CL_SystemWindow); break; case GameLiving.eAttackResult.TargetDead: player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GamePlayer.Attack.AlreadyDead", ad.Target.GetName(0, true)), eChatType.CT_YouHit, eChatLoc.CL_SystemWindow); break; case GameLiving.eAttackResult.Blocked: player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GamePlayer.Attack.Blocked", ad.Target.GetName(0, true)), eChatType.CT_YouHit, eChatLoc.CL_SystemWindow); break; case GameLiving.eAttackResult.Parried: player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GamePlayer.Attack.Parried", ad.Target.GetName(0, true)), eChatType.CT_YouHit, eChatLoc.CL_SystemWindow); break; case GameLiving.eAttackResult.Evaded: player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GamePlayer.Attack.Evaded", ad.Target.GetName(0, true)), eChatType.CT_YouHit, eChatLoc.CL_SystemWindow); break; case GameLiving.eAttackResult.NoTarget: player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GamePlayer.Attack.NeedTarget"), eChatType.CT_YouHit, eChatLoc.CL_SystemWindow); break; case GameLiving.eAttackResult.NoValidTarget: player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GamePlayer.Attack.CantBeAttacked"), eChatType.CT_YouHit, eChatLoc.CL_SystemWindow); break; case GameLiving.eAttackResult.Missed: player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GamePlayer.Attack.Miss"), eChatType.CT_YouHit, eChatLoc.CL_SystemWindow); break; case GameLiving.eAttackResult.Fumbled: player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GamePlayer.Attack.Fumble"), eChatType.CT_YouHit, eChatLoc.CL_SystemWindow); break; case GameLiving.eAttackResult.HitStyle: case GameLiving.eAttackResult.HitUnstyled: string modmessage = ""; if (ad.Modifier > 0) { modmessage = " (+" + ad.Modifier + ")"; } if (ad.Modifier < 0) { modmessage = " (" + ad.Modifier + ")"; } string hitWeapon = ""; switch (ServerProperties.Properties.SERV_LANGUAGE) { case "EN": if (weapon != null) { hitWeapon = GlobalConstants.NameToShortName(weapon.Name); } break; case "DE": if (weapon != null) { hitWeapon = weapon.Name; } break; default: if (weapon != null) { hitWeapon = GlobalConstants.NameToShortName(weapon.Name); } break; } if (hitWeapon.Length > 0) { hitWeapon = " " + LanguageMgr.GetTranslation(player.Client.Account.Language, "GamePlayer.Attack.WithYour") + " " + hitWeapon; } string attackTypeMsg = LanguageMgr.GetTranslation(player.Client.Account.Language, "GamePlayer.Attack.YouAttack"); // intercept messages if (target != null && target != ad.Target) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GamePlayer.Attack.Intercepted", ad.Target.GetName(0, true), target.GetName(0, false)), eChatType.CT_YouHit, eChatLoc.CL_SystemWindow); player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GamePlayer.Attack.InterceptedHit", attackTypeMsg, target.GetName(0, false), hitWeapon, ad.Target.GetName(0, false), ad.Damage, modmessage), eChatType.CT_YouHit, eChatLoc.CL_SystemWindow); } else { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GamePlayer.Attack.InterceptHit", attackTypeMsg, ad.Target.GetName(0, false), hitWeapon, ad.Damage, modmessage), eChatType.CT_YouHit, eChatLoc.CL_SystemWindow); } // critical hit if (ad.CriticalDamage > 0) { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GamePlayer.Attack.Critical", ad.Target.GetName(0, false), ad.CriticalDamage), eChatType.CT_YouHit, eChatLoc.CL_SystemWindow); } break; } }
/// <summary> /// Gets all the meshes and outputs to a string (even grabbing the child of each gameObject) /// </summary> /// <returns>The mesh to string.</returns> /// <param name="gameObj">GameObject Parent.</param> /// <param name="materials">Every Material in the parent that can be accessed.</param> /// <param name="objects">The StringBuidler to create objects for the FBX file.</param> /// <param name="connections">The StringBuidler to create connections for the FBX file.</param> /// <param name="parentObject">Parent object, if left null this is the top parent.</param> /// <param name="parentModelId">Parent model id, 0 if top parent.</param> public static long GetMeshToString(GameObject gameObj, Material[] materials, ref StringBuilder objects, ref StringBuilder connections, GameObject parentObject = null, long parentModelId = 0) { StringBuilder tempObjectSb = new StringBuilder(); StringBuilder tempConnectionsSb = new StringBuilder(); long geometryId = FBXExporter.GetRandomFBXId(); long modelId = FBXExporter.GetRandomFBXId(); // Sees if there is a mesh to export and add to the system MeshFilter filter = gameObj.ThreadSafe_GetComponent <MeshFilter>(); SkinnedMeshRenderer skinnedMesh = gameObj.ThreadSafe_GetComponent <SkinnedMeshRenderer>(); // The mesh to export is this level's mesh that is going to be exported Mesh meshToExport = ThreadSafeUtils.CreateMesh(); if (filter != null) { meshToExport = filter.GetSharedMesh(); } else if (skinnedMesh != null) // If this object has a skinned mesh on it, bake that mesh into whatever pose it is at and add it as a new mesh to export { meshToExport = new Mesh(); skinnedMesh.ThreadSafe_BakeMesh(meshToExport); } if (meshToExport == null) { Debug.LogError("Couldn't find a mesh to export"); } string meshName = gameObj.GetName(); // A NULL parent means that the gameObject is at the top string isMesh = "Null"; if (meshToExport != null) { meshName = meshToExport.GetName(); isMesh = "Mesh"; } if (filter != null) { if (filter.GetSharedMesh() == null) { // The MeshFilter has no mesh assigned, so treat it like an FBX Null node. filter = null; } else { meshName = filter.GetSharedMesh().GetName(); isMesh = "Mesh"; } } // If we've got a skinned mesh without a name, give it a random name if (meshName == "" && skinnedMesh != null) { meshName = "Skinned Mesh " + Random.Range(0, 1000000); } if (parentModelId == 0) { tempConnectionsSb.AppendLine("\t;Model::" + meshName + ", Model::RootNode"); } else { tempConnectionsSb.AppendLine("\t;Model::" + meshName + ", Model::USING PARENT"); } tempConnectionsSb.AppendLine("\tC: \"OO\"," + modelId + "," + parentModelId); tempConnectionsSb.AppendLine(); tempObjectSb.AppendLine("\tModel: " + modelId + ", \"Model::" + gameObj.GetName() + "\", \"" + isMesh + "\" {"); tempObjectSb.AppendLine("\t\tVersion: 232"); tempObjectSb.AppendLine("\t\tProperties70: {"); tempObjectSb.AppendLine("\t\t\tP: \"RotationOrder\", \"enum\", \"\", \"\",4"); tempObjectSb.AppendLine("\t\t\tP: \"RotationActive\", \"bool\", \"\", \"\",1"); tempObjectSb.AppendLine("\t\t\tP: \"InheritType\", \"enum\", \"\", \"\",1"); tempObjectSb.AppendLine("\t\t\tP: \"ScalingMax\", \"Vector3D\", \"Vector\", \"\",0,0,0"); tempObjectSb.AppendLine("\t\t\tP: \"DefaultAttributeIndex\", \"int\", \"Integer\", \"\",0"); // ===== Local Translation Offset ========= Vector3 position = gameObj.GetTransform().GetLocalPosition(); tempObjectSb.Append("\t\t\tP: \"Lcl Translation\", \"Lcl Translation\", \"\", \"A+\","); // Append the X Y Z coords to the system tempObjectSb.AppendFormat("{0},{1},{2}", FE.FBXFormat(position.GetX() * -1), FE.FBXFormat(position.GetY()), FE.FBXFormat(position.GetZ())); tempObjectSb.AppendLine(); // Rotates the object correctly from Unity space Vector3 localRotation = gameObj.GetTransform().GetLocalEulerAngles(); tempObjectSb.AppendFormat("\t\t\tP: \"Lcl Rotation\", \"Lcl Rotation\", \"\", \"A+\",{0},{1},{2}", FE.FBXFormat(localRotation.GetX()), FE.FBXFormat(localRotation.GetY() * -1), FE.FBXFormat(-1 * localRotation.GetZ())); tempObjectSb.AppendLine(); // Adds the local scale of this object Vector3 localScale = gameObj.GetTransform().GetLocalScale(); tempObjectSb.AppendFormat("\t\t\tP: \"Lcl Scaling\", \"Lcl Scaling\", \"\", \"A\",{0},{1},{2}", FE.FBXFormat(localScale.GetX()), FE.FBXFormat(localScale.GetY()), FE.FBXFormat(localScale.GetZ())); tempObjectSb.AppendLine(); tempObjectSb.AppendLine("\t\t\tP: \"currentUVSet\", \"KString\", \"\", \"U\", \"map1\""); tempObjectSb.AppendLine("\t\t}"); tempObjectSb.AppendLine("\t\tShading: T"); tempObjectSb.AppendLine("\t\tCulling: \"CullingOff\""); tempObjectSb.AppendLine("\t}"); // Adds in geometry if it exists, if it it does not exist, this is a empty gameObject file and skips over this if (meshToExport != null) { Mesh mesh = meshToExport; // ================================= // General Geometry Info // ================================= // Generate the geometry information for the mesh created tempObjectSb.AppendLine("\tGeometry: " + geometryId + ", \"Geometry::\", \"Mesh\" {"); // ===== WRITE THE VERTICIES ===== Vector3[] verticies = mesh.GetVertices(); int vertCount = mesh.GetVertexCount() * 3; // <= because the list of points is just a list of comma seperated values, we need to multiply by three tempObjectSb.AppendLine("\t\tVertices: *" + vertCount + " {"); tempObjectSb.Append("\t\t\ta: "); for (int i = 0; i < verticies.Length; i++) { if (i > 0) { tempObjectSb.Append(","); } // Points in the verticies. We also reverse the x value because Unity has a reverse X coordinate tempObjectSb.AppendFormat("{0},{1},{2}", FE.FBXFormat(verticies[i].GetX() * -1), FE.FBXFormat(verticies[i].GetY()), FE.FBXFormat(verticies[i].GetZ())); } tempObjectSb.AppendLine(); tempObjectSb.AppendLine("\t\t} "); // ======= WRITE THE TRIANGLES ======== int triangleCount = mesh.GetTriangles().Length; int[] triangles = mesh.GetTriangles(); tempObjectSb.AppendLine("\t\tPolygonVertexIndex: *" + triangleCount + " {"); // Write triangle indexes tempObjectSb.Append("\t\t\ta: "); for (int i = 0; i < triangleCount; i += 3) { if (i > 0) { tempObjectSb.Append(","); } // To get the correct normals, must rewind the triangles since we flipped the x direction tempObjectSb.AppendFormat("{0},{1},{2}", triangles[i], triangles[i + 2], (triangles[i + 1] * -1) - 1); // <= Tells the poly is ended } tempObjectSb.AppendLine(); tempObjectSb.AppendLine("\t\t} "); tempObjectSb.AppendLine("\t\tGeometryVersion: 124"); tempObjectSb.AppendLine("\t\tLayerElementNormal: 0 {"); tempObjectSb.AppendLine("\t\t\tVersion: 101"); tempObjectSb.AppendLine("\t\t\tName: \"\""); tempObjectSb.AppendLine("\t\t\tMappingInformationType: \"ByPolygonVertex\""); tempObjectSb.AppendLine("\t\t\tReferenceInformationType: \"Direct\""); // ===== WRITE THE NORMALS ========== Vector3[] normals = mesh.ThreadSafe_GetNormals(); tempObjectSb.AppendLine("\t\t\tNormals: *" + (triangleCount * 3) + " {"); tempObjectSb.Append("\t\t\t\ta: "); for (int i = 0; i < triangleCount; i += 3) { if (i > 0) { tempObjectSb.Append(","); } // To get the correct normals, must rewind the normal triangles like the triangles above since x was flipped Vector3 newNormal = normals[triangles[i]]; tempObjectSb.AppendFormat("{0},{1},{2},", FE.FBXFormat(newNormal.GetX() * -1), // Switch normal as is tradition FE.FBXFormat(newNormal.GetY()), FE.FBXFormat(newNormal.GetZ())); newNormal = normals[triangles[i + 2]]; tempObjectSb.AppendFormat("{0},{1},{2},", FE.FBXFormat(newNormal.GetX() * -1), // Switch normal as is tradition FE.FBXFormat(newNormal.GetY()), FE.FBXFormat(newNormal.GetZ())); newNormal = normals[triangles[i + 1]]; tempObjectSb.AppendFormat("{0},{1},{2}", FE.FBXFormat(newNormal.GetX() * -1), // Switch normal as is tradition FE.FBXFormat(newNormal.GetY()), FE.FBXFormat(newNormal.GetZ())); } tempObjectSb.AppendLine(); tempObjectSb.AppendLine("\t\t\t}"); tempObjectSb.AppendLine("\t\t}"); // ===== WRITE THE COLORS ===== bool containsColors = mesh.ThreadSafe_GetColors().Length == verticies.Length; if (containsColors) { Color[] colors = mesh.ThreadSafe_GetColors(); Dictionary <Color, int> colorTable = new Dictionary <Color, int>(); // reducing amount of data by only keeping unique colors. int idx = 0; // build index table of all the different colors present in the mesh for (int i = 0; i < colors.Length; i++) { if (!colorTable.ContainsKey(colors[i])) { colorTable[colors[i]] = idx; idx++; } } tempObjectSb.AppendLine("\t\tLayerElementColor: 0 {"); tempObjectSb.AppendLine("\t\t\tVersion: 101"); tempObjectSb.AppendLine("\t\t\tName: \"Col\""); tempObjectSb.AppendLine("\t\t\tMappingInformationType: \"ByPolygonVertex\""); tempObjectSb.AppendLine("\t\t\tReferenceInformationType: \"IndexToDirect\""); tempObjectSb.AppendLine("\t\t\tColors: *" + colorTable.Count * 4 + " {"); tempObjectSb.Append("\t\t\t\ta: "); bool first = true; foreach (KeyValuePair <Color, int> color in colorTable) { if (!first) { tempObjectSb.Append(","); } tempObjectSb.AppendFormat("{0},{1},{2},{3}", FE.FBXFormat(color.Key.GetR()), FE.FBXFormat(color.Key.GetG()), FE.FBXFormat(color.Key.GetB()), FE.FBXFormat(color.Key.GetA())); first = false; } tempObjectSb.AppendLine(); tempObjectSb.AppendLine("\t\t\t\t}"); // Color index tempObjectSb.AppendLine("\t\t\tColorIndex: *" + triangles.Length + " {"); tempObjectSb.Append("\t\t\t\ta: "); for (int i = 0; i < triangles.Length; i += 3) { if (i > 0) { tempObjectSb.Append(","); } // Triangles need to be fliped for the x flip int index1 = triangles[i]; int index2 = triangles[i + 2]; int index3 = triangles[i + 1]; // Find the color index related to that vertice index index1 = colorTable[colors[index1]]; index2 = colorTable[colors[index2]]; index3 = colorTable[colors[index3]]; tempObjectSb.AppendFormat("{0},{1},{2}", index1, index2, index3); } tempObjectSb.AppendLine(); tempObjectSb.AppendLine("\t\t\t}"); tempObjectSb.AppendLine("\t\t}"); } else { Debug.LogWarning("Mesh contains " + mesh.GetVertices().Length + " vertices for " + mesh.ThreadSafe_GetColors().Length + " colors. Skip color export"); } // ================ UV CREATION ========================= // -- UV 1 Creation int uvLength = mesh.GetUV().Length; Vector2[] uvs = mesh.GetUV(); tempObjectSb.AppendLine("\t\tLayerElementUV: 0 {"); // the Zero here is for the first UV map tempObjectSb.AppendLine("\t\t\tVersion: 101"); tempObjectSb.AppendLine("\t\t\tName: \"map1\""); tempObjectSb.AppendLine("\t\t\tMappingInformationType: \"ByPolygonVertex\""); tempObjectSb.AppendLine("\t\t\tReferenceInformationType: \"IndexToDirect\""); tempObjectSb.AppendLine("\t\t\tUV: *" + uvLength * 2 + " {"); tempObjectSb.Append("\t\t\t\ta: "); for (int i = 0; i < uvLength; i++) { if (i > 0) { tempObjectSb.Append(","); } tempObjectSb.AppendFormat("{0},{1}", FE.FBXFormat(uvs[i].GetX()), FE.FBXFormat(uvs[i].GetY())); } tempObjectSb.AppendLine(); tempObjectSb.AppendLine("\t\t\t\t}"); // UV tile index coords tempObjectSb.AppendLine("\t\t\tUVIndex: *" + triangleCount + " {"); tempObjectSb.Append("\t\t\t\ta: "); for (int i = 0; i < triangleCount; i += 3) { if (i > 0) { tempObjectSb.Append(","); } // Triangles need to be fliped for the x flip int index1 = triangles[i]; int index2 = triangles[i + 2]; int index3 = triangles[i + 1]; tempObjectSb.AppendFormat("{0},{1},{2}", index1, index2, index3); } tempObjectSb.AppendLine(); tempObjectSb.AppendLine("\t\t\t}"); tempObjectSb.AppendLine("\t\t}"); // -- UV 2 Creation // TODO: Add UV2 Creation here // -- Smoothing // TODO: Smoothing doesn't seem to do anything when importing. This maybe should be added. -KBH // ============ MATERIALS ============= tempObjectSb.AppendLine("\t\tLayerElementMaterial: 0 {"); tempObjectSb.AppendLine("\t\t\tVersion: 101"); tempObjectSb.AppendLine("\t\t\tName: \"\""); tempObjectSb.AppendLine("\t\t\tMappingInformationType: \"ByPolygon\""); tempObjectSb.AppendLine("\t\t\tReferenceInformationType: \"IndexToDirect\""); int totalFaceCount = 0; // So by polygon means that we need 1/3rd of how many indicies we wrote. int numberOfSubmeshes = mesh.GetSubmeshCount(); StringBuilder submeshesSb = new StringBuilder(); // For just one submesh, we set them all to zero if (numberOfSubmeshes == 1) { int numFaces = triangles.Length / 3; for (int i = 0; i < numFaces; i++) { submeshesSb.Append("0,"); totalFaceCount++; } } else { List <int[]> allSubmeshes = new List <int[]>(); // Load all submeshes into a space for (int i = 0; i < numberOfSubmeshes; i++) { allSubmeshes.Add(mesh.ThreadSafe_GetIndices(i)); } // TODO: Optimize this search pattern for (int i = 0; i < triangles.Length; i += 3) { for (int subMeshIndex = 0; subMeshIndex < allSubmeshes.Count; subMeshIndex++) { bool breaker = false; for (int n = 0; n < allSubmeshes[subMeshIndex].Length; n += 3) { if (triangles[i] == allSubmeshes[subMeshIndex][n] && triangles[i + 1] == allSubmeshes[subMeshIndex][n + 1] && triangles[i + 2] == allSubmeshes[subMeshIndex][n + 2]) { submeshesSb.Append(subMeshIndex.ToString()); submeshesSb.Append(","); totalFaceCount++; break; } if (breaker) { break; } } } } } tempObjectSb.AppendLine("\t\t\tMaterials: *" + totalFaceCount + " {"); tempObjectSb.Append("\t\t\t\ta: "); tempObjectSb.AppendLine(submeshesSb.ToString()); tempObjectSb.AppendLine("\t\t\t} "); tempObjectSb.AppendLine("\t\t}"); // ============= INFORMS WHAT TYPE OF LATER ELEMENTS ARE IN THIS GEOMETRY ================= tempObjectSb.AppendLine("\t\tLayer: 0 {"); tempObjectSb.AppendLine("\t\t\tVersion: 100"); tempObjectSb.AppendLine("\t\t\tLayerElement: {"); tempObjectSb.AppendLine("\t\t\t\tType: \"LayerElementNormal\""); tempObjectSb.AppendLine("\t\t\t\tTypedIndex: 0"); tempObjectSb.AppendLine("\t\t\t}"); tempObjectSb.AppendLine("\t\t\tLayerElement: {"); tempObjectSb.AppendLine("\t\t\t\tType: \"LayerElementMaterial\""); tempObjectSb.AppendLine("\t\t\t\tTypedIndex: 0"); tempObjectSb.AppendLine("\t\t\t}"); tempObjectSb.AppendLine("\t\t\tLayerElement: {"); tempObjectSb.AppendLine("\t\t\t\tType: \"LayerElementTexture\""); tempObjectSb.AppendLine("\t\t\t\tTypedIndex: 0"); tempObjectSb.AppendLine("\t\t\t}"); if (containsColors) { tempObjectSb.AppendLine("\t\t\tLayerElement: {"); tempObjectSb.AppendLine("\t\t\t\tType: \"LayerElementColor\""); tempObjectSb.AppendLine("\t\t\t\tTypedIndex: 0"); tempObjectSb.AppendLine("\t\t\t}"); } tempObjectSb.AppendLine("\t\t\tLayerElement: {"); tempObjectSb.AppendLine("\t\t\t\tType: \"LayerElementUV\""); tempObjectSb.AppendLine("\t\t\t\tTypedIndex: 0"); tempObjectSb.AppendLine("\t\t\t}"); // TODO: Here we would add UV layer 1 for ambient occlusion UV file // tempObjectSb.AppendLine("\t\t\tLayerElement: {"); // tempObjectSb.AppendLine("\t\t\t\tType: \"LayerElementUV\""); // tempObjectSb.AppendLine("\t\t\t\tTypedIndex: 1"); // tempObjectSb.AppendLine("\t\t\t}"); tempObjectSb.AppendLine("\t\t}"); tempObjectSb.AppendLine("\t}"); // Add the connection for the model to the geometry so it is attached the right mesh tempConnectionsSb.AppendLine("\t;Geometry::, Model::" + mesh.GetName()); tempConnectionsSb.AppendLine("\tC: \"OO\"," + geometryId + "," + modelId); tempConnectionsSb.AppendLine(); // Add the connection of all the materials in order of submesh MeshRenderer meshRenderer = gameObj.ThreadSafe_GetComponent <MeshRenderer>(); if (meshRenderer != null) { Material[] allMaterialsInThisMesh = meshRenderer.GetSharedMaterials(); for (int i = 0; i < allMaterialsInThisMesh.Length; i++) { Material mat = allMaterialsInThisMesh[i]; int referenceId = Mathf.Abs(mat.ThreadSafe_GetInstanceID()); if (mat == null) { Debug.LogError("ERROR: the game object " + gameObj.GetName() + " has an empty material on it. This will export problematic files. Please fix and reexport"); continue; } tempConnectionsSb.AppendLine("\t;Material::" + mat.GetName() + ", Model::" + mesh.GetName()); tempConnectionsSb.AppendLine("\tC: \"OO\"," + referenceId + "," + modelId); tempConnectionsSb.AppendLine(); } } } // Recursively add all the other objects to the string that has been built. for (int i = 0; i < gameObj.GetTransform().ThreadSafe_GetChildCount(); i++) { GameObject childObject = gameObj.GetTransform().ThreadSafe_GetChild(i).GetGameObject(); FBXUnityMeshGetter.GetMeshToString(childObject, materials, ref tempObjectSb, ref tempConnectionsSb, gameObj, modelId); } objects.Append(tempObjectSb.ToString()); connections.Append(tempConnectionsSb.ToString()); return(modelId); }
private void SendEmote(GameClient client, GameObject targetObject, eEmote emoteID, string emoteType) { string messageToSource = null; string messageToTarget = null; string messageToOthers = null; GamePlayer sourcePlayer = client.Player; bool targetMatters = false; if (targetObject != null) { messageToSource = LanguageMgr.GetTranslation(client.Account.Language, string.Format("HorseEmote.{0}.ToSource", emoteType), targetObject.GetName(0, false)); messageToOthers = LanguageMgr.GetTranslation(client.Account.Language, string.Format("HorseEmote.{0}.ToOthers", emoteType), sourcePlayer.Name, targetObject.GetName(0, false), sourcePlayer.GetPronoun(1, false)); if (targetObject is GamePlayer) { messageToTarget = LanguageMgr.GetTranslation(client.Account.Language, string.Format("HorseEmote.{0}.ToOthers", emoteType), sourcePlayer.Name, LanguageMgr.GetTranslation(client.Account.Language, "HorseEmote.You"), sourcePlayer.GetPronoun(1, false)); } if (messageToSource != "-" && messageToOthers != "-") { targetMatters = true; } } if (!targetMatters) { targetObject = null; messageToSource = LanguageMgr.GetTranslation(client.Account.Language, string.Format("HorseEmote.{0}.NoTargetToSource", emoteType)); messageToOthers = LanguageMgr.GetTranslation(client.Account.Language, string.Format("HorseEmote.{0}.NoTargetToOthers", emoteType), sourcePlayer.Name, sourcePlayer.GetPronoun(1, false)); } foreach (GamePlayer player in sourcePlayer.GetPlayersInRadius(WorldMgr.VISIBILITY_DISTANCE)) { player.Out.SendEmoteAnimation(sourcePlayer, emoteID); } SendEmoteMessages(sourcePlayer, targetObject as GamePlayer, messageToSource, messageToTarget, messageToOthers); return; }
public void UpdateMouseInputs() { float dt = FrameController.DT(); UpdateMousePosition(); if (isPaperHeld || (rcCarScript != null && rcCarScript.isMouseHeld)) // Lock input until paper is put down { if (Input.GetTriggered(0, "MouseLClick") == 1.0f) { if (rcCarScript != null && rcCarScript.isMouseHeld) { rcCarScript.isMouseHeld = false; } else { pickedInteractable.OnTriggered(); isPaperHeld = false; } } } else { // Apply raycast of ocuPlayer's mouse to find any interactable object every frame (when mouse is not clicked) Vector3 ocuCamToMouse = (Vector3)gameObject.transform.position - (Vector3)ocuCam.transform.position; // Quick Hack to fix offset // Vector3 xAxis = ocuCam.transform.GetRightVector(); // Vector3 yAxis = ocuCam.transform.GetUpVector(); // ocuCamToMouse += xAxis * 0.055f; // ocuCamToMouse += yAxis * 0.12f; ocuCamToMouse.Normalize(); if (Input.GetHeld(0, "MouseLClick") == 0.0f) { pickedObject = PhysicEngine.getInstance().RayCast3DWithTag(ocuCam.transform.position, ocuCamToMouse, 10000.0f, Common.tagForInteractables); pickedInteractable = null; // Check if mouse is over a valid camInMap if (pickedObject != null) { pickedInteractable = GetScriptClass <InteractableObjectBaseClass>(pickedObject, false); if (pickedInteractable != null) { pickedInteractable.OnMouseOver(); // The logic for ray casting through the camera screen into world objects CameraScreen pickedScreen = pickedInteractable as CameraScreen; if (pickedScreen != null && camScript.gameObjectParentedTo != null && camScript.gameObjectParentedTo != Common.GetNoiseStatic()) { CTransform screenTrans = pickedScreen.gameObject.transform; Vector3 screenPos = screenTrans.position; Vector3 rightVect = screenTrans.GetRightVector(); Vector3 upVect = screenTrans.GetUpVector(); Vector3 normal = screenTrans.GetForwardVector(); Vector3 screenScale = screenTrans.GetScale(); Vector3 pointOnScreen = new Vector3(); MMath.RayToPlaneIntersection(normal, screenPos, ocuCamToMouse, ocuCam.transform.position, ref pointOnScreen); Vector3 screenToPoint = pointOnScreen - screenPos; float xAmt = -Vector3.Dot(screenToPoint, rightVect); // the camera screen's x is negative (to the left) float yAmt = Vector3.Dot(screenToPoint, upVect); float xScaleOfModel = screenScale.X * 0.5f; // Reflect actual camera screen width in pixel units (quad is just nice 1 scale == 1 unit) float yScaleOfModel = screenScale.Y * 0.5f; xAmt /= xScaleOfModel; // [-0.5, 0.5] yAmt /= yScaleOfModel; float nearZ = ocuCameraScreen.GetNearZ(); float screenWidth = ocuCameraScreen.GetNearWindowWidth(); float screenHeight = ocuCameraScreen.GetNearWindowHeight(); xAmt *= screenWidth; // [-0.5, 0.5] -> [-w/2, w/2] yAmt *= screenHeight; // Use the x, y and z values through the actual camera look at directions Vector3 innerCameraVect = xAmt * (Vector3)camScript.gameObjectParentedTo.transform.GetRightVector() + yAmt * (Vector3)camScript.gameObjectParentedTo.transform.GetUpVector() + nearZ * (Vector3)camScript.gameObjectParentedTo.transform.GetForwardVector(); innerCameraVect.Normalize(); Vector3 cameraPos = camScript.gameObjectParentedTo.transform.position + 0.5f * innerCameraVect; // Move in front, so it does not ray cast to the screen itself GameObject cameraInteractable = PhysicEngine.getInstance().RayCast3DWithTag(cameraPos, innerCameraVect, 10000.0f, "camInteract"); if (cameraInteractable != null) { // If there is an interactable objec through the screen, check if there is ANY object infront of it GameObject nearestObj = PhysicEngine.getInstance().RayCast3D(cameraPos, innerCameraVect, 10000.0f); if (nearestObj == cameraInteractable) { pickedInteractable = GetScriptClass <InteractableObjectBaseClass>(cameraInteractable, false); if (pickedInteractable != null) { pickedInteractable.OnMouseOver(); } } else // There is something blocking { Logger.Log("nearer Obj found: " + nearestObj.GetName()); } } } } } // If prev interactable changed or is lost, call it's mouseOverOff if (prevPickedInteractable != pickedInteractable) { if (prevPickedInteractable != null) { prevPickedInteractable.OnMouseOverOff(); if (Input.GetReleased(0, "MouseLClick") == 1.0f) { prevPickedInteractable.OnReleased(); } } prevPickedInteractable = pickedInteractable; } } // End of if not mouse held if (Input.GetTriggered(0, "MouseLClick") == 1.0f) { if (pickedInteractable != null) { pickedInteractable.OnTriggered(); // If picked up paper, lock the input Paper pickedPaper = pickedInteractable as Paper; if (pickedPaper != null) { if (pickedPaper.GetIsHeldUp()) { isPaperHeld = true; } } } } if (Input.GetHeld(0, "MouseLClick") == 1.0f) { if (pickedInteractable != null) { pickedInteractable.OnHeldMouse(mCurrMouseMovement.X, mCurrMouseMovement.Y); } } if (Input.GetReleased(0, "MouseLClick") == 1.0f) { if (pickedInteractable != null) { pickedInteractable.OnReleased(); } } } }
// Remove from the camInMap, camInMapArea, and camInWorld lists public static void RemoveCameraObjectFromList(GameObject inCamInWorld) { // Ensure they are initialized GetCamsInMap(); GetCamsInMapArea(); GetCamsInWorld(); if (inCamInWorld.GetName().StartsWith(nameForCamInWorld)) { String camIndexStr = inCamInWorld.GetName().Substring(nameForCamInWorld.Length); int index = Convert.ToInt32(camIndexStr); if (!camInWorld.Remove(inCamInWorld)) Logger.Log("RemoveCameraObjectFromList: unable to find " + inCamInWorld.GetName()); else camInWorld.Sort(CompareCamInWorld); String inMapName = nameForCamInMap + index.ToString(); String inMapAreaName = nameForCamInMapArea + index.ToString(); GameObject camInMapObj = null; foreach (GameObject gObj in camInMap) { if (gObj.GetName() == inMapName) { if (!camInMap.Remove(gObj)) Logger.Log("RemoveCameraObjectFromList: unable to find " + inMapName); else { camInMap.Sort(CompareCamInMap); camInMapObj = gObj; } break; } } GameObject camInMapAreaObj = null; foreach (GameObject gObj in camInMapArea) { if (gObj.GetName() == inMapAreaName) { if (!camInMapArea.Remove(gObj)) Logger.Log("RemoveCameraObjectFromList: unable to find " + inMapAreaName); else { camInMapArea.Sort(CompareCamInMapArea); camInMapAreaObj = gObj; } break; } } if (camInMapAreaObj != null) { if (CameraInMap.currEnabledCamInMap != null) // Make sure currEnabled is forgotten { CameraInMap.currEnabledCamInMap = null; } } if (camInMapObj != null) { camInMapObj.Destroy(); } } else { Logger.Log("Remove camera from list: name not normal: " + inCamInWorld.GetName() + ", so do not affect list"); } //Logger.Log("Cams in map now: " + camInMap.Count.ToString()); //Logger.Log("Cams in map world now: " + camInWorld.Count.ToString()); //Logger.Log("Cams in map area now: " + camInMapArea.Count.ToString()); }
// Adds to the camInMap, camInMapArea, and camInWorld lists public static void AddCameraObjectToList(GameObject inCamInWorld, out GameObject retCamInMap, out GameObject retCamInMapArea) { // Ensure they are initialized GetCamsInMap(); GetCamsInMapArea(); GetCamsInWorld(); retCamInMap = null; retCamInMapArea = null; if (inCamInWorld.GetName().StartsWith(nameForCamInWorld)) { // Sort and change name based on CamInWorld (parent)'s name String camIndexStr1 = inCamInWorld.transform.GetParent().gameObject.GetName(); camIndexStr1 = camIndexStr1.Substring(nameForCamInWorldParent.Length); int index = Convert.ToInt32(camIndexStr1); inCamInWorld.SetName(nameForCamInWorld + camIndexStr1); //String camIndexStr = inCamInWorld.GetName().Substring(nameForCamInWorld.Length); //int index = Convert.ToInt32(camIndexStr); camInWorld.Add(inCamInWorld); // Sort the physical CamInWorld# by name, so [0] == CamInMap1 and so on, with StickyCamInMap being the last camInWorld.Sort(CompareCamInWorld); retCamInMapArea = null; retCamInMap = ObjectFactory.getInstance().Instantiate("CamInMap"); retCamInMap.SetName(nameForCamInMap + index.ToString()); for (uint i = 0; i < retCamInMap.transform.GetNumberOfChildren(); ++i) { if (retCamInMap.transform.GetChild(i).gameObject.GetName() == nameForCamInMapArea) { retCamInMapArea = retCamInMap.transform.GetChild(i).gameObject; retCamInMapArea.SetName(nameForCamInMapArea + index.ToString()); camInMapArea.Add(retCamInMapArea); break; } } retCamInMap.transform.SetParent(GetMapScreen().transform.GetParent()); camInMap.Add(retCamInMap); camInMap.Sort(CompareCamInMap); camInMapArea.Sort(CompareCamInMapArea); } else { Logger.Log("Adding camera to list: name not normal: " + inCamInWorld.GetName()); if (inCamInWorld.GetName() == nameForStickyCamInWorld) { stickCam = inCamInWorld; retCamInMap = ObjectFactory.getInstance().Instantiate("CamInMap"); retCamInMap.SetName(nameForStickyCamInMap); for (uint i = 0; i < retCamInMap.transform.GetNumberOfChildren(); ++i) { if (retCamInMap.transform.GetChild(i).gameObject.GetName() == nameForCamInMapArea) { retCamInMapArea = retCamInMap.transform.GetChild(i).gameObject; retCamInMapArea.SetName(nameForStickyCamInMap + "Area"); stickCamInMapArea = retCamInMapArea; break; } } retCamInMap.transform.SetParent(GetMapScreen().transform.GetParent()); stickCamInMap = retCamInMap; } else if (inCamInWorld.GetName() == nameForRCCarCamInWorld) { rcCarCam = inCamInWorld; retCamInMap = ObjectFactory.getInstance().Instantiate("CamInMap"); retCamInMap.SetName(nameForRCCarCamInMap); for (uint i = 0; i < retCamInMap.transform.GetNumberOfChildren(); ++i) { if (retCamInMap.transform.GetChild(i).gameObject.GetName() == nameForCamInMapArea) { retCamInMapArea = retCamInMap.transform.GetChild(i).gameObject; retCamInMapArea.SetName(nameForRCCarCamInMap + "Area"); break; } } retCamInMap.transform.SetParent(GetMapScreen().transform.GetParent()); rcCarCamInMap = retCamInMap; } } }
public GameObject Instantiate(NetworkPlayer owner, GameObject prefab, Vector3 position, Quaternion rotation, NetworkGroup group, params object[] initialData) { _AssertPrefab(prefab, true); return(_GetGameObject(base.Instantiate(owner, prefab.GetName(), position, rotation, group, initialData))); }
// Remove from the camInMap, camInMapArea, and camInWorld lists public static void RemoveCameraObjectFromList(GameObject inCamInWorld) { // Ensure they are initialized GetCamsInMap(); GetCamsInMapArea(); GetCamsInWorld(); if (inCamInWorld.GetName().StartsWith(nameForCamInWorld)) { String camIndexStr = inCamInWorld.GetName().Substring(nameForCamInWorld.Length); int index = Convert.ToInt32(camIndexStr); if (!camInWorld.Remove(inCamInWorld)) { Logger.Log("RemoveCameraObjectFromList: unable to find " + inCamInWorld.GetName()); } else { camInWorld.Sort(CompareCamInWorld); } String inMapName = nameForCamInMap + index.ToString(); String inMapAreaName = nameForCamInMapArea + index.ToString(); GameObject camInMapObj = null; foreach (GameObject gObj in camInMap) { if (gObj.GetName() == inMapName) { if (!camInMap.Remove(gObj)) { Logger.Log("RemoveCameraObjectFromList: unable to find " + inMapName); } else { camInMap.Sort(CompareCamInMap); camInMapObj = gObj; } break; } } GameObject camInMapAreaObj = null; foreach (GameObject gObj in camInMapArea) { if (gObj.GetName() == inMapAreaName) { if (!camInMapArea.Remove(gObj)) { Logger.Log("RemoveCameraObjectFromList: unable to find " + inMapAreaName); } else { camInMapArea.Sort(CompareCamInMapArea); camInMapAreaObj = gObj; } break; } } if (camInMapAreaObj != null) { if (CameraInMap.currEnabledCamInMap != null) // Make sure currEnabled is forgotten { CameraInMap.currEnabledCamInMap = null; } } if (camInMapObj != null) { camInMapObj.Destroy(); } } else { Logger.Log("Remove camera from list: name not normal: " + inCamInWorld.GetName() + ", so do not affect list"); } //Logger.Log("Cams in map now: " + camInMap.Count.ToString()); //Logger.Log("Cams in map world now: " + camInWorld.Count.ToString()); //Logger.Log("Cams in map area now: " + camInMapArea.Count.ToString()); }
public static void CopyComplexMaterialsToPath(GameObject gameObj, string path, bool copyTextures, string texturesFolder = "/Textures", string materialsFolder = "/Materials") { #if UNITY_EDITOR int folderIndex = path.LastIndexOf('/'); path = path.Remove(folderIndex, path.Length - folderIndex); // 1. First create the directories that are needed string texturesPath = path + texturesFolder; string materialsPath = path + materialsFolder; if (Directory.Exists(path) == false) { Directory.CreateDirectory(path); } if (Directory.Exists(materialsPath) == false) { Directory.CreateDirectory(materialsPath); } // 2. Copy every distinct Material into the Materials folder //@cartzhang modify.As meshrender and skinnedrender is same level in inherit relation shape. // if not check,skinned render ,may lost some materials. Renderer[] meshRenderers = gameObj.ThreadSafe_GetComponentsInChildren <Renderer>(); List <Material> everyMaterial = new List <Material>(); for (int i = 0; i < meshRenderers.Length; i++) { var sharedMaterials = meshRenderers[i].GetSharedMaterials(); for (int n = 0; n < sharedMaterials.Length; n++) { everyMaterial.Add(sharedMaterials[n]); } //Debug.Log(meshRenderers[i].gameObject.name); } Material[] everyDistinctMaterial = everyMaterial.Distinct().ToArray <Material>(); everyDistinctMaterial = everyDistinctMaterial.OrderBy(o => o.GetName()).ToArray <Material>(); // Log warning if there are multiple assets with the same name for (int i = 0; i < everyDistinctMaterial.Length; i++) { for (int n = 0; n < everyDistinctMaterial.Length; n++) { if (i == n) { continue; } if (everyDistinctMaterial[i].GetName() == everyDistinctMaterial[n].GetName()) { Debug.LogErrorFormat("Two distinct materials {0} and {1} have the same name, this will not work with the FBX Exporter", everyDistinctMaterial[i], everyDistinctMaterial[n]); return; } } } List <string> everyMaterialName = new List <string>(); // Structure of materials naming, is used when packaging up the package // PARENTNAME_ORIGINALMATNAME.mat for (int i = 0; i < everyDistinctMaterial.Length; i++) { string newName = gameObj.GetName() + "_" + everyDistinctMaterial[i].GetName(); string fullPath = materialsPath + "/" + newName + ".mat"; if (File.Exists(fullPath)) { File.Delete(fullPath); } if (CopyAndRenameAsset(everyDistinctMaterial[i], newName, materialsPath)) { everyMaterialName.Add(newName); } } // 3. Go through newly moved materials and copy every texture and update the material ThreadSafeUtils.Refresh(); List <Material> allNewMaterials = new List <Material>(); for (int i = 0; i < everyMaterialName.Count; i++) { string assetPath = materialsPath; if (assetPath[assetPath.Length - 1] != '/') { assetPath += "/"; } assetPath += everyMaterialName[i] + ".mat"; Material sourceMat = (Material)ThreadSafeUtils.LoadAssetAtPath(assetPath, typeof(Material)); if (sourceMat != null) { allNewMaterials.Add(sourceMat); } } // Get all the textures from the mesh renderer if (copyTextures) { if (Directory.Exists(texturesPath) == false) { Directory.CreateDirectory(texturesPath); } ThreadSafeUtils.Refresh(); for (int i = 0; i < allNewMaterials.Count; i++) { allNewMaterials[i] = CopyTexturesAndAssignCopiesToMaterial(allNewMaterials[i], texturesPath); } } ThreadSafeUtils.Refresh(); #endif }
public void OnStart() { player = Common.GetStealthPlayer(); doorPhysics = gameObject.RequireComponent <CPhysics>(); mSound = gameObject.RequireComponent <CSound>(); if (isSingleDoor) { ruDoor = gameObject; } else { uint numChildren = gameObject.transform.GetNumberOfChildren(); if (numChildren >= 2) { for (uint i = 0; i < numChildren; ++i) { GameObject currChild = gameObject.transform.GetChild(i).gameObject; String name = currChild.GetName(); if (ldDoor == null && name == Common.nameForLeftDoor) { ldDoor = currChild; } else if (ruDoor == null && name == Common.nameForRightDoor) { ruDoor = currChild; } } } } isOpen = false; //openDir = 3;//OPENING_DIRECTION.OPEN_LEFT; initPos = gameObject.transform.position; targetPosVal = 0.0f; currTime = 0.0f; if (timeToFullyOpen == 0.0f) { timeToFullyOpen = 1.0f; } normalDir = gameObject.transform.GetForwardVector(); sideDir = gameObject.transform.GetRightVector(); upDir = gameObject.transform.GetUpVector(); if (ruDoor != null) { ruInitPos = ruDoor.transform.position; if (ldDoor != null) { ldInitPos = ldDoor.transform.position; } // normalDir = ruDoor.transform.GetForwardVector(); // sideDir = ruDoor.transform.GetRightVector(); // upDir = ruDoor.transform.GetUpVector(); } currNormalDist = 0.0f; isNormalFrontPositive = 0; if (distToCloseForPlayer <= 0.0f) // if set to 0 or negative, default to open distance { distToCloseForPlayer = distToOpenForPlayer; } }
/// <summary> /// Finds all materials in a gameobject and writes them to a string that can be read by the FBX writer /// </summary> /// <param name="gameObj">Parent GameObject being exported.</param> /// <param name="newPath">The path to export to.</param> /// <param name="materials">Materials which were written to this fbx file.</param> /// <param name="matObjects">The material objects to write to the file.</param> /// <param name="connections">The connections to write to the file.</param> public static void GetAllMaterialsToString(GameObject gameObj, string newPath, bool copyMaterials, bool copyTextures, out Material[] materials, out string matObjects, out string connections) { StringBuilder tempObjectSb = new StringBuilder(); StringBuilder tempConnectionsSb = new StringBuilder(); // Need to get all unique materials for the submesh here and then write them in //@cartzhang modify.As meshrender and skinnedrender is same level in inherit relation shape. // if not check,skinned render ,may lost some materials. Renderer[] meshRenders = gameObj.ThreadSafe_GetComponentsInChildren <Renderer>(); List <Material> uniqueMaterials = new List <Material>(); // Gets all the unique materials within this GameObject Hierarchy for (int i = 0; i < meshRenders.Length; i++) { var sharedMaterials = meshRenders[i].GetSharedMaterials(); for (int n = 0; n < sharedMaterials.Length; n++) { Material mat = sharedMaterials[n]; if (uniqueMaterials.Contains(mat) == false && mat != null) { uniqueMaterials.Add(mat); } } } for (int i = 0; i < uniqueMaterials.Count; i++) { Material mat = uniqueMaterials[i]; // We rename the material if it is being copied string materialName = mat.GetName(); if (copyMaterials) { materialName = gameObj.GetName() + "_" + mat.GetName(); } int referenceId = Mathf.Abs(mat.ThreadSafe_GetInstanceID()); tempObjectSb.AppendLine(); tempObjectSb.AppendLine("\tMaterial: " + referenceId + ", \"Material::" + materialName + "\", \"\" {"); tempObjectSb.AppendLine("\t\tVersion: 102"); tempObjectSb.AppendLine("\t\tShadingModel: \"phong\""); tempObjectSb.AppendLine("\t\tMultiLayer: 0"); tempObjectSb.AppendLine("\t\tProperties70: {"); tempObjectSb.AppendFormat("\t\t\tP: \"Diffuse\", \"Vector3D\", \"Vector\", \"\",{0},{1},{2}", FE.FBXFormat(mat.GetColor().GetR()), FE.FBXFormat(mat.GetColor().GetG()), FE.FBXFormat(mat.GetColor().GetB())); tempObjectSb.AppendLine(); tempObjectSb.AppendFormat("\t\t\tP: \"DiffuseColor\", \"Color\", \"\", \"A\",{0},{1},{2}", FE.FBXFormat(mat.GetColor().GetR()), FE.FBXFormat(mat.GetColor().GetG()), FE.FBXFormat(mat.GetColor().GetB())); tempObjectSb.AppendLine(); // TODO: Figure out if this property can be written to the FBX file // if(mat.HasProperty("_MetallicGlossMap")) // { // Debug.Log("has metallic gloss map"); // Color color = mat.GetColor("_Color"); // tempObjectSb.AppendFormat("\t\t\tP: \"Specular\", \"Vector3D\", \"Vector\", \"\",{0},{1},{2}", color.GetR(), color.GetG(), color.GetR()); // tempObjectSb.AppendLine(); // tempObjectSb.AppendFormat("\t\t\tP: \"SpecularColor\", \"ColorRGB\", \"Color\", \" \",{0},{1},{2}", color.GetR(), color.GetG(), color.GetB()); // tempObjectSb.AppendLine(); // } if (mat.ThreadSafe_HasProperty("_SpecColor")) { Color color = mat.ThreadSafe_GetColor("_SpecColor"); tempObjectSb.AppendFormat("\t\t\tP: \"Specular\", \"Vector3D\", \"Vector\", \"\",{0},{1},{2}", FE.FBXFormat(color.GetR()), FE.FBXFormat(color.GetG()), FE.FBXFormat(color.GetR())); tempObjectSb.AppendLine(); tempObjectSb.AppendFormat("\t\t\tP: \"SpecularColor\", \"ColorRGB\", \"Color\", \" \",{0},{1},{2}", FE.FBXFormat(color.GetR()), FE.FBXFormat(color.GetG()), FE.FBXFormat(color.GetB())); tempObjectSb.AppendLine(); } if (mat.ThreadSafe_HasProperty("_Mode")) { Color color = Color.white; switch ((int)mat.ThreadSafe_GetFloat("_Mode")) { case 0: // Map is opaque break; case 1: // Map is a cutout // TODO: Add option if it is a cutout break; case 2: // Map is a fade color = mat.ThreadSafe_GetColor("_Color"); tempObjectSb.AppendFormat("\t\t\tP: \"TransparentColor\", \"Color\", \"\", \"A\",{0},{1},{2}", FE.FBXFormat(color.GetR()), FE.FBXFormat(color.GetG()), FE.FBXFormat(color.GetB())); tempObjectSb.AppendLine(); tempObjectSb.AppendFormat("\t\t\tP: \"Opacity\", \"double\", \"Number\", \"\",{0}", FE.FBXFormat(color.a)); tempObjectSb.AppendLine(); break; case 3: // Map is transparent color = mat.ThreadSafe_GetColor("_Color"); tempObjectSb.AppendFormat("\t\t\tP: \"TransparentColor\", \"Color\", \"\", \"A\",{0},{1},{2}", FE.FBXFormat(color.GetR()), FE.FBXFormat(color.GetG()), FE.FBXFormat(color.GetB())); tempObjectSb.AppendLine(); tempObjectSb.AppendFormat("\t\t\tP: \"Opacity\", \"double\", \"Number\", \"\",{0}", FE.FBXFormat(color.a)); tempObjectSb.AppendLine(); break; } } // NOTE: Unity doesn't currently import this information (I think) from an FBX file. if (mat.ThreadSafe_HasProperty("_EmissionColor")) { Color color = mat.ThreadSafe_GetColor("_EmissionColor"); tempObjectSb.AppendFormat("\t\t\tP: \"Emissive\", \"Vector3D\", \"Vector\", \"\",{0},{1},{2}", FE.FBXFormat(color.GetR()), FE.FBXFormat(color.GetG()), FE.FBXFormat(color.GetB())); tempObjectSb.AppendLine(); float averageColor = (color.GetR() + color.GetG() + color.GetB()) / 3f; tempObjectSb.AppendFormat("\t\t\tP: \"EmissiveFactor\", \"Number\", \"\", \"A\",{0}", FE.FBXFormat(averageColor)); tempObjectSb.AppendLine(); } // TODO: Add these to the file based on their relation to the PBR files // tempObjectSb.AppendLine("\t\t\tP: \"AmbientColor\", \"Color\", \"\", \"A\",0,0,0"); // tempObjectSb.AppendLine("\t\t\tP: \"ShininessExponent\", \"Number\", \"\", \"A\",6.31179285049438"); // tempObjectSb.AppendLine("\t\t\tP: \"Ambient\", \"Vector3D\", \"Vector\", \"\",0,0,0"); // tempObjectSb.AppendLine("\t\t\tP: \"Shininess\", \"double\", \"Number\", \"\",6.31179285049438"); // tempObjectSb.AppendLine("\t\t\tP: \"Reflectivity\", \"double\", \"Number\", \"\",0"); tempObjectSb.AppendLine("\t\t}"); tempObjectSb.AppendLine("\t}"); string textureObjects; string textureConnections; SerializedTextures(gameObj, newPath, mat, materialName, copyTextures, out textureObjects, out textureConnections); tempObjectSb.Append(textureObjects); tempConnectionsSb.Append(textureConnections); } materials = uniqueMaterials.ToArray <Material>(); matObjects = tempObjectSb.ToString(); connections = tempConnectionsSb.ToString(); }
public static int CompareCamInWorld(GameObject lhs, GameObject rhs) { return CompareWordsAfterLength(lhs.GetName(), rhs.GetName(), nameForCamInWorld.Length); }
internal static string GetNameNullSafe(this GameObject go) { return(!IsNullOrDestroyed(go) ? go.GetName() : String.Empty); }