Beispiel #1
0
        public void LoadPersistedObjects()
        {
            Dictionary<string, ObjectDetails> vObjectDetailDictionary = new Dictionary<string, ObjectDetails>();
            try
            {
                fDBConnection.Open();
                DataTable vFMObjectTable = EvaluateSQL("select * from FMObject");
                foreach (DataRow vRow in vFMObjectTable.Rows)
                {
                    ObjectDetails vOD = new ObjectDetails();
                    vOD.ObjectGUID = vRow["ObjectGUID"].ToString();
                    vOD.ClassName = vRow["ClassName"].ToString();
                    vObjectDetailDictionary.Add(vOD.ObjectGUID, vOD);
                }

                foreach (string Type in SupportedTypes)
                {
                    DataTable vAttributeDataTable = EvaluateSQL("select * from FM" + Type);
                    foreach (DataRow vRow in vAttributeDataTable.Rows)
                    {
                        string vObjectGUID = vRow["objectGUID"].ToString();
                        AttributeDetails vA;
                        vA.Attribute = vRow["Attribute"].ToString();
                        vA.Value = vRow["Value"];
                        vA.Type = Type;
                        vObjectDetailDictionary[vObjectGUID].Attributes.Add(vA);
                    }
                }
                DataTable vDerivedAttributeDataTable = EvaluateSQL("select * from FMDerived");
                foreach (DataRow vRow in vDerivedAttributeDataTable.Rows)
                {
                    string vObjectGUID = vRow["objectGUID"].ToString();
                    DerivedAttributeDetails vD;
                    vD.Attribute = vRow["Attribute"].ToString();
                    vD.Query = vRow["Query"].ToString();
                    vD.Type = vRow["Type"].ToString();
                    vObjectDetailDictionary[vObjectGUID].DerivedAttributes.Add(vD);
                }
            }
            finally
            {
                fDBConnection.Close();
            }

            foreach (KeyValuePair<string, ObjectDetails> KVP in vObjectDetailDictionary)
            {
                LoadObjectByObjectDetails(KVP.Value);
            }
        }
    public VectorObject GameObjectPosition(Vector3 ObjectSize, ObjectDetails objectDetails)
    {
        //Objects with Y set at ZERO should have the Y value updated to the top of terrain at that position
        //Items below or above ZERO are left to that position.  YEA, ZERO denotes on Terrain.  Got a better idea?

        VectorObject position = new VectorObject();

        try
        {
            float   x;
            float   y;
            float   z;
            float   y2      = 0;
            bool    isFound = false;
            Vector3 ObjectPositionToCheck;
            bool    isIntersected = false;
            byte    bAttempts     = 0;


            do
            {
                y2 = 0; //Reset
                x  = Random.Range(objectDetails.MinimumPosition.x, objectDetails.MaximumPosition.x);
                y  = Random.Range(objectDetails.MinimumPosition.y, objectDetails.MaximumPosition.y);
                z  = Random.Range(objectDetails.MinimumPosition.z, objectDetails.MaximumPosition.z);
                ObjectPositionToCheck = new Vector3(x, y, z);


                if (objectDetails.avoidObjects)
                {
                    //If y is zero, then it should be placed on the ground, aka top level of the terrain
                    if (y == 0 && this.currentTerrain != null)
                    {
                        //Find the top Y postion for the terrain
                        y  = currentTerrain.SampleHeight(ObjectPositionToCheck);
                        y2 = y;
                    }

                    //While this seems like the same call as above, the terrain location y value could still come back as zero,
                    //if so it is in water, at least in that location.
                    if (y > 0 || objectDetails.PercentInWater > 0)
                    {
                        ObjectSize.y += objectDetails.toTheSky;

                        ObjectPositionToCheck = new Vector3(x, y + (ObjectSize.y / 2) + 0.2f, z);

                        isIntersected = Physics.CheckBox(ObjectPositionToCheck, (ObjectSize / 2));

                        ObjectPositionToCheck.y -= (objectDetails.toTheSky / 2);

                        if (isIntersected == false)
                        {
                            //Remove this value before moving to check if it's in water.
                            //No need to do it above as it saves running this line if the object was intersected
                            ObjectSize.y -= objectDetails.toTheSky;

                            if (IsInWater(ObjectPositionToCheck, ObjectSize, objectDetails.PercentInWater) == false)
                            {
                                isFound = true;
                            }
                        }
                    }
                }
                else
                {
                    //Since the AvoidObjects flag is false, we only need to check if it is within water
                    if (IsInWater(ObjectPositionToCheck, ObjectSize, objectDetails.PercentInWater) == false)
                    {
                        isFound = true;
                    }
                }

                //To avoid infinite loop
                bAttempts++;
                if (bAttempts > 250)
                {
                    //It is possible that the object was found during the last cycle.  So set the "IsFound" to whatever it is, true or false.
                    position.IsFound = isFound; //This is used in the function PopulateExperience() in case no position is found
                    isFound          = true;    //Not necessarily true, but we need to get out of this loop.
                }
            } while (isFound == false);


            if (y2 > 0)
            {
                //Setting the Y value to the top of the terrain.
                ObjectPositionToCheck.y = y2;
            }

            //Adjusting this just a little to insure that if an object is at ground level then it is burried a tiny bit to avoid floating.
            //Yes this is a hack.  It would be better to find the lowest point of the object.  Someday.
            ObjectPositionToCheck.y += objectDetails.yVariance;

            position.Vector = ObjectPositionToCheck;
        }
        catch (System.Exception ex)
        {
            Debug.Log(ex.Message);
        }

        return(position);
    }
    public VectorObject AdjustObject(GameObject gameObject, ObjectDetails objectDetails)
    {
        //The return object allows this function use outside this class
        //when there is a desire to place Other objects near it.
        VectorObject VectorReturn = new VectorObject();

        try
        {
            float        x;
            float        y;
            float        z;
            VectorObject position;
            Vector3      objectSize = gameObject.transform.localScale;


            //If the terrain is used as the Min/Max of the area that can be used for placing the object
            if (objectDetails.useTerrainSize)
            {
                if (currentTerrain != null)
                {
                    objectDetails.MinimumPosition = currentTerrain.GetPosition();
                    objectDetails.MaximumPosition = currentTerrain.terrainData.size; //TODO: should the Y value be reset to zero or...?
                }
            }

            //Game Object's Size
            if (objectDetails.isScaled)
            {
                x = Random.Range(objectDetails.MinimumScale.x, objectDetails.MaximumScale.x);

                //This option allows for all values to be scaled evenly, I choose X as it was first.  Deal with it.
                if (objectDetails.isEvenlyScaled)
                {
                    y = x;
                    z = x;
                }
                else
                {
                    y = Random.Range(objectDetails.MinimumScale.y, objectDetails.MaximumScale.y);
                    z = Random.Range(objectDetails.MinimumScale.z, objectDetails.MaximumScale.z);
                }
                gameObject.transform.localScale = new Vector3(x, y, z);
            }

            //Game Object's Rotation
            x = Random.Range(objectDetails.MinimumRotation.x, objectDetails.MaximumRotation.x);
            y = Random.Range(objectDetails.MinimumRotation.y, objectDetails.MaximumRotation.y);
            z = Random.Range(objectDetails.MinimumRotation.z, objectDetails.MaximumRotation.z);
            gameObject.transform.rotation = Quaternion.Euler(x, y, z);

            //Some objects do not have a renderer, so in those cases use the original scale
            if (gameObject.GetComponent <Renderer>() != null)
            {
                objectSize = gameObject.GetComponent <Renderer>().bounds.size;
            }

            //Game Object's Position
            position = GameObjectPosition(
                objectSize,
                objectDetails);

            //Only place if the a position was found within GameObjectPosition.
            //There is a possibility that there is no room or other reason why a position is not found
            if (position.IsFound)
            {
                gameObject.transform.localPosition = position.Vector;
                VectorReturn.Vector = position.Vector;
            }
            else
            {
                Destroy(gameObject);
                VectorReturn.IsFound = false;
            }
        }
        catch (System.Exception ex)
        {
            Debug.Log(ex.Message);
        }

        return(VectorReturn);
    }
        public override void OnDetailGUI(ObjectDetails details)
        {
            base.OnDetailGUI(details);

            var destinationReference = details.ReferenceSelector <Transform>("platform_path", "Platform Path");

            CachedDestinationReference = destinationReference;

            if (destinationReference != null)
            {
                var pathDetails = destinationReference.gameObject.AddOrGetComponent <PathDetails>();

                details.SetEntry("CheckPrecondition", ObjectDataType.UTF16, "");

                details.SetEntry("friction", ObjectDataType.Float32, "1.5");

                details.SetEntry("interaction_distance", ObjectDataType.Float32, "16");

                details.SetEntry("create_physics", ObjectDataType.Boolean, "1");

                details.SetEntry("add_to_navmesh", ObjectDataType.Boolean, "1");

                details.SetEntry("attached_path", ObjectDataType.UTF16, pathDetails.PathName);

                details.SimpleDataSelector(ObjectDataType.Int32, "attached_path_start", "Path Start");

                details.SetEntry("platformIsMover", ObjectDataType.Boolean, "1");

                details.SetEntry("platformIsRotater", ObjectDataType.Boolean, "0");

                details.SetEntry("platformIsSimpleMover", ObjectDataType.Boolean, "0");

                details.SetEntry("platformNoUpdateSync", ObjectDataType.Boolean, "0");

                details.SetEntry("allowPosSnap", ObjectDataType.Boolean, "1");

                details.SetEntry("dbonly", ObjectDataType.Boolean, "1");

                details.SetEntry("bounding_radius_override", ObjectDataType.Boolean, "0");

                details.SetEntry("maxLerpDist", ObjectDataType.Int32, "4");

                details.SimpleDataSelector(ObjectDataType.Boolean, "startPathingOnLoad", "Start Pathing On Load");

                details.SimpleDataSelector(ObjectDataType.UTF8, "platformSoundStart", "Start Sound");

                details.SimpleDataSelector(ObjectDataType.UTF8, "platformSoundStop", "Stop Sound");

                details.SimpleDataSelector(ObjectDataType.UTF8, "platformSoundTravel", "Travel Sound");
            }
            else
            {
                destinationReference = new GameObject("Platform Path").transform;

                destinationReference.parent = details.transform;

                destinationReference.position = details.transform.position;

                var pathDetails = destinationReference.gameObject.AddOrGetComponent <PathDetails>();

                pathDetails.PathName = GUID.Generate().ToString();

                pathDetails.Type = PathType.MovingPlatform;

                details.SetReference("platform_path", destinationReference);
            }
        }
        /**
         * Each node in "details view" holds a reference for its corresponding
         * object in the object model. While this works fine with reference
         * types, it fails miserably with nested value types.
         *
         * For more details see OMNUnitTest.RenderHierarchyTestCase.
         */


        //public static bool TryUpdateValueType(TreeGridNode node, object newValue)
        //{
        //    if (node == null || node.Parent == null)
        //        return false;

        //    ValueTypeChange change = ValueTypeChangeFor(node.Parent, 0);
        //    if (change == null)
        //        return false;

        //    FieldInfo fieldInfo = FieldInfoFor(node);
        //    if (fieldInfo == null)
        //        return false;

        //    fieldInfo.SetValueDirect(TypedReference.MakeTypedReference(change.TargetObject, change.FieldPath.ToArray()), newValue);
        //    return true;
        //}

        //private static ValueTypeChange ValueTypeChangeFor(TreeGridNode node, int depth)
        //{
        //    IType omnType = FieldTypeFor(node);
        //    if (omnType.IsCollection || omnType.IsArray)
        //        return null;

        //    Type type = Type.GetType(omnType.FullName);
        //    if (type == null)
        //        return null;

        //    if (type.IsValueType)
        //    {
        //        ValueTypeChange change = ValueTypeChangeFor(node.Parent, depth + 1);
        //        if (change != null)
        //            change.FieldPath.Add(FieldInfoFor(node));

        //        return change;
        //    }

        //    return depth == 0 ? null : new ValueTypeChange(node.Tag);
        //}


        //private static FieldInfo FieldInfoFor(TreeGridNode node)
        //{
        //    Type parentType = Type.GetType(FieldTypeFor(node.Parent).FullName);
        //    return (parentType != null)
        //            ? parentType.GetField(FieldNameFor(node), BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public)
        //            : null;
        //}

        //private static string FieldNameFor(TreeGridNode node)
        //{
        //    return (string)node.Cells[0].Value;
        //}

        //private static IType FieldTypeFor(TreeGridNode node)
        //{
        //    long id = (long)node.Tag;
        //    object obj = Db4oClient.Client.Ext().GetByID(id);
        //    IType type  = ResolveType(DataLayerCommon.ReflectClassFor(obj));
        //    return type;
        //}

        public long GetLocalID(object obj)
        {
            ObjectDetails objDetails = new ObjectDetails(obj);

            return(objDetails.GetLocalID());
        }
Beispiel #6
0
 void LoadObjectByObjectDetails(ObjectDetails vObjectDetails)
 {
     FMObject vLoadedObject = new FMObject(objectSpace, vObjectDetails.ObjectGUID);
     vLoadedObject.FMClass = vObjectDetails.ClassName;
     foreach (AttributeDetails AD in vObjectDetails.Attributes)
         vLoadedObject.CreateAttribute(AD.Type, AD.Attribute, AD.Value);
     foreach (DerivedAttributeDetails DAD in vObjectDetails.DerivedAttributes)
         vLoadedObject.CreateDerivedAttribute(DAD.Type, DAD.Attribute, DAD.Query);
 }
        public static int GetDepth(long id)
        {
            ObjectDetails objDetails = new ObjectDetails(id);

            return(objDetails.GetDepth(id));
        }
        public static object GetObjById(long id)
        {
            ObjectDetails objDetails = new ObjectDetails(id);

            return(objDetails.GetObjById(id));
        }
Beispiel #9
0
        public static int GetDepth(object obj)
        {
            ObjectDetails objDetails = new ObjectDetails(obj);

            return(objDetails.GetDepth(obj));
        }
 public virtual void OnDetailGUI(ObjectDetails details)
 {
 }
 public virtual void OnDetailGizmos(ObjectDetails details)
 {
 }