protected override async Task ConstructScene(GLTFScene scene, bool showSceneObj, CancellationToken cancellationToken) { // calc total vert/poly count /* int vertCount = 0, polyCount = 0; * foreach (var mesh in _gltfRoot.Meshes) * { * foreach (var prim in mesh.Primitives) * { * var localVertCount = (int) prim.Attributes[SemanticProperties.POSITION].Value.Count; * vertCount += localVertCount; * polyCount += ((int?)prim.Indices?.Value.Count ?? localVertCount) / 3; * } * } * * if (vertCount > VERTEX_LIMIT) * { * throw new Exception($"Requested glTF {_gltfFileName} has too many vertices ({vertCount:N} > {VERTEX_LIMIT:N})"); * } * * if (polyCount > POLYGON_LIMIT) * { * throw new Exception($"Requested glTF {_gltfFileName} has too many polygons ({polyCount:N} > {POLYGON_LIMIT:N})"); * } */ await base.ConstructScene(scene, showSceneObj, cancellationToken); foreach (var skin in CreatedObject.GetComponentsInChildren <SkinnedMeshRenderer>(true)) { skin.quality = SkinQuality.Bone2; } }
/// <summary> /// 用于创造一个物体并将创造出这个物体的物体传进被创造的物体,通常是技能,在每个特定的技能释放方法里调用 /// </summary> /// <param name="name"></param> public CreatedObject CreatGameObject(CreatedObject go) { CreatedObject cGo = (CreatedObject)GameObject.Instantiate(go); cGo._gameObject = this.gameObject; return(cGo); }
/// <summary> /// Import a previously exported object. Returns its object ID, or '0' if failed. /// </summary> public uint ImportObject(int playerID, BinaryReader reader) { #if !MODDING // Create a new object and read its RCC data var co = new CreatedObject(); co.objectID = GetUniqueID(); co.type = 1; co.buffer = Buffer.Create(); var data = reader.ReadBytes(reader.ReadInt32()); co.buffer.BeginWriting(false).Write(data); co.buffer.EndWriting(); AddCreatedObject(co); // We need to inform all the players in the channel of this object's creation var packet = Buffer.Create(); var writer = packet.BeginPacket(Packet.ResponseCreateObject); writer.Write(playerID); writer.Write(id); writer.Write(co.objectID); writer.Write(data); packet.EndPacket(); SendToAll(packet); packet.Recycle(); // Now read all the RFCs var size = reader.ReadInt32(); if (size != 0) { for (int i = 0; i < size; ++i) { var rfc = new RFC(); rfc.uid = reader.ReadUInt32(); rfc.objectID = co.objectID; if (rfc.functionID == 0) { rfc.functionName = reader.ReadString(); } data = reader.ReadBytes(reader.ReadInt32()); var b = Buffer.Create(); b.BeginWriting(false).Write(data); b.EndWriting(); rfc.data = b; rfcs.Add(rfc); packet = Buffer.Create(); rfc.WritePacket(id, packet, 0); SendToAll(packet); packet.Recycle(); } } return(co.objectID); #else return(0); #endif }
/// <summary> /// Transfer the specified object to another channel, changing its Object ID in the process. /// </summary> public CreatedObject TransferObject(uint objectID, Channel other) { if (objectID < 32768) { Tools.LogError("Transferring objects only works with objects that were instantiated at run-time."); } else if (mCreatedObjectDictionary.Remove(objectID)) { for (int i = 0; i < created.size; ++i) { CreatedObject obj = created[i]; if (obj.objectID == objectID) { // Move the created object over to the other channel obj.objectID = other.GetUniqueID(); // If the other channel doesn't contain the object's owner, assign a new owner bool changeOwner = true; for (int b = 0; b < other.players.size; ++b) { if (other.players[b].id == obj.playerID) { changeOwner = false; break; } } if (changeOwner) { obj.playerID = (other.host != null) ? other.host.id : 0; } created.RemoveAt(i); other.created.Add(obj); other.mCreatedObjectDictionary[obj.objectID] = true; // Move RFCs over to the other channel for (int b = rfcs.size; b > 0;) { RFC r = rfcs[--b]; if (r.objectID == objectID) { r.objectID = obj.objectID; rfcs.RemoveAt(b); other.rfcs.Add(r); } } return(obj); } } } return(null); }
/// <summary> /// Save the channel's data into the specified file. /// </summary> public void SaveTo(BinaryWriter writer) { writer.Write(Player.version); writer.Write(level); writer.Write(data); writer.Write(objectCounter); writer.Write(password); writer.Write(persistent); writer.Write(playerLimit); writer.Write(rfcs.size); for (int i = 0; i < rfcs.size; ++i) { RFC rfc = rfcs[i]; writer.Write(rfc.id); writer.Write(rfc.buffer.size); if (rfc.buffer.size > 0) { rfc.buffer.BeginReading(); writer.Write(rfc.buffer.buffer, rfc.buffer.position, rfc.buffer.size); } } writer.Write(created.size); for (int i = 0; i < created.size; ++i) { CreatedObject co = created[i]; writer.Write(co.playerID); writer.Write(co.uniqueID); writer.Write(co.objectID); writer.Write(co.buffer.size); if (co.buffer.size > 0) { co.buffer.BeginReading(); writer.Write(co.buffer.buffer, co.buffer.position, co.buffer.size); } } writer.Write(destroyed.size); for (int i = 0; i < destroyed.size; ++i) { writer.Write(destroyed[i]); } }
/// <summary> /// Load the channel's data from the specified file. /// </summary> public bool LoadFrom(BinaryReader reader, bool keepInMemory = false) { #if !MODDING var start = reader.BaseStream.Position; int version = reader.ReadInt32(); if (version < 20160207) { #if UNITY_EDITOR UnityEngine.Debug.LogWarning("Incompatible data: " + version); #endif return(false); } // Clear all RFCs, just in case for (int i = 0; i < rfcs.size; ++i) { var r = rfcs[i]; if (r.data != null) { r.data.Recycle(); } } rfcs.Clear(); created.Clear(); destroyed.Clear(); mCreatedObjectDictionary.Clear(); level = reader.ReadString(); dataNode = reader.ReadDataNode(); objectCounter = reader.ReadUInt32(); password = reader.ReadString(); persistent = reader.ReadBoolean(); playerLimit = reader.ReadUInt16(); int size = reader.ReadInt32(); for (int i = 0; i < size; ++i) { var rfc = new RFC(); rfc.uid = reader.ReadUInt32(); if (rfc.functionID == 0) { rfc.functionName = reader.ReadString(); } var b = Buffer.Create(); b.BeginWriting(false).Write(reader.ReadBytes(reader.ReadInt32())); b.EndWriting(); rfc.data = b; rfcs.Add(rfc); } size = reader.ReadInt32(); for (int i = 0; i < size; ++i) { var co = new CreatedObject(); co.playerID = reader.ReadInt32(); co.objectID = reader.ReadUInt32(); co.playerID = 0; // The player ID is no longer valid as player IDs reset on reload co.type = 1; var b = Buffer.Create(); b.BeginWriting(false).Write(reader.ReadBytes(reader.ReadInt32())); b.EndWriting(); co.buffer = b; AddCreatedObject(co); // TODO: Remove /*var r = b.BeginReading(); * var rccID = r.ReadByte(); * var funcName = (rccID == 0) ? r.ReadString() : null; * * if (funcName == "OnSpawn") * { * var prefab = r.ReadString(); * * if (prefab == "Vehicle S0") * { * var pos = ProceduralTerrain.GetTilePosition(id); * pos.x = Game.UnitsToMeters(pos.x); * pos.y = Game.UnitsToMeters(pos.y); * Debug.Log("/goto " + MathD.RoundToInt(pos.x) + " " + MathD.RoundToInt(pos.y)); * } * } * b.position = 0;*/ } size = reader.ReadInt32(); for (int i = 0; i < size; ++i) { uint uid = reader.ReadUInt32(); if (uid < 32768) { destroyed.Add(uid); } } isLocked = reader.ReadBoolean(); mSource = null; #if STANDALONE if (!keepInMemory && players.size == 0) { Reset(); var end = reader.BaseStream.Position; reader.BaseStream.Position = start; mSourceSize = (int)(end - start); mSource = reader.ReadBytes(mSourceSize); } #endif #endif return(true); }
/// <summary> /// Add a new created object to the list. This object's ID must always be above 32767. /// </summary> public void AddCreatedObject(CreatedObject obj) { created.Add(obj); mCreatedObjectDictionary[obj.objectID] = true; }
/// <summary> /// Load the channel's data from the specified file. /// </summary> public bool LoadFrom(BinaryReader reader) { int version = reader.ReadInt32(); if (version < 20160207) { #if UNITY_EDITOR UnityEngine.Debug.LogWarning("Incompatible data: " + version); #endif return(false); } // Clear all RFCs, just in case for (int i = 0; i < rfcs.size; ++i) { RFC r = rfcs[i]; if (r.data != null) { r.data.Recycle(); } } rfcs.Clear(); created.Clear(); destroyed.Clear(); mCreatedObjectDictionary.Clear(); level = reader.ReadString(); dataNode = reader.ReadDataNode(); objectCounter = reader.ReadUInt32(); password = reader.ReadString(); persistent = reader.ReadBoolean(); playerLimit = reader.ReadUInt16(); int size = reader.ReadInt32(); for (int i = 0; i < size; ++i) { RFC rfc = new RFC(); rfc.uid = reader.ReadUInt32(); if (rfc.functionID == 0) { rfc.functionName = reader.ReadString(); } Buffer b = Buffer.Create(); b.BeginWriting(false).Write(reader.ReadBytes(reader.ReadInt32())); b.EndWriting(); rfc.data = b; rfcs.Add(rfc); } size = reader.ReadInt32(); for (int i = 0; i < size; ++i) { CreatedObject co = new CreatedObject(); co.playerID = reader.ReadInt32(); co.objectID = reader.ReadUInt32(); co.type = 1; Buffer b = Buffer.Create(); b.BeginWriting(false).Write(reader.ReadBytes(reader.ReadInt32())); b.EndWriting(); co.buffer = b; AddCreatedObject(co); } size = reader.ReadInt32(); for (int i = 0; i < size; ++i) { uint uid = reader.ReadUInt32(); if (uid < 32768) { destroyed.Add(uid); } } isLocked = reader.ReadBoolean(); return(true); }
/// <summary> /// Save the channel's data into the specified file. /// </summary> public void SaveTo(BinaryWriter writer) { writer.Write(Player.version); writer.Write(level); writer.Write(dataNode); writer.Write(objectCounter); writer.Write(password); writer.Write(persistent); writer.Write(playerLimit); // Record which objects are temporary and which ones are not for (int i = 0; i < created.size; ++i) { CreatedObject co = created[i]; if (co.type == 1) { mCreatedOBJs.Add(co); mCleanedOBJs.Add(co.objectID); } } // Record all RFCs that don't belong to temporary objects for (int i = 0; i < rfcs.size; ++i) { RFC rfc = rfcs[i]; uint objID = rfc.objectID; if (objID < 32768) { mCreatedRFCs.Add(rfc); } else { for (int b = 0; b < mCleanedOBJs.size; ++b) { if (mCleanedOBJs.buffer[b] == objID) { mCreatedRFCs.Add(rfc); break; } } } } writer.Write(mCreatedRFCs.size); for (int i = 0; i < mCreatedRFCs.size; ++i) { RFC rfc = mCreatedRFCs[i]; writer.Write(rfc.uid); if (rfc.functionID == 0) { writer.Write(rfc.functionName); } writer.Write(rfc.data.size); if (rfc.data.size > 0) { writer.Write(rfc.data.buffer, rfc.data.position, rfc.data.size); } } writer.Write(mCreatedOBJs.size); for (int i = 0; i < mCreatedOBJs.size; ++i) { CreatedObject co = mCreatedOBJs[i]; writer.Write(co.playerID); writer.Write(co.objectID); writer.Write(co.buffer.size); if (co.buffer.size > 0) { writer.Write(co.buffer.buffer, co.buffer.position, co.buffer.size); } } writer.Write(destroyed.size); for (int i = 0; i < destroyed.size; ++i) { writer.Write(destroyed[i]); } mCleanedOBJs.Clear(); mCreatedOBJs.Clear(); mCreatedRFCs.Clear(); writer.Write(isLocked); }
/// <summary> /// Load the channel's data from the specified file. /// </summary> public bool LoadFrom(BinaryReader reader) { int version = reader.ReadInt32(); if (version != Player.version) { return(false); } // Clear all RFCs, just in case for (int i = 0; i < rfcs.size; ++i) { RFC r = rfcs[i]; if (r.buffer != null) { r.buffer.Recycle(); } } rfcs.Clear(); created.Clear(); destroyed.Clear(); level = reader.ReadString(); data = reader.ReadString(); objectCounter = reader.ReadUInt32(); password = reader.ReadString(); persistent = reader.ReadBoolean(); playerLimit = reader.ReadUInt16(); int size = reader.ReadInt32(); for (int i = 0; i < size; ++i) { RFC rfc = new RFC(); rfc.id = reader.ReadUInt32(); Buffer b = Buffer.Create(); b.BeginWriting(false).Write(reader.ReadBytes(reader.ReadInt32())); rfc.buffer = b; rfcs.Add(rfc); } size = reader.ReadInt32(); for (int i = 0; i < size; ++i) { CreatedObject co = new CreatedObject(); co.playerID = reader.ReadInt32(); co.uniqueID = reader.ReadUInt32(); co.objectID = reader.ReadUInt16(); Buffer b = Buffer.Create(); b.BeginWriting(false).Write(reader.ReadBytes(reader.ReadInt32())); co.buffer = b; created.Add(co); } size = reader.ReadInt32(); for (int i = 0; i < size; ++i) { destroyed.Add(reader.ReadUInt32()); } return(true); }
public override string ToString() { return($"{CreatedObject.GetType()} : {RequiredType}"); }
protected virtual void OnCreatedObject(CreatedObjectEventArgs e) { CreatedObject?.Invoke(this, e); }
/// <summary> /// Load the channel's data from the specified file. /// </summary> public bool LoadFrom(BinaryReader reader) { int version = reader.ReadInt32(); if (version != Player.version) return false; // Clear all RFCs, just in case for (int i = 0; i < rfcs.size; ++i) { RFC r = rfcs[i]; if (r.buffer != null) r.buffer.Recycle(); } rfcs.Clear(); created.Clear(); destroyed.Clear(); level = reader.ReadString(); data = reader.ReadString(); objectCounter = reader.ReadUInt32(); password = reader.ReadString(); persistent = reader.ReadBoolean(); playerLimit = reader.ReadUInt16(); int size = reader.ReadInt32(); for (int i = 0; i < size; ++i) { RFC rfc = new RFC(); rfc.id = reader.ReadUInt32(); Buffer b = Buffer.Create(); b.BeginWriting(false).Write(reader.ReadBytes(reader.ReadInt32())); rfc.buffer = b; rfcs.Add(rfc); } size = reader.ReadInt32(); for (int i = 0; i < size; ++i) { CreatedObject co = new CreatedObject(); co.playerID = reader.ReadInt32(); co.uniqueID = reader.ReadUInt32(); co.objectID = reader.ReadUInt16(); Buffer b = Buffer.Create(); b.BeginWriting(false).Write(reader.ReadBytes(reader.ReadInt32())); co.buffer = b; created.Add(co); } size = reader.ReadInt32(); for (int i = 0; i < size; ++i) destroyed.Add(reader.ReadUInt32()); return true; }
/// <summary> /// Save the channel's data into the specified file. /// </summary> public void SaveTo(BinaryWriter writer) { writer.Write(Player.version); writer.Write(level); writer.Write(data); writer.Write(objectCounter); writer.Write(password); writer.Write(persistent); writer.Write(playerLimit); List <uint> tempObjs = new List <uint>(); List <CreatedObject> cleanedObjs = new List <CreatedObject>(); List <RFC> cleanedRFCs = new List <RFC>(); // Record which objects are temporary and which ones are not for (int i = 0; i < created.size; ++i) { CreatedObject co = created[i]; if (co.type == 1) { cleanedObjs.Add(co); } else { tempObjs.Add(co.uniqueID); } } // Record all RFCs that don't belong to temporary objects for (int i = 0; i < rfcs.size; ++i) { RFC rfc = rfcs[i]; if (!tempObjs.Contains(rfc.objectID)) { cleanedRFCs.Add(rfc); } } writer.Write(cleanedRFCs.size); for (int i = 0; i < cleanedRFCs.size; ++i) { RFC rfc = cleanedRFCs[i]; writer.Write(rfc.uid); if (rfc.functionID == 0) { writer.Write(rfc.functionName); } writer.Write(rfc.buffer.size); if (rfc.buffer.size > 0) { rfc.buffer.BeginReading(); writer.Write(rfc.buffer.buffer, rfc.buffer.position, rfc.buffer.size); } } writer.Write(cleanedObjs.size); for (int i = 0; i < cleanedObjs.size; ++i) { CreatedObject co = cleanedObjs[i]; writer.Write(co.playerID); writer.Write(co.uniqueID); writer.Write(co.objectID); writer.Write(co.buffer.size); if (co.buffer.size > 0) { co.buffer.BeginReading(); writer.Write(co.buffer.buffer, co.buffer.position, co.buffer.size); } } writer.Write(destroyed.size); for (int i = 0; i < destroyed.size; ++i) { writer.Write(destroyed[i]); } }
public void OnGUI() { //Box Position EditorGUILayout.BeginVertical(GUI.skin.box); EditorGUILayout.LabelField("Position", EditorStyles.centeredGreyMiniLabel); GUI.color = Color.yellow; EditorGUILayout.BeginVertical(GUI.skin.box); GUI.color = Color.black; EditorGUILayout.LabelField("If non is assigned, then the start position will be (0f,0f,0f)"); GUI.color = Color.white; EditorGUILayout.EndVertical(); m_StartPosition = (Transform)EditorGUILayout.ObjectField("Start Position", m_StartPosition, typeof(Transform), true); EditorGUILayout.EndVertical(); //Box Object Selection EditorGUILayout.BeginVertical(GUI.skin.box); EditorGUILayout.LabelField("Object Selection", EditorStyles.centeredGreyMiniLabel); GUI.color = Color.cyan; if (GUILayout.Button("Use Custom Object")) { m_Custom = !m_Custom; m_CustomObject = null; } if (m_Custom) { m_CustomObject = (GameObject)EditorGUILayout.ObjectField("Custom Object", m_CustomObject, typeof(GameObject), true); } GUI.color = Color.white; m_PrimitiveToCreate = (PrimitiveType)EditorGUILayout.EnumPopup("Primitive Type", m_PrimitiveToCreate); EditorGUILayout.EndVertical(); //Creation Parameter EditorGUILayout.BeginVertical(GUI.skin.box); EditorGUILayout.LabelField("Creation Parameters", EditorStyles.centeredGreyMiniLabel); m_NameOfObjectCreated = EditorGUILayout.TextField("Name", m_NameOfObjectCreated); m_UseColor = EditorGUILayout.Toggle("Use Color?", m_UseColor); EditorGUI.BeginDisabledGroup(!m_UseColor); m_StartColor = EditorGUILayout.ColorField("Start Color", m_StartColor); m_EndColor = EditorGUILayout.ColorField("End Color", m_EndColor); EditorGUI.EndDisabledGroup(); m_NumberToCreate = EditorGUILayout.IntField("NB To Create", m_NumberToCreate); m_Spacing = EditorGUILayout.FloatField("Spacing", m_Spacing); m_DirectionToSpawn = (Direction)EditorGUILayout.EnumPopup("Axis Direction", m_DirectionToSpawn); m_AutoCenter = EditorGUILayout.Toggle("Auto-Center", m_AutoCenter); EditorGUI.BeginDisabledGroup(m_StartPosition == null); m_UseLocalRotation = EditorGUILayout.Toggle("Use Local Rotation?", m_UseLocalRotation); EditorGUI.EndDisabledGroup(); EditorGUILayout.EndVertical(); //Buton Create GUI.color = Color.green; if (GUILayout.Button("Create", GUILayout.Height(40f))) { GameObject Parent = new GameObject("Parent"); for (int i = 0; i < m_NumberToCreate; i++) { GameObject CreatedObject; if (m_CustomObject != null) { CreatedObject = Instantiate(m_CustomObject); } else { CreatedObject = GameObject.CreatePrimitive(m_PrimitiveToCreate); } CreatedObject.transform.parent = Parent.transform; Undo.RegisterCreatedObjectUndo(CreatedObject, "UndoCreatedObject"); Vector3 temp; temp = m_StartPosition == null ? Vector3.zero : m_StartPosition.position; switch (m_DirectionToSpawn) { case Direction.Up: temp.y += i * m_Spacing; break; case Direction.Down: temp.y -= i * m_Spacing; break; case Direction.Left: temp.x -= i * m_Spacing; break; case Direction.Right: temp.x += i * m_Spacing; break; case Direction.Forward: temp.z += i * m_Spacing; break; case Direction.Back: temp.z -= i * m_Spacing; break; default: break; } CreatedObject.transform.position = temp; CreatedObject.AddComponent <Environment>(); if (m_StartPosition != null && m_UseLocalRotation) { CreatedObject.transform.rotation = m_StartPosition.rotation; } if (m_NameOfObjectCreated != "") { CreatedObject.name = m_NameOfObjectCreated; } if (m_UseColor) { CreatedObject.GetComponent <Renderer>().material.color = Color.Lerp(m_StartColor, m_EndColor, ((float)i / (m_NumberToCreate - 1))); } } Selection.activeGameObject = Parent; } GUI.color = Color.white; //Undo.RegisterCreatedObjectUndo( , "UndoCreatedObject"); //Undo.RecordObject(); }
void OnGUI() { if (EditorApplication.isPlaying) { return; } GUILayout.BeginHorizontal(); GUILayout.Label("NAME", EditorStyles.boldLabel); tempString = GUILayout.TextField(tempString); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("ScriptToAttach", EditorStyles.boldLabel); string s = GUILayout.TextField(finalString); if (s != "") { int tempNumber = int.Parse(s); if (tempNumber > numberToAttach) { for (int i = 0; i < tempNumber - numberToAttach; i++) { currentscriptsToAttach.Add(new MonoScript()); } } else if (tempNumber < numberToAttach) { for (int i = 0; i < tempNumber - numberToAttach; i++) { currentscriptsToAttach.RemoveAt(currentscriptsToAttach.Count); } } numberToAttach = tempNumber; finalString = numberToAttach.ToString(); } else { finalString = ""; } GUILayout.EndHorizontal(); for (int i = 0; i < numberToAttach; i++) { currentscriptsToAttach[i] = (MonoScript)EditorGUI.ObjectField(new Rect(0, 50 + i * 30, position.width - 6, 20), currentscriptsToAttach[i], typeof(MonoScript), false); } //t = (System.Type)EditorGUI.ObjectField(new Rect(0, 50 + 3 * 30, position.width - 6, 20), t, typeof(System.Type), false); totalSize = 50 + numberToAttach * 30; GUILayout.Space(totalSize); if (GUILayout.Button("Add Finder !", GUILayout.Height(_buttonSize))) { CreatedObject co = new CreatedObject(tempString); co.scriptsToAttach = new List <MonoScript>(); for (int i = 0; i < numberToAttach; i++) { // MonoScript mb = currentscriptsToAttach[i] as MonoBehaviour; co.scriptsToAttach.Add(currentscriptsToAttach[i]); } allCreatedObjects.Add(co); Debug.Log("Object Created !"); } }