コード例 #1
0
 public void TranslucentMaterials()
 {
     foreach (GameObject part in parts)
     {
         MaterialHandler m = part.GetComponent <MaterialHandler>();
         m.TranslucentMaterials(this);
     }
 }
コード例 #2
0
        public static ItemInstance MakeNaturalWeapon(int wielderSize)
        {
            ItemMaterial itemMaterial = MaterialHandler.GetMaterial("Flesh");
            BaseItemType baseItem     = new BaseItemType("Weapon", "A claw, fist or psuedopod.", "A claw, fist or psuedopod.", "Natural Weapon", "Natural Weapon", "Hand1",
                                                         wielderSize * 40.0f, itemMaterial, "Weapon", "Martial Arts", "strikes", null, 0, 0);

            return(new ItemInstance(baseItem, new Vector2Int(-1, -1), true));
        }
コード例 #3
0
 private void Awake()
 {
     rb              = GetComponent <Rigidbody>();
     timeController  = GetComponent <TimeController>();
     materialHandler = GetComponent <MaterialHandler>();
     trailRenderer   = GetComponent <TrailRenderer>();
     player          = GameObject.FindWithTag("Player");
     ExplosionLayer  = LayerMask.NameToLayer("ExplosionLayer");
 }
コード例 #4
0
 private void Awake()
 {
     if (instance != null && instance != this)
     {
         Destroy(gameObject);
         return;
     }
     instance = this;
 }
コード例 #5
0
 public void UpdateMaterials()
 {
     foreach (GameObject part in parts)
     {
         MaterialHandler m = part.GetComponent <MaterialHandler>();
         m.UpdateMaterials(this);
     }
     hairObject.GetComponent <MeshFilter>().mesh = hairstyle;
     hatObject.transform.localPosition           = hatLocalOffset;
 }
コード例 #6
0
ファイル: GameManager.cs プロジェクト: Nosrick/JoyUnity
 private void InitialiseEverything()
 {
     RNG.SetSeed(DateTime.Now.Millisecond);
     ScriptingEngine.Initialise();
     ObjectIcons.Load();
     NeedHandler.Initialise();
     AbilityHandler.Initialise();
     JobHandler.Initialise();
     CultureHandler.Initialise();
     MaterialHandler.Initialise();
     ItemHandler.LoadItems();
     NameProvider.Initialise();
     EntityTemplateHandler.Initialise();
 }
コード例 #7
0
    private static GameObject AddMeshToNewGameObject(Mesh[] meshes, bool addMeshCollider = false, string name = null)
    {
        //Set up our gameobject and add a renderer and filter
        GameObject obj = new GameObject();

        obj.AddComponent <MeshRenderer>();
        obj.AddComponent <MeshFilter>();

        Renderer objRenderer = obj.GetComponent <Renderer>();

        Material[]      mats       = new Material[meshes.Length];
        MaterialHandler mtlHandler = MaterialHandler.GetInstance();

        for (int i = 0; i < meshes.Length; i++)
        {
            Material mat = mtlHandler.GetMaterialForMesh(meshes[i].name);

            if (mat == null)
            {
                Debug.LogFormat("Could not find material for mesh {0}", meshes[i].name);
                mats[i] = mtlHandler.GetMaterialForMesh("default");
            }
            else
            {
                mats[i] = mat;
            }
        }
        objRenderer.materials = mats;

        Mesh main = new Mesh();

        main.subMeshCount = meshes.Length;

        if (meshes.Length == 0)
        {
            obj.GetComponent <MeshFilter>().mesh = main;
        }
        else
        {
            CombineInstance[] combine = new CombineInstance[meshes.Length];

            for (int i = 0; i < meshes.Length; i++)
            {
                combine[i].mesh      = meshes[i];
                combine[i].transform = Matrix4x4.identity;
            }
            main.CombineMeshes(combine);

            for (int i = 0; i < main.subMeshCount; i++)
            {
                int[] tri = meshes[i].triangles;

                int offset = 0;
                if (i > 0)
                {
                    for (int j = 0; j < i; j++)
                    {
                        offset += meshes[j].vertexCount;
                    }
                }

                main.SetTriangles(tri, i, false, offset);

                //Don't ask?
                if (main.subMeshCount != meshes.Length)
                {
                    main.subMeshCount = meshes.Length;
                }
            }

            obj.GetComponent <MeshFilter>().mesh = main;
        }
        if (addMeshCollider)
        {
            obj.AddComponent <MeshCollider>();
        }

        string newName = "";

        //Redo this
        if (name != null)
        {
            newName = name;
        }
        else
        {
            newName = meshes.Length > 0 ? meshes[0].name.Substring(0, meshes[0].name.Length - 2) : "Unknown";
        }

        obj.name = newName;
        obj.SetActive(false);
        return(obj);
    }
コード例 #8
0
    private static void AddMeshToGameObject(Mesh[] meshes, GameObject obj)
    {
        Renderer objRenderer = obj.GetComponent <Renderer>();

        Material[]      mats       = new Material[meshes.Length];
        MaterialHandler mtlHandler = MaterialHandler.GetInstance();

        for (int i = 0; i < meshes.Length; i++)
        {
            Material mat = mtlHandler.GetMaterialForMesh(meshes[i].name);

            if (mat == null)
            {
                Debug.LogFormat("Could not find material for mesh {0}", meshes[i].name);
                mats[i] = mtlHandler.GetMaterialForMesh("default");
            }
            else
            {
                mats[i] = mat;
            }
        }
        objRenderer.materials = mats;

        Mesh main = new Mesh();

        main.subMeshCount = meshes.Length;

        if (meshes.Length == 0)
        {
            obj.GetComponent <MeshFilter>().mesh = main;
        }
        else
        {
            CombineInstance[] combine = new CombineInstance[meshes.Length];

            for (int i = 0; i < meshes.Length; i++)
            {
                combine[i].mesh      = meshes[i];
                combine[i].transform = Matrix4x4.identity;
            }
            main.CombineMeshes(combine);

            for (int i = 0; i < main.subMeshCount; i++)
            {
                int[] tri = new int[0];

                tri = meshes[i].triangles;

                int offset = 0;
                if (i > 0)
                {
                    for (int j = 0; j < i; j++)
                    {
                        offset += meshes[j].vertexCount;
                    }
                }

                main.SetTriangles(tri, i, false, offset);

                //Don't ask?
                if (main.subMeshCount != meshes.Length)
                {
                    main.subMeshCount = meshes.Length;
                }
            }

            obj.GetComponent <MeshFilter>().mesh = main;
        }
    }
コード例 #9
0
ファイル: DrinkLoader.cs プロジェクト: Nosrick/JoyUnity
        public static List <BaseItemType> LoadDrink()
        {
            List <BaseItemType> drinks = new List <BaseItemType>();

            string    filePath = Directory.GetCurrentDirectory() + "//Data//Items//Drinks//Drink.xml";
            XmlReader reader   = XmlReader.Create(filePath);

            List <IdentifiedItem> identifiedItems = new List <IdentifiedItem>();
            string actionWord     = "strikes";
            string governingSkill = "None";
            string category       = "None";

            while (reader.Read())
            {
                if (reader.Depth == 0 && reader.NodeType == XmlNodeType.Element && !reader.Name.Equals("Items"))
                {
                    break;
                }

                if (reader.Name.Equals("Category") && reader.NodeType == XmlNodeType.Element)
                {
                    category = reader.ReadElementContentAsString();
                }

                if (reader.Name.Equals("IdentifiedItem") && reader.NodeType == XmlNodeType.Element)
                {
                    IdentifiedItem item = new IdentifiedItem();
                    while (reader.NodeType != XmlNodeType.EndElement)
                    {
                        reader.Read();
                        if (reader.Name.Equals("Name"))
                        {
                            item.name = reader.ReadElementContentAsString();
                        }
                        else if (reader.Name.Equals("Description"))
                        {
                            item.description = reader.ReadElementContentAsString();
                        }
                        else if (reader.Name.Equals("Value"))
                        {
                            item.value = reader.ReadElementContentAsInt();
                        }
                        else if (reader.Name.Equals("Effect"))
                        {
                            item.interactionFile = reader.ReadElementContentAsString();
                        }
                        else if (reader.Name.Equals("SpawnWeight"))
                        {
                            item.weighting = reader.ReadElementContentAsInt();
                        }
                        else if (reader.Name.Equals("Materials"))
                        {
                            string materials = reader.ReadElementContentAsString();
                            item.materials = materials.Split(',');
                        }
                        else if (reader.Name.Equals("Size"))
                        {
                            item.size = reader.ReadElementContentAsFloat();
                        }
                    }
                    item.category = category;
                    identifiedItems.Add(item);
                }
                else if (reader.Name.Equals("ActionWord"))
                {
                    actionWord = reader.ReadElementContentAsString();
                }
            }

            reader.Close();

            for (int i = 0; i < identifiedItems.Count; i++)
            {
                drinks.Add(new BaseItemType(identifiedItems[i].category, identifiedItems[i].description, identifiedItems[i].description, identifiedItems[i].name,
                                            identifiedItems[i].name, "None", identifiedItems[i].size, MaterialHandler.GetMaterial(identifiedItems[i].materials[RNG.Roll(0, identifiedItems[i].materials.Length - 1)]),
                                            "Drinks", governingSkill, actionWord, identifiedItems[i].interactionFile, identifiedItems[i].value, identifiedItems[i].weighting));
            }

            return(drinks);
        }
コード例 #10
0
 private void Start()
 {
     _materialHandler = gameObject.GetComponent <MaterialHandler>();
 }
コード例 #11
0
        public static List <BaseItemType> LoadPotions()
        {
            List <BaseItemType> potions = new List <BaseItemType>();

            string    filePath = Directory.GetCurrentDirectory() + "//Data//Items//Potions//Potions.xml";
            XmlReader reader   = XmlReader.Create(filePath);

            List <IdentifiedItem>   identifiedItems   = new List <IdentifiedItem>();
            List <UnidentifiedItem> unidentifiedItems = new List <UnidentifiedItem>();
            string actionWord     = "strikes";
            string governingSkill = "None";
            string category       = "None";

            while (reader.Read())
            {
                if (reader.Depth == 0 && reader.NodeType == XmlNodeType.Element && !reader.Name.Equals("Items"))
                {
                    break;
                }

                if (reader.Name.Equals("Category") && reader.NodeType == XmlNodeType.Element)
                {
                    category = reader.ReadElementContentAsString();
                }

                if (reader.Name.Equals("IdentifiedItem") && reader.NodeType == XmlNodeType.Element)
                {
                    IdentifiedItem item = new IdentifiedItem();
                    while (reader.NodeType != XmlNodeType.EndElement)
                    {
                        reader.Read();
                        if (reader.Name.Equals("Name"))
                        {
                            item.name = reader.ReadElementContentAsString();
                        }
                        else if (reader.Name.Equals("Description"))
                        {
                            item.description = reader.ReadElementContentAsString();
                        }
                        else if (reader.Name.Equals("Value"))
                        {
                            item.value = reader.ReadElementContentAsInt();
                        }
                        else if (reader.Name.Equals("Effect"))
                        {
                            item.interactionFile = Directory.GetCurrentDirectory() + "//Data//Scripts//Items//Potions//" + reader.ReadElementContentAsString();
                        }
                        else if (reader.Name.Equals("SpawnWeight"))
                        {
                            item.weighting = reader.ReadElementContentAsInt();
                        }
                    }
                    item.category = category;
                    identifiedItems.Add(item);
                }
                else if (reader.Name.Equals("UnidentifiedItem") && reader.NodeType == XmlNodeType.Element)
                {
                    UnidentifiedItem item = new UnidentifiedItem();
                    while (reader.NodeType != XmlNodeType.EndElement)
                    {
                        reader.Read();
                        if (reader.Name.Equals("Name"))
                        {
                            item.name = reader.ReadElementContentAsString();
                        }
                        else if (reader.Name.Equals("Description"))
                        {
                            item.description = reader.ReadElementContentAsString();
                        }
                    }
                    unidentifiedItems.Add(item);
                }
                else if (reader.Name.Equals("ActionWord"))
                {
                    actionWord = reader.ReadElementContentAsString();
                }
            }

            reader.Close();

            ItemMaterial glass = MaterialHandler.GetMaterial("Glass");

            for (int i = 0; i < identifiedItems.Count; i++)
            {
                int index = RNG.Roll(0, unidentifiedItems.Count - 1);
                UnidentifiedItem chosenDescription = unidentifiedItems[index];
                unidentifiedItems.RemoveAt(index);

                potions.Add(new BaseItemType(identifiedItems[i].category, identifiedItems[i].description, chosenDescription.description, chosenDescription.name,
                                             identifiedItems[i].name, "None", 5.0f, glass, "Potions", governingSkill, actionWord,
                                             identifiedItems[i].interactionFile, identifiedItems[i].value, identifiedItems[i].weighting));
            }

            return(potions);
        }
コード例 #12
0
ファイル: ItemLoader.cs プロジェクト: Nosrick/JoyUnity
        public static List <BaseItemType> LoadItems()
        {
            List <BaseItemType> weapons = new List <BaseItemType>();

            string folderPath = Directory.GetCurrentDirectory() + GlobalConstants.DATA_FOLDER + "Items";

            string[] files = Directory.GetFiles(folderPath, "*.xml", SearchOption.AllDirectories);


            for (int i = 0; i < files.Length; i++)
            {
                XmlReader reader = XmlReader.Create(files[i]);

                List <IdentifiedItem>   identifiedItems   = new List <IdentifiedItem>();
                List <UnidentifiedItem> unidentifiedItems = new List <UnidentifiedItem>();

                string actionWord = "strikes";
                string category   = "Misc";
                int    lightLevel = 0;

                while (reader.Read())
                {
                    if (reader.Depth == 0 && reader.NodeType == XmlNodeType.Element && !reader.Name.Equals("Items"))
                    {
                        break;
                    }

                    if (reader.Name.Equals("Category") && reader.NodeType == XmlNodeType.Element)
                    {
                        category = reader.ReadElementContentAsString();
                    }

                    if (reader.Name.Equals("IdentifiedItem") && reader.NodeType == XmlNodeType.Element)
                    {
                        IdentifiedItem item = new IdentifiedItem();
                        item.slot  = "None";
                        item.skill = "None";
                        while (reader.NodeType != XmlNodeType.EndElement)
                        {
                            reader.Read();
                            if (reader.Name.Equals("Name"))
                            {
                                item.name = reader.ReadElementContentAsString();
                            }
                            else if (reader.Name.Equals("Description"))
                            {
                                item.description = reader.ReadElementContentAsString();
                            }
                            else if (reader.Name.Equals("Value"))
                            {
                                item.value = reader.ReadElementContentAsInt();
                            }
                            else if (reader.Name.Equals("Effect"))
                            {
                                item.interactionFile = reader.ReadElementContentAsString();
                            }
                            else if (reader.Name.Equals("SpawnWeight"))
                            {
                                item.weighting = reader.ReadElementContentAsInt();
                            }
                            else if (reader.Name.Equals("Materials"))
                            {
                                string materials = reader.ReadElementContentAsString();
                                item.materials = materials.Split(',');
                            }
                            else if (reader.Name.Equals("Size"))
                            {
                                item.size = reader.ReadElementContentAsFloat();
                            }
                            else if (reader.Name.Equals("Slot"))
                            {
                                item.slot = reader.ReadElementContentAsString();
                            }
                            else if (reader.Name.Equals("Skill"))
                            {
                                item.skill = reader.ReadElementContentAsString();
                            }
                            else if (reader.Name.Equals("LightLevel"))
                            {
                                lightLevel = reader.ReadElementContentAsInt();
                            }
                        }
                        item.category = category;
                        identifiedItems.Add(item);
                    }
                    else if (reader.Name.Equals("UnidentifiedItem"))
                    {
                        UnidentifiedItem item = new UnidentifiedItem();
                        while (reader.NodeType != XmlNodeType.EndElement)
                        {
                            reader.Read();
                            if (reader.Name.Equals("Name"))
                            {
                                item.name = reader.ReadElementContentAsString();
                            }
                            else if (reader.Name.Equals("Description"))
                            {
                                item.description = reader.ReadElementContentAsString();
                            }
                        }
                        unidentifiedItems.Add(item);
                    }
                    else if (reader.Name.Equals("ActionWord"))
                    {
                        actionWord = reader.ReadElementContentAsString();
                    }
                }

                reader.Close();

                for (int j = 0; j < identifiedItems.Count; j++)
                {
                    UnidentifiedItem chosenDescription = new UnidentifiedItem(identifiedItems[j].name, identifiedItems[j].description);

                    if (unidentifiedItems.Count != 0)
                    {
                        int index = RNG.Roll(0, unidentifiedItems.Count - 1);
                        chosenDescription = unidentifiedItems[index];
                        unidentifiedItems.RemoveAt(index);
                    }

                    for (int k = 0; k < identifiedItems[j].materials.Length; k++)
                    {
                        weapons.Add(new BaseItemType(identifiedItems[j].category, identifiedItems[j].description, chosenDescription.description, chosenDescription.name,
                                                     identifiedItems[j].name, identifiedItems[j].slot, identifiedItems[j].size,
                                                     MaterialHandler.GetMaterial(identifiedItems[j].materials[k]),
                                                     identifiedItems[j].category, identifiedItems[j].skill, actionWord, identifiedItems[j].interactionFile,
                                                     identifiedItems[j].value, identifiedItems[j].weighting, lightLevel));
                    }
                }
            }

            return(weapons);
        }
コード例 #13
0
 public string OnAddedMaterial(MaterialHandler handler)
 {
     return(handler.Invoke($"Student {FirstName} added material"));
 }
コード例 #14
0
    private void LoadMeshData(string fileName)
    {
        StringBuilder sb            = new StringBuilder();
        string        text          = File.ReadAllText(fileName);
        int           start         = 0;
        string        objectName    = null;
        bool          hasColor      = false;
        int           faceDataCount = 0;

        StringBuilder sbFloat = new StringBuilder();
        StringBuilder mtlFile = new StringBuilder();
        StringBuilder mtlName = new StringBuilder();

        for (int i = 0; i < text.Length; i++)
        {
            if (text[i] == '\n')// || text[i] == '#')
            {
                sb.Remove(0, sb.Length);

                // Start +1 for whitespace '\n'
                sb.Append(text, start + 1, i - start);
                start = i;

                if (sb[0] == 'o' && sb[1] == ' ')
                {
                    sbFloat.Remove(0, sbFloat.Length);
                    int j = 2;
                    while (j < sb.Length)
                    {
                        objectName += sb[j];
                        j++;
                    }
                }
                else if (sb[0] == 'm' && sb[1] == 't' && sb[2] == 'l' && sb[3] == 'l' && sb[4] == 'i' && sb[5] == 'b')
                {
                    int splitStart = 6;

                    sbFloat.Remove(0, sbFloat.Length);

                    while (splitStart < sb.Length)
                    {
                        mtlFile.Append(sb[splitStart]);
                        splitStart++;
                    }
                }
                else if (sb[0] == 'u' && sb[1] == 's' && sb[2] == 'e' && sb[3] == 'm' && sb[4] == 't' && sb[5] == 'l')
                {
                    int splitStart = 6;

                    sbFloat.Remove(0, sbFloat.Length);

                    while (splitStart < sb.Length)
                    {
                        mtlName.Append(sb[splitStart]);
                        splitStart++;
                    }
                }
                else if (sb[0] == 'v' && sb[1] == ' ') // Vertices
                {
                    int splitStart = 2;

                    vertices.Add(new Vector3(GetFloat(sb, ref splitStart, ref sbFloat),
                                             GetFloat(sb, ref splitStart, ref sbFloat),
                                             GetFloat(sb, ref splitStart, ref sbFloat)));
                }
                else if (sb[0] == 'v' && sb[1] == 't' && sb[2] == ' ') // UV
                {
                    int splitStart = 3;

                    uv.Add(new Vector4(GetFloat(sb, ref splitStart, ref sbFloat),
                                       GetFloat(sb, ref splitStart, ref sbFloat),
                                       GetFloat(sb, ref splitStart, ref sbFloat),
                                       GetFloat(sb, ref splitStart, ref sbFloat)));
                }
                else if (sb[0] == 'v' && sb[1] == 'n' && sb[2] == ' ') // Normals
                {
                    int splitStart = 3;

                    normals.Add(new Vector3(GetFloat(sb, ref splitStart, ref sbFloat),
                                            GetFloat(sb, ref splitStart, ref sbFloat),
                                            GetFloat(sb, ref splitStart, ref sbFloat)));
                }
                else if (sb[0] == 'v' && sb[1] == 'c' && sb[2] == ' ') // Vertex colors
                {
                    int splitStart = 3;

                    //Colors are written a, r, g, b
                    byte a = Scale(GetFloat(sb, ref splitStart, ref sbFloat));
                    byte r = Scale(GetFloat(sb, ref splitStart, ref sbFloat));
                    byte g = Scale(GetFloat(sb, ref splitStart, ref sbFloat));
                    byte b = Scale(GetFloat(sb, ref splitStart, ref sbFloat));

                    if (!hasColor && r + g + b + a > 0)
                    {
                        hasColor = true;
                    }

                    colors.Add(new Color32(r, g, b, a));
                }
                else if (sb[0] == 'f' && sb[1] == ' ')
                {
                    int splitStart = 2;

                    int j = 1;
                    intArray.Clear();
                    int info = 0;
                    // Add faceData, a face can contain multiple triangles, facedata is stored in following order vert, uv, normal. If uv or normal are / set it to a 0
                    while (splitStart < sb.Length && char.IsDigit(sb[splitStart]))
                    {
                        faceData.Add(new Vector3Int(GetInt(sb, ref splitStart, ref sbFloat),
                                                    GetInt(sb, ref splitStart, ref sbFloat),
                                                    GetInt(sb, ref splitStart, ref sbFloat)));
                        j++;

                        intArray.Add(faceDataCount);
                        faceDataCount++;
                    }

                    info += j;
                    j     = 1;
                    while (j + 2 < info) //Create triangles out of the face data.  There will generally be more than 1 triangle per face.
                    {
                        triangles.Add(intArray[0]);
                        triangles.Add(intArray[j]);
                        triangles.Add(intArray[j + 1]);

                        j++;
                    }
                }
            }
        }

        MaterialHandler mtlHandler = MaterialHandler.GetInstance();

        mtlHandler.LoadMaterial(Path.Combine(fileName.Substring(0, fileName.LastIndexOf(@"\")), mtlFile.ToString().Trim()));
        mtlHandler.RegisterMaterialForMesh(meshName, mtlName.ToString().Trim());

        if (hasColor)
        {
            mtlHandler.SetMaterialShader(mtlName.ToString(), "texblend");
        }
    }
コード例 #15
0
        /// <summary>
        /// Processes a single file
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        IEnumerator Run(string fileName)
        {
            var counter = 0;
            var sw      = new Stopwatch();

            sw.Start();

            var lastFrame = sw.ElapsedMilliseconds;

            using (XmlReader reader = XmlReader.Create(fileName, new XmlReaderSettings {
                IgnoreWhitespace = true
            }))
            {
                yield return(null);

                while (!reader.EOF)
                {
                    reader.Read();
                    if (reader.LocalName == "CityModel")
                    {
                        break;
                    }
                }

                var version = 0;
                for (int i = 0; i < reader.AttributeCount; i++)
                {
                    var attr = reader.GetAttribute(i);
                    if (attr == "http://www.opengis.net/citygml/1.0")
                    {
                        version = 1;
                        break;
                    }
                    if (attr == "http://www.opengis.net/citygml/2.0")
                    {
                        version = 2;
                        break;
                    }
                }

                if (version == 0)
                {
                    Debug.LogWarning("Possibly invalid xml. Check for xml:ns citygml version.");
                }

                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "cityObjectMember")
                    {
                        while (reader.Read())
                        {
                            if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "Building")
                            {
                                counter++;

                                if (UpdateRate > 0 && sw.ElapsedMilliseconds > lastFrame + UpdateRate)
                                {
                                    lastFrame = sw.ElapsedMilliseconds;
                                    yield return(null);
                                }
                                BuildingHandler.HandleBuilding(reader, this);
                            }
                        }
                    }
                }
            }
            //CombineMeshes();
            MaterialHandler.ApplyMaterials(this);

            yield return(null);
        }