Пример #1
0
    private void DrawPropSelection()
    {
        if (Event.current.type == EventType.Repaint)
        {
            propTools.lastRect = GUILayoutUtility.GetLastRect();
        }

        Rect scrollRect  = new Rect(5, propTools.lastRect.yMax + 2, window.position.width - 5, 200);
        Rect scrollRect2 = new Rect(scrollRect.xMin, scrollRect.yMin, scrollRect.width - 30, scrollRect.yMin + (propTools.props.Count * (GUIStyle.none.lineHeight + 4)));

        // Begin the ScrollView
        propTools.propScrollPosition = GUI.BeginScrollView(scrollRect, propTools.propScrollPosition, scrollRect2, false, true);

        foreach (PropTools.Prop p in propTools.props)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(p.propName, GUILayout.Width(220));
            if (GUILayout.Button("Spawn", GUILayout.Width(50)))
            {
                PropObject newProp = PropObject.Create(propTools.transform, p);

                Selection.activeGameObject = newProp.gameObject;

                Debug.Log(p.propName + " created");
            }
            GUILayout.EndHorizontal();
        }

        // End the ScrollView
        GUI.EndScrollView();
    }
Пример #2
0
    public static PropObject Create(Transform parent, PropTools.Prop prop)
    {
        GameObject newPropGO = new GameObject();

        newPropGO.name             = prop.propName;
        newPropGO.transform.parent = parent;

        PropObject newProp = newPropGO.AddComponent <PropObject>();

        newProp.prop = prop;

        Bounds propBounds = CreateProxies(newPropGO, prop);

        BoxCollider collider = newPropGO.AddComponent <BoxCollider>();

        collider.hideFlags = HideFlags.HideInInspector | HideFlags.NotEditable;
        collider.center    = propBounds.center;
        collider.size      = propBounds.size;

        return(newProp);
    }
Пример #3
0
    public static PropObject LoadProp(string scd, string LocalPath)
    {
        if (LoadedPropObjects.ContainsKey(LocalPath))
        {
            return(LoadedPropObjects[LocalPath]);
        }


        PropObject ToReturn = new PropObject();

        byte[] Bytes = LoadBytes(scd, LocalPath);
        if (Bytes.Length == 0)
        {
            Debug.LogError("Prop does not exits: " + LocalPath);
            return(ToReturn);
        }
        string BluePrintString = System.Text.Encoding.UTF8.GetString(Bytes);

        if (BluePrintString.Length == 0)
        {
            Debug.LogError("Loaded blueprint is empty");
            return(ToReturn);
        }

        BluePrintString = BluePrintString.Replace("PropBlueprint {", "PropBlueprint = {");

        // *** Parse Blueprint
        ToReturn.BP = new PropBluePrint();
        // Create Lua
        Lua BP = new Lua();

        BP.LoadCLRPackage();

        string[] PathSplit = LocalPath.Split(("/").ToCharArray());
        ToReturn.BP.Name = PathSplit[PathSplit.Length - 1].Replace(".bp", "");


        //Fix LUA
        string[] SplitedBlueprint   = BluePrintString.Split("\n".ToCharArray());
        string   NewBlueprintString = "";

        for (int i = 0; i < SplitedBlueprint.Length; i++)
        {
            if (SplitedBlueprint[i].Length > 0 && !SplitedBlueprint[i].Contains("#"))
            {
                NewBlueprintString += SplitedBlueprint[i] + "\n";
            }
        }
        BluePrintString = NewBlueprintString;

        ToReturn.BP.Path = LocalPath;

        try
        {
            BP.DoString(MapLuaParser.Current.SaveLuaHeader.text + BluePrintString);
        }
        catch (NLua.Exceptions.LuaException e)
        {
            Debug.LogWarning(LuaParser.Read.FormatException(e) + "\n" + LocalPath);
            return(ToReturn);
        }

        if (ToReturn.BP.Categories == null)
        {
            ToReturn.BP.Categories = new HashSet <string>();
        }
        else
        {
            ToReturn.BP.Categories.Clear();
        }

        if (BP.GetTable("PropBlueprint.Categories") != null)
        {
            string[] Categories = LuaParser.Read.StringArrayFromTable(BP.GetTable("PropBlueprint.Categories"));
            for (int i = 0; i < Categories.Length; i++)
            {
                ToReturn.BP.Categories.Add(Categories[i]);
            }

            ToReturn.BP.RECLAIMABLE = ToReturn.BP.Categories.Contains("RECLAIMABLE");
        }

        // Economy
        LuaTable EconomyTab = BP.GetTable("PropBlueprint.Economy");

        if (EconomyTab != null)
        {
            if (EconomyTab.RawGet("ReclaimEnergyMax") != null)
            {
                ToReturn.BP.ReclaimEnergyMax = LuaParser.Read.StringToFloat(EconomyTab.RawGet("ReclaimEnergyMax").ToString());
            }

            if (EconomyTab.RawGet("ReclaimMassMax") != null)
            {
                ToReturn.BP.ReclaimMassMax = LuaParser.Read.StringToFloat(EconomyTab.RawGet("ReclaimMassMax").ToString());
            }

            if (EconomyTab.RawGet("ReclaimTime") != null)
            {
                ToReturn.BP.ReclaimTime = LuaParser.Read.StringToFloat(EconomyTab.RawGet("ReclaimTime").ToString());
            }
        }

        //Size
        object SizeX = BP.GetTable("PropBlueprint").RawGet("SizeX");

        if (SizeX != null)
        {
            ToReturn.BP.SizeX = LuaParser.Read.StringToFloat(SizeX.ToString());
        }

        object SizeY = BP.GetTable("PropBlueprint").RawGet("SizeY");

        if (SizeY != null)
        {
            ToReturn.BP.SizeY = LuaParser.Read.StringToFloat(SizeY.ToString());
        }

        object SizeZ = BP.GetTable("PropBlueprint").RawGet("SizeZ");

        if (SizeZ != null)
        {
            ToReturn.BP.SizeY = LuaParser.Read.StringToFloat(SizeZ.ToString());
        }


        //Display
        if (BP.GetTable("PropBlueprint.Display") != null)
        {
            if (BP.GetTable("PropBlueprint.Display").RawGet("UniformScale") != null)
            {
                ToReturn.BP.UniformScale = LuaParser.Read.StringToFloat(BP.GetTable("PropBlueprint.Display").RawGet("UniformScale").ToString());
            }

            // Mesh
            if (BP.GetTable("PropBlueprint.Display.Mesh") != null)
            {
                if (BP.GetTable("PropBlueprint.Display.Mesh").RawGet("IconFadeInZoom") != null)
                {
                    ToReturn.BP.IconFadeInZoom = LuaParser.Read.StringToFloat(BP.GetTable("PropBlueprint.Display.Mesh").RawGet("IconFadeInZoom").ToString());
                }

                //Lods
                LuaTable LodTable = BP.GetTable("PropBlueprint.Display.Mesh.LODs");

                LuaTable[] LodTableValues = new LuaTable[LodTable.Keys.Count];
                ToReturn.BP.LODs = new BluePrintLoD[LodTableValues.Length];
                LodTable.Values.CopyTo(LodTableValues, 0);

                for (int i = 0; i < LodTableValues.Length; i++)
                {
                    ToReturn.BP.LODs[i] = new BluePrintLoD();

                    if (LodTableValues[i].RawGet("AlbedoName") != null)
                    {
                        ToReturn.BP.LODs[i].AlbedoName = LodTableValues[i].RawGet("AlbedoName").ToString();
                    }

                    if (LodTableValues[i].RawGet("NormalsName") != null)
                    {
                        ToReturn.BP.LODs[i].NormalsName = LodTableValues[i].RawGet("NormalsName").ToString();
                    }

                    if (LodTableValues[i].RawGet("ShaderName") != null)
                    {
                        ToReturn.BP.LODs[i].ShaderName = LodTableValues[i].RawGet("ShaderName").ToString();
                    }

                    if (LodTableValues[i].RawGet("LODCutoff") != null)
                    {
                        ToReturn.BP.LODs[i].LODCutoff = LuaParser.Read.StringToFloat(LodTableValues[i].RawGet("LODCutoff").ToString());
                    }

                    ToReturn.BP.LODs[i].Scm = LocalPath.Replace("prop.bp", "lod" + i.ToString() + ".scm");
                }
            }
        }

        for (int i = 0; i < ToReturn.BP.LODs.Length; i++)
        {
            ToReturn.BP.LODs[i].Mesh = LoadModel(scd, ToReturn.BP.LODs[i].Scm);

            //ToReturn.BP.LODs[i].Mat = new Material(Shader.Find("Standard (Specular setup)"));
            ToReturn.BP.LODs[i].Mat = new Material(EditMap.PropsInfo.Current.PropMaterial);

            ToReturn.BP.LODs[i].Mat.name = ToReturn.BP.Name + " mat";



            if (i > 0 && (string.IsNullOrEmpty(ToReturn.BP.LODs[i].AlbedoName) || ToReturn.BP.LODs[i].AlbedoName == ToReturn.BP.LODs[0].AlbedoName) &&
                (string.IsNullOrEmpty(ToReturn.BP.LODs[i].NormalsName) || ToReturn.BP.LODs[i].NormalsName == ToReturn.BP.LODs[0].NormalsName))
            {
                ToReturn.BP.LODs[i].Mat = ToReturn.BP.LODs[0].Mat;
                continue;
            }

            if (ToReturn.BP.LODs[i].AlbedoName.Length == 0)
            {
                ToReturn.BP.LODs[i].AlbedoName = LocalPath.Replace("prop.bp", "albedo.dds");
            }
            else
            {
                ToReturn.BP.LODs[i].AlbedoName = OffsetRelativePath(LocalPath, ToReturn.BP.LODs[i].AlbedoName, true);
            }

            ToReturn.BP.LODs[i].Albedo            = LoadTexture2DFromGamedata(scd, ToReturn.BP.LODs[i].AlbedoName, false);
            ToReturn.BP.LODs[i].Albedo.anisoLevel = 2;
            ToReturn.BP.LODs[i].Mat.SetTexture("_MainTex", ToReturn.BP.LODs[i].Albedo);


            if (ToReturn.BP.LODs[i].ShaderName == "VertexNormal")
            {
                ToReturn.BP.LODs[i].NormalsName = "";
            }
            else if (ToReturn.BP.LODs[i].NormalsName.Length == 0 && i == 0)
            {
                ToReturn.BP.LODs[i].NormalsName = LocalPath.Replace("prop.bp", "normalsTS.dds");
            }
            else
            {
                ToReturn.BP.LODs[i].NormalsName = OffsetRelativePath(LocalPath, ToReturn.BP.LODs[i].NormalsName, true);
            }

            if (ToReturn.BP.LODs[i].ShaderName == "NormalMappedTerrain")
            {
                ToReturn.BP.LODs[i].Mat.SetInt("_GlowAlpha", 1);
            }

            if (!string.IsNullOrEmpty(ToReturn.BP.LODs[i].NormalsName))
            {
                ToReturn.BP.LODs[i].Normal            = LoadTexture2DFromGamedata(scd, ToReturn.BP.LODs[i].NormalsName, true);
                ToReturn.BP.LODs[i].Normal.anisoLevel = 2;
                ToReturn.BP.LODs[i].Mat.SetTexture("_BumpMap", ToReturn.BP.LODs[i].Normal);
            }
        }
        if (ToReturn.BP.LODs.Length <= 0)
        {
            ToReturn.BP.LODs              = new BluePrintLoD[1];
            ToReturn.BP.LODs[0]           = new BluePrintLoD();
            ToReturn.BP.LODs[0].LODCutoff = 100;
        }

        if (ToReturn.BP.LODs[0].Mesh == null)
        {
            ToReturn.BP.LODs[0].Mesh = PropsInfo.Current.NoPropMesh;
            ToReturn.BP.UniformScale = 2f;
        }

        if (ToReturn.BP.LODs[0].Mat == null)
        {
            ToReturn.BP.LODs[0].Mat = PropsInfo.Current.NoPropMaterial;
        }

        if (ToReturn.BP.UniformScale <= 0.01f)
        {
            ToReturn.BP.UniformScale = 0.01f;
        }

        ToReturn.BP.LocalScale = Vector3.one * (ToReturn.BP.UniformScale * 0.1f);



        LoadedPropObjects.Add(LocalPath, ToReturn);

        return(ToReturn);
    }
Пример #4
0
    private TwitterData buildData()
    {
        Character c1 = new Character(1, "Mister Fantastic");
        Character c2 = new Character(2, "Invisible Woman");
        Character c3 = new Character(3, "The Human Torch");
        Character c4 = new Character(4, "The Thing");

        Character c5 = new Character(5, "Annihilus");
        Character c6 = new Character(6, "Doctor Doom");
        Character c7 = new Character(7, "Mad Thinker");
        Character c8 = new Character(8, "Terminus");

        List<Character> l1 = new List<Character>();
        l1.Add(c1);
        l1.Add(c2);
        l1.Add(c3);
        l1.Add(c4);
        l1.Add(c5);
        l1.Add(c6);
        l1.Add(c7);
        l1.Add(c8);

        Relationship r1 = new Relationship(1, 2);
        Relationship r2 = new Relationship(1, 3);
        Relationship r3 = new Relationship(1, 4);
        Relationship r4 = new Relationship(7, 5);
        Relationship r5 = new Relationship(7, 6);
        Relationship r6 = new Relationship(7, 8);

        List<Relationship> l2 = new List<Relationship>();
        l2.Add(r1);
        l2.Add(r2);
        l2.Add(r3);
        l2.Add(r4);
        l2.Add(r5);
        l2.Add(r6);

        PropObject o1 = new PropObject(1, "Chocolate");
        PropObject o2 = new PropObject(2, "Gun");
        PropObject o3 = new PropObject(2, "Porsche");
        List<PropObject> lp = new List<PropObject>();
        lp.Add(o1);
        lp.Add(o2);
        lp.Add(o3);

        c2.Likes = new List<int>();
        c2.Likes.Add(o1.ID);

        c3.Likes = new List<int>();
        c3.Likes.Add(o2.ID);

        c4.Likes = new List<int>();
        c4.Likes.Add(o3.ID);

        TwitterData td = new TwitterData();
        td.Characters = l1;
        td.Relationships = l2;
        td.PropObjects = lp;
        td.Villain = 7;
        td.Sidekick = 1;

        return td;
    }