示例#1
0
        public static string GetObjModelExtra(SetObject obj,
                                              SetObjectType type, string startName = null)
        {
            // Get the correct extra's model name
            string mdlName = startName;

            foreach (var extra in type.Extras)
            {
                if (extra.Type.ToLower() != "model")
                {
                    continue;
                }

                if (string.IsNullOrEmpty(extra.Condition) ||
                    LuaScript.EvaluateObjectCondition(obj, type, extra.Condition))
                {
                    mdlName = extra.Value;
                    break;
                }
            }

            if (string.IsNullOrEmpty(mdlName))
            {
                return(mdlName);
            }

            // If the model name is actually supposed to be the value of
            // another parameter (e.g. in Gismos), get the name from that instead.
            if (mdlName.IndexOf('.') == -1)
            {
                int mdlNameParamIndex = type.GetParameterIndex(mdlName);
                if (mdlNameParamIndex != -1)
                {
                    mdlName = (obj.Parameters[
                                   mdlNameParamIndex].Data as string);
                }
            }
            else
            {
                int openIndex  = mdlName.IndexOf('{');
                int closeIndex = mdlName.IndexOf('}');

                if (openIndex != -1 && closeIndex > openIndex)
                {
                    ++openIndex;
                    if (int.TryParse(mdlName.Substring(openIndex,
                                                       closeIndex - openIndex), out int index) &&
                        index >= 0 && index < type.Parameters.Count)
                    {
                        mdlName = mdlName.Replace($"{{{index}}}",
                                                  (obj.Parameters[index].Data as string));
                    }
                }
            }

            return(mdlName);
        }
示例#2
0
        public static Vector3 GetObjScale(SetObjectType type, SetObject obj)
        {
            if (type == null)
            {
                return(new Vector3(1, 1, 1));
            }

            var scaleExtra = type.GetExtra("scale");

            if (scaleExtra != null && !string.IsNullOrEmpty(scaleExtra.Value))
            {
                if (float.TryParse(scaleExtra.Value, out float s))
                {
                    return(new Vector3(s, s, s));
                }

                // TODO: Maybe try to parse it as a Vector3 as well?

                else
                {
                    int scaleParamIndex = type.GetParameterIndex(scaleExtra.Value);
                    if (scaleParamIndex != -1)
                    {
                        var param = obj.Parameters[scaleParamIndex];
                        if (param != null)
                        {
                            if (param.DataType == typeof(Vector3))
                            {
                                return((Vector3)param.Data);
                            }
                            else if (param.DataType == typeof(float))
                            {
                                float f = (float)param.Data;
                                return(new Vector3(f, f, f));
                            }
                        }
                    }
                }
            }

            return(new Vector3(1, 1, 1));
        }