public static CathodeParameter ParameterDefinitionToParameter(ParameterDefinition def) { CathodeParameter this_param = null; switch (def.datatype.ToUpper()) { case "POSITION": this_param = new CathodeTransform(); break; case "FLOAT": this_param = new CathodeFloat(); break; case "FILEPATH": case "STRING": this_param = new CathodeString(); break; case "SPLINEDATA": this_param = new CathodeSpline(); break; case "BOOL": this_param = new CathodeBool(); break; case "DIRECTION": this_param = new CathodeVector3(); break; case "INT": this_param = new CathodeInteger(); break; /* * case "ENUM": * thisParam = new CathodeEnum(); * ((CathodeEnum)thisParam).enumID = new cGUID("4C-B9-82-48"); //ALERTNESS_STATE is the first alphabetically * break; * case CathodeDataType.SHORT_GUID: * thisParam = new CathodeResource(); * ((CathodeResource)thisParam).resourceID = new cGUID("00-00-00-00"); * break; */ } return(this_param); }
public void PopulateUI(CathodeTransform cTrans, cGUID paramID) { transformVal = cTrans; POSITION_VARIABLE_DUMMY.Text = NodeDBEx.GetParameterName(paramID) + " (" + paramID.ToString() + ")"; POS_X.Value = (decimal)cTrans.position.x; POS_Y.Value = (decimal)cTrans.position.y; POS_Z.Value = (decimal)cTrans.position.z; ROT_X.Value = (decimal)cTrans.rotation.x; ROT_Y.Value = (decimal)cTrans.rotation.y; ROT_Z.Value = (decimal)cTrans.rotation.z; //POS_X.DataBindings.Add("Value", (decimal)cTrans.position.X, ""); //POS_Y.DataBindings.Add("Value", (decimal)cTrans.position.Y, ""); //POS_Z.DataBindings.Add("Value", (decimal)cTrans.position.Z, ""); //ROT_X.DataBindings.Add("Value", (decimal)cTrans.rotation.X, ""); //ROT_Y.DataBindings.Add("Value", (decimal)cTrans.rotation.Y, ""); //ROT_Z.DataBindings.Add("Value", (decimal)cTrans.rotation.Z, ""); }
private PosAndRot GetTransform(ref CathodeNodeEntity node) { PosAndRot toReturn = new PosAndRot(); foreach (CathodeParameterReference paramRef in node.nodeParameterReferences) { CathodeParameter param = commandsPAK.GetParameter(paramRef.offset); if (param == null) { continue; } if (param.dataType != CathodeDataType.POSITION) { continue; } CathodeTransform transform = (CathodeTransform)param; toReturn.position = transform.position; toReturn.rotation = Quaternion.Euler(transform.rotation); break; } return(toReturn); }
private void LoadFlowgraphAssets() { //First, make dummy prefabs of all flowgraphs GameObject rootGO = new GameObject(); AssetDatabase.StartAssetEditing(); for (int i = 0; i < levelData.CommandsPAK.AllFlowgraphs.Count; i++) { string fullFilePath = GetFlowgraphAssetPath(levelData.CommandsPAK.AllFlowgraphs[i]); string fileDirectory = GetDirectory(fullFilePath); if (!Directory.Exists(fileDirectory)) { Directory.CreateDirectory(fileDirectory); } if (!File.Exists(fullFilePath)) { PrefabUtility.SaveAsPrefabAsset(rootGO, fullFilePath); } } AssetDatabase.StopAssetEditing(); //Then, populate the prefabs for all flowgraphs AssetDatabase.StartAssetEditing(); for (int i = 0; i < levelData.CommandsPAK.AllFlowgraphs.Count; i++) { GameObject flowgraphGO = new GameObject(levelData.CommandsPAK.AllFlowgraphs[i].name); string nodeType = ""; for (int x = 0; x < levelData.CommandsPAK.AllFlowgraphs[i].nodes.Count; x++) { CathodeFlowgraph flowgraphRef = levelData.CommandsPAK.GetFlowgraph(levelData.CommandsPAK.AllFlowgraphs[i].nodes[x].nodeType); GameObject nodeGO = null; if (flowgraphRef != null) { //This is a reference to another flowgraph GameObject flowgraphAsset = Resources.Load <GameObject>(GetFlowgraphAssetPath(flowgraphRef, true)); nodeGO = PrefabUtility.InstantiatePrefab(flowgraphAsset) as GameObject; nodeGO.name = flowgraphRef.name; } else { //This is a node nodeGO = new GameObject(CathodeLib.NodeDB.GetFriendlyName(levelData.CommandsPAK.AllFlowgraphs[i].nodes[x].nodeID)); nodeType = CathodeLib.NodeDB.GetNodeTypeName(levelData.CommandsPAK.AllFlowgraphs[i].nodes[x].nodeType, ref levelData.CommandsPAK); } nodeGO.transform.parent = flowgraphGO.transform; //TODO: this can all be optimised massively List <uint> resourceIDs = new List <uint>(); foreach (CathodeParameterReference paramRef in levelData.CommandsPAK.AllFlowgraphs[i].nodes[x].nodeParameterReferences) { CathodeParameter param = levelData.CommandsPAK.GetParameter(paramRef.offset); if (param == null) { continue; } switch (param.dataType) { case CathodeDataType.POSITION: CathodeTransform transform = (CathodeTransform)param; nodeGO.transform.localPosition = transform.position; nodeGO.transform.localRotation = Quaternion.Euler(transform.rotation); break; case CathodeDataType.SHORT_GUID: resourceIDs.Add(((CathodeResource)param).resourceID); break; } } switch (nodeType) { case "PlayerTriggerBox": //nodeGO.AddComponent<BoxCollider>().bounds = new Bounds(new Vector3(0, 0, 0), new Vector3(0, 0, 0)); break; case "PositionMarker": //debug render marker break; case "Sound": //nodeGO.AddComponent<AudioSource>().clip = null; break; case "PlayEnvironmentAnimation": break; case "ParticleEmitterReference": break; case "ModelReference": for (int y = 0; y < resourceIDs.Count; y++) { List <CathodeResourceReference> resourceReference = levelData.CommandsPAK.AllFlowgraphs[i].GetResourceReferencesByID(resourceIDs[y]); for (int z = 0; z < resourceReference.Count; z++) { if (resourceReference[z].entryType != CathodeResourceReferenceType.RENDERABLE_INSTANCE) { continue; //Ignoring collision maps, etc, for now } //TODO: This is kinda hacked for now while we're not saving with submeshes for (int p = 0; p < resourceReference[z].entryCountREDS; p++) { int thisIndex = levelData.RenderableREDS.Entries[resourceReference[z].entryIndexREDS].ModelIndex + p; string meshResourcePath = GetMeshAssetPath(thisIndex, true) + "_" + p; GameObject newSubmesh = new GameObject(meshResourcePath); newSubmesh.transform.parent = nodeGO.transform; newSubmesh.transform.localScale = new Vector3(1, 1, 1) * levelData.ModelsBIN.Models[thisIndex].ScaleFactor; newSubmesh.transform.localPosition = Vector3.zero; newSubmesh.transform.localRotation = Quaternion.identity; newSubmesh.AddComponent <MeshFilter>().sharedMesh = Resources.Load <Mesh>(GetMeshAssetPath(thisIndex, true) + "_" + p); newSubmesh.AddComponent <MeshRenderer>().sharedMaterial = Resources.Load <Material>("DUMMY"); //TODO: replace } } } break; } } PrefabUtility.SaveAsPrefabAsset(flowgraphGO, GetFlowgraphAssetPath(levelData.CommandsPAK.AllFlowgraphs[i])); Destroy(flowgraphGO); } AssetDatabase.StopAssetEditing(); Destroy(rootGO); }
private void createEntity(object sender, EventArgs e) { cGUID thisID = Utilities.GenerateGUID(DateTime.Now.ToString("G")); if (createDatatypeEntity.Checked) { //Make the DatatypeEntity DatatypeEntity newEntity = new DatatypeEntity(thisID); newEntity.type = (CathodeDataType)entityVariant.SelectedIndex; newEntity.parameter = Utilities.GenerateGUID(textBox1.Text); //Make the parameter to give this DatatypeEntity a value (the only time you WOULDN'T want this is if the val is coming from a linked entity) CathodeParameter thisParam = null; switch (newEntity.type) { case CathodeDataType.POSITION: thisParam = new CathodeTransform(); break; case CathodeDataType.FLOAT: thisParam = new CathodeFloat(); break; case CathodeDataType.FILEPATH: case CathodeDataType.STRING: thisParam = new CathodeString(); break; case CathodeDataType.SPLINE_DATA: thisParam = new CathodeSpline(); break; case CathodeDataType.ENUM: thisParam = new CathodeEnum(); ((CathodeEnum)thisParam).enumID = new cGUID("4C-B9-82-48"); //ALERTNESS_STATE is the first alphabetically break; case CathodeDataType.SHORT_GUID: thisParam = new CathodeResource(); ((CathodeResource)thisParam).resourceID = new cGUID("00-00-00-00"); break; case CathodeDataType.BOOL: thisParam = new CathodeBool(); break; case CathodeDataType.DIRECTION: thisParam = new CathodeVector3(); break; case CathodeDataType.INTEGER: thisParam = new CathodeInteger(); break; } newEntity.parameters.Add(new CathodeLoadedParameter(newEntity.parameter, thisParam)); //Add to flowgraph & save name flow.datatypes.Add(newEntity); if (NodeDB.GetCathodeName(newEntity.parameter) == newEntity.parameter.ToString()) { NodeDBEx.AddNewParameterName(newEntity.parameter, textBox1.Text); } NewEntity = newEntity; } else if (createFunctionEntity.Checked) { //Create FunctionEntity FunctionEntity newEntity = new FunctionEntity(thisID); switch (entityVariant.Text) { //TODO: find a nicer way of auto selecting this (E.G. can we reflect to class names?) case "CAGEAnimation": newEntity = new CAGEAnimation(thisID); break; case "TriggerSequence": newEntity = new TriggerSequence(thisID); break; } newEntity.function = CathodeEntityDatabase.GetEntityAtIndex(entityVariant.SelectedIndex).guid; //TODO: auto populate params here //Add to flowgraph & save name flow.functions.Add(newEntity); NodeDBEx.AddNewNodeName(thisID, textBox1.Text); NewEntity = newEntity; } else if (createFlowgraphEntity.Checked) { //Create FunctionEntity FunctionEntity newEntity = new FunctionEntity(thisID); CathodeFlowgraph selectedFlowgraph = availableFlows.FirstOrDefault(o => o.name == entityVariant.Text); if (selectedFlowgraph == null) { MessageBox.Show("Failed to look up flowgraph!\nPlease report this issue on GitHub.\n\n" + entityVariant.Text, "Could not find flowgraph!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } newEntity.function = selectedFlowgraph.nodeID; //Add to flowgraph & save name flow.functions.Add(newEntity); NodeDBEx.AddNewNodeName(thisID, textBox1.Text); NewEntity = newEntity; } this.Close(); }
private void button1_Click(object sender, EventArgs e) { if (param_name.Text == "") { return; } cGUID thisParamID = Utilities.GenerateGUID(param_name.Text); foreach (CathodeLoadedParameter param in node.parameters) { if (param.paramID == thisParamID) { MessageBox.Show("This parameter already exists on the entity!"); return; } } CathodeParameter thisParam = null; switch ((CathodeDataType)param_datatype.SelectedIndex) { case CathodeDataType.POSITION: thisParam = new CathodeTransform(); break; case CathodeDataType.FLOAT: thisParam = new CathodeFloat(); break; case CathodeDataType.FILEPATH: case CathodeDataType.STRING: thisParam = new CathodeString(); break; case CathodeDataType.SPLINE_DATA: thisParam = new CathodeSpline(); break; case CathodeDataType.ENUM: thisParam = new CathodeEnum(); ((CathodeEnum)thisParam).enumID = new cGUID("4C-B9-82-48"); //ALERTNESS_STATE is the first alphabetically break; case CathodeDataType.SHORT_GUID: thisParam = new CathodeResource(); ((CathodeResource)thisParam).resourceID = new cGUID("00-00-00-00"); break; case CathodeDataType.BOOL: thisParam = new CathodeBool(); break; case CathodeDataType.DIRECTION: thisParam = new CathodeVector3(); break; case CathodeDataType.INTEGER: thisParam = new CathodeInteger(); break; } node.parameters.Add(new CathodeLoadedParameter(thisParamID, thisParam)); //If this parameter doesn't come up in the CATHODE string table, add it to our own if (NodeDB.GetCathodeName(thisParamID) == thisParamID.ToString()) { NodeDBEx.AddNewParameterName(thisParamID, param_name.Text); } this.Close(); }