Beispiel #1
0
    private void OnDisable()
    {
        SurfaceSet surfaceSet   = (SurfaceSet)target;
        int        subMeshCount = surfaceSet.GetSubMeshCount();

        surfaceSet.subMeshIndexPreview = subMeshCount + 1;
    }
Beispiel #2
0
    private void OnSceneGUI()
    {
        SurfaceSet surfaceSet   = (SurfaceSet)target;
        int        subMeshCount = surfaceSet.GetSubMeshCount();

        if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.clickCount == 2 && !Event.current.alt)
        {
            Ray        ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            RaycastHit raycastHit;
            bool       hit = Physics.Raycast(ray, out raycastHit);
            if (hit)
            {
                _clickPosition = raycastHit.point;
                Mesh mesh = MeshHelper.GetObjectMesh(surfaceSet.gameObject);

                int[] meshSubMeshTriangleRanges = MeshHelper.GetMeshSubMeshTriangleRanges(mesh);
                int   selectionIndex            = MeshHelper.GetSubMeshIndexByTriangle(raycastHit.triangleIndex, subMeshCount, meshSubMeshTriangleRanges);
                if (surfaceSet.subMeshIndexPreview == selectionIndex)
                {
                    surfaceSet.subMeshIndexPreview = subMeshCount + 1;
                }
                else
                {
                    surfaceSet.subMeshIndexPreview = selectionIndex;
                }
            }
        }

        if (surfaceSet.subMeshIndexPreview < surfaceSet.surfaceTypes.Length)
        {
            GUIStyle gUIStlye = new GUIStyle();
            gUIStlye.normal.textColor = Color.white;
            Handles.Label(_clickPosition, "Type: " + surfaceSet.surfaceTypes[surfaceSet.subMeshIndexPreview].ToString() + " (Index : " + surfaceSet.subMeshIndexPreview.ToString() + ")", gUIStlye);

            Handles.BeginGUI();
            Vector2 enumPosition = HandleUtility.WorldToGUIPoint(_clickPosition);

            surfaceSet.surfaceTypes[surfaceSet.subMeshIndexPreview] = (SurfaceType)EditorGUI.EnumPopup(new Rect(enumPosition.x, enumPosition.y + 20, 100, 50), surfaceSet.surfaceTypes[surfaceSet.subMeshIndexPreview]);
            Handles.EndGUI();
        }
        surfaceSet.SetSurfaceTypeCount(subMeshCount);
    }
 // Given an xml node and a surface set, parse the xml node and
 // update approprate fields of the surface set.
 public void RefreshSurfaceSet(XmlNode surfSetXML, SurfaceSet surfSet)
 {
     // first get the properties of the surface set
     foreach (XmlNode node in surfSetXML.ChildNodes)
     {
         if (node.Name == "Name")
         {
             string name = node.InnerText;
             // keeping this around for validation; not doing anything with it at the moment.
         }
         if (node.Name == "SurfaceNames")
         {
             string[] names   = new string[8];
             int      curName = 0;
             // now we're going to accumulate the names
             // of all the surfaces applied to the slots in this
             // model - note that order is paramount - different slots
             // correspond to different body parts of the bot
             foreach (XmlNode surfNameNode in node.ChildNodes)
             {
                 System.Diagnostics.Debug.Assert(surfNameNode.Name == "string",
                                                 "Expected string parsing SurfaceNames in XmlActor");
                 names[curName++] = surfNameNode.InnerText;
             }
             surfSet.SurfaceNames = names;
         }
         else if (node.Name == "BumpDetailName")
         {
             surfSet.BumpDetailName = node.InnerText;
         }
         else if (node.Name == "DirtMapName")
         {
             surfSet.DirtMapName = node.InnerText;
         }
     }
 }
        public void RefreshFromXML()
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(System.IO.Directory.GetCurrentDirectory() + XmlFileName);

            // note on persistence: the surface sets are in subnodes of the root xml document
            // each surface set record will hold pointers to these subnodes
            // when we save, we copy date back to the subnodes and then write the whole doc
            // back to the file.
            foreach (XmlNode node in xmlDoc.ChildNodes)
            {
                // look for the actor - should be one per file
                if (node.Name == "XmlGameActor")
                {
                    foreach (XmlNode actorNode in node.ChildNodes)
                    {
                        // we currently rely on the surface sets being in the same order, as there is no
                        // way for the user to reorder them and they should always be in load order
                        if (actorNode.Name == "SurfaceSets")
                        {
                            int curSurfSet = 0;
                            foreach (XmlNode surfSetNode in actorNode.ChildNodes)
                            {
                                if (surfSetNode.Name == "SurfaceSet")
                                {
                                    SurfaceSet curSet = this.SurfaceSets[curSurfSet];
                                    RefreshSurfaceSet(surfSetNode, curSet);
                                    curSurfSet++;
                                }
                            }
                        }
                    }
                }
            }
        }