virtual public void Init(GKToyBaseOverlord ovelord) { _overlord = ovelord; Type t = GetType(); props = t.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); var fs = t.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); if (null == propStates) { propNames = new string[props.Length]; propStates = new int[props.Length]; ioStates = new int[props.Length]; propLock = new bool[props.Length]; for (int i = 0; i < props.Length; i++) { propNames[i] = props[i].Name; propStates[i] = -1; ioStates[i] = 0; propLock[i] = false; } } state = NodeState.Inactive; parmRect = new Dictionary <string, NodeParm>(); parmRect.Clear(); for (int i = 0; i < props.Length; i++) { // 引用变量赋值. if (-1 != propStates[i]) { var v = props[i].PropertyType; var vlst = _overlord.GetVariableListByType(v); if (vlst.Count > propStates[i]) { props[i].SetValue(this, ((GKToyVariable)vlst[propStates[i]]), null); } } NodeParm np = new NodeParm(); np.propretyInfo = props[i]; np.rect = Rect.zero; // 参数节点区域初始化. parmRect.Add(props[i].Name, np); } }
/// <summary> /// 检查还原字符串中节点参数和现有节点属性是否有出入 /// </summary> /// <param name="backStr">还原字符串</param> /// <returns>是否有出入</returns> virtual public bool Restore(string backStr) { // 统一属性相关的变量. Type t = GetType(); props = t.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); bool isEdit = false; if (props.Length == propNames.Length) { for (int i = 0; i < props.Length; i++) { if (propNames[i] != props[i].Name) { isEdit = true; } } } else { isEdit = true; } if (isEdit) { string[] tmpPropNames = new string[props.Length]; int[] tmpPropStates = new int[props.Length]; int[] tmpIoStates = new int[props.Length]; bool[] tmpPropLock = new bool[props.Length]; for (int i = 0; i < props.Length; i++) { if (propNames.Length > i && propNames[i] == props[i].Name) { tmpPropStates[i] = propStates[i]; tmpIoStates[i] = ioStates[i]; tmpPropLock[i] = propLock[i]; } else { int index = Array.IndexOf(propNames, props[i].Name); if (0 <= index) { tmpPropStates[i] = propStates[index]; tmpIoStates[i] = ioStates[index]; tmpPropLock[i] = propLock[index]; } else { tmpPropStates[i] = -1; tmpIoStates[i] = 0; tmpPropLock[i] = false; } } tmpPropNames[i] = props[i].Name; } propNames = tmpPropNames; propStates = tmpPropStates; ioStates = tmpIoStates; propLock = tmpPropLock; } // 初始化. state = NodeState.Inactive; parmRect = new Dictionary <string, NodeParm>(); parmRect.Clear(); for (int i = 0; i < props.Length; i++) { // 引用变量赋值. if (-1 != propStates[i]) { var v = props[i].PropertyType; var vlst = _overlord.GetVariableListByType(v); if (vlst.Count > propStates[i]) { props[i].SetValue(this, ((GKToyVariable)vlst[propStates[i]]), null); } } NodeParm np = new NodeParm(); np.propretyInfo = props[i]; np.rect = Rect.zero; // 参数节点区域初始化. parmRect.Add(props[i].Name, np); } return(isEdit); }