public GameObject CreateObject(NFGUID ident, string strPrefabName, Vector3 vec, string strTag) { if (!mhtObject.ContainsKey(ident)) { try { GameObject xGameObject = GameObject.Instantiate(Resources.Load(strPrefabName)) as GameObject; mhtObject.Add(ident, xGameObject); GameObject.DontDestroyOnLoad(xGameObject); Transform shadow = GetChild(xGameObject.transform, "Shadow (1)"); shadow.gameObject.GetComponent <MeshRenderer>().enabled = false; Transform heroMesh = GetChild(xGameObject.transform, "Customer"); heroMesh.gameObject.GetComponent <SkinnedMeshRenderer>().enabled = false; xGameObject.transform.position = vec; return(xGameObject); } catch { Debug.LogError("Load Prefab Failed " + ident.ToString() + " Prefab:" + strPrefabName); } } return(null); }
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(string) && value == typeof(NFGUID)) { NFGUID id = (NFGUID)value; return(id.ToString()); } return(base.ConvertTo(context, culture, value, destinationType)); }
public GameObject CreateObject(NFGUID ident, string strPrefabName, Vector3 vec, string strTag) { if (!mhtObject.ContainsKey(ident)) { try { GameObject xGameObject = GameObject.Instantiate(Resources.Load(strPrefabName)) as GameObject; mhtObject.Add(ident, xGameObject); GameObject.DontDestroyOnLoad(xGameObject); xGameObject.transform.position = vec; return(xGameObject); } catch { Debug.LogError("Load Prefab Failed " + ident.ToString() + " Prefab:" + strPrefabName); } } return(null); }
private void OnConfigIDChangeHandler(NFGUID self, string strProperty, NFDataList.TData oldVar, NFDataList.TData newVar, Int64 reason) { Vector3 vec = GetRenderObjectPosition(self); DestroyObject(self); if (vec.Equals(Vector3.zero)) { NFVector3 vec3 = mKernelModule.QueryPropertyVector3(self, NPC.Position); vec.x = vec3.X(); vec.y = vec3.Y(); vec.z = vec3.Z(); } string strCnfID = newVar.StringVal(); string strPrefabPath = mElementModule.QueryPropertyString(strCnfID, NPC.Prefab); if (strPrefabPath.Length <= 0) { strPrefabPath = mElementModule.QueryPropertyString("DefaultObject", NPC.Prefab); } GameObject xPlayer = CreateObject(self, strPrefabPath, vec, NFrame.Player.ThisName); if (xPlayer) { xPlayer.name = NFrame.Player.ThisName; xPlayer.transform.Rotate(new Vector3(0, 90, 0)); NFBodyIdent xBodyIdent = xPlayer.GetComponent <NFBodyIdent>(); if (null != xBodyIdent) {//不能没有 xBodyIdent.enabled = true; xBodyIdent.SetObjectID(self); xBodyIdent.cnfID = strCnfID; } else { Debug.LogError("No 'BodyIdent' component in " + strPrefabPath); } if (self == mLoginModule.mRoleID) { InitPlayerComponent(self, xPlayer, true); } else { InitPlayerComponent(self, xPlayer, false); } if (Camera.main && self == mLoginModule.mRoleID) { NFHeroCameraFollow xHeroCameraFollow = Camera.main.GetComponent <NFHeroCameraFollow>(); if (!xHeroCameraFollow) { xHeroCameraFollow = Camera.main.GetComponentInParent <NFHeroCameraFollow>(); } xHeroCameraFollow.SetPlayer(xPlayer.transform); } Debug.Log("Create Object successful" + NFrame.Player.ThisName + " " + vec.ToString() + " " + self.ToString()); } else { Debug.LogError("Create Object failed" + NFrame.Player.ThisName + " " + vec.ToString() + " " + self.ToString()); } }
private void OnClassPlayerEventHandler(NFGUID self, int nContainerID, int nGroupID, NFIObject.CLASS_EVENT_TYPE eType, string strClassName, string strConfigIndex) { if (eType == NFIObject.CLASS_EVENT_TYPE.OBJECT_CREATE) { Debug.Log("OBJECT_CREATE:" + self.ToString()); string strConfigID = mKernelModule.QueryPropertyString(self, NFrame.Player.ConfigID); Vector3 vec = new Vector3(); NFVector3 vector3 = mKernelModule.QueryPropertyVector3(self, NFrame.Player.Position); //vec.x = vector3.X(); //vec.y = vector3.Y(); //vec.z = vector3.Z(); //MainPlayer string strPrefabPath = "Player/AIThirdPersonController"; if (self == mLoginModule.mRoleID) { strPrefabPath = "Player/ThirdPersonController"; } //if (strConfigID.Length <= 0) //{ // strPrefabPath = NFCElementModule.Instance().QueryPropertyString("Player", "Prefab"); //} //else //{ // strPrefabPath = NFCKernelModule.Instance.GetElementModule().QueryPropertyString(strConfigID, "Prefab"); //} //CreateObject(self, strPrefabPath, vec, strClassName); GameObject perfb = Resources.Load <GameObject>(strPrefabPath); GameObject player = GameObject.Instantiate(perfb); mGameObjectMap.Add(self, player); GameObject.DontDestroyOnLoad(player); player.name = self.ToString(); player.transform.position = vec; //MainPlayer if (self == mLoginModule.mRoleID) { player.AddComponent <MainPlayer>(); } else { player.AddComponent <OtherPlayer>(); } } else if (eType == NFIObject.CLASS_EVENT_TYPE.OBJECT_DESTROY) { //DestroyObject(transform.Find(self.ToString())); GameObject go = GetObject(self); if (go != null) { mGameObjectMap.Remove(self); GameObject.DestroyObject(go); } } }