/// <summary> /// Are we ready to merge in this scene entry? /// </summary> /// <param name="entry">The entry to merge</param> /// <returns>True iff it can be merged</returns> private bool CanMerge(SceneEntry entry) { if (entry.loadMethod != LoadMethod.Baked) { return(false); } var scene = entry.scene.scene; if (!scene.IsValid()) { return(false); } var activeScene = SceneManager.GetActiveScene(); if (scene == activeScene || scene == gameObject.scene) { return(false); } if (!gameObject.scene.isLoaded) { return(false); } return(true); }
/// <summary> /// OnBeforeSerialize is called whenever we're about to save or inspect this Component. /// We want to match exactly what the Editor has in terms of Scene setup, so we do it here. /// </summary> public void OnBeforeSerialize() { #if UNITY_EDITOR if (!this || BuildPipeline.isBuildingPlayer || Application.isPlaying) { return; } // Save off the scene path if (gameObject && gameObject.scene.IsValid()) { _thisScenePath = gameObject.scene.path; } // We don't care about the scene setup if (!_isMainScene) { return; } var newSceneSetup = new List <SceneEntry>(); var activeScene = EditorSceneManager.GetActiveScene(); // Update our scene setup SceneSetup[] editorSceneSetup = EditorSceneManager.GetSceneManagerSetup(); for (int i = 0; i < editorSceneSetup.Length; ++i) { // If we're the active scene, don't save it. var editorEntry = editorSceneSetup[i]; if (editorEntry.path == activeScene.path) { continue; } var newEntry = new SceneEntry(editorEntry); newSceneSetup.Add(newEntry); // Save the baked settings var oldEntry = _sceneSetup.Find(x => newEntry.scene.Equals(x.scene)); if (oldEntry != null) { newEntry.loadMethod = oldEntry.loadMethod; } } // If we had a new scene setup... if (!newSceneSetup.SequenceEqual(_sceneSetup)) { _sceneSetup = newSceneSetup; EditorUtility.SetDirty(this); if (gameObject) { EditorSceneManager.MarkSceneDirty(gameObject.scene); } } #endif }
public void AddToBackOfSceneList(string sceneName) { if (_sceneSettings != null) { var scene = new SceneEntry(sceneName, false); _sceneSettings.Scenes.Add(new SceneEntry(sceneName, false)); _log.AddScene(scene); _log.RemoveExperimentSceneOrder(_launchManager.ExperimentName); _log.SetExperimentSceneOrder(_launchManager.ExperimentName, _sceneSettings.Scenes.ToArray()); } }
/// <summary> /// 'Bakes' a scene by merging it into our scene. /// </summary> /// <param name="entry">The entry to bake</param> private void PreMerge(SceneEntry entry) { var scene = entry.scene.scene; // This is a last chance before that scene gets destroyed. var crossSceneRefs = AmsCrossSceneReferences.GetSceneSingleton(scene, false); if (crossSceneRefs) { crossSceneRefs.ResolvePendingCrossSceneReferences(); } }
public void OnHierarchyChanged() { OnBeforeSerialize(); // We don't care about the scene setup if (!_isMainScene) { return; } var newSceneSetup = new List <SceneEntry>(); var activeScene = EditorSceneManager.GetActiveScene(); // Update our scene setup bool bForceDirty = false; SceneSetup[] editorSceneSetup = EditorSceneManager.GetSceneManagerSetup(); for (int i = 0; i < editorSceneSetup.Length; ++i) { // If we're the active scene, don't save it. var editorEntry = editorSceneSetup[i]; if (editorEntry.path == activeScene.path) { continue; } var newEntry = new SceneEntry(editorEntry); newSceneSetup.Add(newEntry); // Save the baked settings var oldEntry = _sceneSetup.Find(x => newEntry.scene.Equals(x.scene)); if (oldEntry != null) { newEntry.loadMethod = oldEntry.loadMethod; // We need to update the path if the runtime paths aren't the same (implies a rename) bForceDirty = bForceDirty || (newEntry.scene.runtimePath != oldEntry.scene.runtimePath); } } // If we had a new scene setup... if (bForceDirty || !newSceneSetup.SequenceEqual(_sceneSetup)) { _sceneSetup = newSceneSetup; EditorUtility.SetDirty(this); if (gameObject) { EditorSceneManager.MarkSceneDirty(gameObject.scene); } } }
private void MergeScene(SceneEntry entry) { var scene = entry.scene.scene; // Make sure there is only ever one AmsMultiSceneSetup in a given scene var sourceSetup = GameObjectEx.GetSceneSingleton <AmsMultiSceneSetup>(scene, false); if (sourceSetup) { GameObject.Destroy(sourceSetup.gameObject); } AmsDebug.Log(this, "Merging {0} into {1}", scene.path, gameObject.scene.path); SceneManager.MergeScenes(scene, gameObject.scene); }
/// <summary> /// Loads a particular Scene Entry in the Editor /// </summary> /// <param name="entry">The entry to load</param> private void LoadEntryInEditor(SceneEntry entry) { // Bad time to do this. if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying) { return; } // We can't do this if (string.IsNullOrEmpty(entry.scene.editorPath) || entry.scene.editorPath == gameObject.scene.path) { return; } bool bShouldLoad = entry.loadInEditor && AmsPreferences.AllowAutoload; var scene = entry.scene.scene; try { if (!scene.IsValid()) { if (bShouldLoad) { AmsDebug.Log(this, "Scene {0} is loading Scene {1} in Editor", gameObject.scene.name, entry.scene.name); EditorSceneManager.OpenScene(entry.scene.editorPath, OpenSceneMode.Additive); } else { AmsDebug.Log(this, "Scene {0} is opening Scene {1} (without loading) in Editor", gameObject.scene.name, entry.scene.name); EditorSceneManager.OpenScene(entry.scene.editorPath, OpenSceneMode.AdditiveWithoutLoading); } } else if (bShouldLoad != scene.isLoaded) { if (bShouldLoad && !scene.isLoaded) { AmsDebug.Log(this, "Scene {0} is loading existing Scene {1} in Editor", gameObject.scene.name, entry.scene.name); EditorSceneManager.OpenScene(entry.scene.editorPath, OpenSceneMode.Additive); } else { AmsDebug.Log(this, "Scene {0} is closing Scene {1} in Editor", gameObject.scene.name, entry.scene.name); EditorSceneManager.CloseScene(scene, false); } } } catch (System.Exception ex) { Debug.LogException(ex, this); } }
public ObjectInfo( bool weighted, GeometryEntry g, Matrix bindMatrix, SkinEntry skin, SceneEntry scene, InstanceEntry inst, ResourceNode parent, NodeEntry node) { _weighted = weighted; _g = g; _bindMatrix = bindMatrix; _skin = skin; _scene = scene; _parent = parent; _node = node; _inst = inst; }
/// <summary> /// Load a particular Scene Entry /// </summary> /// <param name="entry">The Entry to load</param> private void LoadEntryAtRuntime(SceneEntry entry) { // Don't load if (entry.loadMethod == LoadMethod.DontLoad) { return; } // Already loaded, try editor first var existingScene = SceneManager.GetSceneByPath(entry.scene.editorPath); // Try runtime path if (!existingScene.IsValid()) { existingScene = SceneManager.GetSceneByPath(entry.scene.runtimePath); } #if UNITY_EDITOR // Could be we just created the scene because it's baked if (!existingScene.IsValid()) { existingScene = SceneManager.GetSceneByName(entry.scene.runtimePath); } if (Application.isEditor && entry.loadMethod == LoadMethod.Baked) { // If we've already processed this, return early if (_bakedScenesLoading.Contains(entry) || _bakedScenesMerged.Contains(entry)) { return; } // We're loading this entry, don't allow this to be re-entrant _bakedScenesLoading.Add(entry); if (!existingScene.IsValid()) { // This allows us to load the level even in playmode EditorApplication.LoadLevelAdditiveInPlayMode(entry.scene.editorPath); } // Loading a scene can take multiple frames so we have to wait. // Baking scenes can only take place when they're all loaded due to cross-scene referencing if (_waitingToBake != null) { StopCoroutine(_waitingToBake); } _waitingToBake = StartCoroutine(CoWaitAndBake()); return; } #endif // If it's already loaded, return early if (existingScene.IsValid()) { return; } if (entry.loadMethod == LoadMethod.AdditiveAsync) { AmsDebug.Log(this, "Loading {0} Asynchronously from {1}", entry.scene.name, gameObject.scene.name); entry.asyncOp = SceneManager.LoadSceneAsync(entry.scene.runtimePath, LoadSceneMode.Additive); return; } if (entry.loadMethod == LoadMethod.Additive) { AmsDebug.Log(this, "Loading {0} from {1}", entry.scene.name, gameObject.scene.name); SceneManager.LoadScene(entry.scene.runtimePath, LoadSceneMode.Additive); return; } }
public static void ParseData(string content, string fileName) { metaData = new Dictionary <int, SceneData>(); CSVParser parser = new CSVParser(); if (!parser.Parse(content)) { ClientLog.Instance.LogError("SceneData" + ConfigLoader.Instance.csvext + "解析错误"); return; } int recordCounter = parser.GetRecordCounter(); SceneData data = null; for (int i = 0; i < recordCounter; ++i) { data = new SceneData(); data.id_ = parser.GetInt(i, "sceneId"); data.sceneType_ = (SceneType)Enum.Parse(typeof(SceneType), parser.GetString(i, "SceneType")); data.sceneName_ = parser.GetString(i, "scene_name"); data.sceneIcon_ = parser.GetString(i, "scene_icon"); data.sceneXml_ = parser.GetString(i, "scene_xml"); data.sceneXml_ = data.sceneXml_.Substring(data.sceneXml_.LastIndexOf("/") + 1, data.sceneXml_.IndexOf(".xml") - 1 - data.sceneXml_.LastIndexOf("/")); data.UnLockQuestID_ = parser.GetInt(i, "UnLockQuestID"); data.nameEffectId_ = parser.GetString(i, "EffectId"); data.M_ID = parser.GetInt(i, "MUSIC_ID"); data.scene_icon = parser.GetString(i, "scene_icon"); data.xmlNameId_ = int.Parse(data.sceneXml_.Substring(data.sceneXml_.LastIndexOf("_") + 1)); data.sceneLevelName_ = parser.GetString(i, "SceneName"); data.battleLevelName_ = parser.GetString(i, "BattleName"); data.offsetX_ = parser.GetFloat(i, "offsetx"); data.offsetY_ = parser.GetFloat(i, "offsety"); data.zoom_ = parser.GetFloat(i, "zoom"); data.dir_ = parser.GetFloat(i, "dir"); data.minmap = parser.GetString(i, "minimap"); string entrysStr = parser.GetString(i, "EntryInfo"); string[] entryAry = entrysStr.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); for (int j = 0; j < entryAry.Length; ++j) { string[] entryInfo = entryAry[j].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); string[] entryPosStr = entryInfo[0].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); SceneEntry se = new SceneEntry(); se.pos_ = new UnityEngine.Vector2(float.Parse(entryPosStr[0]), float.Parse(entryPosStr[1])); se.toSceneId_ = int.Parse(entryInfo[1]); if (data.entrys_ == null) { data.entrys_ = new List <SceneEntry>(); } data.entrys_.Add(se); } if (data.sceneType_ == SceneType.SCT_Home) { HomeSceneId_ = data.id_; } // { // string str = parser.GetString(i,"UnLockQuestID"); // if(str.Contains(";")) // { // string [] strs = str.Split(';'); // data.UnLockQuestID_ = strs; // } // else // { // data.UnLockQuestID_ [0]=str; // } // } if (metaData.ContainsKey(data.id_)) { ClientLog.Instance.LogError("SceneSimpleData" + ConfigLoader.Instance.csvext + "ID重复"); return; } metaData[data.id_] = data; } parser.Dispose(); parser = null; }
static PrimitiveManager DecodePrimitivesWeighted(NodeEntry n, GeometryEntry geo, SkinEntry skin, SceneEntry scene, InfluenceManager infManager, ref string Error) { PrimitiveManager manager = DecodePrimitives(n._matrix, geo); MDL0BoneNode[] boneList; MDL0BoneNode bone = null; int boneCount; string[] jointStrings = null; byte* pCmd = stackalloc byte[4]; int cmdCount = skin._weightInputs.Count; float weight = 0; float* pWeights = null; Vector3* pVert = null, pNorms = null; ushort* pVInd = (ushort*)manager._indices.Address; List<Vertex3> vertList = new List<Vertex3>(skin._weightCount); Matrix* pMatrix = null; UnsafeBuffer remap = new UnsafeBuffer(skin._weightCount * 2); ushort* pRemap = (ushort*)remap.Address; pNorms = (Vector3*)manager._faceData[1].Address; manager._vertices = vertList; //Find vertex source foreach (SourceEntry s in geo._sources) if (s._id == geo._verticesInput._source) { pVert = (Vector3*)((UnsafeBuffer)s._arrayData).Address; break; } //Find joint source foreach (InputEntry inp in skin._jointInputs) if (inp._semantic == SemanticType.JOINT) { foreach (SourceEntry src in skin._sources) if (src._id == inp._source) { jointStrings = src._arrayData as string[]; break; } } else if (inp._semantic == SemanticType.INV_BIND_MATRIX) { foreach (SourceEntry src in skin._sources) if (src._id == inp._source) { pMatrix = (Matrix*)((UnsafeBuffer)src._arrayData).Address; break; } } Error = "There was a problem creating the list of bones for geometry entry " + geo._name; //Populate bone list boneCount = jointStrings.Length; boneList = new MDL0BoneNode[boneCount]; for (int i = 0; i < boneCount; i++) boneList[i] = scene.FindNode(jointStrings[i])._node as MDL0BoneNode; //Build command list foreach (InputEntry inp in skin._weightInputs) { switch (inp._semantic) { case SemanticType.JOINT: pCmd[inp._offset] = 1; break; case SemanticType.WEIGHT: pCmd[inp._offset] = 2; //Get weight source foreach (SourceEntry src in skin._sources) if (src._id == inp._source) { pWeights = (float*)((UnsafeBuffer)src._arrayData).Address; break; } break; default: pCmd[inp._offset] = 0; break; } } Error = "There was a problem creating vertex influences for geometry entry " + geo._name; //Build vertex list and remap table for (int i = 0; i < skin._weightCount; i++) { //Create influence int iCount = skin._weights[i].Length / cmdCount; Influence inf = new Influence(/*iCount*/); fixed (int* p = skin._weights[i]) { int* iPtr = p; for (int x = 0; x < iCount; x++) { for (int z = 0; z < cmdCount; z++, iPtr++) if (pCmd[z] == 1) bone = boneList[*iPtr]; else if (pCmd[z] == 2) weight = pWeights[*iPtr]; inf._weights.Add(new BoneWeight(bone, weight)); } } inf.CalcMatrix(); Error = "There was a problem creating a vertex from the geometry entry " + geo._name + ".\nMake sure that all the vertices are weighted properly."; Vertex3 v; if (inf._weights.Count > 1) { //Match with manager inf = infManager.FindOrCreate(inf, true); v = new Vertex3(n._matrix * skin._bindMatrix * pVert[i], inf); //World position } else { bone = inf._weights[0].Bone; v = new Vertex3(n._matrix * bone._inverseBindMatrix * skin._bindMatrix * pVert[i], bone); //Local position } ushort index = 0; while (index < vertList.Count) { if (v.Equals(vertList[index])) break; index++; } if (index == vertList.Count) vertList.Add(v); pRemap[i] = index; } Error = "There was a problem fixing normal rotations for geometry entry " + geo._name; //Remap vertex indices and fix normals for (int i = 0; i < manager._pointCount; i++, pVInd++) { *pVInd = pRemap[*pVInd]; Vertex3 v = null; if (*pVInd < vertList.Count) v = vertList[*pVInd]; if (v != null && v._matrixNode != null) if (v._matrixNode.Weights.Count > 1) pNorms[i] = skin._bindMatrix.GetRotationMatrix() * pNorms[i]; else pNorms[i] = skin._bindMatrix.GetRotationMatrix() * v._matrixNode.Weights[0].Bone._inverseBindMatrix.GetRotationMatrix() * pNorms[i]; } remap.Dispose(); return manager; }
static void EditLayout() { // sceneInfo GUILayout.BeginVertical(); GUILayout.Label("Chapter:"); scene_.CID = GUILayout.TextField(scene_.CID); GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.Label("SceneID:"); scene_.ID = GUILayout.TextField(scene_.ID); GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.Label("SceneName:"); scene_.Name = GUILayout.TextField(scene_.Name); GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.Label("BattleName:"); scene_.BattleName = GUILayout.TextField(scene_.BattleName); GUILayout.EndVertical(); GUILayout.Space(5); TotalScrollPos_ = GUILayout.BeginScrollView(TotalScrollPos_, GUILayout.Width(600), GUILayout.Height(600)); // npcInfo GUILayout.Box("NpcInfo"); if (scene_.npcList.Count > 0) { NpcScrollPos_ = GUILayout.BeginScrollView(NpcScrollPos_, GUILayout.Width(300), GUILayout.Height(200)); for (int i = 0; i < scene_.npcList.Count; ++i) { GUILayout.BeginHorizontal(); GUILayout.Label("ID"); ((Npc)scene_.npcList[i]).ID = GUILayout.TextField(((Npc)scene_.npcList[i]).ID); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Position" + new Vector3(((Npc)scene_.npcList[i]).X, ((Npc)scene_.npcList[i]).Y, ((Npc)scene_.npcList[i]).Z)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Rotation" + new Quaternion(((Npc)scene_.npcList[i]).RX, ((Npc)scene_.npcList[i]).RY, ((Npc)scene_.npcList[i]).RZ, ((Npc)scene_.npcList[i]).RW)); GUILayout.EndHorizontal(); if (scene_.npcList.Count != npcObjList_.Count) { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Capsule); go.transform.parent = root.transform; go.transform.position = new Vector3(((Npc)scene_.npcList[i]).X, ((Npc)scene_.npcList[i]).Y, ((Npc)scene_.npcList[i]).Z); go.transform.rotation = new Quaternion(((Npc)scene_.npcList[i]).RX, ((Npc)scene_.npcList[i]).RY, ((Npc)scene_.npcList[i]).RZ, ((Npc)scene_.npcList[i]).RW); npcObjList_.Add(go); } ((Npc)scene_.npcList[i]).X = npcObjList_[i].transform.position.x; ((Npc)scene_.npcList[i]).Y = npcObjList_[i].transform.position.y; ((Npc)scene_.npcList[i]).Z = npcObjList_[i].transform.position.z; ((Npc)scene_.npcList[i]).RX = npcObjList_[i].transform.rotation.x; ((Npc)scene_.npcList[i]).RY = npcObjList_[i].transform.rotation.y; ((Npc)scene_.npcList[i]).RZ = npcObjList_[i].transform.rotation.z; ((Npc)scene_.npcList[i]).RW = npcObjList_[i].transform.rotation.w; if (GUILayout.Button("Delete")) { scene_.npcList.RemoveAt(i); DestroyImmediate(npcObjList_[i]); npcObjList_.RemoveAt(i); } GUILayout.Space(15); } GUILayout.EndScrollView(); } else { GUILayout.Label("Empty"); } GUILayout.Space(5); // monsterInfo GUILayout.Box("ZoneInfo"); ZoneScrollPos_ = GUILayout.BeginScrollView(ZoneScrollPos_, GUILayout.Width(300), GUILayout.Height(200)); for (int i = 0; i < scene_.zoneList.Count; ++i) { GUILayout.BeginHorizontal(); GUILayout.Label("ID"); GUILayout.Label(((Zone)scene_.zoneList[i]).ID); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Radius " + ((Zone)scene_.zoneList[i]).Radius); GUILayout.Label("Center" + new Vector3(((Zone)scene_.zoneList[i]).CenterX, 0f, ((Zone)scene_.zoneList[i]).CenterZ)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("MinCount"); ((Zone)scene_.zoneList[i]).MonsterMin = GUILayout.TextField(((Zone)scene_.zoneList[i]).MonsterMin); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("MaxCount"); ((Zone)scene_.zoneList[i]).MonsterMax = GUILayout.TextField(((Zone)scene_.zoneList[i]).MonsterMax); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Rate"); ((Zone)scene_.zoneList[i]).Rate = GUILayout.TextField(((Zone)scene_.zoneList[i]).Rate); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("MonsterGroup"); ((Zone)scene_.zoneList[i]).MonsterGroup = GUILayout.TextField(((Zone)scene_.zoneList[i]).MonsterGroup); GUILayout.EndHorizontal(); if (scene_.zoneList.Count != zoneObjList_.Count) { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere); go.transform.localScale = new Vector3(1f, 0.1f, 1f); DestroyImmediate(go.GetComponent <SphereCollider>()); go.transform.parent = root.transform; go.transform.position = new Vector3(((Zone)scene_.zoneList[i]).CenterX, ((Zone)scene_.zoneList[i]).CenterY, ((Zone)scene_.zoneList[i]).CenterZ); go.transform.localScale = new Vector3(((Zone)scene_.zoneList[i]).Radius * 2f, 0.1f, ((Zone)scene_.zoneList[i]).Radius * 2f); zoneObjList_.Add(go); } ((Zone)scene_.zoneList[i]).CenterX = zoneObjList_[i].transform.position.x; ((Zone)scene_.zoneList[i]).CenterY = zoneObjList_[i].transform.position.y; ((Zone)scene_.zoneList[i]).CenterZ = zoneObjList_[i].transform.position.z; ((Zone)scene_.zoneList[i]).Radius = zoneObjList_[i].transform.localScale.x / 2f; if (GUILayout.Button("Delete")) { scene_.zoneList.RemoveAt(i); DestroyImmediate(zoneObjList_[i]); zoneObjList_.RemoveAt(i); } GUILayout.Space(15); } GUILayout.EndScrollView(); GUILayout.Space(10); // entryInfo GUILayout.Box("EntryInfo"); EntryScrollPos_ = GUILayout.BeginScrollView(EntryScrollPos_, GUILayout.Width(300), GUILayout.Height(200)); for (int i = 0; i < scene_.entryList.Count; ++i) { GUILayout.BeginHorizontal(); GUILayout.Label("ID"); GUILayout.Label(((SceneEntry)scene_.entryList[i]).ID); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); ((SceneEntry)scene_.entryList[i]).isBornPos = GUILayout.Toggle(((SceneEntry)scene_.entryList[i]).isBornPos, "是否当作出生点"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Radius " + ((SceneEntry)scene_.entryList[i]).Radius); GUILayout.Label("Center" + new Vector3(((SceneEntry)scene_.entryList[i]).CenterX, ((SceneEntry)scene_.entryList[i]).CenterY, ((SceneEntry)scene_.entryList[i]).CenterZ)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("AreaNum"); ((SceneEntry)scene_.entryList[i]).areaNum = GUILayout.TextField(((SceneEntry)scene_.entryList[i]).areaNum); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("toSceneID"); ((SceneEntry)scene_.entryList[i]).toSceneID = GUILayout.TextField(((SceneEntry)scene_.entryList[i]).toSceneID); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("toEntryID"); ((SceneEntry)scene_.entryList[i]).toEntryID = GUILayout.TextField(((SceneEntry)scene_.entryList[i]).toEntryID); GUILayout.EndHorizontal(); if (scene_.entryList.Count != entryObjList_.Count) { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere); go.transform.localScale = new Vector3(1f, 0.1f, 1f); DestroyImmediate(go.GetComponent <SphereCollider>()); go.transform.parent = root.transform; go.transform.position = new Vector3(((SceneEntry)scene_.entryList[i]).CenterX, ((SceneEntry)scene_.entryList[i]).CenterY, ((SceneEntry)scene_.entryList[i]).CenterZ); go.transform.localScale = new Vector3(((SceneEntry)scene_.entryList[i]).Radius * 2f, 0.1f, ((SceneEntry)scene_.entryList[i]).Radius * 2f); entryObjList_.Add(go); } ((SceneEntry)scene_.entryList[i]).CenterX = entryObjList_[i].transform.position.x; ((SceneEntry)scene_.entryList[i]).CenterY = entryObjList_[i].transform.position.y; ((SceneEntry)scene_.entryList[i]).CenterZ = entryObjList_[i].transform.position.z; ((SceneEntry)scene_.entryList[i]).Radius = entryObjList_[i].transform.localScale.x / 2f; if (GUILayout.Button("Delete")) { scene_.entryList.RemoveAt(i); DestroyImmediate(entryObjList_[i]); entryObjList_.RemoveAt(i); } GUILayout.Space(15); } GUILayout.EndScrollView(); GUILayout.Space(10); // mutifuncPointInfo GUILayout.Box("FunctionalPoints"); FuncPointScrollPos_ = GUILayout.BeginScrollView(FuncPointScrollPos_, GUILayout.Width(500), GUILayout.Height(400)); for (int i = 0; i < scene_.funcPointList.Count; ++i) { GUILayout.BeginHorizontal(); GUILayout.Label("ID"); ((FunctionalPoint)scene_.funcPointList[i]).ID = i.ToString(); GUILayout.Label(i.ToString()); GUILayout.EndHorizontal(); GUI.color = Color.yellow; GUILayout.BeginHorizontal(); GUILayout.Label("NpcId"); GUILayout.Label(((FunctionalPoint)scene_.funcPointList[i]).NpcId); GUILayout.EndHorizontal(); GUI.color = Color.white; GUILayout.BeginHorizontal(); GUILayout.Label("Position" + new Vector3(((FunctionalPoint)scene_.funcPointList[i]).X, ((FunctionalPoint)scene_.funcPointList[i]).Y, ((FunctionalPoint)scene_.funcPointList[i]).Z)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Rotation" + new Quaternion(((FunctionalPoint)scene_.funcPointList[i]).RX, ((FunctionalPoint)scene_.funcPointList[i]).RY, ((FunctionalPoint)scene_.funcPointList[i]).RZ, ((FunctionalPoint)scene_.funcPointList[i]).RW)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Type"); ((FunctionalPoint)scene_.funcPointList[i]).type = (FunctionalPointType)GUILayout.SelectionGrid((int)((FunctionalPoint)scene_.funcPointList[i]).type, new string[] { "FPT_None", "FPT_Tongji", "FPT_Mogu", "FPT_SinglePK", "FPT_TeamPK", "FPT_Npc", "FPT_Xiji" }, 5); GUILayout.EndHorizontal(); if (scene_.funcPointList.Count != funcObjList_.Count) { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Capsule); go.name = "FunctionalPoint"; go.GetComponent <MeshRenderer>().material = funcPointMat_; go.transform.parent = root.transform; go.transform.position = new Vector3(((FunctionalPoint)scene_.funcPointList[i]).X, ((FunctionalPoint)scene_.funcPointList[i]).Y, ((FunctionalPoint)scene_.funcPointList[i]).Z); go.transform.rotation = new Quaternion(((FunctionalPoint)scene_.funcPointList[i]).RX, ((FunctionalPoint)scene_.funcPointList[i]).RY, ((FunctionalPoint)scene_.funcPointList[i]).RZ, ((FunctionalPoint)scene_.funcPointList[i]).RW); funcObjList_.Add(go); } ((FunctionalPoint)scene_.funcPointList[i]).X = funcObjList_[i].transform.position.x; ((FunctionalPoint)scene_.funcPointList[i]).Y = funcObjList_[i].transform.position.y; ((FunctionalPoint)scene_.funcPointList[i]).Z = funcObjList_[i].transform.position.z; ((FunctionalPoint)scene_.funcPointList[i]).RX = funcObjList_[i].transform.rotation.x; ((FunctionalPoint)scene_.funcPointList[i]).RY = funcObjList_[i].transform.rotation.y; ((FunctionalPoint)scene_.funcPointList[i]).RZ = funcObjList_[i].transform.rotation.z; ((FunctionalPoint)scene_.funcPointList[i]).RW = funcObjList_[i].transform.rotation.w; if (GUILayout.Button("Delete")) { scene_.funcPointList.RemoveAt(i); DestroyImmediate(funcObjList_[i]); funcObjList_.RemoveAt(i); } GUILayout.Space(15); } GUILayout.EndScrollView(); GUILayout.Space(10); GUILayout.EndScrollView(); GUILayout.BeginHorizontal(); if (GUILayout.Button("AddMonster")) { GameObject monsterArea = GameObject.CreatePrimitive(PrimitiveType.Sphere); monsterArea.transform.localScale = new Vector3(1f, 0.1f, 1f); DestroyImmediate(monsterArea.GetComponent <SphereCollider>()); monsterArea.transform.parent = root.transform; Zone zone = new Zone(); zone.ID = (scene_.zoneList.Count + 1).ToString(); zoneObjList_.Add(monsterArea); scene_.Add(zone); } if (GUILayout.Button("AddEntry")) { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere); go.transform.localScale = new Vector3(1f, 0.1f, 1f); DestroyImmediate(go.GetComponent <SphereCollider>()); go.transform.parent = root.transform; SceneEntry entry = new SceneEntry(); entry.ID = (scene_.entryList.Count + 1).ToString(); entryObjList_.Add(go); scene_.Add(entry); } if (GUILayout.Button("AddFuncPoint")) { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Capsule); go.name = "FunctionalPoint"; go.GetComponent <MeshRenderer>().material = funcPointMat_; go.transform.parent = root.transform; FunctionalPoint fp = new FunctionalPoint(); funcObjList_.Add(go); scene_.Add(fp); } if (GUILayout.Button("CombieNpcPoint")) { for (int i = 0; i < scene_.npcList.Count; ++i) { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Capsule); go.name = "FunctionalPoint"; go.GetComponent <MeshRenderer>().material = funcPointMat_; go.transform.parent = root.transform; go.transform.position = new Vector3(((Npc)scene_.npcList[i]).X, ((Npc)scene_.npcList[i]).Y, ((Npc)scene_.npcList[i]).Z); go.transform.rotation = new Quaternion(((Npc)scene_.npcList[i]).RX, ((Npc)scene_.npcList[i]).RY, ((Npc)scene_.npcList[i]).RZ, ((Npc)scene_.npcList[i]).RW); funcObjList_.Add(go); FunctionalPoint fp = new FunctionalPoint(); fp.NpcId = ((Npc)scene_.npcList[i]).ID; fp.type = FunctionalPointType.FPT_Npc; scene_.Add(fp); } scene_.npcList.Clear(); npcObjList_.Clear(); } // createXML if (GUILayout.Button("Save")) { if (EditorUtility.DisplayDialog("Save", "确定保存数据吗?", "似的", "不")) { Save(scene_); EditorUtility.DisplayDialog("Alert", "保存完毕", "确定"); } } // update if (GUILayout.Button("Update")) { UpdateEnviroment(); } GUILayout.EndHorizontal(); SceneView.RepaintAll(); }
public void Add(SceneEntry entry) { entryList.Add(entry); }
/// <summary> /// Loads a particular Scene Entry in the Editor /// </summary> /// <param name="entry">The entry to load</param> private void LoadEntryInEditor( SceneEntry entry ) { // Bad time to do this. if ( EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying ) return; // We can't do this if ( string.IsNullOrEmpty(entry.scene.editorPath) || entry.scene.editorPath == gameObject.scene.path ) return; bool bShouldLoad = entry.loadInEditor && AmsPreferences.AllowAutoload; var scene = entry.scene.scene; try { if ( !scene.IsValid() ) { if ( bShouldLoad ) { AmsDebug.Log( this, "Scene {0} is loading Scene {1} in Editor", gameObject.scene.name, entry.scene.name ); EditorSceneManager.OpenScene( entry.scene.editorPath, OpenSceneMode.Additive ); } else { AmsDebug.Log( this, "Scene {0} is opening Scene {1} (without loading) in Editor", gameObject.scene.name, entry.scene.name ); EditorSceneManager.OpenScene( entry.scene.editorPath, OpenSceneMode.AdditiveWithoutLoading ); } } else if ( bShouldLoad != scene.isLoaded ) { if ( bShouldLoad && !scene.isLoaded ) { AmsDebug.Log( this, "Scene {0} is loading existing Scene {1} in Editor", gameObject.scene.name, entry.scene.name ); EditorSceneManager.OpenScene( entry.scene.editorPath, OpenSceneMode.Additive ); } else { AmsDebug.Log( this, "Scene {0} is closing Scene {1} in Editor", gameObject.scene.name, entry.scene.name ); EditorSceneManager.CloseScene( scene, false ); } } } catch ( System.Exception ex ) { Debug.LogException( ex, this ); } }
private static PrimitiveManager DecodePrimitivesWeighted( Matrix bindMatrix, GeometryEntry geo, SkinEntry skin, SceneEntry scene, InfluenceManager infManager, Type boneType) { PrimitiveManager manager = DecodePrimitives(geo); IBoneNode[] boneList; IBoneNode bone = null; int boneCount; string[] jointStringArray = null; string jointString = null; byte * pCmd = stackalloc byte[4]; int cmdCount = skin._weightInputs.Count; float weight = 0; float * pWeights = null; Vector3 * pVert = null, pNorms = null; ushort * pVInd = (ushort *)manager._indices.Address; List <Vertex3> vertList = new List <Vertex3>(skin._weightCount); Matrix * pMatrix = null; UnsafeBuffer remap = new UnsafeBuffer(skin._weightCount * 2); ushort * pRemap = (ushort *)remap.Address; if (manager._faceData[1] != null) { pNorms = (Vector3 *)manager._faceData[1].Address; } manager._vertices = vertList; //Find vertex source foreach (SourceEntry s in geo._sources) { if (s._id == geo._verticesInput._source) { pVert = (Vector3 *)((UnsafeBuffer)s._arrayData).Address; break; } } //Find joint source foreach (InputEntry inp in skin._jointInputs) { if (inp._semantic == SemanticType.JOINT) { foreach (SourceEntry src in skin._sources) { if (src._id == inp._source) { jointStringArray = src._arrayData as string[]; jointString = src._arrayDataString; break; } } } else if (inp._semantic == SemanticType.INV_BIND_MATRIX) { foreach (SourceEntry src in skin._sources) { if (src._id == inp._source) { pMatrix = (Matrix *)((UnsafeBuffer)src._arrayData).Address; break; } } } } Error = "There was a problem creating the list of bones for geometry entry " + geo._name; //Populate bone list boneCount = jointStringArray.Length; boneList = new IBoneNode[boneCount]; for (int i = 0; i < boneCount; i++) { NodeEntry entry = scene.FindNode(jointStringArray[i]); if (entry != null && entry._node != null) { boneList[i] = entry._node as IBoneNode; } else { //Search in reverse! foreach (NodeEntry node in scene._nodes) { if ((entry = RecursiveTestNode(jointString, node)) != null) { if (entry._node != null) { boneList[i] = entry._node as IBoneNode; } break; } } //Couldn't find the bone if (boneList[i] == null) { boneList[i] = Activator.CreateInstance(boneType) as IBoneNode; } } } //Build command list foreach (InputEntry inp in skin._weightInputs) { switch (inp._semantic) { case SemanticType.JOINT: pCmd[inp._offset] = 1; break; case SemanticType.WEIGHT: pCmd[inp._offset] = 2; //Get weight source foreach (SourceEntry src in skin._sources) { if (src._id == inp._source) { pWeights = (float *)((UnsafeBuffer)src._arrayData).Address; break; } } break; default: pCmd[inp._offset] = 0; break; } } Error = "There was a problem creating vertex influences for geometry entry " + geo._name; //Build vertex list and remap table for (int i = 0; i < skin._weightCount; i++) { //Create influence int iCount = skin._weights[i].Length / cmdCount; Influence inf = new Influence(); fixed(int *p = skin._weights[i]) { int *iPtr = p; for (int x = 0; x < iCount; x++) { for (int z = 0; z < cmdCount; z++, iPtr++) { if (pCmd[z] == 1) { bone = boneList[*iPtr]; } else if (pCmd[z] == 2) { weight = pWeights[*iPtr]; } } inf.AddWeight(new BoneWeight(bone, weight)); } } inf.CalcMatrix(); Error = "There was a problem creating a vertex from the geometry entry " + geo._name + ".\nMake sure that all the vertices are weighted properly."; Vector3 worldPos = bindMatrix * skin._bindMatrix * pVert[i]; Vertex3 v; if (inf.Weights.Count > 1) { //Match with manager inf = infManager.FindOrCreate(inf); v = new Vertex3(worldPos, inf); //World position } else { bone = inf.Weights[0].Bone; v = new Vertex3(bone.InverseBindMatrix * worldPos, bone); //Local position } ushort index = 0; while (index < vertList.Count) { if (v.Equals(vertList[index])) { break; } index++; } if (index == vertList.Count) { vertList.Add(v); } pRemap[i] = index; } Error = "There was a problem fixing normal rotations for geometry entry " + geo._name; //Remap vertex indices and fix normals for (int i = 0; i < manager._pointCount; i++, pVInd++) { *pVInd = pRemap[*pVInd]; if (pNorms != null) { Vertex3 v = null; if (*pVInd < vertList.Count) { v = vertList[*pVInd]; } if (v != null && v.MatrixNode != null) { if (v.MatrixNode.Weights.Count > 1) { pNorms[i] = (bindMatrix * skin._bindMatrix).GetRotationMatrix() * pNorms[i]; } else { pNorms[i] = (v.MatrixNode.Weights[0].Bone.InverseBindMatrix * bindMatrix * skin._bindMatrix).GetRotationMatrix() * pNorms[i]; } } } } remap.Dispose(); return(manager); }
/// <summary> /// Load a particular Scene Entry /// </summary> /// <param name="entry">The Entry to load</param> private void LoadEntryAtRuntime( SceneEntry entry ) { // Don't load if ( entry.loadMethod == LoadMethod.DontLoad ) return; // Already loaded, try editor first var existingScene = SceneManager.GetSceneByPath(entry.scene.editorPath); // Try runtime path if ( !existingScene.IsValid() ) existingScene = SceneManager.GetSceneByPath(entry.scene.runtimePath); #if UNITY_EDITOR // Could be we just created the scene because it's baked if ( !existingScene.IsValid() ) existingScene = SceneManager.GetSceneByName(entry.scene.runtimePath); if ( Application.isEditor && entry.loadMethod == LoadMethod.Baked ) { // If we've already processed this, return early if ( _bakedScenesLoading.Contains(entry) || _bakedScenesMerged.Contains(entry) ) return; // We're loading this entry, don't allow this to be re-entrant _bakedScenesLoading.Add(entry); if ( !existingScene.IsValid() ) { // This allows us to load the level even in playmode EditorApplication.LoadLevelAdditiveInPlayMode( entry.scene.editorPath ); } // Loading a scene can take multiple frames so we have to wait. // Baking scenes can only take place when they're all loaded due to cross-scene referencing if ( _waitingToBake != null ) StopCoroutine( _waitingToBake ); _waitingToBake = StartCoroutine( CoWaitAndBake() ); return; } #endif // If it's already loaded, return early if( existingScene.IsValid() ) return; if ( entry.loadMethod == LoadMethod.AdditiveAsync ) { AmsDebug.Log( this, "Loading {0} Asynchronously from {1}", entry.scene.name, gameObject.scene.name ); entry.asyncOp = SceneManager.LoadSceneAsync( entry.scene.runtimePath, LoadSceneMode.Additive ); return; } if ( entry.loadMethod == LoadMethod.Additive ) { AmsDebug.Log( this, "Loading {0} from {1}", entry.scene.name, gameObject.scene.name ); SceneManager.LoadScene( entry.scene.runtimePath, LoadSceneMode.Additive ); return; } }
/// <summary> /// 'Bakes' a scene by merging it into our scene. /// </summary> /// <param name="entry">The entry to bake</param> private void PreMerge( SceneEntry entry ) { var scene = entry.scene.scene; // This is a last chance before that scene gets destroyed. var crossSceneRefs = AmsCrossSceneReferences.GetSceneSingleton( scene, false ); if ( crossSceneRefs ) crossSceneRefs.ResolvePendingCrossSceneReferences(); }
public SceneEntry Read(int index) { // TODO check possible corruption of files if(index >= count) return null; SceneEntry entry = new SceneEntry(); readerScene.BaseStream.Seek(index * ENTRY_SIZE, 0); entry.mapID = readerScene.ReadUInt16(); entry.scriptEnter = readerScene.ReadUInt16(); entry.scriptLeave = readerScene.ReadUInt16(); entry.firstEventID = readerScene.ReadUInt16(); return entry; }
private void MergeScene( SceneEntry entry ) { var scene = entry.scene.scene; // Make sure there is only ever one AmsMultiSceneSetup in a given scene var sourceSetup = GameObjectEx.GetSceneSingleton< AmsMultiSceneSetup >( scene, false ); if ( sourceSetup ) GameObject.Destroy( sourceSetup.gameObject ); AmsDebug.Log( this, "Merging {0} into {1}", scene.path, gameObject.scene.path ); SceneManager.MergeScenes( scene, gameObject.scene ); }
static PrimitiveManager DecodePrimitivesWeighted(GeometryEntry geo, SkinEntry skin, SceneEntry scene, InfluenceManager infManager) { PrimitiveManager manager = DecodePrimitives(geo); MDL0BoneNode[] boneList; MDL0BoneNode bone = null; int boneCount; string[] jointStrings = null; byte * pCmd = stackalloc byte[4]; int cmdCount = skin._weightInputs.Count; float weight = 0; float * pWeights = null; Vector3 * pVert = null; ushort * pVInd = (ushort *)manager._faceData[0].Address; List <Vertex3> vertList = new List <Vertex3>(skin._weightCount); Matrix * pMatrix = null; UnsafeBuffer remap = new UnsafeBuffer(skin._weightCount * 2); ushort * pRemap = (ushort *)remap.Address; manager._vertices = vertList; //Find vertex source foreach (SourceEntry s in geo._sources) { if (s._id == geo._verticesInput._source) { pVert = (Vector3 *)((UnsafeBuffer)s._arrayData).Address; break; } } //Find joint source foreach (InputEntry inp in skin._jointInputs) { if (inp._semantic == SemanticType.JOINT) { foreach (SourceEntry src in skin._sources) { if (src._id == inp._source) { jointStrings = src._arrayData as string[]; break; } } } else if (inp._semantic == SemanticType.INV_BIND_MATRIX) { foreach (SourceEntry src in skin._sources) { if (src._id == inp._source) { pMatrix = (Matrix *)((UnsafeBuffer)src._arrayData).Address; break; } } } } //Populate bone list boneCount = jointStrings.Length; boneList = new MDL0BoneNode[boneCount]; for (int i = 0; i < boneCount; i++) { boneList[i] = scene.FindNode(jointStrings[i])._node as MDL0BoneNode; } //Build command list foreach (InputEntry inp in skin._weightInputs) { switch (inp._semantic) { case SemanticType.JOINT: pCmd[inp._offset] = 1; break; case SemanticType.WEIGHT: pCmd[inp._offset] = 2; //Get weight source foreach (SourceEntry src in skin._sources) { if (src._id == inp._source) { pWeights = (float *)((UnsafeBuffer)src._arrayData).Address; break; } } break; default: pCmd[inp._offset] = 0; break; } } //Build vertex list and remap table for (int i = 0; i < skin._weightCount; i++) { //Create influence int iCount = skin._weights[i].Length / cmdCount; Influence inf = new Influence(iCount); fixed(int *p = skin._weights[i]) { int *iPtr = p; for (int x = 0; x < iCount; x++) { for (int z = 0; z < cmdCount; z++, iPtr++) { if (pCmd[z] == 1) { bone = boneList[*iPtr]; } else if (pCmd[z] == 2) { weight = pWeights[*iPtr]; } } inf._weights[x] = new BoneWeight(bone, weight); } } Vertex3 v; if (inf._weights.Length > 1) { //Match with manager inf = infManager.AddOrCreate(inf); v = new Vertex3(skin._bindMatrix * pVert[i], inf); //World position } else { bone = inf._weights[0].Bone; v = new Vertex3(bone._inverseBindMatrix * skin._bindMatrix * pVert[i], bone); //Local position } //Create Vertex, set to world position. //Vertex3 v = new Vertex3(skin._bindMatrix * pVert[i], inf); //Fix single-bind vertices //if (inf._weights.Length == 1) // v.Position = inf._weights[0].Bone._inverseBindMatrix * v.Position; ushort index = 0; while (index < vertList.Count) { if (v.Equals(vertList[index])) { break; } index++; } if (index == vertList.Count) { vertList.Add(v); } pRemap[i] = index; } //Remap vertex indices for (int i = 0; i < manager._pointCount; i++, pVInd++) { *pVInd = pRemap[*pVInd]; } remap.Dispose(); return(manager); }
private void EnumNode(NodeEntry node, ResourceNode parent, SceneEntry scene, MDL0Node model, DecoderShell shell) { MDL0BoneNode bone = null; Influence inf = null; if (node._type == NodeType.JOINT) { Error = "There was a problem creating a new bone."; bone = new MDL0BoneNode(); bone._name = node._name != null ? node._name : node._id; bone._bindState = node._transform; node._node = bone; parent._children.Add(bone); bone._parent = parent; bone.RecalcBindState(); bone.CalcFlags(); foreach (NodeEntry e in node._children) EnumNode(e, bone, scene, model, shell); inf = new Influence(bone); model._influences._influences.Add(inf); } else foreach (NodeEntry e in node._children) EnumNode(e, parent, scene, model, shell); foreach (InstanceEntry inst in node._instances) { if (inst._type == InstanceType.Controller) { foreach (SkinEntry skin in shell._skins) if (skin._id == inst._url) { foreach (GeometryEntry g in shell._geometry) if (g._id == skin._skinSource) { Error = @" There was a problem decoding weighted primitives for the object " + (node._name != null ? node._name : node._id) + ".\nOne or more vertices may not be weighted correctly."; Say("Decoding weighted primitives for " + (g._name != null ? g._name : g._id) + "..."); CreateObject(inst, node, parent, DecodePrimitivesWeighted(node, g, skin, scene, model._influences, ref Error), model, shell); break; } break; } } else if (inst._type == InstanceType.Geometry) { foreach (GeometryEntry g in shell._geometry) if (g._id == inst._url) { Error = "There was a problem decoding unweighted primitives for the object " + (node._name != null ? node._name : node._id) + "."; Say("Decoding unweighted primitives for " + (g._name != null ? g._name : g._id) + "..."); CreateObject(inst, node, parent, DecodePrimitivesUnweighted(node, g), model, shell); break; } } else { foreach (NodeEntry e in shell._nodes) if (e._id == inst._url) EnumNode(e, parent, scene, model, shell); } } }
private SceneEntry ParseScene() { SceneEntry sc = new SceneEntry(); while (_reader.ReadAttribute()) if (_reader.Name.Equals("id", true)) sc._id = (string)_reader.Value; while (_reader.ReadAttribute()) if (_reader.Name.Equals("name", true)) sc._name = (string)_reader.Value; while (_reader.BeginElement()) { if (_reader.Name.Equals("node", true)) sc._nodes.Add(ParseNode()); _reader.EndElement(); } return sc; }
/// <summary> /// OnBeforeSerialize is called whenever we're about to save or inspect this Component. /// We want to match exactly what the Editor has in terms of Scene setup, so we do it here. /// </summary> public void OnBeforeSerialize() { #if UNITY_EDITOR if ( !this || BuildPipeline.isBuildingPlayer || Application.isPlaying ) return; // Save off the scene path if ( gameObject && gameObject.scene.IsValid() ) _thisScenePath = gameObject.scene.path; // We don't care about the scene setup if ( !_isMainScene ) return; var newSceneSetup = new List<SceneEntry>(); var activeScene = EditorSceneManager.GetActiveScene(); // Update our scene setup SceneSetup[] editorSceneSetup = EditorSceneManager.GetSceneManagerSetup(); for(int i = 0 ; i < editorSceneSetup.Length ; ++i) { // If we're the active scene, don't save it. var editorEntry = editorSceneSetup[i]; if ( editorEntry.path == activeScene.path ) continue; var newEntry = new SceneEntry(editorEntry); newSceneSetup.Add( newEntry ); // Save the baked settings var oldEntry = _sceneSetup.Find( x => newEntry.scene.Equals(x.scene) ); if ( oldEntry != null ) { newEntry.loadMethod = oldEntry.loadMethod; } } // If we had a new scene setup... if ( !newSceneSetup.SequenceEqual(_sceneSetup) ) { _sceneSetup = newSceneSetup; EditorUtility.SetDirty( this ); if ( gameObject ) EditorSceneManager.MarkSceneDirty( gameObject.scene ); } #endif }
static PrimitiveManager DecodePrimitivesWeighted(GeometryEntry geo, SkinEntry skin, SceneEntry scene, InfluenceManager infManager, ref string Error) { PrimitiveManager manager = DecodePrimitives(geo); MDL0BoneNode[] boneList; MDL0BoneNode bone = null; int boneCount; string[] jointStrings = null; byte * pCmd = stackalloc byte[4]; int cmdCount = skin._weightInputs.Count; float weight = 0; float * pWeights = null; Vector3 * pVert = null, pNorms = null; ushort * pVInd = (ushort *)manager._indices.Address; List <Vertex3> vertList = new List <Vertex3>(skin._weightCount); Matrix * pMatrix = null; UnsafeBuffer remap = new UnsafeBuffer(skin._weightCount * 2); ushort * pRemap = (ushort *)remap.Address; pNorms = (Vector3 *)manager._faceData[1].Address; //List<int> FixedIndices = new List<int>(); manager._vertices = vertList; //Find vertex source foreach (SourceEntry s in geo._sources) { if (s._id == geo._verticesInput._source) { pVert = (Vector3 *)((UnsafeBuffer)s._arrayData).Address; break; } } //Find joint source foreach (InputEntry inp in skin._jointInputs) { if (inp._semantic == SemanticType.JOINT) { foreach (SourceEntry src in skin._sources) { if (src._id == inp._source) { jointStrings = src._arrayData as string[]; break; } } } else if (inp._semantic == SemanticType.INV_BIND_MATRIX) { foreach (SourceEntry src in skin._sources) { if (src._id == inp._source) { pMatrix = (Matrix *)((UnsafeBuffer)src._arrayData).Address; break; } } } } Error = "There was a problem creating the list of bones for geometry entry " + geo._name; //Populate bone list boneCount = jointStrings.Length; boneList = new MDL0BoneNode[boneCount]; for (int i = 0; i < boneCount; i++) { boneList[i] = scene.FindNode(jointStrings[i])._node as MDL0BoneNode; } //Build command list foreach (InputEntry inp in skin._weightInputs) { switch (inp._semantic) { case SemanticType.JOINT: pCmd[inp._offset] = 1; break; case SemanticType.WEIGHT: pCmd[inp._offset] = 2; //Get weight source foreach (SourceEntry src in skin._sources) { if (src._id == inp._source) { pWeights = (float *)((UnsafeBuffer)src._arrayData).Address; break; } } break; default: pCmd[inp._offset] = 0; break; } } Error = "There was a problem creating vertex influences for geometry entry " + geo._name; //Build vertex list and remap table for (int i = 0; i < skin._weightCount; i++) { //Create influence int iCount = skin._weights[i].Length / cmdCount; Influence inf = new Influence(iCount); fixed(int *p = skin._weights[i]) { int *iPtr = p; for (int x = 0; x < iCount; x++) { for (int z = 0; z < cmdCount; z++, iPtr++) { if (pCmd[z] == 1) { bone = boneList[*iPtr]; } else if (pCmd[z] == 2) { weight = pWeights[*iPtr]; } } //if (bone != null) // if (bone.Name == "TopN" || bone.Name == "XRotN" || bone.Name == "YRotN" || bone.Name == "TransN" || bone.Name == "ThrowN" || bone.Name == "FacePattern") // Console.WriteLine(bone.Name); // else if (bone.Parent != null) // if (bone.Parent.Name == "FacePattern") // Console.WriteLine(bone.Name); inf._weights[x] = new BoneWeight(bone, weight); } } inf.CalcMatrix(); Error = "There was a problem creating a vertex from the geometry entry " + geo._name + ".\nMake sure that all the vertices are weighted properly."; Vertex3 v; if (inf._weights.Length > 1) { //Match with manager inf = infManager.AddOrCreate(inf); v = new Vertex3(skin._bindMatrix * pVert[i], inf); //World position } else { bone = inf._weights[0].Bone; v = new Vertex3(bone._inverseBindMatrix * skin._bindMatrix * pVert[i], bone); //Local position } ////Create Vertex, set to world position. //v = new Vertex3(skin._bindMatrix * pVert[i], inf); ////Fix single-bind vertices //v.Position = inf._weights[0].Bone._inverseBindMatrix * v.Position; ushort index = 0; while (index < vertList.Count) { if (v.Equals(vertList[index])) { break; } index++; } if (index == vertList.Count) { vertList.Add(v); } pRemap[i] = index; } Error = "There was a problem fixing normal rotations for geometry entry " + geo._name; //Remap vertex indices and fix normals for (int i = 0; i < manager._pointCount; i++, pVInd++) { * pVInd = pRemap[*pVInd]; Vertex3 v = null; if (*pVInd < vertList.Count) { v = vertList[*pVInd]; } if (v != null && v._influence != null) { if (v._influence.Weights.Length > 1) { pNorms[i] = skin._bindMatrix.GetRotationMatrix() * pNorms[i]; } else { pNorms[i] = skin._bindMatrix.GetRotationMatrix() * v._influence.Weights[0].Bone._inverseBindMatrix.GetRotationMatrix() * pNorms[i]; } } } remap.Dispose(); //manager.MergeTempData(); return(manager); }
private void EnumNode( NodeEntry node, ResourceNode parent, SceneEntry scene, IModel model, DecoderShell shell, List <ObjectInfo> objects, Matrix bindMatrix, Matrix parentInvMatrix) { bindMatrix *= node._matrix; if (node._type == NodeType.JOINT || (node._type == NodeType.NONE && node._instances.Count == 0)) { Error = "There was a problem creating a new bone."; Influence inf = null; switch (ModelType) { case ImportType.MDL0: MDL0BoneNode bone = new MDL0BoneNode(); bone._name = node._name != null ? node._name : node._id; bone._bindState = node._matrix.Derive(); node._node = bone; parent._children.Add(bone); bone._parent = parent; bone.RecalcBindState(false, false); bone.CalcFlags(); parent = bone; inf = new Influence(bone); break; } if (inf != null) { model.Influences._influences.Add(inf); } } //parentInvMatrix *= node._matrix.Invert(); foreach (NodeEntry e in node._children) { EnumNode(e, parent, scene, model, shell, objects, bindMatrix, parentInvMatrix); } foreach (InstanceEntry inst in node._instances) { if (inst._type == InstanceType.Controller) { foreach (SkinEntry skin in shell._skins) { if (skin._id == inst._url) { foreach (GeometryEntry g in shell._geometry) { if (g._id == skin._skinSource) { objects.Add(new ObjectInfo(true, g, bindMatrix, skin, scene, inst, parent, node)); break; } } break; } } } else if (inst._type == InstanceType.Geometry) { foreach (GeometryEntry g in shell._geometry) { if (g._id == inst._url) { objects.Add(new ObjectInfo(false, g, bindMatrix, null, null, inst, parent, node)); break; } } } else { foreach (NodeEntry e in shell._nodes) { if (e._id == inst._url) { EnumNode(e, parent, scene, model, shell, objects, bindMatrix, parentInvMatrix); } } } } }
public static void OnSceneSaving(Scene scene, string path) { if (!scene.IsValid() || !scene.isLoaded) { return; } var instance = scene.GetSceneSingleton <AmsMultiSceneSetup>(true); if (!instance) { return; } instance.OnBeforeSerialize(); bool isSceneSetupManual = instance._sceneSetupMode == SceneSetupManagement.Manual; if (isSceneSetupManual) { return; } // Clear if we're disabled... by implicitly never setting any values var newSceneSetup = new List <SceneEntry>(); bool bForceDirty = false; // We only update the scene setup if we're the active scene var activeScene = SceneManager.GetActiveScene(); bool isSceneSetupAuto = instance._sceneSetupMode == SceneSetupManagement.Automatic && (activeScene == scene); if (isSceneSetupAuto) { // Update our scene setup SceneSetup[] editorSceneSetup = EditorSceneManager.GetSceneManagerSetup(); for (int i = 0; i < editorSceneSetup.Length; ++i) { // If we're the active scene, don't save it. var editorEntry = editorSceneSetup[i]; if (editorEntry.path == activeScene.path) { continue; } var newEntry = new SceneEntry(editorEntry); newSceneSetup.Add(newEntry); // Save the baked settings var oldEntry = instance._sceneSetup.Find(x => newEntry.scene.Equals(x.scene)); if (oldEntry != null) { newEntry.loadMethod = oldEntry.loadMethod; // We need to update the path if the runtime paths aren't the same (implies a rename) bForceDirty = bForceDirty || (newEntry.scene.runtimePath != oldEntry.scene.runtimePath); } } } // If we had a new scene setup... if (bForceDirty || !newSceneSetup.SequenceEqual(instance._sceneSetup)) { instance._sceneSetup = newSceneSetup; EditorUtility.SetDirty(instance); EditorSceneManager.MarkSceneDirty(scene); AmsDebug.Log(instance, "SceneSetup for {0} has been updated. If this is unexpected, click here to double-check the entries!", activeScene.name); } }
/// <summary> /// Remove a scene from thedatabase. /// </summary> /// <param name="sceneName"> Name of the scene.</param> public void RemoveScene(SceneEntry sceneName) { _dbConnector.RemoveScene(sceneName); }
/// <summary> /// Are we ready to merge in this scene entry? /// </summary> /// <param name="entry">The entry to merge</param> /// <returns>True iff it can be merged</returns> private bool CanMerge( SceneEntry entry ) { if ( entry.loadMethod != LoadMethod.Baked ) return false; var scene = entry.scene.scene; if ( !scene.IsValid() ) return false; var activeScene = SceneManager.GetActiveScene(); if ( scene == activeScene || scene == gameObject.scene ) return false; if ( !gameObject.scene.isLoaded ) return false; return true; }
private void UpdatedExportedScenesList(string absExportPath, List<string> assetProfiles) { List<SceneEntry> sceneEntries = new List<SceneEntry>(); string luaFile = Path.Combine(Application.StartupPath, @"..\..\..\..\Data\Vision\Tools\vPlayer\Exported.lua"); Regex entryRegex = new Regex(@"AddScene \((?<platform>\w+), ""(?<displayname>[^""]+)"", ""(?<scene>[^""]+)"", ""(?<searchpaths>[^""]+)""(, ""(?<nativeworkspace>[^""]+)"")?\)"); try { using (StreamReader reader = new StreamReader(luaFile)) { while (!reader.EndOfStream) { string line = reader.ReadLine().Trim(); if (line.StartsWith("--")) { continue; } Match match = entryRegex.Match(line); if (match.Success) { SceneEntry entry = new SceneEntry(); entry.Platform = match.Groups["platform"].Value; entry.DisplayName = match.Groups["displayname"].Value; entry.Scene = match.Groups["scene"].Value.Replace('\\', '/'); entry.SearchPaths = match.Groups["searchpaths"].Value.Split(';'); entry.NativeWorkspace = match.Groups["nativeworkspace"].Value; sceneEntries.Add(entry); } } } } catch (System.Exception) { // Ignore } string sceneName = Path.GetFileNameWithoutExtension(absExportPath); List<string> searchPaths = new List<string> { EditorManager.Project.ProjectSearchPath }; if (EditorManager.Project.CustomDataDirectories != null) { foreach (IProject.CustomDataDirectoryEntry dir in EditorManager.Project.CustomDataDirectories) { searchPaths.Add(dir.AbsolutePath); } } string projectRelativeScenePath; try { projectRelativeScenePath = EditorManager.Project.MakeRelative(absExportPath); } catch (Exception ex) { // Scene path can't be made relative to any data dir EditorManager.ShowMessageBox(ex.Message, "Failed to update exported scenes list for vPlayer"); return; } foreach (string profile in assetProfiles) { SceneEntry newEntry = new SceneEntry(); var platform = EditorManager.ProfileManager.GetProfileByName(profile).GetPlatform(); // Default profile name is equivalent to platform name newEntry.Platform = EditorManager.ProfileManager.GetDefaultProfile(platform).ToUpper(); newEntry.DisplayName = string.Format("{0} (Exported scene)", sceneName); newEntry.Scene = Path.ChangeExtension(projectRelativeScenePath, string.Format("{0}.vscene", profile)).Replace('\\', '/'); newEntry.SearchPaths = searchPaths.ToArray(); if (platform == TargetDevice_e.TARGETDEVICE_DX9 || platform == TargetDevice_e.TARGETDEVICE_DX11) { newEntry.NativeWorkspace = EditorManager.Project.WorkspaceDir.Replace('\\', '/').TrimEnd('/'); } else { newEntry.NativeWorkspace = ""; } // Remove existing entries for this scene and profile and place the new one on top of the list sceneEntries.RemoveAll(entry => entry.Scene == newEntry.Scene && entry.SearchPaths[0] == newEntry.SearchPaths[0] && entry.Platform == newEntry.Platform && entry.NativeWorkspace == newEntry.NativeWorkspace); sceneEntries.Insert(0, newEntry); } try { // Write out first 20 entries string output = "-- This file is automatically generated during scene export. Do not edit this file.\n"; output += string.Join("\n", sceneEntries.Take(20).Select(entry => entry.GetLuaLine())); System.IO.File.WriteAllText(luaFile, output); } catch (System.IO.IOException ex) { EditorManager.ShowMessageBox("An error occurred while writing ExportedScenes.lua:\n" + ex.Message, "File write error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Add scene to database /// </summary> /// <param name="sceneName"> Name of the scene</param> public abstract void AddScene(SceneEntry sceneName);
/// <summary> /// Remove scene to database /// </summary> /// <param name="sceneName"> Name of the scene</param> public abstract void RemoveScene(SceneEntry sceneName);
/// <summary> /// Add a scene to the database. /// </summary> /// <param name="sceneName"> Name of the scene.</param> public void AddScene(SceneEntry sceneName) { _dbConnector.AddScene(sceneName); }